class LineBuffer

Constants

DEFAULT_ENCODING
NEWLINE

Public Class Methods

new(options = {}) click to toggle source
# File lib/line_buffer.rb, line 2
def initialize(options = {})
  @encoding = options[:encoding] || DEFAULT_ENCODING
  @buffer = ''.force_encoding(Encoding::BINARY)
  @cut_offset = @index_offset = 0
end

Public Instance Methods

<<(chunk) click to toggle source
# File lib/line_buffer.rb, line 8
def <<(chunk)
  @buffer << chunk
end
done?() click to toggle source
# File lib/line_buffer.rb, line 23
def done?
  @buffer.empty?
end
get() { |force_encoding| ... } click to toggle source
# File lib/line_buffer.rb, line 12
def get(&block)
  @buffer.force_encoding(Encoding::BINARY)
  while (i = @buffer.index(NEWLINE, @index_offset))
    yield @buffer[@cut_offset, i-@cut_offset+1].force_encoding(@encoding)
    @index_offset = @cut_offset = i+1
  end
  @buffer.slice!(0, @cut_offset)
  @index_offset = @buffer.size
  @cut_offset = 0
end