roslib-ts 1.0.0-beta.11 → 1.0.0-beta.12

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