Class: Async::HTTP::Body::Readable
- Inherits:
-
Object
- Object
- Async::HTTP::Body::Readable
- Defined in:
- lib/async/http/body/readable.rb
Overview
A generic base class for wrapping body instances. Typically you’d override ‘#read`.
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.
29 30 |
# File 'lib/async/http/body/readable.rb', line 29 def close(error = nil) end |
#each ⇒ Object
Enumerate all chunks until finished, then invoke ‘#close`.
53 54 55 56 57 58 59 60 |
# File 'lib/async/http/body/readable.rb', line 53 def each while chunk = self.read yield chunk # chunk.clear end ensure self.close($!) end |
#empty? ⇒ Boolean
Will read return any data?
33 34 35 |
# File 'lib/async/http/body/readable.rb', line 33 def empty? false end |
#finish ⇒ Object
Read all remaining chunks into a buffered body and close the underlying input.
47 48 49 50 |
# File 'lib/async/http/body/readable.rb', line 47 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`.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/async/http/body/readable.rb', line 63 def join buffer = IO::Buffer.new self.each do |chunk| buffer << chunk chunk.clear end return buffer end |
#length ⇒ Object
37 38 39 |
# File 'lib/async/http/body/readable.rb', line 37 def length nil end |
#read ⇒ Object
Read the next available chunk.
42 43 44 |
# File 'lib/async/http/body/readable.rb', line 42 def read nil end |