# class Puppet::Network::HTTP::Compression::Active::ZlibAdapter

This adapters knows how to uncompress both ‘zlib’ stream (the deflate algorithm from Content-Encoding) and GZip streams.

### Public Class Methods

new() click to toggle source

    # File lib/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

### Public Instance Methods

close() click to toggle source

    # File lib/puppet/network/http/compression.rb, line 85
    def close
      @uncompressor.finish
      @uncompressor.close
    end

uncompress(chunk) click to toggle source

    # File lib/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