diff --git a/.gitignore b/.gitignore index 8681871..e1cfe81 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /doc /node_modules/ +/coverage + diff --git a/.jshintignore b/.jshintignore index 6264b72..265b534 100644 --- a/.jshintignore +++ b/.jshintignore @@ -1,3 +1,4 @@ .git/ node_modules/ benchmark/implementations +coverage/ diff --git a/.npmignore b/.npmignore index 35ac5e1..9804234 100644 --- a/.npmignore +++ b/.npmignore @@ -1,5 +1,6 @@ -/banchmark/ +/benchmark/ /test/ +/coverage/ /.* /Makefile diff --git a/Makefile b/Makefile index 3a92167..8c91cc5 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,9 @@ test: lint fi mocha +cover: + rm -rf cover + istanbul cover node_modules/.bin/_mocha -- -t 30000 -R spec doc: @if test ! `which ndoc` ; then \ diff --git a/lib/deflate.js b/lib/deflate.js index 96db340..b4196aa 100644 --- a/lib/deflate.js +++ b/lib/deflate.js @@ -93,7 +93,7 @@ function sliceBuf(buf, size) { var Deflate = function(options) { this.options = utils.assign({ - level: 6, + level: c.Z_DEFAULT_COMPRESSION, method: c.Z_DEFLATED, chunkSize: 16384, windowBits: 15, diff --git a/lib/zlib/deflate.js b/lib/zlib/deflate.js index 28f30c1..9dc9a5f 100644 --- a/lib/zlib/deflate.js +++ b/lib/zlib/deflate.js @@ -1206,14 +1206,16 @@ function DeflateState() { } function deflateResetKeep(strm) { - strm.total_in = strm.total_out = 0; - strm.data_type = c.Z_UNKNOWN; + var s; if (!strm || !strm.state) { return c.Z_STREAM_ERROR; } - var s = strm.state; + strm.total_in = strm.total_out = 0; + strm.data_type = c.Z_UNKNOWN; + + s = strm.state; s.pending = 0; s.pending_out = 0; diff --git a/lib/zlib/zstream.js b/lib/zlib/zstream.js index 32252ce..2b5f7ee 100644 --- a/lib/zlib/zstream.js +++ b/lib/zlib/zstream.js @@ -19,7 +19,7 @@ function ZStream() { /* not visible by applications */ this.state = null; /* best guess about the data type: binary or text */ - this.data_type = 2; + this.data_type = 2/*Z_UNKNOWN*/; /* adler32 value of the uncompressed data */ this.adler = 0; } diff --git a/test/deflate.js b/test/deflate.js index 73817b1..f4b7a2b 100644 --- a/test/deflate.js +++ b/test/deflate.js @@ -64,7 +64,9 @@ describe('Deflate levels', function () { it('level 0', function(done) { testDeflate(zlib.createDeflate, pako.deflate, samples, { level: 0 }, done); }); - + it('level -1 (implicit default)', function(done) { + testDeflate(zlib.createDeflate, pako.deflate, samples, { level: 0 }, done); + }); }); @@ -94,6 +96,9 @@ describe('Deflate windowBits', function () { it('windowBits 8', function(done) { testDeflate(zlib.createDeflate, pako.deflate, samples, { windowBits: 8 }, done); }); + it('windowBits -15 (implicit raw)', function(done) { + testDeflate(zlib.createDeflateRaw, pako.deflate, samples, { windowBits: -15 }, done); + }); }); diff --git a/test/helpers.js b/test/helpers.js index 87bf4e0..177dbfb 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -54,7 +54,12 @@ function cmpBuf(a, b) { // function testDeflateSingle(zlib_factory, pako_deflate, data, options, callback) { - var zlibStream = zlib_factory(options); + var zlib_options = _.clone(options); + + // hack for testing negative windowBits + if (zlib_options.windowBits < 0) { zlib_options.windowBits = -zlib_options.windowBits; } + + var zlibStream = zlib_factory(zlib_options); var buffers = [], nread = 0;