10 if ( typeof define ===
"function" && define.amd ) {
11 define( [
'JSRootCore'], factory );
13 if (typeof exports ===
'object' && typeof module !==
'undefined') {
14 factory(require(
"./JSRootCore.js"));
16 if (typeof JSROOT ==
'undefined')
17 throw new Error(
'JSROOT is not defined',
'rawinflate.js');
19 if (typeof JSROOT.ZIP !==
'undefined')
20 throw new Error(
'JSROOT.ZIP already exists',
'rawinflate.js');
38 var zip_WSIZE = 32768,
54 zip_fixed_bl, zip_fixed_bd,
68 zip_MASK_BITS =
new Array(
70 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
71 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff),
74 zip_cplens =
new Array(
75 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
76 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0),
79 zip_cplext =
new Array(
80 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
81 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99),
83 zip_cpdist =
new Array(
84 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
85 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
86 8193, 12289, 16385, 24577),
88 zip_cpdext =
new Array(
89 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
90 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
93 zip_border =
new Array(
94 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15);
97 var zip_HuftList =
function() {
102 var zip_HuftNode =
function() {
111 var zip_HuftBuild =
function(b,
133 c =
new Array(BMAX+1),
134 lx =
new Array(BMAX+1),
136 v =
new Array(N_MAX),
137 x =
new Array(BMAX+1),
138 r =
new zip_HuftNode(),
156 tail = this.root = null;
158 for (i=0; i<=BMAX; ++i) c[i] = lx[i] = x[i] = 0;
159 for (i=0; i<BMAX; ++i) u[i] = null;
160 for (i=0; i<N_MAX; ++i) v[i] = 0;
163 el = (n > 256) ? b[256] : BMAX;
164 p = b; pidx = 0; i = n;
177 for (j = 1; j <= BMAX; ++j)
183 for (i = BMAX; i != 0; --i)
191 for (y = 1 << j; j < i; ++j, y <<= 1) {
192 if ((y -= c[j]) < 0) {
198 if ((y -= c[i]) < 0) {
211 x[xp++] = (j += p[pidx++]);
217 if ((j = p[pidx++]) != 0)
231 for (; k <= g; ++k) {
236 while (k > w + lx[1 + h]) {
240 z = (z = g - w) > mm ? mm : z;
241 if ((f = 1 << (j = k - w)) > a + 1) {
246 if ((f <<= 1) <= c[++xp])
251 if (w + j > el && w < el)
258 for (o = 0; o < z; ++o) {
259 q[o] =
new zip_HuftNode();
263 tail = this.root =
new zip_HuftList();
265 tail = tail.next =
new zip_HuftList();
276 j = (i & ((1 << w) - 1)) >> (w - lx[h]);
289 else if (p[pidx] < s) {
290 r.e = (p[pidx] < 256 ? 16 : 15);
293 r.e = e[p[pidx] - s];
294 r.n = d[p[pidx++] - s];
299 for (j = i >> w; j < z; j += f) {
308 for (j = 1 << (k - 1); (i & j) != 0; j >>= 1)
313 while ((i & ((1 << w) - 1)) != x[h]) {
323 this.status = ((y != 0 && g != 1) ? 1 : 0);
331 var zip_NEEDBITS =
function(n) {
332 while (zip_bit_len < n) {
333 if (zip_inflate_pos < zip_inflate_datalen)
334 zip_bit_buf |= zip_inflate_data[zip_inflate_pos++] << zip_bit_len;
339 var zip_GETBITS =
function(n) {
340 return zip_bit_buf & zip_MASK_BITS[n];
343 var zip_DUMPBITS =
function(n) {
348 var zip_inflate_codes =
function(buff, off, size) {
349 if (size == 0)
return 0;
360 zip_NEEDBITS(zip_bl);
361 t = zip_tl.list[zip_GETBITS(zip_bl)];
369 t = t.t[zip_GETBITS(e)];
375 zip_wp &= zip_WSIZE - 1;
376 buff[off + n++] = zip_slide[zip_wp++] = t.n;
390 zip_copy_leng = t.n + zip_GETBITS(e);
394 zip_NEEDBITS(zip_bd);
395 t = zip_td.list[zip_GETBITS(zip_bd)];
404 t = t.t[zip_GETBITS(e)];
409 zip_copy_dist = zip_wp - t.n - zip_GETBITS(e);
413 while (zip_copy_leng > 0 && n < size) {
415 zip_copy_dist &= zip_WSIZE - 1;
416 zip_wp &= zip_WSIZE - 1;
417 buff[off + n++] = zip_slide[zip_wp++] = zip_slide[zip_copy_dist++];
428 var zip_inflate_stored =
function(buff, off, size) {
432 var n = zip_bit_len & 7;
440 if (n != ((~zip_bit_buf) & 0xffff))
448 while (zip_copy_leng > 0 && n < size) {
450 zip_wp &= zip_WSIZE - 1;
452 buff[off + n++] = zip_slide[zip_wp++] = zip_GETBITS(8);
456 if (zip_copy_leng == 0)
461 var zip_inflate_fixed =
function(buff, off, size) {
467 if (zip_fixed_tl == null) {
472 while (i < 144) l[i++] = 8;
473 while (i < 256) l[i++] = 9;
474 while (i < 280) l[i++] = 7;
475 while (i < 288) l[i++] = 8;
478 var h =
new zip_HuftBuild(l, 288, 257, zip_cplens, zip_cplext, zip_fixed_bl);
480 throw new Error(
"HufBuild error: "+h.status,
"rawinflate.js");
483 zip_fixed_tl = h.root;
487 for (i = 0; i<30; ++i) l[i] = 5;
490 h =
new zip_HuftBuild(l, 30, 0, zip_cpdist, zip_cpdext, zip_fixed_bd);
493 throw new Error(
"HufBuild error: "+h.status,
"rawinflate.js");
496 zip_fixed_td = h.root;
500 zip_tl = zip_fixed_tl;
501 zip_td = zip_fixed_td;
502 zip_bl = zip_fixed_bl;
503 zip_bd = zip_fixed_bd;
504 return zip_inflate_codes(buff, off, size);
507 var zip_inflate_dynamic =
function(buff, off, size) {
514 ll =
new Array(286+30);
516 for (i = 0; i < ll.length; ++i)
521 var nl = 257 + zip_GETBITS(5);
524 var nd = 1 + zip_GETBITS(5);
527 var nb = 4 + zip_GETBITS(4);
529 if (nl > 286 || nd > 30)
533 for (j = 0; j < nb; ++j) {
535 ll[zip_border[j]] = zip_GETBITS(3);
539 ll[zip_border[j]] = 0;
543 h =
new zip_HuftBuild(ll, 19, 19, null, null, zip_bl);
554 zip_NEEDBITS(zip_bl);
555 t = zip_tl.list[zip_GETBITS(zip_bl)];
563 j = 3 + zip_GETBITS(2);
569 }
else if (j == 17) {
571 j = 3 + zip_GETBITS(3);
580 j = 11 + zip_GETBITS(7);
592 h =
new zip_HuftBuild(ll, nl, 257, zip_cplens, zip_cplext, zip_bl);
602 for (i = 0; i < nd; ++i)
605 h =
new zip_HuftBuild(ll, nd, 0, zip_cpdist, zip_cpdext, zip_bd);
609 if (zip_bd == 0 && nl > 257) {
620 return zip_inflate_codes(buff, off, size);
623 var zip_inflate_internal =
function(buff, off, size) {
628 if (zip_eof && zip_method == -1)
631 if (zip_copy_leng > 0) {
632 if (zip_method != 0 ) {
634 while (zip_copy_leng > 0 && n < size) {
636 zip_copy_dist &= zip_WSIZE - 1;
637 zip_wp &= zip_WSIZE - 1;
638 buff[off + n++] = zip_slide[zip_wp++] =
639 zip_slide[zip_copy_dist++];
642 while (zip_copy_leng > 0 && n < size) {
644 zip_wp &= zip_WSIZE - 1;
646 buff[off + n++] = zip_slide[zip_wp++] = zip_GETBITS(8);
649 if (zip_copy_leng == 0)
656 if (zip_method == -1) {
662 if (zip_GETBITS(1) != 0)
668 zip_method = zip_GETBITS(2);
674 switch (zip_method) {
676 i = zip_inflate_stored(buff, off + n, size - n);
681 i = zip_inflate_codes(buff, off + n, size - n);
683 i = zip_inflate_fixed(buff, off + n, size - n);
688 i = zip_inflate_codes(buff, off + n, size - n);
690 i = zip_inflate_dynamic(buff, off + n, size - n);
699 return zip_eof ? 0 : -1;
707 JSROOT.ZIP.inflate =
function(arr, tgt)
710 zip_slide =
new Array(2 * zip_WSIZE);
716 zip_copy_leng = zip_copy_dist = 0;
719 zip_inflate_data = arr;
720 zip_inflate_datalen = arr.byteLength;
724 while ((i = zip_inflate_internal(tgt, cnt, Math.min(1024, tgt.byteLength-cnt))) > 0) {
727 zip_inflate_data = null;
752 JSROOT.LZ4.uncompress =
function (input, output, sIdx, eIdx) {
754 eIdx = eIdx || (input.length - sIdx)
756 for (var i = sIdx, n = eIdx, j = 0; i < n;) {
757 var token = input[i++]
760 var literals_length = (token >> 4)
761 if (literals_length > 0) {
763 var l = literals_length + 240
770 var end = i + literals_length
771 while (i < end) output[j++] = input[i++]
774 if (i === n)
return j
779 var offset = input[i++] | (input[i++] << 8)
782 if (offset === 0 || offset > j)
return -(i-2)
785 var match_length = (token & 0xf)
786 var l = match_length + 240
794 var end = j + match_length + 4
795 while (j < end) output[j++] = output[pos++]