1 Clazz.declarePackage ("JU");
2 Clazz.load (["JU.InfTree"], "JU.InfBlocks", ["JU.InfCodes"], function () {
3 c$ = Clazz.decorateAsClass (function () {
29 Clazz.instantialize (this, arguments);
31 Clazz.prepareFields (c$, function () {
32 this.bb = Clazz.newIntArray (1, 0);
33 this.tb = Clazz.newIntArray (1, 0);
34 this.bl = Clazz.newIntArray (1, 0);
35 this.bd = Clazz.newIntArray (1, 0);
36 this.tli = Clazz.newIntArray (1, 0);
37 this.tdi = Clazz.newIntArray (1, 0);
38 this.inftree = new JU.InfTree ();
40 Clazz.makeConstructor (c$,
43 this.codes = new JU.InfCodes (this.z, this);
44 this.hufts = Clazz.newIntArray (4320, 0);
45 this.window = Clazz.newByteArray (w, 0);
47 this.check = (z.istate.wrap == 0) ? false : true;
50 this.tl = Clazz.newArray(1, null);
51 this.td = Clazz.newArray(1, null);
54 Clazz.defineMethod (c$, "reset",
57 this.codes.free (this.z);
61 this.read = this.write = 0;
63 this.z.checksum.reset ();
65 Clazz.defineMethod (c$, "proc",
75 p = this.z.next_in_index;
81 m = (q < this.read ? this.read - q - 1 : this.end - q);
92 this.z.total_in += p - this.z.next_in_index;
93 this.z.next_in_index = p;
95 return this.inflate_flush (r);
97 b |= (this.z.next_in[p++] & 0xff) << k;
114 JU.InfTree.inflate_trees_fixed (this.bl, this.bd, this.tl, this.td, this.z);
115 this.codes.init (this.bl[0], this.bd[0], this.tl[0], 0, this.td[0], 0);
132 this.z.msg = "invalid block type";
137 this.z.total_in += p - this.z.next_in_index;
138 this.z.next_in_index = p;
140 return this.inflate_flush (r);
151 this.z.total_in += p - this.z.next_in_index;
152 this.z.next_in_index = p;
154 return this.inflate_flush (r);
156 b |= (this.z.next_in[p++] & 0xff) << k;
159 if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)) {
161 this.z.msg = "invalid stored block lengths";
166 this.z.total_in += p - this.z.next_in_index;
167 this.z.next_in_index = p;
169 return this.inflate_flush (r);
170 }this.left = (b & 0xffff);
172 this.mode = this.left != 0 ? 2 : (this.last != 0 ? 7 : 0);
179 this.z.total_in += p - this.z.next_in_index;
180 this.z.next_in_index = p;
182 return this.inflate_flush (r);
184 if (q == this.end && this.read != 0) {
186 m = (q < this.read ? this.read - q - 1 : this.end - q);
189 r = this.inflate_flush (r);
191 m = (q < this.read ? this.read - q - 1 : this.end - q);
192 if (q == this.end && this.read != 0) {
194 m = (q < this.read ? this.read - q - 1 : this.end - q);
199 this.z.total_in += p - this.z.next_in_index;
200 this.z.next_in_index = p;
202 return this.inflate_flush (r);
207 System.arraycopy (this.z.next_in, p, this.window, q, t);
212 if ((this.left -= t) != 0) break;
213 this.mode = this.last != 0 ? 7 : 0;
223 this.z.total_in += p - this.z.next_in_index;
224 this.z.next_in_index = p;
226 return this.inflate_flush (r);
228 b |= (this.z.next_in[p++] & 0xff) << k;
231 this.table = t = (b & 0x3fff);
232 if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) {
234 this.z.msg = "too many length or distance symbols";
239 this.z.total_in += p - this.z.next_in_index;
240 this.z.next_in_index = p;
242 return this.inflate_flush (r);
243 }t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
244 if (this.blens == null || this.blens.length < t) {
245 this.blens = Clazz.newIntArray (t, 0);
247 for (var i = 0; i < t; i++) {
256 while (this.index < 4 + (this.table >>> 10)) {
264 this.z.total_in += p - this.z.next_in_index;
265 this.z.next_in_index = p;
267 return this.inflate_flush (r);
269 b |= (this.z.next_in[p++] & 0xff) << k;
272 this.blens[JU.InfBlocks.border[this.index++]] = b & 7;
277 while (this.index < 19) {
278 this.blens[JU.InfBlocks.border[this.index++]] = 0;
281 t = this.inftree.inflate_trees_bits (this.blens, this.bb, this.tb, this.hufts, this.z);
290 this.z.total_in += p - this.z.next_in_index;
291 this.z.next_in_index = p;
293 return this.inflate_flush (r);
299 if (!(this.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))) {
312 this.z.total_in += p - this.z.next_in_index;
313 this.z.next_in_index = p;
315 return this.inflate_flush (r);
317 b |= (this.z.next_in[p++] & 0xff) << k;
320 t = this.hufts[(this.tb[0] + (b & JU.InfBlocks.inflate_mask[t])) * 3 + 1];
321 c = this.hufts[(this.tb[0] + (b & JU.InfBlocks.inflate_mask[t])) * 3 + 2];
325 this.blens[this.index++] = c;
327 i = c == 18 ? 7 : c - 14;
328 j = c == 18 ? 11 : 3;
329 while (k < (t + i)) {
336 this.z.total_in += p - this.z.next_in_index;
337 this.z.next_in_index = p;
339 return this.inflate_flush (r);
341 b |= (this.z.next_in[p++] & 0xff) << k;
346 j += (b & JU.InfBlocks.inflate_mask[i]);
351 if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) {
354 this.z.msg = "invalid bit length repeat";
359 this.z.total_in += p - this.z.next_in_index;
360 this.z.next_in_index = p;
362 return this.inflate_flush (r);
363 }c = c == 16 ? this.blens[i - 1] : 0;
374 t = this.inftree.inflate_trees_dynamic (257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), this.blens, this.bl, this.bd, this.tli, this.tdi, this.hufts, this.z);
383 this.z.total_in += p - this.z.next_in_index;
384 this.z.next_in_index = p;
386 return this.inflate_flush (r);
387 }this.codes.init (this.bl[0], this.bd[0], this.hufts, this.tli[0], this.hufts, this.tdi[0]);
393 this.z.total_in += p - this.z.next_in_index;
394 this.z.next_in_index = p;
396 if ((r = this.codes.proc (r)) != 1) {
397 return this.inflate_flush (r);
399 this.codes.free (this.z);
400 p = this.z.next_in_index;
405 m = (q < this.read ? this.read - q - 1 : this.end - q);
406 if (this.last == 0) {
412 r = this.inflate_flush (r);
414 m = (q < this.read ? this.read - q - 1 : this.end - q);
415 if (this.read != this.write) {
419 this.z.total_in += p - this.z.next_in_index;
420 this.z.next_in_index = p;
422 return this.inflate_flush (r);
429 this.z.total_in += p - this.z.next_in_index;
430 this.z.next_in_index = p;
432 return this.inflate_flush (r);
438 this.z.total_in += p - this.z.next_in_index;
439 this.z.next_in_index = p;
441 return this.inflate_flush (r);
447 this.z.total_in += p - this.z.next_in_index;
448 this.z.next_in_index = p;
450 return this.inflate_flush (r);
454 Clazz.defineMethod (c$, "free",
460 Clazz.defineMethod (c$, "set_dictionary",
461 function (d, start, n) {
462 System.arraycopy (d, start, this.window, 0, n);
463 this.read = this.write = n;
465 Clazz.defineMethod (c$, "sync_point",
467 return this.mode == 1 ? 1 : 0;
469 Clazz.defineMethod (c$, "inflate_flush",
474 p = this.z.next_out_index;
476 n = ((q <= this.write ? this.write : this.end) - q);
477 if (n > this.z.avail_out) n = this.z.avail_out;
478 if (n != 0 && r == -5) r = 0;
479 this.z.avail_out -= n;
480 this.z.total_out += n;
481 if (this.check && n > 0) {
482 this.z.checksum.update (this.window, q, n);
483 }System.arraycopy (this.window, q, this.z.next_out, p, n);
488 if (this.write == this.end) this.write = 0;
490 if (n > this.z.avail_out) n = this.z.avail_out;
491 if (n != 0 && r == -5) r = 0;
492 this.z.avail_out -= n;
493 this.z.total_out += n;
494 if (this.check && n > 0) {
495 this.z.checksum.update (this.window, q, n);
496 }System.arraycopy (this.window, q, this.z.next_out, p, n);
499 }this.z.next_out_index = p;
503 Clazz.defineStatics (c$,
505 "inflate_mask", Clazz.newIntArray (-1, [0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff]),
506 "border", Clazz.newIntArray (-1, [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]),
509 "Z_STREAM_ERROR", -2,