diff --git a/lib/inflate.js b/lib/inflate.js index 808dfc3..0ed4999 100644 --- a/lib/inflate.js +++ b/lib/inflate.js @@ -180,6 +180,7 @@ Inflate.prototype.push = function (data, mode) { var dictionary = this.options.dictionary; var status, _mode; var next_out_utf8, tail, utf8str; + var dict; // Flag to properly process Z_BUF_ERROR on testing inflate call // when we check that all output data was flushed. @@ -211,8 +212,6 @@ Inflate.prototype.push = function (data, mode) { status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH); /* no bad return value */ if (status === c.Z_NEED_DICT && dictionary) { - var dict; - // Convert data if needed if (typeof dictionary === 'string') { dict = strings.string2buf(dictionary); diff --git a/lib/zlib/deflate.js b/lib/zlib/deflate.js index 953a804..dce5a4d 100644 --- a/lib/zlib/deflate.js +++ b/lib/zlib/deflate.js @@ -1739,13 +1739,6 @@ function deflateEnd(strm) { return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK; } -/* ========================================================================= - * Copy the source state to the destination state - */ -//function deflateCopy(dest, source) { -// -//} - /* ========================================================================= * Initializes the compression dictionary from the given byte @@ -1760,6 +1753,7 @@ function deflateSetDictionary(strm, dictionary) { var avail; var next; var input; + var tmpDict; if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) { return Z_STREAM_ERROR; @@ -1791,7 +1785,7 @@ function deflateSetDictionary(strm, dictionary) { } /* use the tail */ // dictionary = dictionary.slice(dictLength - s.w_size); - var tmpDict = new utils.Buf8(s.w_size); + tmpDict = new utils.Buf8(s.w_size); utils.arraySet(tmpDict, dictionary, dictLength - s.w_size, s.w_size, 0); dictionary = tmpDict; dictLength = s.w_size; @@ -1841,8 +1835,8 @@ exports.deflateResetKeep = deflateResetKeep; exports.deflateSetHeader = deflateSetHeader; exports.deflate = deflate; exports.deflateEnd = deflateEnd; -exports.deflateInfo = 'pako deflate (from Nodeca project)'; exports.deflateSetDictionary = deflateSetDictionary; +exports.deflateInfo = 'pako deflate (from Nodeca project)'; /* Not implemented exports.deflateBound = deflateBound; diff --git a/lib/zlib/inflate.js b/lib/zlib/inflate.js index 972f05e..3be8b62 100644 --- a/lib/zlib/inflate.js +++ b/lib/zlib/inflate.js @@ -1524,8 +1524,8 @@ exports.inflateInit2 = inflateInit2; exports.inflate = inflate; exports.inflateEnd = inflateEnd; exports.inflateGetHeader = inflateGetHeader; -exports.inflateInfo = 'pako inflate (from Nodeca project)'; exports.inflateSetDictionary = inflateSetDictionary; +exports.inflateInfo = 'pako inflate (from Nodeca project)'; /* Not implemented exports.inflateCopy = inflateCopy; diff --git a/test/deflate.js b/test/deflate.js index 5bb15d2..4a8fb51 100644 --- a/test/deflate.js +++ b/test/deflate.js @@ -171,14 +171,18 @@ describe('Deflate RAW', function () { }); + describe('Deflate dictionary', function () { + it('trivial dictionary', function (done) { var dict = new Buffer('abcdefghijklmnoprstuvwxyz'); testSamples(zlib.createDeflate, pako.deflate, samples, { dictionary: dict }, done); }); it('spdy dictionary', function (done) { - testSamples(zlib.createDeflate, pako.deflate, samples, { dictionary: helpers.spdyDict }, done); + var spdyDict = require('fs').readFileSync(require('path').join(__dirname, 'fixtures', 'spdy_dict.txt')); + + testSamples(zlib.createDeflate, pako.deflate, samples, { dictionary: spdyDict }, done); }); it('handles multiple pushes', function () { diff --git a/test/helpers.js b/test/helpers.js index 8626009..e4e72c1 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -165,11 +165,8 @@ function testInflate(samples, inflateOptions, deflateOptions, callback) { callback(); } -var spdyDict = new Buffer(fs.readFileSync(path.join(__dirname, 'fixtures', 'spdy_dict.txt'))); - exports.cmpBuf = cmpBuf; exports.testSamples = testSamples; exports.testInflate = testInflate; exports.loadSamples = loadSamples; -exports.spdyDict = spdyDict; diff --git a/test/inflate.js b/test/inflate.js index d755a4e..7d50041 100644 --- a/test/inflate.js +++ b/test/inflate.js @@ -163,7 +163,9 @@ describe('Inflate RAW', function () { }); + describe('Inflate with dictionary', function () { + it('should throw on the wrong dictionary', function () { // var zCompressed = helpers.deflateSync('world', { dictionary: new Buffer('hello') }); var zCompressed = new Buffer([ 120, 187, 6, 44, 2, 21, 43, 207, 47, 202, 73, 1, 0, 6, 166, 2, 41 ]); @@ -187,7 +189,9 @@ describe('Inflate with dictionary', function () { }); it('spdy dictionary', function (done) { - testInflate(samples, { dictionary: helpers.spdyDict }, { dictionary: helpers.spdyDict }, done); + var spdyDict = require('fs').readFileSync(require('path').join(__dirname, 'fixtures', 'spdy_dict.txt')); + + testInflate(samples, { dictionary: spdyDict }, { dictionary: helpers.spdyDict }, done); }); });