keycloakify 11.15.5 → 11.15.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/910.index.js CHANGED
@@ -11621,124 +11621,6 @@ exports.flatten = (...args) => {
11621
11621
  };
11622
11622
 
11623
11623
 
11624
- /***/ }),
11625
-
11626
- /***/ 34024:
11627
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
11628
-
11629
- var Buffer = (__webpack_require__(14300).Buffer);
11630
-
11631
- var CRC_TABLE = [
11632
- 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11633
- 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11634
- 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11635
- 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11636
- 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11637
- 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11638
- 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11639
- 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11640
- 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11641
- 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11642
- 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11643
- 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11644
- 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11645
- 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11646
- 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11647
- 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11648
- 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11649
- 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11650
- 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11651
- 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11652
- 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11653
- 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11654
- 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11655
- 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11656
- 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11657
- 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11658
- 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11659
- 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11660
- 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11661
- 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11662
- 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11663
- 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11664
- 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11665
- 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11666
- 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11667
- 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11668
- 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11669
- 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11670
- 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11671
- 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11672
- 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11673
- 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11674
- 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11675
- 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11676
- 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11677
- 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11678
- 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11679
- 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11680
- 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11681
- 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11682
- 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11683
- 0x2d02ef8d
11684
- ];
11685
-
11686
- if (typeof Int32Array !== 'undefined') {
11687
- CRC_TABLE = new Int32Array(CRC_TABLE);
11688
- }
11689
-
11690
- function ensureBuffer(input) {
11691
- if (Buffer.isBuffer(input)) {
11692
- return input;
11693
- }
11694
-
11695
- var hasNewBufferAPI =
11696
- typeof Buffer.alloc === "function" &&
11697
- typeof Buffer.from === "function";
11698
-
11699
- if (typeof input === "number") {
11700
- return hasNewBufferAPI ? Buffer.alloc(input) : new Buffer(input);
11701
- }
11702
- else if (typeof input === "string") {
11703
- return hasNewBufferAPI ? Buffer.from(input) : new Buffer(input);
11704
- }
11705
- else {
11706
- throw new Error("input must be buffer, number, or string, received " +
11707
- typeof input);
11708
- }
11709
- }
11710
-
11711
- function bufferizeInt(num) {
11712
- var tmp = ensureBuffer(4);
11713
- tmp.writeInt32BE(num, 0);
11714
- return tmp;
11715
- }
11716
-
11717
- function _crc32(buf, previous) {
11718
- buf = ensureBuffer(buf);
11719
- if (Buffer.isBuffer(previous)) {
11720
- previous = previous.readUInt32BE(0);
11721
- }
11722
- var crc = ~~previous ^ -1;
11723
- for (var n = 0; n < buf.length; n++) {
11724
- crc = CRC_TABLE[(crc ^ buf[n]) & 0xff] ^ (crc >>> 8);
11725
- }
11726
- return (crc ^ -1);
11727
- }
11728
-
11729
- function crc32() {
11730
- return bufferizeInt(_crc32.apply(null, arguments));
11731
- }
11732
- crc32.signed = function () {
11733
- return _crc32.apply(null, arguments);
11734
- };
11735
- crc32.unsigned = function () {
11736
- return _crc32.apply(null, arguments) >>> 0;
11737
- };
11738
-
11739
- module.exports = crc32;
11740
-
11741
-
11742
11624
  /***/ }),
11743
11625
 
11744
11626
  /***/ 83491:
@@ -22125,309 +22007,6 @@ function createError(err, code, props) {
22125
22007
  module.exports = createError;
22126
22008
 
22127
22009
 
22128
- /***/ }),
22129
-
22130
- /***/ 65010:
22131
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
22132
-
22133
- var fs = __webpack_require__(57147);
22134
- var util = __webpack_require__(73837);
22135
- var stream = __webpack_require__(12781);
22136
- var Readable = stream.Readable;
22137
- var Writable = stream.Writable;
22138
- var PassThrough = stream.PassThrough;
22139
- var Pend = __webpack_require__(54833);
22140
- var EventEmitter = (__webpack_require__(82361).EventEmitter);
22141
-
22142
- exports.createFromBuffer = createFromBuffer;
22143
- exports.createFromFd = createFromFd;
22144
- exports.BufferSlicer = BufferSlicer;
22145
- exports.FdSlicer = FdSlicer;
22146
-
22147
- util.inherits(FdSlicer, EventEmitter);
22148
- function FdSlicer(fd, options) {
22149
- options = options || {};
22150
- EventEmitter.call(this);
22151
-
22152
- this.fd = fd;
22153
- this.pend = new Pend();
22154
- this.pend.max = 1;
22155
- this.refCount = 0;
22156
- this.autoClose = !!options.autoClose;
22157
- }
22158
-
22159
- FdSlicer.prototype.read = function(buffer, offset, length, position, callback) {
22160
- var self = this;
22161
- self.pend.go(function(cb) {
22162
- fs.read(self.fd, buffer, offset, length, position, function(err, bytesRead, buffer) {
22163
- cb();
22164
- callback(err, bytesRead, buffer);
22165
- });
22166
- });
22167
- };
22168
-
22169
- FdSlicer.prototype.write = function(buffer, offset, length, position, callback) {
22170
- var self = this;
22171
- self.pend.go(function(cb) {
22172
- fs.write(self.fd, buffer, offset, length, position, function(err, written, buffer) {
22173
- cb();
22174
- callback(err, written, buffer);
22175
- });
22176
- });
22177
- };
22178
-
22179
- FdSlicer.prototype.createReadStream = function(options) {
22180
- return new ReadStream(this, options);
22181
- };
22182
-
22183
- FdSlicer.prototype.createWriteStream = function(options) {
22184
- return new WriteStream(this, options);
22185
- };
22186
-
22187
- FdSlicer.prototype.ref = function() {
22188
- this.refCount += 1;
22189
- };
22190
-
22191
- FdSlicer.prototype.unref = function() {
22192
- var self = this;
22193
- self.refCount -= 1;
22194
-
22195
- if (self.refCount > 0) return;
22196
- if (self.refCount < 0) throw new Error("invalid unref");
22197
-
22198
- if (self.autoClose) {
22199
- fs.close(self.fd, onCloseDone);
22200
- }
22201
-
22202
- function onCloseDone(err) {
22203
- if (err) {
22204
- self.emit('error', err);
22205
- } else {
22206
- self.emit('close');
22207
- }
22208
- }
22209
- };
22210
-
22211
- util.inherits(ReadStream, Readable);
22212
- function ReadStream(context, options) {
22213
- options = options || {};
22214
- Readable.call(this, options);
22215
-
22216
- this.context = context;
22217
- this.context.ref();
22218
-
22219
- this.start = options.start || 0;
22220
- this.endOffset = options.end;
22221
- this.pos = this.start;
22222
- this.destroyed = false;
22223
- }
22224
-
22225
- ReadStream.prototype._read = function(n) {
22226
- var self = this;
22227
- if (self.destroyed) return;
22228
-
22229
- var toRead = Math.min(self._readableState.highWaterMark, n);
22230
- if (self.endOffset != null) {
22231
- toRead = Math.min(toRead, self.endOffset - self.pos);
22232
- }
22233
- if (toRead <= 0) {
22234
- self.destroyed = true;
22235
- self.push(null);
22236
- self.context.unref();
22237
- return;
22238
- }
22239
- self.context.pend.go(function(cb) {
22240
- if (self.destroyed) return cb();
22241
- var buffer = Buffer.allocUnsafe ? Buffer.allocUnsafe(toRead) : new Buffer(toRead);
22242
- fs.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) {
22243
- if (err) {
22244
- self.destroy(err);
22245
- } else if (bytesRead === 0) {
22246
- self.destroyed = true;
22247
- self.push(null);
22248
- self.context.unref();
22249
- } else {
22250
- self.pos += bytesRead;
22251
- self.push(buffer.slice(0, bytesRead));
22252
- }
22253
- cb();
22254
- });
22255
- });
22256
- };
22257
-
22258
- ReadStream.prototype.destroy = function(err) {
22259
- if (this.destroyed) return;
22260
- err = err || new Error("stream destroyed");
22261
- this.destroyed = true;
22262
- this.emit('error', err);
22263
- this.context.unref();
22264
- };
22265
-
22266
- util.inherits(WriteStream, Writable);
22267
- function WriteStream(context, options) {
22268
- options = options || {};
22269
- Writable.call(this, options);
22270
-
22271
- this.context = context;
22272
- this.context.ref();
22273
-
22274
- this.start = options.start || 0;
22275
- this.endOffset = (options.end == null) ? Infinity : +options.end;
22276
- this.bytesWritten = 0;
22277
- this.pos = this.start;
22278
- this.destroyed = false;
22279
-
22280
- this.on('finish', this.destroy.bind(this));
22281
- }
22282
-
22283
- WriteStream.prototype._write = function(buffer, encoding, callback) {
22284
- var self = this;
22285
- if (self.destroyed) return;
22286
-
22287
- if (self.pos + buffer.length > self.endOffset) {
22288
- var err = new Error("maximum file length exceeded");
22289
- err.code = 'ETOOBIG';
22290
- self.destroy();
22291
- callback(err);
22292
- return;
22293
- }
22294
- self.context.pend.go(function(cb) {
22295
- if (self.destroyed) return cb();
22296
- fs.write(self.context.fd, buffer, 0, buffer.length, self.pos, function(err, bytes) {
22297
- if (err) {
22298
- self.destroy();
22299
- cb();
22300
- callback(err);
22301
- } else {
22302
- self.bytesWritten += bytes;
22303
- self.pos += bytes;
22304
- self.emit('progress');
22305
- cb();
22306
- callback();
22307
- }
22308
- });
22309
- });
22310
- };
22311
-
22312
- WriteStream.prototype.destroy = function() {
22313
- if (this.destroyed) return;
22314
- this.destroyed = true;
22315
- this.context.unref();
22316
- };
22317
-
22318
- util.inherits(BufferSlicer, EventEmitter);
22319
- function BufferSlicer(buffer, options) {
22320
- EventEmitter.call(this);
22321
-
22322
- options = options || {};
22323
- this.refCount = 0;
22324
- this.buffer = buffer;
22325
- this.maxChunkSize = options.maxChunkSize || Number.MAX_SAFE_INTEGER;
22326
- }
22327
-
22328
- BufferSlicer.prototype.read = function(buffer, offset, length, position, callback) {
22329
- var end = position + length;
22330
- var delta = end - this.buffer.length;
22331
- var written = (delta > 0) ? delta : length;
22332
- this.buffer.copy(buffer, offset, position, end);
22333
- setImmediate(function() {
22334
- callback(null, written);
22335
- });
22336
- };
22337
-
22338
- BufferSlicer.prototype.write = function(buffer, offset, length, position, callback) {
22339
- buffer.copy(this.buffer, position, offset, offset + length);
22340
- setImmediate(function() {
22341
- callback(null, length, buffer);
22342
- });
22343
- };
22344
-
22345
- BufferSlicer.prototype.createReadStream = function(options) {
22346
- options = options || {};
22347
- var readStream = new PassThrough(options);
22348
- readStream.destroyed = false;
22349
- readStream.start = options.start || 0;
22350
- readStream.endOffset = options.end;
22351
- // by the time this function returns, we'll be done.
22352
- readStream.pos = readStream.endOffset || this.buffer.length;
22353
-
22354
- // respect the maxChunkSize option to slice up the chunk into smaller pieces.
22355
- var entireSlice = this.buffer.slice(readStream.start, readStream.pos);
22356
- var offset = 0;
22357
- while (true) {
22358
- var nextOffset = offset + this.maxChunkSize;
22359
- if (nextOffset >= entireSlice.length) {
22360
- // last chunk
22361
- if (offset < entireSlice.length) {
22362
- readStream.write(entireSlice.slice(offset, entireSlice.length));
22363
- }
22364
- break;
22365
- }
22366
- readStream.write(entireSlice.slice(offset, nextOffset));
22367
- offset = nextOffset;
22368
- }
22369
-
22370
- readStream.end();
22371
- readStream.destroy = function() {
22372
- readStream.destroyed = true;
22373
- };
22374
- return readStream;
22375
- };
22376
-
22377
- BufferSlicer.prototype.createWriteStream = function(options) {
22378
- var bufferSlicer = this;
22379
- options = options || {};
22380
- var writeStream = new Writable(options);
22381
- writeStream.start = options.start || 0;
22382
- writeStream.endOffset = (options.end == null) ? this.buffer.length : +options.end;
22383
- writeStream.bytesWritten = 0;
22384
- writeStream.pos = writeStream.start;
22385
- writeStream.destroyed = false;
22386
- writeStream._write = function(buffer, encoding, callback) {
22387
- if (writeStream.destroyed) return;
22388
-
22389
- var end = writeStream.pos + buffer.length;
22390
- if (end > writeStream.endOffset) {
22391
- var err = new Error("maximum file length exceeded");
22392
- err.code = 'ETOOBIG';
22393
- writeStream.destroyed = true;
22394
- callback(err);
22395
- return;
22396
- }
22397
- buffer.copy(bufferSlicer.buffer, writeStream.pos, 0, buffer.length);
22398
-
22399
- writeStream.bytesWritten += buffer.length;
22400
- writeStream.pos = end;
22401
- writeStream.emit('progress');
22402
- callback();
22403
- };
22404
- writeStream.destroy = function() {
22405
- writeStream.destroyed = true;
22406
- };
22407
- return writeStream;
22408
- };
22409
-
22410
- BufferSlicer.prototype.ref = function() {
22411
- this.refCount += 1;
22412
- };
22413
-
22414
- BufferSlicer.prototype.unref = function() {
22415
- this.refCount -= 1;
22416
-
22417
- if (this.refCount < 0) {
22418
- throw new Error("invalid unref");
22419
- }
22420
- };
22421
-
22422
- function createFromBuffer(buffer, options) {
22423
- return new BufferSlicer(buffer, options);
22424
- }
22425
-
22426
- function createFromFd(fd, options) {
22427
- return new FdSlicer(fd, options);
22428
- }
22429
-
22430
-
22431
22010
  /***/ }),
