files rename/cleanup (+ dropped inflatePrime method)

This commit is contained in:
Vitaly Puzrin 2014-04-10 07:06:04 +04:00
parent 471505d113
commit 195e40c0df
3 changed files with 38 additions and 48 deletions

View file

@ -256,22 +256,6 @@ function inflateInit(strm) {
return inflateInit2(strm, DEF_WBITS); return inflateInit2(strm, DEF_WBITS);
} }
function inflatePrime(strm, bits, value) {
var state;
if (!strm || !strm.state) { return Z_STREAM_ERROR; }
state = strm.state;
if (bits < 0) {
state.hold = 0;
state.bits = 0;
return Z_OK;
}
if (bits > 16 || state.bits + bits > 32) { return Z_STREAM_ERROR; }
value &= (1 << bits) - 1;
state.hold += value << state.bits;
state.bits += bits;
return Z_OK;
}
/* /*
Return state with length and distance decoding tables and index sizes set to Return state with length and distance decoding tables and index sizes set to
@ -406,10 +390,10 @@ function inflate(strm, flush) {
[16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
// TODO: check if needed and don't affect speed if (!strm || !strm.state || !strm.next_out ||
//if (strm === Z_NULL || strm.state === Z_NULL || strm.next_out === Z_NULL || (!strm.next_in && strm.avail_in !== 0)) {
// (strm.next_in === Z_NULL && strm.avail_in !== 0)) return Z_STREAM_ERROR;
// return Z_STREAM_ERROR; }
state = strm.state; state = strm.state;
if (state.mode === TYPE) { state.mode = TYPEDO; } /* skip check */ if (state.mode === TYPE) { state.mode = TYPEDO; } /* skip check */
@ -1463,8 +1447,11 @@ function inflate(strm, flush) {
} }
function inflateEnd(strm) { function inflateEnd(strm) {
// if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
// return Z_STREAM_ERROR; if (!strm || !strm.state /*|| strm->zfree == (free_func)0*/) {
return Z_STREAM_ERROR;
}
var state = strm.state; var state = strm.state;
if (state.window) { if (state.window) {
state.window = null; state.window = null;
@ -1493,7 +1480,6 @@ exports.inflateReset2 = inflateReset2;
exports.inflateResetKeep = inflateResetKeep; exports.inflateResetKeep = inflateResetKeep;
exports.inflateInit = inflateInit; exports.inflateInit = inflateInit;
exports.inflateInit2 = inflateInit2; exports.inflateInit2 = inflateInit2;
exports.inflatePrime = inflatePrime;
exports.inflate = inflate; exports.inflate = inflate;
exports.inflateEnd = inflateEnd; exports.inflateEnd = inflateEnd;
exports.inflateGetHeader = inflateGetHeader; exports.inflateGetHeader = inflateGetHeader;
@ -1507,4 +1493,5 @@ exports.inflateSyncPoint = inflateSyncPoint;
exports.inflateCopy = inflateCopy; exports.inflateCopy = inflateCopy;
exports.inflateUndermine = inflateUndermine; exports.inflateUndermine = inflateUndermine;
exports.inflateMark = inflateMark; exports.inflateMark = inflateMark;
exports.inflatePrime = inflatePrime;
*/ */

View file

@ -17,8 +17,9 @@ function a2s(array) {
} }
describe('Inflate gzip header', function() { describe('Gzip special cases', function() {
it('Check headers content from prepared file', function() {
it('Read custom headers', function() {
var data = fs.readFileSync(path.join(__dirname, 'fixtures/gzip-headers.gz')); var data = fs.readFileSync(path.join(__dirname, 'fixtures/gzip-headers.gz'));
var inflator = new pako.Inflate(); var inflator = new pako.Inflate();
inflator.push(data, true); inflator.push(data, true);
@ -27,10 +28,8 @@ describe('Inflate gzip header', function() {
assert.equal(inflator.header.comment, 'test comment'); assert.equal(inflator.header.comment, 'test comment');
assert.equal(a2s(inflator.header.extra), 'test extra'); assert.equal(a2s(inflator.header.extra), 'test extra');
}); });
});
describe('Inflate gzip joined', function() { it('Read stream with SYNC marks', function() {
it('Check content from prepared file', function() {
var inflator, strm, _in, len, pos = 0, i = 0; var inflator, strm, _in, len, pos = 0, i = 0;
var data = fs.readFileSync(path.join(__dirname, 'fixtures/gzip-joined.gz')); var data = fs.readFileSync(path.join(__dirname, 'fixtures/gzip-joined.gz'));
@ -51,4 +50,5 @@ describe('Inflate gzip joined', function() {
assert(i === 2, 'invalid blobs count'); assert(i === 2, 'invalid blobs count');
}); });
}); });

View file

@ -1,3 +1,5 @@
// This tests are ported from original zlib
/*global describe, it*/ /*global describe, it*/
@ -8,7 +10,7 @@ var assert = require('assert');
var c = require('../lib/zlib/constants'); var c = require('../lib/zlib/constants');
var msg = require('../lib/zlib/messages'); var msg = require('../lib/zlib/messages');
var zlib_stream = require('../lib/zlib/zstream'); //var zlib_stream = require('../lib/zlib/zstream');
var zlib_inflate = require('../lib/zlib/inflate.js'); var zlib_inflate = require('../lib/zlib/inflate.js');
var inflate_table = require('../lib/zlib/inftrees'); var inflate_table = require('../lib/zlib/inftrees');
@ -36,20 +38,20 @@ function testInflate(hex, wbits, status) {
describe('Inflate states', function() { describe('Inflate states', function() {
// //in port checking input parameters was removed //in port checking input parameters was removed
// it.skip('inflate bad parameters', function() { it('inflate bad parameters', function() {
// var ret; var ret;
//
// ret = zlib_inflate.inflate(null, 0); ret = zlib_inflate.inflate(null, 0);
// assert(ret == c.Z_STREAM_ERROR); assert(ret === c.Z_STREAM_ERROR);
//
// ret = zlib_inflate.inflateEnd(null); ret = zlib_inflate.inflateEnd(null);
// assert(ret == c.Z_STREAM_ERROR); assert(ret === c.Z_STREAM_ERROR);
//
// //skip: inflateCopy is not implemented //skip: inflateCopy is not implemented
// //ret = zlib_inflate.inflateCopy(null, null); //ret = zlib_inflate.inflateCopy(null, null);
// //assert(ret == c.Z_STREAM_ERROR); //assert(ret == c.Z_STREAM_ERROR);
// }); });
it('bad gzip method', function() { it('bad gzip method', function() {
testInflate('1f 8b 0 0', 31, c.Z_DATA_ERROR); testInflate('1f 8b 0 0', 31, c.Z_DATA_ERROR);
}); });
@ -203,7 +205,8 @@ describe('Inflate fast', function() {
}); });
describe('Inflate support', function() { describe('Inflate support', function() {
it('prime', function() { // `inflatePrime` not implemented
/*it('prime', function() {
var ret; var ret;
var strm = new zlib_stream(); var strm = new zlib_stream();
strm.avail_in = 0; strm.avail_in = 0;
@ -218,13 +221,13 @@ describe('Inflate support', function() {
ret = zlib_inflate.inflatePrime(strm, -1, 0); ret = zlib_inflate.inflatePrime(strm, -1, 0);
assert(ret === c.Z_OK); assert(ret === c.Z_OK);
// skipped: inflateSetDictionary is not implemented // `inflateSetDictionary` not implemented
// ret = inflateSetDictionary(strm, null, 0); // ret = zlib_inflate.inflateSetDictionary(strm, null, 0);
// assert(ret === c.Z_STREAM_ERROR); // assert(ret === c.Z_STREAM_ERROR);
ret = zlib_inflate.inflateEnd(strm); ret = zlib_inflate.inflateEnd(strm);
assert(ret === c.Z_OK); assert(ret === c.Z_OK);
}); });*/
it('force window allocation', function() { it('force window allocation', function() {
testInflate('63 0', -15, c.Z_OK); testInflate('63 0', -15, c.Z_OK);
}); });