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 ⇒ Object
Buffer any remaining body.
-
#each ⇒ Object
Enumerate all chunks until finished.
-
#empty? ⇒ Boolean
Will read return any data?.
-
#join ⇒ Object
Read all remaining chunks into a single binary string.
-
#read ⇒ Object
Read the next available chunk.
-
#stop(error) ⇒ Object
The consumer can call stop to signal that the stream output has terminated.
Instance Method Details
#close ⇒ Object
Buffer any remaining body.
29 30 31 |
# File 'lib/async/http/body/readable.rb', line 29 def close Buffered.for(self) end |
#each ⇒ Object
Enumerate all chunks until finished. If an error is thrown, #stop will be invoked.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/async/http/body/readable.rb', line 48 def each return to_enum unless block_given? while chunk = self.read yield chunk end rescue stop($!) raise end |
#empty? ⇒ Boolean
Will read return any data?
34 35 36 |
# File 'lib/async/http/body/readable.rb', line 34 def empty? false end |
#join ⇒ Object
Read all remaining chunks into a single binary string.
61 62 63 64 65 66 67 68 69 |
# File 'lib/async/http/body/readable.rb', line 61 def join buffer = IO::BinaryString.new self.each do |chunk| buffer << chunk end return buffer end |
#read ⇒ Object
Read the next available chunk.
39 40 41 |
# File 'lib/async/http/body/readable.rb', line 39 def read nil end |
#stop(error) ⇒ Object
The consumer can call stop to signal that the stream output has terminated.
44 45 |
# File 'lib/async/http/body/readable.rb', line 44 def stop(error) end |