Class: Protocol::Rack::Body::Streaming
- Inherits:
-
HTTP::Body::Readable
- Object
- HTTP::Body::Readable
- Protocol::Rack::Body::Streaming
- Defined in:
- lib/protocol/rack/body/streaming.rb
Overview
Wraps a streaming response body into a compatible Protocol::HTTP body.
Defined Under Namespace
Classes: Output
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
Instance Method Summary collapse
- #call(stream) ⇒ Object
-
#initialize(block, input = nil) ⇒ Streaming
constructor
A new instance of Streaming.
-
#read ⇒ Object
Invokes the block in a fiber which yields chunks when they are available.
- #stream? ⇒ Boolean
Constructor Details
#initialize(block, input = nil) ⇒ Streaming
Returns a new instance of Streaming.
14 15 16 17 18 |
# File 'lib/protocol/rack/body/streaming.rb', line 14 def initialize(block, input = nil) @block = block @input = input @output = nil end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
20 21 22 |
# File 'lib/protocol/rack/body/streaming.rb', line 20 def block @block end |
Instance Method Details
#call(stream) ⇒ Object
54 55 56 57 |
# File 'lib/protocol/rack/body/streaming.rb', line 54 def call(stream) raise "Streaming body has already been read!" if @output @block.call(stream) end |
#read ⇒ Object
Invokes the block in a fiber which yields chunks when they are available.
45 46 47 48 |
# File 'lib/protocol/rack/body/streaming.rb', line 45 def read @output ||= Output.new(@input, @block) return @output.read end |
#stream? ⇒ Boolean
50 51 52 |
# File 'lib/protocol/rack/body/streaming.rb', line 50 def stream? true end |