mirror of
https://github.com/0x5eal/rbxts-pako.git
synced 2025-04-09 05:10:59 +01:00
Autodetect inflate window size by default
This commit is contained in:
parent
dfe21c62da
commit
b3ff0b746e
3 changed files with 17 additions and 9 deletions
|
@ -89,19 +89,20 @@ var Inflate = function(options) {
|
|||
|
||||
this.options = utils.assign({
|
||||
chunkSize: 16384,
|
||||
windowBits: 15
|
||||
windowBits: 0
|
||||
}, options || {});
|
||||
|
||||
var opt = this.options;
|
||||
|
||||
// check `raw` if `windowBits` NOT defined directly,
|
||||
// or we will get bug because of autodetect
|
||||
if (opt.raw && (opt.windowBits > 0) && (opt.windowBits < 16)) {
|
||||
if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
|
||||
opt.windowBits = -opt.windowBits;
|
||||
if (opt.windowBits === 0) { opt.windowBits = -15; }
|
||||
}
|
||||
|
||||
// If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
|
||||
if ((opt.windowBits > 0) && (opt.windowBits < 16) &&
|
||||
if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&
|
||||
!(options && options.windowBits)) {
|
||||
opt.windowBits += 32;
|
||||
}
|
||||
|
|
|
@ -131,7 +131,14 @@ function testDeflate(zlib_factory, pako_deflate, samples, options, callback) {
|
|||
|
||||
|
||||
function testInflate(samples, options, callback) {
|
||||
var name, data, deflated, inflated;
|
||||
var name, data, deflated, inflated, inflate_options;
|
||||
|
||||
// inflate options have windowBits = 0 to force autodetect window size
|
||||
//
|
||||
inflate_options = pako_utils.assign({}, options);
|
||||
if (inflate_options.windowBits > 0 && inflate_options.windowBits < 16) {
|
||||
inflate_options.windowBits = 0;
|
||||
}
|
||||
|
||||
for (name in samples) {
|
||||
data = samples[name];
|
||||
|
@ -139,7 +146,7 @@ function testInflate(samples, options, callback) {
|
|||
|
||||
// with untyped arrays
|
||||
pako_utils.forceUntyped = true;
|
||||
inflated = pako.inflate(deflated, options);
|
||||
inflated = pako.inflate(deflated, inflate_options);
|
||||
pako_utils.forceUntyped = false;
|
||||
|
||||
if (!cmpBuf(inflated, data)) {
|
||||
|
@ -148,7 +155,7 @@ function testInflate(samples, options, callback) {
|
|||
}
|
||||
|
||||
// with typed arrays
|
||||
inflated = pako.inflate(deflated, options);
|
||||
inflated = pako.inflate(deflated, inflate_options);
|
||||
|
||||
if (!cmpBuf(inflated, data)) {
|
||||
callback('Error in "' + name + '" - inflate result != original');
|
||||
|
|
|
@ -30,11 +30,11 @@ describe('Inflate ungzip', function () {
|
|||
var gzipped = pako.gzip(samples.lorem_cat);
|
||||
|
||||
it.skip('ungzip with autodetect', function(done) {
|
||||
done(helpers.cmp(orig, pako.inflate(gzipped).result));
|
||||
done(helpers.cmp(orig, pako.inflate(gzipped)));
|
||||
});
|
||||
|
||||
it.skip('ungzip with method set directly', function(done) {
|
||||
done(helpers.cmp(orig, pako.inflate(gzipped, { windowBits: 15 + 16 }).result));
|
||||
done(helpers.cmp(orig, pako.inflate(gzipped, { windowBits: 15 + 16 })));
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -99,7 +99,7 @@ describe('Inflate windowBits', function () {
|
|||
it('windowBits 9', function(done) {
|
||||
testInflate(samples, { windowBits: 9 }, done);
|
||||
});
|
||||
it.skip('windowBits 8', function(done) {
|
||||
it('windowBits 8', function(done) {
|
||||
testInflate(samples, { windowBits: 8 }, done);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue