Class: Rack::Deflater::GzipStream
- Inherits:
-
Object
- Object
- Rack::Deflater::GzipStream
- Defined in:
- lib/rack/deflater.rb
Instance Method Summary collapse
- #close ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(body, mtime, sync) ⇒ GzipStream
constructor
A new instance of GzipStream.
- #write(data) ⇒ Object
Constructor Details
#initialize(body, mtime, sync) ⇒ GzipStream
Returns a new instance of GzipStream.
80 81 82 83 84 |
# File 'lib/rack/deflater.rb', line 80 def initialize(body, mtime, sync) @sync = sync @body = body @mtime = mtime end |
Instance Method Details
#close ⇒ Object
104 105 106 107 |
# File 'lib/rack/deflater.rb', line 104 def close @body.close if @body.respond_to?(:close) @body = nil end |
#each(&block) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rack/deflater.rb', line 86 def each(&block) @writer = block gzip = ::Zlib::GzipWriter.new(self) gzip.mtime = @mtime if @mtime @body.each { |part| len = gzip.write(part) # Flushing empty parts would raise Zlib::BufError. gzip.flush if @sync && len > 0 } ensure gzip.close @writer = nil end |
#write(data) ⇒ Object
100 101 102 |
# File 'lib/rack/deflater.rb', line 100 def write(data) @writer.call(data) end |