Class: Grack::IOStreamer
- Inherits:
-
Object
- Object
- Grack::IOStreamer
- Defined in:
- lib/grack/io_streamer.rb
Overview
A Rack body implementation that streams a given IO object in chunks for a Rack response.
Direct Known Subclasses
Constant Summary collapse
- READ_SIZE =
The number of bytes to read at a time from IO streams.
32768
Instance Attribute Summary collapse
-
#mtime ⇒ Object
readonly
The last modified time to report for the Rack response.
Instance Method Summary collapse
-
#each {|chunk| ... } ⇒ Object
Iterates over the wrapped IO object in chunks, yielding each one.
-
#initialize(io, mtime) ⇒ IOStreamer
constructor
Creates a new instance of this object.
- #with_io {|io| ... } ⇒ Object private
Constructor Details
#initialize(io, mtime) ⇒ IOStreamer
Creates a new instance of this object.
16 17 18 19 |
# File 'lib/grack/io_streamer.rb', line 16 def initialize(io, mtime) @io = io @mtime = mtime end |
Instance Attribute Details
#mtime ⇒ Object (readonly)
The last modified time to report for the Rack response.
23 24 25 |
# File 'lib/grack/io_streamer.rb', line 23 def mtime @mtime end |
Instance Method Details
#each {|chunk| ... } ⇒ Object
Iterates over the wrapped IO object in chunks, yielding each one.
29 30 31 32 33 34 35 |
# File 'lib/grack/io_streamer.rb', line 29 def each with_io do |io| while chunk = io.read(READ_SIZE) do yield(chunk) end end end |
#with_io {|io| ... } ⇒ Object (private)
41 42 43 |
# File 'lib/grack/io_streamer.rb', line 41 def with_io yield(@io) end |