class Protocol::HTTP::Body::Readable
def finish -> buffer the stream and close it. def close(error = nil) -> close the stream immediately.
end
Public Instance Methods
call(stream)
click to toggle source
Write the body to the given stream.
# File lib/protocol/http/body/readable.rb, line 70 def call(stream) while chunk = self.read stream.write(chunk) end ensure stream.close($!) end
close(error = nil)
click to toggle source
The consumer can call stop to signal that the stream output has terminated.
# File lib/protocol/http/body/readable.rb, line 39 def close(error = nil) end
each() { |chunk| ... }
click to toggle source
Enumerate all chunks until finished, then invoke `#close`.
# File lib/protocol/http/body/readable.rb, line 85 def each while chunk = self.read yield chunk end ensure self.close($!) end
empty?()
click to toggle source
Will read return any data?
# File lib/protocol/http/body/readable.rb, line 43 def empty? false end
finish()
click to toggle source
Read all remaining chunks into a buffered body and close the underlying input.
# File lib/protocol/http/body/readable.rb, line 79 def finish # Internally, this invokes `self.each` which then invokes `self.close`. Buffered.for(self) end
join()
click to toggle source
Read all remaining chunks into a single binary string using `#each`.
# File lib/protocol/http/body/readable.rb, line 94 def join buffer = String.new.force_encoding(Encoding::BINARY) self.each do |chunk| buffer << chunk chunk.clear end if buffer.empty? return nil else return buffer end end
length()
click to toggle source
# File lib/protocol/http/body/readable.rb, line 54 def length nil end
read()
click to toggle source
Read the next available chunk.
# File lib/protocol/http/body/readable.rb, line 59 def read nil end
ready?()
click to toggle source
Whether calling read will block. We prefer pessimistic implementation, and thus default to `false`. @return [Boolean]
# File lib/protocol/http/body/readable.rb, line 50 def ready? false end
stream?()
click to toggle source
Should the internal mechanism prefer to use {call}? @returns [Boolean]
# File lib/protocol/http/body/readable.rb, line 65 def stream? false end