From 07173737fc3fe6ab1336f44e50623b37b68b5ba8 Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Fri, 14 Mar 2014 00:58:09 +0400 Subject: [PATCH] Fixed ungzip: force window size when not set, because autodetect impossible --- lib/inflate.js | 10 ++++++++++ test/inflate.js | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/inflate.js b/lib/inflate.js index 662ad7b..23a6753 100644 --- a/lib/inflate.js +++ b/lib/inflate.js @@ -100,6 +100,16 @@ var Inflate = function(options) { 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 diff --git a/test/inflate.js b/test/inflate.js index 90282dd..94cfac3 100644 --- a/test/inflate.js +++ b/test/inflate.js @@ -28,12 +28,12 @@ describe('Inflate ungzip', function () { // TODO: Investigate, why ungzip does not autodetect window size and // require to set windowBits directly - it.skip('with autodetect', function(done) { + it('with autodetect', function(done) { testInflate(samples, {}, { gzip: true }, done); }); it('with method set directly', function(done) { - testInflate(samples, { windowBits: 15 + 16 }, { gzip: true }, done); + testInflate(samples, { windowBits: 16 }, { gzip: true }, done); }); });