From 3f30aa82508074fbad1ce7dad0c17796937b927e Mon Sep 17 00:00:00 2001
From: nik <andrew.tupitsin@gmail.com>
Date: Thu, 13 Mar 2014 12:54:03 -0300
Subject: [PATCH] fix inflate data check & enable inflate ungzip test with
 method set directly

---
 lib/zlib/inflate.js |  2 +-
 test/helpers.js     |  4 ++--
 test/inflate.js     | 12 ++++--------
 3 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/lib/zlib/inflate.js b/lib/zlib/inflate.js
index 28ac423..3d4a740 100644
--- a/lib/zlib/inflate.js
+++ b/lib/zlib/inflate.js
@@ -1371,7 +1371,7 @@ function inflate(strm, flush) {
 
         }
         _out = left;
-        if ((state.flags ? hold : ZSWAP32(hold)) !== state.check) {
+        if ((state.flags ? hold : ZSWAP32(hold) >>> 0) !== state.check >>> 0) {
           strm.msg = 'incorrect data check';
           state.mode = BAD;
           break;
diff --git a/test/helpers.js b/test/helpers.js
index 29e0138..90c346a 100644
--- a/test/helpers.js
+++ b/test/helpers.js
@@ -130,7 +130,7 @@ function testDeflate(zlib_factory, pako_deflate, samples, options, callback) {
 }
 
 
-function testInflate(samples, options, callback) {
+function testInflate(samples, options, callback, is_gzip) {
   var name, data, deflated, inflated, inflate_options;
 
   // inflate options have windowBits = 0 to force autodetect window size
@@ -142,7 +142,7 @@ function testInflate(samples, options, callback) {
 
   for (name in samples) {
     data = samples[name];
-    deflated = pako.deflate(data, options);
+    deflated = is_gzip ? pako.gzip(data, options) : pako.deflate(data, options);
 
     // with untyped arrays
     pako_utils.setTyped(false);
diff --git a/test/inflate.js b/test/inflate.js
index 9a18311..59e1345 100644
--- a/test/inflate.js
+++ b/test/inflate.js
@@ -6,7 +6,6 @@
 
 var helpers = require('./helpers');
 var testInflate = helpers.testInflate;
-var pako  = require('../index');
 
 
 var samples = helpers.loadSamples();
@@ -26,15 +25,12 @@ describe('Inflate defaults', function () {
 
 
 describe('Inflate ungzip', function () {
-  var orig = samples.lorem_cat;
-  var gzipped = pako.gzip(samples.lorem_cat);
-
-  it.skip('ungzip with autodetect', function(done) {
-    done(helpers.cmp(orig, pako.inflate(gzipped)));
+  it.skip('with autodetect', function(done) {
+    testInflate(samples, {}, done, true);
   });
 
-  it.skip('ungzip with method set directly', function(done) {
-    done(helpers.cmp(orig, pako.inflate(gzipped, { windowBits: 15 + 16 })));
+  it('with method set directly', function(done) {
+    testInflate(samples, { windowBits: 15 + 16 }, done, true);
   });
 
 });