Class: Rack::Deflater::GzipStream

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/deflater.rb

Instance Method Summary collapse

Constructor Details

#initialize(body, mtime, sync) ⇒ GzipStream

Returns a new instance of GzipStream



76
77
78
79
80
# File 'lib/rack/deflater.rb', line 76

def initialize(body, mtime, sync)
  @sync = sync
  @body = body
  @mtime = mtime
end

Instance Method Details

#closeObject



99
100
101
102
# File 'lib/rack/deflater.rb', line 99

def close
  @body.close if @body.respond_to?(:close)
  @body = nil
end

#each(&block) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rack/deflater.rb', line 82

def each(&block)
  @writer = block
  gzip = ::Zlib::GzipWriter.new(self)
  gzip.mtime = @mtime if @mtime
  @body.each { |part|
    gzip.write(part)
    gzip.flush if @sync
  }
ensure
  gzip.close
  @writer = nil
end

#write(data) ⇒ Object



95
96
97
# File 'lib/rack/deflater.rb', line 95

def write(data)
  @writer.call(data)
end