class Rack::Deflater::GzipStream

Public Class Methods

new(body, mtime, sync) click to toggle source
# File lib/rack/deflater.rb, line 80
def initialize(body, mtime, sync)
  @sync = sync
  @body = body
  @mtime = mtime
end

Public Instance Methods

close() click to toggle source
# File lib/rack/deflater.rb, line 104
def close
  @body.close if @body.respond_to?(:close)
  @body = nil
end
each(&block) click to toggle source
# 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) click to toggle source
# File lib/rack/deflater.rb, line 100
def write(data)
  @writer.call(data)
end