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
Read all remaining chunks into a buffered 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.
- #length ⇒ Object
-
#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
Read all remaining chunks into a buffered 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.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/async/http/body/readable.rb', line 52 def each return to_enum unless block_given? while chunk = self.read yield chunk # chunk.clear 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.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/async/http/body/readable.rb', line 66 def join buffer = IO::Buffer.new self.each do |chunk| buffer << chunk chunk.clear end return buffer end |
#length ⇒ Object
38 39 40 |
# File 'lib/async/http/body/readable.rb', line 38 def length nil end |
#read ⇒ Object
Read the next available chunk.
43 44 45 |
# File 'lib/async/http/body/readable.rb', line 43 def read nil end |
#stop(error) ⇒ Object
The consumer can call stop to signal that the stream output has terminated.
48 49 |
# File 'lib/async/http/body/readable.rb', line 48 def stop(error) end |