@apocaliss92/addon-series-scraper 0.0.0-stage → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1346 @@
1
+ import { createRequire as __scraperCreateRequire, createRequire as __createRequire } from "node:module";
2
+ __scraperCreateRequire(import.meta.url);
3
+ import { t as __commonJSMin } from "./rolldown-runtime-cIwnrN2i.js";
4
+ import { b as require_src } from "./proxy-Btrb1iBN.js";
5
+ import { t as require_pump } from "./pump-DDROyUu9.js";
6
+ function __require() {
7
+ const require = __createRequire(import.meta.url);
8
+ __require = () => require;
9
+ return require;
10
+ }
11
+ // node_modules/get-stream/buffer-stream.js
12
+ var require_buffer_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
13
+ var { PassThrough: PassThroughStream } = (/* @__PURE__ */ __require())("stream");
14
+ module.exports = (options) => {
15
+ options = { ...options };
16
+ const { array } = options;
17
+ let { encoding } = options;
18
+ const isBuffer = encoding === "buffer";
19
+ let objectMode = false;
20
+ if (array) objectMode = !(encoding || isBuffer);
21
+ else encoding = encoding || "utf8";
22
+ if (isBuffer) encoding = null;
23
+ const stream = new PassThroughStream({ objectMode });
24
+ if (encoding) stream.setEncoding(encoding);
25
+ let length = 0;
26
+ const chunks = [];
27
+ stream.on("data", (chunk) => {
28
+ chunks.push(chunk);
29
+ if (objectMode) length = chunks.length;
30
+ else length += chunk.length;
31
+ });
32
+ stream.getBufferedValue = () => {
33
+ if (array) return chunks;
34
+ return isBuffer ? Buffer.concat(chunks, length) : chunks.join("");
35
+ };
36
+ stream.getBufferedLength = () => length;
37
+ return stream;
38
+ };
39
+ }));
40
+ // node_modules/get-stream/index.js
41
+ var require_get_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
42
+ var { constants: BufferConstants } = (/* @__PURE__ */ __require())("buffer");
43
+ var pump = require_pump();
44
+ var bufferStream = require_buffer_stream();
45
+ var MaxBufferError = class extends Error {
46
+ constructor() {
47
+ super("maxBuffer exceeded");
48
+ this.name = "MaxBufferError";
49
+ }
50
+ };
51
+ async function getStream(inputStream, options) {
52
+ if (!inputStream) return Promise.reject(/* @__PURE__ */ new Error("Expected a stream"));
53
+ options = {
54
+ maxBuffer: 1e400,
55
+ ...options
56
+ };
57
+ const { maxBuffer } = options;
58
+ let stream;
59
+ await new Promise((resolve, reject) => {
60
+ const rejectPromise = (error) => {
61
+ if (error && stream.getBufferedLength() <= BufferConstants.MAX_LENGTH) error.bufferedData = stream.getBufferedValue();
62
+ reject(error);
63
+ };
64
+ stream = pump(inputStream, bufferStream(options), (error) => {
65
+ if (error) {
66
+ rejectPromise(error);
67
+ return;
68
+ }
69
+ resolve();
70
+ });
71
+ stream.on("data", () => {
72
+ if (stream.getBufferedLength() > maxBuffer) rejectPromise(new MaxBufferError());
73
+ });
74
+ });
75
+ return stream.getBufferedValue();
76
+ }
77
+ module.exports = getStream;
78
+ module.exports.default = getStream;
79
+ module.exports.buffer = (stream, options) => getStream(stream, {
80
+ ...options,
81
+ encoding: "buffer"
82
+ });
83
+ module.exports.array = (stream, options) => getStream(stream, {
84
+ ...options,
85
+ array: true
86
+ });
87
+ module.exports.MaxBufferError = MaxBufferError;
88
+ }));
89
+ // node_modules/pend/index.js
90
+ var require_pend = /* @__PURE__ */ __commonJSMin(((exports, module) => {
91
+ module.exports = Pend;
92
+ function Pend() {
93
+ this.pending = 0;
94
+ this.max = 1e400;
95
+ this.listeners = [];
96
+ this.waiting = [];
97
+ this.error = null;
98
+ }
99
+ Pend.prototype.go = function(fn) {
100
+ if (this.pending < this.max) pendGo(this, fn);
101
+ else this.waiting.push(fn);
102
+ };
103
+ Pend.prototype.wait = function(cb) {
104
+ if (this.pending === 0) cb(this.error);
105
+ else this.listeners.push(cb);
106
+ };
107
+ Pend.prototype.hold = function() {
108
+ return pendHold(this);
109
+ };
110
+ function pendHold(self) {
111
+ self.pending += 1;
112
+ var called = false;
113
+ return onCb;
114
+ function onCb(err) {
115
+ if (called) throw new Error("callback called twice");
116
+ called = true;
117
+ self.error = self.error || err;
118
+ self.pending -= 1;
119
+ if (self.waiting.length > 0 && self.pending < self.max) pendGo(self, self.waiting.shift());
120
+ else if (self.pending === 0) {
121
+ var listeners = self.listeners;
122
+ self.listeners = [];
123
+ listeners.forEach(cbListener);
124
+ }
125
+ }
126
+ function cbListener(listener) {
127
+ listener(self.error);
128
+ }
129
+ }
130
+ function pendGo(self, fn) {
131
+ fn(pendHold(self));
132
+ }
133
+ }));
134
+ // node_modules/fd-slicer/index.js
135
+ var require_fd_slicer = /* @__PURE__ */ __commonJSMin(((exports) => {
136
+ var fs = (/* @__PURE__ */ __require())("fs");
137
+ var util = (/* @__PURE__ */ __require())("util");
138
+ var stream = (/* @__PURE__ */ __require())("stream");
139
+ var Readable = stream.Readable;
140
+ var Writable = stream.Writable;
141
+ var PassThrough = stream.PassThrough;
142
+ var Pend = require_pend();
143
+ var EventEmitter = (/* @__PURE__ */ __require())("events").EventEmitter;
144
+ exports.createFromBuffer = createFromBuffer;
145
+ exports.createFromFd = createFromFd;
146
+ exports.BufferSlicer = BufferSlicer;
147
+ exports.FdSlicer = FdSlicer;
148
+ util.inherits(FdSlicer, EventEmitter);
149
+ function FdSlicer(fd, options) {
150
+ options = options || {};
151
+ EventEmitter.call(this);
152
+ this.fd = fd;
153
+ this.pend = new Pend();
154
+ this.pend.max = 1;
155
+ this.refCount = 0;
156
+ this.autoClose = !!options.autoClose;
157
+ }
158
+ FdSlicer.prototype.read = function(buffer, offset, length, position, callback) {
159
+ var self = this;
160
+ self.pend.go(function(cb) {
161
+ fs.read(self.fd, buffer, offset, length, position, function(err, bytesRead, buffer) {
162
+ cb();
163
+ callback(err, bytesRead, buffer);
164
+ });
165
+ });
166
+ };
167
+ FdSlicer.prototype.write = function(buffer, offset, length, position, callback) {
168
+ var self = this;
169
+ self.pend.go(function(cb) {
170
+ fs.write(self.fd, buffer, offset, length, position, function(err, written, buffer) {
171
+ cb();
172
+ callback(err, written, buffer);
173
+ });
174
+ });
175
+ };
176
+ FdSlicer.prototype.createReadStream = function(options) {
177
+ return new ReadStream(this, options);
178
+ };
179
+ FdSlicer.prototype.createWriteStream = function(options) {
180
+ return new WriteStream(this, options);
181
+ };
182
+ FdSlicer.prototype.ref = function() {
183
+ this.refCount += 1;
184
+ };
185
+ FdSlicer.prototype.unref = function() {
186
+ var self = this;
187
+ self.refCount -= 1;
188
+ if (self.refCount > 0) return;
189
+ if (self.refCount < 0) throw new Error("invalid unref");
190
+ if (self.autoClose) fs.close(self.fd, onCloseDone);
191
+ function onCloseDone(err) {
192
+ if (err) self.emit("error", err);
193
+ else self.emit("close");
194
+ }
195
+ };
196
+ util.inherits(ReadStream, Readable);
197
+ function ReadStream(context, options) {
198
+ options = options || {};
199
+ Readable.call(this, options);
200
+ this.context = context;
201
+ this.context.ref();
202
+ this.start = options.start || 0;
203
+ this.endOffset = options.end;
204
+ this.pos = this.start;
205
+ this.destroyed = false;
206
+ }
207
+ ReadStream.prototype._read = function(n) {
208
+ var self = this;
209
+ if (self.destroyed) return;
210
+ var toRead = Math.min(self._readableState.highWaterMark, n);
211
+ if (self.endOffset != null) toRead = Math.min(toRead, self.endOffset - self.pos);
212
+ if (toRead <= 0) {
213
+ self.destroyed = true;
214
+ self.push(null);
215
+ self.context.unref();
216
+ return;
217
+ }
218
+ self.context.pend.go(function(cb) {
219
+ if (self.destroyed) return cb();
220
+ var buffer = new Buffer(toRead);
221
+ fs.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) {
222
+ if (err) self.destroy(err);
223
+ else if (bytesRead === 0) {
224
+ self.destroyed = true;
225
+ self.push(null);
226
+ self.context.unref();
227
+ } else {
228
+ self.pos += bytesRead;
229
+ self.push(buffer.slice(0, bytesRead));
230
+ }
231
+ cb();
232
+ });
233
+ });
234
+ };
235
+ ReadStream.prototype.destroy = function(err) {
236
+ if (this.destroyed) return;
237
+ err = err || /* @__PURE__ */ new Error("stream destroyed");
238
+ this.destroyed = true;
239
+ this.emit("error", err);
240
+ this.context.unref();
241
+ };
242
+ util.inherits(WriteStream, Writable);
243
+ function WriteStream(context, options) {
244
+ options = options || {};
245
+ Writable.call(this, options);
246
+ this.context = context;
247
+ this.context.ref();
248
+ this.start = options.start || 0;
249
+ this.endOffset = options.end == null ? 1e400 : +options.end;
250
+ this.bytesWritten = 0;
251
+ this.pos = this.start;
252
+ this.destroyed = false;
253
+ this.on("finish", this.destroy.bind(this));
254
+ }
255
+ WriteStream.prototype._write = function(buffer, encoding, callback) {
256
+ var self = this;
257
+ if (self.destroyed) return;
258
+ if (self.pos + buffer.length > self.endOffset) {
259
+ var err = /* @__PURE__ */ new Error("maximum file length exceeded");
260
+ err.code = "ETOOBIG";
261
+ self.destroy();
262
+ callback(err);
263
+ return;
264
+ }
265
+ self.context.pend.go(function(cb) {
266
+ if (self.destroyed) return cb();
267
+ fs.write(self.context.fd, buffer, 0, buffer.length, self.pos, function(err, bytes) {
268
+ if (err) {
269
+ self.destroy();
270
+ cb();
271
+ callback(err);
272
+ } else {
273
+ self.bytesWritten += bytes;
274
+ self.pos += bytes;
275
+ self.emit("progress");
276
+ cb();
277
+ callback();
278
+ }
279
+ });
280
+ });
281
+ };
282
+ WriteStream.prototype.destroy = function() {
283
+ if (this.destroyed) return;
284
+ this.destroyed = true;
285
+ this.context.unref();
286
+ };
287
+ util.inherits(BufferSlicer, EventEmitter);
288
+ function BufferSlicer(buffer, options) {
289
+ EventEmitter.call(this);
290
+ options = options || {};
291
+ this.refCount = 0;
292
+ this.buffer = buffer;
293
+ this.maxChunkSize = options.maxChunkSize || Number.MAX_SAFE_INTEGER;
294
+ }
295
+ BufferSlicer.prototype.read = function(buffer, offset, length, position, callback) {
296
+ var end = position + length;
297
+ var delta = end - this.buffer.length;
298
+ var written = delta > 0 ? delta : length;
299
+ this.buffer.copy(buffer, offset, position, end);
300
+ setImmediate(function() {
301
+ callback(null, written);
302
+ });
303
+ };
304
+ BufferSlicer.prototype.write = function(buffer, offset, length, position, callback) {
305
+ buffer.copy(this.buffer, position, offset, offset + length);
306
+ setImmediate(function() {
307
+ callback(null, length, buffer);
308
+ });
309
+ };
310
+ BufferSlicer.prototype.createReadStream = function(options) {
311
+ options = options || {};
312
+ var readStream = new PassThrough(options);
313
+ readStream.destroyed = false;
314
+ readStream.start = options.start || 0;
315
+ readStream.endOffset = options.end;
316
+ readStream.pos = readStream.endOffset || this.buffer.length;
317
+ var entireSlice = this.buffer.slice(readStream.start, readStream.pos);
318
+ var offset = 0;
319
+ while (true) {
320
+ var nextOffset = offset + this.maxChunkSize;
321
+ if (nextOffset >= entireSlice.length) {
322
+ if (offset < entireSlice.length) readStream.write(entireSlice.slice(offset, entireSlice.length));
323
+ break;
324
+ }
325
+ readStream.write(entireSlice.slice(offset, nextOffset));
326
+ offset = nextOffset;
327
+ }
328
+ readStream.end();
329
+ readStream.destroy = function() {
330
+ readStream.destroyed = true;
331
+ };
332
+ return readStream;
333
+ };
334
+ BufferSlicer.prototype.createWriteStream = function(options) {
335
+ var bufferSlicer = this;
336
+ options = options || {};
337
+ var writeStream = new Writable(options);
338
+ writeStream.start = options.start || 0;
339
+ writeStream.endOffset = options.end == null ? this.buffer.length : +options.end;
340
+ writeStream.bytesWritten = 0;
341
+ writeStream.pos = writeStream.start;
342
+ writeStream.destroyed = false;
343
+ writeStream._write = function(buffer, encoding, callback) {
344
+ if (writeStream.destroyed) return;
345
+ var end = writeStream.pos + buffer.length;
346
+ if (end > writeStream.endOffset) {
347
+ var err = /* @__PURE__ */ new Error("maximum file length exceeded");
348
+ err.code = "ETOOBIG";
349
+ writeStream.destroyed = true;
350
+ callback(err);
351
+ return;
352
+ }
353
+ buffer.copy(bufferSlicer.buffer, writeStream.pos, 0, buffer.length);
354
+ writeStream.bytesWritten += buffer.length;
355
+ writeStream.pos = end;
356
+ writeStream.emit("progress");
357
+ callback();
358
+ };
359
+ writeStream.destroy = function() {
360
+ writeStream.destroyed = true;
361
+ };
362
+ return writeStream;
363
+ };
364
+ BufferSlicer.prototype.ref = function() {
365
+ this.refCount += 1;
366
+ };
367
+ BufferSlicer.prototype.unref = function() {
368
+ this.refCount -= 1;
369
+ if (this.refCount < 0) throw new Error("invalid unref");
370
+ };
371
+ function createFromBuffer(buffer, options) {
372
+ return new BufferSlicer(buffer, options);
373
+ }
374
+ function createFromFd(fd, options) {
375
+ return new FdSlicer(fd, options);
376
+ }
377
+ }));
378
+ // node_modules/buffer-crc32/index.js
379
+ var require_buffer_crc32 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
380
+ var Buffer = (/* @__PURE__ */ __require())("buffer").Buffer;
381
+ var CRC_TABLE = [
382
+ 0,
383
+ 0x77073096,
384
+ 0xee0e612c,
385
+ 0x990951ba,
386
+ 0x76dc419,
387
+ 0x706af48f,
388
+ 0xe963a535,
389
+ 0x9e6495a3,
390
+ 0xedb8832,
391
+ 0x79dcb8a4,
392
+ 0xe0d5e91e,
393
+ 0x97d2d988,
394
+ 0x9b64c2b,
395
+ 0x7eb17cbd,
396
+ 0xe7b82d07,
397
+ 0x90bf1d91,
398
+ 498536548,
399
+ 0x6ab020f2,
400
+ 0xf3b97148,
401
+ 0x84be41de,
402
+ 450548861,
403
+ 0x6ddde4eb,
404
+ 0xf4d4b551,
405
+ 0x83d385c7,
406
+ 325883990,
407
+ 0x646ba8c0,
408
+ 0xfd62f97a,
409
+ 0x8a65c9ec,
410
+ 335633487,
411
+ 0x63066cd9,
412
+ 0xfa0f3d63,
413
+ 0x8d080df5,
414
+ 997073096,
415
+ 0x4c69105e,
416
+ 0xd56041e4,
417
+ 0xa2677172,
418
+ 0x3c03e4d1,
419
+ 0x4b04d447,
420
+ 0xd20d85fd,
421
+ 0xa50ab56b,
422
+ 901097722,
423
+ 0x42b2986c,
424
+ 0xdbbbc9d6,
425
+ 0xacbcf940,
426
+ 853044451,
427
+ 0x45df5c75,
428
+ 0xdcd60dcf,
429
+ 0xabd13d59,
430
+ 651767980,
431
+ 0x51de003a,
432
+ 0xc8d75180,
433
+ 0xbfd06116,
434
+ 565507253,
435
+ 0x56b3c423,
436
+ 0xcfba9599,
437
+ 0xb8bda50f,
438
+ 671266974,
439
+ 0x5f058808,
440
+ 0xc60cd9b2,
441
+ 0xb10be924,
442
+ 795835527,
443
+ 0x58684c11,
444
+ 0xc1611dab,
445
+ 0xb6662d3d,
446
+ 0x76dc4190,
447
+ 31158534,
448
+ 0x98d220bc,
449
+ 0xefd5102a,
450
+ 0x71b18589,
451
+ 0x6b6b51f,
452
+ 0x9fbfe4a5,
453
+ 0xe8b8d433,
454
+ 0x7807c9a2,
455
+ 0xf00f934,
456
+ 0x9609a88e,
457
+ 0xe10e9818,
458
+ 0x7f6a0dbb,
459
+ 0x86d3d2d,
460
+ 0x91646c97,
461
+ 0xe6635c01,
462
+ 0x6b6b51f4,
463
+ 476864866,
464
+ 0x856530d8,
465
+ 0xf262004e,
466
+ 0x6c0695ed,
467
+ 453092731,
468
+ 0x8208f4c1,
469
+ 0xf50fc457,
470
+ 0x65b0d9c6,
471
+ 314042704,
472
+ 0x8bbeb8ea,
473
+ 0xfcb9887c,
474
+ 0x62dd1ddf,
475
+ 366619977,
476
+ 0x8cd37cf3,
477
+ 0xfbd44c65,
478
+ 0x4db26158,
479
+ 984961486,
480
+ 0xa3bc0074,
481
+ 0xd4bb30e2,
482
+ 0x4adfa541,
483
+ 0x3dd895d7,
484
+ 0xa4d1c46d,
485
+ 0xd3d6f4fb,
486
+ 0x4369e96a,
487
+ 879679996,
488
+ 0xad678846,
489
+ 0xda60b8d0,
490
+ 0x44042d73,
491
+ 855842277,
492
+ 0xaa0a4c5f,
493
+ 0xdd0d7cc9,
494
+ 0x5005713c,
495
+ 654459306,
496
+ 0xbe0b1010,
497
+ 0xc90c2086,
498
+ 0x5768b525,
499
+ 544179635,
500
+ 0xb966d409,
501
+ 0xce61e49f,
502
+ 0x5edef90e,
503
+ 702138776,
504
+ 0xb0d09822,
505
+ 0xc7d7a8b4,
506
+ 0x59b33d17,
507
+ 783551873,
508
+ 0xb7bd5c3b,
509
+ 0xc0ba6cad,
510
+ 0xedb88320,
511
+ 0x9abfb3b6,
512
+ 62317068,
513
+ 0x74b1d29a,
514
+ 0xead54739,
515
+ 0x9dd277af,
516
+ 81470997,
517
+ 0x73dc1683,
518
+ 0xe3630b12,
519
+ 0x94643b84,
520
+ 0xd6d6a3e,
521
+ 0x7a6a5aa8,
522
+ 0xe40ecf0b,
523
+ 0x9309ff9d,
524
+ 0xa00ae27,
525
+ 0x7d079eb1,
526
+ 0xf00f9344,
527
+ 0x8708a3d2,
528
+ 503444072,
529
+ 0x6906c2fe,
530
+ 0xf762575d,
531
+ 0x806567cb,
532
+ 426522225,
533
+ 0x6e6b06e7,
534
+ 0xfed41b76,
535
+ 0x89d32be0,
536
+ 282753626,
537
+ 0x67dd4acc,
538
+ 0xf9b9df6f,
539
+ 0x8ebeeff9,
540
+ 397917763,
541
+ 0x60b08ed5,
542
+ 0xd6d6a3e8,
543
+ 0xa1d1937e,
544
+ 953729732,
545
+ 0x4fdff252,
546
+ 0xd1bb67f1,
547
+ 0xa6bc5767,
548
+ 0x3fb506dd,
549
+ 0x48b2364b,
550
+ 0xd80d2bda,
551
+ 0xaf0a1b4c,
552
+ 906185462,
553
+ 0x41047a60,
554
+ 0xdf60efc3,
555
+ 0xa867df55,
556
+ 829329135,
557
+ 0x4669be79,
558
+ 0xcb61b38c,
559
+ 0xbc66831a,
560
+ 628085408,
561
+ 0x5268e236,
562
+ 0xcc0c7795,
563
+ 0xbb0b4703,
564
+ 570562233,
565
+ 0x5505262f,
566
+ 0xc5ba3bbe,
567
+ 0xb2bd0b28,
568
+ 733239954,
569
+ 0x5cb36a04,
570
+ 0xc2d7ffa7,
571
+ 0xb5d0cf31,
572
+ 752459403,
573
+ 0x5bdeae1d,
574
+ 0x9b64c2b0,
575
+ 0xec63f226,
576
+ 0x756aa39c,
577
+ 40735498,
578
+ 0x9c0906a9,
579
+ 0xeb0e363f,
580
+ 0x72076785,
581
+ 83908371,
582
+ 0x95bf4a82,
583
+ 0xe2b87a14,
584
+ 0x7bb12bae,
585
+ 0xcb61b38,
586
+ 0x92d28e9b,
587
+ 0xe5d5be0d,
588
+ 0x7cdcefb7,
589
+ 0xbdbdf21,
590
+ 0x86d3d2d4,
591
+ 0xf1d4e242,
592
+ 0x68ddb3f8,
593
+ 534414190,
594
+ 0x81be16cd,
595
+ 0xf6b9265b,
596
+ 0x6fb077e1,
597
+ 414664567,
598
+ 0x88085ae6,
599
+ 0xff0f6a70,
600
+ 0x66063bca,
601
+ 285281116,
602
+ 0x8f659eff,
603
+ 0xf862ae69,
604
+ 0x616bffd3,
605
+ 376229701,
606
+ 0xa00ae278,
607
+ 0xd70dd2ee,
608
+ 0x4e048354,
609
+ 956543938,
610
+ 0xa7672661,
611
+ 0xd06016f7,
612
+ 0x4969474d,
613
+ 0x3e6e77db,
614
+ 0xaed16a4a,
615
+ 0xd9d65adc,
616
+ 0x40df0b66,
617
+ 936918e3,
618
+ 0xa9bcae53,
619
+ 0xdebb9ec5,
620
+ 0x47b2cf7f,
621
+ 817233897,
622
+ 0xbdbdf21c,
623
+ 0xcabac28a,
624
+ 0x53b39330,
625
+ 615818150,
626
+ 0xbad03605,
627
+ 0xcdd70693,
628
+ 0x54de5729,
629
+ 601450431,
630
+ 0xb3667a2e,
631
+ 0xc4614ab8,
632
+ 0x5d681b02,
633
+ 711928724,
634
+ 0xb40bbe37,
635
+ 0xc30c8ea1,
636
+ 0x5a05df1b,
637
+ 755167117
638
+ ];
639
+ if (typeof Int32Array !== "undefined") CRC_TABLE = new Int32Array(CRC_TABLE);
640
+ function ensureBuffer(input) {
641
+ if (Buffer.isBuffer(input)) return input;
642
+ var hasNewBufferAPI = typeof Buffer.alloc === "function" && typeof Buffer.from === "function";
643
+ if (typeof input === "number") return hasNewBufferAPI ? Buffer.alloc(input) : new Buffer(input);
644
+ else if (typeof input === "string") return hasNewBufferAPI ? Buffer.from(input) : new Buffer(input);
645
+ else throw new Error("input must be buffer, number, or string, received " + typeof input);
646
+ }
647
+ function bufferizeInt(num) {
648
+ var tmp = ensureBuffer(4);
649
+ tmp.writeInt32BE(num, 0);
650
+ return tmp;
651
+ }
652
+ function _crc32(buf, previous) {
653
+ buf = ensureBuffer(buf);
654
+ if (Buffer.isBuffer(previous)) previous = previous.readUInt32BE(0);
655
+ var crc = ~~previous ^ -1;
656
+ for (var n = 0; n < buf.length; n++) crc = CRC_TABLE[(crc ^ buf[n]) & 255] ^ crc >>> 8;
657
+ return crc ^ -1;
658
+ }
659
+ function crc32() {
660
+ return bufferizeInt(_crc32.apply(null, arguments));
661
+ }
662
+ crc32.signed = function() {
663
+ return _crc32.apply(null, arguments);
664
+ };
665
+ crc32.unsigned = function() {
666
+ return _crc32.apply(null, arguments) >>> 0;
667
+ };
668
+ module.exports = crc32;
669
+ }));
670
+ // node_modules/yauzl/index.js
671
+ var require_yauzl = /* @__PURE__ */ __commonJSMin(((exports) => {
672
+ var fs = (/* @__PURE__ */ __require())("fs");
673
+ var zlib = (/* @__PURE__ */ __require())("zlib");
674
+ var fd_slicer = require_fd_slicer();
675
+ var crc32 = require_buffer_crc32();
676
+ var util = (/* @__PURE__ */ __require())("util");
677
+ var EventEmitter = (/* @__PURE__ */ __require())("events").EventEmitter;
678
+ var Transform = (/* @__PURE__ */ __require())("stream").Transform;
679
+ var PassThrough = (/* @__PURE__ */ __require())("stream").PassThrough;
680
+ var Writable = (/* @__PURE__ */ __require())("stream").Writable;
681
+ exports.open = open;
682
+ exports.fromFd = fromFd;
683
+ exports.fromBuffer = fromBuffer;
684
+ exports.fromRandomAccessReader = fromRandomAccessReader;
685
+ exports.dosDateTimeToDate = dosDateTimeToDate;
686
+ exports.validateFileName = validateFileName;
687
+ exports.ZipFile = ZipFile;
688
+ exports.Entry = Entry;
689
+ exports.RandomAccessReader = RandomAccessReader;
690
+ function open(path, options, callback) {
691
+ if (typeof options === "function") {
692
+ callback = options;
693
+ options = null;
694
+ }
695
+ if (options == null) options = {};
696
+ if (options.autoClose == null) options.autoClose = true;
697
+ if (options.lazyEntries == null) options.lazyEntries = false;
698
+ if (options.decodeStrings == null) options.decodeStrings = true;
699
+ if (options.validateEntrySizes == null) options.validateEntrySizes = true;
700
+ if (options.strictFileNames == null) options.strictFileNames = false;
701
+ if (callback == null) callback = defaultCallback;
702
+ fs.open(path, "r", function(err, fd) {
703
+ if (err) return callback(err);
704
+ fromFd(fd, options, function(err, zipfile) {
705
+ if (err) fs.close(fd, defaultCallback);
706
+ callback(err, zipfile);
707
+ });
708
+ });
709
+ }
710
+ function fromFd(fd, options, callback) {
711
+ if (typeof options === "function") {
712
+ callback = options;
713
+ options = null;
714
+ }
715
+ if (options == null) options = {};
716
+ if (options.autoClose == null) options.autoClose = false;
717
+ if (options.lazyEntries == null) options.lazyEntries = false;
718
+ if (options.decodeStrings == null) options.decodeStrings = true;
719
+ if (options.validateEntrySizes == null) options.validateEntrySizes = true;
720
+ if (options.strictFileNames == null) options.strictFileNames = false;
721
+ if (callback == null) callback = defaultCallback;
722
+ fs.fstat(fd, function(err, stats) {
723
+ if (err) return callback(err);
724
+ fromRandomAccessReader(fd_slicer.createFromFd(fd, { autoClose: true }), stats.size, options, callback);
725
+ });
726
+ }
727
+ function fromBuffer(buffer, options, callback) {
728
+ if (typeof options === "function") {
729
+ callback = options;
730
+ options = null;
731
+ }
732
+ if (options == null) options = {};
733
+ options.autoClose = false;
734
+ if (options.lazyEntries == null) options.lazyEntries = false;
735
+ if (options.decodeStrings == null) options.decodeStrings = true;
736
+ if (options.validateEntrySizes == null) options.validateEntrySizes = true;
737
+ if (options.strictFileNames == null) options.strictFileNames = false;
738
+ fromRandomAccessReader(fd_slicer.createFromBuffer(buffer, { maxChunkSize: 65536 }), buffer.length, options, callback);
739
+ }
740
+ function fromRandomAccessReader(reader, totalSize, options, callback) {
741
+ if (typeof options === "function") {
742
+ callback = options;
743
+ options = null;
744
+ }
745
+ if (options == null) options = {};
746
+ if (options.autoClose == null) options.autoClose = true;
747
+ if (options.lazyEntries == null) options.lazyEntries = false;
748
+ if (options.decodeStrings == null) options.decodeStrings = true;
749
+ var decodeStrings = !!options.decodeStrings;
750
+ if (options.validateEntrySizes == null) options.validateEntrySizes = true;
751
+ if (options.strictFileNames == null) options.strictFileNames = false;
752
+ if (callback == null) callback = defaultCallback;
753
+ if (typeof totalSize !== "number") throw new Error("expected totalSize parameter to be a number");
754
+ if (totalSize > Number.MAX_SAFE_INTEGER) throw new Error("zip file too large. only file sizes up to 2^52 are supported due to JavaScript's Number type being an IEEE 754 double.");
755
+ reader.ref();
756
+ var eocdrWithoutCommentSize = 22;
757
+ var bufferSize = Math.min(eocdrWithoutCommentSize + 65535, totalSize);
758
+ var buffer = newBuffer(bufferSize);
759
+ var bufferReadStart = totalSize - buffer.length;
760
+ readAndAssertNoEof(reader, buffer, 0, bufferSize, bufferReadStart, function(err) {
761
+ if (err) return callback(err);
762
+ for (var i = bufferSize - eocdrWithoutCommentSize; i >= 0; i -= 1) {
763
+ if (buffer.readUInt32LE(i) !== 0x6054b50) continue;
764
+ var eocdrBuffer = buffer.slice(i);
765
+ var diskNumber = eocdrBuffer.readUInt16LE(4);
766
+ if (diskNumber !== 0) return callback(/* @__PURE__ */ new Error("multi-disk zip files are not supported: found disk number: " + diskNumber));
767
+ var entryCount = eocdrBuffer.readUInt16LE(10);
768
+ var centralDirectoryOffset = eocdrBuffer.readUInt32LE(16);
769
+ var commentLength = eocdrBuffer.readUInt16LE(20);
770
+ var expectedCommentLength = eocdrBuffer.length - eocdrWithoutCommentSize;
771
+ if (commentLength !== expectedCommentLength) return callback(/* @__PURE__ */ new Error("invalid comment length. expected: " + expectedCommentLength + ". found: " + commentLength));
772
+ var comment = decodeStrings ? decodeBuffer(eocdrBuffer, 22, eocdrBuffer.length, false) : eocdrBuffer.slice(22);
773
+ if (!(entryCount === 65535 || centralDirectoryOffset === 0xffffffff)) return callback(null, new ZipFile(reader, centralDirectoryOffset, totalSize, entryCount, comment, options.autoClose, options.lazyEntries, decodeStrings, options.validateEntrySizes, options.strictFileNames));
774
+ var zip64EocdlBuffer = newBuffer(20);
775
+ var zip64EocdlOffset = bufferReadStart + i - zip64EocdlBuffer.length;
776
+ readAndAssertNoEof(reader, zip64EocdlBuffer, 0, zip64EocdlBuffer.length, zip64EocdlOffset, function(err) {
777
+ if (err) return callback(err);
778
+ if (zip64EocdlBuffer.readUInt32LE(0) !== 0x7064b50) return callback(/* @__PURE__ */ new Error("invalid zip64 end of central directory locator signature"));
779
+ var zip64EocdrOffset = readUInt64LE(zip64EocdlBuffer, 8);
780
+ var zip64EocdrBuffer = newBuffer(56);
781
+ readAndAssertNoEof(reader, zip64EocdrBuffer, 0, zip64EocdrBuffer.length, zip64EocdrOffset, function(err) {
782
+ if (err) return callback(err);
783
+ if (zip64EocdrBuffer.readUInt32LE(0) !== 0x6064b50) return callback(/* @__PURE__ */ new Error("invalid zip64 end of central directory record signature"));
784
+ entryCount = readUInt64LE(zip64EocdrBuffer, 32);
785
+ centralDirectoryOffset = readUInt64LE(zip64EocdrBuffer, 48);
786
+ return callback(null, new ZipFile(reader, centralDirectoryOffset, totalSize, entryCount, comment, options.autoClose, options.lazyEntries, decodeStrings, options.validateEntrySizes, options.strictFileNames));
787
+ });
788
+ });
789
+ return;
790
+ }
791
+ callback(/* @__PURE__ */ new Error("end of central directory record signature not found"));
792
+ });
793
+ }
794
+ util.inherits(ZipFile, EventEmitter);
795
+ function ZipFile(reader, centralDirectoryOffset, fileSize, entryCount, comment, autoClose, lazyEntries, decodeStrings, validateEntrySizes, strictFileNames) {
796
+ var self = this;
797
+ EventEmitter.call(self);
798
+ self.reader = reader;
799
+ self.reader.on("error", function(err) {
800
+ emitError(self, err);
801
+ });
802
+ self.reader.once("close", function() {
803
+ self.emit("close");
804
+ });
805
+ self.readEntryCursor = centralDirectoryOffset;
806
+ self.fileSize = fileSize;
807
+ self.entryCount = entryCount;
808
+ self.comment = comment;
809
+ self.entriesRead = 0;
810
+ self.autoClose = !!autoClose;
811
+ self.lazyEntries = !!lazyEntries;
812
+ self.decodeStrings = !!decodeStrings;
813
+ self.validateEntrySizes = !!validateEntrySizes;
814
+ self.strictFileNames = !!strictFileNames;
815
+ self.isOpen = true;
816
+ self.emittedError = false;
817
+ if (!self.lazyEntries) self._readEntry();
818
+ }
819
+ ZipFile.prototype.close = function() {
820
+ if (!this.isOpen) return;
821
+ this.isOpen = false;
822
+ this.reader.unref();
823
+ };
824
+ function emitErrorAndAutoClose(self, err) {
825
+ if (self.autoClose) self.close();
826
+ emitError(self, err);
827
+ }
828
+ function emitError(self, err) {
829
+ if (self.emittedError) return;
830
+ self.emittedError = true;
831
+ self.emit("error", err);
832
+ }
833
+ ZipFile.prototype.readEntry = function() {
834
+ if (!this.lazyEntries) throw new Error("readEntry() called without lazyEntries:true");
835
+ this._readEntry();
836
+ };
837
+ ZipFile.prototype._readEntry = function() {
838
+ var self = this;
839
+ if (self.entryCount === self.entriesRead) {
840
+ setImmediate(function() {
841
+ if (self.autoClose) self.close();
842
+ if (self.emittedError) return;
843
+ self.emit("end");
844
+ });
845
+ return;
846
+ }
847
+ if (self.emittedError) return;
848
+ var buffer = newBuffer(46);
849
+ readAndAssertNoEof(self.reader, buffer, 0, buffer.length, self.readEntryCursor, function(err) {
850
+ if (err) return emitErrorAndAutoClose(self, err);
851
+ if (self.emittedError) return;
852
+ var entry = new Entry();
853
+ var signature = buffer.readUInt32LE(0);
854
+ if (signature !== 33639248) return emitErrorAndAutoClose(self, /* @__PURE__ */ new Error("invalid central directory file header signature: 0x" + signature.toString(16)));
855
+ entry.versionMadeBy = buffer.readUInt16LE(4);
856
+ entry.versionNeededToExtract = buffer.readUInt16LE(6);
857
+ entry.generalPurposeBitFlag = buffer.readUInt16LE(8);
858
+ entry.compressionMethod = buffer.readUInt16LE(10);
859
+ entry.lastModFileTime = buffer.readUInt16LE(12);
860
+ entry.lastModFileDate = buffer.readUInt16LE(14);
861
+ entry.crc32 = buffer.readUInt32LE(16);
862
+ entry.compressedSize = buffer.readUInt32LE(20);
863
+ entry.uncompressedSize = buffer.readUInt32LE(24);
864
+ entry.fileNameLength = buffer.readUInt16LE(28);
865
+ entry.extraFieldLength = buffer.readUInt16LE(30);
866
+ entry.fileCommentLength = buffer.readUInt16LE(32);
867
+ entry.internalFileAttributes = buffer.readUInt16LE(36);
868
+ entry.externalFileAttributes = buffer.readUInt32LE(38);
869
+ entry.relativeOffsetOfLocalHeader = buffer.readUInt32LE(42);
870
+ if (entry.generalPurposeBitFlag & 64) return emitErrorAndAutoClose(self, /* @__PURE__ */ new Error("strong encryption is not supported"));
871
+ self.readEntryCursor += 46;
872
+ buffer = newBuffer(entry.fileNameLength + entry.extraFieldLength + entry.fileCommentLength);
873
+ readAndAssertNoEof(self.reader, buffer, 0, buffer.length, self.readEntryCursor, function(err) {
874
+ if (err) return emitErrorAndAutoClose(self, err);
875
+ if (self.emittedError) return;
876
+ var isUtf8 = (entry.generalPurposeBitFlag & 2048) !== 0;
877
+ entry.fileName = self.decodeStrings ? decodeBuffer(buffer, 0, entry.fileNameLength, isUtf8) : buffer.slice(0, entry.fileNameLength);
878
+ var fileCommentStart = entry.fileNameLength + entry.extraFieldLength;
879
+ var extraFieldBuffer = buffer.slice(entry.fileNameLength, fileCommentStart);
880
+ entry.extraFields = [];
881
+ var i = 0;
882
+ while (i < extraFieldBuffer.length - 3) {
883
+ var headerId = extraFieldBuffer.readUInt16LE(i + 0);
884
+ var dataSize = extraFieldBuffer.readUInt16LE(i + 2);
885
+ var dataStart = i + 4;
886
+ var dataEnd = dataStart + dataSize;
887
+ if (dataEnd > extraFieldBuffer.length) return emitErrorAndAutoClose(self, /* @__PURE__ */ new Error("extra field length exceeds extra field buffer size"));
888
+ var dataBuffer = newBuffer(dataSize);
889
+ extraFieldBuffer.copy(dataBuffer, 0, dataStart, dataEnd);
890
+ entry.extraFields.push({
891
+ id: headerId,
892
+ data: dataBuffer
893
+ });
894
+ i = dataEnd;
895
+ }
896
+ entry.fileComment = self.decodeStrings ? decodeBuffer(buffer, fileCommentStart, fileCommentStart + entry.fileCommentLength, isUtf8) : buffer.slice(fileCommentStart, fileCommentStart + entry.fileCommentLength);
897
+ entry.comment = entry.fileComment;
898
+ self.readEntryCursor += buffer.length;
899
+ self.entriesRead += 1;
900
+ if (entry.uncompressedSize === 0xffffffff || entry.compressedSize === 0xffffffff || entry.relativeOffsetOfLocalHeader === 0xffffffff) {
901
+ var zip64EiefBuffer = null;
902
+ for (var i = 0; i < entry.extraFields.length; i++) {
903
+ var extraField = entry.extraFields[i];
904
+ if (extraField.id === 1) {
905
+ zip64EiefBuffer = extraField.data;
906
+ break;
907
+ }
908
+ }
909
+ if (zip64EiefBuffer == null) return emitErrorAndAutoClose(self, /* @__PURE__ */ new Error("expected zip64 extended information extra field"));
910
+ var index = 0;
911
+ if (entry.uncompressedSize === 0xffffffff) {
912
+ if (index + 8 > zip64EiefBuffer.length) return emitErrorAndAutoClose(self, /* @__PURE__ */ new Error("zip64 extended information extra field does not include uncompressed size"));
913
+ entry.uncompressedSize = readUInt64LE(zip64EiefBuffer, index);
914
+ index += 8;
915
+ }
916
+ if (entry.compressedSize === 0xffffffff) {
917
+ if (index + 8 > zip64EiefBuffer.length) return emitErrorAndAutoClose(self, /* @__PURE__ */ new Error("zip64 extended information extra field does not include compressed size"));
918
+ entry.compressedSize = readUInt64LE(zip64EiefBuffer, index);
919
+ index += 8;
920
+ }
921
+ if (entry.relativeOffsetOfLocalHeader === 0xffffffff) {
922
+ if (index + 8 > zip64EiefBuffer.length) return emitErrorAndAutoClose(self, /* @__PURE__ */ new Error("zip64 extended information extra field does not include relative header offset"));
923
+ entry.relativeOffsetOfLocalHeader = readUInt64LE(zip64EiefBuffer, index);
924
+ index += 8;
925
+ }
926
+ }
927
+ if (self.decodeStrings) for (var i = 0; i < entry.extraFields.length; i++) {
928
+ var extraField = entry.extraFields[i];
929
+ if (extraField.id === 28789) {
930
+ if (extraField.data.length < 6) continue;
931
+ if (extraField.data.readUInt8(0) !== 1) continue;
932
+ var oldNameCrc32 = extraField.data.readUInt32LE(1);
933
+ if (crc32.unsigned(buffer.slice(0, entry.fileNameLength)) !== oldNameCrc32) continue;
934
+ entry.fileName = decodeBuffer(extraField.data, 5, extraField.data.length, true);
935
+ break;
936
+ }
937
+ }
938
+ if (self.validateEntrySizes && entry.compressionMethod === 0) {
939
+ var expectedCompressedSize = entry.uncompressedSize;
940
+ if (entry.isEncrypted()) expectedCompressedSize += 12;
941
+ if (entry.compressedSize !== expectedCompressedSize) {
942
+ var msg = "compressed/uncompressed size mismatch for stored file: " + entry.compressedSize + " != " + entry.uncompressedSize;
943
+ return emitErrorAndAutoClose(self, new Error(msg));
944
+ }
945
+ }
946
+ if (self.decodeStrings) {
947
+ if (!self.strictFileNames) entry.fileName = entry.fileName.replace(/\\/g, "/");
948
+ var errorMessage = validateFileName(entry.fileName, self.validateFileNameOptions);
949
+ if (errorMessage != null) return emitErrorAndAutoClose(self, new Error(errorMessage));
950
+ }
951
+ self.emit("entry", entry);
952
+ if (!self.lazyEntries) self._readEntry();
953
+ });
954
+ });
955
+ };
956
+ ZipFile.prototype.openReadStream = function(entry, options, callback) {
957
+ var self = this;
958
+ var relativeStart = 0;
959
+ var relativeEnd = entry.compressedSize;
960
+ if (callback == null) {
961
+ callback = options;
962
+ options = {};
963
+ } else {
964
+ if (options.decrypt != null) {
965
+ if (!entry.isEncrypted()) throw new Error("options.decrypt can only be specified for encrypted entries");
966
+ if (options.decrypt !== false) throw new Error("invalid options.decrypt value: " + options.decrypt);
967
+ if (entry.isCompressed()) {
968
+ if (options.decompress !== false) throw new Error("entry is encrypted and compressed, and options.decompress !== false");
969
+ }
970
+ }
971
+ if (options.decompress != null) {
972
+ if (!entry.isCompressed()) throw new Error("options.decompress can only be specified for compressed entries");
973
+ if (!(options.decompress === false || options.decompress === true)) throw new Error("invalid options.decompress value: " + options.decompress);
974
+ }
975
+ if (options.start != null || options.end != null) {
976
+ if (entry.isCompressed() && options.decompress !== false) throw new Error("start/end range not allowed for compressed entry without options.decompress === false");
977
+ if (entry.isEncrypted() && options.decrypt !== false) throw new Error("start/end range not allowed for encrypted entry without options.decrypt === false");
978
+ }
979
+ if (options.start != null) {
980
+ relativeStart = options.start;
981
+ if (relativeStart < 0) throw new Error("options.start < 0");
982
+ if (relativeStart > entry.compressedSize) throw new Error("options.start > entry.compressedSize");
983
+ }
984
+ if (options.end != null) {
985
+ relativeEnd = options.end;
986
+ if (relativeEnd < 0) throw new Error("options.end < 0");
987
+ if (relativeEnd > entry.compressedSize) throw new Error("options.end > entry.compressedSize");
988
+ if (relativeEnd < relativeStart) throw new Error("options.end < options.start");
989
+ }
990
+ }
991
+ if (!self.isOpen) return callback(/* @__PURE__ */ new Error("closed"));
992
+ if (entry.isEncrypted()) {
993
+ if (options.decrypt !== false) return callback(/* @__PURE__ */ new Error("entry is encrypted, and options.decrypt !== false"));
994
+ }
995
+ self.reader.ref();
996
+ var buffer = newBuffer(30);
997
+ readAndAssertNoEof(self.reader, buffer, 0, buffer.length, entry.relativeOffsetOfLocalHeader, function(err) {
998
+ try {
999
+ if (err) return callback(err);
1000
+ var signature = buffer.readUInt32LE(0);
1001
+ if (signature !== 67324752) return callback(/* @__PURE__ */ new Error("invalid local file header signature: 0x" + signature.toString(16)));
1002
+ var fileNameLength = buffer.readUInt16LE(26);
1003
+ var extraFieldLength = buffer.readUInt16LE(28);
1004
+ var localFileHeaderEnd = entry.relativeOffsetOfLocalHeader + buffer.length + fileNameLength + extraFieldLength;
1005
+ var decompress;
1006
+ if (entry.compressionMethod === 0) decompress = false;
1007
+ else if (entry.compressionMethod === 8) decompress = options.decompress != null ? options.decompress : true;
1008
+ else return callback(/* @__PURE__ */ new Error("unsupported compression method: " + entry.compressionMethod));
1009
+ var fileDataStart = localFileHeaderEnd;
1010
+ var fileDataEnd = fileDataStart + entry.compressedSize;
1011
+ if (entry.compressedSize !== 0) {
1012
+ if (fileDataEnd > self.fileSize) return callback(/* @__PURE__ */ new Error("file data overflows file bounds: " + fileDataStart + " + " + entry.compressedSize + " > " + self.fileSize));
1013
+ }
1014
+ var readStream = self.reader.createReadStream({
1015
+ start: fileDataStart + relativeStart,
1016
+ end: fileDataStart + relativeEnd
1017
+ });
1018
+ var endpointStream = readStream;
1019
+ if (decompress) {
1020
+ var destroyed = false;
1021
+ var inflateFilter = zlib.createInflateRaw();
1022
+ readStream.on("error", function(err) {
1023
+ setImmediate(function() {
1024
+ if (!destroyed) inflateFilter.emit("error", err);
1025
+ });
1026
+ });
1027
+ readStream.pipe(inflateFilter);
1028
+ if (self.validateEntrySizes) {
1029
+ endpointStream = new AssertByteCountStream(entry.uncompressedSize);
1030
+ inflateFilter.on("error", function(err) {
1031
+ setImmediate(function() {
1032
+ if (!destroyed) endpointStream.emit("error", err);
1033
+ });
1034
+ });
1035
+ inflateFilter.pipe(endpointStream);
1036
+ } else endpointStream = inflateFilter;
1037
+ endpointStream.destroy = function() {
1038
+ destroyed = true;
1039
+ if (inflateFilter !== endpointStream) inflateFilter.unpipe(endpointStream);
1040
+ readStream.unpipe(inflateFilter);
1041
+ readStream.destroy();
1042
+ };
1043
+ }
1044
+ callback(null, endpointStream);
1045
+ } finally {
1046
+ self.reader.unref();
1047
+ }
1048
+ });
1049
+ };
1050
+ function Entry() {}
1051
+ Entry.prototype.getLastModDate = function() {
1052
+ return dosDateTimeToDate(this.lastModFileDate, this.lastModFileTime);
1053
+ };
1054
+ Entry.prototype.isEncrypted = function() {
1055
+ return (this.generalPurposeBitFlag & 1) !== 0;
1056
+ };
1057
+ Entry.prototype.isCompressed = function() {
1058
+ return this.compressionMethod === 8;
1059
+ };
1060
+ function dosDateTimeToDate(date, time) {
1061
+ var day = date & 31;
1062
+ var month = (date >> 5 & 15) - 1;
1063
+ var year = (date >> 9 & 127) + 1980;
1064
+ var millisecond = 0;
1065
+ var second = (time & 31) * 2;
1066
+ var minute = time >> 5 & 63;
1067
+ var hour = time >> 11 & 31;
1068
+ return new Date(year, month, day, hour, minute, second, millisecond);
1069
+ }
1070
+ function validateFileName(fileName) {
1071
+ if (fileName.indexOf("\\") !== -1) return "invalid characters in fileName: " + fileName;
1072
+ if (/^[a-zA-Z]:/.test(fileName) || /^\//.test(fileName)) return "absolute path: " + fileName;
1073
+ if (fileName.split("/").indexOf("..") !== -1) return "invalid relative path: " + fileName;
1074
+ return null;
1075
+ }
1076
+ function readAndAssertNoEof(reader, buffer, offset, length, position, callback) {
1077
+ if (length === 0) return setImmediate(function() {
1078
+ callback(null, newBuffer(0));
1079
+ });
1080
+ reader.read(buffer, offset, length, position, function(err, bytesRead) {
1081
+ if (err) return callback(err);
1082
+ if (bytesRead < length) return callback(/* @__PURE__ */ new Error("unexpected EOF"));
1083
+ callback();
1084
+ });
1085
+ }
1086
+ util.inherits(AssertByteCountStream, Transform);
1087
+ function AssertByteCountStream(byteCount) {
1088
+ Transform.call(this);
1089
+ this.actualByteCount = 0;
1090
+ this.expectedByteCount = byteCount;
1091
+ }
1092
+ AssertByteCountStream.prototype._transform = function(chunk, encoding, cb) {
1093
+ this.actualByteCount += chunk.length;
1094
+ if (this.actualByteCount > this.expectedByteCount) {
1095
+ var msg = "too many bytes in the stream. expected " + this.expectedByteCount + ". got at least " + this.actualByteCount;
1096
+ return cb(new Error(msg));
1097
+ }
1098
+ cb(null, chunk);
1099
+ };
1100
+ AssertByteCountStream.prototype._flush = function(cb) {
1101
+ if (this.actualByteCount < this.expectedByteCount) {
1102
+ var msg = "not enough bytes in the stream. expected " + this.expectedByteCount + ". got only " + this.actualByteCount;
1103
+ return cb(new Error(msg));
1104
+ }
1105
+ cb();
1106
+ };
1107
+ util.inherits(RandomAccessReader, EventEmitter);
1108
+ function RandomAccessReader() {
1109
+ EventEmitter.call(this);
1110
+ this.refCount = 0;
1111
+ }
1112
+ RandomAccessReader.prototype.ref = function() {
1113
+ this.refCount += 1;
1114
+ };
1115
+ RandomAccessReader.prototype.unref = function() {
1116
+ var self = this;
1117
+ self.refCount -= 1;
1118
+ if (self.refCount > 0) return;
1119
+ if (self.refCount < 0) throw new Error("invalid unref");
1120
+ self.close(onCloseDone);
1121
+ function onCloseDone(err) {
1122
+ if (err) return self.emit("error", err);
1123
+ self.emit("close");
1124
+ }
1125
+ };
1126
+ RandomAccessReader.prototype.createReadStream = function(options) {
1127
+ var start = options.start;
1128
+ var end = options.end;
1129
+ if (start === end) {
1130
+ var emptyStream = new PassThrough();
1131
+ setImmediate(function() {
1132
+ emptyStream.end();
1133
+ });
1134
+ return emptyStream;
1135
+ }
1136
+ var stream = this._readStreamForRange(start, end);
1137
+ var destroyed = false;
1138
+ var refUnrefFilter = new RefUnrefFilter(this);
1139
+ stream.on("error", function(err) {
1140
+ setImmediate(function() {
1141
+ if (!destroyed) refUnrefFilter.emit("error", err);
1142
+ });
1143
+ });
1144
+ refUnrefFilter.destroy = function() {
1145
+ stream.unpipe(refUnrefFilter);
1146
+ refUnrefFilter.unref();
1147
+ stream.destroy();
1148
+ };
1149
+ var byteCounter = new AssertByteCountStream(end - start);
1150
+ refUnrefFilter.on("error", function(err) {
1151
+ setImmediate(function() {
1152
+ if (!destroyed) byteCounter.emit("error", err);
1153
+ });
1154
+ });
1155
+ byteCounter.destroy = function() {
1156
+ destroyed = true;
1157
+ refUnrefFilter.unpipe(byteCounter);
1158
+ refUnrefFilter.destroy();
1159
+ };
1160
+ return stream.pipe(refUnrefFilter).pipe(byteCounter);
1161
+ };
1162
+ RandomAccessReader.prototype._readStreamForRange = function(start, end) {
1163
+ throw new Error("not implemented");
1164
+ };
1165
+ RandomAccessReader.prototype.read = function(buffer, offset, length, position, callback) {
1166
+ var readStream = this.createReadStream({
1167
+ start: position,
1168
+ end: position + length
1169
+ });
1170
+ var writeStream = new Writable();
1171
+ var written = 0;
1172
+ writeStream._write = function(chunk, encoding, cb) {
1173
+ chunk.copy(buffer, offset + written, 0, chunk.length);
1174
+ written += chunk.length;
1175
+ cb();
1176
+ };
1177
+ writeStream.on("finish", callback);
1178
+ readStream.on("error", function(error) {
1179
+ callback(error);
1180
+ });
1181
+ readStream.pipe(writeStream);
1182
+ };
1183
+ RandomAccessReader.prototype.close = function(callback) {
1184
+ setImmediate(callback);
1185
+ };
1186
+ util.inherits(RefUnrefFilter, PassThrough);
1187
+ function RefUnrefFilter(context) {
1188
+ PassThrough.call(this);
1189
+ this.context = context;
1190
+ this.context.ref();
1191
+ this.unreffedYet = false;
1192
+ }
1193
+ RefUnrefFilter.prototype._flush = function(cb) {
1194
+ this.unref();
1195
+ cb();
1196
+ };
1197
+ RefUnrefFilter.prototype.unref = function(cb) {
1198
+ if (this.unreffedYet) return;
1199
+ this.unreffedYet = true;
1200
+ this.context.unref();
1201
+ };
1202
+ var cp437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■\xA0";
1203
+ function decodeBuffer(buffer, start, end, isUtf8) {
1204
+ if (isUtf8) return buffer.toString("utf8", start, end);
1205
+ else {
1206
+ var result = "";
1207
+ for (var i = start; i < end; i++) result += cp437[buffer[i]];
1208
+ return result;
1209
+ }
1210
+ }
1211
+ function readUInt64LE(buffer, offset) {
1212
+ var lower32 = buffer.readUInt32LE(offset);
1213
+ return buffer.readUInt32LE(offset + 4) * 4294967296 + lower32;
1214
+ }
1215
+ var newBuffer;
1216
+ if (typeof Buffer.allocUnsafe === "function") newBuffer = function(len) {
1217
+ return Buffer.allocUnsafe(len);
1218
+ };
1219
+ else newBuffer = function(len) {
1220
+ return new Buffer(len);
1221
+ };
1222
+ function defaultCallback(err) {
1223
+ if (err) throw err;
1224
+ }
1225
+ }));
1226
+ // node_modules/extract-zip/index.js
1227
+ var require_extract_zip = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1228
+ var debug = require_src()("extract-zip");
1229
+ var { createWriteStream, promises: fs } = (/* @__PURE__ */ __require())("fs");
1230
+ var getStream = require_get_stream();
1231
+ var path = (/* @__PURE__ */ __require())("path");
1232
+ var { promisify } = (/* @__PURE__ */ __require())("util");
1233
+ var stream = (/* @__PURE__ */ __require())("stream");
1234
+ var openZip = promisify(require_yauzl().open);
1235
+ var pipeline = promisify(stream.pipeline);
1236
+ var Extractor = class {
1237
+ constructor(zipPath, opts) {
1238
+ this.zipPath = zipPath;
1239
+ this.opts = opts;
1240
+ }
1241
+ async extract() {
1242
+ debug("opening", this.zipPath, "with opts", this.opts);
1243
+ this.zipfile = await openZip(this.zipPath, { lazyEntries: true });
1244
+ this.canceled = false;
1245
+ return new Promise((resolve, reject) => {
1246
+ this.zipfile.on("error", (err) => {
1247
+ this.canceled = true;
1248
+ reject(err);
1249
+ });
1250
+ this.zipfile.readEntry();
1251
+ this.zipfile.on("close", () => {
1252
+ if (!this.canceled) {
1253
+ debug("zip extraction complete");
1254
+ resolve();
1255
+ }
1256
+ });
1257
+ this.zipfile.on("entry", async (entry) => {
1258
+ /* istanbul ignore if */
1259
+ if (this.canceled) {
1260
+ debug("skipping entry", entry.fileName, { cancelled: this.canceled });
1261
+ return;
1262
+ }
1263
+ debug("zipfile entry", entry.fileName);
1264
+ if (entry.fileName.startsWith("__MACOSX/")) {
1265
+ this.zipfile.readEntry();
1266
+ return;
1267
+ }
1268
+ const destDir = path.dirname(path.join(this.opts.dir, entry.fileName));
1269
+ try {
1270
+ await fs.mkdir(destDir, { recursive: true });
1271
+ const canonicalDestDir = await fs.realpath(destDir);
1272
+ if (path.relative(this.opts.dir, canonicalDestDir).split(path.sep).includes("..")) throw new Error(`Out of bound path "${canonicalDestDir}" found while processing file ${entry.fileName}`);
1273
+ await this.extractEntry(entry);
1274
+ debug("finished processing", entry.fileName);
1275
+ this.zipfile.readEntry();
1276
+ } catch (err) {
1277
+ this.canceled = true;
1278
+ this.zipfile.close();
1279
+ reject(err);
1280
+ }
1281
+ });
1282
+ });
1283
+ }
1284
+ async extractEntry(entry) {
1285
+ /* istanbul ignore if */
1286
+ if (this.canceled) {
1287
+ debug("skipping entry extraction", entry.fileName, { cancelled: this.canceled });
1288
+ return;
1289
+ }
1290
+ if (this.opts.onEntry) this.opts.onEntry(entry, this.zipfile);
1291
+ const dest = path.join(this.opts.dir, entry.fileName);
1292
+ const mode = entry.externalFileAttributes >> 16 & 65535;
1293
+ const IFMT = 61440;
1294
+ const IFDIR = 16384;
1295
+ const symlink = (mode & IFMT) === 40960;
1296
+ let isDir = (mode & IFMT) === IFDIR;
1297
+ if (!isDir && entry.fileName.endsWith("/")) isDir = true;
1298
+ const madeBy = entry.versionMadeBy >> 8;
1299
+ if (!isDir) isDir = madeBy === 0 && entry.externalFileAttributes === 16;
1300
+ debug("extracting entry", {
1301
+ filename: entry.fileName,
1302
+ isDir,
1303
+ isSymlink: symlink
1304
+ });
1305
+ const procMode = this.getExtractedMode(mode, isDir) & 511;
1306
+ const destDir = isDir ? dest : path.dirname(dest);
1307
+ const mkdirOptions = { recursive: true };
1308
+ if (isDir) mkdirOptions.mode = procMode;
1309
+ debug("mkdir", {
1310
+ dir: destDir,
1311
+ ...mkdirOptions
1312
+ });
1313
+ await fs.mkdir(destDir, mkdirOptions);
1314
+ if (isDir) return;
1315
+ debug("opening read stream", dest);
1316
+ const readStream = await promisify(this.zipfile.openReadStream.bind(this.zipfile))(entry);
1317
+ if (symlink) {
1318
+ const link = await getStream(readStream);
1319
+ debug("creating symlink", link, dest);
1320
+ await fs.symlink(link, dest);
1321
+ } else await pipeline(readStream, createWriteStream(dest, { mode: procMode }));
1322
+ }
1323
+ getExtractedMode(entryMode, isDir) {
1324
+ let mode = entryMode;
1325
+ if (mode === 0) {
1326
+ if (isDir) {
1327
+ if (this.opts.defaultDirMode) mode = parseInt(this.opts.defaultDirMode, 10);
1328
+ if (!mode) mode = 493;
1329
+ } else {
1330
+ if (this.opts.defaultFileMode) mode = parseInt(this.opts.defaultFileMode, 10);
1331
+ if (!mode) mode = 420;
1332
+ }
1333
+ }
1334
+ return mode;
1335
+ }
1336
+ };
1337
+ module.exports = async function(zipPath, opts) {
1338
+ debug("creating target directory", opts.dir);
1339
+ if (!path.isAbsolute(opts.dir)) throw new Error("Target directory is expected to be absolute");
1340
+ await fs.mkdir(opts.dir, { recursive: true });
1341
+ opts.dir = await fs.realpath(opts.dir);
1342
+ return new Extractor(zipPath, opts).extract();
1343
+ };
1344
+ }));
1345
+ export default require_extract_zip();
1346
+ export {};