From 5370c1382d51ad586308a1fb9ac018ae3cbca82f Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Wed, 12 Mar 2014 02:46:29 +0400 Subject: [PATCH] Fixed bug in inflate options logic --- lib/inflate.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/inflate.js b/lib/inflate.js index 5b94154..9715e10 100644 --- a/lib/inflate.js +++ b/lib/inflate.js @@ -88,15 +88,23 @@ var Inflate = function(options) { this.options = utils.assign({ chunkSize: 16384, - windowBits: 15 + 32 // By default - autodetect deflate/gzip + windowBits: 15 }, options || {}); var opt = this.options; - if (opt.raw && (opt.windowBits > 0)) { + // check `raw` if `windowBits` NOT defined directly, + // or we will get bug because of autodetect + if (opt.raw && (opt.windowBits > 0) && (opt.windowBits < 16)) { opt.windowBits = -opt.windowBits; } + // 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; + } + this.err = 0; // error code, if happens (0 = Z_OK) this.msg = ''; // error message this.ended = false; // used to avoid multiple onEnd() calls