22432
22011
 
22433
22012
  /***/ 6330:
@@ -40405,29 +39984,319 @@ try {
40405
39984
 
40406
39985
  /***/ }),
40407
39986
 
40408
- /***/ 78781:
39987
+ /***/ 75481:
39988
+ /***/ ((module) => {
39989
+
39990
+ // Adapted from https://github.com/brianloveswords/buffer-crc32/blob/v0.2.13/index.js
39991
+ const CRC_TABLE = new Int32Array([
39992
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
39993
+ 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
39994
+ 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
39995
+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
39996
+ 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
39997
+ 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
39998
+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
39999
+ 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
40000
+ 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
40001
+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
40002
+ 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
40003
+ 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
40004
+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
40005
+ 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
40006
+ 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
40007
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
40008
+ 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
40009
+ 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
40010
+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
40011
+ 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
40012
+ 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
40013
+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
40014
+ 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
40015
+ 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
40016
+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
40017
+ 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
40018
+ 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
40019
+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
40020
+ 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
40021
+ 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
40022
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
40023
+ 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
40024
+ ]);
40025
+
40026
+ function crc32(buf) {
40027
+ let crc = -1;
40028
+ for (let x of buf) {
40029
+ crc = CRC_TABLE[(crc ^ x) & 0xff] ^ (crc >>> 8);
40030
+ }
40031
+ return (crc ^ -1) >>> 0;
40032
+ }
40033
+
40034
+ module.exports = crc32;
40035
+
40036
+
40037
+ /***/ }),
40038
+
40039
+ /***/ 11276:
40409
40040
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
40410
40041
 
40042
+ // This was adapted from https://github.com/andrewrk/node-fd-slicer by Andrew Kelley under the MIT License.
40411
40043
  var fs = __webpack_require__(57147);
40412
- var zlib = __webpack_require__(59796);
40413
- var fd_slicer = __webpack_require__(65010);
40414
- var crc32 = __webpack_require__(34024);
40415
40044
  var util = __webpack_require__(73837);
40045
+ var stream = __webpack_require__(12781);
40046
+ var Readable = stream.Readable;
40047
+ var PassThrough = stream.PassThrough;
40048
+ var Pend = __webpack_require__(54833);
40416
40049
  var EventEmitter = (__webpack_require__(82361).EventEmitter);
