Class: Rack::Deflater::DeflateStream

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

Constant Summary collapse

DEFLATE_ARGS =
[
  Zlib::DEFAULT_COMPRESSION,
  # drop the zlib header which causes both Safari and IE to choke
  -Zlib::MAX_WBITS,
  Zlib::DEF_MEM_LEVEL,
  Zlib::DEFAULT_STRATEGY
]

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ DeflateStream

Returns a new instance of DeflateStream.


83
84
85
# File 'lib/rack/deflater.rb', line 83

def initialize(body)
  @body = body
end

Instance Method Details

#each {|deflater.finish| ... } ⇒ Object

Yields:

  • (deflater.finish)

87
88
89
90
91
92
93
# File 'lib/rack/deflater.rb', line 87

def each
  deflater = ::Zlib::Deflate.new(*DEFLATE_ARGS)
  @body.each { |part| yield deflater.deflate(part) }
  @body.close if @body.respond_to?(:close)
  yield deflater.finish
  nil
end