class Roda::RodaPlugins::Streaming::Stream
Class of the response body in case you use stream.
Public Class Methods
Source
# File lib/roda/plugins/streaming.rb, line 51 def initialize(opts=OPTS, &block) @block = block @out = nil @callback = opts[:callback] @closed = false end
Handle streaming options, see Streaming
for details.
Public Instance Methods
Source
# File lib/roda/plugins/streaming.rb, line 66 def <<(data) write(data) self end
Add output to the streaming response body. Returns self.
Source
# File lib/roda/plugins/streaming.rb, line 73 def close return if closed? @closed = true @callback.call if @callback end
If not already closed, close the connection, and call any callbacks.
Source
# File lib/roda/plugins/streaming.rb, line 80 def closed? @closed end
Whether the connection has already been closed.
Source
# File lib/roda/plugins/streaming.rb, line 85 def each(&out) @out = out @block.call(self) ensure close end
Yield values to the block as they are passed in via <<
.
Source
# File lib/roda/plugins/streaming.rb, line 59 def write(data) data = data.to_s @out.call(data) data.bytesize end
Add output to the streaming response body. Returns number of bytes written.