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)
-
(Readable, nil)
- the wrapped body or nil if nil was given.
def self.wrap(body) if body.is_a? Async::HTTP::Body::Readable return body elsif body.is_a? Array return self.new(body) elsif body return self.for(body) end end
def close
def close self end
def empty?
def empty? @index >= @chunks.length 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&.dup end
def rewind
def rewind @index = 0 end