Method: Origami::Filter::ASCII85#encode

Defined in:
lib/origami/filters/ascii.rb

#encode(stream) ⇒ Object

Encodes given data into base85.

stream

The data to encode.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/origami/filters/ascii.rb', line 80

def encode(stream)
    i = 0
    code = ::String.new.b
    input = stream.dup

    while i < input.size do

        if input.length - i < 4
            addend = 4 - (input.length - i)
            input << "\0" * addend
        else
            addend = 0
        end

        # Encode the 4 bytes input value into a 5 character string.
        value = input[i, 4].unpack("L>")[0]
        outblock = encode_block(value)

        outblock = "z" if outblock == "!!!!!" and addend == 0

        if addend != 0
            outblock = outblock[0, 4 - addend + 1]
        end

        code << outblock

        i = i + 4
    end

    code
end