Class: Puppet::Network::HTTP::Compression::Active::ZlibAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/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

Constructor Details

#initializeZlibAdapter

Returns a new instance of ZlibAdapter.



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vendor/puppet/network/http/compression.rb', line 56

def initialize
  # 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 = Zlib::Inflate.new(15 + 32)
  @first = true
end

Instance Method Details

#closeObject



85
86
87
88
# File 'lib/vendor/puppet/network/http/compression.rb', line 85

def close
  @uncompressor.finish
  @uncompressor.close
end

#uncompress(chunk) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/vendor/puppet/network/http/compression.rb', line 68

def uncompress(chunk)
  out = @uncompressor.inflate(chunk)
  @first = false
  return out
rescue Zlib::DataError => z
  # 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