Class: Protocol::HTTP::Body::Readable
- Inherits:
-
Object
- Object
- Protocol::HTTP::Body::Readable
- Defined in:
- lib/protocol/http/body/readable.rb
Overview
def finish -> buffer the stream and close it. def close(error = nil) -> close the stream immediately. end
Instance Method Summary collapse
-
#close(error = nil) ⇒ Object
The consumer can call stop to signal that the stream output has terminated.
-
#each ⇒ Object
Enumerate all chunks until finished, then invoke ‘#close`.
-
#empty? ⇒ Boolean
Will read return any data?.
-
#finish ⇒ Object
Read all remaining chunks into a buffered body and close the underlying input.
-
#join ⇒ Object
Read all remaining chunks into a single binary string using ‘#each`.
- #length ⇒ Object
-
#read ⇒ Object
Read the next available chunk.
Instance Method Details
#close(error = nil) ⇒ Object
The consumer can call stop to signal that the stream output has terminated.
39 40 |
# File 'lib/protocol/http/body/readable.rb', line 39 def close(error = nil) end |
#each ⇒ Object
Enumerate all chunks until finished, then invoke ‘#close`.
63 64 65 66 67 68 69 |
# File 'lib/protocol/http/body/readable.rb', line 63 def each while chunk = self.read yield chunk end ensure self.close($!) end |
#empty? ⇒ Boolean
Will read return any data?
43 44 45 |
# File 'lib/protocol/http/body/readable.rb', line 43 def empty? false end |
#finish ⇒ Object
Read all remaining chunks into a buffered body and close the underlying input.
57 58 59 60 |
# File 'lib/protocol/http/body/readable.rb', line 57 def finish # Internally, this invokes `self.each` which then invokes `self.close`. Buffered.for(self) end |
#join ⇒ Object
Read all remaining chunks into a single binary string using ‘#each`.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/protocol/http/body/readable.rb', line 72 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 ⇒ Object
47 48 49 |
# File 'lib/protocol/http/body/readable.rb', line 47 def length nil end |
#read ⇒ Object
Read the next available chunk.
52 53 54 |
# File 'lib/protocol/http/body/readable.rb', line 52 def read nil end |