class Ascii85::Wrapper
Wraps the input in ‘<~’ and ‘~>’ delimiters and ensures that no line is longer than the specified length. You do not need to use this directly.
@private
Public Class Methods
new(out, wrap_lines)
click to toggle source
# File lib/ascii85.rb, line 398 def initialize(out, wrap_lines) @line_length = [2, wrap_lines.to_i].max @out = out @out.write(START_MARKER) @cur_len = 2 end
Public Instance Methods
finish()
click to toggle source
# File lib/ascii85.rb, line 426 def finish # Add the closing delimiter (may need to be pushed to the next line) @out.write(LINE_BREAK) if @cur_len + 2 > @line_length @out.write(ENDING_MARKER) @out.flush @out end
write(buffer)
click to toggle source
# File lib/ascii85.rb, line 407 def write(buffer) loop do s = buffer.bytesize if @cur_len + s < @line_length @out.write(buffer) @cur_len += s return end remaining = @line_length - @cur_len @out.write(buffer[0...remaining]) @out.write(LINE_BREAK) @cur_len = 0 buffer = buffer[remaining..] return if buffer.empty? end end