40417
- var Transform = (__webpack_require__(12781).Transform);
40418
- var PassThrough = (__webpack_require__(12781).PassThrough);
40050
+
40051
+ exports.BufferSlicer = BufferSlicer;
40052
+ exports.FdSlicer = FdSlicer;
40053
+
40054
+ util.inherits(FdSlicer, EventEmitter);
40055
+ function FdSlicer(fd) {
40056
+ EventEmitter.call(this);
40057
+
40058
+ this.fd = fd;
40059
+ this.pend = new Pend();
40060
+ this.pend.max = 1;
40061
+ this.refCount = 0;
40062
+ }
40063
+
40064
+ FdSlicer.prototype.read = function(buffer, offset, length, position, callback) {
40065
+ var self = this;
40066
+ self.pend.go(function(cb) {
40067
+ fs.read(self.fd, buffer, offset, length, position, function(err, bytesRead, buffer) {
40068
+ cb();
40069
+ callback(err, bytesRead, buffer);
40070
+ });
40071
+ });
40072
+ };
40073
+
40074
+ FdSlicer.prototype.createReadStream = function(options) {
40075
+ return new ReadStream(this, options);
40076
+ };
40077
+
40078
+ FdSlicer.prototype.ref = function() {
40079
+ this.refCount += 1;
40080
+ };
40081
+
40082
+ FdSlicer.prototype.unref = function() {
40083
+ var self = this;
40084
+ self.refCount -= 1;
40085
+ if (self.refCount < 0) throw new Error("invalid unref");
40086
+ if (self.refCount > 0) return;
40087
+
40088
+ fs.close(self.fd, onCloseDone);
40089
+
40090
+ function onCloseDone(err) {
40091
+ if (err) {
40092
+ self.emit('error', err);
40093
+ } else {
40094
+ self.emit('close');
40095
+ }
40096
+ }
40097
+ };
40098
+
40099
+ util.inherits(ReadStream, Readable);
40100
+ function ReadStream(context, options) {
40101
+ options = options || {};
40102
+ Readable.call(this, options);
40103
+
40104
+ this.context = context;
40105
+ this.context.ref();
40106
+
40107
+ this.start = options.start || 0;
40108
+ this.endOffset = options.end;
40109
+ this.pos = this.start;
40110
+ }
40111
+
40112
+ ReadStream.prototype._read = function(n) {
40113
+ var self = this;
40114
+
40115
+ var toRead = Math.min(self._readableState.highWaterMark, n);
40116
+ if (self.endOffset != null) {
40117
+ toRead = Math.min(toRead, self.endOffset - self.pos);
40118
+ }
40119
+ if (toRead <= 0) {
40120
+ self.push(null);
40121
+ this._cleanup();
40122
+ return;
40123
+ }
40124
+ self.context.pend.go(function(cb) {
40125
+ var buffer = Buffer.allocUnsafe(toRead);
40126
+ fs.read(self.context.fd, buffer, 0, toRead, self.pos, function(err, bytesRead) {
40127
+ if (err) {
40128
+ self.destroy(err);
40129
+ } else if (bytesRead === 0) {
40130
+ self.push(null);
40131
+ self._cleanup();
40132
+ } else {
40133
+ self.pos += bytesRead;
40134
+ self.push(buffer.slice(0, bytesRead));
40135
+ }
40136
+ cb();
40137
+ });
40138
+ });
40139
+ };
40140
+
40141
+ ReadStream.prototype._destroy = function(err, cb) {
40142
+ // Node 14+ calls this automatically at EOF.
40143
+ this._cleanup();
40144
+ cb(err);
40145
+ };
40146
+
40147
+ ReadStream.prototype._cleanup = function() {
40148
+ if (this.context != null) {
40149
+ this.context.unref();
40150
+ this.context = null;
40151
+ }
40152
+ };
40153
+
40154
+ util.inherits(BufferSlicer, EventEmitter);
40155
+ function BufferSlicer(buffer) {
40156
+ EventEmitter.call(this);
40157
+
40158
+ this.refCount = 0;
40159
+ this.buffer = buffer;
40160
+ }
40161
+
40162
+ BufferSlicer.prototype.read = function(buffer, offset, length, position, callback) {
40163
+ if (!(0 <= offset && offset <= buffer.length)) throw new RangeError("offset outside buffer: 0 <= " + offset + " <= " + buffer.length);
40164
+ if (position < 0) throw new RangeError("position is negative: " + position);
40165
+ if (offset + length > buffer.length) {
40166
+ // The caller's buffer can't hold all the bytes they're trying to read.
40167
+ // Clamp the length instead of giving an error.
40168
+ // The callback will be informed of fewer than expected bytes written.
40169
+ length = buffer.length - offset;
40170
+ }
40171
+ if (position + length > this.buffer.length) {
40172
+ // Clamp any attempt to read past the end of the source buffer.
40173
+ length = this.buffer.length - position;
40174
+ }
40175
+ if (length <= 0) {
40176
+ // After any clamping, we're fully out of bounds or otherwise have nothing to do.
40177
+ // This isn't an error; it's just zero bytes written.
40178
+ setImmediate(function() {
40179
+ callback(null, 0);
40180
+ });
40181
+ return;
40182
+ }
40183
+ this.buffer.copy(buffer, offset, position, position + length);
40184
+ setImmediate(function() {
40185
+ callback(null, length);
40186
+ });
40187
+ };
40188
+
40189
+ BufferSlicer.prototype.createReadStream = function(options) {
40190
+ options = options || {};
40191
+ var readStream = new PassThrough(options);
40192
+ readStream.start = options.start || 0;
40193
+ readStream.endOffset = options.end;
40194
+ // by the time this function returns, we'll be done.
40195
+ readStream.pos = readStream.endOffset || this.buffer.length;
40196
+
40197
+ var entireSlice = this.buffer.slice(readStream.start, readStream.pos);
40198
+ // Cut the buffer into smaller slices for better memory usage when streaming into a zlib inflate stream.
40199
+ // See https://github.com/thejoshwolfe/yauzl/issues/87
40200
+ var maxChunkSize = 0x10000;
40201
+ var offset = 0;
40202
+ while (true) {
40203
+ var nextOffset = offset + maxChunkSize;
40204
+ if (nextOffset >= entireSlice.length) {
40205
+ // last chunk
40206
+ if (offset < entireSlice.length) {
40207
+ readStream.write(entireSlice.slice(offset, entireSlice.length));
40208
+ }
40209
+ break;
40210
+ }
40211
+ readStream.write(entireSlice.slice(offset, nextOffset));
40212
+ offset = nextOffset;
40213
+ }
40214
+
40215
+ readStream.end();
40216
+ return readStream;
40217
+ };
40218
+
40219
+ BufferSlicer.prototype.ref = function() {
40220
+ this.refCount += 1;
40221
+ };
40222
+
40223
+ BufferSlicer.prototype.unref = function() {
40224
+ this.refCount -= 1;
40225
+
40226
+ if (this.refCount < 0) {
40227
+ throw new Error("invalid unref");
40228
+ }
40229
+ };
40230
+
40231
+
40232
+ /***/ }),
40233
+
40234
+ /***/ 78781:
40235
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
40236
+
40237
+ var fs = __webpack_require__(57147);
40238
+ var zlib = __webpack_require__(59796);
40239
+ var fd_slicer = __webpack_require__(11276);
40240
+ var util = __webpack_require__(73837);
40241
+ var EventEmitter = (__webpack_require__(82361).EventEmitter);
40242
+ var Transform = (__webpack_require__(12781).Transform);
40243
+ var PassThrough = (__webpack_require__(12781).PassThrough);
40419
40244
  var Writable = (__webpack_require__(12781).Writable);
40420
40245
 
40246
+ // Node 20 added zlib.crc32.
40247
+ const crc32 = typeof zlib.crc32 === "function" ? zlib.crc32 : __webpack_require__(75481);
40248
+
40421
40249
  exports.open = open;
40422
40250
  exports.fromFd = fromFd;
40423
40251
  exports.fromBuffer = fromBuffer;
40424
40252
  exports.fromRandomAccessReader = fromRandomAccessReader;
40253
+ exports.openPromise = openPromise;
40254
+ exports.fromFdPromise = fromFdPromise;
40255
+ exports.fromBufferPromise = fromBufferPromise;
40256
+ exports.fromRandomAccessReaderPromise = fromRandomAccessReaderPromise;
40257
+
40425
40258
  exports.dosDateTimeToDate = dosDateTimeToDate;
40259
+ exports.getFileNameLowLevel = getFileNameLowLevel;
40426
40260
  exports.validateFileName = validateFileName;
40261
+ exports.parseExtraFields = parseExtraFields;
40427
40262
  exports.ZipFile = ZipFile;
40428
40263
  exports.Entry = Entry;
40264
+ exports.LocalFileHeader = LocalFileHeader;
40429
40265
  exports.RandomAccessReader = RandomAccessReader;
40430
40266
 
