Class: Puppet::Network::HTTP::Compression::Active::ZlibAdapter
- Defined in:
- lib/puppet/network/http/compression.rb
Overview
This adapters knows how to uncompress both ‘zlib’ stream (the deflate algorithm from Content-Encoding) and GZip streams.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(uncompressor = Zlib::Inflate.new(15 + 32)) ⇒ ZlibAdapter
constructor
A new instance of ZlibAdapter.
- #uncompress(chunk) ⇒ Object
Constructor Details
#initialize(uncompressor = Zlib::Inflate.new(15 + 32)) ⇒ ZlibAdapter
Returns a new instance of ZlibAdapter.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/puppet/network/http/compression.rb', line 61 def initialize(uncompressor = Zlib::Inflate.new(15 + 32)) # Create an inflater that knows to parse GZip streams and zlib streams. # This uses a property of the C Zlib library, documented as follow: # windowBits can also be greater than 15 for optional gzip decoding. Add # 32 to windowBits to enable zlib and gzip decoding with automatic header # detection, or add 16 to decode only the gzip format (the zlib format will # return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is # a crc32 instead of an adler32. @uncompressor = uncompressor @first = true end |
Instance Method Details
#close ⇒ Object
90 91 92 93 94 |
# File 'lib/puppet/network/http/compression.rb', line 90 def close @uncompressor.finish ensure @uncompressor.close end |
#uncompress(chunk) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/puppet/network/http/compression.rb', line 73 def uncompress(chunk) out = @uncompressor.inflate(chunk) @first = false return out rescue Zlib::DataError # it can happen that we receive a raw deflate stream # which might make our inflate throw a data error. # in this case, we try with a verbatim (no header) # deflater. @uncompressor = Zlib::Inflate.new if @first then @first = false retry end raise end |