1 Clazz.declarePackage ("JU");
2 Clazz.load (["JU.Tree"], "JU.Deflate", ["JU.CRC32", "$.GZIPHeader", "$.StaticTree"], function () {
3 c$ = Clazz.decorateAsClass (function () {
6 this.pending_buf = null;
7 this.pending_buf_size = 0;
27 this.match_length = 0;
29 this.match_available = 0;
34 this.max_chain_length = 0;
35 this.max_lazy_match = 0;
40 this.dyn_ltree = null;
41 this.dyn_dtree = null;
58 this.last_eob_len = 0;
62 Clazz.instantialize (this, arguments);
64 Clazz.prepareFields (c$, function () {
65 this.l_desc = new JU.Tree ();
66 this.d_desc = new JU.Tree ();
67 this.bl_desc = new JU.Tree ();
68 this.bl_count = Clazz.newShortArray (16, 0);
69 this.heap = Clazz.newIntArray (573, 0);
70 this.depth = Clazz.newByteArray (573, 0);
72 Clazz.makeConstructor (c$,
75 this.dyn_ltree = Clazz.newShortArray (1146, 0);
76 this.dyn_dtree = Clazz.newShortArray (122, 0);
77 this.bl_tree = Clazz.newShortArray (78, 0);
79 Clazz.defineMethod (c$, "deflateInit",
81 return this.deflateInit2 (level, 15);
83 Clazz.defineMethod (c$, "deflateInit2",
84 function (level, bits) {
85 return this.deflateInit5 (level, 8, bits, 8, 0);
87 Clazz.defineMethod (c$, "deflateInit3",
88 function (level, bits, memlevel) {
89 return this.deflateInit5 (level, 8, bits, memlevel, 0);
91 Clazz.defineMethod (c$, "lm_init",
93 this.window_size = 2 * this.w_size;
94 this.head[this.hash_size - 1] = 0;
95 for (var i = 0; i < this.hash_size - 1; i++) {
98 this.max_lazy_match = JU.Deflate.config_table[this.level].max_lazy;
99 this.good_match = JU.Deflate.config_table[this.level].good_length;
100 this.nice_match = JU.Deflate.config_table[this.level].nice_length;
101 this.max_chain_length = JU.Deflate.config_table[this.level].max_chain;
103 this.block_start = 0;
105 this.match_length = this.prev_length = 2;
106 this.match_available = 0;
109 Clazz.defineMethod (c$, "tr_init",
111 this.l_desc.dyn_tree = this.dyn_ltree;
112 this.l_desc.stat_desc = JU.StaticTree.static_l_desc;
113 this.d_desc.dyn_tree = this.dyn_dtree;
114 this.d_desc.stat_desc = JU.StaticTree.static_d_desc;
115 this.bl_desc.dyn_tree = this.bl_tree;
116 this.bl_desc.stat_desc = JU.StaticTree.static_bl_desc;
119 this.last_eob_len = 8;
122 Clazz.defineMethod (c$, "init_block",
124 for (var i = 0; i < 286; i++) this.dyn_ltree[i * 2] = 0;
126 for (var i = 0; i < 30; i++) this.dyn_dtree[i * 2] = 0;
128 for (var i = 0; i < 19; i++) this.bl_tree[i * 2] = 0;
130 this.dyn_ltree[512] = 1;
131 this.opt_len = this.static_len = 0;
132 this.last_lit = this.matches = 0;
134 Clazz.defineMethod (c$, "pqdownheap",
136 var v = this.heap[k];
138 while (j <= this.heap_len) {
139 if (j < this.heap_len && JU.Deflate.smaller (tree, this.heap[j + 1], this.heap[j], this.depth)) {
141 }if (JU.Deflate.smaller (tree, v, this.heap[j], this.depth)) break;
142 this.heap[k] = this.heap[j];
148 c$.smaller = Clazz.defineMethod (c$, "smaller",
149 function (tree, n, m, depth) {
150 var tn2 = tree[n * 2];
151 var tm2 = tree[m * 2];
152 return (tn2 < tm2 || (tn2 == tm2 && depth[n] <= depth[m]));
154 Clazz.defineMethod (c$, "scan_tree",
155 function (tree, max_code) {
159 var nextlen = tree[1];
166 }tree[(max_code + 1) * 2 + 1] = 0xffff;
167 for (n = 0; n <= max_code; n++) {
169 nextlen = tree[(n + 1) * 2 + 1];
170 if (++count < max_count && curlen == nextlen) {
172 } else if (count < min_count) {
173 this.bl_tree[curlen * 2] += count;
174 } else if (curlen != 0) {
175 if (curlen != prevlen) this.bl_tree[curlen * 2]++;
177 } else if (count <= 10) {
186 } else if (curlen == nextlen) {
194 Clazz.defineMethod (c$, "build_bl_tree",
197 this.scan_tree (this.dyn_ltree, this.l_desc.max_code);
198 this.scan_tree (this.dyn_dtree, this.d_desc.max_code);
199 this.bl_desc.build_tree (this);
200 for (max_blindex = 18; max_blindex >= 3; max_blindex--) {
201 if (this.bl_tree[JU.Tree.bl_order[max_blindex] * 2 + 1] != 0) break;
203 this.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
206 Clazz.defineMethod (c$, "send_all_trees",
207 function (lcodes, dcodes, blcodes) {
209 this.send_bits (lcodes - 257, 5);
210 this.send_bits (dcodes - 1, 5);
211 this.send_bits (blcodes - 4, 4);
212 for (rank = 0; rank < blcodes; rank++) {
213 this.send_bits (this.bl_tree[JU.Tree.bl_order[rank] * 2 + 1], 3);
215 this.send_tree (this.dyn_ltree, lcodes - 1);
216 this.send_tree (this.dyn_dtree, dcodes - 1);
218 Clazz.defineMethod (c$, "send_tree",
219 function (tree, max_code) {
223 var nextlen = tree[1];
230 }for (n = 0; n <= max_code; n++) {
232 nextlen = tree[(n + 1) * 2 + 1];
233 if (++count < max_count && curlen == nextlen) {
235 } else if (count < min_count) {
237 this.send_code (curlen, this.bl_tree);
238 } while (--count != 0);
239 } else if (curlen != 0) {
240 if (curlen != prevlen) {
241 this.send_code (curlen, this.bl_tree);
243 }this.send_code (16, this.bl_tree);
244 this.send_bits (count - 3, 2);
245 } else if (count <= 10) {
246 this.send_code (17, this.bl_tree);
247 this.send_bits (count - 3, 3);
249 this.send_code (18, this.bl_tree);
250 this.send_bits (count - 11, 7);
256 } else if (curlen == nextlen) {
264 Clazz.defineMethod (c$, "put_byte",
265 function (p, start, len) {
266 System.arraycopy (p, start, this.pending_buf, this.pending, len);
269 Clazz.defineMethod (c$, "put_byteB",
272 this.pending_buf[this.pending++] = c&0xff;
274 Clazz.defineMethod (c$, "put_short",
276 this.put_byteB ((w));
277 this.put_byteB ((w >>> 8));
279 Clazz.defineMethod (c$, "putShortMSB",
281 this.put_byteB ((b >> 8));
282 this.put_byteB ((b));
284 Clazz.defineMethod (c$, "send_code",
287 this.send_bits ((tree[c2] & 0xffff), (tree[c2 + 1] & 0xffff));
289 Clazz.defineMethod (c$, "send_bits",
290 function (value, length) {
292 if (this.bi_valid > 16 - len) {
294 this.bi_buf |= ((val << this.bi_valid) & 0xffff);
295 this.put_short (this.bi_buf);
296 this.bi_buf = ((val >>> (16 - this.bi_valid)) & 0xffff);
297 this.bi_valid += len - 16;
299 this.bi_buf |= (((value) << this.bi_valid) & 0xffff);
300 this.bi_valid += len;
302 Clazz.defineMethod (c$, "_tr_align",
304 this.send_bits (2, 3);
305 this.send_code (256, JU.StaticTree.static_ltree);
307 if (1 + this.last_eob_len + 10 - this.bi_valid < 9) {
308 this.send_bits (2, 3);
309 this.send_code (256, JU.StaticTree.static_ltree);
311 }this.last_eob_len = 7;
313 Clazz.defineMethod (c$, "_tr_tally",
314 function (dist, lc) {
315 this.pending_buf[this.d_buf + this.last_lit * 2] = (dist >>> 8);
316 this.pending_buf[this.d_buf + this.last_lit * 2 + 1] = dist;
317 this.pending_buf[this.l_buf + this.last_lit] = lc;
320 this.dyn_ltree[lc * 2]++;
324 this.dyn_ltree[(JU.Tree._length_code[lc] + 256 + 1) * 2]++;
325 this.dyn_dtree[JU.Tree.d_code (dist) * 2]++;
326 }if ((this.last_lit & 0x1fff) == 0 && this.level > 2) {
327 var out_length = this.last_lit * 8;
328 var in_length = this.strstart - this.block_start;
330 for (dcode = 0; dcode < 30; dcode++) {
331 out_length += this.dyn_dtree[dcode * 2] * (5 + JU.Tree.extra_dbits[dcode]);
334 if ((this.matches < (Clazz.doubleToInt (this.last_lit / 2))) && out_length < Clazz.doubleToInt (in_length / 2)) return true;
335 }return (this.last_lit == this.lit_bufsize - 1);
337 Clazz.defineMethod (c$, "compress_block",
338 function (ltree, dtree) {
344 if (this.last_lit != 0) {
346 dist = ((this.pending_buf[this.d_buf + lx * 2] << 8) & 0xff00) | (this.pending_buf[this.d_buf + lx * 2 + 1] & 0xff);
347 lc = (this.pending_buf[this.l_buf + lx]) & 0xff;
350 this.send_code (lc, ltree);
352 code = JU.Tree._length_code[lc];
353 this.send_code (code + 256 + 1, ltree);
354 extra = JU.Tree.extra_lbits[code];
356 lc -= JU.Tree.base_length[code];
357 this.send_bits (lc, extra);
359 code = JU.Tree.d_code (dist);
360 this.send_code (code, dtree);
361 extra = JU.Tree.extra_dbits[code];
363 dist -= JU.Tree.base_dist[code];
364 this.send_bits (dist, extra);
365 }}} while (lx < this.last_lit);
366 }this.send_code (256, ltree);
367 this.last_eob_len = ltree[513];
369 Clazz.defineMethod (c$, "set_data_type",
375 bin_freq += this.dyn_ltree[n * 2];
379 ascii_freq += this.dyn_ltree[n * 2];
383 bin_freq += this.dyn_ltree[n * 2];
386 this.data_type = (bin_freq > (ascii_freq >>> 2) ? 0 : 1);
388 Clazz.defineMethod (c$, "bi_flush",
390 if (this.bi_valid == 16) {
391 this.put_short (this.bi_buf);
394 } else if (this.bi_valid >= 8) {
395 this.put_byteB (this.bi_buf);
399 Clazz.defineMethod (c$, "bi_windup",
401 if (this.bi_valid > 8) {
402 this.put_short (this.bi_buf);
403 } else if (this.bi_valid > 0) {
404 this.put_byteB (this.bi_buf);
408 Clazz.defineMethod (c$, "copy_block",
409 function (buf, len, header) {
411 this.last_eob_len = 8;
413 this.put_short (len);
414 this.put_short (~len);
415 }this.put_byte (this.window, buf, len);
417 Clazz.defineMethod (c$, "flush_block_only",
419 this._tr_flush_block (this.block_start >= 0 ? this.block_start : -1, this.strstart - this.block_start, eof);
420 this.block_start = this.strstart;
421 this.strm.flush_pending ();
423 Clazz.defineMethod (c$, "deflate_stored",
425 var max_block_size = 0xffff;
427 if (max_block_size > this.pending_buf_size - 5) {
428 max_block_size = this.pending_buf_size - 5;
430 if (this.lookahead <= 1) {
432 if (this.lookahead == 0 && flush == 0) return 0;
433 if (this.lookahead == 0) break;
434 }this.strstart += this.lookahead;
436 max_start = this.block_start + max_block_size;
437 if (this.strstart == 0 || this.strstart >= max_start) {
438 this.lookahead = (this.strstart - max_start);
439 this.strstart = max_start;
440 this.flush_block_only (false);
441 if (this.strm.avail_out == 0) return 0;
442 }if (this.strstart - this.block_start >= this.w_size - 262) {
443 this.flush_block_only (false);
444 if (this.strm.avail_out == 0) return 0;
446 this.flush_block_only (flush == 4);
447 if (this.strm.avail_out == 0) return (flush == 4) ? 2 : 0;
448 return flush == 4 ? 3 : 1;
450 Clazz.defineMethod (c$, "_tr_stored_block",
451 function (buf, stored_len, eof) {
452 this.send_bits ((0) + (eof ? 1 : 0), 3);
453 this.copy_block (buf, stored_len, true);
455 Clazz.defineMethod (c$, "_tr_flush_block",
456 function (buf, stored_len, eof) {
460 if (this.level > 0) {
461 if (this.data_type == 2) this.set_data_type ();
462 this.l_desc.build_tree (this);
463 this.d_desc.build_tree (this);
464 max_blindex = this.build_bl_tree ();
465 opt_lenb = (this.opt_len + 3 + 7) >>> 3;
466 static_lenb = (this.static_len + 3 + 7) >>> 3;
467 if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
469 opt_lenb = static_lenb = stored_len + 5;
470 }if (stored_len + 4 <= opt_lenb && buf != -1) {
471 this._tr_stored_block (buf, stored_len, eof);
472 } else if (static_lenb == opt_lenb) {
473 this.send_bits ((2) + (eof ? 1 : 0), 3);
474 this.compress_block (JU.StaticTree.static_ltree, JU.StaticTree.static_dtree);
476 this.send_bits ((4) + (eof ? 1 : 0), 3);
477 this.send_all_trees (this.l_desc.max_code + 1, this.d_desc.max_code + 1, max_blindex + 1);
478 this.compress_block (this.dyn_ltree, this.dyn_dtree);
483 Clazz.defineMethod (c$, "fill_window",
490 more = (this.window_size - this.lookahead - this.strstart);
491 if (more == 0 && this.strstart == 0 && this.lookahead == 0) {
493 } else if (more == -1) {
495 } else if (this.strstart >= this.w_size + this.w_size - 262) {
496 System.arraycopy (this.window, this.w_size, this.window, 0, this.w_size);
497 this.match_start -= this.w_size;
498 this.strstart -= this.w_size;
499 this.block_start -= this.w_size;
503 m = (this.head[--p] & 0xffff);
504 this.head[p] = (m >= this.w_size ? (m - this.w_size) : 0);
509 m = (this.prev[--p] & 0xffff);
510 this.prev[p] = (m >= this.w_size ? (m - this.w_size) : 0);
513 }if (this.strm.avail_in == 0) return;
514 n = this.strm.read_buf (this.window, this.strstart + this.lookahead, more);
516 if (this.lookahead >= 3) {
517 this.ins_h = this.window[this.strstart] & 0xff;
518 this.ins_h = (((this.ins_h) << this.hash_shift) ^ (this.window[this.strstart + 1] & 0xff)) & this.hash_mask;
519 }} while (this.lookahead < 262 && this.strm.avail_in != 0);
521 Clazz.defineMethod (c$, "deflate_fast",
526 if (this.lookahead < 262) {
528 if (this.lookahead < 262 && flush == 0) {
530 }if (this.lookahead == 0) break;
531 }if (this.lookahead >= 3) {
532 this.ins_h = (((this.ins_h) << this.hash_shift) ^ (this.window[(this.strstart) + (2)] & 0xff)) & this.hash_mask;
533 hash_head = (this.head[this.ins_h] & 0xffff);
534 this.prev[this.strstart & this.w_mask] = this.head[this.ins_h];
535 this.head[this.ins_h] = this.strstart;
536 }if (hash_head != 0 && ((this.strstart - hash_head) & 0xffff) <= this.w_size - 262) {
537 if (this.strategy != 2) {
538 this.match_length = this.longest_match (hash_head);
539 }}if (this.match_length >= 3) {
540 bflush = this._tr_tally (this.strstart - this.match_start, this.match_length - 3);
541 this.lookahead -= this.match_length;
542 if (this.match_length <= this.max_lazy_match && this.lookahead >= 3) {
546 this.ins_h = ((this.ins_h << this.hash_shift) ^ (this.window[(this.strstart) + (2)] & 0xff)) & this.hash_mask;
547 hash_head = (this.head[this.ins_h] & 0xffff);
548 this.prev[this.strstart & this.w_mask] = this.head[this.ins_h];
549 this.head[this.ins_h] = this.strstart;
550 } while (--this.match_length != 0);
553 this.strstart += this.match_length;
554 this.match_length = 0;
555 this.ins_h = this.window[this.strstart] & 0xff;
556 this.ins_h = (((this.ins_h) << this.hash_shift) ^ (this.window[this.strstart + 1] & 0xff)) & this.hash_mask;
558 bflush = this._tr_tally (0, this.window[this.strstart] & 0xff);
562 this.flush_block_only (false);
563 if (this.strm.avail_out == 0) return 0;
565 this.flush_block_only (flush == 4);
566 if (this.strm.avail_out == 0) {
567 if (flush == 4) return 2;
569 }return flush == 4 ? 3 : 1;
571 Clazz.defineMethod (c$, "deflate_slow",
576 if (this.lookahead < 262) {
578 if (this.lookahead < 262 && flush == 0) {
580 }if (this.lookahead == 0) break;
581 }if (this.lookahead >= 3) {
582 this.ins_h = (((this.ins_h) << this.hash_shift) ^ (this.window[(this.strstart) + (2)] & 0xff)) & this.hash_mask;
583 hash_head = (this.head[this.ins_h] & 0xffff);
584 this.prev[this.strstart & this.w_mask] = this.head[this.ins_h];
585 this.head[this.ins_h] = this.strstart;
586 }this.prev_length = this.match_length;
587 this.prev_match = this.match_start;
588 this.match_length = 2;
589 if (hash_head != 0 && this.prev_length < this.max_lazy_match && ((this.strstart - hash_head) & 0xffff) <= this.w_size - 262) {
590 if (this.strategy != 2) {
591 this.match_length = this.longest_match (hash_head);
592 }if (this.match_length <= 5 && (this.strategy == 1 || (this.match_length == 3 && this.strstart - this.match_start > 4096))) {
593 this.match_length = 2;
594 }}if (this.prev_length >= 3 && this.match_length <= this.prev_length) {
595 var max_insert = this.strstart + this.lookahead - 3;
596 bflush = this._tr_tally (this.strstart - 1 - this.prev_match, this.prev_length - 3);
597 this.lookahead -= this.prev_length - 1;
598 this.prev_length -= 2;
600 if (++this.strstart <= max_insert) {
601 this.ins_h = (((this.ins_h) << this.hash_shift) ^ (this.window[(this.strstart) + (2)] & 0xff)) & this.hash_mask;
602 hash_head = (this.head[this.ins_h] & 0xffff);
603 this.prev[this.strstart & this.w_mask] = this.head[this.ins_h];
604 this.head[this.ins_h] = this.strstart;
605 }} while (--this.prev_length != 0);
606 this.match_available = 0;
607 this.match_length = 2;
610 this.flush_block_only (false);
611 if (this.strm.avail_out == 0) return 0;
612 }} else if (this.match_available != 0) {
613 bflush = this._tr_tally (0, this.window[this.strstart - 1] & 0xff);
615 this.flush_block_only (false);
618 if (this.strm.avail_out == 0) return 0;
620 this.match_available = 1;
624 if (this.match_available != 0) {
625 bflush = this._tr_tally (0, this.window[this.strstart - 1] & 0xff);
626 this.match_available = 0;
627 }this.flush_block_only (flush == 4);
628 if (this.strm.avail_out == 0) {
629 if (flush == 4) return 2;
631 }return flush == 4 ? 3 : 1;
633 Clazz.defineMethod (c$, "longest_match",
634 function (cur_match) {
635 var chain_length = this.max_chain_length;
636 var scan = this.strstart;
639 var best_len = this.prev_length;
640 var limit = this.strstart > (this.w_size - 262) ? this.strstart - (this.w_size - 262) : 0;
641 var nice_match = this.nice_match;
642 var wmask = this.w_mask;
643 var strend = this.strstart + 258;
644 var scan_end1 = this.window[scan + best_len - 1];
645 var scan_end = this.window[scan + best_len];
646 if (this.prev_length >= this.good_match) {
648 }if (nice_match > this.lookahead) nice_match = this.lookahead;
651 if (this.window[match + best_len] != scan_end || this.window[match + best_len - 1] != scan_end1 || this.window[match] != this.window[scan] || this.window[++match] != this.window[scan + 1]) continue;
655 } while (this.window[++scan] == this.window[++match] && this.window[++scan] == this.window[++match] && this.window[++scan] == this.window[++match] && this.window[++scan] == this.window[++match] && this.window[++scan] == this.window[++match] && this.window[++scan] == this.window[++match] && this.window[++scan] == this.window[++match] && this.window[++scan] == this.window[++match] && scan < strend);
656 len = 258 - (strend - scan);
658 if (len > best_len) {
659 this.match_start = cur_match;
661 if (len >= nice_match) break;
662 scan_end1 = this.window[scan + best_len - 1];
663 scan_end = this.window[scan + best_len];
664 }} while ((cur_match = (this.prev[cur_match & wmask] & 0xffff)) > limit && --chain_length != 0);
665 if (best_len <= this.lookahead) return best_len;
666 return this.lookahead;
668 Clazz.defineMethod (c$, "deflateInit5",
669 function (level, method, windowBits, memLevel, strategy) {
671 this.strm.msg = null;
672 if (level == -1) level = 6;
673 if (windowBits < 0) {
675 windowBits = -windowBits;
676 } else if (windowBits > 15) {
679 this.strm.checksum = new JU.CRC32 ();
680 }if (memLevel < 1 || memLevel > 9 || method != 8 || windowBits < 9 || windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > 2) {
682 }this.strm.dstate = this;
684 this.w_bits = windowBits;
685 this.w_size = 1 << this.w_bits;
686 this.w_mask = this.w_size - 1;
687 this.hash_bits = memLevel + 7;
688 this.hash_size = 1 << this.hash_bits;
689 this.hash_mask = this.hash_size - 1;
690 this.hash_shift = (Clazz.doubleToInt ((this.hash_bits + 3 - 1) / 3));
691 this.window = Clazz.newByteArray (this.w_size * 2, 0);
692 this.prev = Clazz.newShortArray (this.w_size, 0);
693 this.head = Clazz.newShortArray (this.hash_size, 0);
694 this.lit_bufsize = 1 << (memLevel + 6);
695 this.pending_buf = Clazz.newByteArray (this.lit_bufsize * 4, 0);
696 this.pending_buf_size = this.lit_bufsize * 4;
697 this.d_buf = Clazz.doubleToInt (this.lit_bufsize / 2);
698 this.l_buf = (3) * this.lit_bufsize;
700 this.strategy = strategy;
701 this.method = method;
702 return this.deflateReset ();
703 }, "~N,~N,~N,~N,~N");
704 Clazz.defineMethod (c$, "deflateReset",
706 this.strm.total_in = this.strm.total_out = 0;
707 this.strm.msg = null;
708 this.strm.data_type = 2;
710 this.pending_out = 0;
712 this.wrap = -this.wrap;
713 }this.status = (this.wrap == 0) ? 113 : 42;
714 this.strm.checksum.reset ();
720 Clazz.defineMethod (c$, "deflateEnd",
722 if (this.status != 42 && this.status != 113 && this.status != 666) {
724 }this.pending_buf = null;
728 return this.status == 113 ? -3 : 0;
730 Clazz.defineMethod (c$, "deflateParams",
731 function (_level, _strategy) {
735 }if (_level < 0 || _level > 9 || _strategy < 0 || _strategy > 2) {
737 }if (JU.Deflate.config_table[this.level].func != JU.Deflate.config_table[_level].func && this.strm.total_in != 0) {
738 err = this.strm.deflate (1);
739 }if (this.level != _level) {
741 this.max_lazy_match = JU.Deflate.config_table[this.level].max_lazy;
742 this.good_match = JU.Deflate.config_table[this.level].good_length;
743 this.nice_match = JU.Deflate.config_table[this.level].nice_length;
744 this.max_chain_length = JU.Deflate.config_table[this.level].max_chain;
745 }this.strategy = _strategy;
748 Clazz.defineMethod (c$, "deflateSetDictionary",
749 function (dictionary, dictLength) {
750 var length = dictLength;
752 if (dictionary == null || this.status != 42) return -2;
753 this.strm.checksum.update (dictionary, 0, dictLength);
754 if (length < 3) return 0;
755 if (length > this.w_size - 262) {
756 length = this.w_size - 262;
757 index = dictLength - length;
758 }System.arraycopy (dictionary, index, this.window, 0, length);
759 this.strstart = length;
760 this.block_start = length;
761 this.ins_h = this.window[0] & 0xff;
762 this.ins_h = (((this.ins_h) << this.hash_shift) ^ (this.window[1] & 0xff)) & this.hash_mask;
763 for (var n = 0; n <= length - 3; n++) {
764 this.ins_h = (((this.ins_h) << this.hash_shift) ^ (this.window[(n) + (2)] & 0xff)) & this.hash_mask;
765 this.prev[n & this.w_mask] = this.head[this.ins_h];
766 this.head[this.ins_h] = n;
770 Clazz.defineMethod (c$, "deflate",
773 if (flush > 4 || flush < 0) {
775 }if (this.strm.next_out == null || (this.strm.next_in == null && this.strm.avail_in != 0) || (this.status == 666 && flush != 4)) {
776 this.strm.msg = JU.Deflate.z_errmsg[4];
778 }if (this.strm.avail_out == 0) {
779 this.strm.msg = JU.Deflate.z_errmsg[7];
781 }old_flush = this.last_flush;
782 this.last_flush = flush;
783 if (this.status == 42) {
784 if (this.wrap == 2) {
785 this.getGZIPHeader ().put (this);
787 this.strm.checksum.reset ();
789 var header = (8 + ((this.w_bits - 8) << 4)) << 8;
790 var level_flags = ((this.level - 1) & 0xff) >> 1;
791 if (level_flags > 3) level_flags = 3;
792 header |= (level_flags << 6);
793 if (this.strstart != 0) header |= 32;
794 header += 31 - (header % 31);
796 this.putShortMSB (header);
797 if (this.strstart != 0) {
798 var adler = this.strm.checksum.getValue ();
799 this.putShortMSB ((adler >>> 16));
800 this.putShortMSB ((adler & 0xffff));
801 }this.strm.checksum.reset ();
802 }}if (this.pending != 0) {
803 this.strm.flush_pending ();
804 if (this.strm.avail_out == 0) {
805 this.last_flush = -1;
807 }} else if (this.strm.avail_in == 0 && flush <= old_flush && flush != 4) {
808 this.strm.msg = JU.Deflate.z_errmsg[7];
810 }if (this.status == 666 && this.strm.avail_in != 0) {
811 this.strm.msg = JU.Deflate.z_errmsg[7];
813 }if (this.strm.avail_in != 0 || this.lookahead != 0 || (flush != 0 && this.status != 666)) {
815 switch (JU.Deflate.config_table[this.level].func) {
817 bstate = this.deflate_stored (flush);
820 bstate = this.deflate_fast (flush);
823 bstate = this.deflate_slow (flush);
827 if (bstate == 2 || bstate == 3) {
829 }if (bstate == 0 || bstate == 2) {
830 if (this.strm.avail_out == 0) {
831 this.last_flush = -1;
837 this._tr_stored_block (0, 0, false);
839 for (var i = 0; i < this.hash_size; i++) this.head[i] = 0;
841 }}this.strm.flush_pending ();
842 if (this.strm.avail_out == 0) {
843 this.last_flush = -1;
845 }}}if (flush != 4) return 0;
846 if (this.wrap <= 0) return 1;
847 if (this.wrap == 2) {
848 var adler = this.strm.checksum.getValue ();
849 this.put_byteB ((adler & 0xff));
850 this.put_byteB (((adler >> 8) & 0xff));
851 this.put_byteB (((adler >> 16) & 0xff));
852 this.put_byteB (((adler >> 24) & 0xff));
853 this.put_byteB ((this.strm.total_in & 0xff));
854 this.put_byteB (((this.strm.total_in >> 8) & 0xff));
855 this.put_byteB (((this.strm.total_in >> 16) & 0xff));
856 this.put_byteB (((this.strm.total_in >> 24) & 0xff));
857 this.getGZIPHeader ().setCRC (adler);
859 var adler = this.strm.checksum.getValue ();
860 this.putShortMSB ((adler >>> 16));
861 this.putShortMSB ((adler & 0xffff));
862 }this.strm.flush_pending ();
863 if (this.wrap > 0) this.wrap = -this.wrap;
864 return this.pending != 0 ? 0 : 1;
866 Clazz.defineMethod (c$, "getGZIPHeader",
868 if (this.gheader == null) {
869 this.gheader = new JU.GZIPHeader ();
870 }return this.gheader;
872 Clazz.defineMethod (c$, "getBytesRead",
874 return this.strm.total_in;
876 Clazz.defineMethod (c$, "getBytesWritten",
878 return this.strm.total_out;
881 c$ = Clazz.decorateAsClass (function () {
882 this.good_length = 0;
884 this.nice_length = 0;
887 Clazz.instantialize (this, arguments);
888 }, JU.Deflate, "Config");
889 Clazz.makeConstructor (c$,
890 function (a, b, c, d, e) {
891 this.good_length = a;
893 this.nice_length = c;
896 }, "~N,~N,~N,~N,~N");
898 Clazz.defineStatics (c$,
900 "Z_DEFAULT_COMPRESSION", -1,
906 "config_table", null);
908 JU.Deflate.config_table = new Array (10);
909 JU.Deflate.config_table[0] = new JU.Deflate.Config (0, 0, 0, 0, 0);
910 JU.Deflate.config_table[1] = new JU.Deflate.Config (4, 4, 8, 4, 1);
911 JU.Deflate.config_table[2] = new JU.Deflate.Config (4, 5, 16, 8, 1);
912 JU.Deflate.config_table[3] = new JU.Deflate.Config (4, 6, 32, 32, 1);
913 JU.Deflate.config_table[4] = new JU.Deflate.Config (4, 4, 16, 16, 2);
914 JU.Deflate.config_table[5] = new JU.Deflate.Config (8, 16, 32, 32, 2);
915 JU.Deflate.config_table[6] = new JU.Deflate.Config (8, 16, 128, 128, 2);
916 JU.Deflate.config_table[7] = new JU.Deflate.Config (8, 32, 128, 256, 2);
917 JU.Deflate.config_table[8] = new JU.Deflate.Config (32, 128, 258, 1024, 2);
918 JU.Deflate.config_table[9] = new JU.Deflate.Config (32, 258, 258, 4096, 2);
919 }Clazz.defineStatics (c$,
920 "z_errmsg", Clazz.newArray (-1, ["need dictionary", "stream end", "", "file error", "stream error", "data error", "insufficient memory", "buffer error", "incompatible version", ""]),
928 "Z_DEFAULT_STRATEGY", 0,
930 "Z_PARTIAL_FLUSH", 1,
936 "Z_STREAM_ERROR", -2,
955 "MIN_LOOKAHEAD", (262),