You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3979 lines
108 KiB

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