lib/inflate.js
function Inflate(options) {
  if (!(this instanceof Inflate)) return new Inflate(options);

  this.options = utils.assign({
    chunkSize: 16384,
    windowBits: 0,
    to: ''
  }, options || {});

  var opt = this.options;

  // Force window size for `raw` data, if not set directly,
  // because we have no header for autodetect.
  if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
    opt.windowBits = -opt.windowBits;
    if (opt.windowBits === 0) { opt.windowBits = -15; }
  }

  // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
  if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&
      !(options && options.windowBits)) {
    opt.windowBits += 32;
  }

  // Gzip header has no info about windows size, we can do autodetect only
  // for deflate. So, if window size not set, force it to max when gzip possible
  if ((opt.windowBits > 15) && (opt.windowBits < 48)) {
    // bit 3 (16) -> gzipped data
    // bit 4 (32) -> autodetect gzip/deflate
    if ((opt.windowBits & 15) === 0) {
      opt.windowBits |= 15;
    }
  }

  this.err    = 0;      // error code, if happens (0 = Z_OK)
  this.msg    = '';     // error message
  this.ended  = false;  // used to avoid multiple onEnd() calls
  this.chunks = [];     // chunks of compressed data

  this.strm   = new ZStream();
  this.strm.avail_out = 0;

  var status  = zlib_inflate.inflateInit2(
    this.strm,
    opt.windowBits
  );

  if (status !== c.Z_OK) {
    throw new Error(msg[status]);
  }

  this.header = new GZheader();

  zlib_inflate.inflateGetHeader(this.strm, this.header);

  // Setup dictionary
  if (opt.dictionary) {
    // Convert data if needed
    if (typeof opt.dictionary === 'string') {
      opt.dictionary = strings.string2buf(opt.dictionary);
    } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
      opt.dictionary = new Uint8Array(opt.dictionary);
    }
    if (opt.raw) { //In raw mode we need to set the dictionary early
      status = zlib_inflate.inflateSetDictionary(this.strm, opt.dictionary);
      if (status !== c.Z_OK) {
        throw new Error(msg[status]);
      }
    }
  }
}
function Inflate(options) {
  if (!(this instanceof Inflate)) return new Inflate(options);

  this.options = utils.assign({
    chunkSize: 16384,
    windowBits: 0,
    to: ''
  }, options || {});

  var opt = this.options;

  // Force window size for `raw` data, if not set directly,
  // because we have no header for autodetect.
  if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
    opt.windowBits = -opt.windowBits;
    if (opt.windowBits === 0) { opt.windowBits = -15; }
  }

  // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
  if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&
      !(options && options.windowBits)) {
    opt.windowBits += 32;
  }

  // Gzip header has no info about windows size, we can do autodetect only
  // for deflate. So, if window size not set, force it to max when gzip possible
  if ((opt.windowBits > 15) && (opt.windowBits < 48)) {
    // bit 3 (16) -> gzipped data
    // bit 4 (32) -> autodetect gzip/deflate
    if ((opt.windowBits & 15) === 0) {
      opt.windowBits |= 15;
    }
  }

  this.err    = 0;      // error code, if happens (0 = Z_OK)
  this.msg    = '';     // error message
  this.ended  = false;  // used to avoid multiple onEnd() calls
  this.chunks = [];     // chunks of compressed data

  this.strm   = new ZStream();
  this.strm.avail_out = 0;

  var status  = zlib_inflate.inflateInit2(
    this.strm,
    opt.windowBits
  );

  if (status !== c.Z_OK) {
    throw new Error(msg[status]);
  }

  this.header = new GZheader();

  zlib_inflate.inflateGetHeader(this.strm, this.header);

  // Setup dictionary
  if (opt.dictionary) {
    // Convert data if needed
    if (typeof opt.dictionary === 'string') {
      opt.dictionary = strings.string2buf(opt.dictionary);
    } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
      opt.dictionary = new Uint8Array(opt.dictionary);
    }
    if (opt.raw) { //In raw mode we need to set the dictionary early
      status = zlib_inflate.inflateSetDictionary(this.strm, opt.dictionary);
      if (status !== c.Z_OK) {
        throw new Error(msg[status]);
      }
    }
  }
}
function Inflate ( options ) { if ( ! ( this instanceof Inflate ) ) return new Inflate ( options ) ; this . options = utils . assign ( { chunkSize : 16384 , windowBits : 0 , to : '' } , options || { } ) ; var opt = this . options ; // Force window size for `raw` data, if not set directly, // because we have no header for autodetect. if ( opt . raw && ( opt . windowBits >= 0 ) && ( opt . windowBits < 16 ) ) { opt . windowBits = - opt . windowBits ; if ( opt . windowBits === 0 ) { opt . windowBits = - 15 ; } } // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate if ( ( opt . windowBits >= 0 ) && ( opt . windowBits < 16 ) && ! ( options && options . windowBits ) ) { opt . windowBits += 32 ; } // Gzip header has no info about windows size, we can do autodetect only // for deflate. So, if window size not set, force it to max when gzip possible if ( ( opt . windowBits > 15 ) && ( opt . windowBits < 48 ) ) { // bit 3 (16) -> gzipped data // bit 4 (32) -> autodetect gzip/deflate if ( ( opt . windowBits & 15 ) === 0 ) { opt . windowBits |= 15 ; } } this . err = 0 ; // error code, if happens (0 = Z_OK) this . msg = '' ; // error message this . ended = false ; // used to avoid multiple onEnd() calls this . chunks = [ ] ; // chunks of compressed data this . strm = new ZStream ( ) ; this . strm . avail_out = 0 ; var status = zlib_inflate . inflateInit2 ( this . strm , opt . windowBits ) ; if ( status !== c . Z_OK ) { throw new Error ( msg [ status ] ) ; } this . header = new GZheader ( ) ; zlib_inflate . inflateGetHeader ( this . strm , this . header ) ; // Setup dictionary if ( opt . dictionary ) { // Convert data if needed if ( typeof opt . dictionary === 'string' ) { opt . dictionary = strings . string2buf ( opt . dictionary ) ; } else if ( toString . call ( opt . dictionary ) === '[object ArrayBuffer]' ) { opt . dictionary = new Uint8Array ( opt . dictionary ) ; } if ( opt . raw ) { //In raw mode we need to set the dictionary early status = zlib_inflate . inflateSetDictionary ( this . strm , opt . dictionary ) ; if ( status !== c . Z_OK ) { throw new Error ( msg [ status ] ) ; } } } }
Inflate.msg -> String

Error message, if [[Inflate.err]] != 0
 
new Inflate(options)
- options (Object): zlib inflate options.

Creates new inflator instance with specified params. Throws exception
on bad params. Supported options:

- `windowBits`
- `dictionary`

[http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
for more information on these.

Additional options, for internal needs:

- `chunkSize` - size of generated data chunks (16K by default)
- `raw` (Boolean) - do raw inflate
- `to` (String) - if equal to 'string', then result will be converted
from utf8 to utf16 (javascript) string. When string output requested,
chunk length can differ from `chunkSize`, depending on content.

By default, when no options set, autodetect deflate/gzip data format via
wrapper header.

##### Example:

```javascript
var pako = require('pako')
, chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
, chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);

var inflate = new pako.Inflate({ level: 3});

inflate.push(chunk1, false);
inflate.push(chunk2, true);  // true -> last chunk

if (inflate.err) { throw new Error(inflate.err); }

console.log(inflate.result);
```
Inflate . msg - > String