class Protocol::HTTP::Body::Buffered
A body which buffers all it’s contents.
def self.for(body)
def self.for(body) chunks = [] body.each do |chunk| chunks << chunk end self.new(chunks) end
def self.wrap(body)
-
(Readable, nil)
- the wrapped body or nil if nil was given.
def self.wrap(body) if body.is_a? Readable return body elsif body.is_a? Array return self.new(body) elsif body.is_a?(String) return self.new([body]) elsif body return self.for(body) end end
def close(error = nil)
def close(error = nil) @chunks << nil end
def empty?
def empty? @index >= @chunks.length end
def finish
def finish self end
def initialize(chunks = [], length = nil)
def initialize(chunks = [], length = nil) @chunks = chunks @length = length @index = 0 end
def inspect
def inspect "\#<#{self.class} #{@chunks.count} chunks, #{self.length} bytes>" end
def length
def length @length ||= @chunks.inject(0) {|sum, chunk| sum + chunk.bytesize} end
def read
def read if chunk = @chunks[@index] @index += 1 return chunk.dup end end
def rewind
def rewind @index = 0 end
def write(chunk)
def write(chunk) @chunks << chunk end