class HTTP::Response::IoBody
object.
A Body class that wraps an IO, rather than a the client
def each
def each while (part = readpartial) yield part end end
def initialize(an_io)
def initialize(an_io) @streaming = nil @stream = an_io end
def inspect
def inspect "#<#{self.class}:#{object_id.to_s(16)} @streaming=#{!!@streaming}>" end
def readall
def readall fail StateError, "body is being streamed" unless @streaming.nil? @streaming = false "".tap do |buf| buf << stream.read until stream.eof? end end
def readpartial(size = HTTP::Connection::BUFFER_SIZE)
-
(String, nil)
- the next `size` octets part of the
def readpartial(size = HTTP::Connection::BUFFER_SIZE) stream! return nil if stream.eof? stream.readpartial(size) end
def stream!
def stream! fail StateError, "body has already been consumed" if @streaming == false @streaming = true end
def to_s
-
(String)
- eagerly consume the entire body as a string
def to_s @contents ||= readall end