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