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.



86
87
88
# File 'lib/rack/deflater.rb', line 86

def initialize(body)
  @body = body
end

Instance Method Details

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

Yields:

  • (deflater.finish)


90
91
92
93
94
95
96
# File 'lib/rack/deflater.rb', line 90

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