source: imaps-frontend/node_modules/fflate/lib/node.cjs

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 88.3 KB
Line 
1"use strict";
2// DEFLATE is a complex format; to read this code, you should probably check the RFC first:
3// https://tools.ietf.org/html/rfc1951
4// You may also wish to take a look at the guide I made about this program:
5// https://gist.github.com/101arrowz/253f31eb5abc3d9275ab943003ffecad
6// Some of the following code is similar to that of UZIP.js:
7// https://github.com/photopea/UZIP.js
8// However, the vast majority of the codebase has diverged from UZIP.js to increase performance and reduce bundle size.
9// Sometimes 0 will appear where -1 would be more appropriate. This is because using a uint
10// is better for memory in most engines (I *think*).
11// Mediocre shim
12var Worker;
13var workerAdd = ";var __w=require('worker_threads');__w.parentPort.on('message',function(m){onmessage({data:m})}),postMessage=function(m,t){__w.parentPort.postMessage(m,t)},close=process.exit;self=global";
14try {
15 Worker = require('worker_threads').Worker;
16}
17catch (e) {
18}
19var node_worker_1 = {};
20node_worker_1["default"] = Worker ? function (c, _, msg, transfer, cb) {
21 var done = false;
22 var w = new Worker(c + workerAdd, { eval: true })
23 .on('error', function (e) { return cb(e, null); })
24 .on('message', function (m) { return cb(null, m); })
25 .on('exit', function (c) {
26 if (c && !done)
27 cb(new Error('exited with code ' + c), null);
28 });
29 w.postMessage(msg, transfer);
30 w.terminate = function () {
31 done = true;
32 return Worker.prototype.terminate.call(w);
33 };
34 return w;
35} : function (_, __, ___, ____, cb) {
36 setImmediate(function () { return cb(new Error('async operations unsupported - update to Node 12+ (or Node 10-11 with the --experimental-worker CLI flag)'), null); });
37 var NOP = function () { };
38 return {
39 terminate: NOP,
40 postMessage: NOP
41 };
42};
43
44// aliases for shorter compressed code (most minifers don't do this)
45var u8 = Uint8Array, u16 = Uint16Array, i32 = Int32Array;
46// fixed length extra bits
47var fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, /* unused */ 0, 0, /* impossible */ 0]);
48// fixed distance extra bits
49var fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, /* unused */ 0, 0]);
50// code length index map
51var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
52// get base, reverse index map from extra bits
53var freb = function (eb, start) {
54 var b = new u16(31);
55 for (var i = 0; i < 31; ++i) {
56 b[i] = start += 1 << eb[i - 1];
57 }
58 // numbers here are at max 18 bits
59 var r = new i32(b[30]);
60 for (var i = 1; i < 30; ++i) {
61 for (var j = b[i]; j < b[i + 1]; ++j) {
62 r[j] = ((j - b[i]) << 5) | i;
63 }
64 }
65 return { b: b, r: r };
66};
67var _a = freb(fleb, 2), fl = _a.b, revfl = _a.r;
68// we can ignore the fact that the other numbers are wrong; they never happen anyway
69fl[28] = 258, revfl[258] = 28;
70var _b = freb(fdeb, 0), fd = _b.b, revfd = _b.r;
71// map of value to reverse (assuming 16 bits)
72var rev = new u16(32768);
73for (var i = 0; i < 32768; ++i) {
74 // reverse table algorithm from SO
75 var x = ((i & 0xAAAA) >> 1) | ((i & 0x5555) << 1);
76 x = ((x & 0xCCCC) >> 2) | ((x & 0x3333) << 2);
77 x = ((x & 0xF0F0) >> 4) | ((x & 0x0F0F) << 4);
78 rev[i] = (((x & 0xFF00) >> 8) | ((x & 0x00FF) << 8)) >> 1;
79}
80// create huffman tree from u8 "map": index -> code length for code index
81// mb (max bits) must be at most 15
82// TODO: optimize/split up?
83var hMap = (function (cd, mb, r) {
84 var s = cd.length;
85 // index
86 var i = 0;
87 // u16 "map": index -> # of codes with bit length = index
88 var l = new u16(mb);
89 // length of cd must be 288 (total # of codes)
90 for (; i < s; ++i) {
91 if (cd[i])
92 ++l[cd[i] - 1];
93 }
94 // u16 "map": index -> minimum code for bit length = index
95 var le = new u16(mb);
96 for (i = 1; i < mb; ++i) {
97 le[i] = (le[i - 1] + l[i - 1]) << 1;
98 }
99 var co;
100 if (r) {
101 // u16 "map": index -> number of actual bits, symbol for code
102 co = new u16(1 << mb);
103 // bits to remove for reverser
104 var rvb = 15 - mb;
105 for (i = 0; i < s; ++i) {
106 // ignore 0 lengths
107 if (cd[i]) {
108 // num encoding both symbol and bits read
109 var sv = (i << 4) | cd[i];
110 // free bits
111 var r_1 = mb - cd[i];
112 // start value
113 var v = le[cd[i] - 1]++ << r_1;
114 // m is end value
115 for (var m = v | ((1 << r_1) - 1); v <= m; ++v) {
116 // every 16 bit value starting with the code yields the same result
117 co[rev[v] >> rvb] = sv;
118 }
119 }
120 }
121 }
122 else {
123 co = new u16(s);
124 for (i = 0; i < s; ++i) {
125 if (cd[i]) {
126 co[i] = rev[le[cd[i] - 1]++] >> (15 - cd[i]);
127 }
128 }
129 }
130 return co;
131});
132// fixed length tree
133var flt = new u8(288);
134for (var i = 0; i < 144; ++i)
135 flt[i] = 8;
136for (var i = 144; i < 256; ++i)
137 flt[i] = 9;
138for (var i = 256; i < 280; ++i)
139 flt[i] = 7;
140for (var i = 280; i < 288; ++i)
141 flt[i] = 8;
142// fixed distance tree
143var fdt = new u8(32);
144for (var i = 0; i < 32; ++i)
145 fdt[i] = 5;
146// fixed length map
147var flm = /*#__PURE__*/ hMap(flt, 9, 0), flrm = /*#__PURE__*/ hMap(flt, 9, 1);
148// fixed distance map
149var fdm = /*#__PURE__*/ hMap(fdt, 5, 0), fdrm = /*#__PURE__*/ hMap(fdt, 5, 1);
150// find max of array
151var max = function (a) {
152 var m = a[0];
153 for (var i = 1; i < a.length; ++i) {
154 if (a[i] > m)
155 m = a[i];
156 }
157 return m;
158};
159// read d, starting at bit p and mask with m
160var bits = function (d, p, m) {
161 var o = (p / 8) | 0;
162 return ((d[o] | (d[o + 1] << 8)) >> (p & 7)) & m;
163};
164// read d, starting at bit p continuing for at least 16 bits
165var bits16 = function (d, p) {
166 var o = (p / 8) | 0;
167 return ((d[o] | (d[o + 1] << 8) | (d[o + 2] << 16)) >> (p & 7));
168};
169// get end of byte
170var shft = function (p) { return ((p + 7) / 8) | 0; };
171// typed array slice - allows garbage collector to free original reference,
172// while being more compatible than .slice
173var slc = function (v, s, e) {
174 if (s == null || s < 0)
175 s = 0;
176 if (e == null || e > v.length)
177 e = v.length;
178 // can't use .constructor in case user-supplied
179 return new u8(v.subarray(s, e));
180};
181/**
182 * Codes for errors generated within this library
183 */
184exports.FlateErrorCode = {
185 UnexpectedEOF: 0,
186 InvalidBlockType: 1,
187 InvalidLengthLiteral: 2,
188 InvalidDistance: 3,
189 StreamFinished: 4,
190 NoStreamHandler: 5,
191 InvalidHeader: 6,
192 NoCallback: 7,
193 InvalidUTF8: 8,
194 ExtraFieldTooLong: 9,
195 InvalidDate: 10,
196 FilenameTooLong: 11,
197 StreamFinishing: 12,
198 InvalidZipData: 13,
199 UnknownCompressionMethod: 14
200};
201// error codes
202var ec = [
203 'unexpected EOF',
204 'invalid block type',
205 'invalid length/literal',
206 'invalid distance',
207 'stream finished',
208 'no stream handler',
209 ,
210 'no callback',
211 'invalid UTF-8 data',
212 'extra field too long',
213 'date not in range 1980-2099',
214 'filename too long',
215 'stream finishing',
216 'invalid zip data'
217 // determined by unknown compression method
218];
219;
220var err = function (ind, msg, nt) {
221 var e = new Error(msg || ec[ind]);
222 e.code = ind;
223 if (Error.captureStackTrace)
224 Error.captureStackTrace(e, err);
225 if (!nt)
226 throw e;
227 return e;
228};
229// expands raw DEFLATE data
230var inflt = function (dat, st, buf, dict) {
231 // source length dict length
232 var sl = dat.length, dl = dict ? dict.length : 0;
233 if (!sl || st.f && !st.l)
234 return buf || new u8(0);
235 var noBuf = !buf;
236 // have to estimate size
237 var resize = noBuf || st.i != 2;
238 // no state
239 var noSt = st.i;
240 // Assumes roughly 33% compression ratio average
241 if (noBuf)
242 buf = new u8(sl * 3);
243 // ensure buffer can fit at least l elements
244 var cbuf = function (l) {
245 var bl = buf.length;
246 // need to increase size to fit
247 if (l > bl) {
248 // Double or set to necessary, whichever is greater
249 var nbuf = new u8(Math.max(bl * 2, l));
250 nbuf.set(buf);
251 buf = nbuf;
252 }
253 };
254 // last chunk bitpos bytes
255 var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;
256 // total bits
257 var tbts = sl * 8;
258 do {
259 if (!lm) {
260 // BFINAL - this is only 1 when last chunk is next
261 final = bits(dat, pos, 1);
262 // type: 0 = no compression, 1 = fixed huffman, 2 = dynamic huffman
263 var type = bits(dat, pos + 1, 3);
264 pos += 3;
265 if (!type) {
266 // go to end of byte boundary
267 var s = shft(pos) + 4, l = dat[s - 4] | (dat[s - 3] << 8), t = s + l;
268 if (t > sl) {
269 if (noSt)
270 err(0);
271 break;
272 }
273 // ensure size
274 if (resize)
275 cbuf(bt + l);
276 // Copy over uncompressed data
277 buf.set(dat.subarray(s, t), bt);
278 // Get new bitpos, update byte count
279 st.b = bt += l, st.p = pos = t * 8, st.f = final;
280 continue;
281 }
282 else if (type == 1)
283 lm = flrm, dm = fdrm, lbt = 9, dbt = 5;
284 else if (type == 2) {
285 // literal lengths
286 var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;
287 var tl = hLit + bits(dat, pos + 5, 31) + 1;
288 pos += 14;
289 // length+distance tree
290 var ldt = new u8(tl);
291 // code length tree
292 var clt = new u8(19);
293 for (var i = 0; i < hcLen; ++i) {
294 // use index map to get real code
295 clt[clim[i]] = bits(dat, pos + i * 3, 7);
296 }
297 pos += hcLen * 3;
298 // code lengths bits
299 var clb = max(clt), clbmsk = (1 << clb) - 1;
300 // code lengths map
301 var clm = hMap(clt, clb, 1);
302 for (var i = 0; i < tl;) {
303 var r = clm[bits(dat, pos, clbmsk)];
304 // bits read
305 pos += r & 15;
306 // symbol
307 var s = r >> 4;
308 // code length to copy
309 if (s < 16) {
310 ldt[i++] = s;
311 }
312 else {
313 // copy count
314 var c = 0, n = 0;
315 if (s == 16)
316 n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];
317 else if (s == 17)
318 n = 3 + bits(dat, pos, 7), pos += 3;
319 else if (s == 18)
320 n = 11 + bits(dat, pos, 127), pos += 7;
321 while (n--)
322 ldt[i++] = c;
323 }
324 }
325 // length tree distance tree
326 var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);
327 // max length bits
328 lbt = max(lt);
329 // max dist bits
330 dbt = max(dt);
331 lm = hMap(lt, lbt, 1);
332 dm = hMap(dt, dbt, 1);
333 }
334 else
335 err(1);
336 if (pos > tbts) {
337 if (noSt)
338 err(0);
339 break;
340 }
341 }
342 // Make sure the buffer can hold this + the largest possible addition
343 // Maximum chunk size (practically, theoretically infinite) is 2^17
344 if (resize)
345 cbuf(bt + 131072);
346 var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;
347 var lpos = pos;
348 for (;; lpos = pos) {
349 // bits read, code
350 var c = lm[bits16(dat, pos) & lms], sym = c >> 4;
351 pos += c & 15;
352 if (pos > tbts) {
353 if (noSt)
354 err(0);
355 break;
356 }
357 if (!c)
358 err(2);
359 if (sym < 256)
360 buf[bt++] = sym;
361 else if (sym == 256) {
362 lpos = pos, lm = null;
363 break;
364 }
365 else {
366 var add = sym - 254;
367 // no extra bits needed if less
368 if (sym > 264) {
369 // index
370 var i = sym - 257, b = fleb[i];
371 add = bits(dat, pos, (1 << b) - 1) + fl[i];
372 pos += b;
373 }
374 // dist
375 var d = dm[bits16(dat, pos) & dms], dsym = d >> 4;
376 if (!d)
377 err(3);
378 pos += d & 15;
379 var dt = fd[dsym];
380 if (dsym > 3) {
381 var b = fdeb[dsym];
382 dt += bits16(dat, pos) & (1 << b) - 1, pos += b;
383 }
384 if (pos > tbts) {
385 if (noSt)
386 err(0);
387 break;
388 }
389 if (resize)
390 cbuf(bt + 131072);
391 var end = bt + add;
392 if (bt < dt) {
393 var shift = dl - dt, dend = Math.min(dt, end);
394 if (shift + bt < 0)
395 err(3);
396 for (; bt < dend; ++bt)
397 buf[bt] = dict[shift + bt];
398 }
399 for (; bt < end; ++bt)
400 buf[bt] = buf[bt - dt];
401 }
402 }
403 st.l = lm, st.p = lpos, st.b = bt, st.f = final;
404 if (lm)
405 final = 1, st.m = lbt, st.d = dm, st.n = dbt;
406 } while (!final);
407 // don't reallocate for streams or user buffers
408 return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
409};
410// starting at p, write the minimum number of bits that can hold v to d
411var wbits = function (d, p, v) {
412 v <<= p & 7;
413 var o = (p / 8) | 0;
414 d[o] |= v;
415 d[o + 1] |= v >> 8;
416};
417// starting at p, write the minimum number of bits (>8) that can hold v to d
418var wbits16 = function (d, p, v) {
419 v <<= p & 7;
420 var o = (p / 8) | 0;
421 d[o] |= v;
422 d[o + 1] |= v >> 8;
423 d[o + 2] |= v >> 16;
424};
425// creates code lengths from a frequency table
426var hTree = function (d, mb) {
427 // Need extra info to make a tree
428 var t = [];
429 for (var i = 0; i < d.length; ++i) {
430 if (d[i])
431 t.push({ s: i, f: d[i] });
432 }
433 var s = t.length;
434 var t2 = t.slice();
435 if (!s)
436 return { t: et, l: 0 };
437 if (s == 1) {
438 var v = new u8(t[0].s + 1);
439 v[t[0].s] = 1;
440 return { t: v, l: 1 };
441 }
442 t.sort(function (a, b) { return a.f - b.f; });
443 // after i2 reaches last ind, will be stopped
444 // freq must be greater than largest possible number of symbols
445 t.push({ s: -1, f: 25001 });
446 var l = t[0], r = t[1], i0 = 0, i1 = 1, i2 = 2;
447 t[0] = { s: -1, f: l.f + r.f, l: l, r: r };
448 // efficient algorithm from UZIP.js
449 // i0 is lookbehind, i2 is lookahead - after processing two low-freq
450 // symbols that combined have high freq, will start processing i2 (high-freq,
451 // non-composite) symbols instead
452 // see https://reddit.com/r/photopea/comments/ikekht/uzipjs_questions/
453 while (i1 != s - 1) {
454 l = t[t[i0].f < t[i2].f ? i0++ : i2++];
455 r = t[i0 != i1 && t[i0].f < t[i2].f ? i0++ : i2++];
456 t[i1++] = { s: -1, f: l.f + r.f, l: l, r: r };
457 }
458 var maxSym = t2[0].s;
459 for (var i = 1; i < s; ++i) {
460 if (t2[i].s > maxSym)
461 maxSym = t2[i].s;
462 }
463 // code lengths
464 var tr = new u16(maxSym + 1);
465 // max bits in tree
466 var mbt = ln(t[i1 - 1], tr, 0);
467 if (mbt > mb) {
468 // more algorithms from UZIP.js
469 // TODO: find out how this code works (debt)
470 // ind debt
471 var i = 0, dt = 0;
472 // left cost
473 var lft = mbt - mb, cst = 1 << lft;
474 t2.sort(function (a, b) { return tr[b.s] - tr[a.s] || a.f - b.f; });
475 for (; i < s; ++i) {
476 var i2_1 = t2[i].s;
477 if (tr[i2_1] > mb) {
478 dt += cst - (1 << (mbt - tr[i2_1]));
479 tr[i2_1] = mb;
480 }
481 else
482 break;
483 }
484 dt >>= lft;
485 while (dt > 0) {
486 var i2_2 = t2[i].s;
487 if (tr[i2_2] < mb)
488 dt -= 1 << (mb - tr[i2_2]++ - 1);
489 else
490 ++i;
491 }
492 for (; i >= 0 && dt; --i) {
493 var i2_3 = t2[i].s;
494 if (tr[i2_3] == mb) {
495 --tr[i2_3];
496 ++dt;
497 }
498 }
499 mbt = mb;
500 }
501 return { t: new u8(tr), l: mbt };
502};
503// get the max length and assign length codes
504var ln = function (n, l, d) {
505 return n.s == -1
506 ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1))
507 : (l[n.s] = d);
508};
509// length codes generation
510var lc = function (c) {
511 var s = c.length;
512 // Note that the semicolon was intentional
513 while (s && !c[--s])
514 ;
515 var cl = new u16(++s);
516 // ind num streak
517 var cli = 0, cln = c[0], cls = 1;
518 var w = function (v) { cl[cli++] = v; };
519 for (var i = 1; i <= s; ++i) {
520 if (c[i] == cln && i != s)
521 ++cls;
522 else {
523 if (!cln && cls > 2) {
524 for (; cls > 138; cls -= 138)
525 w(32754);
526 if (cls > 2) {
527 w(cls > 10 ? ((cls - 11) << 5) | 28690 : ((cls - 3) << 5) | 12305);
528 cls = 0;
529 }
530 }
531 else if (cls > 3) {
532 w(cln), --cls;
533 for (; cls > 6; cls -= 6)
534 w(8304);
535 if (cls > 2)
536 w(((cls - 3) << 5) | 8208), cls = 0;
537 }
538 while (cls--)
539 w(cln);
540 cls = 1;
541 cln = c[i];
542 }
543 }
544 return { c: cl.subarray(0, cli), n: s };
545};
546// calculate the length of output from tree, code lengths
547var clen = function (cf, cl) {
548 var l = 0;
549 for (var i = 0; i < cl.length; ++i)
550 l += cf[i] * cl[i];
551 return l;
552};
553// writes a fixed block
554// returns the new bit pos
555var wfblk = function (out, pos, dat) {
556 // no need to write 00 as type: TypedArray defaults to 0
557 var s = dat.length;
558 var o = shft(pos + 2);
559 out[o] = s & 255;
560 out[o + 1] = s >> 8;
561 out[o + 2] = out[o] ^ 255;
562 out[o + 3] = out[o + 1] ^ 255;
563 for (var i = 0; i < s; ++i)
564 out[o + i + 4] = dat[i];
565 return (o + 4 + s) * 8;
566};
567// writes a block
568var wblk = function (dat, out, final, syms, lf, df, eb, li, bs, bl, p) {
569 wbits(out, p++, final);
570 ++lf[256];
571 var _a = hTree(lf, 15), dlt = _a.t, mlb = _a.l;
572 var _b = hTree(df, 15), ddt = _b.t, mdb = _b.l;
573 var _c = lc(dlt), lclt = _c.c, nlc = _c.n;
574 var _d = lc(ddt), lcdt = _d.c, ndc = _d.n;
575 var lcfreq = new u16(19);
576 for (var i = 0; i < lclt.length; ++i)
577 ++lcfreq[lclt[i] & 31];
578 for (var i = 0; i < lcdt.length; ++i)
579 ++lcfreq[lcdt[i] & 31];
580 var _e = hTree(lcfreq, 7), lct = _e.t, mlcb = _e.l;
581 var nlcc = 19;
582 for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)
583 ;
584 var flen = (bl + 5) << 3;
585 var ftlen = clen(lf, flt) + clen(df, fdt) + eb;
586 var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18];
587 if (bs >= 0 && flen <= ftlen && flen <= dtlen)
588 return wfblk(out, p, dat.subarray(bs, bs + bl));
589 var lm, ll, dm, dl;
590 wbits(out, p, 1 + (dtlen < ftlen)), p += 2;
591 if (dtlen < ftlen) {
592 lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;
593 var llm = hMap(lct, mlcb, 0);
594 wbits(out, p, nlc - 257);
595 wbits(out, p + 5, ndc - 1);
596 wbits(out, p + 10, nlcc - 4);
597 p += 14;
598 for (var i = 0; i < nlcc; ++i)
599 wbits(out, p + 3 * i, lct[clim[i]]);
600 p += 3 * nlcc;
601 var lcts = [lclt, lcdt];
602 for (var it = 0; it < 2; ++it) {
603 var clct = lcts[it];
604 for (var i = 0; i < clct.length; ++i) {
605 var len = clct[i] & 31;
606 wbits(out, p, llm[len]), p += lct[len];
607 if (len > 15)
608 wbits(out, p, (clct[i] >> 5) & 127), p += clct[i] >> 12;
609 }
610 }
611 }
612 else {
613 lm = flm, ll = flt, dm = fdm, dl = fdt;
614 }
615 for (var i = 0; i < li; ++i) {
616 var sym = syms[i];
617 if (sym > 255) {
618 var len = (sym >> 18) & 31;
619 wbits16(out, p, lm[len + 257]), p += ll[len + 257];
620 if (len > 7)
621 wbits(out, p, (sym >> 23) & 31), p += fleb[len];
622 var dst = sym & 31;
623 wbits16(out, p, dm[dst]), p += dl[dst];
624 if (dst > 3)
625 wbits16(out, p, (sym >> 5) & 8191), p += fdeb[dst];
626 }
627 else {
628 wbits16(out, p, lm[sym]), p += ll[sym];
629 }
630 }
631 wbits16(out, p, lm[256]);
632 return p + ll[256];
633};
634// deflate options (nice << 13) | chain
635var deo = /*#__PURE__*/ new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);
636// empty
637var et = /*#__PURE__*/ new u8(0);
638// compresses data into a raw DEFLATE buffer
639var dflt = function (dat, lvl, plvl, pre, post, st) {
640 var s = st.z || dat.length;
641 var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post);
642 // writing to this writes to the output buffer
643 var w = o.subarray(pre, o.length - post);
644 var lst = st.l;
645 var pos = (st.r || 0) & 7;
646 if (lvl) {
647 if (pos)
648 w[0] = st.r >> 3;
649 var opt = deo[lvl - 1];
650 var n = opt >> 13, c = opt & 8191;
651 var msk_1 = (1 << plvl) - 1;
652 // prev 2-byte val map curr 2-byte val map
653 var prev = st.p || new u16(32768), head = st.h || new u16(msk_1 + 1);
654 var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;
655 var hsh = function (i) { return (dat[i] ^ (dat[i + 1] << bs1_1) ^ (dat[i + 2] << bs2_1)) & msk_1; };
656 // 24576 is an arbitrary number of maximum symbols per block
657 // 424 buffer for last block
658 var syms = new i32(25000);
659 // length/literal freq distance freq
660 var lf = new u16(288), df = new u16(32);
661 // l/lcnt exbits index l/lind waitdx blkpos
662 var lc_1 = 0, eb = 0, i = st.i || 0, li = 0, wi = st.w || 0, bs = 0;
663 for (; i + 2 < s; ++i) {
664 // hash value
665 var hv = hsh(i);
666 // index mod 32768 previous index mod
667 var imod = i & 32767, pimod = head[hv];
668 prev[imod] = pimod;
669 head[hv] = imod;
670 // We always should modify head and prev, but only add symbols if
671 // this data is not yet processed ("wait" for wait index)
672 if (wi <= i) {
673 // bytes remaining
674 var rem = s - i;
675 if ((lc_1 > 7000 || li > 24576) && (rem > 423 || !lst)) {
676 pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos);
677 li = lc_1 = eb = 0, bs = i;
678 for (var j = 0; j < 286; ++j)
679 lf[j] = 0;
680 for (var j = 0; j < 30; ++j)
681 df[j] = 0;
682 }
683 // len dist chain
684 var l = 2, d = 0, ch_1 = c, dif = imod - pimod & 32767;
685 if (rem > 2 && hv == hsh(i - dif)) {
686 var maxn = Math.min(n, rem) - 1;
687 var maxd = Math.min(32767, i);
688 // max possible length
689 // not capped at dif because decompressors implement "rolling" index population
690 var ml = Math.min(258, rem);
691 while (dif <= maxd && --ch_1 && imod != pimod) {
692 if (dat[i + l] == dat[i + l - dif]) {
693 var nl = 0;
694 for (; nl < ml && dat[i + nl] == dat[i + nl - dif]; ++nl)
695 ;
696 if (nl > l) {
697 l = nl, d = dif;
698 // break out early when we reach "nice" (we are satisfied enough)
699 if (nl > maxn)
700 break;
701 // now, find the rarest 2-byte sequence within this
702 // length of literals and search for that instead.
703 // Much faster than just using the start
704 var mmd = Math.min(dif, nl - 2);
705 var md = 0;
706 for (var j = 0; j < mmd; ++j) {
707 var ti = i - dif + j & 32767;
708 var pti = prev[ti];
709 var cd = ti - pti & 32767;
710 if (cd > md)
711 md = cd, pimod = ti;
712 }
713 }
714 }
715 // check the previous match
716 imod = pimod, pimod = prev[imod];
717 dif += imod - pimod & 32767;
718 }
719 }
720 // d will be nonzero only when a match was found
721 if (d) {
722 // store both dist and len data in one int32
723 // Make sure this is recognized as a len/dist with 28th bit (2^28)
724 syms[li++] = 268435456 | (revfl[l] << 18) | revfd[d];
725 var lin = revfl[l] & 31, din = revfd[d] & 31;
726 eb += fleb[lin] + fdeb[din];
727 ++lf[257 + lin];
728 ++df[din];
729 wi = i + l;
730 ++lc_1;
731 }
732 else {
733 syms[li++] = dat[i];
734 ++lf[dat[i]];
735 }
736 }
737 }
738 for (i = Math.max(i, wi); i < s; ++i) {
739 syms[li++] = dat[i];
740 ++lf[dat[i]];
741 }
742 pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos);
743 if (!lst) {
744 st.r = (pos & 7) | w[(pos / 8) | 0] << 3;
745 // shft(pos) now 1 less if pos & 7 != 0
746 pos -= 7;
747 st.h = head, st.p = prev, st.i = i, st.w = wi;
748 }
749 }
750 else {
751 for (var i = st.w || 0; i < s + lst; i += 65535) {
752 // end
753 var e = i + 65535;
754 if (e >= s) {
755 // write final block
756 w[(pos / 8) | 0] = lst;
757 e = s;
758 }
759 pos = wfblk(w, pos + 1, dat.subarray(i, e));
760 }
761 st.i = s;
762 }
763 return slc(o, 0, pre + shft(pos) + post);
764};
765// CRC32 table
766var crct = /*#__PURE__*/ (function () {
767 var t = new Int32Array(256);
768 for (var i = 0; i < 256; ++i) {
769 var c = i, k = 9;
770 while (--k)
771 c = ((c & 1) && -306674912) ^ (c >>> 1);
772 t[i] = c;
773 }
774 return t;
775})();
776// CRC32
777var crc = function () {
778 var c = -1;
779 return {
780 p: function (d) {
781 // closures have awful performance
782 var cr = c;
783 for (var i = 0; i < d.length; ++i)
784 cr = crct[(cr & 255) ^ d[i]] ^ (cr >>> 8);
785 c = cr;
786 },
787 d: function () { return ~c; }
788 };
789};
790// Adler32
791var adler = function () {
792 var a = 1, b = 0;
793 return {
794 p: function (d) {
795 // closures have awful performance
796 var n = a, m = b;
797 var l = d.length | 0;
798 for (var i = 0; i != l;) {
799 var e = Math.min(i + 2655, l);
800 for (; i < e; ++i)
801 m += n += d[i];
802 n = (n & 65535) + 15 * (n >> 16), m = (m & 65535) + 15 * (m >> 16);
803 }
804 a = n, b = m;
805 },
806 d: function () {
807 a %= 65521, b %= 65521;
808 return (a & 255) << 24 | (a & 0xFF00) << 8 | (b & 255) << 8 | (b >> 8);
809 }
810 };
811};
812;
813// deflate with opts
814var dopt = function (dat, opt, pre, post, st) {
815 if (!st) {
816 st = { l: 1 };
817 if (opt.dictionary) {
818 var dict = opt.dictionary.subarray(-32768);
819 var newDat = new u8(dict.length + dat.length);
820 newDat.set(dict);
821 newDat.set(dat, dict.length);
822 dat = newDat;
823 st.w = dict.length;
824 }
825 }
826 return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? (st.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20) : (12 + opt.mem), pre, post, st);
827};
828// Walmart object spread
829var mrg = function (a, b) {
830 var o = {};
831 for (var k in a)
832 o[k] = a[k];
833 for (var k in b)
834 o[k] = b[k];
835 return o;
836};
837// worker clone
838// This is possibly the craziest part of the entire codebase, despite how simple it may seem.
839// The only parameter to this function is a closure that returns an array of variables outside of the function scope.
840// We're going to try to figure out the variable names used in the closure as strings because that is crucial for workerization.
841// We will return an object mapping of true variable name to value (basically, the current scope as a JS object).
842// The reason we can't just use the original variable names is minifiers mangling the toplevel scope.
843// This took me three weeks to figure out how to do.
844var wcln = function (fn, fnStr, td) {
845 var dt = fn();
846 var st = fn.toString();
847 var ks = st.slice(st.indexOf('[') + 1, st.lastIndexOf(']')).replace(/\s+/g, '').split(',');
848 for (var i = 0; i < dt.length; ++i) {
849 var v = dt[i], k = ks[i];
850 if (typeof v == 'function') {
851 fnStr += ';' + k + '=';
852 var st_1 = v.toString();
853 if (v.prototype) {
854 // for global objects
855 if (st_1.indexOf('[native code]') != -1) {
856 var spInd = st_1.indexOf(' ', 8) + 1;
857 fnStr += st_1.slice(spInd, st_1.indexOf('(', spInd));
858 }
859 else {
860 fnStr += st_1;
861 for (var t in v.prototype)
862 fnStr += ';' + k + '.prototype.' + t + '=' + v.prototype[t].toString();
863 }
864 }
865 else
866 fnStr += st_1;
867 }
868 else
869 td[k] = v;
870 }
871 return fnStr;
872};
873var ch = [];
874// clone bufs
875var cbfs = function (v) {
876 var tl = [];
877 for (var k in v) {
878 if (v[k].buffer) {
879 tl.push((v[k] = new v[k].constructor(v[k])).buffer);
880 }
881 }
882 return tl;
883};
884// use a worker to execute code
885var wrkr = function (fns, init, id, cb) {
886 if (!ch[id]) {
887 var fnStr = '', td_1 = {}, m = fns.length - 1;
888 for (var i = 0; i < m; ++i)
889 fnStr = wcln(fns[i], fnStr, td_1);
890 ch[id] = { c: wcln(fns[m], fnStr, td_1), e: td_1 };
891 }
892 var td = mrg({}, ch[id].e);
893 return (0, node_worker_1.default)(ch[id].c + ';onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage=' + init.toString() + '}', id, td, cbfs(td), cb);
894};
895// base async inflate fn
896var bInflt = function () { return [u8, u16, i32, fleb, fdeb, clim, fl, fd, flrm, fdrm, rev, ec, hMap, max, bits, bits16, shft, slc, err, inflt, inflateSync, pbf, gopt]; };
897var bDflt = function () { return [u8, u16, i32, fleb, fdeb, clim, revfl, revfd, flm, flt, fdm, fdt, rev, deo, et, hMap, wbits, wbits16, hTree, ln, lc, clen, wfblk, wblk, shft, slc, dflt, dopt, deflateSync, pbf]; };
898// gzip extra
899var gze = function () { return [gzh, gzhl, wbytes, crc, crct]; };
900// gunzip extra
901var guze = function () { return [gzs, gzl]; };
902// zlib extra
903var zle = function () { return [zlh, wbytes, adler]; };
904// unzlib extra
905var zule = function () { return [zls]; };
906// post buf
907var pbf = function (msg) { return postMessage(msg, [msg.buffer]); };
908// get opts
909var gopt = function (o) { return o && {
910 out: o.size && new u8(o.size),
911 dictionary: o.dictionary
912}; };
913// async helper
914var cbify = function (dat, opts, fns, init, id, cb) {
915 var w = wrkr(fns, init, id, function (err, dat) {
916 w.terminate();
917 cb(err, dat);
918 });
919 w.postMessage([dat, opts], opts.consume ? [dat.buffer] : []);
920 return function () { w.terminate(); };
921};
922// auto stream
923var astrm = function (strm) {
924 strm.ondata = function (dat, final) { return postMessage([dat, final], [dat.buffer]); };
925 return function (ev) {
926 if (ev.data.length) {
927 strm.push(ev.data[0], ev.data[1]);
928 postMessage([ev.data[0].length]);
929 }
930 else
931 strm.flush();
932 };
933};
934// async stream attach
935var astrmify = function (fns, strm, opts, init, id, flush, ext) {
936 var t;
937 var w = wrkr(fns, init, id, function (err, dat) {
938 if (err)
939 w.terminate(), strm.ondata.call(strm, err);
940 else if (!Array.isArray(dat))
941 ext(dat);
942 else if (dat.length == 1) {
943 strm.queuedSize -= dat[0];
944 if (strm.ondrain)
945 strm.ondrain(dat[0]);
946 }
947 else {
948 if (dat[1])
949 w.terminate();
950 strm.ondata.call(strm, err, dat[0], dat[1]);
951 }
952 });
953 w.postMessage(opts);
954 strm.queuedSize = 0;
955 strm.push = function (d, f) {
956 if (!strm.ondata)
957 err(5);
958 if (t)
959 strm.ondata(err(4, 0, 1), null, !!f);
960 strm.queuedSize += d.length;
961 w.postMessage([d, t = f], [d.buffer]);
962 };
963 strm.terminate = function () { w.terminate(); };
964 if (flush) {
965 strm.flush = function () { w.postMessage([]); };
966 }
967};
968// read 2 bytes
969var b2 = function (d, b) { return d[b] | (d[b + 1] << 8); };
970// read 4 bytes
971var b4 = function (d, b) { return (d[b] | (d[b + 1] << 8) | (d[b + 2] << 16) | (d[b + 3] << 24)) >>> 0; };
972var b8 = function (d, b) { return b4(d, b) + (b4(d, b + 4) * 4294967296); };
973// write bytes
974var wbytes = function (d, b, v) {
975 for (; v; ++b)
976 d[b] = v, v >>>= 8;
977};
978// gzip header
979var gzh = function (c, o) {
980 var fn = o.filename;
981 c[0] = 31, c[1] = 139, c[2] = 8, c[8] = o.level < 2 ? 4 : o.level == 9 ? 2 : 0, c[9] = 3; // assume Unix
982 if (o.mtime != 0)
983 wbytes(c, 4, Math.floor(new Date(o.mtime || Date.now()) / 1000));
984 if (fn) {
985 c[3] = 8;
986 for (var i = 0; i <= fn.length; ++i)
987 c[i + 10] = fn.charCodeAt(i);
988 }
989};
990// gzip footer: -8 to -4 = CRC, -4 to -0 is length
991// gzip start
992var gzs = function (d) {
993 if (d[0] != 31 || d[1] != 139 || d[2] != 8)
994 err(6, 'invalid gzip data');
995 var flg = d[3];
996 var st = 10;
997 if (flg & 4)
998 st += (d[10] | d[11] << 8) + 2;
999 for (var zs = (flg >> 3 & 1) + (flg >> 4 & 1); zs > 0; zs -= !d[st++])
1000 ;
1001 return st + (flg & 2);
1002};
1003// gzip length
1004var gzl = function (d) {
1005 var l = d.length;
1006 return (d[l - 4] | d[l - 3] << 8 | d[l - 2] << 16 | d[l - 1] << 24) >>> 0;
1007};
1008// gzip header length
1009var gzhl = function (o) { return 10 + (o.filename ? o.filename.length + 1 : 0); };
1010// zlib header
1011var zlh = function (c, o) {
1012 var lv = o.level, fl = lv == 0 ? 0 : lv < 6 ? 1 : lv == 9 ? 3 : 2;
1013 c[0] = 120, c[1] = (fl << 6) | (o.dictionary && 32);
1014 c[1] |= 31 - ((c[0] << 8) | c[1]) % 31;
1015 if (o.dictionary) {
1016 var h = adler();
1017 h.p(o.dictionary);
1018 wbytes(c, 2, h.d());
1019 }
1020};
1021// zlib start
1022var zls = function (d, dict) {
1023 if ((d[0] & 15) != 8 || (d[0] >> 4) > 7 || ((d[0] << 8 | d[1]) % 31))
1024 err(6, 'invalid zlib data');
1025 if ((d[1] >> 5 & 1) == +!dict)
1026 err(6, 'invalid zlib data: ' + (d[1] & 32 ? 'need' : 'unexpected') + ' dictionary');
1027 return (d[1] >> 3 & 4) + 2;
1028};
1029function StrmOpt(opts, cb) {
1030 if (typeof opts == 'function')
1031 cb = opts, opts = {};
1032 this.ondata = cb;
1033 return opts;
1034}
1035/**
1036 * Streaming DEFLATE compression
1037 */
1038var Deflate = /*#__PURE__*/ (function () {
1039 function Deflate(opts, cb) {
1040 if (typeof opts == 'function')
1041 cb = opts, opts = {};
1042 this.ondata = cb;
1043 this.o = opts || {};
1044 this.s = { l: 0, i: 32768, w: 32768, z: 32768 };
1045 // Buffer length must always be 0 mod 32768 for index calculations to be correct when modifying head and prev
1046 // 98304 = 32768 (lookback) + 65536 (common chunk size)
1047 this.b = new u8(98304);
1048 if (this.o.dictionary) {
1049 var dict = this.o.dictionary.subarray(-32768);
1050 this.b.set(dict, 32768 - dict.length);
1051 this.s.i = 32768 - dict.length;
1052 }
1053 }
1054 Deflate.prototype.p = function (c, f) {
1055 this.ondata(dopt(c, this.o, 0, 0, this.s), f);
1056 };
1057 /**
1058 * Pushes a chunk to be deflated
1059 * @param chunk The chunk to push
1060 * @param final Whether this is the last chunk
1061 */
1062 Deflate.prototype.push = function (chunk, final) {
1063 if (!this.ondata)
1064 err(5);
1065 if (this.s.l)
1066 err(4);
1067 var endLen = chunk.length + this.s.z;
1068 if (endLen > this.b.length) {
1069 if (endLen > 2 * this.b.length - 32768) {
1070 var newBuf = new u8(endLen & -32768);
1071 newBuf.set(this.b.subarray(0, this.s.z));
1072 this.b = newBuf;
1073 }
1074 var split = this.b.length - this.s.z;
1075 this.b.set(chunk.subarray(0, split), this.s.z);
1076 this.s.z = this.b.length;
1077 this.p(this.b, false);
1078 this.b.set(this.b.subarray(-32768));
1079 this.b.set(chunk.subarray(split), 32768);
1080 this.s.z = chunk.length - split + 32768;
1081 this.s.i = 32766, this.s.w = 32768;
1082 }
1083 else {
1084 this.b.set(chunk, this.s.z);
1085 this.s.z += chunk.length;
1086 }
1087 this.s.l = final & 1;
1088 if (this.s.z > this.s.w + 8191 || final) {
1089 this.p(this.b, final || false);
1090 this.s.w = this.s.i, this.s.i -= 2;
1091 }
1092 };
1093 /**
1094 * Flushes buffered uncompressed data. Useful to immediately retrieve the
1095 * deflated output for small inputs.
1096 */
1097 Deflate.prototype.flush = function () {
1098 if (!this.ondata)
1099 err(5);
1100 if (this.s.l)
1101 err(4);
1102 this.p(this.b, false);
1103 this.s.w = this.s.i, this.s.i -= 2;
1104 };
1105 return Deflate;
1106}());
1107exports.Deflate = Deflate;
1108/**
1109 * Asynchronous streaming DEFLATE compression
1110 */
1111var AsyncDeflate = /*#__PURE__*/ (function () {
1112 function AsyncDeflate(opts, cb) {
1113 astrmify([
1114 bDflt,
1115 function () { return [astrm, Deflate]; }
1116 ], this, StrmOpt.call(this, opts, cb), function (ev) {
1117 var strm = new Deflate(ev.data);
1118 onmessage = astrm(strm);
1119 }, 6, 1);
1120 }
1121 return AsyncDeflate;
1122}());
1123exports.AsyncDeflate = AsyncDeflate;
1124function deflate(data, opts, cb) {
1125 if (!cb)
1126 cb = opts, opts = {};
1127 if (typeof cb != 'function')
1128 err(7);
1129 return cbify(data, opts, [
1130 bDflt,
1131 ], function (ev) { return pbf(deflateSync(ev.data[0], ev.data[1])); }, 0, cb);
1132}
1133exports.deflate = deflate;
1134/**
1135 * Compresses data with DEFLATE without any wrapper
1136 * @param data The data to compress
1137 * @param opts The compression options
1138 * @returns The deflated version of the data
1139 */
1140function deflateSync(data, opts) {
1141 return dopt(data, opts || {}, 0, 0);
1142}
1143exports.deflateSync = deflateSync;
1144/**
1145 * Streaming DEFLATE decompression
1146 */
1147var Inflate = /*#__PURE__*/ (function () {
1148 function Inflate(opts, cb) {
1149 // no StrmOpt here to avoid adding to workerizer
1150 if (typeof opts == 'function')
1151 cb = opts, opts = {};
1152 this.ondata = cb;
1153 var dict = opts && opts.dictionary && opts.dictionary.subarray(-32768);
1154 this.s = { i: 0, b: dict ? dict.length : 0 };
1155 this.o = new u8(32768);
1156 this.p = new u8(0);
1157 if (dict)
1158 this.o.set(dict);
1159 }
1160 Inflate.prototype.e = function (c) {
1161 if (!this.ondata)
1162 err(5);
1163 if (this.d)
1164 err(4);
1165 if (!this.p.length)
1166 this.p = c;
1167 else if (c.length) {
1168 var n = new u8(this.p.length + c.length);
1169 n.set(this.p), n.set(c, this.p.length), this.p = n;
1170 }
1171 };
1172 Inflate.prototype.c = function (final) {
1173 this.s.i = +(this.d = final || false);
1174 var bts = this.s.b;
1175 var dt = inflt(this.p, this.s, this.o);
1176 this.ondata(slc(dt, bts, this.s.b), this.d);
1177 this.o = slc(dt, this.s.b - 32768), this.s.b = this.o.length;
1178 this.p = slc(this.p, (this.s.p / 8) | 0), this.s.p &= 7;
1179 };
1180 /**
1181 * Pushes a chunk to be inflated
1182 * @param chunk The chunk to push
1183 * @param final Whether this is the final chunk
1184 */
1185 Inflate.prototype.push = function (chunk, final) {
1186 this.e(chunk), this.c(final);
1187 };
1188 return Inflate;
1189}());
1190exports.Inflate = Inflate;
1191/**
1192 * Asynchronous streaming DEFLATE decompression
1193 */
1194var AsyncInflate = /*#__PURE__*/ (function () {
1195 function AsyncInflate(opts, cb) {
1196 astrmify([
1197 bInflt,
1198 function () { return [astrm, Inflate]; }
1199 ], this, StrmOpt.call(this, opts, cb), function (ev) {
1200 var strm = new Inflate(ev.data);
1201 onmessage = astrm(strm);
1202 }, 7, 0);
1203 }
1204 return AsyncInflate;
1205}());
1206exports.AsyncInflate = AsyncInflate;
1207function inflate(data, opts, cb) {
1208 if (!cb)
1209 cb = opts, opts = {};
1210 if (typeof cb != 'function')
1211 err(7);
1212 return cbify(data, opts, [
1213 bInflt
1214 ], function (ev) { return pbf(inflateSync(ev.data[0], gopt(ev.data[1]))); }, 1, cb);
1215}
1216exports.inflate = inflate;
1217/**
1218 * Expands DEFLATE data with no wrapper
1219 * @param data The data to decompress
1220 * @param opts The decompression options
1221 * @returns The decompressed version of the data
1222 */
1223function inflateSync(data, opts) {
1224 return inflt(data, { i: 2 }, opts && opts.out, opts && opts.dictionary);
1225}
1226exports.inflateSync = inflateSync;
1227// before you yell at me for not just using extends, my reason is that TS inheritance is hard to workerize.
1228/**
1229 * Streaming GZIP compression
1230 */
1231var Gzip = /*#__PURE__*/ (function () {
1232 function Gzip(opts, cb) {
1233 this.c = crc();
1234 this.l = 0;
1235 this.v = 1;
1236 Deflate.call(this, opts, cb);
1237 }
1238 /**
1239 * Pushes a chunk to be GZIPped
1240 * @param chunk The chunk to push
1241 * @param final Whether this is the last chunk
1242 */
1243 Gzip.prototype.push = function (chunk, final) {
1244 this.c.p(chunk);
1245 this.l += chunk.length;
1246 Deflate.prototype.push.call(this, chunk, final);
1247 };
1248 Gzip.prototype.p = function (c, f) {
1249 var raw = dopt(c, this.o, this.v && gzhl(this.o), f && 8, this.s);
1250 if (this.v)
1251 gzh(raw, this.o), this.v = 0;
1252 if (f)
1253 wbytes(raw, raw.length - 8, this.c.d()), wbytes(raw, raw.length - 4, this.l);
1254 this.ondata(raw, f);
1255 };
1256 /**
1257 * Flushes buffered uncompressed data. Useful to immediately retrieve the
1258 * GZIPped output for small inputs.
1259 */
1260 Gzip.prototype.flush = function () {
1261 Deflate.prototype.flush.call(this);
1262 };
1263 return Gzip;
1264}());
1265exports.Gzip = Gzip;
1266exports.Compress = Gzip;
1267/**
1268 * Asynchronous streaming GZIP compression
1269 */
1270var AsyncGzip = /*#__PURE__*/ (function () {
1271 function AsyncGzip(opts, cb) {
1272 astrmify([
1273 bDflt,
1274 gze,
1275 function () { return [astrm, Deflate, Gzip]; }
1276 ], this, StrmOpt.call(this, opts, cb), function (ev) {
1277 var strm = new Gzip(ev.data);
1278 onmessage = astrm(strm);
1279 }, 8, 1);
1280 }
1281 return AsyncGzip;
1282}());
1283exports.AsyncGzip = AsyncGzip;
1284exports.AsyncCompress = AsyncGzip;
1285function gzip(data, opts, cb) {
1286 if (!cb)
1287 cb = opts, opts = {};
1288 if (typeof cb != 'function')
1289 err(7);
1290 return cbify(data, opts, [
1291 bDflt,
1292 gze,
1293 function () { return [gzipSync]; }
1294 ], function (ev) { return pbf(gzipSync(ev.data[0], ev.data[1])); }, 2, cb);
1295}
1296exports.gzip = gzip;
1297exports.compress = gzip;
1298/**
1299 * Compresses data with GZIP
1300 * @param data The data to compress
1301 * @param opts The compression options
1302 * @returns The gzipped version of the data
1303 */
1304function gzipSync(data, opts) {
1305 if (!opts)
1306 opts = {};
1307 var c = crc(), l = data.length;
1308 c.p(data);
1309 var d = dopt(data, opts, gzhl(opts), 8), s = d.length;
1310 return gzh(d, opts), wbytes(d, s - 8, c.d()), wbytes(d, s - 4, l), d;
1311}
1312exports.gzipSync = gzipSync;
1313exports.compressSync = gzipSync;
1314/**
1315 * Streaming single or multi-member GZIP decompression
1316 */
1317var Gunzip = /*#__PURE__*/ (function () {
1318 function Gunzip(opts, cb) {
1319 this.v = 1;
1320 this.r = 0;
1321 Inflate.call(this, opts, cb);
1322 }
1323 /**
1324 * Pushes a chunk to be GUNZIPped
1325 * @param chunk The chunk to push
1326 * @param final Whether this is the last chunk
1327 */
1328 Gunzip.prototype.push = function (chunk, final) {
1329 Inflate.prototype.e.call(this, chunk);
1330 this.r += chunk.length;
1331 if (this.v) {
1332 var p = this.p.subarray(this.v - 1);
1333 var s = p.length > 3 ? gzs(p) : 4;
1334 if (s > p.length) {
1335 if (!final)
1336 return;
1337 }
1338 else if (this.v > 1 && this.onmember) {
1339 this.onmember(this.r - p.length);
1340 }
1341 this.p = p.subarray(s), this.v = 0;
1342 }
1343 // necessary to prevent TS from using the closure value
1344 // This allows for workerization to function correctly
1345 Inflate.prototype.c.call(this, final);
1346 // process concatenated GZIP
1347 if (this.s.f && !this.s.l && !final) {
1348 this.v = shft(this.s.p) + 9;
1349 this.s = { i: 0 };
1350 this.o = new u8(0);
1351 this.push(new u8(0), final);
1352 }
1353 };
1354 return Gunzip;
1355}());
1356exports.Gunzip = Gunzip;
1357/**
1358 * Asynchronous streaming single or multi-member GZIP decompression
1359 */
1360var AsyncGunzip = /*#__PURE__*/ (function () {
1361 function AsyncGunzip(opts, cb) {
1362 var _this = this;
1363 astrmify([
1364 bInflt,
1365 guze,
1366 function () { return [astrm, Inflate, Gunzip]; }
1367 ], this, StrmOpt.call(this, opts, cb), function (ev) {
1368 var strm = new Gunzip(ev.data);
1369 strm.onmember = function (offset) { return postMessage(offset); };
1370 onmessage = astrm(strm);
1371 }, 9, 0, function (offset) { return _this.onmember && _this.onmember(offset); });
1372 }
1373 return AsyncGunzip;
1374}());
1375exports.AsyncGunzip = AsyncGunzip;
1376function gunzip(data, opts, cb) {
1377 if (!cb)
1378 cb = opts, opts = {};
1379 if (typeof cb != 'function')
1380 err(7);
1381 return cbify(data, opts, [
1382 bInflt,
1383 guze,
1384 function () { return [gunzipSync]; }
1385 ], function (ev) { return pbf(gunzipSync(ev.data[0], ev.data[1])); }, 3, cb);
1386}
1387exports.gunzip = gunzip;
1388/**
1389 * Expands GZIP data
1390 * @param data The data to decompress
1391 * @param opts The decompression options
1392 * @returns The decompressed version of the data
1393 */
1394function gunzipSync(data, opts) {
1395 var st = gzs(data);
1396 if (st + 8 > data.length)
1397 err(6, 'invalid gzip data');
1398 return inflt(data.subarray(st, -8), { i: 2 }, opts && opts.out || new u8(gzl(data)), opts && opts.dictionary);
1399}
1400exports.gunzipSync = gunzipSync;
1401/**
1402 * Streaming Zlib compression
1403 */
1404var Zlib = /*#__PURE__*/ (function () {
1405 function Zlib(opts, cb) {
1406 this.c = adler();
1407 this.v = 1;
1408 Deflate.call(this, opts, cb);
1409 }
1410 /**
1411 * Pushes a chunk to be zlibbed
1412 * @param chunk The chunk to push
1413 * @param final Whether this is the last chunk
1414 */
1415 Zlib.prototype.push = function (chunk, final) {
1416 this.c.p(chunk);
1417 Deflate.prototype.push.call(this, chunk, final);
1418 };
1419 Zlib.prototype.p = function (c, f) {
1420 var raw = dopt(c, this.o, this.v && (this.o.dictionary ? 6 : 2), f && 4, this.s);
1421 if (this.v)
1422 zlh(raw, this.o), this.v = 0;
1423 if (f)
1424 wbytes(raw, raw.length - 4, this.c.d());
1425 this.ondata(raw, f);
1426 };
1427 /**
1428 * Flushes buffered uncompressed data. Useful to immediately retrieve the
1429 * zlibbed output for small inputs.
1430 */
1431 Zlib.prototype.flush = function () {
1432 Deflate.prototype.flush.call(this);
1433 };
1434 return Zlib;
1435}());
1436exports.Zlib = Zlib;
1437/**
1438 * Asynchronous streaming Zlib compression
1439 */
1440var AsyncZlib = /*#__PURE__*/ (function () {
1441 function AsyncZlib(opts, cb) {
1442 astrmify([
1443 bDflt,
1444 zle,
1445 function () { return [astrm, Deflate, Zlib]; }
1446 ], this, StrmOpt.call(this, opts, cb), function (ev) {
1447 var strm = new Zlib(ev.data);
1448 onmessage = astrm(strm);
1449 }, 10, 1);
1450 }
1451 return AsyncZlib;
1452}());
1453exports.AsyncZlib = AsyncZlib;
1454function zlib(data, opts, cb) {
1455 if (!cb)
1456 cb = opts, opts = {};
1457 if (typeof cb != 'function')
1458 err(7);
1459 return cbify(data, opts, [
1460 bDflt,
1461 zle,
1462 function () { return [zlibSync]; }
1463 ], function (ev) { return pbf(zlibSync(ev.data[0], ev.data[1])); }, 4, cb);
1464}
1465exports.zlib = zlib;
1466/**
1467 * Compress data with Zlib
1468 * @param data The data to compress
1469 * @param opts The compression options
1470 * @returns The zlib-compressed version of the data
1471 */
1472function zlibSync(data, opts) {
1473 if (!opts)
1474 opts = {};
1475 var a = adler();
1476 a.p(data);
1477 var d = dopt(data, opts, opts.dictionary ? 6 : 2, 4);
1478 return zlh(d, opts), wbytes(d, d.length - 4, a.d()), d;
1479}
1480exports.zlibSync = zlibSync;
1481/**
1482 * Streaming Zlib decompression
1483 */
1484var Unzlib = /*#__PURE__*/ (function () {
1485 function Unzlib(opts, cb) {
1486 Inflate.call(this, opts, cb);
1487 this.v = opts && opts.dictionary ? 2 : 1;
1488 }
1489 /**
1490 * Pushes a chunk to be unzlibbed
1491 * @param chunk The chunk to push
1492 * @param final Whether this is the last chunk
1493 */
1494 Unzlib.prototype.push = function (chunk, final) {
1495 Inflate.prototype.e.call(this, chunk);
1496 if (this.v) {
1497 if (this.p.length < 6 && !final)
1498 return;
1499 this.p = this.p.subarray(zls(this.p, this.v - 1)), this.v = 0;
1500 }
1501 if (final) {
1502 if (this.p.length < 4)
1503 err(6, 'invalid zlib data');
1504 this.p = this.p.subarray(0, -4);
1505 }
1506 // necessary to prevent TS from using the closure value
1507 // This allows for workerization to function correctly
1508 Inflate.prototype.c.call(this, final);
1509 };
1510 return Unzlib;
1511}());
1512exports.Unzlib = Unzlib;
1513/**
1514 * Asynchronous streaming Zlib decompression
1515 */
1516var AsyncUnzlib = /*#__PURE__*/ (function () {
1517 function AsyncUnzlib(opts, cb) {
1518 astrmify([
1519 bInflt,
1520 zule,
1521 function () { return [astrm, Inflate, Unzlib]; }
1522 ], this, StrmOpt.call(this, opts, cb), function (ev) {
1523 var strm = new Unzlib(ev.data);
1524 onmessage = astrm(strm);
1525 }, 11, 0);
1526 }
1527 return AsyncUnzlib;
1528}());
1529exports.AsyncUnzlib = AsyncUnzlib;
1530function unzlib(data, opts, cb) {
1531 if (!cb)
1532 cb = opts, opts = {};
1533 if (typeof cb != 'function')
1534 err(7);
1535 return cbify(data, opts, [
1536 bInflt,
1537 zule,
1538 function () { return [unzlibSync]; }
1539 ], function (ev) { return pbf(unzlibSync(ev.data[0], gopt(ev.data[1]))); }, 5, cb);
1540}
1541exports.unzlib = unzlib;
1542/**
1543 * Expands Zlib data
1544 * @param data The data to decompress
1545 * @param opts The decompression options
1546 * @returns The decompressed version of the data
1547 */
1548function unzlibSync(data, opts) {
1549 return inflt(data.subarray(zls(data, opts && opts.dictionary), -4), { i: 2 }, opts && opts.out, opts && opts.dictionary);
1550}
1551exports.unzlibSync = unzlibSync;
1552/**
1553 * Streaming GZIP, Zlib, or raw DEFLATE decompression
1554 */
1555var Decompress = /*#__PURE__*/ (function () {
1556 function Decompress(opts, cb) {
1557 this.o = StrmOpt.call(this, opts, cb) || {};
1558 this.G = Gunzip;
1559 this.I = Inflate;
1560 this.Z = Unzlib;
1561 }
1562 // init substream
1563 // overriden by AsyncDecompress
1564 Decompress.prototype.i = function () {
1565 var _this = this;
1566 this.s.ondata = function (dat, final) {
1567 _this.ondata(dat, final);
1568 };
1569 };
1570 /**
1571 * Pushes a chunk to be decompressed
1572 * @param chunk The chunk to push
1573 * @param final Whether this is the last chunk
1574 */
1575 Decompress.prototype.push = function (chunk, final) {
1576 if (!this.ondata)
1577 err(5);
1578 if (!this.s) {
1579 if (this.p && this.p.length) {
1580 var n = new u8(this.p.length + chunk.length);
1581 n.set(this.p), n.set(chunk, this.p.length);
1582 }
1583 else
1584 this.p = chunk;
1585 if (this.p.length > 2) {
1586 this.s = (this.p[0] == 31 && this.p[1] == 139 && this.p[2] == 8)
1587 ? new this.G(this.o)
1588 : ((this.p[0] & 15) != 8 || (this.p[0] >> 4) > 7 || ((this.p[0] << 8 | this.p[1]) % 31))
1589 ? new this.I(this.o)
1590 : new this.Z(this.o);
1591 this.i();
1592 this.s.push(this.p, final);
1593 this.p = null;
1594 }
1595 }
1596 else
1597 this.s.push(chunk, final);
1598 };
1599 return Decompress;
1600}());
1601exports.Decompress = Decompress;
1602/**
1603 * Asynchronous streaming GZIP, Zlib, or raw DEFLATE decompression
1604 */
1605var AsyncDecompress = /*#__PURE__*/ (function () {
1606 function AsyncDecompress(opts, cb) {
1607 Decompress.call(this, opts, cb);
1608 this.queuedSize = 0;
1609 this.G = AsyncGunzip;
1610 this.I = AsyncInflate;
1611 this.Z = AsyncUnzlib;
1612 }
1613 AsyncDecompress.prototype.i = function () {
1614 var _this = this;
1615 this.s.ondata = function (err, dat, final) {
1616 _this.ondata(err, dat, final);
1617 };
1618 this.s.ondrain = function (size) {
1619 _this.queuedSize -= size;
1620 if (_this.ondrain)
1621 _this.ondrain(size);
1622 };
1623 };
1624 /**
1625 * Pushes a chunk to be decompressed
1626 * @param chunk The chunk to push
1627 * @param final Whether this is the last chunk
1628 */
1629 AsyncDecompress.prototype.push = function (chunk, final) {
1630 this.queuedSize += chunk.length;
1631 Decompress.prototype.push.call(this, chunk, final);
1632 };
1633 return AsyncDecompress;
1634}());
1635exports.AsyncDecompress = AsyncDecompress;
1636function decompress(data, opts, cb) {
1637 if (!cb)
1638 cb = opts, opts = {};
1639 if (typeof cb != 'function')
1640 err(7);
1641 return (data[0] == 31 && data[1] == 139 && data[2] == 8)
1642 ? gunzip(data, opts, cb)
1643 : ((data[0] & 15) != 8 || (data[0] >> 4) > 7 || ((data[0] << 8 | data[1]) % 31))
1644 ? inflate(data, opts, cb)
1645 : unzlib(data, opts, cb);
1646}
1647exports.decompress = decompress;
1648/**
1649 * Expands compressed GZIP, Zlib, or raw DEFLATE data, automatically detecting the format
1650 * @param data The data to decompress
1651 * @param opts The decompression options
1652 * @returns The decompressed version of the data
1653 */
1654function decompressSync(data, opts) {
1655 return (data[0] == 31 && data[1] == 139 && data[2] == 8)
1656 ? gunzipSync(data, opts)
1657 : ((data[0] & 15) != 8 || (data[0] >> 4) > 7 || ((data[0] << 8 | data[1]) % 31))
1658 ? inflateSync(data, opts)
1659 : unzlibSync(data, opts);
1660}
1661exports.decompressSync = decompressSync;
1662// flatten a directory structure
1663var fltn = function (d, p, t, o) {
1664 for (var k in d) {
1665 var val = d[k], n = p + k, op = o;
1666 if (Array.isArray(val))
1667 op = mrg(o, val[1]), val = val[0];
1668 if (val instanceof u8)
1669 t[n] = [val, op];
1670 else {
1671 t[n += '/'] = [new u8(0), op];
1672 fltn(val, n, t, o);
1673 }
1674 }
1675};
1676// text encoder
1677var te = typeof TextEncoder != 'undefined' && /*#__PURE__*/ new TextEncoder();
1678// text decoder
1679var td = typeof TextDecoder != 'undefined' && /*#__PURE__*/ new TextDecoder();
1680// text decoder stream
1681var tds = 0;
1682try {
1683 td.decode(et, { stream: true });
1684 tds = 1;
1685}
1686catch (e) { }
1687// decode UTF8
1688var dutf8 = function (d) {
1689 for (var r = '', i = 0;;) {
1690 var c = d[i++];
1691 var eb = (c > 127) + (c > 223) + (c > 239);
1692 if (i + eb > d.length)
1693 return { s: r, r: slc(d, i - 1) };
1694 if (!eb)
1695 r += String.fromCharCode(c);
1696 else if (eb == 3) {
1697 c = ((c & 15) << 18 | (d[i++] & 63) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63)) - 65536,
1698 r += String.fromCharCode(55296 | (c >> 10), 56320 | (c & 1023));
1699 }
1700 else if (eb & 1)
1701 r += String.fromCharCode((c & 31) << 6 | (d[i++] & 63));
1702 else
1703 r += String.fromCharCode((c & 15) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63));
1704 }
1705};
1706/**
1707 * Streaming UTF-8 decoding
1708 */
1709var DecodeUTF8 = /*#__PURE__*/ (function () {
1710 /**
1711 * Creates a UTF-8 decoding stream
1712 * @param cb The callback to call whenever data is decoded
1713 */
1714 function DecodeUTF8(cb) {
1715 this.ondata = cb;
1716 if (tds)
1717 this.t = new TextDecoder();
1718 else
1719 this.p = et;
1720 }
1721 /**
1722 * Pushes a chunk to be decoded from UTF-8 binary
1723 * @param chunk The chunk to push
1724 * @param final Whether this is the last chunk
1725 */
1726 DecodeUTF8.prototype.push = function (chunk, final) {
1727 if (!this.ondata)
1728 err(5);
1729 final = !!final;
1730 if (this.t) {
1731 this.ondata(this.t.decode(chunk, { stream: true }), final);
1732 if (final) {
1733 if (this.t.decode().length)
1734 err(8);
1735 this.t = null;
1736 }
1737 return;
1738 }
1739 if (!this.p)
1740 err(4);
1741 var dat = new u8(this.p.length + chunk.length);
1742 dat.set(this.p);
1743 dat.set(chunk, this.p.length);
1744 var _a = dutf8(dat), s = _a.s, r = _a.r;
1745 if (final) {
1746 if (r.length)
1747 err(8);
1748 this.p = null;
1749 }
1750 else
1751 this.p = r;
1752 this.ondata(s, final);
1753 };
1754 return DecodeUTF8;
1755}());
1756exports.DecodeUTF8 = DecodeUTF8;
1757/**
1758 * Streaming UTF-8 encoding
1759 */
1760var EncodeUTF8 = /*#__PURE__*/ (function () {
1761 /**
1762 * Creates a UTF-8 decoding stream
1763 * @param cb The callback to call whenever data is encoded
1764 */
1765 function EncodeUTF8(cb) {
1766 this.ondata = cb;
1767 }
1768 /**
1769 * Pushes a chunk to be encoded to UTF-8
1770 * @param chunk The string data to push
1771 * @param final Whether this is the last chunk
1772 */
1773 EncodeUTF8.prototype.push = function (chunk, final) {
1774 if (!this.ondata)
1775 err(5);
1776 if (this.d)
1777 err(4);
1778 this.ondata(strToU8(chunk), this.d = final || false);
1779 };
1780 return EncodeUTF8;
1781}());
1782exports.EncodeUTF8 = EncodeUTF8;
1783/**
1784 * Converts a string into a Uint8Array for use with compression/decompression methods
1785 * @param str The string to encode
1786 * @param latin1 Whether or not to interpret the data as Latin-1. This should
1787 * not need to be true unless decoding a binary string.
1788 * @returns The string encoded in UTF-8/Latin-1 binary
1789 */
1790function strToU8(str, latin1) {
1791 if (latin1) {
1792 var ar_1 = new u8(str.length);
1793 for (var i = 0; i < str.length; ++i)
1794 ar_1[i] = str.charCodeAt(i);
1795 return ar_1;
1796 }
1797 if (te)
1798 return te.encode(str);
1799 var l = str.length;
1800 var ar = new u8(str.length + (str.length >> 1));
1801 var ai = 0;
1802 var w = function (v) { ar[ai++] = v; };
1803 for (var i = 0; i < l; ++i) {
1804 if (ai + 5 > ar.length) {
1805 var n = new u8(ai + 8 + ((l - i) << 1));
1806 n.set(ar);
1807 ar = n;
1808 }
1809 var c = str.charCodeAt(i);
1810 if (c < 128 || latin1)
1811 w(c);
1812 else if (c < 2048)
1813 w(192 | (c >> 6)), w(128 | (c & 63));
1814 else if (c > 55295 && c < 57344)
1815 c = 65536 + (c & 1023 << 10) | (str.charCodeAt(++i) & 1023),
1816 w(240 | (c >> 18)), w(128 | ((c >> 12) & 63)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));
1817 else
1818 w(224 | (c >> 12)), w(128 | ((c >> 6) & 63)), w(128 | (c & 63));
1819 }
1820 return slc(ar, 0, ai);
1821}
1822exports.strToU8 = strToU8;
1823/**
1824 * Converts a Uint8Array to a string
1825 * @param dat The data to decode to string
1826 * @param latin1 Whether or not to interpret the data as Latin-1. This should
1827 * not need to be true unless encoding to binary string.
1828 * @returns The original UTF-8/Latin-1 string
1829 */
1830function strFromU8(dat, latin1) {
1831 if (latin1) {
1832 var r = '';
1833 for (var i = 0; i < dat.length; i += 16384)
1834 r += String.fromCharCode.apply(null, dat.subarray(i, i + 16384));
1835 return r;
1836 }
1837 else if (td) {
1838 return td.decode(dat);
1839 }
1840 else {
1841 var _a = dutf8(dat), s = _a.s, r = _a.r;
1842 if (r.length)
1843 err(8);
1844 return s;
1845 }
1846}
1847exports.strFromU8 = strFromU8;
1848;
1849// deflate bit flag
1850var dbf = function (l) { return l == 1 ? 3 : l < 6 ? 2 : l == 9 ? 1 : 0; };
1851// skip local zip header
1852var slzh = function (d, b) { return b + 30 + b2(d, b + 26) + b2(d, b + 28); };
1853// read zip header
1854var zh = function (d, b, z) {
1855 var fnl = b2(d, b + 28), fn = strFromU8(d.subarray(b + 46, b + 46 + fnl), !(b2(d, b + 8) & 2048)), es = b + 46 + fnl, bs = b4(d, b + 20);
1856 var _a = z && bs == 4294967295 ? z64e(d, es) : [bs, b4(d, b + 24), b4(d, b + 42)], sc = _a[0], su = _a[1], off = _a[2];
1857 return [b2(d, b + 10), sc, su, fn, es + b2(d, b + 30) + b2(d, b + 32), off];
1858};
1859// read zip64 extra field
1860var z64e = function (d, b) {
1861 for (; b2(d, b) != 1; b += 4 + b2(d, b + 2))
1862 ;
1863 return [b8(d, b + 12), b8(d, b + 4), b8(d, b + 20)];
1864};
1865// extra field length
1866var exfl = function (ex) {
1867 var le = 0;
1868 if (ex) {
1869 for (var k in ex) {
1870 var l = ex[k].length;
1871 if (l > 65535)
1872 err(9);
1873 le += l + 4;
1874 }
1875 }
1876 return le;
1877};
1878// write zip header
1879var wzh = function (d, b, f, fn, u, c, ce, co) {
1880 var fl = fn.length, ex = f.extra, col = co && co.length;
1881 var exl = exfl(ex);
1882 wbytes(d, b, ce != null ? 0x2014B50 : 0x4034B50), b += 4;
1883 if (ce != null)
1884 d[b++] = 20, d[b++] = f.os;
1885 d[b] = 20, b += 2; // spec compliance? what's that?
1886 d[b++] = (f.flag << 1) | (c < 0 && 8), d[b++] = u && 8;
1887 d[b++] = f.compression & 255, d[b++] = f.compression >> 8;
1888 var dt = new Date(f.mtime == null ? Date.now() : f.mtime), y = dt.getFullYear() - 1980;
1889 if (y < 0 || y > 119)
1890 err(10);
1891 wbytes(d, b, (y << 25) | ((dt.getMonth() + 1) << 21) | (dt.getDate() << 16) | (dt.getHours() << 11) | (dt.getMinutes() << 5) | (dt.getSeconds() >> 1)), b += 4;
1892 if (c != -1) {
1893 wbytes(d, b, f.crc);
1894 wbytes(d, b + 4, c < 0 ? -c - 2 : c);
1895 wbytes(d, b + 8, f.size);
1896 }
1897 wbytes(d, b + 12, fl);
1898 wbytes(d, b + 14, exl), b += 16;
1899 if (ce != null) {
1900 wbytes(d, b, col);
1901 wbytes(d, b + 6, f.attrs);
1902 wbytes(d, b + 10, ce), b += 14;
1903 }
1904 d.set(fn, b);
1905 b += fl;
1906 if (exl) {
1907 for (var k in ex) {
1908 var exf = ex[k], l = exf.length;
1909 wbytes(d, b, +k);
1910 wbytes(d, b + 2, l);
1911 d.set(exf, b + 4), b += 4 + l;
1912 }
1913 }
1914 if (col)
1915 d.set(co, b), b += col;
1916 return b;
1917};
1918// write zip footer (end of central directory)
1919var wzf = function (o, b, c, d, e) {
1920 wbytes(o, b, 0x6054B50); // skip disk
1921 wbytes(o, b + 8, c);
1922 wbytes(o, b + 10, c);
1923 wbytes(o, b + 12, d);
1924 wbytes(o, b + 16, e);
1925};
1926/**
1927 * A pass-through stream to keep data uncompressed in a ZIP archive.
1928 */
1929var ZipPassThrough = /*#__PURE__*/ (function () {
1930 /**
1931 * Creates a pass-through stream that can be added to ZIP archives
1932 * @param filename The filename to associate with this data stream
1933 */
1934 function ZipPassThrough(filename) {
1935 this.filename = filename;
1936 this.c = crc();
1937 this.size = 0;
1938 this.compression = 0;
1939 }
1940 /**
1941 * Processes a chunk and pushes to the output stream. You can override this
1942 * method in a subclass for custom behavior, but by default this passes
1943 * the data through. You must call this.ondata(err, chunk, final) at some
1944 * point in this method.
1945 * @param chunk The chunk to process
1946 * @param final Whether this is the last chunk
1947 */
1948 ZipPassThrough.prototype.process = function (chunk, final) {
1949 this.ondata(null, chunk, final);
1950 };
1951 /**
1952 * Pushes a chunk to be added. If you are subclassing this with a custom
1953 * compression algorithm, note that you must push data from the source
1954 * file only, pre-compression.
1955 * @param chunk The chunk to push
1956 * @param final Whether this is the last chunk
1957 */
1958 ZipPassThrough.prototype.push = function (chunk, final) {
1959 if (!this.ondata)
1960 err(5);
1961 this.c.p(chunk);
1962 this.size += chunk.length;
1963 if (final)
1964 this.crc = this.c.d();
1965 this.process(chunk, final || false);
1966 };
1967 return ZipPassThrough;
1968}());
1969exports.ZipPassThrough = ZipPassThrough;
1970// I don't extend because TypeScript extension adds 1kB of runtime bloat
1971/**
1972 * Streaming DEFLATE compression for ZIP archives. Prefer using AsyncZipDeflate
1973 * for better performance
1974 */
1975var ZipDeflate = /*#__PURE__*/ (function () {
1976 /**
1977 * Creates a DEFLATE stream that can be added to ZIP archives
1978 * @param filename The filename to associate with this data stream
1979 * @param opts The compression options
1980 */
1981 function ZipDeflate(filename, opts) {
1982 var _this = this;
1983 if (!opts)
1984 opts = {};
1985 ZipPassThrough.call(this, filename);
1986 this.d = new Deflate(opts, function (dat, final) {
1987 _this.ondata(null, dat, final);
1988 });
1989 this.compression = 8;
1990 this.flag = dbf(opts.level);
1991 }
1992 ZipDeflate.prototype.process = function (chunk, final) {
1993 try {
1994 this.d.push(chunk, final);
1995 }
1996 catch (e) {
1997 this.ondata(e, null, final);
1998 }
1999 };
2000 /**
2001 * Pushes a chunk to be deflated
2002 * @param chunk The chunk to push
2003 * @param final Whether this is the last chunk
2004 */
2005 ZipDeflate.prototype.push = function (chunk, final) {
2006 ZipPassThrough.prototype.push.call(this, chunk, final);
2007 };
2008 return ZipDeflate;
2009}());
2010exports.ZipDeflate = ZipDeflate;
2011/**
2012 * Asynchronous streaming DEFLATE compression for ZIP archives
2013 */
2014var AsyncZipDeflate = /*#__PURE__*/ (function () {
2015 /**
2016 * Creates an asynchronous DEFLATE stream that can be added to ZIP archives
2017 * @param filename The filename to associate with this data stream
2018 * @param opts The compression options
2019 */
2020 function AsyncZipDeflate(filename, opts) {
2021 var _this = this;
2022 if (!opts)
2023 opts = {};
2024 ZipPassThrough.call(this, filename);
2025 this.d = new AsyncDeflate(opts, function (err, dat, final) {
2026 _this.ondata(err, dat, final);
2027 });
2028 this.compression = 8;
2029 this.flag = dbf(opts.level);
2030 this.terminate = this.d.terminate;
2031 }
2032 AsyncZipDeflate.prototype.process = function (chunk, final) {
2033 this.d.push(chunk, final);
2034 };
2035 /**
2036 * Pushes a chunk to be deflated
2037 * @param chunk The chunk to push
2038 * @param final Whether this is the last chunk
2039 */
2040 AsyncZipDeflate.prototype.push = function (chunk, final) {
2041 ZipPassThrough.prototype.push.call(this, chunk, final);
2042 };
2043 return AsyncZipDeflate;
2044}());
2045exports.AsyncZipDeflate = AsyncZipDeflate;
2046// TODO: Better tree shaking
2047/**
2048 * A zippable archive to which files can incrementally be added
2049 */
2050var Zip = /*#__PURE__*/ (function () {
2051 /**
2052 * Creates an empty ZIP archive to which files can be added
2053 * @param cb The callback to call whenever data for the generated ZIP archive
2054 * is available
2055 */
2056 function Zip(cb) {
2057 this.ondata = cb;
2058 this.u = [];
2059 this.d = 1;
2060 }
2061 /**
2062 * Adds a file to the ZIP archive
2063 * @param file The file stream to add
2064 */
2065 Zip.prototype.add = function (file) {
2066 var _this = this;
2067 if (!this.ondata)
2068 err(5);
2069 // finishing or finished
2070 if (this.d & 2)
2071 this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, false);
2072 else {
2073 var f = strToU8(file.filename), fl_1 = f.length;
2074 var com = file.comment, o = com && strToU8(com);
2075 var u = fl_1 != file.filename.length || (o && (com.length != o.length));
2076 var hl_1 = fl_1 + exfl(file.extra) + 30;
2077 if (fl_1 > 65535)
2078 this.ondata(err(11, 0, 1), null, false);
2079 var header = new u8(hl_1);
2080 wzh(header, 0, file, f, u, -1);
2081 var chks_1 = [header];
2082 var pAll_1 = function () {
2083 for (var _i = 0, chks_2 = chks_1; _i < chks_2.length; _i++) {
2084 var chk = chks_2[_i];
2085 _this.ondata(null, chk, false);
2086 }
2087 chks_1 = [];
2088 };
2089 var tr_1 = this.d;
2090 this.d = 0;
2091 var ind_1 = this.u.length;
2092 var uf_1 = mrg(file, {
2093 f: f,
2094 u: u,
2095 o: o,
2096 t: function () {
2097 if (file.terminate)
2098 file.terminate();
2099 },
2100 r: function () {
2101 pAll_1();
2102 if (tr_1) {
2103 var nxt = _this.u[ind_1 + 1];
2104 if (nxt)
2105 nxt.r();
2106 else
2107 _this.d = 1;
2108 }
2109 tr_1 = 1;
2110 }
2111 });
2112 var cl_1 = 0;
2113 file.ondata = function (err, dat, final) {
2114 if (err) {
2115 _this.ondata(err, dat, final);
2116 _this.terminate();
2117 }
2118 else {
2119 cl_1 += dat.length;
2120 chks_1.push(dat);
2121 if (final) {
2122 var dd = new u8(16);
2123 wbytes(dd, 0, 0x8074B50);
2124 wbytes(dd, 4, file.crc);
2125 wbytes(dd, 8, cl_1);
2126 wbytes(dd, 12, file.size);
2127 chks_1.push(dd);
2128 uf_1.c = cl_1, uf_1.b = hl_1 + cl_1 + 16, uf_1.crc = file.crc, uf_1.size = file.size;
2129 if (tr_1)
2130 uf_1.r();
2131 tr_1 = 1;
2132 }
2133 else if (tr_1)
2134 pAll_1();
2135 }
2136 };
2137 this.u.push(uf_1);
2138 }
2139 };
2140 /**
2141 * Ends the process of adding files and prepares to emit the final chunks.
2142 * This *must* be called after adding all desired files for the resulting
2143 * ZIP file to work properly.
2144 */
2145 Zip.prototype.end = function () {
2146 var _this = this;
2147 if (this.d & 2) {
2148 this.ondata(err(4 + (this.d & 1) * 8, 0, 1), null, true);
2149 return;
2150 }
2151 if (this.d)
2152 this.e();
2153 else
2154 this.u.push({
2155 r: function () {
2156 if (!(_this.d & 1))
2157 return;
2158 _this.u.splice(-1, 1);
2159 _this.e();
2160 },
2161 t: function () { }
2162 });
2163 this.d = 3;
2164 };
2165 Zip.prototype.e = function () {
2166 var bt = 0, l = 0, tl = 0;
2167 for (var _i = 0, _a = this.u; _i < _a.length; _i++) {
2168 var f = _a[_i];
2169 tl += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0);
2170 }
2171 var out = new u8(tl + 22);
2172 for (var _b = 0, _c = this.u; _b < _c.length; _b++) {
2173 var f = _c[_b];
2174 wzh(out, bt, f, f.f, f.u, -f.c - 2, l, f.o);
2175 bt += 46 + f.f.length + exfl(f.extra) + (f.o ? f.o.length : 0), l += f.b;
2176 }
2177 wzf(out, bt, this.u.length, tl, l);
2178 this.ondata(null, out, true);
2179 this.d = 2;
2180 };
2181 /**
2182 * A method to terminate any internal workers used by the stream. Subsequent
2183 * calls to add() will fail.
2184 */
2185 Zip.prototype.terminate = function () {
2186 for (var _i = 0, _a = this.u; _i < _a.length; _i++) {
2187 var f = _a[_i];
2188 f.t();
2189 }
2190 this.d = 2;
2191 };
2192 return Zip;
2193}());
2194exports.Zip = Zip;
2195function zip(data, opts, cb) {
2196 if (!cb)
2197 cb = opts, opts = {};
2198 if (typeof cb != 'function')
2199 err(7);
2200 var r = {};
2201 fltn(data, '', r, opts);
2202 var k = Object.keys(r);
2203 var lft = k.length, o = 0, tot = 0;
2204 var slft = lft, files = new Array(lft);
2205 var term = [];
2206 var tAll = function () {
2207 for (var i = 0; i < term.length; ++i)
2208 term[i]();
2209 };
2210 var cbd = function (a, b) {
2211 mt(function () { cb(a, b); });
2212 };
2213 mt(function () { cbd = cb; });
2214 var cbf = function () {
2215 var out = new u8(tot + 22), oe = o, cdl = tot - o;
2216 tot = 0;
2217 for (var i = 0; i < slft; ++i) {
2218 var f = files[i];
2219 try {
2220 var l = f.c.length;
2221 wzh(out, tot, f, f.f, f.u, l);
2222 var badd = 30 + f.f.length + exfl(f.extra);
2223 var loc = tot + badd;
2224 out.set(f.c, loc);
2225 wzh(out, o, f, f.f, f.u, l, tot, f.m), o += 16 + badd + (f.m ? f.m.length : 0), tot = loc + l;
2226 }
2227 catch (e) {
2228 return cbd(e, null);
2229 }
2230 }
2231 wzf(out, o, files.length, cdl, oe);
2232 cbd(null, out);
2233 };
2234 if (!lft)
2235 cbf();
2236 var _loop_1 = function (i) {
2237 var fn = k[i];
2238 var _a = r[fn], file = _a[0], p = _a[1];
2239 var c = crc(), size = file.length;
2240 c.p(file);
2241 var f = strToU8(fn), s = f.length;
2242 var com = p.comment, m = com && strToU8(com), ms = m && m.length;
2243 var exl = exfl(p.extra);
2244 var compression = p.level == 0 ? 0 : 8;
2245 var cbl = function (e, d) {
2246 if (e) {
2247 tAll();
2248 cbd(e, null);
2249 }
2250 else {
2251 var l = d.length;
2252 files[i] = mrg(p, {
2253 size: size,
2254 crc: c.d(),
2255 c: d,
2256 f: f,
2257 m: m,
2258 u: s != fn.length || (m && (com.length != ms)),
2259 compression: compression
2260 });
2261 o += 30 + s + exl + l;
2262 tot += 76 + 2 * (s + exl) + (ms || 0) + l;
2263 if (!--lft)
2264 cbf();
2265 }
2266 };
2267 if (s > 65535)
2268 cbl(err(11, 0, 1), null);
2269 if (!compression)
2270 cbl(null, file);
2271 else if (size < 160000) {
2272 try {
2273 cbl(null, deflateSync(file, p));
2274 }
2275 catch (e) {
2276 cbl(e, null);
2277 }
2278 }
2279 else
2280 term.push(deflate(file, p, cbl));
2281 };
2282 // Cannot use lft because it can decrease
2283 for (var i = 0; i < slft; ++i) {
2284 _loop_1(i);
2285 }
2286 return tAll;
2287}
2288exports.zip = zip;
2289/**
2290 * Synchronously creates a ZIP file. Prefer using `zip` for better performance
2291 * with more than one file.
2292 * @param data The directory structure for the ZIP archive
2293 * @param opts The main options, merged with per-file options
2294 * @returns The generated ZIP archive
2295 */
2296function zipSync(data, opts) {
2297 if (!opts)
2298 opts = {};
2299 var r = {};
2300 var files = [];
2301 fltn(data, '', r, opts);
2302 var o = 0;
2303 var tot = 0;
2304 for (var fn in r) {
2305 var _a = r[fn], file = _a[0], p = _a[1];
2306 var compression = p.level == 0 ? 0 : 8;
2307 var f = strToU8(fn), s = f.length;
2308 var com = p.comment, m = com && strToU8(com), ms = m && m.length;
2309 var exl = exfl(p.extra);
2310 if (s > 65535)
2311 err(11);
2312 var d = compression ? deflateSync(file, p) : file, l = d.length;
2313 var c = crc();
2314 c.p(file);
2315 files.push(mrg(p, {
2316 size: file.length,
2317 crc: c.d(),
2318 c: d,
2319 f: f,
2320 m: m,
2321 u: s != fn.length || (m && (com.length != ms)),
2322 o: o,
2323 compression: compression
2324 }));
2325 o += 30 + s + exl + l;
2326 tot += 76 + 2 * (s + exl) + (ms || 0) + l;
2327 }
2328 var out = new u8(tot + 22), oe = o, cdl = tot - o;
2329 for (var i = 0; i < files.length; ++i) {
2330 var f = files[i];
2331 wzh(out, f.o, f, f.f, f.u, f.c.length);
2332 var badd = 30 + f.f.length + exfl(f.extra);
2333 out.set(f.c, f.o + badd);
2334 wzh(out, o, f, f.f, f.u, f.c.length, f.o, f.m), o += 16 + badd + (f.m ? f.m.length : 0);
2335 }
2336 wzf(out, o, files.length, cdl, oe);
2337 return out;
2338}
2339exports.zipSync = zipSync;
2340/**
2341 * Streaming pass-through decompression for ZIP archives
2342 */
2343var UnzipPassThrough = /*#__PURE__*/ (function () {
2344 function UnzipPassThrough() {
2345 }
2346 UnzipPassThrough.prototype.push = function (data, final) {
2347 this.ondata(null, data, final);
2348 };
2349 UnzipPassThrough.compression = 0;
2350 return UnzipPassThrough;
2351}());
2352exports.UnzipPassThrough = UnzipPassThrough;
2353/**
2354 * Streaming DEFLATE decompression for ZIP archives. Prefer AsyncZipInflate for
2355 * better performance.
2356 */
2357var UnzipInflate = /*#__PURE__*/ (function () {
2358 /**
2359 * Creates a DEFLATE decompression that can be used in ZIP archives
2360 */
2361 function UnzipInflate() {
2362 var _this = this;
2363 this.i = new Inflate(function (dat, final) {
2364 _this.ondata(null, dat, final);
2365 });
2366 }
2367 UnzipInflate.prototype.push = function (data, final) {
2368 try {
2369 this.i.push(data, final);
2370 }
2371 catch (e) {
2372 this.ondata(e, null, final);
2373 }
2374 };
2375 UnzipInflate.compression = 8;
2376 return UnzipInflate;
2377}());
2378exports.UnzipInflate = UnzipInflate;
2379/**
2380 * Asynchronous streaming DEFLATE decompression for ZIP archives
2381 */
2382var AsyncUnzipInflate = /*#__PURE__*/ (function () {
2383 /**
2384 * Creates a DEFLATE decompression that can be used in ZIP archives
2385 */
2386 function AsyncUnzipInflate(_, sz) {
2387 var _this = this;
2388 if (sz < 320000) {
2389 this.i = new Inflate(function (dat, final) {
2390 _this.ondata(null, dat, final);
2391 });
2392 }
2393 else {
2394 this.i = new AsyncInflate(function (err, dat, final) {
2395 _this.ondata(err, dat, final);
2396 });
2397 this.terminate = this.i.terminate;
2398 }
2399 }
2400 AsyncUnzipInflate.prototype.push = function (data, final) {
2401 if (this.i.terminate)
2402 data = slc(data, 0);
2403 this.i.push(data, final);
2404 };
2405 AsyncUnzipInflate.compression = 8;
2406 return AsyncUnzipInflate;
2407}());
2408exports.AsyncUnzipInflate = AsyncUnzipInflate;
2409/**
2410 * A ZIP archive decompression stream that emits files as they are discovered
2411 */
2412var Unzip = /*#__PURE__*/ (function () {
2413 /**
2414 * Creates a ZIP decompression stream
2415 * @param cb The callback to call whenever a file in the ZIP archive is found
2416 */
2417 function Unzip(cb) {
2418 this.onfile = cb;
2419 this.k = [];
2420 this.o = {
2421 0: UnzipPassThrough
2422 };
2423 this.p = et;
2424 }
2425 /**
2426 * Pushes a chunk to be unzipped
2427 * @param chunk The chunk to push
2428 * @param final Whether this is the last chunk
2429 */
2430 Unzip.prototype.push = function (chunk, final) {
2431 var _this = this;
2432 if (!this.onfile)
2433 err(5);
2434 if (!this.p)
2435 err(4);
2436 if (this.c > 0) {
2437 var len = Math.min(this.c, chunk.length);
2438 var toAdd = chunk.subarray(0, len);
2439 this.c -= len;
2440 if (this.d)
2441 this.d.push(toAdd, !this.c);
2442 else
2443 this.k[0].push(toAdd);
2444 chunk = chunk.subarray(len);
2445 if (chunk.length)
2446 return this.push(chunk, final);
2447 }
2448 else {
2449 var f = 0, i = 0, is = void 0, buf = void 0;
2450 if (!this.p.length)
2451 buf = chunk;
2452 else if (!chunk.length)
2453 buf = this.p;
2454 else {
2455 buf = new u8(this.p.length + chunk.length);
2456 buf.set(this.p), buf.set(chunk, this.p.length);
2457 }
2458 var l = buf.length, oc = this.c, add = oc && this.d;
2459 var _loop_2 = function () {
2460 var _a;
2461 var sig = b4(buf, i);
2462 if (sig == 0x4034B50) {
2463 f = 1, is = i;
2464 this_1.d = null;
2465 this_1.c = 0;
2466 var bf = b2(buf, i + 6), cmp_1 = b2(buf, i + 8), u = bf & 2048, dd = bf & 8, fnl = b2(buf, i + 26), es = b2(buf, i + 28);
2467 if (l > i + 30 + fnl + es) {
2468 var chks_3 = [];
2469 this_1.k.unshift(chks_3);
2470 f = 2;
2471 var sc_1 = b4(buf, i + 18), su_1 = b4(buf, i + 22);
2472 var fn_1 = strFromU8(buf.subarray(i + 30, i += 30 + fnl), !u);
2473 if (sc_1 == 4294967295) {
2474 _a = dd ? [-2] : z64e(buf, i), sc_1 = _a[0], su_1 = _a[1];
2475 }
2476 else if (dd)
2477 sc_1 = -1;
2478 i += es;
2479 this_1.c = sc_1;
2480 var d_1;
2481 var file_1 = {
2482 name: fn_1,
2483 compression: cmp_1,
2484 start: function () {
2485 if (!file_1.ondata)
2486 err(5);
2487 if (!sc_1)
2488 file_1.ondata(null, et, true);
2489 else {
2490 var ctr = _this.o[cmp_1];
2491 if (!ctr)
2492 file_1.ondata(err(14, 'unknown compression type ' + cmp_1, 1), null, false);
2493 d_1 = sc_1 < 0 ? new ctr(fn_1) : new ctr(fn_1, sc_1, su_1);
2494 d_1.ondata = function (err, dat, final) { file_1.ondata(err, dat, final); };
2495 for (var _i = 0, chks_4 = chks_3; _i < chks_4.length; _i++) {
2496 var dat = chks_4[_i];
2497 d_1.push(dat, false);
2498 }
2499 if (_this.k[0] == chks_3 && _this.c)
2500 _this.d = d_1;
2501 else
2502 d_1.push(et, true);
2503 }
2504 },
2505 terminate: function () {
2506 if (d_1 && d_1.terminate)
2507 d_1.terminate();
2508 }
2509 };
2510 if (sc_1 >= 0)
2511 file_1.size = sc_1, file_1.originalSize = su_1;
2512 this_1.onfile(file_1);
2513 }
2514 return "break";
2515 }
2516 else if (oc) {
2517 if (sig == 0x8074B50) {
2518 is = i += 12 + (oc == -2 && 8), f = 3, this_1.c = 0;
2519 return "break";
2520 }
2521 else if (sig == 0x2014B50) {
2522 is = i -= 4, f = 3, this_1.c = 0;
2523 return "break";
2524 }
2525 }
2526 };
2527 var this_1 = this;
2528 for (; i < l - 4; ++i) {
2529 var state_1 = _loop_2();
2530 if (state_1 === "break")
2531 break;
2532 }
2533 this.p = et;
2534 if (oc < 0) {
2535 var dat = f ? buf.subarray(0, is - 12 - (oc == -2 && 8) - (b4(buf, is - 16) == 0x8074B50 && 4)) : buf.subarray(0, i);
2536 if (add)
2537 add.push(dat, !!f);
2538 else
2539 this.k[+(f == 2)].push(dat);
2540 }
2541 if (f & 2)
2542 return this.push(buf.subarray(i), final);
2543 this.p = buf.subarray(i);
2544 }
2545 if (final) {
2546 if (this.c)
2547 err(13);
2548 this.p = null;
2549 }
2550 };
2551 /**
2552 * Registers a decoder with the stream, allowing for files compressed with
2553 * the compression type provided to be expanded correctly
2554 * @param decoder The decoder constructor
2555 */
2556 Unzip.prototype.register = function (decoder) {
2557 this.o[decoder.compression] = decoder;
2558 };
2559 return Unzip;
2560}());
2561exports.Unzip = Unzip;
2562var mt = typeof queueMicrotask == 'function' ? queueMicrotask : typeof setTimeout == 'function' ? setTimeout : function (fn) { fn(); };
2563function unzip(data, opts, cb) {
2564 if (!cb)
2565 cb = opts, opts = {};
2566 if (typeof cb != 'function')
2567 err(7);
2568 var term = [];
2569 var tAll = function () {
2570 for (var i = 0; i < term.length; ++i)
2571 term[i]();
2572 };
2573 var files = {};
2574 var cbd = function (a, b) {
2575 mt(function () { cb(a, b); });
2576 };
2577 mt(function () { cbd = cb; });
2578 var e = data.length - 22;
2579 for (; b4(data, e) != 0x6054B50; --e) {
2580 if (!e || data.length - e > 65558) {
2581 cbd(err(13, 0, 1), null);
2582 return tAll;
2583 }
2584 }
2585 ;
2586 var lft = b2(data, e + 8);
2587 if (lft) {
2588 var c = lft;
2589 var o = b4(data, e + 16);
2590 var z = o == 4294967295 || c == 65535;
2591 if (z) {
2592 var ze = b4(data, e - 12);
2593 z = b4(data, ze) == 0x6064B50;
2594 if (z) {
2595 c = lft = b4(data, ze + 32);
2596 o = b4(data, ze + 48);
2597 }
2598 }
2599 var fltr = opts && opts.filter;
2600 var _loop_3 = function (i) {
2601 var _a = zh(data, o, z), c_1 = _a[0], sc = _a[1], su = _a[2], fn = _a[3], no = _a[4], off = _a[5], b = slzh(data, off);
2602 o = no;
2603 var cbl = function (e, d) {
2604 if (e) {
2605 tAll();
2606 cbd(e, null);
2607 }
2608 else {
2609 if (d)
2610 files[fn] = d;
2611 if (!--lft)
2612 cbd(null, files);
2613 }
2614 };
2615 if (!fltr || fltr({
2616 name: fn,
2617 size: sc,
2618 originalSize: su,
2619 compression: c_1
2620 })) {
2621 if (!c_1)
2622 cbl(null, slc(data, b, b + sc));
2623 else if (c_1 == 8) {
2624 var infl = data.subarray(b, b + sc);
2625 // Synchronously decompress under 512KB, or barely-compressed data
2626 if (su < 524288 || sc > 0.8 * su) {
2627 try {
2628 cbl(null, inflateSync(infl, { out: new u8(su) }));
2629 }
2630 catch (e) {
2631 cbl(e, null);
2632 }
2633 }
2634 else
2635 term.push(inflate(infl, { size: su }, cbl));
2636 }
2637 else
2638 cbl(err(14, 'unknown compression type ' + c_1, 1), null);
2639 }
2640 else
2641 cbl(null, null);
2642 };
2643 for (var i = 0; i < c; ++i) {
2644 _loop_3(i);
2645 }
2646 }
2647 else
2648 cbd(null, {});
2649 return tAll;
2650}
2651exports.unzip = unzip;
2652/**
2653 * Synchronously decompresses a ZIP archive. Prefer using `unzip` for better
2654 * performance with more than one file.
2655 * @param data The raw compressed ZIP file
2656 * @param opts The ZIP extraction options
2657 * @returns The decompressed files
2658 */
2659function unzipSync(data, opts) {
2660 var files = {};
2661 var e = data.length - 22;
2662 for (; b4(data, e) != 0x6054B50; --e) {
2663 if (!e || data.length - e > 65558)
2664 err(13);
2665 }
2666 ;
2667 var c = b2(data, e + 8);
2668 if (!c)
2669 return {};
2670 var o = b4(data, e + 16);
2671 var z = o == 4294967295 || c == 65535;
2672 if (z) {
2673 var ze = b4(data, e - 12);
2674 z = b4(data, ze) == 0x6064B50;
2675 if (z) {
2676 c = b4(data, ze + 32);
2677 o = b4(data, ze + 48);
2678 }
2679 }
2680 var fltr = opts && opts.filter;
2681 for (var i = 0; i < c; ++i) {
2682 var _a = zh(data, o, z), c_2 = _a[0], sc = _a[1], su = _a[2], fn = _a[3], no = _a[4], off = _a[5], b = slzh(data, off);
2683 o = no;
2684 if (!fltr || fltr({
2685 name: fn,
2686 size: sc,
2687 originalSize: su,
2688 compression: c_2
2689 })) {
2690 if (!c_2)
2691 files[fn] = slc(data, b, b + sc);
2692 else if (c_2 == 8)
2693 files[fn] = inflateSync(data.subarray(b, b + sc), { out: new u8(su) });
2694 else
2695 err(14, 'unknown compression type ' + c_2);
2696 }
2697 }
2698 return files;
2699}
2700exports.unzipSync = unzipSync;
Note: See TracBrowser for help on using the repository browser.