source: trip-planner-front/node_modules/pako/dist/pako_inflate.js@ e29cc2e

Last change on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 106.0 KB
Line 
1/* pako 1.0.11 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2'use strict';
3
4
5var TYPED_OK = (typeof Uint8Array !== 'undefined') &&
6 (typeof Uint16Array !== 'undefined') &&
7 (typeof Int32Array !== 'undefined');
8
9function _has(obj, key) {
10 return Object.prototype.hasOwnProperty.call(obj, key);
11}
12
13exports.assign = function (obj /*from1, from2, from3, ...*/) {
14 var sources = Array.prototype.slice.call(arguments, 1);
15 while (sources.length) {
16 var source = sources.shift();
17 if (!source) { continue; }
18
19 if (typeof source !== 'object') {
20 throw new TypeError(source + 'must be non-object');
21 }
22
23 for (var p in source) {
24 if (_has(source, p)) {
25 obj[p] = source[p];
26 }
27 }
28 }
29
30 return obj;
31};
32
33
34// reduce buffer size, avoiding mem copy
35exports.shrinkBuf = function (buf, size) {
36 if (buf.length === size) { return buf; }
37 if (buf.subarray) { return buf.subarray(0, size); }
38 buf.length = size;
39 return buf;
40};
41
42
43var fnTyped = {
44 arraySet: function (dest, src, src_offs, len, dest_offs) {
45 if (src.subarray && dest.subarray) {
46 dest.set(src.subarray(src_offs, src_offs + len), dest_offs);
47 return;
48 }
49 // Fallback to ordinary array
50 for (var i = 0; i < len; i++) {
51 dest[dest_offs + i] = src[src_offs + i];
52 }
53 },
54 // Join array of chunks to single array.
55 flattenChunks: function (chunks) {
56 var i, l, len, pos, chunk, result;
57
58 // calculate data length
59 len = 0;
60 for (i = 0, l = chunks.length; i < l; i++) {
61 len += chunks[i].length;
62 }
63
64 // join chunks
65 result = new Uint8Array(len);
66 pos = 0;
67 for (i = 0, l = chunks.length; i < l; i++) {
68 chunk = chunks[i];
69 result.set(chunk, pos);
70 pos += chunk.length;
71 }
72
73 return result;
74 }
75};
76
77var fnUntyped = {
78 arraySet: function (dest, src, src_offs, len, dest_offs) {
79 for (var i = 0; i < len; i++) {
80 dest[dest_offs + i] = src[src_offs + i];
81 }
82 },
83 // Join array of chunks to single array.
84 flattenChunks: function (chunks) {
85 return [].concat.apply([], chunks);
86 }
87};
88
89
90// Enable/Disable typed arrays use, for testing
91//
92exports.setTyped = function (on) {
93 if (on) {
94 exports.Buf8 = Uint8Array;
95 exports.Buf16 = Uint16Array;
96 exports.Buf32 = Int32Array;
97 exports.assign(exports, fnTyped);
98 } else {
99 exports.Buf8 = Array;
100 exports.Buf16 = Array;
101 exports.Buf32 = Array;
102 exports.assign(exports, fnUntyped);
103 }
104};
105
106exports.setTyped(TYPED_OK);
107
108},{}],2:[function(require,module,exports){
109// String encode/decode helpers
110'use strict';
111
112
113var utils = require('./common');
114
115
116// Quick check if we can use fast array to bin string conversion
117//
118// - apply(Array) can fail on Android 2.2
119// - apply(Uint8Array) can fail on iOS 5.1 Safari
120//
121var STR_APPLY_OK = true;
122var STR_APPLY_UIA_OK = true;
123
124try { String.fromCharCode.apply(null, [ 0 ]); } catch (__) { STR_APPLY_OK = false; }
125try { String.fromCharCode.apply(null, new Uint8Array(1)); } catch (__) { STR_APPLY_UIA_OK = false; }
126
127
128// Table with utf8 lengths (calculated by first byte of sequence)
129// Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
130// because max possible codepoint is 0x10ffff
131var _utf8len = new utils.Buf8(256);
132for (var q = 0; q < 256; q++) {
133 _utf8len[q] = (q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1);
134}
135_utf8len[254] = _utf8len[254] = 1; // Invalid sequence start
136
137
138// convert string to array (typed, when possible)
139exports.string2buf = function (str) {
140 var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;
141
142 // count binary size
143 for (m_pos = 0; m_pos < str_len; m_pos++) {
144 c = str.charCodeAt(m_pos);
145 if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
146 c2 = str.charCodeAt(m_pos + 1);
147 if ((c2 & 0xfc00) === 0xdc00) {
148 c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
149 m_pos++;
150 }
151 }
152 buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
153 }
154
155 // allocate buffer
156 buf = new utils.Buf8(buf_len);
157
158 // convert
159 for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
160 c = str.charCodeAt(m_pos);
161 if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
162 c2 = str.charCodeAt(m_pos + 1);
163 if ((c2 & 0xfc00) === 0xdc00) {
164 c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
165 m_pos++;
166 }
167 }
168 if (c < 0x80) {
169 /* one byte */
170 buf[i++] = c;
171 } else if (c < 0x800) {
172 /* two bytes */
173 buf[i++] = 0xC0 | (c >>> 6);
174 buf[i++] = 0x80 | (c & 0x3f);
175 } else if (c < 0x10000) {
176 /* three bytes */
177 buf[i++] = 0xE0 | (c >>> 12);
178 buf[i++] = 0x80 | (c >>> 6 & 0x3f);
179 buf[i++] = 0x80 | (c & 0x3f);
180 } else {
181 /* four bytes */
182 buf[i++] = 0xf0 | (c >>> 18);
183 buf[i++] = 0x80 | (c >>> 12 & 0x3f);
184 buf[i++] = 0x80 | (c >>> 6 & 0x3f);
185 buf[i++] = 0x80 | (c & 0x3f);
186 }
187 }
188
189 return buf;
190};
191
192// Helper (used in 2 places)
193function buf2binstring(buf, len) {
194 // On Chrome, the arguments in a function call that are allowed is `65534`.
195 // If the length of the buffer is smaller than that, we can use this optimization,
196 // otherwise we will take a slower path.
197 if (len < 65534) {
198 if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) {
199 return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));
200 }
201 }
202
203 var result = '';
204 for (var i = 0; i < len; i++) {
205 result += String.fromCharCode(buf[i]);
206 }
207 return result;
208}
209
210
211// Convert byte array to binary string
212exports.buf2binstring = function (buf) {
213 return buf2binstring(buf, buf.length);
214};
215
216
217// Convert binary string (typed, when possible)
218exports.binstring2buf = function (str) {
219 var buf = new utils.Buf8(str.length);
220 for (var i = 0, len = buf.length; i < len; i++) {
221 buf[i] = str.charCodeAt(i);
222 }
223 return buf;
224};
225
226
227// convert array to string
228exports.buf2string = function (buf, max) {
229 var i, out, c, c_len;
230 var len = max || buf.length;
231
232 // Reserve max possible length (2 words per char)
233 // NB: by unknown reasons, Array is significantly faster for
234 // String.fromCharCode.apply than Uint16Array.
235 var utf16buf = new Array(len * 2);
236
237 for (out = 0, i = 0; i < len;) {
238 c = buf[i++];
239 // quick process ascii
240 if (c < 0x80) { utf16buf[out++] = c; continue; }
241
242 c_len = _utf8len[c];
243 // skip 5 & 6 byte codes
244 if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len - 1; continue; }
245
246 // apply mask on first byte
247 c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
248 // join the rest
249 while (c_len > 1 && i < len) {
250 c = (c << 6) | (buf[i++] & 0x3f);
251 c_len--;
252 }
253
254 // terminated by end of string?
255 if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }
256
257 if (c < 0x10000) {
258 utf16buf[out++] = c;
259 } else {
260 c -= 0x10000;
261 utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);
262 utf16buf[out++] = 0xdc00 | (c & 0x3ff);
263 }
264 }
265
266 return buf2binstring(utf16buf, out);
267};
268
269
270// Calculate max possible position in utf8 buffer,
271// that will not break sequence. If that's not possible
272// - (very small limits) return max size as is.
273//
274// buf[] - utf8 bytes array
275// max - length limit (mandatory);
276exports.utf8border = function (buf, max) {
277 var pos;
278
279 max = max || buf.length;
280 if (max > buf.length) { max = buf.length; }
281
282 // go back from last position, until start of sequence found
283 pos = max - 1;
284 while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }
285
286 // Very small and broken sequence,
287 // return max, because we should return something anyway.
288 if (pos < 0) { return max; }
289
290 // If we came to start of buffer - that means buffer is too small,
291 // return max too.
292 if (pos === 0) { return max; }
293
294 return (pos + _utf8len[buf[pos]] > max) ? pos : max;
295};
296
297},{"./common":1}],3:[function(require,module,exports){
298'use strict';
299
300// Note: adler32 takes 12% for level 0 and 2% for level 6.
301// It isn't worth it to make additional optimizations as in original.
302// Small size is preferable.
303
304// (C) 1995-2013 Jean-loup Gailly and Mark Adler
305// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
306//
307// This software is provided 'as-is', without any express or implied
308// warranty. In no event will the authors be held liable for any damages
309// arising from the use of this software.
310//
311// Permission is granted to anyone to use this software for any purpose,
312// including commercial applications, and to alter it and redistribute it
313// freely, subject to the following restrictions:
314//
315// 1. The origin of this software must not be misrepresented; you must not
316// claim that you wrote the original software. If you use this software
317// in a product, an acknowledgment in the product documentation would be
318// appreciated but is not required.
319// 2. Altered source versions must be plainly marked as such, and must not be
320// misrepresented as being the original software.
321// 3. This notice may not be removed or altered from any source distribution.
322
323function adler32(adler, buf, len, pos) {
324 var s1 = (adler & 0xffff) |0,
325 s2 = ((adler >>> 16) & 0xffff) |0,
326 n = 0;
327
328 while (len !== 0) {
329 // Set limit ~ twice less than 5552, to keep
330 // s2 in 31-bits, because we force signed ints.
331 // in other case %= will fail.
332 n = len > 2000 ? 2000 : len;
333 len -= n;
334
335 do {
336 s1 = (s1 + buf[pos++]) |0;
337 s2 = (s2 + s1) |0;
338 } while (--n);
339
340 s1 %= 65521;
341 s2 %= 65521;
342 }
343
344 return (s1 | (s2 << 16)) |0;
345}
346
347
348module.exports = adler32;
349
350},{}],4:[function(require,module,exports){
351'use strict';
352
353// (C) 1995-2013 Jean-loup Gailly and Mark Adler
354// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
355//
356// This software is provided 'as-is', without any express or implied
357// warranty. In no event will the authors be held liable for any damages
358// arising from the use of this software.
359//
360// Permission is granted to anyone to use this software for any purpose,
361// including commercial applications, and to alter it and redistribute it
362// freely, subject to the following restrictions:
363//
364// 1. The origin of this software must not be misrepresented; you must not
365// claim that you wrote the original software. If you use this software
366// in a product, an acknowledgment in the product documentation would be
367// appreciated but is not required.
368// 2. Altered source versions must be plainly marked as such, and must not be
369// misrepresented as being the original software.
370// 3. This notice may not be removed or altered from any source distribution.
371
372module.exports = {
373
374 /* Allowed flush values; see deflate() and inflate() below for details */
375 Z_NO_FLUSH: 0,
376 Z_PARTIAL_FLUSH: 1,
377 Z_SYNC_FLUSH: 2,
378 Z_FULL_FLUSH: 3,
379 Z_FINISH: 4,
380 Z_BLOCK: 5,
381 Z_TREES: 6,
382
383 /* Return codes for the compression/decompression functions. Negative values
384 * are errors, positive values are used for special but normal events.
385 */
386 Z_OK: 0,
387 Z_STREAM_END: 1,
388 Z_NEED_DICT: 2,
389 Z_ERRNO: -1,
390 Z_STREAM_ERROR: -2,
391 Z_DATA_ERROR: -3,
392 //Z_MEM_ERROR: -4,
393 Z_BUF_ERROR: -5,
394 //Z_VERSION_ERROR: -6,
395
396 /* compression levels */
397 Z_NO_COMPRESSION: 0,
398 Z_BEST_SPEED: 1,
399 Z_BEST_COMPRESSION: 9,
400 Z_DEFAULT_COMPRESSION: -1,
401
402
403 Z_FILTERED: 1,
404 Z_HUFFMAN_ONLY: 2,
405 Z_RLE: 3,
406 Z_FIXED: 4,
407 Z_DEFAULT_STRATEGY: 0,
408
409 /* Possible values of the data_type field (though see inflate()) */
410 Z_BINARY: 0,
411 Z_TEXT: 1,
412 //Z_ASCII: 1, // = Z_TEXT (deprecated)
413 Z_UNKNOWN: 2,
414
415 /* The deflate compression method */
416 Z_DEFLATED: 8
417 //Z_NULL: null // Use -1 or null inline, depending on var type
418};
419
420},{}],5:[function(require,module,exports){
421'use strict';
422
423// Note: we can't get significant speed boost here.
424// So write code to minimize size - no pregenerated tables
425// and array tools dependencies.
426
427// (C) 1995-2013 Jean-loup Gailly and Mark Adler
428// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
429//
430// This software is provided 'as-is', without any express or implied
431// warranty. In no event will the authors be held liable for any damages
432// arising from the use of this software.
433//
434// Permission is granted to anyone to use this software for any purpose,
435// including commercial applications, and to alter it and redistribute it
436// freely, subject to the following restrictions:
437//
438// 1. The origin of this software must not be misrepresented; you must not
439// claim that you wrote the original software. If you use this software
440// in a product, an acknowledgment in the product documentation would be
441// appreciated but is not required.
442// 2. Altered source versions must be plainly marked as such, and must not be
443// misrepresented as being the original software.
444// 3. This notice may not be removed or altered from any source distribution.
445
446// Use ordinary array, since untyped makes no boost here
447function makeTable() {
448 var c, table = [];
449
450 for (var n = 0; n < 256; n++) {
451 c = n;
452 for (var k = 0; k < 8; k++) {
453 c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
454 }
455 table[n] = c;
456 }
457
458 return table;
459}
460
461// Create table on load. Just 255 signed longs. Not a problem.
462var crcTable = makeTable();
463
464
465function crc32(crc, buf, len, pos) {
466 var t = crcTable,
467 end = pos + len;
468
469 crc ^= -1;
470
471 for (var i = pos; i < end; i++) {
472 crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];
473 }
474
475 return (crc ^ (-1)); // >>> 0;
476}
477
478
479module.exports = crc32;
480
481},{}],6:[function(require,module,exports){
482'use strict';
483
484// (C) 1995-2013 Jean-loup Gailly and Mark Adler
485// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
486//
487// This software is provided 'as-is', without any express or implied
488// warranty. In no event will the authors be held liable for any damages
489// arising from the use of this software.
490//
491// Permission is granted to anyone to use this software for any purpose,
492// including commercial applications, and to alter it and redistribute it
493// freely, subject to the following restrictions:
494//
495// 1. The origin of this software must not be misrepresented; you must not
496// claim that you wrote the original software. If you use this software
497// in a product, an acknowledgment in the product documentation would be
498// appreciated but is not required.
499// 2. Altered source versions must be plainly marked as such, and must not be
500// misrepresented as being the original software.
501// 3. This notice may not be removed or altered from any source distribution.
502
503function GZheader() {
504 /* true if compressed data believed to be text */
505 this.text = 0;
506 /* modification time */
507 this.time = 0;
508 /* extra flags (not used when writing a gzip file) */
509 this.xflags = 0;
510 /* operating system */
511 this.os = 0;
512 /* pointer to extra field or Z_NULL if none */
513 this.extra = null;
514 /* extra field length (valid if extra != Z_NULL) */
515 this.extra_len = 0; // Actually, we don't need it in JS,
516 // but leave for few code modifications
517
518 //
519 // Setup limits is not necessary because in js we should not preallocate memory
520 // for inflate use constant limit in 65536 bytes
521 //
522
523 /* space at extra (only when reading header) */
524 // this.extra_max = 0;
525 /* pointer to zero-terminated file name or Z_NULL */
526 this.name = '';
527 /* space at name (only when reading header) */
528 // this.name_max = 0;
529 /* pointer to zero-terminated comment or Z_NULL */
530 this.comment = '';
531 /* space at comment (only when reading header) */
532 // this.comm_max = 0;
533 /* true if there was or will be a header crc */
534 this.hcrc = 0;
535 /* true when done reading gzip header (not used when writing a gzip file) */
536 this.done = false;
537}
538
539module.exports = GZheader;
540
541},{}],7:[function(require,module,exports){
542'use strict';
543
544// (C) 1995-2013 Jean-loup Gailly and Mark Adler
545// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
546//
547// This software is provided 'as-is', without any express or implied
548// warranty. In no event will the authors be held liable for any damages
549// arising from the use of this software.
550//
551// Permission is granted to anyone to use this software for any purpose,
552// including commercial applications, and to alter it and redistribute it
553// freely, subject to the following restrictions:
554//
555// 1. The origin of this software must not be misrepresented; you must not
556// claim that you wrote the original software. If you use this software
557// in a product, an acknowledgment in the product documentation would be
558// appreciated but is not required.
559// 2. Altered source versions must be plainly marked as such, and must not be
560// misrepresented as being the original software.
561// 3. This notice may not be removed or altered from any source distribution.
562
563// See state defs from inflate.js
564var BAD = 30; /* got a data error -- remain here until reset */
565var TYPE = 12; /* i: waiting for type bits, including last-flag bit */
566
567/*
568 Decode literal, length, and distance codes and write out the resulting
569 literal and match bytes until either not enough input or output is
570 available, an end-of-block is encountered, or a data error is encountered.
571 When large enough input and output buffers are supplied to inflate(), for
572 example, a 16K input buffer and a 64K output buffer, more than 95% of the
573 inflate execution time is spent in this routine.
574
575 Entry assumptions:
576
577 state.mode === LEN
578 strm.avail_in >= 6
579 strm.avail_out >= 258
580 start >= strm.avail_out
581 state.bits < 8
582
583 On return, state.mode is one of:
584
585 LEN -- ran out of enough output space or enough available input
586 TYPE -- reached end of block code, inflate() to interpret next block
587 BAD -- error in block data
588
589 Notes:
590
591 - The maximum input bits used by a length/distance pair is 15 bits for the
592 length code, 5 bits for the length extra, 15 bits for the distance code,
593 and 13 bits for the distance extra. This totals 48 bits, or six bytes.
594 Therefore if strm.avail_in >= 6, then there is enough input to avoid
595 checking for available input while decoding.
596
597 - The maximum bytes that a single length/distance pair can output is 258
598 bytes, which is the maximum length that can be coded. inflate_fast()
599 requires strm.avail_out >= 258 for each loop to avoid checking for
600 output space.
601 */
602module.exports = function inflate_fast(strm, start) {
603 var state;
604 var _in; /* local strm.input */
605 var last; /* have enough input while in < last */
606 var _out; /* local strm.output */
607 var beg; /* inflate()'s initial strm.output */
608 var end; /* while out < end, enough space available */
609//#ifdef INFLATE_STRICT
610 var dmax; /* maximum distance from zlib header */
611//#endif
612 var wsize; /* window size or zero if not using window */
613 var whave; /* valid bytes in the window */
614 var wnext; /* window write index */
615 // Use `s_window` instead `window`, avoid conflict with instrumentation tools
616 var s_window; /* allocated sliding window, if wsize != 0 */
617 var hold; /* local strm.hold */
618 var bits; /* local strm.bits */
619 var lcode; /* local strm.lencode */
620 var dcode; /* local strm.distcode */
621 var lmask; /* mask for first level of length codes */
622 var dmask; /* mask for first level of distance codes */
623 var here; /* retrieved table entry */
624 var op; /* code bits, operation, extra bits, or */
625 /* window position, window bytes to copy */
626 var len; /* match length, unused bytes */
627 var dist; /* match distance */
628 var from; /* where to copy match from */
629 var from_source;
630
631
632 var input, output; // JS specific, because we have no pointers
633
634 /* copy state to local variables */
635 state = strm.state;
636 //here = state.here;
637 _in = strm.next_in;
638 input = strm.input;
639 last = _in + (strm.avail_in - 5);
640 _out = strm.next_out;
641 output = strm.output;
642 beg = _out - (start - strm.avail_out);
643 end = _out + (strm.avail_out - 257);
644//#ifdef INFLATE_STRICT
645 dmax = state.dmax;
646//#endif
647 wsize = state.wsize;
648 whave = state.whave;
649 wnext = state.wnext;
650 s_window = state.window;
651 hold = state.hold;
652 bits = state.bits;
653 lcode = state.lencode;
654 dcode = state.distcode;
655 lmask = (1 << state.lenbits) - 1;
656 dmask = (1 << state.distbits) - 1;
657
658
659 /* decode literals and length/distances until end-of-block or not enough
660 input data or output space */
661
662 top:
663 do {
664 if (bits < 15) {
665 hold += input[_in++] << bits;
666 bits += 8;
667 hold += input[_in++] << bits;
668 bits += 8;
669 }
670
671 here = lcode[hold & lmask];
672
673 dolen:
674 for (;;) { // Goto emulation
675 op = here >>> 24/*here.bits*/;
676 hold >>>= op;
677 bits -= op;
678 op = (here >>> 16) & 0xff/*here.op*/;
679 if (op === 0) { /* literal */
680 //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
681 // "inflate: literal '%c'\n" :
682 // "inflate: literal 0x%02x\n", here.val));
683 output[_out++] = here & 0xffff/*here.val*/;
684 }
685 else if (op & 16) { /* length base */
686 len = here & 0xffff/*here.val*/;
687 op &= 15; /* number of extra bits */
688 if (op) {
689 if (bits < op) {
690 hold += input[_in++] << bits;
691 bits += 8;
692 }
693 len += hold & ((1 << op) - 1);
694 hold >>>= op;
695 bits -= op;
696 }
697 //Tracevv((stderr, "inflate: length %u\n", len));
698 if (bits < 15) {
699 hold += input[_in++] << bits;
700 bits += 8;
701 hold += input[_in++] << bits;
702 bits += 8;
703 }
704 here = dcode[hold & dmask];
705
706 dodist:
707 for (;;) { // goto emulation
708 op = here >>> 24/*here.bits*/;
709 hold >>>= op;
710 bits -= op;
711 op = (here >>> 16) & 0xff/*here.op*/;
712
713 if (op & 16) { /* distance base */
714 dist = here & 0xffff/*here.val*/;
715 op &= 15; /* number of extra bits */
716 if (bits < op) {
717 hold += input[_in++] << bits;
718 bits += 8;
719 if (bits < op) {
720 hold += input[_in++] << bits;
721 bits += 8;
722 }
723 }
724 dist += hold & ((1 << op) - 1);
725//#ifdef INFLATE_STRICT
726 if (dist > dmax) {
727 strm.msg = 'invalid distance too far back';
728 state.mode = BAD;
729 break top;
730 }
731//#endif
732 hold >>>= op;
733 bits -= op;
734 //Tracevv((stderr, "inflate: distance %u\n", dist));
735 op = _out - beg; /* max distance in output */
736 if (dist > op) { /* see if copy from window */
737 op = dist - op; /* distance back in window */
738 if (op > whave) {
739 if (state.sane) {
740 strm.msg = 'invalid distance too far back';
741 state.mode = BAD;
742 break top;
743 }
744
745// (!) This block is disabled in zlib defaults,
746// don't enable it for binary compatibility
747//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
748// if (len <= op - whave) {
749// do {
750// output[_out++] = 0;
751// } while (--len);
752// continue top;
753// }
754// len -= op - whave;
755// do {
756// output[_out++] = 0;
757// } while (--op > whave);
758// if (op === 0) {
759// from = _out - dist;
760// do {
761// output[_out++] = output[from++];
762// } while (--len);
763// continue top;
764// }
765//#endif
766 }
767 from = 0; // window index
768 from_source = s_window;
769 if (wnext === 0) { /* very common case */
770 from += wsize - op;
771 if (op < len) { /* some from window */
772 len -= op;
773 do {
774 output[_out++] = s_window[from++];
775 } while (--op);
776 from = _out - dist; /* rest from output */
777 from_source = output;
778 }
779 }
780 else if (wnext < op) { /* wrap around window */
781 from += wsize + wnext - op;
782 op -= wnext;
783 if (op < len) { /* some from end of window */
784 len -= op;
785 do {
786 output[_out++] = s_window[from++];
787 } while (--op);
788 from = 0;
789 if (wnext < len) { /* some from start of window */
790 op = wnext;
791 len -= op;
792 do {
793 output[_out++] = s_window[from++];
794 } while (--op);
795 from = _out - dist; /* rest from output */
796 from_source = output;
797 }
798 }
799 }
800 else { /* contiguous in window */
801 from += wnext - op;
802 if (op < len) { /* some from window */
803 len -= op;
804 do {
805 output[_out++] = s_window[from++];
806 } while (--op);
807 from = _out - dist; /* rest from output */
808 from_source = output;
809 }
810 }
811 while (len > 2) {
812 output[_out++] = from_source[from++];
813 output[_out++] = from_source[from++];
814 output[_out++] = from_source[from++];
815 len -= 3;
816 }
817 if (len) {
818 output[_out++] = from_source[from++];
819 if (len > 1) {
820 output[_out++] = from_source[from++];
821 }
822 }
823 }
824 else {
825 from = _out - dist; /* copy direct from output */
826 do { /* minimum length is three */
827 output[_out++] = output[from++];
828 output[_out++] = output[from++];
829 output[_out++] = output[from++];
830 len -= 3;
831 } while (len > 2);
832 if (len) {
833 output[_out++] = output[from++];
834 if (len > 1) {
835 output[_out++] = output[from++];
836 }
837 }
838 }
839 }
840 else if ((op & 64) === 0) { /* 2nd level distance code */
841 here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
842 continue dodist;
843 }
844 else {
845 strm.msg = 'invalid distance code';
846 state.mode = BAD;
847 break top;
848 }
849
850 break; // need to emulate goto via "continue"
851 }
852 }
853 else if ((op & 64) === 0) { /* 2nd level length code */
854 here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
855 continue dolen;
856 }
857 else if (op & 32) { /* end-of-block */
858 //Tracevv((stderr, "inflate: end of block\n"));
859 state.mode = TYPE;
860 break top;
861 }
862 else {
863 strm.msg = 'invalid literal/length code';
864 state.mode = BAD;
865 break top;
866 }
867
868 break; // need to emulate goto via "continue"
869 }
870 } while (_in < last && _out < end);
871
872 /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
873 len = bits >> 3;
874 _in -= len;
875 bits -= len << 3;
876 hold &= (1 << bits) - 1;
877
878 /* update state and return */
879 strm.next_in = _in;
880 strm.next_out = _out;
881 strm.avail_in = (_in < last ? 5 + (last - _in) : 5 - (_in - last));
882 strm.avail_out = (_out < end ? 257 + (end - _out) : 257 - (_out - end));
883 state.hold = hold;
884 state.bits = bits;
885 return;
886};
887
888},{}],8:[function(require,module,exports){
889'use strict';
890
891// (C) 1995-2013 Jean-loup Gailly and Mark Adler
892// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
893//
894// This software is provided 'as-is', without any express or implied
895// warranty. In no event will the authors be held liable for any damages
896// arising from the use of this software.
897//
898// Permission is granted to anyone to use this software for any purpose,
899// including commercial applications, and to alter it and redistribute it
900// freely, subject to the following restrictions:
901//
902// 1. The origin of this software must not be misrepresented; you must not
903// claim that you wrote the original software. If you use this software
904// in a product, an acknowledgment in the product documentation would be
905// appreciated but is not required.
906// 2. Altered source versions must be plainly marked as such, and must not be
907// misrepresented as being the original software.
908// 3. This notice may not be removed or altered from any source distribution.
909
910var utils = require('../utils/common');
911var adler32 = require('./adler32');
912var crc32 = require('./crc32');
913var inflate_fast = require('./inffast');
914var inflate_table = require('./inftrees');
915
916var CODES = 0;
917var LENS = 1;
918var DISTS = 2;
919
920/* Public constants ==========================================================*/
921/* ===========================================================================*/
922
923
924/* Allowed flush values; see deflate() and inflate() below for details */
925//var Z_NO_FLUSH = 0;
926//var Z_PARTIAL_FLUSH = 1;
927//var Z_SYNC_FLUSH = 2;
928//var Z_FULL_FLUSH = 3;
929var Z_FINISH = 4;
930var Z_BLOCK = 5;
931var Z_TREES = 6;
932
933
934/* Return codes for the compression/decompression functions. Negative values
935 * are errors, positive values are used for special but normal events.
936 */
937var Z_OK = 0;
938var Z_STREAM_END = 1;
939var Z_NEED_DICT = 2;
940//var Z_ERRNO = -1;
941var Z_STREAM_ERROR = -2;
942var Z_DATA_ERROR = -3;
943var Z_MEM_ERROR = -4;
944var Z_BUF_ERROR = -5;
945//var Z_VERSION_ERROR = -6;
946
947/* The deflate compression method */
948var Z_DEFLATED = 8;
949
950
951/* STATES ====================================================================*/
952/* ===========================================================================*/
953
954
955var HEAD = 1; /* i: waiting for magic header */
956var FLAGS = 2; /* i: waiting for method and flags (gzip) */
957var TIME = 3; /* i: waiting for modification time (gzip) */
958var OS = 4; /* i: waiting for extra flags and operating system (gzip) */
959var EXLEN = 5; /* i: waiting for extra length (gzip) */
960var EXTRA = 6; /* i: waiting for extra bytes (gzip) */
961var NAME = 7; /* i: waiting for end of file name (gzip) */
962var COMMENT = 8; /* i: waiting for end of comment (gzip) */
963var HCRC = 9; /* i: waiting for header crc (gzip) */
964var DICTID = 10; /* i: waiting for dictionary check value */
965var DICT = 11; /* waiting for inflateSetDictionary() call */
966var TYPE = 12; /* i: waiting for type bits, including last-flag bit */
967var TYPEDO = 13; /* i: same, but skip check to exit inflate on new block */
968var STORED = 14; /* i: waiting for stored size (length and complement) */
969var COPY_ = 15; /* i/o: same as COPY below, but only first time in */
970var COPY = 16; /* i/o: waiting for input or output to copy stored block */
971var TABLE = 17; /* i: waiting for dynamic block table lengths */
972var LENLENS = 18; /* i: waiting for code length code lengths */
973var CODELENS = 19; /* i: waiting for length/lit and distance code lengths */
974var LEN_ = 20; /* i: same as LEN below, but only first time in */
975var LEN = 21; /* i: waiting for length/lit/eob code */
976var LENEXT = 22; /* i: waiting for length extra bits */
977var DIST = 23; /* i: waiting for distance code */
978var DISTEXT = 24; /* i: waiting for distance extra bits */
979var MATCH = 25; /* o: waiting for output space to copy string */
980var LIT = 26; /* o: waiting for output space to write literal */
981var CHECK = 27; /* i: waiting for 32-bit check value */
982var LENGTH = 28; /* i: waiting for 32-bit length (gzip) */
983var DONE = 29; /* finished check, done -- remain here until reset */
984var BAD = 30; /* got a data error -- remain here until reset */
985var MEM = 31; /* got an inflate() memory error -- remain here until reset */
986var SYNC = 32; /* looking for synchronization bytes to restart inflate() */
987
988/* ===========================================================================*/
989
990
991
992var ENOUGH_LENS = 852;
993var ENOUGH_DISTS = 592;
994//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
995
996var MAX_WBITS = 15;
997/* 32K LZ77 window */
998var DEF_WBITS = MAX_WBITS;
999
1000
1001function zswap32(q) {
1002 return (((q >>> 24) & 0xff) +
1003 ((q >>> 8) & 0xff00) +
1004 ((q & 0xff00) << 8) +
1005 ((q & 0xff) << 24));
1006}
1007
1008
1009function InflateState() {
1010 this.mode = 0; /* current inflate mode */
1011 this.last = false; /* true if processing last block */
1012 this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */
1013 this.havedict = false; /* true if dictionary provided */
1014 this.flags = 0; /* gzip header method and flags (0 if zlib) */
1015 this.dmax = 0; /* zlib header max distance (INFLATE_STRICT) */
1016 this.check = 0; /* protected copy of check value */
1017 this.total = 0; /* protected copy of output count */
1018 // TODO: may be {}
1019 this.head = null; /* where to save gzip header information */
1020
1021 /* sliding window */
1022 this.wbits = 0; /* log base 2 of requested window size */
1023 this.wsize = 0; /* window size or zero if not using window */
1024 this.whave = 0; /* valid bytes in the window */
1025 this.wnext = 0; /* window write index */
1026 this.window = null; /* allocated sliding window, if needed */
1027
1028 /* bit accumulator */
1029 this.hold = 0; /* input bit accumulator */
1030 this.bits = 0; /* number of bits in "in" */
1031
1032 /* for string and stored block copying */
1033 this.length = 0; /* literal or length of data to copy */
1034 this.offset = 0; /* distance back to copy string from */
1035
1036 /* for table and code decoding */
1037 this.extra = 0; /* extra bits needed */
1038
1039 /* fixed and dynamic code tables */
1040 this.lencode = null; /* starting table for length/literal codes */
1041 this.distcode = null; /* starting table for distance codes */
1042 this.lenbits = 0; /* index bits for lencode */
1043 this.distbits = 0; /* index bits for distcode */
1044
1045 /* dynamic table building */
1046 this.ncode = 0; /* number of code length code lengths */
1047 this.nlen = 0; /* number of length code lengths */
1048 this.ndist = 0; /* number of distance code lengths */
1049 this.have = 0; /* number of code lengths in lens[] */
1050 this.next = null; /* next available space in codes[] */
1051
1052 this.lens = new utils.Buf16(320); /* temporary storage for code lengths */
1053 this.work = new utils.Buf16(288); /* work area for code table building */
1054
1055 /*
1056 because we don't have pointers in js, we use lencode and distcode directly
1057 as buffers so we don't need codes
1058 */
1059 //this.codes = new utils.Buf32(ENOUGH); /* space for code tables */
1060 this.lendyn = null; /* dynamic table for length/literal codes (JS specific) */
1061 this.distdyn = null; /* dynamic table for distance codes (JS specific) */
1062 this.sane = 0; /* if false, allow invalid distance too far */
1063 this.back = 0; /* bits back of last unprocessed length/lit */
1064 this.was = 0; /* initial length of match */
1065}
1066
1067function inflateResetKeep(strm) {
1068 var state;
1069
1070 if (!strm || !strm.state) { return Z_STREAM_ERROR; }
1071 state = strm.state;
1072 strm.total_in = strm.total_out = state.total = 0;
1073 strm.msg = ''; /*Z_NULL*/
1074 if (state.wrap) { /* to support ill-conceived Java test suite */
1075 strm.adler = state.wrap & 1;
1076 }
1077 state.mode = HEAD;
1078 state.last = 0;
1079 state.havedict = 0;
1080 state.dmax = 32768;
1081 state.head = null/*Z_NULL*/;
1082 state.hold = 0;
1083 state.bits = 0;
1084 //state.lencode = state.distcode = state.next = state.codes;
1085 state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS);
1086 state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS);
1087
1088 state.sane = 1;
1089 state.back = -1;
1090 //Tracev((stderr, "inflate: reset\n"));
1091 return Z_OK;
1092}
1093
1094function inflateReset(strm) {
1095 var state;
1096
1097 if (!strm || !strm.state) { return Z_STREAM_ERROR; }
1098 state = strm.state;
1099 state.wsize = 0;
1100 state.whave = 0;
1101 state.wnext = 0;
1102 return inflateResetKeep(strm);
1103
1104}
1105
1106function inflateReset2(strm, windowBits) {
1107 var wrap;
1108 var state;
1109
1110 /* get the state */
1111 if (!strm || !strm.state) { return Z_STREAM_ERROR; }
1112 state = strm.state;
1113
1114 /* extract wrap request from windowBits parameter */
1115 if (windowBits < 0) {
1116 wrap = 0;
1117 windowBits = -windowBits;
1118 }
1119 else {
1120 wrap = (windowBits >> 4) + 1;
1121 if (windowBits < 48) {
1122 windowBits &= 15;
1123 }
1124 }
1125
1126 /* set number of window bits, free window if different */
1127 if (windowBits && (windowBits < 8 || windowBits > 15)) {
1128 return Z_STREAM_ERROR;
1129 }
1130 if (state.window !== null && state.wbits !== windowBits) {
1131 state.window = null;
1132 }
1133
1134 /* update state and reset the rest of it */
1135 state.wrap = wrap;
1136 state.wbits = windowBits;
1137 return inflateReset(strm);
1138}
1139
1140function inflateInit2(strm, windowBits) {
1141 var ret;
1142 var state;
1143
1144 if (!strm) { return Z_STREAM_ERROR; }
1145 //strm.msg = Z_NULL; /* in case we return an error */
1146
1147 state = new InflateState();
1148
1149 //if (state === Z_NULL) return Z_MEM_ERROR;
1150 //Tracev((stderr, "inflate: allocated\n"));
1151 strm.state = state;
1152 state.window = null/*Z_NULL*/;
1153 ret = inflateReset2(strm, windowBits);
1154 if (ret !== Z_OK) {
1155 strm.state = null/*Z_NULL*/;
1156 }
1157 return ret;
1158}
1159
1160function inflateInit(strm) {
1161 return inflateInit2(strm, DEF_WBITS);
1162}
1163
1164
1165/*
1166 Return state with length and distance decoding tables and index sizes set to
1167 fixed code decoding. Normally this returns fixed tables from inffixed.h.
1168 If BUILDFIXED is defined, then instead this routine builds the tables the
1169 first time it's called, and returns those tables the first time and
1170 thereafter. This reduces the size of the code by about 2K bytes, in
1171 exchange for a little execution time. However, BUILDFIXED should not be
1172 used for threaded applications, since the rewriting of the tables and virgin
1173 may not be thread-safe.
1174 */
1175var virgin = true;
1176
1177var lenfix, distfix; // We have no pointers in JS, so keep tables separate
1178
1179function fixedtables(state) {
1180 /* build fixed huffman tables if first call (may not be thread safe) */
1181 if (virgin) {
1182 var sym;
1183
1184 lenfix = new utils.Buf32(512);
1185 distfix = new utils.Buf32(32);
1186
1187 /* literal/length table */
1188 sym = 0;
1189 while (sym < 144) { state.lens[sym++] = 8; }
1190 while (sym < 256) { state.lens[sym++] = 9; }
1191 while (sym < 280) { state.lens[sym++] = 7; }
1192 while (sym < 288) { state.lens[sym++] = 8; }
1193
1194 inflate_table(LENS, state.lens, 0, 288, lenfix, 0, state.work, { bits: 9 });
1195
1196 /* distance table */
1197 sym = 0;
1198 while (sym < 32) { state.lens[sym++] = 5; }
1199
1200 inflate_table(DISTS, state.lens, 0, 32, distfix, 0, state.work, { bits: 5 });
1201
1202 /* do this just once */
1203 virgin = false;
1204 }
1205
1206 state.lencode = lenfix;
1207 state.lenbits = 9;
1208 state.distcode = distfix;
1209 state.distbits = 5;
1210}
1211
1212
1213/*
1214 Update the window with the last wsize (normally 32K) bytes written before
1215 returning. If window does not exist yet, create it. This is only called
1216 when a window is already in use, or when output has been written during this
1217 inflate call, but the end of the deflate stream has not been reached yet.
1218 It is also called to create a window for dictionary data when a dictionary
1219 is loaded.
1220
1221 Providing output buffers larger than 32K to inflate() should provide a speed
1222 advantage, since only the last 32K of output is copied to the sliding window
1223 upon return from inflate(), and since all distances after the first 32K of
1224 output will fall in the output data, making match copies simpler and faster.
1225 The advantage may be dependent on the size of the processor's data caches.
1226 */
1227function updatewindow(strm, src, end, copy) {
1228 var dist;
1229 var state = strm.state;
1230
1231 /* if it hasn't been done already, allocate space for the window */
1232 if (state.window === null) {
1233 state.wsize = 1 << state.wbits;
1234 state.wnext = 0;
1235 state.whave = 0;
1236
1237 state.window = new utils.Buf8(state.wsize);
1238 }
1239
1240 /* copy state->wsize or less output bytes into the circular window */
1241 if (copy >= state.wsize) {
1242 utils.arraySet(state.window, src, end - state.wsize, state.wsize, 0);
1243 state.wnext = 0;
1244 state.whave = state.wsize;
1245 }
1246 else {
1247 dist = state.wsize - state.wnext;
1248 if (dist > copy) {
1249 dist = copy;
1250 }
1251 //zmemcpy(state->window + state->wnext, end - copy, dist);
1252 utils.arraySet(state.window, src, end - copy, dist, state.wnext);
1253 copy -= dist;
1254 if (copy) {
1255 //zmemcpy(state->window, end - copy, copy);
1256 utils.arraySet(state.window, src, end - copy, copy, 0);
1257 state.wnext = copy;
1258 state.whave = state.wsize;
1259 }
1260 else {
1261 state.wnext += dist;
1262 if (state.wnext === state.wsize) { state.wnext = 0; }
1263 if (state.whave < state.wsize) { state.whave += dist; }
1264 }
1265 }
1266 return 0;
1267}
1268
1269function inflate(strm, flush) {
1270 var state;
1271 var input, output; // input/output buffers
1272 var next; /* next input INDEX */
1273 var put; /* next output INDEX */
1274 var have, left; /* available input and output */
1275 var hold; /* bit buffer */
1276 var bits; /* bits in bit buffer */
1277 var _in, _out; /* save starting available input and output */
1278 var copy; /* number of stored or match bytes to copy */
1279 var from; /* where to copy match bytes from */
1280 var from_source;
1281 var here = 0; /* current decoding table entry */
1282 var here_bits, here_op, here_val; // paked "here" denormalized (JS specific)
1283 //var last; /* parent table entry */
1284 var last_bits, last_op, last_val; // paked "last" denormalized (JS specific)
1285 var len; /* length to copy for repeats, bits to drop */
1286 var ret; /* return code */
1287 var hbuf = new utils.Buf8(4); /* buffer for gzip header crc calculation */
1288 var opts;
1289
1290 var n; // temporary var for NEED_BITS
1291
1292 var order = /* permutation of code lengths */
1293 [ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 ];
1294
1295
1296 if (!strm || !strm.state || !strm.output ||
1297 (!strm.input && strm.avail_in !== 0)) {
1298 return Z_STREAM_ERROR;
1299 }
1300
1301 state = strm.state;
1302 if (state.mode === TYPE) { state.mode = TYPEDO; } /* skip check */
1303
1304
1305 //--- LOAD() ---
1306 put = strm.next_out;
1307 output = strm.output;
1308 left = strm.avail_out;
1309 next = strm.next_in;
1310 input = strm.input;
1311 have = strm.avail_in;
1312 hold = state.hold;
1313 bits = state.bits;
1314 //---
1315
1316 _in = have;
1317 _out = left;
1318 ret = Z_OK;
1319
1320 inf_leave: // goto emulation
1321 for (;;) {
1322 switch (state.mode) {
1323 case HEAD:
1324 if (state.wrap === 0) {
1325 state.mode = TYPEDO;
1326 break;
1327 }
1328 //=== NEEDBITS(16);
1329 while (bits < 16) {
1330 if (have === 0) { break inf_leave; }
1331 have--;
1332 hold += input[next++] << bits;
1333 bits += 8;
1334 }
1335 //===//
1336 if ((state.wrap & 2) && hold === 0x8b1f) { /* gzip header */
1337 state.check = 0/*crc32(0L, Z_NULL, 0)*/;
1338 //=== CRC2(state.check, hold);
1339 hbuf[0] = hold & 0xff;
1340 hbuf[1] = (hold >>> 8) & 0xff;
1341 state.check = crc32(state.check, hbuf, 2, 0);
1342 //===//
1343
1344 //=== INITBITS();
1345 hold = 0;
1346 bits = 0;
1347 //===//
1348 state.mode = FLAGS;
1349 break;
1350 }
1351 state.flags = 0; /* expect zlib header */
1352 if (state.head) {
1353 state.head.done = false;
1354 }
1355 if (!(state.wrap & 1) || /* check if zlib header allowed */
1356 (((hold & 0xff)/*BITS(8)*/ << 8) + (hold >> 8)) % 31) {
1357 strm.msg = 'incorrect header check';
1358 state.mode = BAD;
1359 break;
1360 }
1361 if ((hold & 0x0f)/*BITS(4)*/ !== Z_DEFLATED) {
1362 strm.msg = 'unknown compression method';
1363 state.mode = BAD;
1364 break;
1365 }
1366 //--- DROPBITS(4) ---//
1367 hold >>>= 4;
1368 bits -= 4;
1369 //---//
1370 len = (hold & 0x0f)/*BITS(4)*/ + 8;
1371 if (state.wbits === 0) {
1372 state.wbits = len;
1373 }
1374 else if (len > state.wbits) {
1375 strm.msg = 'invalid window size';
1376 state.mode = BAD;
1377 break;
1378 }
1379 state.dmax = 1 << len;
1380 //Tracev((stderr, "inflate: zlib header ok\n"));
1381 strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
1382 state.mode = hold & 0x200 ? DICTID : TYPE;
1383 //=== INITBITS();
1384 hold = 0;
1385 bits = 0;
1386 //===//
1387 break;
1388 case FLAGS:
1389 //=== NEEDBITS(16); */
1390 while (bits < 16) {
1391 if (have === 0) { break inf_leave; }
1392 have--;
1393 hold += input[next++] << bits;
1394 bits += 8;
1395 }
1396 //===//
1397 state.flags = hold;
1398 if ((state.flags & 0xff) !== Z_DEFLATED) {
1399 strm.msg = 'unknown compression method';
1400 state.mode = BAD;
1401 break;
1402 }
1403 if (state.flags & 0xe000) {
1404 strm.msg = 'unknown header flags set';
1405 state.mode = BAD;
1406 break;
1407 }
1408 if (state.head) {
1409 state.head.text = ((hold >> 8) & 1);
1410 }
1411 if (state.flags & 0x0200) {
1412 //=== CRC2(state.check, hold);
1413 hbuf[0] = hold & 0xff;
1414 hbuf[1] = (hold >>> 8) & 0xff;
1415 state.check = crc32(state.check, hbuf, 2, 0);
1416 //===//
1417 }
1418 //=== INITBITS();
1419 hold = 0;
1420 bits = 0;
1421 //===//
1422 state.mode = TIME;
1423 /* falls through */
1424 case TIME:
1425 //=== NEEDBITS(32); */
1426 while (bits < 32) {
1427 if (have === 0) { break inf_leave; }
1428 have--;
1429 hold += input[next++] << bits;
1430 bits += 8;
1431 }
1432 //===//
1433 if (state.head) {
1434 state.head.time = hold;
1435 }
1436 if (state.flags & 0x0200) {
1437 //=== CRC4(state.check, hold)
1438 hbuf[0] = hold & 0xff;
1439 hbuf[1] = (hold >>> 8) & 0xff;
1440 hbuf[2] = (hold >>> 16) & 0xff;
1441 hbuf[3] = (hold >>> 24) & 0xff;
1442 state.check = crc32(state.check, hbuf, 4, 0);
1443 //===
1444 }
1445 //=== INITBITS();
1446 hold = 0;
1447 bits = 0;
1448 //===//
1449 state.mode = OS;
1450 /* falls through */
1451 case OS:
1452 //=== NEEDBITS(16); */
1453 while (bits < 16) {
1454 if (have === 0) { break inf_leave; }
1455 have--;
1456 hold += input[next++] << bits;
1457 bits += 8;
1458 }
1459 //===//
1460 if (state.head) {
1461 state.head.xflags = (hold & 0xff);
1462 state.head.os = (hold >> 8);
1463 }
1464 if (state.flags & 0x0200) {
1465 //=== CRC2(state.check, hold);
1466 hbuf[0] = hold & 0xff;
1467 hbuf[1] = (hold >>> 8) & 0xff;
1468 state.check = crc32(state.check, hbuf, 2, 0);
1469 //===//
1470 }
1471 //=== INITBITS();
1472 hold = 0;
1473 bits = 0;
1474 //===//
1475 state.mode = EXLEN;
1476 /* falls through */
1477 case EXLEN:
1478 if (state.flags & 0x0400) {
1479 //=== NEEDBITS(16); */
1480 while (bits < 16) {
1481 if (have === 0) { break inf_leave; }
1482 have--;
1483 hold += input[next++] << bits;
1484 bits += 8;
1485 }
1486 //===//
1487 state.length = hold;
1488 if (state.head) {
1489 state.head.extra_len = hold;
1490 }
1491 if (state.flags & 0x0200) {
1492 //=== CRC2(state.check, hold);
1493 hbuf[0] = hold & 0xff;
1494 hbuf[1] = (hold >>> 8) & 0xff;
1495 state.check = crc32(state.check, hbuf, 2, 0);
1496 //===//
1497 }
1498 //=== INITBITS();
1499 hold = 0;
1500 bits = 0;
1501 //===//
1502 }
1503 else if (state.head) {
1504 state.head.extra = null/*Z_NULL*/;
1505 }
1506 state.mode = EXTRA;
1507 /* falls through */
1508 case EXTRA:
1509 if (state.flags & 0x0400) {
1510 copy = state.length;
1511 if (copy > have) { copy = have; }
1512 if (copy) {
1513 if (state.head) {
1514 len = state.head.extra_len - state.length;
1515 if (!state.head.extra) {
1516 // Use untyped array for more convenient processing later
1517 state.head.extra = new Array(state.head.extra_len);
1518 }
1519 utils.arraySet(
1520 state.head.extra,
1521 input,
1522 next,
1523 // extra field is limited to 65536 bytes
1524 // - no need for additional size check
1525 copy,
1526 /*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
1527 len
1528 );
1529 //zmemcpy(state.head.extra + len, next,
1530 // len + copy > state.head.extra_max ?
1531 // state.head.extra_max - len : copy);
1532 }
1533 if (state.flags & 0x0200) {
1534 state.check = crc32(state.check, input, copy, next);
1535 }
1536 have -= copy;
1537 next += copy;
1538 state.length -= copy;
1539 }
1540 if (state.length) { break inf_leave; }
1541 }
1542 state.length = 0;
1543 state.mode = NAME;
1544 /* falls through */
1545 case NAME:
1546 if (state.flags & 0x0800) {
1547 if (have === 0) { break inf_leave; }
1548 copy = 0;
1549 do {
1550 // TODO: 2 or 1 bytes?
1551 len = input[next + copy++];
1552 /* use constant limit because in js we should not preallocate memory */
1553 if (state.head && len &&
1554 (state.length < 65536 /*state.head.name_max*/)) {
1555 state.head.name += String.fromCharCode(len);
1556 }
1557 } while (len && copy < have);
1558
1559 if (state.flags & 0x0200) {
1560 state.check = crc32(state.check, input, copy, next);
1561 }
1562 have -= copy;
1563 next += copy;
1564 if (len) { break inf_leave; }
1565 }
1566 else if (state.head) {
1567 state.head.name = null;
1568 }
1569 state.length = 0;
1570 state.mode = COMMENT;
1571 /* falls through */
1572 case COMMENT:
1573 if (state.flags & 0x1000) {
1574 if (have === 0) { break inf_leave; }
1575 copy = 0;
1576 do {
1577 len = input[next + copy++];
1578 /* use constant limit because in js we should not preallocate memory */
1579 if (state.head && len &&
1580 (state.length < 65536 /*state.head.comm_max*/)) {
1581 state.head.comment += String.fromCharCode(len);
1582 }
1583 } while (len && copy < have);
1584 if (state.flags & 0x0200) {
1585 state.check = crc32(state.check, input, copy, next);
1586 }
1587 have -= copy;
1588 next += copy;
1589 if (len) { break inf_leave; }
1590 }
1591 else if (state.head) {
1592 state.head.comment = null;
1593 }
1594 state.mode = HCRC;
1595 /* falls through */
1596 case HCRC:
1597 if (state.flags & 0x0200) {
1598 //=== NEEDBITS(16); */
1599 while (bits < 16) {
1600 if (have === 0) { break inf_leave; }
1601 have--;
1602 hold += input[next++] << bits;
1603 bits += 8;
1604 }
1605 //===//
1606 if (hold !== (state.check & 0xffff)) {
1607 strm.msg = 'header crc mismatch';
1608 state.mode = BAD;
1609 break;
1610 }
1611 //=== INITBITS();
1612 hold = 0;
1613 bits = 0;
1614 //===//
1615 }
1616 if (state.head) {
1617 state.head.hcrc = ((state.flags >> 9) & 1);
1618 state.head.done = true;
1619 }
1620 strm.adler = state.check = 0;
1621 state.mode = TYPE;
1622 break;
1623 case DICTID:
1624 //=== NEEDBITS(32); */
1625 while (bits < 32) {
1626 if (have === 0) { break inf_leave; }
1627 have--;
1628 hold += input[next++] << bits;
1629 bits += 8;
1630 }
1631 //===//
1632 strm.adler = state.check = zswap32(hold);
1633 //=== INITBITS();
1634 hold = 0;
1635 bits = 0;
1636 //===//
1637 state.mode = DICT;
1638 /* falls through */
1639 case DICT:
1640 if (state.havedict === 0) {
1641 //--- RESTORE() ---
1642 strm.next_out = put;
1643 strm.avail_out = left;
1644 strm.next_in = next;
1645 strm.avail_in = have;
1646 state.hold = hold;
1647 state.bits = bits;
1648 //---
1649 return Z_NEED_DICT;
1650 }
1651 strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
1652 state.mode = TYPE;
1653 /* falls through */
1654 case TYPE:
1655 if (flush === Z_BLOCK || flush === Z_TREES) { break inf_leave; }
1656 /* falls through */
1657 case TYPEDO:
1658 if (state.last) {
1659 //--- BYTEBITS() ---//
1660 hold >>>= bits & 7;
1661 bits -= bits & 7;
1662 //---//
1663 state.mode = CHECK;
1664 break;
1665 }
1666 //=== NEEDBITS(3); */
1667 while (bits < 3) {
1668 if (have === 0) { break inf_leave; }
1669 have--;
1670 hold += input[next++] << bits;
1671 bits += 8;
1672 }
1673 //===//
1674 state.last = (hold & 0x01)/*BITS(1)*/;
1675 //--- DROPBITS(1) ---//
1676 hold >>>= 1;
1677 bits -= 1;
1678 //---//
1679
1680 switch ((hold & 0x03)/*BITS(2)*/) {
1681 case 0: /* stored block */
1682 //Tracev((stderr, "inflate: stored block%s\n",
1683 // state.last ? " (last)" : ""));
1684 state.mode = STORED;
1685 break;
1686 case 1: /* fixed block */
1687 fixedtables(state);
1688 //Tracev((stderr, "inflate: fixed codes block%s\n",
1689 // state.last ? " (last)" : ""));
1690 state.mode = LEN_; /* decode codes */
1691 if (flush === Z_TREES) {
1692 //--- DROPBITS(2) ---//
1693 hold >>>= 2;
1694 bits -= 2;
1695 //---//
1696 break inf_leave;
1697 }
1698 break;
1699 case 2: /* dynamic block */
1700 //Tracev((stderr, "inflate: dynamic codes block%s\n",
1701 // state.last ? " (last)" : ""));
1702 state.mode = TABLE;
1703 break;
1704 case 3:
1705 strm.msg = 'invalid block type';
1706 state.mode = BAD;
1707 }
1708 //--- DROPBITS(2) ---//
1709 hold >>>= 2;
1710 bits -= 2;
1711 //---//
1712 break;
1713 case STORED:
1714 //--- BYTEBITS() ---// /* go to byte boundary */
1715 hold >>>= bits & 7;
1716 bits -= bits & 7;
1717 //---//
1718 //=== NEEDBITS(32); */
1719 while (bits < 32) {
1720 if (have === 0) { break inf_leave; }
1721 have--;
1722 hold += input[next++] << bits;
1723 bits += 8;
1724 }
1725 //===//
1726 if ((hold & 0xffff) !== ((hold >>> 16) ^ 0xffff)) {
1727 strm.msg = 'invalid stored block lengths';
1728 state.mode = BAD;
1729 break;
1730 }
1731 state.length = hold & 0xffff;
1732 //Tracev((stderr, "inflate: stored length %u\n",
1733 // state.length));
1734 //=== INITBITS();
1735 hold = 0;
1736 bits = 0;
1737 //===//
1738 state.mode = COPY_;
1739 if (flush === Z_TREES) { break inf_leave; }
1740 /* falls through */
1741 case COPY_:
1742 state.mode = COPY;
1743 /* falls through */
1744 case COPY:
1745 copy = state.length;
1746 if (copy) {
1747 if (copy > have) { copy = have; }
1748 if (copy > left) { copy = left; }
1749 if (copy === 0) { break inf_leave; }
1750 //--- zmemcpy(put, next, copy); ---
1751 utils.arraySet(output, input, next, copy, put);
1752 //---//
1753 have -= copy;
1754 next += copy;
1755 left -= copy;
1756 put += copy;
1757 state.length -= copy;
1758 break;
1759 }
1760 //Tracev((stderr, "inflate: stored end\n"));
1761 state.mode = TYPE;
1762 break;
1763 case TABLE:
1764 //=== NEEDBITS(14); */
1765 while (bits < 14) {
1766 if (have === 0) { break inf_leave; }
1767 have--;
1768 hold += input[next++] << bits;
1769 bits += 8;
1770 }
1771 //===//
1772 state.nlen = (hold & 0x1f)/*BITS(5)*/ + 257;
1773 //--- DROPBITS(5) ---//
1774 hold >>>= 5;
1775 bits -= 5;
1776 //---//
1777 state.ndist = (hold & 0x1f)/*BITS(5)*/ + 1;
1778 //--- DROPBITS(5) ---//
1779 hold >>>= 5;
1780 bits -= 5;
1781 //---//
1782 state.ncode = (hold & 0x0f)/*BITS(4)*/ + 4;
1783 //--- DROPBITS(4) ---//
1784 hold >>>= 4;
1785 bits -= 4;
1786 //---//
1787//#ifndef PKZIP_BUG_WORKAROUND
1788 if (state.nlen > 286 || state.ndist > 30) {
1789 strm.msg = 'too many length or distance symbols';
1790 state.mode = BAD;
1791 break;
1792 }
1793//#endif
1794 //Tracev((stderr, "inflate: table sizes ok\n"));
1795 state.have = 0;
1796 state.mode = LENLENS;
1797 /* falls through */
1798 case LENLENS:
1799 while (state.have < state.ncode) {
1800 //=== NEEDBITS(3);
1801 while (bits < 3) {
1802 if (have === 0) { break inf_leave; }
1803 have--;
1804 hold += input[next++] << bits;
1805 bits += 8;
1806 }
1807 //===//
1808 state.lens[order[state.have++]] = (hold & 0x07);//BITS(3);
1809 //--- DROPBITS(3) ---//
1810 hold >>>= 3;
1811 bits -= 3;
1812 //---//
1813 }
1814 while (state.have < 19) {
1815 state.lens[order[state.have++]] = 0;
1816 }
1817 // We have separate tables & no pointers. 2 commented lines below not needed.
1818 //state.next = state.codes;
1819 //state.lencode = state.next;
1820 // Switch to use dynamic table
1821 state.lencode = state.lendyn;
1822 state.lenbits = 7;
1823
1824 opts = { bits: state.lenbits };
1825 ret = inflate_table(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts);
1826 state.lenbits = opts.bits;
1827
1828 if (ret) {
1829 strm.msg = 'invalid code lengths set';
1830 state.mode = BAD;
1831 break;
1832 }
1833 //Tracev((stderr, "inflate: code lengths ok\n"));
1834 state.have = 0;
1835 state.mode = CODELENS;
1836 /* falls through */
1837 case CODELENS:
1838 while (state.have < state.nlen + state.ndist) {
1839 for (;;) {
1840 here = state.lencode[hold & ((1 << state.lenbits) - 1)];/*BITS(state.lenbits)*/
1841 here_bits = here >>> 24;
1842 here_op = (here >>> 16) & 0xff;
1843 here_val = here & 0xffff;
1844
1845 if ((here_bits) <= bits) { break; }
1846 //--- PULLBYTE() ---//
1847 if (have === 0) { break inf_leave; }
1848 have--;
1849 hold += input[next++] << bits;
1850 bits += 8;
1851 //---//
1852 }
1853 if (here_val < 16) {
1854 //--- DROPBITS(here.bits) ---//
1855 hold >>>= here_bits;
1856 bits -= here_bits;
1857 //---//
1858 state.lens[state.have++] = here_val;
1859 }
1860 else {
1861 if (here_val === 16) {
1862 //=== NEEDBITS(here.bits + 2);
1863 n = here_bits + 2;
1864 while (bits < n) {
1865 if (have === 0) { break inf_leave; }
1866 have--;
1867 hold += input[next++] << bits;
1868 bits += 8;
1869 }
1870 //===//
1871 //--- DROPBITS(here.bits) ---//
1872 hold >>>= here_bits;
1873 bits -= here_bits;
1874 //---//
1875 if (state.have === 0) {
1876 strm.msg = 'invalid bit length repeat';
1877 state.mode = BAD;
1878 break;
1879 }
1880 len = state.lens[state.have - 1];
1881 copy = 3 + (hold & 0x03);//BITS(2);
1882 //--- DROPBITS(2) ---//
1883 hold >>>= 2;
1884 bits -= 2;
1885 //---//
1886 }
1887 else if (here_val === 17) {
1888 //=== NEEDBITS(here.bits + 3);
1889 n = here_bits + 3;
1890 while (bits < n) {
1891 if (have === 0) { break inf_leave; }
1892 have--;
1893 hold += input[next++] << bits;
1894 bits += 8;
1895 }
1896 //===//
1897 //--- DROPBITS(here.bits) ---//
1898 hold >>>= here_bits;
1899 bits -= here_bits;
1900 //---//
1901 len = 0;
1902 copy = 3 + (hold & 0x07);//BITS(3);
1903 //--- DROPBITS(3) ---//
1904 hold >>>= 3;
1905 bits -= 3;
1906 //---//
1907 }
1908 else {
1909 //=== NEEDBITS(here.bits + 7);
1910 n = here_bits + 7;
1911 while (bits < n) {
1912 if (have === 0) { break inf_leave; }
1913 have--;
1914 hold += input[next++] << bits;
1915 bits += 8;
1916 }
1917 //===//
1918 //--- DROPBITS(here.bits) ---//
1919 hold >>>= here_bits;
1920 bits -= here_bits;
1921 //---//
1922 len = 0;
1923 copy = 11 + (hold & 0x7f);//BITS(7);
1924 //--- DROPBITS(7) ---//
1925 hold >>>= 7;
1926 bits -= 7;
1927 //---//
1928 }
1929 if (state.have + copy > state.nlen + state.ndist) {
1930 strm.msg = 'invalid bit length repeat';
1931 state.mode = BAD;
1932 break;
1933 }
1934 while (copy--) {
1935 state.lens[state.have++] = len;
1936 }
1937 }
1938 }
1939
1940 /* handle error breaks in while */
1941 if (state.mode === BAD) { break; }
1942
1943 /* check for end-of-block code (better have one) */
1944 if (state.lens[256] === 0) {
1945 strm.msg = 'invalid code -- missing end-of-block';
1946 state.mode = BAD;
1947 break;
1948 }
1949
1950 /* build code tables -- note: do not change the lenbits or distbits
1951 values here (9 and 6) without reading the comments in inftrees.h
1952 concerning the ENOUGH constants, which depend on those values */
1953 state.lenbits = 9;
1954
1955 opts = { bits: state.lenbits };
1956 ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts);
1957 // We have separate tables & no pointers. 2 commented lines below not needed.
1958 // state.next_index = opts.table_index;
1959 state.lenbits = opts.bits;
1960 // state.lencode = state.next;
1961
1962 if (ret) {
1963 strm.msg = 'invalid literal/lengths set';
1964 state.mode = BAD;
1965 break;
1966 }
1967
1968 state.distbits = 6;
1969 //state.distcode.copy(state.codes);
1970 // Switch to use dynamic table
1971 state.distcode = state.distdyn;
1972 opts = { bits: state.distbits };
1973 ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);
1974 // We have separate tables & no pointers. 2 commented lines below not needed.
1975 // state.next_index = opts.table_index;
1976 state.distbits = opts.bits;
1977 // state.distcode = state.next;
1978
1979 if (ret) {
1980 strm.msg = 'invalid distances set';
1981 state.mode = BAD;
1982 break;
1983 }
1984 //Tracev((stderr, 'inflate: codes ok\n'));
1985 state.mode = LEN_;
1986 if (flush === Z_TREES) { break inf_leave; }
1987 /* falls through */
1988 case LEN_:
1989 state.mode = LEN;
1990 /* falls through */
1991 case LEN:
1992 if (have >= 6 && left >= 258) {
1993 //--- RESTORE() ---
1994 strm.next_out = put;
1995 strm.avail_out = left;
1996 strm.next_in = next;
1997 strm.avail_in = have;
1998 state.hold = hold;
1999 state.bits = bits;
2000 //---
2001 inflate_fast(strm, _out);
2002 //--- LOAD() ---
2003 put = strm.next_out;
2004 output = strm.output;
2005 left = strm.avail_out;
2006 next = strm.next_in;
2007 input = strm.input;
2008 have = strm.avail_in;
2009 hold = state.hold;
2010 bits = state.bits;
2011 //---
2012
2013 if (state.mode === TYPE) {
2014 state.back = -1;
2015 }
2016 break;
2017 }
2018 state.back = 0;
2019 for (;;) {
2020 here = state.lencode[hold & ((1 << state.lenbits) - 1)]; /*BITS(state.lenbits)*/
2021 here_bits = here >>> 24;
2022 here_op = (here >>> 16) & 0xff;
2023 here_val = here & 0xffff;
2024
2025 if (here_bits <= bits) { break; }
2026 //--- PULLBYTE() ---//
2027 if (have === 0) { break inf_leave; }
2028 have--;
2029 hold += input[next++] << bits;
2030 bits += 8;
2031 //---//
2032 }
2033 if (here_op && (here_op & 0xf0) === 0) {
2034 last_bits = here_bits;
2035 last_op = here_op;
2036 last_val = here_val;
2037 for (;;) {
2038 here = state.lencode[last_val +
2039 ((hold & ((1 << (last_bits + last_op)) - 1))/*BITS(last.bits + last.op)*/ >> last_bits)];
2040 here_bits = here >>> 24;
2041 here_op = (here >>> 16) & 0xff;
2042 here_val = here & 0xffff;
2043
2044 if ((last_bits + here_bits) <= bits) { break; }
2045 //--- PULLBYTE() ---//
2046 if (have === 0) { break inf_leave; }
2047 have--;
2048 hold += input[next++] << bits;
2049 bits += 8;
2050 //---//
2051 }
2052 //--- DROPBITS(last.bits) ---//
2053 hold >>>= last_bits;
2054 bits -= last_bits;
2055 //---//
2056 state.back += last_bits;
2057 }
2058 //--- DROPBITS(here.bits) ---//
2059 hold >>>= here_bits;
2060 bits -= here_bits;
2061 //---//
2062 state.back += here_bits;
2063 state.length = here_val;
2064 if (here_op === 0) {
2065 //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
2066 // "inflate: literal '%c'\n" :
2067 // "inflate: literal 0x%02x\n", here.val));
2068 state.mode = LIT;
2069 break;
2070 }
2071 if (here_op & 32) {
2072 //Tracevv((stderr, "inflate: end of block\n"));
2073 state.back = -1;
2074 state.mode = TYPE;
2075 break;
2076 }
2077 if (here_op & 64) {
2078 strm.msg = 'invalid literal/length code';
2079 state.mode = BAD;
2080 break;
2081 }
2082 state.extra = here_op & 15;
2083 state.mode = LENEXT;
2084 /* falls through */
2085 case LENEXT:
2086 if (state.extra) {
2087 //=== NEEDBITS(state.extra);
2088 n = state.extra;
2089 while (bits < n) {
2090 if (have === 0) { break inf_leave; }
2091 have--;
2092 hold += input[next++] << bits;
2093 bits += 8;
2094 }
2095 //===//
2096 state.length += hold & ((1 << state.extra) - 1)/*BITS(state.extra)*/;
2097 //--- DROPBITS(state.extra) ---//
2098 hold >>>= state.extra;
2099 bits -= state.extra;
2100 //---//
2101 state.back += state.extra;
2102 }
2103 //Tracevv((stderr, "inflate: length %u\n", state.length));
2104 state.was = state.length;
2105 state.mode = DIST;
2106 /* falls through */
2107 case DIST:
2108 for (;;) {
2109 here = state.distcode[hold & ((1 << state.distbits) - 1)];/*BITS(state.distbits)*/
2110 here_bits = here >>> 24;
2111 here_op = (here >>> 16) & 0xff;
2112 here_val = here & 0xffff;
2113
2114 if ((here_bits) <= bits) { break; }
2115 //--- PULLBYTE() ---//
2116 if (have === 0) { break inf_leave; }
2117 have--;
2118 hold += input[next++] << bits;
2119 bits += 8;
2120 //---//
2121 }
2122 if ((here_op & 0xf0) === 0) {
2123 last_bits = here_bits;
2124 last_op = here_op;
2125 last_val = here_val;
2126 for (;;) {
2127 here = state.distcode[last_val +
2128 ((hold & ((1 << (last_bits + last_op)) - 1))/*BITS(last.bits + last.op)*/ >> last_bits)];
2129 here_bits = here >>> 24;
2130 here_op = (here >>> 16) & 0xff;
2131 here_val = here & 0xffff;
2132
2133 if ((last_bits + here_bits) <= bits) { break; }
2134 //--- PULLBYTE() ---//
2135 if (have === 0) { break inf_leave; }
2136 have--;
2137 hold += input[next++] << bits;
2138 bits += 8;
2139 //---//
2140 }
2141 //--- DROPBITS(last.bits) ---//
2142 hold >>>= last_bits;
2143 bits -= last_bits;
2144 //---//
2145 state.back += last_bits;
2146 }
2147 //--- DROPBITS(here.bits) ---//
2148 hold >>>= here_bits;
2149 bits -= here_bits;
2150 //---//
2151 state.back += here_bits;
2152 if (here_op & 64) {
2153 strm.msg = 'invalid distance code';
2154 state.mode = BAD;
2155 break;
2156 }
2157 state.offset = here_val;
2158 state.extra = (here_op) & 15;
2159 state.mode = DISTEXT;
2160 /* falls through */
2161 case DISTEXT:
2162 if (state.extra) {
2163 //=== NEEDBITS(state.extra);
2164 n = state.extra;
2165 while (bits < n) {
2166 if (have === 0) { break inf_leave; }
2167 have--;
2168 hold += input[next++] << bits;
2169 bits += 8;
2170 }
2171 //===//
2172 state.offset += hold & ((1 << state.extra) - 1)/*BITS(state.extra)*/;
2173 //--- DROPBITS(state.extra) ---//
2174 hold >>>= state.extra;
2175 bits -= state.extra;
2176 //---//
2177 state.back += state.extra;
2178 }
2179//#ifdef INFLATE_STRICT
2180 if (state.offset > state.dmax) {
2181 strm.msg = 'invalid distance too far back';
2182 state.mode = BAD;
2183 break;
2184 }
2185//#endif
2186 //Tracevv((stderr, "inflate: distance %u\n", state.offset));
2187 state.mode = MATCH;
2188 /* falls through */
2189 case MATCH:
2190 if (left === 0) { break inf_leave; }
2191 copy = _out - left;
2192 if (state.offset > copy) { /* copy from window */
2193 copy = state.offset - copy;
2194 if (copy > state.whave) {
2195 if (state.sane) {
2196 strm.msg = 'invalid distance too far back';
2197 state.mode = BAD;
2198 break;
2199 }
2200// (!) This block is disabled in zlib defaults,
2201// don't enable it for binary compatibility
2202//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
2203// Trace((stderr, "inflate.c too far\n"));
2204// copy -= state.whave;
2205// if (copy > state.length) { copy = state.length; }
2206// if (copy > left) { copy = left; }
2207// left -= copy;
2208// state.length -= copy;
2209// do {
2210// output[put++] = 0;
2211// } while (--copy);
2212// if (state.length === 0) { state.mode = LEN; }
2213// break;
2214//#endif
2215 }
2216 if (copy > state.wnext) {
2217 copy -= state.wnext;
2218 from = state.wsize - copy;
2219 }
2220 else {
2221 from = state.wnext - copy;
2222 }
2223 if (copy > state.length) { copy = state.length; }
2224 from_source = state.window;
2225 }
2226 else { /* copy from output */
2227 from_source = output;
2228 from = put - state.offset;
2229 copy = state.length;
2230 }
2231 if (copy > left) { copy = left; }
2232 left -= copy;
2233 state.length -= copy;
2234 do {
2235 output[put++] = from_source[from++];
2236 } while (--copy);
2237 if (state.length === 0) { state.mode = LEN; }
2238 break;
2239 case LIT:
2240 if (left === 0) { break inf_leave; }
2241 output[put++] = state.length;
2242 left--;
2243 state.mode = LEN;
2244 break;
2245 case CHECK:
2246 if (state.wrap) {
2247 //=== NEEDBITS(32);
2248 while (bits < 32) {
2249 if (have === 0) { break inf_leave; }
2250 have--;
2251 // Use '|' instead of '+' to make sure that result is signed
2252 hold |= input[next++] << bits;
2253 bits += 8;
2254 }
2255 //===//
2256 _out -= left;
2257 strm.total_out += _out;
2258 state.total += _out;
2259 if (_out) {
2260 strm.adler = state.check =
2261 /*UPDATE(state.check, put - _out, _out);*/
2262 (state.flags ? crc32(state.check, output, _out, put - _out) : adler32(state.check, output, _out, put - _out));
2263
2264 }
2265 _out = left;
2266 // NB: crc32 stored as signed 32-bit int, zswap32 returns signed too
2267 if ((state.flags ? hold : zswap32(hold)) !== state.check) {
2268 strm.msg = 'incorrect data check';
2269 state.mode = BAD;
2270 break;
2271 }
2272 //=== INITBITS();
2273 hold = 0;
2274 bits = 0;
2275 //===//
2276 //Tracev((stderr, "inflate: check matches trailer\n"));
2277 }
2278 state.mode = LENGTH;
2279 /* falls through */
2280 case LENGTH:
2281 if (state.wrap && state.flags) {
2282 //=== NEEDBITS(32);
2283 while (bits < 32) {
2284 if (have === 0) { break inf_leave; }
2285 have--;
2286 hold += input[next++] << bits;
2287 bits += 8;
2288 }
2289 //===//
2290 if (hold !== (state.total & 0xffffffff)) {
2291 strm.msg = 'incorrect length check';
2292 state.mode = BAD;
2293 break;
2294 }
2295 //=== INITBITS();
2296 hold = 0;
2297 bits = 0;
2298 //===//
2299 //Tracev((stderr, "inflate: length matches trailer\n"));
2300 }
2301 state.mode = DONE;
2302 /* falls through */
2303 case DONE:
2304 ret = Z_STREAM_END;
2305 break inf_leave;
2306 case BAD:
2307 ret = Z_DATA_ERROR;
2308 break inf_leave;
2309 case MEM:
2310 return Z_MEM_ERROR;
2311 case SYNC:
2312 /* falls through */
2313 default:
2314 return Z_STREAM_ERROR;
2315 }
2316 }
2317
2318 // inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave"
2319
2320 /*
2321 Return from inflate(), updating the total counts and the check value.
2322 If there was no progress during the inflate() call, return a buffer
2323 error. Call updatewindow() to create and/or update the window state.
2324 Note: a memory error from inflate() is non-recoverable.
2325 */
2326
2327 //--- RESTORE() ---
2328 strm.next_out = put;
2329 strm.avail_out = left;
2330 strm.next_in = next;
2331 strm.avail_in = have;
2332 state.hold = hold;
2333 state.bits = bits;
2334 //---
2335
2336 if (state.wsize || (_out !== strm.avail_out && state.mode < BAD &&
2337 (state.mode < CHECK || flush !== Z_FINISH))) {
2338 if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) {
2339 state.mode = MEM;
2340 return Z_MEM_ERROR;
2341 }
2342 }
2343 _in -= strm.avail_in;
2344 _out -= strm.avail_out;
2345 strm.total_in += _in;
2346 strm.total_out += _out;
2347 state.total += _out;
2348 if (state.wrap && _out) {
2349 strm.adler = state.check = /*UPDATE(state.check, strm.next_out - _out, _out);*/
2350 (state.flags ? crc32(state.check, output, _out, strm.next_out - _out) : adler32(state.check, output, _out, strm.next_out - _out));
2351 }
2352 strm.data_type = state.bits + (state.last ? 64 : 0) +
2353 (state.mode === TYPE ? 128 : 0) +
2354 (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);
2355 if (((_in === 0 && _out === 0) || flush === Z_FINISH) && ret === Z_OK) {
2356 ret = Z_BUF_ERROR;
2357 }
2358 return ret;
2359}
2360
2361function inflateEnd(strm) {
2362
2363 if (!strm || !strm.state /*|| strm->zfree == (free_func)0*/) {
2364 return Z_STREAM_ERROR;
2365 }
2366
2367 var state = strm.state;
2368 if (state.window) {
2369 state.window = null;
2370 }
2371 strm.state = null;
2372 return Z_OK;
2373}
2374
2375function inflateGetHeader(strm, head) {
2376 var state;
2377
2378 /* check state */
2379 if (!strm || !strm.state) { return Z_STREAM_ERROR; }
2380 state = strm.state;
2381 if ((state.wrap & 2) === 0) { return Z_STREAM_ERROR; }
2382
2383 /* save header structure */
2384 state.head = head;
2385 head.done = false;
2386 return Z_OK;
2387}
2388
2389function inflateSetDictionary(strm, dictionary) {
2390 var dictLength = dictionary.length;
2391
2392 var state;
2393 var dictid;
2394 var ret;
2395
2396 /* check state */
2397 if (!strm /* == Z_NULL */ || !strm.state /* == Z_NULL */) { return Z_STREAM_ERROR; }
2398 state = strm.state;
2399
2400 if (state.wrap !== 0 && state.mode !== DICT) {
2401 return Z_STREAM_ERROR;
2402 }
2403
2404 /* check for correct dictionary identifier */
2405 if (state.mode === DICT) {
2406 dictid = 1; /* adler32(0, null, 0)*/
2407 /* dictid = adler32(dictid, dictionary, dictLength); */
2408 dictid = adler32(dictid, dictionary, dictLength, 0);
2409 if (dictid !== state.check) {
2410 return Z_DATA_ERROR;
2411 }
2412 }
2413 /* copy dictionary to window using updatewindow(), which will amend the
2414 existing dictionary if appropriate */
2415 ret = updatewindow(strm, dictionary, dictLength, dictLength);
2416 if (ret) {
2417 state.mode = MEM;
2418 return Z_MEM_ERROR;
2419 }
2420 state.havedict = 1;
2421 // Tracev((stderr, "inflate: dictionary set\n"));
2422 return Z_OK;
2423}
2424
2425exports.inflateReset = inflateReset;
2426exports.inflateReset2 = inflateReset2;
2427exports.inflateResetKeep = inflateResetKeep;
2428exports.inflateInit = inflateInit;
2429exports.inflateInit2 = inflateInit2;
2430exports.inflate = inflate;
2431exports.inflateEnd = inflateEnd;
2432exports.inflateGetHeader = inflateGetHeader;
2433exports.inflateSetDictionary = inflateSetDictionary;
2434exports.inflateInfo = 'pako inflate (from Nodeca project)';
2435
2436/* Not implemented
2437exports.inflateCopy = inflateCopy;
2438exports.inflateGetDictionary = inflateGetDictionary;
2439exports.inflateMark = inflateMark;
2440exports.inflatePrime = inflatePrime;
2441exports.inflateSync = inflateSync;
2442exports.inflateSyncPoint = inflateSyncPoint;
2443exports.inflateUndermine = inflateUndermine;
2444*/
2445
2446},{"../utils/common":1,"./adler32":3,"./crc32":5,"./inffast":7,"./inftrees":9}],9:[function(require,module,exports){
2447'use strict';
2448
2449// (C) 1995-2013 Jean-loup Gailly and Mark Adler
2450// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
2451//
2452// This software is provided 'as-is', without any express or implied
2453// warranty. In no event will the authors be held liable for any damages
2454// arising from the use of this software.
2455//
2456// Permission is granted to anyone to use this software for any purpose,
2457// including commercial applications, and to alter it and redistribute it
2458// freely, subject to the following restrictions:
2459//
2460// 1. The origin of this software must not be misrepresented; you must not
2461// claim that you wrote the original software. If you use this software
2462// in a product, an acknowledgment in the product documentation would be
2463// appreciated but is not required.
2464// 2. Altered source versions must be plainly marked as such, and must not be
2465// misrepresented as being the original software.
2466// 3. This notice may not be removed or altered from any source distribution.
2467
2468var utils = require('../utils/common');
2469
2470var MAXBITS = 15;
2471var ENOUGH_LENS = 852;
2472var ENOUGH_DISTS = 592;
2473//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
2474
2475var CODES = 0;
2476var LENS = 1;
2477var DISTS = 2;
2478
2479var lbase = [ /* Length codes 257..285 base */
2480 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
2481 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
2482];
2483
2484var lext = [ /* Length codes 257..285 extra */
2485 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
2486 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78
2487];
2488
2489var dbase = [ /* Distance codes 0..29 base */
2490 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
2491 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
2492 8193, 12289, 16385, 24577, 0, 0
2493];
2494
2495var dext = [ /* Distance codes 0..29 extra */
2496 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
2497 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
2498 28, 28, 29, 29, 64, 64
2499];
2500
2501module.exports = function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts)
2502{
2503 var bits = opts.bits;
2504 //here = opts.here; /* table entry for duplication */
2505
2506 var len = 0; /* a code's length in bits */
2507 var sym = 0; /* index of code symbols */
2508 var min = 0, max = 0; /* minimum and maximum code lengths */
2509 var root = 0; /* number of index bits for root table */
2510 var curr = 0; /* number of index bits for current table */
2511 var drop = 0; /* code bits to drop for sub-table */
2512 var left = 0; /* number of prefix codes available */
2513 var used = 0; /* code entries in table used */
2514 var huff = 0; /* Huffman code */
2515 var incr; /* for incrementing code, index */
2516 var fill; /* index for replicating entries */
2517 var low; /* low bits for current root entry */
2518 var mask; /* mask for low root bits */
2519 var next; /* next available space in table */
2520 var base = null; /* base value table to use */
2521 var base_index = 0;
2522// var shoextra; /* extra bits table to use */
2523 var end; /* use base and extra for symbol > end */
2524 var count = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* number of codes of each length */
2525 var offs = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* offsets in table for each length */
2526 var extra = null;
2527 var extra_index = 0;
2528
2529 var here_bits, here_op, here_val;
2530
2531 /*
2532 Process a set of code lengths to create a canonical Huffman code. The
2533 code lengths are lens[0..codes-1]. Each length corresponds to the
2534 symbols 0..codes-1. The Huffman code is generated by first sorting the
2535 symbols by length from short to long, and retaining the symbol order
2536 for codes with equal lengths. Then the code starts with all zero bits
2537 for the first code of the shortest length, and the codes are integer
2538 increments for the same length, and zeros are appended as the length
2539 increases. For the deflate format, these bits are stored backwards
2540 from their more natural integer increment ordering, and so when the
2541 decoding tables are built in the large loop below, the integer codes
2542 are incremented backwards.
2543
2544 This routine assumes, but does not check, that all of the entries in
2545 lens[] are in the range 0..MAXBITS. The caller must assure this.
2546 1..MAXBITS is interpreted as that code length. zero means that that
2547 symbol does not occur in this code.
2548
2549 The codes are sorted by computing a count of codes for each length,
2550 creating from that a table of starting indices for each length in the
2551 sorted table, and then entering the symbols in order in the sorted
2552 table. The sorted table is work[], with that space being provided by
2553 the caller.
2554
2555 The length counts are used for other purposes as well, i.e. finding
2556 the minimum and maximum length codes, determining if there are any
2557 codes at all, checking for a valid set of lengths, and looking ahead
2558 at length counts to determine sub-table sizes when building the
2559 decoding tables.
2560 */
2561
2562 /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
2563 for (len = 0; len <= MAXBITS; len++) {
2564 count[len] = 0;
2565 }
2566 for (sym = 0; sym < codes; sym++) {
2567 count[lens[lens_index + sym]]++;
2568 }
2569
2570 /* bound code lengths, force root to be within code lengths */
2571 root = bits;
2572 for (max = MAXBITS; max >= 1; max--) {
2573 if (count[max] !== 0) { break; }
2574 }
2575 if (root > max) {
2576 root = max;
2577 }
2578 if (max === 0) { /* no symbols to code at all */
2579 //table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */
2580 //table.bits[opts.table_index] = 1; //here.bits = (var char)1;
2581 //table.val[opts.table_index++] = 0; //here.val = (var short)0;
2582 table[table_index++] = (1 << 24) | (64 << 16) | 0;
2583
2584
2585 //table.op[opts.table_index] = 64;
2586 //table.bits[opts.table_index] = 1;
2587 //table.val[opts.table_index++] = 0;
2588 table[table_index++] = (1 << 24) | (64 << 16) | 0;
2589
2590 opts.bits = 1;
2591 return 0; /* no symbols, but wait for decoding to report error */
2592 }
2593 for (min = 1; min < max; min++) {
2594 if (count[min] !== 0) { break; }
2595 }
2596 if (root < min) {
2597 root = min;
2598 }
2599
2600 /* check for an over-subscribed or incomplete set of lengths */
2601 left = 1;
2602 for (len = 1; len <= MAXBITS; len++) {
2603 left <<= 1;
2604 left -= count[len];
2605 if (left < 0) {
2606 return -1;
2607 } /* over-subscribed */
2608 }
2609 if (left > 0 && (type === CODES || max !== 1)) {
2610 return -1; /* incomplete set */
2611 }
2612
2613 /* generate offsets into symbol table for each length for sorting */
2614 offs[1] = 0;
2615 for (len = 1; len < MAXBITS; len++) {
2616 offs[len + 1] = offs[len] + count[len];
2617 }
2618
2619 /* sort symbols by length, by symbol order within each length */
2620 for (sym = 0; sym < codes; sym++) {
2621 if (lens[lens_index + sym] !== 0) {
2622 work[offs[lens[lens_index + sym]]++] = sym;
2623 }
2624 }
2625
2626 /*
2627 Create and fill in decoding tables. In this loop, the table being
2628 filled is at next and has curr index bits. The code being used is huff
2629 with length len. That code is converted to an index by dropping drop
2630 bits off of the bottom. For codes where len is less than drop + curr,
2631 those top drop + curr - len bits are incremented through all values to
2632 fill the table with replicated entries.
2633
2634 root is the number of index bits for the root table. When len exceeds
2635 root, sub-tables are created pointed to by the root entry with an index
2636 of the low root bits of huff. This is saved in low to check for when a
2637 new sub-table should be started. drop is zero when the root table is
2638 being filled, and drop is root when sub-tables are being filled.
2639
2640 When a new sub-table is needed, it is necessary to look ahead in the
2641 code lengths to determine what size sub-table is needed. The length
2642 counts are used for this, and so count[] is decremented as codes are
2643 entered in the tables.
2644
2645 used keeps track of how many table entries have been allocated from the
2646 provided *table space. It is checked for LENS and DIST tables against
2647 the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
2648 the initial root table size constants. See the comments in inftrees.h
2649 for more information.
2650
2651 sym increments through all symbols, and the loop terminates when
2652 all codes of length max, i.e. all codes, have been processed. This
2653 routine permits incomplete codes, so another loop after this one fills
2654 in the rest of the decoding tables with invalid code markers.
2655 */
2656
2657 /* set up for code type */
2658 // poor man optimization - use if-else instead of switch,
2659 // to avoid deopts in old v8
2660 if (type === CODES) {
2661 base = extra = work; /* dummy value--not used */
2662 end = 19;
2663
2664 } else if (type === LENS) {
2665 base = lbase;
2666 base_index -= 257;
2667 extra = lext;
2668 extra_index -= 257;
2669 end = 256;
2670
2671 } else { /* DISTS */
2672 base = dbase;
2673 extra = dext;
2674 end = -1;
2675 }
2676
2677 /* initialize opts for loop */
2678 huff = 0; /* starting code */
2679 sym = 0; /* starting code symbol */
2680 len = min; /* starting code length */
2681 next = table_index; /* current table to fill in */
2682 curr = root; /* current table index bits */
2683 drop = 0; /* current bits to drop from code for index */
2684 low = -1; /* trigger new sub-table when len > root */
2685 used = 1 << root; /* use root table entries */
2686 mask = used - 1; /* mask for comparing low */
2687
2688 /* check available table space */
2689 if ((type === LENS && used > ENOUGH_LENS) ||
2690 (type === DISTS && used > ENOUGH_DISTS)) {
2691 return 1;
2692 }
2693
2694 /* process all codes and make table entries */
2695 for (;;) {
2696 /* create table entry */
2697 here_bits = len - drop;
2698 if (work[sym] < end) {
2699 here_op = 0;
2700 here_val = work[sym];
2701 }
2702 else if (work[sym] > end) {
2703 here_op = extra[extra_index + work[sym]];
2704 here_val = base[base_index + work[sym]];
2705 }
2706 else {
2707 here_op = 32 + 64; /* end of block */
2708 here_val = 0;
2709 }
2710
2711 /* replicate for those indices with low len bits equal to huff */
2712 incr = 1 << (len - drop);
2713 fill = 1 << curr;
2714 min = fill; /* save offset to next table */
2715 do {
2716 fill -= incr;
2717 table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0;
2718 } while (fill !== 0);
2719
2720 /* backwards increment the len-bit code huff */
2721 incr = 1 << (len - 1);
2722 while (huff & incr) {
2723 incr >>= 1;
2724 }
2725 if (incr !== 0) {
2726 huff &= incr - 1;
2727 huff += incr;
2728 } else {
2729 huff = 0;
2730 }
2731
2732 /* go to next symbol, update count, len */
2733 sym++;
2734 if (--count[len] === 0) {
2735 if (len === max) { break; }
2736 len = lens[lens_index + work[sym]];
2737 }
2738
2739 /* create new sub-table if needed */
2740 if (len > root && (huff & mask) !== low) {
2741 /* if first time, transition to sub-tables */
2742 if (drop === 0) {
2743 drop = root;
2744 }
2745
2746 /* increment past last table */
2747 next += min; /* here min is 1 << curr */
2748
2749 /* determine length of next table */
2750 curr = len - drop;
2751 left = 1 << curr;
2752 while (curr + drop < max) {
2753 left -= count[curr + drop];
2754 if (left <= 0) { break; }
2755 curr++;
2756 left <<= 1;
2757 }
2758
2759 /* check for enough space */
2760 used += 1 << curr;
2761 if ((type === LENS && used > ENOUGH_LENS) ||
2762 (type === DISTS && used > ENOUGH_DISTS)) {
2763 return 1;
2764 }
2765
2766 /* point entry in root table to sub-table */
2767 low = huff & mask;
2768 /*table.op[low] = curr;
2769 table.bits[low] = root;
2770 table.val[low] = next - opts.table_index;*/
2771 table[low] = (root << 24) | (curr << 16) | (next - table_index) |0;
2772 }
2773 }
2774
2775 /* fill in remaining table entry if code is incomplete (guaranteed to have
2776 at most one remaining entry, since if the code is incomplete, the
2777 maximum code length that was allowed to get this far is one bit) */
2778 if (huff !== 0) {
2779 //table.op[next + huff] = 64; /* invalid code marker */
2780 //table.bits[next + huff] = len - drop;
2781 //table.val[next + huff] = 0;
2782 table[next + huff] = ((len - drop) << 24) | (64 << 16) |0;
2783 }
2784
2785 /* set return parameters */
2786 //opts.table_index += used;
2787 opts.bits = root;
2788 return 0;
2789};
2790
2791},{"../utils/common":1}],10:[function(require,module,exports){
2792'use strict';
2793
2794// (C) 1995-2013 Jean-loup Gailly and Mark Adler
2795// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
2796//
2797// This software is provided 'as-is', without any express or implied
2798// warranty. In no event will the authors be held liable for any damages
2799// arising from the use of this software.
2800//
2801// Permission is granted to anyone to use this software for any purpose,
2802// including commercial applications, and to alter it and redistribute it
2803// freely, subject to the following restrictions:
2804//
2805// 1. The origin of this software must not be misrepresented; you must not
2806// claim that you wrote the original software. If you use this software
2807// in a product, an acknowledgment in the product documentation would be
2808// appreciated but is not required.
2809// 2. Altered source versions must be plainly marked as such, and must not be
2810// misrepresented as being the original software.
2811// 3. This notice may not be removed or altered from any source distribution.
2812
2813module.exports = {
2814 2: 'need dictionary', /* Z_NEED_DICT 2 */
2815 1: 'stream end', /* Z_STREAM_END 1 */
2816 0: '', /* Z_OK 0 */
2817 '-1': 'file error', /* Z_ERRNO (-1) */
2818 '-2': 'stream error', /* Z_STREAM_ERROR (-2) */
2819 '-3': 'data error', /* Z_DATA_ERROR (-3) */
2820 '-4': 'insufficient memory', /* Z_MEM_ERROR (-4) */
2821 '-5': 'buffer error', /* Z_BUF_ERROR (-5) */
2822 '-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */
2823};
2824
2825},{}],11:[function(require,module,exports){
2826'use strict';
2827
2828// (C) 1995-2013 Jean-loup Gailly and Mark Adler
2829// (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
2830//
2831// This software is provided 'as-is', without any express or implied
2832// warranty. In no event will the authors be held liable for any damages
2833// arising from the use of this software.
2834//
2835// Permission is granted to anyone to use this software for any purpose,
2836// including commercial applications, and to alter it and redistribute it
2837// freely, subject to the following restrictions:
2838//
2839// 1. The origin of this software must not be misrepresented; you must not
2840// claim that you wrote the original software. If you use this software
2841// in a product, an acknowledgment in the product documentation would be
2842// appreciated but is not required.
2843// 2. Altered source versions must be plainly marked as such, and must not be
2844// misrepresented as being the original software.
2845// 3. This notice may not be removed or altered from any source distribution.
2846
2847function ZStream() {
2848 /* next input byte */
2849 this.input = null; // JS specific, because we have no pointers
2850 this.next_in = 0;
2851 /* number of bytes available at input */
2852 this.avail_in = 0;
2853 /* total number of input bytes read so far */
2854 this.total_in = 0;
2855 /* next output byte should be put there */
2856 this.output = null; // JS specific, because we have no pointers
2857 this.next_out = 0;
2858 /* remaining free space at output */
2859 this.avail_out = 0;
2860 /* total number of bytes output so far */
2861 this.total_out = 0;
2862 /* last error message, NULL if no error */
2863 this.msg = ''/*Z_NULL*/;
2864 /* not visible by applications */
2865 this.state = null;
2866 /* best guess about the data type: binary or text */
2867 this.data_type = 2/*Z_UNKNOWN*/;
2868 /* adler32 value of the uncompressed data */
2869 this.adler = 0;
2870}
2871
2872module.exports = ZStream;
2873
2874},{}],"/lib/inflate.js":[function(require,module,exports){
2875'use strict';
2876
2877
2878var zlib_inflate = require('./zlib/inflate');
2879var utils = require('./utils/common');
2880var strings = require('./utils/strings');
2881var c = require('./zlib/constants');
2882var msg = require('./zlib/messages');
2883var ZStream = require('./zlib/zstream');
2884var GZheader = require('./zlib/gzheader');
2885
2886var toString = Object.prototype.toString;
2887
2888/**
2889 * class Inflate
2890 *
2891 * Generic JS-style wrapper for zlib calls. If you don't need
2892 * streaming behaviour - use more simple functions: [[inflate]]
2893 * and [[inflateRaw]].
2894 **/
2895
2896/* internal
2897 * inflate.chunks -> Array
2898 *
2899 * Chunks of output data, if [[Inflate#onData]] not overridden.
2900 **/
2901
2902/**
2903 * Inflate.result -> Uint8Array|Array|String
2904 *
2905 * Uncompressed result, generated by default [[Inflate#onData]]
2906 * and [[Inflate#onEnd]] handlers. Filled after you push last chunk
2907 * (call [[Inflate#push]] with `Z_FINISH` / `true` param) or if you
2908 * push a chunk with explicit flush (call [[Inflate#push]] with
2909 * `Z_SYNC_FLUSH` param).
2910 **/
2911
2912/**
2913 * Inflate.err -> Number
2914 *
2915 * Error code after inflate finished. 0 (Z_OK) on success.
2916 * Should be checked if broken data possible.
2917 **/
2918
2919/**
2920 * Inflate.msg -> String
2921 *
2922 * Error message, if [[Inflate.err]] != 0
2923 **/
2924
2925
2926/**
2927 * new Inflate(options)
2928 * - options (Object): zlib inflate options.
2929 *
2930 * Creates new inflator instance with specified params. Throws exception
2931 * on bad params. Supported options:
2932 *
2933 * - `windowBits`
2934 * - `dictionary`
2935 *
2936 * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
2937 * for more information on these.
2938 *
2939 * Additional options, for internal needs:
2940 *
2941 * - `chunkSize` - size of generated data chunks (16K by default)
2942 * - `raw` (Boolean) - do raw inflate
2943 * - `to` (String) - if equal to 'string', then result will be converted
2944 * from utf8 to utf16 (javascript) string. When string output requested,
2945 * chunk length can differ from `chunkSize`, depending on content.
2946 *
2947 * By default, when no options set, autodetect deflate/gzip data format via
2948 * wrapper header.
2949 *
2950 * ##### Example:
2951 *
2952 * ```javascript
2953 * var pako = require('pako')
2954 * , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
2955 * , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
2956 *
2957 * var inflate = new pako.Inflate({ level: 3});
2958 *
2959 * inflate.push(chunk1, false);
2960 * inflate.push(chunk2, true); // true -> last chunk
2961 *
2962 * if (inflate.err) { throw new Error(inflate.err); }
2963 *
2964 * console.log(inflate.result);
2965 * ```
2966 **/
2967function Inflate(options) {
2968 if (!(this instanceof Inflate)) return new Inflate(options);
2969
2970 this.options = utils.assign({
2971 chunkSize: 16384,
2972 windowBits: 0,
2973 to: ''
2974 }, options || {});
2975
2976 var opt = this.options;
2977
2978 // Force window size for `raw` data, if not set directly,
2979 // because we have no header for autodetect.
2980 if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
2981 opt.windowBits = -opt.windowBits;
2982 if (opt.windowBits === 0) { opt.windowBits = -15; }
2983 }
2984
2985 // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
2986 if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&
2987 !(options && options.windowBits)) {
2988 opt.windowBits += 32;
2989 }
2990
2991 // Gzip header has no info about windows size, we can do autodetect only
2992 // for deflate. So, if window size not set, force it to max when gzip possible
2993 if ((opt.windowBits > 15) && (opt.windowBits < 48)) {
2994 // bit 3 (16) -> gzipped data
2995 // bit 4 (32) -> autodetect gzip/deflate
2996 if ((opt.windowBits & 15) === 0) {
2997 opt.windowBits |= 15;
2998 }
2999 }
3000
3001 this.err = 0; // error code, if happens (0 = Z_OK)
3002 this.msg = ''; // error message
3003 this.ended = false; // used to avoid multiple onEnd() calls
3004 this.chunks = []; // chunks of compressed data
3005
3006 this.strm = new ZStream();
3007 this.strm.avail_out = 0;
3008
3009 var status = zlib_inflate.inflateInit2(
3010 this.strm,
3011 opt.windowBits
3012 );
3013
3014 if (status !== c.Z_OK) {
3015 throw new Error(msg[status]);
3016 }
3017
3018 this.header = new GZheader();
3019
3020 zlib_inflate.inflateGetHeader(this.strm, this.header);
3021
3022 // Setup dictionary
3023 if (opt.dictionary) {
3024 // Convert data if needed
3025 if (typeof opt.dictionary === 'string') {
3026 opt.dictionary = strings.string2buf(opt.dictionary);
3027 } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
3028 opt.dictionary = new Uint8Array(opt.dictionary);
3029 }
3030 if (opt.raw) { //In raw mode we need to set the dictionary early
3031 status = zlib_inflate.inflateSetDictionary(this.strm, opt.dictionary);
3032 if (status !== c.Z_OK) {
3033 throw new Error(msg[status]);
3034 }
3035 }
3036 }
3037}
3038
3039/**
3040 * Inflate#push(data[, mode]) -> Boolean
3041 * - data (Uint8Array|Array|ArrayBuffer|String): input data
3042 * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
3043 * See constants. Skipped or `false` means Z_NO_FLUSH, `true` means Z_FINISH.
3044 *
3045 * Sends input data to inflate pipe, generating [[Inflate#onData]] calls with
3046 * new output chunks. Returns `true` on success. The last data block must have
3047 * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
3048 * [[Inflate#onEnd]]. For interim explicit flushes (without ending the stream) you
3049 * can use mode Z_SYNC_FLUSH, keeping the decompression context.
3050 *
3051 * On fail call [[Inflate#onEnd]] with error code and return false.
3052 *
3053 * We strongly recommend to use `Uint8Array` on input for best speed (output
3054 * format is detected automatically). Also, don't skip last param and always
3055 * use the same type in your code (boolean or number). That will improve JS speed.
3056 *
3057 * For regular `Array`-s make sure all elements are [0..255].
3058 *
3059 * ##### Example
3060 *
3061 * ```javascript
3062 * push(chunk, false); // push one of data chunks
3063 * ...
3064 * push(chunk, true); // push last chunk
3065 * ```
3066 **/
3067Inflate.prototype.push = function (data, mode) {
3068 var strm = this.strm;
3069 var chunkSize = this.options.chunkSize;
3070 var dictionary = this.options.dictionary;
3071 var status, _mode;
3072 var next_out_utf8, tail, utf8str;
3073
3074 // Flag to properly process Z_BUF_ERROR on testing inflate call
3075 // when we check that all output data was flushed.
3076 var allowBufError = false;
3077
3078 if (this.ended) { return false; }
3079 _mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH);
3080
3081 // Convert data if needed
3082 if (typeof data === 'string') {
3083 // Only binary strings can be decompressed on practice
3084 strm.input = strings.binstring2buf(data);
3085 } else if (toString.call(data) === '[object ArrayBuffer]') {
3086 strm.input = new Uint8Array(data);
3087 } else {
3088 strm.input = data;
3089 }
3090
3091 strm.next_in = 0;
3092 strm.avail_in = strm.input.length;
3093
3094 do {
3095 if (strm.avail_out === 0) {
3096 strm.output = new utils.Buf8(chunkSize);
3097 strm.next_out = 0;
3098 strm.avail_out = chunkSize;
3099 }
3100
3101 status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH); /* no bad return value */
3102
3103 if (status === c.Z_NEED_DICT && dictionary) {
3104 status = zlib_inflate.inflateSetDictionary(this.strm, dictionary);
3105 }
3106
3107 if (status === c.Z_BUF_ERROR && allowBufError === true) {
3108 status = c.Z_OK;
3109 allowBufError = false;
3110 }
3111
3112 if (status !== c.Z_STREAM_END && status !== c.Z_OK) {
3113 this.onEnd(status);
3114 this.ended = true;
3115 return false;
3116 }
3117
3118 if (strm.next_out) {
3119 if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && (_mode === c.Z_FINISH || _mode === c.Z_SYNC_FLUSH))) {
3120
3121 if (this.options.to === 'string') {
3122
3123 next_out_utf8 = strings.utf8border(strm.output, strm.next_out);
3124
3125 tail = strm.next_out - next_out_utf8;
3126 utf8str = strings.buf2string(strm.output, next_out_utf8);
3127
3128 // move tail
3129 strm.next_out = tail;
3130 strm.avail_out = chunkSize - tail;
3131 if (tail) { utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0); }
3132
3133 this.onData(utf8str);
3134
3135 } else {
3136 this.onData(utils.shrinkBuf(strm.output, strm.next_out));
3137 }
3138 }
3139 }
3140
3141 // When no more input data, we should check that internal inflate buffers
3142 // are flushed. The only way to do it when avail_out = 0 - run one more
3143 // inflate pass. But if output data not exists, inflate return Z_BUF_ERROR.
3144 // Here we set flag to process this error properly.
3145 //
3146 // NOTE. Deflate does not return error in this case and does not needs such
3147 // logic.
3148 if (strm.avail_in === 0 && strm.avail_out === 0) {
3149 allowBufError = true;
3150 }
3151
3152 } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== c.Z_STREAM_END);
3153
3154 if (status === c.Z_STREAM_END) {
3155 _mode = c.Z_FINISH;
3156 }
3157
3158 // Finalize on the last chunk.
3159 if (_mode === c.Z_FINISH) {
3160 status = zlib_inflate.inflateEnd(this.strm);
3161 this.onEnd(status);
3162 this.ended = true;
3163 return status === c.Z_OK;
3164 }
3165
3166 // callback interim results if Z_SYNC_FLUSH.
3167 if (_mode === c.Z_SYNC_FLUSH) {
3168 this.onEnd(c.Z_OK);
3169 strm.avail_out = 0;
3170 return true;
3171 }
3172
3173 return true;
3174};
3175
3176
3177/**
3178 * Inflate#onData(chunk) -> Void
3179 * - chunk (Uint8Array|Array|String): output data. Type of array depends
3180 * on js engine support. When string output requested, each chunk
3181 * will be string.
3182 *
3183 * By default, stores data blocks in `chunks[]` property and glue
3184 * those in `onEnd`. Override this handler, if you need another behaviour.
3185 **/
3186Inflate.prototype.onData = function (chunk) {
3187 this.chunks.push(chunk);
3188};
3189
3190
3191/**
3192 * Inflate#onEnd(status) -> Void
3193 * - status (Number): inflate status. 0 (Z_OK) on success,
3194 * other if not.
3195 *
3196 * Called either after you tell inflate that the input stream is
3197 * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
3198 * or if an error happened. By default - join collected chunks,
3199 * free memory and fill `results` / `err` properties.
3200 **/
3201Inflate.prototype.onEnd = function (status) {
3202 // On success - join
3203 if (status === c.Z_OK) {
3204 if (this.options.to === 'string') {
3205 // Glue & convert here, until we teach pako to send
3206 // utf8 aligned strings to onData
3207 this.result = this.chunks.join('');
3208 } else {
3209 this.result = utils.flattenChunks(this.chunks);
3210 }
3211 }
3212 this.chunks = [];
3213 this.err = status;
3214 this.msg = this.strm.msg;
3215};
3216
3217
3218/**
3219 * inflate(data[, options]) -> Uint8Array|Array|String
3220 * - data (Uint8Array|Array|String): input data to decompress.
3221 * - options (Object): zlib inflate options.
3222 *
3223 * Decompress `data` with inflate/ungzip and `options`. Autodetect
3224 * format via wrapper header by default. That's why we don't provide
3225 * separate `ungzip` method.
3226 *
3227 * Supported options are:
3228 *
3229 * - windowBits
3230 *
3231 * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
3232 * for more information.
3233 *
3234 * Sugar (options):
3235 *
3236 * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
3237 * negative windowBits implicitly.
3238 * - `to` (String) - if equal to 'string', then result will be converted
3239 * from utf8 to utf16 (javascript) string. When string output requested,
3240 * chunk length can differ from `chunkSize`, depending on content.
3241 *
3242 *
3243 * ##### Example:
3244 *
3245 * ```javascript
3246 * var pako = require('pako')
3247 * , input = pako.deflate([1,2,3,4,5,6,7,8,9])
3248 * , output;
3249 *
3250 * try {
3251 * output = pako.inflate(input);
3252 * } catch (err)
3253 * console.log(err);
3254 * }
3255 * ```
3256 **/
3257function inflate(input, options) {
3258 var inflator = new Inflate(options);
3259
3260 inflator.push(input, true);
3261
3262 // That will never happens, if you don't cheat with options :)
3263 if (inflator.err) { throw inflator.msg || msg[inflator.err]; }
3264
3265 return inflator.result;
3266}
3267
3268
3269/**
3270 * inflateRaw(data[, options]) -> Uint8Array|Array|String
3271 * - data (Uint8Array|Array|String): input data to decompress.
3272 * - options (Object): zlib inflate options.
3273 *
3274 * The same as [[inflate]], but creates raw data, without wrapper
3275 * (header and adler32 crc).
3276 **/
3277function inflateRaw(input, options) {
3278 options = options || {};
3279 options.raw = true;
3280 return inflate(input, options);
3281}
3282
3283
3284/**
3285 * ungzip(data[, options]) -> Uint8Array|Array|String
3286 * - data (Uint8Array|Array|String): input data to decompress.
3287 * - options (Object): zlib inflate options.
3288 *
3289 * Just shortcut to [[inflate]], because it autodetects format
3290 * by header.content. Done for convenience.
3291 **/
3292
3293
3294exports.Inflate = Inflate;
3295exports.inflate = inflate;
3296exports.inflateRaw = inflateRaw;
3297exports.ungzip = inflate;
3298
3299},{"./utils/common":1,"./utils/strings":2,"./zlib/constants":4,"./zlib/gzheader":6,"./zlib/inflate":8,"./zlib/messages":10,"./zlib/zstream":11}]},{},[])("/lib/inflate.js")
3300});
Note: See TracBrowser for help on using the repository browser.