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`.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/async/http/body/readable.rb', line 56 def each return to_enum unless block_given? 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 51 52 53 |
# File 'lib/async/http/body/readable.rb', line 47 def finish buffered = Buffered.for(self) self.close return buffered end |
#join ⇒ Object
Read all remaining chunks into a single binary string using ‘#each`.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/async/http/body/readable.rb', line 68 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 |