40267
+ function openPromise(path, options) {
40268
+ return new Promise((resolve, reject) => {
40269
+ open(path, {...options, lazyEntries: true}, function(err, zipfile) {
40270
+ if (err) return reject(err);
40271
+ resolve(zipfile);
40272
+ });
40273
+ });
40274
+ }
40275
+ function fromFdPromise(fd, options) {
40276
+ return new Promise((resolve, reject) => {
40277
+ fromFd(fd, {...options, lazyEntries: true}, function(err, zipfile) {
40278
+ if (err) return reject(err);
40279
+ resolve(zipfile);
40280
+ });
40281
+ });
40282
+ }
40283
+ function fromBufferPromise(buffer, options) {
40284
+ return new Promise((resolve, reject) => {
40285
+ fromBuffer(buffer, {...options, lazyEntries: true}, function(err, zipfile) {
40286
+ if (err) return reject(err);
40287
+ resolve(zipfile);
40288
+ });
40289
+ });
40290
+ }
40291
+ function fromRandomAccessReaderPromise(reader, totalSize, options) {
40292
+ return new Promise((resolve, reject) => {
40293
+ fromRandomAccessReader(reader, totalSize, {...options, lazyEntries: true}, function(err, zipfile) {
40294
+ if (err) return reject(err);
40295
+ resolve(zipfile);
40296
+ });
40297
+ });
40298
+ }
40299
+
40431
40300
  function open(path, options, callback) {
40432
40301
  if (typeof options === "function") {
40433
40302
  callback = options;
@@ -40463,7 +40332,7 @@ function fromFd(fd, options, callback) {
40463
40332
  if (callback == null) callback = defaultCallback;
40464
40333
  fs.fstat(fd, function(err, stats) {
40465
40334
  if (err) return callback(err);
40466
- var reader = fd_slicer.createFromFd(fd, {autoClose: true});
40335
+ var reader = new fd_slicer.FdSlicer(fd);
40467
40336
  fromRandomAccessReader(reader, stats.size, options, callback);
40468
40337
  });
40469
40338
  }
@@ -40479,8 +40348,7 @@ function fromBuffer(buffer, options, callback) {
40479
40348
  if (options.decodeStrings == null) options.decodeStrings = true;
40480
40349
  if (options.validateEntrySizes == null) options.validateEntrySizes = true;
40481
40350
  if (options.strictFileNames == null) options.strictFileNames = false;
40482
- // limit the max chunk size. see https://github.com/thejoshwolfe/yauzl/issues/87
40483
- var reader = fd_slicer.createFromBuffer(buffer, {maxChunkSize: 0x10000});
40351
+ var reader = new fd_slicer.BufferSlicer(buffer);
40484
40352
  fromRandomAccessReader(reader, buffer.length, options, callback);
40485
40353
  }
40486
40354
 
@@ -40512,8 +40380,9 @@ function fromRandomAccessReader(reader, totalSize, options, callback) {
40512
40380
  // as a consequence of this design decision, it's possible to have ambiguous zip file metadata if a coherent eocdr was in the comment.
40513
40381
  // we search backwards for a eocdr signature, and hope that whoever made the zip file was smart enough to forbid the eocdr signature in the comment.
40514
40382
  var eocdrWithoutCommentSize = 22;
40383
+ var zip64EocdlSize = 20; // Zip64 end of central directory locator
40515
40384
  var maxCommentSize = 0xffff; // 2-byte size
40516
- var bufferSize = Math.min(eocdrWithoutCommentSize + maxCommentSize, totalSize);
40385
+ var bufferSize = Math.min(zip64EocdlSize + eocdrWithoutCommentSize + maxCommentSize, totalSize);
40517
40386
  var buffer = newBuffer(bufferSize);
40518
40387
  var bufferReadStart = totalSize - buffer.length;
40519
40388
  readAndAssertNoEof(reader, buffer, 0, bufferSize, bufferReadStart, function(err) {
@@ -40521,14 +40390,11 @@ function fromRandomAccessReader(reader, totalSize, options, callback) {
40521
40390
  for (var i = bufferSize - eocdrWithoutCommentSize; i >= 0; i -= 1) {
40522
40391
  if (buffer.readUInt32LE(i) !== 0x06054b50) continue;
40523
40392
  // found eocdr
40524
- var eocdrBuffer = buffer.slice(i);
40393
+ var eocdrBuffer = buffer.subarray(i);
40525
40394
 
40526
40395
  // 0 - End of central directory signature = 0x06054b50
40527
40396
  // 4 - Number of this disk
40528
40397
  var diskNumber = eocdrBuffer.readUInt16LE(4);
40529
- if (diskNumber !== 0) {
40530
- return callback(new Error("multi-disk zip files are not supported: found disk number: " + diskNumber));
40531
- }
40532
40398
  // 6 - Disk where central directory starts
40533
40399
  // 8 - Number of central directory records on this disk
40534
40400
  // 10 - Total number of central directory records
@@ -40540,29 +40406,18 @@ function fromRandomAccessReader(reader, totalSize, options, callback) {
40540
40406
  var commentLength = eocdrBuffer.readUInt16LE(20);
40541
40407
  var expectedCommentLength = eocdrBuffer.length - eocdrWithoutCommentSize;
40542
40408
  if (commentLength !== expectedCommentLength) {
40543
- return callback(new Error("invalid comment length. expected: " + expectedCommentLength + ". found: " + commentLength));
40409
+ return callback(new Error("Invalid comment length. Expected: " + expectedCommentLength + ". Found: " + commentLength + ". Are there extra bytes at the end of the file? Or is the end of central dir signature `PK☺☻` in the comment?"));
40544
40410
  }
40545
40411
  // 22 - Comment
40546
40412
  // the encoding is always cp437.
40547
- var comment = decodeStrings ? decodeBuffer(eocdrBuffer, 22, eocdrBuffer.length, false)
40548
- : eocdrBuffer.slice(22);
40549
-
40550
- if (!(entryCount === 0xffff || centralDirectoryOffset === 0xffffffff)) {
40551
- return callback(null, new ZipFile(reader, centralDirectoryOffset, totalSize, entryCount, comment, options.autoClose, options.lazyEntries, decodeStrings, options.validateEntrySizes, options.strictFileNames));
40552
- }
40553
-
40554
- // ZIP64 format
40555
-
40556
- // ZIP64 Zip64 end of central directory locator
40557
- var zip64EocdlBuffer = newBuffer(20);
40558
- var zip64EocdlOffset = bufferReadStart + i - zip64EocdlBuffer.length;
40559
- readAndAssertNoEof(reader, zip64EocdlBuffer, 0, zip64EocdlBuffer.length, zip64EocdlOffset, function(err) {
40560
- if (err) return callback(err);
40413
+ var comment = decodeStrings ? decodeBuffer(eocdrBuffer.subarray(22), false)
40414
+ : eocdrBuffer.subarray(22);
40561
40415
 
40416
+ // Look for a Zip64 end of central directory locator
40417
+ if (i - zip64EocdlSize >= 0 && buffer.readUInt32LE(i - zip64EocdlSize) === 0x07064b50) {
40418
+ // ZIP64 format
40419
+ var zip64EocdlBuffer = buffer.subarray(i - zip64EocdlSize, i - zip64EocdlSize + zip64EocdlSize);
40562
40420
  // 0 - zip64 end of central dir locator signature = 0x07064b50
40563
- if (zip64EocdlBuffer.readUInt32LE(0) !== 0x07064b50) {
40564
- return callback(new Error("invalid zip64 end of central directory locator signature"));
40565
- }
40566
40421
  // 4 - number of the disk with the start of the zip64 end of central directory
40567
40422
  // 8 - relative offset of the zip64 end of central directory record
40568
40423
  var zip64EocdrOffset = readUInt64LE(zip64EocdlBuffer, 8);
@@ -40570,7 +40425,7 @@ function fromRandomAccessReader(reader, totalSize, options, callback) {
40570
40425
 
40571
40426
  // ZIP64 end of central directory record
40572
40427
  var zip64EocdrBuffer = newBuffer(56);
40573
- readAndAssertNoEof(reader, zip64EocdrBuffer, 0, zip64EocdrBuffer.length, zip64EocdrOffset, function(err) {
40428
+ return readAndAssertNoEof(reader, zip64EocdrBuffer, 0, zip64EocdrBuffer.length, zip64EocdrOffset, function(err) {
40574
40429
  if (err) return callback(err);
40575
40430
 
40576
40431
  // 0 - zip64 end of central dir signature 4 bytes (0x06064b50)
@@ -40581,6 +40436,11 @@ function fromRandomAccessReader(reader, totalSize, options, callback) {
40581
40436
  // 12 - version made by 2 bytes
40582
40437
  // 14 - version needed to extract 2 bytes
40583
40438
  // 16 - number of this disk 4 bytes
40439
+ diskNumber = zip64EocdrBuffer.readUInt32LE(16);
40440
+ if (diskNumber !== 0) {
40441
+ // Check this only after zip64 overrides. See #118.
40442
+ return callback(new Error("multi-disk zip files are not supported: found disk number: " + diskNumber));
40443
+ }
40584
40444
  // 20 - number of the disk with the start of the central directory 4 bytes
40585
40445
  // 24 - total number of entries in the central directory on this disk 8 bytes
40586
40446
  // 32 - total number of entries in the central directory 8 bytes
@@ -40591,10 +40451,18 @@ function fromRandomAccessReader(reader, totalSize, options, callback) {
40591
40451
  // 56 - zip64 extensible data sector (variable size)
40592
40452
  return callback(null, new ZipFile(reader, centralDirectoryOffset, totalSize, entryCount, comment, options.autoClose, options.lazyEntries, decodeStrings, options.validateEntrySizes, options.strictFileNames));
40593
40453
  });
40594
- });
40595
- return;
40454
+ }
40455
+
40456
+ // Not ZIP64 format
40457
+ if (diskNumber !== 0) {
40458
+ return callback(new Error("multi-disk zip files are not supported: found disk number: " + diskNumber));
40459
+ }
40460
+ return callback(null, new ZipFile(reader, centralDirectoryOffset, totalSize, entryCount, comment, options.autoClose, options.lazyEntries, decodeStrings, options.validateEntrySizes, options.strictFileNames));
40461
+
40596
40462
  }
40597
- callback(new Error("end of central directory record signature not found"));
40463
+
40464
+ // Not a zip file.
40465
+ callback(new Error("End of central directory record signature not found. Either not a zip file, or file is truncated."));
40598
40466
  });
40599
40467
  }
40600
40468
 
@@ -40623,6 +40491,7 @@ function ZipFile(reader, centralDirectoryOffset, fileSize, entryCount, comment,
40623
40491
  self.strictFileNames = !!strictFileNames;
40624
40492
  self.isOpen = true;
40625
40493
  self.emittedError = false;
40494
+ self.hasEachEntryBeenCalled = false;
40626
40495
 
40627
40496
  if (!self.lazyEntries) self._readEntry();
40628
40497
  }
@@ -40707,55 +40576,44 @@ ZipFile.prototype._readEntry = function() {
40707
40576
  if (err) return emitErrorAndAutoClose(self, err);
40708
40577
  if (self.emittedError) return;
40709
40578
  // 46 - File name
40710
- var isUtf8 = (entry.generalPurposeBitFlag & 0x800) !== 0;
40711
- entry.fileName = self.decodeStrings ? decodeBuffer(buffer, 0, entry.fileNameLength, isUtf8)
40712
- : buffer.slice(0, entry.fileNameLength);
40713
-
40579
+ entry.fileNameRaw = buffer.subarray(0, entry.fileNameLength);
40714
40580
  // 46+n - Extra field
40715
40581
  var fileCommentStart = entry.fileNameLength + entry.extraFieldLength;
40716
- var extraFieldBuffer = buffer.slice(entry.fileNameLength, fileCommentStart);
40717
- entry.extraFields = [];
40718
- var i = 0;
40719
- while (i < extraFieldBuffer.length - 3) {
40720
- var headerId = extraFieldBuffer.readUInt16LE(i + 0);
40721
- var dataSize = extraFieldBuffer.readUInt16LE(i + 2);
40722
- var dataStart = i + 4;
40723
- var dataEnd = dataStart + dataSize;
40724
- if (dataEnd > extraFieldBuffer.length) return emitErrorAndAutoClose(self, new Error("extra field length exceeds extra field buffer size"));
40725
- var dataBuffer = newBuffer(dataSize);
40726
- extraFieldBuffer.copy(dataBuffer, 0, dataStart, dataEnd);
40727
- entry.extraFields.push({
40728
- id: headerId,
40729
- data: dataBuffer,
40730
- });
40731
- i = dataEnd;
40582
+ entry.extraFieldRaw = buffer.subarray(entry.fileNameLength, fileCommentStart);
40583
+ // 46+n+m - File comment
40584
+ entry.fileCommentRaw = buffer.subarray(fileCommentStart, fileCommentStart + entry.fileCommentLength);
40585
+
40586
+ // Parse the extra fields, which we need for processing other fields.
40587
+ try {
40588
+ entry.extraFields = parseExtraFields(entry.extraFieldRaw);
40589
+ } catch (err) {
40590
+ return emitErrorAndAutoClose(self, err);
40732
40591
  }
40733
40592
 
40734
- // 46+n+m - File comment
40735
- entry.fileComment = self.decodeStrings ? decodeBuffer(buffer, fileCommentStart, fileCommentStart + entry.fileCommentLength, isUtf8)
40736
- : buffer.slice(fileCommentStart, fileCommentStart + entry.fileCommentLength);
40737
- // compatibility hack for https://github.com/thejoshwolfe/yauzl/issues/47
40593
+ // Interpret strings according to bit flags, extra fields, and options.
40594
+ if (self.decodeStrings) {
40595
+ var isUtf8 = (entry.generalPurposeBitFlag & 0x800) !== 0;
40596
+ entry.fileComment = decodeBuffer(entry.fileCommentRaw, isUtf8);
40597
+ entry.fileName = getFileNameLowLevel(entry.generalPurposeBitFlag, entry.fileNameRaw, entry.extraFields, self.strictFileNames);
40598
+ var errorMessage = validateFileName(entry.fileName);
40599
+ if (errorMessage != null) return emitErrorAndAutoClose(self, new Error(errorMessage));
40600
+ } else {
40601
+ entry.fileComment = entry.fileCommentRaw;
40602
+ entry.fileName = entry.fileNameRaw;
40603
+ }
40604
+ // Maintain API compatibility. See https://github.com/thejoshwolfe/yauzl/issues/47
40738
40605
  entry.comment = entry.fileComment;
40739
40606
 
40740
40607
  self.readEntryCursor += buffer.length;
40741
40608
  self.entriesRead += 1;
40742
40609
 
40743
- if (entry.uncompressedSize === 0xffffffff ||
40744
- entry.compressedSize === 0xffffffff ||
40745
- entry.relativeOffsetOfLocalHeader === 0xffffffff) {
40746
- // ZIP64 format
40747
- // find the Zip64 Extended Information Extra Field
40748
- var zip64EiefBuffer = null;
40749
- for (var i = 0; i < entry.extraFields.length; i++) {
40750
- var extraField = entry.extraFields[i];
40751
- if (extraField.id === 0x0001) {
40752
- zip64EiefBuffer = extraField.data;
40753
- break;
40754
- }
40755
- }
40756
- if (zip64EiefBuffer == null) {
40757
- return emitErrorAndAutoClose(self, new Error("expected zip64 extended information extra field"));
40758
- }
40610
+ // Check for the Zip64 Extended Information Extra Field.
40611
+ for (var i = 0; i < entry.extraFields.length; i++) {
40612
+ var extraField = entry.extraFields[i];
40613
+ if (extraField.id !== 0x0001) continue;
40614
+ // Found it.
40615
+
40616
+ var zip64EiefBuffer = extraField.data;
40759
40617
  var index = 0;
40760
40618
  // 0 - Original Size 8 bytes
40761
40619
  if (entry.uncompressedSize === 0xffffffff) {
@@ -40782,36 +40640,8 @@ ZipFile.prototype._readEntry = function() {
40782
40640
  index += 8;
40783
40641
  }
40784
40642
  // 24 - Disk Start Number 4 bytes
40785
- }
40786
40643
 
40787
- // check for Info-ZIP Unicode Path Extra Field (0x7075)
40788
- // see https://github.com/thejoshwolfe/yauzl/issues/33
40789
- if (self.decodeStrings) {
40790
- for (var i = 0; i < entry.extraFields.length; i++) {
40791
- var extraField = entry.extraFields[i];
40792
- if (extraField.id === 0x7075) {
40793
- if (extraField.data.length < 6) {
40794
- // too short to be meaningful
40795
- continue;
40796
- }
40797
- // Version 1 byte version of this extra field, currently 1
40798
- if (extraField.data.readUInt8(0) !== 1) {
40799
- // > Changes may not be backward compatible so this extra
40800
- // > field should not be used if the version is not recognized.
40801
- continue;
40802
- }
40803
- // NameCRC32 4 bytes File Name Field CRC32 Checksum
40804
- var oldNameCrc32 = extraField.data.readUInt32LE(1);
40805
- if (crc32.unsigned(buffer.slice(0, entry.fileNameLength)) !== oldNameCrc32) {
40806
- // > If the CRC check fails, this UTF-8 Path Extra Field should be
40807
- // > ignored and the File Name field in the header should be used instead.
40808
- continue;
40809
- }
40810
- // UnicodeName Variable UTF-8 version of the entry File Name
40811
- entry.fileName = decodeBuffer(extraField.data, 5, extraField.data.length, true);
40812
- break;
40813
- }
40814
- }
40644
+ break;
40815
40645
  }
40816
40646
 
40817
40647
  // validate file size
@@ -40827,14 +40657,6 @@ ZipFile.prototype._readEntry = function() {
40827
40657
  }
40828
40658
  }
40829
40659
 
40830
- if (self.decodeStrings) {
40831
- if (!self.strictFileNames) {
40832
- // allow backslash
40833
- entry.fileName = entry.fileName.replace(/\\/g, "/");
40834
- }
40835
- var errorMessage = validateFileName(entry.fileName, self.validateFileNameOptions);
40836
- if (errorMessage != null) return emitErrorAndAutoClose(self, new Error(errorMessage));
40837
- }
40838
40660
  self.emit("entry", entry);
40839
40661
 
40840
40662
  if (!self.lazyEntries) self._readEntry();
@@ -40842,6 +40664,68 @@ ZipFile.prototype._readEntry = function() {
40842
40664
  });
40843
40665
  };
40844
40666
 
40667
+ ZipFile.prototype.eachEntry = function() {
40668
+ const self = this;
40669
+ if (!self.lazyEntries) throw new Error("eachEntry() requires lazyEntries: true");
40670
+ if (self.hasEachEntryBeenCalled) throw new Error("eachEntry() must only be called once per ZipFile");
40671
+ self.hasEachEntryBeenCalled = true;
40672
+
40673
+ let pendingResolveReject = null;
40674
+ self.on("entry", onEntry);
40675
+ self.on("end", onEnd);
40676
+ self.on("error", onError);
40677
+ function cleanup() {
40678
+ self.removeListener("entry", onEntry);
40679
+ self.removeListener("end", onEnd);
40680
+ self.removeListener("error", onError);
40681
+ if (self.autoClose) self.close();
40682
+ }
40683
+
40684
+ function onEntry(entry) {
40685
+ let {resolve} = pendingResolveReject;
40686
+ pendingResolveReject = null;
40687
+ resolve({value: entry});
40688
+ }
40689
+ function onEnd() {
40690
+ let {resolve} = pendingResolveReject;
40691
+ pendingResolveReject = null;
40692
+ cleanup();
40693
+ resolve({done: true});
40694
+ }
40695
+ function onError(err) {
40696
+ let {reject} = pendingResolveReject;
40697
+ pendingResolveReject = null;
40698
+ cleanup();
40699
+ reject(err);
40700
+ }
40701
+
40702
+ return {
40703
+ [Symbol.asyncIterator]() {
40704
+ // Called once by `for await...of`.
40705
+ return this;
40706
+ },
40707
+ next() {
40708
+ // Called on each iteration in a `for await...of`.
40709
+ const promise = new Promise((resolve, reject) => {
40710
+ if (pendingResolveReject != null) throw new Error("next() called before previous Promise was resolved.");
40711
+ pendingResolveReject = {resolve, reject};
40712
+ });
40713
+ self.readEntry();
40714
+ return promise;
40715
+ },
40716
+ return(value) {
40717
+ // Called when breaking, returning, throwing out of a `for await...of`.
40718
+ cleanup();
40719
+ return Promise.resolve({done: true, value});
40720
+ },
40721
+ throw(value) {
40722
+ // Almost never called. Something about `yield*` maybe?
40723
+ cleanup();
40724
+ return Promise.reject(value);
40725
+ },
40726
+ };
40727
+ };
40728
+
40845
40729
  ZipFile.prototype.openReadStream = function(entry, options, callback) {
40846
40730
  var self = this;
40847
40731
  // parameter validation
@@ -40849,32 +40733,39 @@ ZipFile.prototype.openReadStream = function(entry, options, callback) {
40849
40733
  var relativeEnd = entry.compressedSize;
40850
40734
  if (callback == null) {
40851
40735
  callback = options;
40736
+ options = null;
40737
+ }
40738
+ if (options == null) {
40852
40739
  options = {};
40853
40740
  } else {
40854
- // validate options that the caller has no excuse to get wrong
40855
- if (options.decrypt != null) {
40856
- if (!entry.isEncrypted()) {
40857
- throw new Error("options.decrypt can only be specified for encrypted entries");
40741
+ if (options.decodeFileData === false) {
40742
+ // new, simple option
40743
+ if (options.decrypt != null) {
40744
+ throw new Error("cannot use options.decrypt when options.decodeFileData === false");
40858
40745
  }
40859
- if (options.decrypt !== false) throw new Error("invalid options.decrypt value: " + options.decrypt);
40860
- if (entry.isCompressed()) {
40861
- if (options.decompress !== false) throw new Error("entry is encrypted and compressed, and options.decompress !== false");
40746
+ if (options.decompress != null) {
40747
+ throw new Error("cannot use options.decompress when options.decodeFileData === false");
40862
40748
  }
40863
- }
40864
- if (options.decompress != null) {
40865
- if (!entry.isCompressed()) {
40866
- throw new Error("options.decompress can only be specified for compressed entries");
40867
- }
40868
- if (!(options.decompress === false || options.decompress === true)) {
40869
- throw new Error("invalid options.decompress value: " + options.decompress);
40870
- }
40871
- }
40872
- if (options.start != null || options.end != null) {
40873
- if (entry.isCompressed() && options.decompress !== false) {
40874
- throw new Error("start/end range not allowed for compressed entry without options.decompress === false");
40749
+ // start and end are allowed
40750
+ } else {
40751
+ // old, complicated options
40752
+ if (options.decrypt != null) {
40753
+ if (!entry.isEncrypted()) {
40754
+ throw new Error("options.decrypt can only be specified for encrypted entries. See also option decodeFileData.");
40755
+ }
40756
+ if (options.decrypt !== false) throw new Error("invalid options.decrypt value: " + options.decrypt);
40757
+ if (entry.isCompressed()) {
40758
+ if (options.decompress !== false) throw new Error("entry is encrypted and compressed, and options.decompress !== false. See also option decodeFileData.");
40759
+ }
40875
40760
  }
40876
- if (entry.isEncrypted() && options.decrypt !== false) {
40877
- throw new Error("start/end range not allowed for encrypted entry without options.decrypt === false");
40761
+ if (options.decompress != null) {
40762
+ if (!entry.isCompressed()) {
40763
+ throw new Error("options.decompress can only be specified for compressed entries. See also option decodeFileData.");
40764
+ }
40765
+ if (!(options.decompress === false || options.decompress === true)) {
40766
+ throw new Error("invalid options.decompress value: " + options.decompress);
40767
+ }
40768
+ decompress = options.decompress;
40878
40769
  }
40879
40770
  }
40880
40771
  if (options.start != null) {
@@ -40889,14 +40780,102 @@ ZipFile.prototype.openReadStream = function(entry, options, callback) {
40889
40780
  if (relativeEnd < relativeStart) throw new Error("options.end < options.start");
40890
40781
  }
40891
40782
  }
40783
+ var rawMode = (
40784
+ options.decodeFileData === false || // Explicitly requested raw.
40785
+ (
40786
+ (entry.compressionMethod === 0 || // Naturally without compression.
40787
+ (entry.compressionMethod === 8 && options.decompress === false) // Deprecated compression bypass option.
40788
+ ) &&
40789
+ (!entry.isEncrypted() || // Naturally without encryption.
40790
+ options.decrypt === false // Deprecated encryption bypass option.
40791
+ )
40792
+ )
40793
+ );
40794
+ if (options.start != null || options.end != null) {
40795
+ // Ensure slicing deals with raw data.
40796
+ if (!rawMode) throw new Error("start/end range require options.decodeFileData === false for non-trivial encoded entries.");
40797
+ }
40798
+
40892
40799
  // any further errors can either be caused by the zipfile,
40893
40800
  // or were introduced in a minor version of yauzl,
40894
40801
  // so should be passed to the client rather than thrown.
40895
40802
  if (!self.isOpen) return callback(new Error("closed"));
40896
- if (entry.isEncrypted()) {
40897
- if (options.decrypt !== false) return callback(new Error("entry is encrypted, and options.decrypt !== false"));
40803
+ if (entry.isEncrypted() && !rawMode) {
40804
+ if (options.decrypt !== false) return callback(new Error("entry is encrypted, and options.decodeFileData !== false"));
40805
+ }
40806
+ var decompress;
40807
+ if (rawMode) {
40808
+ decompress = false;
40809
+ } else if (entry.compressionMethod === 8) {
40810
+ // 8 - The file is Deflated
40811
+ decompress = options.decodeFileData !== true;
40812
+ } else {
40813
+ return callback(new Error("unsupported compression method: " + entry.compressionMethod));
40898
40814
  }
40899
- // make sure we don't lose the fd before we open the actual read stream
40815
+
40816
+ self.readLocalFileHeader(entry, {minimal: true}, function(err, localFileHeader) {
40817
+ if (err) return callback(err);
40818
+ self.openReadStreamLowLevel(
40819
+ localFileHeader.fileDataStart, entry.compressedSize,
40820
+ relativeStart, relativeEnd,
40821
+ decompress, entry.uncompressedSize,
40822
+ callback);
40823
+ });
40824
+ };
40825
+
40826
+ ZipFile.prototype.openReadStreamLowLevel = function(fileDataStart, compressedSize, relativeStart, relativeEnd, decompress, uncompressedSize, callback) {
40827
+ var self = this;
40828
+
40829
+ var fileDataEnd = fileDataStart + compressedSize;
40830
+ var readStream = self.reader.createReadStream({
40831
+ start: fileDataStart + relativeStart,
40832
+ end: fileDataStart + relativeEnd,
40833
+ });
40834
+ var endpointStream = readStream;
40835
+ if (decompress) {
40836
+ var destroyed = false;
40837
+ var inflateFilter = zlib.createInflateRaw();
40838
+ readStream.on("error", function(err) {
40839
+ // setImmediate here because errors can be emitted during the first call to pipe()
40840
+ setImmediate(function() {
40841
+ if (!destroyed) inflateFilter.emit("error", err);
40842
+ });
40843
+ });
40844
+ readStream.pipe(inflateFilter);
40845
+
40846
+ if (self.validateEntrySizes) {
40847
+ endpointStream = new AssertByteCountStream(uncompressedSize);
40848
+ inflateFilter.on("error", function(err) {
40849
+ // forward zlib errors to the client-visible stream
40850
+ setImmediate(function() {
40851
+ if (!destroyed) endpointStream.emit("error", err);
40852
+ });
40853
+ });
40854
+ inflateFilter.pipe(endpointStream);
40855
+ } else {
40856
+ // the zlib filter is the client-visible stream
40857
+ endpointStream = inflateFilter;
40858
+ }
40859
+ // this is part of yauzl's API, so implement this function on the client-visible stream
40860
+ installDestroyFn(endpointStream, function() {
40861
+ destroyed = true;
40862
+ if (inflateFilter !== endpointStream) inflateFilter.unpipe(endpointStream);
40863
+ readStream.unpipe(inflateFilter);
40864
+ // TODO: the inflateFilter may cause a memory leak. see Issue #27.
40865
+ readStream.destroy();
40866
+ });
40867
+ }
40868
+ callback(null, endpointStream);
40869
+ };
40870
+
40871
+ ZipFile.prototype.readLocalFileHeader = function(entry, options, callback) {
40872
+ var self = this;
40873
+ if (callback == null) {
40874
+ callback = options;
40875
+ options = null;
40876
+ }
40877
+ if (options == null) options = {};
40878
+
40900
40879
  self.reader.ref();
40901
40880
  var buffer = newBuffer(30);
40902
40881
  readAndAssertNoEof(self.reader, buffer, 0, buffer.length, entry.relativeOffsetOfLocalHeader, function(err) {
@@ -40907,92 +40886,150 @@ ZipFile.prototype.openReadStream = function(entry, options, callback) {
40907
40886
  if (signature !== 0x04034b50) {
40908
40887
  return callback(new Error("invalid local file header signature: 0x" + signature.toString(16)));
40909
40888
  }
40910
- // all this should be redundant
40889
+
40890
+ var fileNameLength = buffer.readUInt16LE(26);
40891
+ var extraFieldLength = buffer.readUInt16LE(28);
40892
+ var fileDataStart = entry.relativeOffsetOfLocalHeader + 30 + fileNameLength + extraFieldLength;
40893
+ // We now have enough information to do this bounds check.
40894
+ if (fileDataStart + entry.compressedSize > self.fileSize) {
40895
+ return callback(new Error("file data overflows file bounds: " +
40896
+ fileDataStart + " + " + entry.compressedSize + " > " + self.fileSize));
40897
+ }
40898
+
40899
+ if (options.minimal) {
40900
+ return callback(null, {fileDataStart: fileDataStart});
40901
+ }
40902
+
40903
+ var localFileHeader = new LocalFileHeader();
40904
+ localFileHeader.fileDataStart = fileDataStart;
40905
+
40911
40906
  // 4 - Version needed to extract (minimum)
40907
+ localFileHeader.versionNeededToExtract = buffer.readUInt16LE(4);
40912
40908
  // 6 - General purpose bit flag
40909
+ localFileHeader.generalPurposeBitFlag = buffer.readUInt16LE(6);
40913
40910
  // 8 - Compression method
40911
+ localFileHeader.compressionMethod = buffer.readUInt16LE(8);
40914
40912
  // 10 - File last modification time
40913
+ localFileHeader.lastModFileTime = buffer.readUInt16LE(10);
40915
40914
  // 12 - File last modification date
40915
+ localFileHeader.lastModFileDate = buffer.readUInt16LE(12);
40916
40916
  // 14 - CRC-32
40917
+ localFileHeader.crc32 = buffer.readUInt32LE(14);
40917
40918
  // 18 - Compressed size
40919
+ localFileHeader.compressedSize = buffer.readUInt32LE(18);
40918
40920
  // 22 - Uncompressed size
40921
+ localFileHeader.uncompressedSize = buffer.readUInt32LE(22);
40919
40922
  // 26 - File name length (n)
40920
- var fileNameLength = buffer.readUInt16LE(26);
40923
+ localFileHeader.fileNameLength = fileNameLength;
40921
40924
  // 28 - Extra field length (m)
40922
- var extraFieldLength = buffer.readUInt16LE(28);
40925
+ localFileHeader.extraFieldLength = extraFieldLength;
40923
40926
  // 30 - File name
40924
40927
  // 30+n - Extra field
40925
- var localFileHeaderEnd = entry.relativeOffsetOfLocalHeader + buffer.length + fileNameLength + extraFieldLength;
40926
- var decompress;
40927
- if (entry.compressionMethod === 0) {
40928
- // 0 - The file is stored (no compression)
40929
- decompress = false;
40930
- } else if (entry.compressionMethod === 8) {
40931
- // 8 - The file is Deflated
40932
- decompress = options.decompress != null ? options.decompress : true;
40933
- } else {
40934
- return callback(new Error("unsupported compression method: " + entry.compressionMethod));
40935
- }
40936
- var fileDataStart = localFileHeaderEnd;
40937
- var fileDataEnd = fileDataStart + entry.compressedSize;
40938
- if (entry.compressedSize !== 0) {
40939
- // bounds check now, because the read streams will probably not complain loud enough.
40940
- // since we're dealing with an unsigned offset plus an unsigned size,
40941
- // we only have 1 thing to check for.
40942
- if (fileDataEnd > self.fileSize) {
40943
- return callback(new Error("file data overflows file bounds: " +
40944
- fileDataStart + " + " + entry.compressedSize + " > " + self.fileSize));
40945
- }
40946
- }
40947
- var readStream = self.reader.createReadStream({
40948
- start: fileDataStart + relativeStart,
40949
- end: fileDataStart + relativeEnd,
40928
+
40929
+ buffer = newBuffer(fileNameLength + extraFieldLength);
40930
+ self.reader.ref();
40931
+ readAndAssertNoEof(self.reader, buffer, 0, buffer.length, entry.relativeOffsetOfLocalHeader + 30, function(err) {
40932
+ try {
40933
+ if (err) return callback(err);
40934
+ localFileHeader.fileName = buffer.subarray(0, fileNameLength);
40935
+ localFileHeader.extraField = buffer.subarray(fileNameLength);
40936
+ return callback(null, localFileHeader);
40937
+ } finally {
40938
+ self.reader.unref();
40939
+ }
40950
40940
  });
40951
- var endpointStream = readStream;
40952
- if (decompress) {
40953
- var destroyed = false;
40954
- var inflateFilter = zlib.createInflateRaw();
40955
- readStream.on("error", function(err) {
40956
- // setImmediate here because errors can be emitted during the first call to pipe()
40957
- setImmediate(function() {
40958
- if (!destroyed) inflateFilter.emit("error", err);
40959
- });
40960
- });
40961
- readStream.pipe(inflateFilter);
40962
-
40963
- if (self.validateEntrySizes) {
40964
- endpointStream = new AssertByteCountStream(entry.uncompressedSize);
40965
- inflateFilter.on("error", function(err) {
40966
- // forward zlib errors to the client-visible stream
40967
- setImmediate(function() {
40968
- if (!destroyed) endpointStream.emit("error", err);
40969
- });
40970
- });
40971
- inflateFilter.pipe(endpointStream);
40972
- } else {
40973
- // the zlib filter is the client-visible stream
40974
- endpointStream = inflateFilter;
40975
- }
40976
- // this is part of yauzl's API, so implement this function on the client-visible stream
40977
- endpointStream.destroy = function() {
40978
- destroyed = true;
40979
- if (inflateFilter !== endpointStream) inflateFilter.unpipe(endpointStream);
40980
- readStream.unpipe(inflateFilter);
40981
- // TODO: the inflateFilter may cause a memory leak. see Issue #27.
40982
- readStream.destroy();
40983
- };
40984
- }
40985
- callback(null, endpointStream);
40986
40941
  } finally {
40987
40942
  self.reader.unref();
40988
40943
  }
40989
40944
  });
40990
40945
  };
40991
40946
 
40947
+ ZipFile.prototype.openReadStreamPromise = function(entry, options) {
40948
+ return new Promise((resolve, reject) => {
40949
+ this.openReadStream(entry, options, function(err, readStream) {
40950
+ if (err) return reject(err);
40951
+ resolve(readStream);
40952
+ });
40953
+ });
40954
+ };
40955
+ ZipFile.prototype.openReadStreamLowLevelPromise = function(fileDataStart, compressedSize, relativeStart, relativeEnd, decompress, uncompressedSize) {
40956
+ return new Promise((resolve, reject) => {
40957
+ this.openReadStream(fileDataStart, compressedSize, relativeStart, relativeEnd, decompress, uncompressedSize, function(err, readStream) {
40958
+ if (err) return reject(err);
40959
+ resolve(readStream);
40960
+ });
40961
+ });
40962
+ };
40963
+ ZipFile.prototype.readLocalFileHeaderPromise = function(entry, options) {
40964
+ return new Promise((resolve, reject) => {
40965
+ this.readLocalFileHeader(entry, options, function(err, localFileHeader) {
40966
+ if (err) return reject(err);
40967
+ resolve(localFileHeader);
40968
+ });
40969
+ });
40970
+ };
40971
+
40992
40972
  function Entry() {
40993
40973
  }
40994
- Entry.prototype.getLastModDate = function() {
40995
- return dosDateTimeToDate(this.lastModFileDate, this.lastModFileTime);
40974
+ Entry.prototype.getLastModDate = function(options) {
40975
+ if (options == null) options = {};
40976
+
40977
+ if (!options.forceDosFormat) {
40978
+ // Check extended fields.
40979
+ for (var i = 0; i < this.extraFields.length; i++) {
40980
+ var extraField = this.extraFields[i];
40981
+ if (extraField.id === 0x5455) {
40982
+ // Info-ZIP "universal timestamp" extended field (`0x5455` aka `"UT"`).
40983
+ // See the Info-ZIP source code unix/unix.c:set_extra_field() and zipfile.c:ef_scan_ut_time().
40984
+ var data = extraField.data;
40985
+ if (data.length < 5) continue; // Too short.
40986
+ // The flags define which of the three fields are present: mtime, atime, ctime.
40987
+ // We only care about mtime.
40988
+ // Also, ctime is never included in practice.
40989
+ // And also, atime is only included in the local file header for some reason
40990
+ // despite the flags lying about its inclusion in the central header.
40991
+ var flags = data[0];
40992
+ var HAS_MTIME = 1;
40993
+ if (!(flags & HAS_MTIME)) continue; // This will realistically never happen.
40994
+ // Although the positions of all of the fields shift around depending on the presence of other fields,
40995
+ // mtime is always first if present, and that's the only one we care about.
40996
+ var posixTimestamp = data.readInt32LE(1);
40997
+ return new Date(posixTimestamp * 1000);
40998
+ } else if (extraField.id === 0x000a) {
40999
+ var data = extraField.data;
41000
+ if (data.length !== 32) continue; // The length is always the same.
41001
+ // 4 bytes reserved
41002
+ // 2 bytes Tag
41003
+ if (data.readUInt16LE(4) !== 1) continue; // Tag1 is actually the only defined Tag.
41004
+ // 2 bytes Size
41005
+ if (data.readUInt16LE(6) !== 24) continue; // Size is always 24.
41006
+ // 8 bytes Mtime
41007
+ var hundredNanoSecondsSince1601 = data.readUInt32LE(8) + 4294967296 * data.readInt32LE(12);
41008
+ // Convert from NTFS to POSIX milliseconds.
41009
+ // The big number below is the milliseconds between year 1601 and year 1970
41010
+ // (i.e. the negative POSIX timestamp of 1601-01-01 00:00:00Z)
41011
+ var millisecondsSince1970 = hundredNanoSecondsSince1601 / 10000 - 11644473600000;
41012
+ // Note on numeric precision: JavaScript Number objects lose precision above Number.MAX_SAFE_INTEGER,
41013
+ // and NTFS timestamps are typically much bigger than that limit.
41014
+ // (MAX_SAFE_INTEGER would represent 1629-07-17T23:58:45.475Z.)
41015
+ // However, we're losing precision in the conversion from 100nanosecond units to millisecond units anyway,
41016
+ // and the time at which we also lose 1-millisecond precision is year 275760, the JavaScript Date limit (by design).
41017
+ // Up through the year 2057, this conversion only drops 4 bits of precision,
41018
+ // which is well under the 13-14 bits ratio between the milliseconds and 100nanoseconds.
41019
+ return new Date(millisecondsSince1970);
41020
+ }
41021
+ }
41022
+ }
41023
+
41024
+ // Fallback to non-extended encoding.
41025
+ return dosDateTimeToDate(this.lastModFileDate, this.lastModFileTime, options.timezone);
41026
+ };
41027
+
41028
+ Entry.prototype.canDecodeFileData = function() {
41029
+ return (
41030
+ !this.isEncrypted() &&
41031
+ (this.compressionMethod === 0 || this.compressionMethod === 8)
41032
+ );
40996
41033
  };
40997
41034
  Entry.prototype.isEncrypted = function() {
40998
41035
  return (this.generalPurposeBitFlag & 0x1) !== 0;
@@ -41001,7 +41038,10 @@ Entry.prototype.isCompressed = function() {
41001
41038
  return this.compressionMethod === 8;
41002
41039
  };
41003
41040
 
41004
- function dosDateTimeToDate(date, time) {
41041
+ function LocalFileHeader() {
41042
+ }
41043
+
41044
+ function dosDateTimeToDate(date, time, timezone) {
41005
41045
  var day = date & 0x1f; // 1-31
41006
41046
  var month = (date >> 5 & 0xf) - 1; // 1-12, 0-11
41007
41047
  var year = (date >> 9 & 0x7f) + 1980; // 0-128, 1980-2108
@@ -41011,7 +41051,57 @@ function dosDateTimeToDate(date, time) {
41011
41051
  var minute = time >> 5 & 0x3f; // 0-59
41012
41052
  var hour = time >> 11 & 0x1f; // 0-23
41013
41053
 
41014
- return new Date(year, month, day, hour, minute, second, millisecond);
41054
+ if (timezone == null || timezone === "local") {
41055
+ return new Date(year, month, day, hour, minute, second, millisecond);
41056
+ } else if (timezone === "UTC") {
41057
+ return new Date(Date.UTC(year, month, day, hour, minute, second, millisecond));
41058
+ } else {
41059
+ throw new Error("unrecognized options.timezone: " + options.timezone);
41060
+ }
41061
+ }
41062
+
41063
+ function getFileNameLowLevel(generalPurposeBitFlag, fileNameBuffer, extraFields, strictFileNames) {
41064
+ var fileName = null;
41065
+
41066
+ // check for Info-ZIP Unicode Path Extra Field (0x7075)
41067
+ // see https://github.com/thejoshwolfe/yauzl/issues/33
41068
+ for (var i = 0; i < extraFields.length; i++) {
41069
+ var extraField = extraFields[i];
41070
+ if (extraField.id === 0x7075) {
41071
+ if (extraField.data.length < 6) {
41072
+ // too short to be meaningful
41073
+ continue;
41074
+ }
41075
+ // Version 1 byte version of this extra field, currently 1
41076
+ if (extraField.data.readUInt8(0) !== 1) {
41077
+ // > Changes may not be backward compatible so this extra
41078
+ // > field should not be used if the version is not recognized.
41079
+ continue;
41080
+ }
41081
+ // NameCRC32 4 bytes File Name Field CRC32 Checksum
41082
+ var oldNameCrc32 = extraField.data.readUInt32LE(1);
41083
+ if (crc32(fileNameBuffer) !== oldNameCrc32) {
41084
+ // > If the CRC check fails, this UTF-8 Path Extra Field should be
41085
+ // > ignored and the File Name field in the header should be used instead.
41086
+ continue;
41087
+ }
41088
+ // UnicodeName Variable UTF-8 version of the entry File Name
41089
+ fileName = decodeBuffer(extraField.data.subarray(5), true);
41090
+ break;
41091
+ }
41092
+ }
41093
+
41094
+ if (fileName == null) {
41095
+ // The typical case.
41096
+ var isUtf8 = (generalPurposeBitFlag & 0x800) !== 0;
41097
+ fileName = decodeBuffer(fileNameBuffer, isUtf8);
41098
+ }
41099
+
41100
+ if (!strictFileNames) {
41101
+ // Allow backslash.
41102
+ fileName = fileName.replace(/\\/g, "/");
41103
+ }
41104
+ return fileName;
41015
41105
  }
41016
41106
 
41017
41107
  function validateFileName(fileName) {
@@ -41028,6 +41118,25 @@ function validateFileName(fileName) {
41028
41118
  return null;
41029
41119
  }
41030
41120
 
41121
+ function parseExtraFields(extraFieldBuffer) {
41122
+ var extraFields = [];
41123
+ var i = 0;
41124
+ while (i < extraFieldBuffer.length - 3) {
41125
+ var headerId = extraFieldBuffer.readUInt16LE(i + 0);
41126
+ var dataSize = extraFieldBuffer.readUInt16LE(i + 2);
41127
+ var dataStart = i + 4;
41128
+ var dataEnd = dataStart + dataSize;
41129
+ if (dataEnd > extraFieldBuffer.length) throw new Error("extra field length exceeds extra field buffer size");
41130
+ var dataBuffer = extraFieldBuffer.subarray(dataStart, dataEnd);
41131
+ extraFields.push({
41132
+ id: headerId,
41133
+ data: dataBuffer,
41134
+ });
41135
+ i = dataEnd;
41136
+ }
41137
+ return extraFields;
41138
+ }
41139
+
41031
41140
  function readAndAssertNoEof(reader, buffer, offset, length, position, callback) {
41032
41141
  if (length === 0) {
41033
41142
  // fs.read will throw an out-of-bounds error if you try to read 0 bytes from a 0 byte file
@@ -41087,6 +41196,7 @@ RandomAccessReader.prototype.unref = function() {
41087
41196
  }
41088
41197
  };
41089
41198
  RandomAccessReader.prototype.createReadStream = function(options) {
41199
+ if (options == null) options = {};
41090
41200
  var start = options.start;
41091
41201
  var end = options.end;
41092
41202
  if (start === end) {
@@ -41105,11 +41215,11 @@ RandomAccessReader.prototype.createReadStream = function(options) {
41105
41215
  if (!destroyed) refUnrefFilter.emit("error", err);
41106
41216
  });
41107
41217
  });
41108
- refUnrefFilter.destroy = function() {
41218
+ installDestroyFn(refUnrefFilter, function() {
41109
41219
  stream.unpipe(refUnrefFilter);
41110
41220
  refUnrefFilter.unref();
41111
41221
  stream.destroy();
41112
- };
41222
+ });
41113
41223
 
41114
41224
  var byteCounter = new AssertByteCountStream(end - start);
41115
41225
  refUnrefFilter.on("error", function(err) {
@@ -41117,11 +41227,11 @@ RandomAccessReader.prototype.createReadStream = function(options) {
41117
41227
  if (!destroyed) byteCounter.emit("error", err);
41118
41228
  });
41119
41229
  });
41120
- byteCounter.destroy = function() {
41230
+ installDestroyFn(byteCounter, function() {
41121
41231
  destroyed = true;
41122
41232
  refUnrefFilter.unpipe(byteCounter);
41123
41233
  refUnrefFilter.destroy();
41124
- };
41234
+ });
41125
41235
 
41126
41236
  return stream.pipe(refUnrefFilter).pipe(byteCounter);
41127
41237
  };
@@ -41165,12 +41275,12 @@ RefUnrefFilter.prototype.unref = function(cb) {
41165
41275
  };
41166
41276
 
41167
41277
  var cp437 = '\u0000☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ';
41168
- function decodeBuffer(buffer, start, end, isUtf8) {
41278
+ function decodeBuffer(buffer, isUtf8) {
41169
41279
  if (isUtf8) {
41170
- return buffer.toString("utf8", start, end);
41280
+ return buffer.toString("utf8");
41171
41281
  } else {
41172
41282
  var result = "";
41173
- for (var i = start; i < end; i++) {
41283
+ for (var i = 0; i < buffer.length; i++) {
41174
41284
  result += cp437[buffer[i]];
41175
41285
  }
41176
41286
  return result;
@@ -41178,9 +41288,11 @@ function decodeBuffer(buffer, start, end, isUtf8) {
41178
41288
  }
41179
41289
 
41180
41290
  function readUInt64LE(buffer, offset) {
41181
- // there is no native function for this, because we can't actually store 64-bit integers precisely.
41291
+ // There is no native function for this, because we can't actually store 64-bit integers precisely.
41182
41292
  // after 53 bits, JavaScript's Number type (IEEE 754 double) can't store individual integers anymore.
41183
41293
  // but since 53 bits is a whole lot more than 32 bits, we do our best anyway.
41294
+ // As of 2020, Node has added support for BigInt, which obviates this whole function,
41295
+ // but yauzl hasn't been updated to depend on BigInt (yet?).
41184
41296
  var lower32 = buffer.readUInt32LE(offset);
41185
41297
  var upper32 = buffer.readUInt32LE(offset + 4);
41186
41298
  // we can't use bitshifting here, because JavaScript bitshifting only works on 32-bit integers.
@@ -41201,6 +41313,20 @@ if (typeof Buffer.allocUnsafe === "function") {
41201
41313
  };
41202
41314
  }
41203
41315
 
41316
+ // Node 8 introduced a proper destroy() implementation on writable streams.
41317
+ function installDestroyFn(stream, fn) {
41318
+ if (typeof stream.destroy === "function") {
41319
+ // New API.
41320
+ stream._destroy = function(err, cb) {
41321
+ fn();
41322
+ if (cb != null) cb(err);
41323
+ };
41324
+ } else {
41325
+ // Old API.
41326
+ stream.destroy = fn;
41327
+ }
41328
+ }
41329
+
41204
41330
  function defaultCallback(err) {
41205
41331
  if (err) throw err;
41206
41332
  }