Class: Zipstream::Body
- Inherits:
-
Object
- Object
- Zipstream::Body
- Defined in:
- lib/zipstream/body.rb
Overview
Stream a zipfile as a rack response body
We use Fibers to deep-yield data being written to the zip stream directly to Rack
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(&block) ⇒ Body
constructor
A new instance of Body.
Constructor Details
#initialize(&block) ⇒ Body
Returns a new instance of Body.
6 7 8 9 10 11 12 13 |
# File 'lib/zipstream/body.rb', line 6 def initialize &block @stream = Zipstream::FiberYieldingStream.new @fiber = Zipstream::Fiber.new do Zipstream.new(@stream).tap(&block).close # Make sure this returns nil as a sentinel nil end end |
Instance Method Details
#each ⇒ Object
15 16 17 18 19 20 |
# File 'lib/zipstream/body.rb', line 15 def each # Yield fiber yielded data until we hit our nil sentinel until (yielded = @fiber.resume).nil? yield yielded end end |