module IOP::BufferingFeed

@private

Feed implementation for sequential streams which can not seek or request for the block size to read.

@note a class including this module must implement the {#next_data} method.

@since 0.1

Public Instance Methods

process!() click to toggle source
# File lib/iop.rb, line 272
def process!
  unless @buffer.nil?
    if @buffer.size > @size
      @left = 0
      process(@buffer[0, @size])
      @buffer = @buffer[@size..-1]
    else
      @left -= @buffer.size
      process(@buffer)
      @buffer = nil
    end
  end
  until @left.zero?
    raise EOFError, INSUFFICIENT_DATA if (data = next_data).nil?
    if @left < data.size
      process(data[0, @left])
      @buffer = data[@left..-1]
      @left = 0
    else
      process(data)
      @left -= data.size
    end
  end
  @left = @size = nil
  process
end
read!(size) click to toggle source
# File lib/iop.rb, line 267
def read!(size)
  @left = @size = size
  self
end

Protected Instance Methods

next_data() click to toggle source

Returns the data portion of non-zero size or nil on EOF.

@abstract @return [String] data chunk recently read or nil

# File lib/iop.rb, line 305
def next_data; nil end