Class: Async::HTTP::Body::Streamable
- Defined in:
- lib/async/http/body/streamable.rb
Overview
Invokes a callback once the body has finished reading.
Instance Attribute Summary
Attributes inherited from Wrapper
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(body, callback, remaining = nil) ⇒ Streamable
constructor
A new instance of Streamable.
- #read ⇒ Object
Methods inherited from Wrapper
#empty?, #finish, #inspect, #length
Methods inherited from Readable
#each, #empty?, #finish, #join, #length
Constructor Details
#initialize(body, callback, remaining = nil) ⇒ Streamable
Returns a new instance of Streamable.
40 41 42 43 44 45 |
# File 'lib/async/http/body/streamable.rb', line 40 def initialize(body, callback, remaining = nil) super(body) @callback = callback @remaining = remaining end |
Class Method Details
.wrap(message, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/async/http/body/streamable.rb', line 28 def self.wrap(, &block) if and body = .body if remaining = body.length remaining = Integer(remaining) end .body = self.new(.body, block, remaining) else yield end end |
Instance Method Details
#close ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/async/http/body/streamable.rb', line 47 def close(*) if @body super @callback.call @body = nil end end |
#read ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/async/http/body/streamable.rb', line 57 def read if chunk = super @remaining -= chunk.bytesize if @remaining else if @remaining and @remaining > 0 raise EOFError, "Expected #{@remaining} more bytes!" end end return chunk end |