mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-10 22:00:58 +01:00
minor code cleanup
This commit is contained in:
parent
b40c7cd0ab
commit
d884686332
6 changed files with 15 additions and 17 deletions
|
@ -180,6 +180,7 @@ Inflate.prototype.push = function (data, mode) {
|
||||||
var dictionary = this.options.dictionary;
|
var dictionary = this.options.dictionary;
|
||||||
var status, _mode;
|
var status, _mode;
|
||||||
var next_out_utf8, tail, utf8str;
|
var next_out_utf8, tail, utf8str;
|
||||||
|
var dict;
|
||||||
|
|
||||||
// Flag to properly process Z_BUF_ERROR on testing inflate call
|
// Flag to properly process Z_BUF_ERROR on testing inflate call
|
||||||
// when we check that all output data was flushed.
|
// 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 */
|
status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH); /* no bad return value */
|
||||||
|
|
||||||
if (status === c.Z_NEED_DICT && dictionary) {
|
if (status === c.Z_NEED_DICT && dictionary) {
|
||||||
var dict;
|
|
||||||
|
|
||||||
// Convert data if needed
|
// Convert data if needed
|
||||||
if (typeof dictionary === 'string') {
|
if (typeof dictionary === 'string') {
|
||||||
dict = strings.string2buf(dictionary);
|
dict = strings.string2buf(dictionary);
|
||||||
|
|
|
@ -1739,13 +1739,6 @@ function deflateEnd(strm) {
|
||||||
return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;
|
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
|
* Initializes the compression dictionary from the given byte
|
||||||
|
@ -1760,6 +1753,7 @@ function deflateSetDictionary(strm, dictionary) {
|
||||||
var avail;
|
var avail;
|
||||||
var next;
|
var next;
|
||||||
var input;
|
var input;
|
||||||
|
var tmpDict;
|
||||||
|
|
||||||
if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {
|
if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {
|
||||||
return Z_STREAM_ERROR;
|
return Z_STREAM_ERROR;
|
||||||
|
@ -1791,7 +1785,7 @@ function deflateSetDictionary(strm, dictionary) {
|
||||||
}
|
}
|
||||||
/* use the tail */
|
/* use the tail */
|
||||||
// dictionary = dictionary.slice(dictLength - s.w_size);
|
// 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);
|
utils.arraySet(tmpDict, dictionary, dictLength - s.w_size, s.w_size, 0);
|
||||||
dictionary = tmpDict;
|
dictionary = tmpDict;
|
||||||
dictLength = s.w_size;
|
dictLength = s.w_size;
|
||||||
|
@ -1841,8 +1835,8 @@ exports.deflateResetKeep = deflateResetKeep;
|
||||||
exports.deflateSetHeader = deflateSetHeader;
|
exports.deflateSetHeader = deflateSetHeader;
|
||||||
exports.deflate = deflate;
|
exports.deflate = deflate;
|
||||||
exports.deflateEnd = deflateEnd;
|
exports.deflateEnd = deflateEnd;
|
||||||
exports.deflateInfo = 'pako deflate (from Nodeca project)';
|
|
||||||
exports.deflateSetDictionary = deflateSetDictionary;
|
exports.deflateSetDictionary = deflateSetDictionary;
|
||||||
|
exports.deflateInfo = 'pako deflate (from Nodeca project)';
|
||||||
|
|
||||||
/* Not implemented
|
/* Not implemented
|
||||||
exports.deflateBound = deflateBound;
|
exports.deflateBound = deflateBound;
|
||||||
|
|
|
@ -1524,8 +1524,8 @@ exports.inflateInit2 = inflateInit2;
|
||||||
exports.inflate = inflate;
|
exports.inflate = inflate;
|
||||||
exports.inflateEnd = inflateEnd;
|
exports.inflateEnd = inflateEnd;
|
||||||
exports.inflateGetHeader = inflateGetHeader;
|
exports.inflateGetHeader = inflateGetHeader;
|
||||||
exports.inflateInfo = 'pako inflate (from Nodeca project)';
|
|
||||||
exports.inflateSetDictionary = inflateSetDictionary;
|
exports.inflateSetDictionary = inflateSetDictionary;
|
||||||
|
exports.inflateInfo = 'pako inflate (from Nodeca project)';
|
||||||
|
|
||||||
/* Not implemented
|
/* Not implemented
|
||||||
exports.inflateCopy = inflateCopy;
|
exports.inflateCopy = inflateCopy;
|
||||||
|
|
|
@ -171,14 +171,18 @@ describe('Deflate RAW', function () {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('Deflate dictionary', function () {
|
describe('Deflate dictionary', function () {
|
||||||
|
|
||||||
it('trivial dictionary', function (done) {
|
it('trivial dictionary', function (done) {
|
||||||
var dict = new Buffer('abcdefghijklmnoprstuvwxyz');
|
var dict = new Buffer('abcdefghijklmnoprstuvwxyz');
|
||||||
testSamples(zlib.createDeflate, pako.deflate, samples, { dictionary: dict }, done);
|
testSamples(zlib.createDeflate, pako.deflate, samples, { dictionary: dict }, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('spdy dictionary', function (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 () {
|
it('handles multiple pushes', function () {
|
||||||
|
|
|
@ -165,11 +165,8 @@ function testInflate(samples, inflateOptions, deflateOptions, callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
var spdyDict = new Buffer(fs.readFileSync(path.join(__dirname, 'fixtures', 'spdy_dict.txt')));
|
|
||||||
|
|
||||||
|
|
||||||
exports.cmpBuf = cmpBuf;
|
exports.cmpBuf = cmpBuf;
|
||||||
exports.testSamples = testSamples;
|
exports.testSamples = testSamples;
|
||||||
exports.testInflate = testInflate;
|
exports.testInflate = testInflate;
|
||||||
exports.loadSamples = loadSamples;
|
exports.loadSamples = loadSamples;
|
||||||
exports.spdyDict = spdyDict;
|
|
||||||
|
|
|
@ -163,7 +163,9 @@ describe('Inflate RAW', function () {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('Inflate with dictionary', function () {
|
describe('Inflate with dictionary', function () {
|
||||||
|
|
||||||
it('should throw on the wrong dictionary', function () {
|
it('should throw on the wrong dictionary', function () {
|
||||||
// var zCompressed = helpers.deflateSync('world', { dictionary: new Buffer('hello') });
|
// 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 ]);
|
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) {
|
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);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue