class Async::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)
def self.wrap(body) if body.is_a? Async::HTTP::Body::Readable return body elsif body.is_a? Array return self.new(body) else return self.for(body) end end
def close
def close self end
def each
def each return to_enum unless block_given? while @index < @chunks.count yield @chunks[@index] @index += 1 end end
def empty?
def empty? @chunks.empty? end
def initialize(chunks)
def initialize(chunks) @chunks = chunks @length = nil @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 end return chunk end
def rewind
def rewind @index = 0 end