remove codes table variable & add switching between fixed and dynamic tables for inflate, issue #22

master
nik 2014-04-30 19:37:17 -03:00
rodzic 57a80d98cf
commit 4e16144fad
2 zmienionych plików z 15 dodań i 11 usunięć

Wyświetl plik

@ -85,7 +85,7 @@ var SYNC = 32; /* looking for synchronization bytes to restart inflate()
var ENOUGH_LENS = 852;
var ENOUGH_DISTS = 592;
var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
var MAX_WBITS = 15;
/* 32K LZ77 window */
@ -143,12 +143,16 @@ function InflateState() {
this.have = 0; /* number of code lengths in lens[] */
this.next = null; /* next available space in codes[] */
//unsigned short array
//todo: test later with Uint16Array
this.lens = new utils.Buf16(320); /* temporary storage for code lengths */
this.work = new utils.Buf16(288); /* work area for code table building */
this.codes = new utils.Buf32(ENOUGH); /* space for code tables */
/*
because we don't have pointers in js, we use lencode and distcode directly
as buffers so we don't need codes
*/
//this.codes = new utils.Buf32(ENOUGH); /* space for code tables */
this.lendyn = null; /* dynamic table for length/literal codes (JS specific) */
this.distdyn = null; /* dynamic table for distance codes (JS specific) */
this.sane = 0; /* if false, allow invalid distance too far */
this.back = 0; /* bits back of last unprocessed length/lit */
this.was = 0; /* initial length of match */
@ -172,8 +176,8 @@ function inflateResetKeep(strm) {
state.hold = 0;
state.bits = 0;
//state.lencode = state.distcode = state.next = state.codes;
state.lencode = new utils.Buf32(ENOUGH);
state.distcode = new utils.Buf32(ENOUGH);
state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS);
state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS);
state.sane = 1;
state.back = -1;
@ -907,7 +911,8 @@ function inflate(strm, flush) {
// We have separate tables & no pointers. 2 commented lines below not needed.
//state.next = state.codes;
//state.lencode = state.next;
utils.arraySet(state.lencode, state.codes, 0, state.codes.length, 0);
// Switch to use dynamic table
state.lencode = state.lendyn;
state.lenbits = 7;
opts = {bits: state.lenbits};
@ -1039,8 +1044,6 @@ function inflate(strm, flush) {
/* build code tables -- note: do not change the lenbits or distbits
values here (9 and 6) without reading the comments in inftrees.h
concerning the ENOUGH constants, which depend on those values */
//state.lencode.copy(state.codes);
utils.arraySet(state.lencode, state.codes, 0, state.codes.length, 0);
state.lenbits = 9;
opts = {bits: state.lenbits};
@ -1058,7 +1061,8 @@ function inflate(strm, flush) {
state.distbits = 6;
//state.distcode.copy(state.codes);
utils.arraySet(state.distcode, state.codes, 0, state.codes.length, 0);
// Switch to use dynamic table
state.distcode = state.distdyn;
opts = {bits: state.distbits};
ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);
// We have separate tables & no pointers. 2 commented lines below not needed.

Wyświetl plik

@ -24,7 +24,7 @@ describe('Inflate defaults', function () {
testInflate(samples, { raw: true }, { raw: true }, done);
});
it.skip('inflate raw from compressed samples', function(done) {
it('inflate raw from compressed samples', function(done) {
var compressed_samples = helpers.loadSamples('samples_deflated_raw');
helpers.testSamples(zlib.createInflateRaw, pako.inflateRaw, compressed_samples, {}, done);
});