class HTTP::FormData::CompositeIO

Provides IO interface across multiple IO objects.

def initialize(ios)

Parameters:
  • ios (Array) -- Array of IO objects

Other tags:
    Api: - public
def initialize(ios)
  @index = 0
  @ios   = ios.map do |io|
    if io.is_a?(String)
      StringIO.new(io)
    elsif io.respond_to?(:read)
      io
    else
      raise ArgumentError,
            "#{io.inspect} is neither a String nor an IO object"
    end
  end
end

def read(length = nil, outbuf = nil)

Returns:
  • (String, nil) -

Parameters:
  • outbuf (String) -- String to be replaced with retrieved data
  • length (Integer) -- Number of bytes to retrieve

Other tags:
    Api: - public
def read(length = nil, outbuf = nil)
  data   = outbuf.clear.force_encoding(Encoding::BINARY) if outbuf
  data ||= "".b
  read_chunks(length) { |chunk| data << chunk }
  data unless length && data.empty?
end

def read_chunks(length)

Returns:
  • (void) -

Other tags:
    Api: - private
def read_chunks(length)
  while (chunk = readpartial(length))
    yield chunk.force_encoding(Encoding::BINARY)
    next if length.nil?
    remaining = length - chunk.bytesize
    break if remaining.zero?
    length = remaining
  end
end

def readpartial(max_length)

Returns:
  • (String, nil) -

Other tags:
    Api: - private
def readpartial(max_length)
  while (io = @ios.at(@index))
    chunk = io.read(max_length)
    return chunk if chunk && !chunk.empty?
    @index += 1
  end
end

def rewind

Returns:
  • (void) -

Other tags:
    Api: - public
def rewind
  @ios.each(&:rewind)
  @index = 0
end

def size

Returns:
  • (Integer) -

Other tags:
    Api: - public
def size
  @size ||= @ios.sum(&:size)
end