node-stream-zip 1.12.0 → 1.13.3

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.
@@ -3,160 +3,142 @@
3
3
  * Portions copyright https://github.com/cthackers/adm-zip | https://raw.githubusercontent.com/cthackers/adm-zip/master/LICENSE
4
4
  */
5
5
 
6
- // region Deps
7
-
8
- var
9
- util = require('util'),
10
- fs = require('fs'),
11
- path = require('path'),
12
- events = require('events'),
13
- zlib = require('zlib'),
14
- stream = require('stream');
15
-
16
- // endregion
17
-
18
- // region Constants
19
-
20
- var consts = {
6
+ let fs = require('fs');
7
+ const util = require('util');
8
+ const path = require('path');
9
+ const events = require('events');
10
+ const zlib = require('zlib');
11
+ const stream = require('stream');
12
+
13
+ const consts = {
21
14
  /* The local file header */
22
- LOCHDR : 30, // LOC header size
23
- LOCSIG : 0x04034b50, // "PK\003\004"
24
- LOCVER : 4, // version needed to extract
25
- LOCFLG : 6, // general purpose bit flag
26
- LOCHOW : 8, // compression method
27
- LOCTIM : 10, // modification time (2 bytes time, 2 bytes date)
28
- LOCCRC : 14, // uncompressed file crc-32 value
29
- LOCSIZ : 18, // compressed size
30
- LOCLEN : 22, // uncompressed size
31
- LOCNAM : 26, // filename length
32
- LOCEXT : 28, // extra field length
15
+ LOCHDR: 30, // LOC header size
16
+ LOCSIG: 0x04034b50, // "PK\003\004"
17
+ LOCVER: 4, // version needed to extract
18
+ LOCFLG: 6, // general purpose bit flag
19
+ LOCHOW: 8, // compression method
20
+ LOCTIM: 10, // modification time (2 bytes time, 2 bytes date)
21
+ LOCCRC: 14, // uncompressed file crc-32 value
22
+ LOCSIZ: 18, // compressed size
23
+ LOCLEN: 22, // uncompressed size
24
+ LOCNAM: 26, // filename length
25
+ LOCEXT: 28, // extra field length
33
26
 
34
27
  /* The Data descriptor */
35
- EXTSIG : 0x08074b50, // "PK\007\008"
36
- EXTHDR : 16, // EXT header size
37
- EXTCRC : 4, // uncompressed file crc-32 value
38
- EXTSIZ : 8, // compressed size
39
- EXTLEN : 12, // uncompressed size
28
+ EXTSIG: 0x08074b50, // "PK\007\008"
29
+ EXTHDR: 16, // EXT header size
30
+ EXTCRC: 4, // uncompressed file crc-32 value
31
+ EXTSIZ: 8, // compressed size
32
+ EXTLEN: 12, // uncompressed size
40
33
 
41
34
  /* The central directory file header */
42
- CENHDR : 46, // CEN header size
43
- CENSIG : 0x02014b50, // "PK\001\002"
44
- CENVEM : 4, // version made by
45
- CENVER : 6, // version needed to extract
46
- CENFLG : 8, // encrypt, decrypt flags
47
- CENHOW : 10, // compression method
48
- CENTIM : 12, // modification time (2 bytes time, 2 bytes date)
49
- CENCRC : 16, // uncompressed file crc-32 value
50
- CENSIZ : 20, // compressed size
51
- CENLEN : 24, // uncompressed size
52
- CENNAM : 28, // filename length
53
- CENEXT : 30, // extra field length
54
- CENCOM : 32, // file comment length
55
- CENDSK : 34, // volume number start
56
- CENATT : 36, // internal file attributes
57
- CENATX : 38, // external file attributes (host system dependent)
58
- CENOFF : 42, // LOC header offset
35
+ CENHDR: 46, // CEN header size
36
+ CENSIG: 0x02014b50, // "PK\001\002"
37
+ CENVEM: 4, // version made by
38
+ CENVER: 6, // version needed to extract
39
+ CENFLG: 8, // encrypt, decrypt flags
40
+ CENHOW: 10, // compression method
41
+ CENTIM: 12, // modification time (2 bytes time, 2 bytes date)
42
+ CENCRC: 16, // uncompressed file crc-32 value
43
+ CENSIZ: 20, // compressed size
44
+ CENLEN: 24, // uncompressed size
45
+ CENNAM: 28, // filename length
46
+ CENEXT: 30, // extra field length
47
+ CENCOM: 32, // file comment length
48
+ CENDSK: 34, // volume number start
49
+ CENATT: 36, // internal file attributes
50
+ CENATX: 38, // external file attributes (host system dependent)
51
+ CENOFF: 42, // LOC header offset
59
52
 
60
53
  /* The entries in the end of central directory */
61
- ENDHDR : 22, // END header size
62
- ENDSIG : 0x06054b50, // "PK\005\006"
63
- ENDSIGFIRST : 0x50,
64
- ENDSUB : 8, // number of entries on this disk
65
- ENDTOT : 10, // total number of entries
66
- ENDSIZ : 12, // central directory size in bytes
67
- ENDOFF : 16, // offset of first CEN header
68
- ENDCOM : 20, // zip file comment length
69
- MAXFILECOMMENT : 0xFFFF,
54
+ ENDHDR: 22, // END header size
55
+ ENDSIG: 0x06054b50, // "PK\005\006"
56
+ ENDSIGFIRST: 0x50,
57
+ ENDSUB: 8, // number of entries on this disk
58
+ ENDTOT: 10, // total number of entries
59
+ ENDSIZ: 12, // central directory size in bytes
60
+ ENDOFF: 16, // offset of first CEN header
61
+ ENDCOM: 20, // zip file comment length
62
+ MAXFILECOMMENT: 0xffff,
70
63
 
71
64
  /* The entries in the end of ZIP64 central directory locator */
72
- ENDL64HDR : 20, // ZIP64 end of central directory locator header size
73
- ENDL64SIG : 0x07064b50, // ZIP64 end of central directory locator signature
74
- ENDL64SIGFIRST : 0x50,
75
- ENDL64OFS : 8, // ZIP64 end of central directory offset
65
+ ENDL64HDR: 20, // ZIP64 end of central directory locator header size
66
+ ENDL64SIG: 0x07064b50, // ZIP64 end of central directory locator signature
67
+ ENDL64SIGFIRST: 0x50,
68
+ ENDL64OFS: 8, // ZIP64 end of central directory offset
76
69
 
77
70
  /* The entries in the end of ZIP64 central directory */
78
- END64HDR : 56, // ZIP64 end of central directory header size
79
- END64SIG : 0x06064b50, // ZIP64 end of central directory signature
80
- END64SIGFIRST : 0x50,
81
- END64SUB : 24, // number of entries on this disk
82
- END64TOT : 32, // total number of entries
83
- END64SIZ : 40,
84
- END64OFF : 48,
71
+ END64HDR: 56, // ZIP64 end of central directory header size
72
+ END64SIG: 0x06064b50, // ZIP64 end of central directory signature
73
+ END64SIGFIRST: 0x50,
74
+ END64SUB: 24, // number of entries on this disk
75
+ END64TOT: 32, // total number of entries
76
+ END64SIZ: 40,
77
+ END64OFF: 48,
85
78
 
86
79
  /* Compression methods */
87
- STORED : 0, // no compression
88
- SHRUNK : 1, // shrunk
89
- REDUCED1 : 2, // reduced with compression factor 1
90
- REDUCED2 : 3, // reduced with compression factor 2
91
- REDUCED3 : 4, // reduced with compression factor 3
92
- REDUCED4 : 5, // reduced with compression factor 4
93
- IMPLODED : 6, // imploded
80
+ STORED: 0, // no compression
81
+ SHRUNK: 1, // shrunk
82
+ REDUCED1: 2, // reduced with compression factor 1
83
+ REDUCED2: 3, // reduced with compression factor 2
84
+ REDUCED3: 4, // reduced with compression factor 3
85
+ REDUCED4: 5, // reduced with compression factor 4
86
+ IMPLODED: 6, // imploded
94
87
  // 7 reserved
95
- DEFLATED : 8, // deflated
88
+ DEFLATED: 8, // deflated
96
89
  ENHANCED_DEFLATED: 9, // deflate64
97
- PKWARE : 10,// PKWare DCL imploded
90
+ PKWARE: 10, // PKWare DCL imploded
98
91
  // 11 reserved
99
- BZIP2 : 12, // compressed using BZIP2
92
+ BZIP2: 12, // compressed using BZIP2
100
93
  // 13 reserved
101
- LZMA : 14, // LZMA
94
+ LZMA: 14, // LZMA
102
95
  // 15-17 reserved
103
- IBM_TERSE : 18, // compressed using IBM TERSE
104
- IBM_LZ77 : 19, //IBM LZ77 z
96
+ IBM_TERSE: 18, // compressed using IBM TERSE
97
+ IBM_LZ77: 19, //IBM LZ77 z
105
98
 
106
99
  /* General purpose bit flag */
107
- FLG_ENC : 0, // encrypted file
108
- FLG_COMP1 : 1, // compression option
109
- FLG_COMP2 : 2, // compression option
110
- FLG_DESC : 4, // data descriptor
111
- FLG_ENH : 8, // enhanced deflation
112
- FLG_STR : 16, // strong encryption
113
- FLG_LNG : 1024, // language encoding
114
- FLG_MSK : 4096, // mask header values
115
- FLG_ENTRY_ENC : 1,
100
+ FLG_ENC: 0, // encrypted file
101
+ FLG_COMP1: 1, // compression option
102
+ FLG_COMP2: 2, // compression option
103
+ FLG_DESC: 4, // data descriptor
104
+ FLG_ENH: 8, // enhanced deflation
105
+ FLG_STR: 16, // strong encryption
106
+ FLG_LNG: 1024, // language encoding
107
+ FLG_MSK: 4096, // mask header values
108
+ FLG_ENTRY_ENC: 1,
116
109
 
117
110
  /* 4.5 Extensible data fields */
118
- EF_ID : 0,
119
- EF_SIZE : 2,
111
+ EF_ID: 0,
112
+ EF_SIZE: 2,
120
113
 
121
114
  /* Header IDs */
122
- ID_ZIP64 : 0x0001,
123
- ID_AVINFO : 0x0007,
124
- ID_PFS : 0x0008,
125
- ID_OS2 : 0x0009,
126
- ID_NTFS : 0x000a,
127
- ID_OPENVMS : 0x000c,
128
- ID_UNIX : 0x000d,
129
- ID_FORK : 0x000e,
130
- ID_PATCH : 0x000f,
131
- ID_X509_PKCS7 : 0x0014,
132
- ID_X509_CERTID_F : 0x0015,
133
- ID_X509_CERTID_C : 0x0016,
134
- ID_STRONGENC : 0x0017,
135
- ID_RECORD_MGT : 0x0018,
136
- ID_X509_PKCS7_RL : 0x0019,
137
- ID_IBM1 : 0x0065,
138
- ID_IBM2 : 0x0066,
139
- ID_POSZIP : 0x4690,
140
-
141
- EF_ZIP64_OR_32 : 0xffffffff,
142
- EF_ZIP64_OR_16 : 0xffff
115
+ ID_ZIP64: 0x0001,
116
+ ID_AVINFO: 0x0007,
117
+ ID_PFS: 0x0008,
118
+ ID_OS2: 0x0009,
119
+ ID_NTFS: 0x000a,
120
+ ID_OPENVMS: 0x000c,
121
+ ID_UNIX: 0x000d,
122
+ ID_FORK: 0x000e,
123
+ ID_PATCH: 0x000f,
124
+ ID_X509_PKCS7: 0x0014,
125
+ ID_X509_CERTID_F: 0x0015,
126
+ ID_X509_CERTID_C: 0x0016,
127
+ ID_STRONGENC: 0x0017,
128
+ ID_RECORD_MGT: 0x0018,
129
+ ID_X509_PKCS7_RL: 0x0019,
130
+ ID_IBM1: 0x0065,
131
+ ID_IBM2: 0x0066,
132
+ ID_POSZIP: 0x4690,
133
+
134
+ EF_ZIP64_OR_32: 0xffffffff,
135
+ EF_ZIP64_OR_16: 0xffff,
143
136
  };
144
137
 
145
- // endregion
146
-
147
- // region StreamZip
148
-
149
- var StreamZip = function(config) {
150
- var
151
- fd,
152
- fileSize,
153
- chunkSize,
154
- ready = false,
138
+ const StreamZip = function (config) {
139
+ let fd, fileSize, chunkSize, op, centralDirectory, closed;
140
+ const ready = false,
155
141
  that = this,
156
- op,
157
- centralDirectory,
158
- closed,
159
-
160
142
  entries = config.storeEntries !== false ? {} : null,
161
143
  fileName = config.file;
162
144
 
@@ -167,9 +149,10 @@ var StreamZip = function(config) {
167
149
  fd = config.fd;
168
150
  readFile();
169
151
  } else {
170
- fs.open(fileName, 'r', function (err, f) {
171
- if (err)
152
+ fs.open(fileName, 'r', (err, f) => {
153
+ if (err) {
172
154
  return that.emit('error', err);
155
+ }
173
156
  fd = f;
174
157
  readFile();
175
158
  });
@@ -177,27 +160,31 @@ var StreamZip = function(config) {
177
160
  }
178
161
 
179
162
  function readFile() {
180
- fs.fstat(fd, function(err, stat) {
181
- if (err)
163
+ fs.fstat(fd, (err, stat) => {
164
+ if (err) {
182
165
  return that.emit('error', err);
166
+ }
183
167
  fileSize = stat.size;
184
168
  chunkSize = config.chunkSize || Math.round(fileSize / 1000);
185
- chunkSize = Math.max(Math.min(chunkSize, Math.min(128*1024, fileSize)), Math.min(1024, fileSize));
169
+ chunkSize = Math.max(
170
+ Math.min(chunkSize, Math.min(128 * 1024, fileSize)),
171
+ Math.min(1024, fileSize)
172
+ );
186
173
  readCentralDirectory();
187
174
  });
188
175
  }
189
176
 
190
177
  function readUntilFoundCallback(err, bytesRead) {
191
- if (err || !bytesRead)
192
- return that.emit('error', err || 'Archive read error');
193
- var
194
- buffer = op.win.buffer,
195
- pos = op.lastPos,
196
- bufferPosition = pos - op.win.position,
197
- minPos = op.minPos;
178
+ if (err || !bytesRead) {
179
+ return that.emit('error', err || new Error('Archive read error'));
180
+ }
181
+ let pos = op.lastPos;
182
+ let bufferPosition = pos - op.win.position;
183
+ const buffer = op.win.buffer;
184
+ const minPos = op.minPos;
198
185
  while (--pos >= minPos && --bufferPosition >= 0) {
199
- if (buffer.length - bufferPosition >= 4 &&
200
- buffer[bufferPosition] === op.firstByte) { // quick check first signature byte
186
+ if (buffer.length - bufferPosition >= 4 && buffer[bufferPosition] === op.firstByte) {
187
+ // quick check first signature byte
201
188
  if (buffer.readUInt32LE(bufferPosition) === op.sig) {
202
189
  op.lastBufferPosition = bufferPosition;
203
190
  op.lastBytesRead = bytesRead;
@@ -207,48 +194,57 @@ var StreamZip = function(config) {
207
194
  }
208
195
  }
209
196
  if (pos === minPos) {
210
- return that.emit('error', 'Bad archive');
197
+ return that.emit('error', new Error('Bad archive'));
211
198
  }
212
199
  op.lastPos = pos + 1;
213
200
  op.chunkSize *= 2;
214
- if (pos <= minPos)
215
- return that.emit('error', 'Bad archive');
216
- var expandLength = Math.min(op.chunkSize, pos - minPos);
201
+ if (pos <= minPos) {
202
+ return that.emit('error', new Error('Bad archive'));
203
+ }
204
+ const expandLength = Math.min(op.chunkSize, pos - minPos);
217
205
  op.win.expandLeft(expandLength, readUntilFoundCallback);
218
-
219
206
  }
220
207
 
221
208
  function readCentralDirectory() {
222
- var totalReadLength = Math.min(consts.ENDHDR + consts.MAXFILECOMMENT, fileSize);
209
+ const totalReadLength = Math.min(consts.ENDHDR + consts.MAXFILECOMMENT, fileSize);
223
210
  op = {
224
211
  win: new FileWindowBuffer(fd),
225
- totalReadLength: totalReadLength,
212
+ totalReadLength,
226
213
  minPos: fileSize - totalReadLength,
227
214
  lastPos: fileSize,
228
215
  chunkSize: Math.min(1024, chunkSize),
229
216
  firstByte: consts.ENDSIGFIRST,
230
217
  sig: consts.ENDSIG,
231
- complete: readCentralDirectoryComplete
218
+ complete: readCentralDirectoryComplete,
232
219
  };
233
220
  op.win.read(fileSize - op.chunkSize, op.chunkSize, readUntilFoundCallback);
234
221
  }
235
222
 
236
223
  function readCentralDirectoryComplete() {
237
- var buffer = op.win.buffer;
238
- var pos = op.lastBufferPosition;
224
+ const buffer = op.win.buffer;
225
+ const pos = op.lastBufferPosition;
239
226
  try {
240
227
  centralDirectory = new CentralDirectoryHeader();
241
228
  centralDirectory.read(buffer.slice(pos, pos + consts.ENDHDR));
242
229
  centralDirectory.headerOffset = op.win.position + pos;
243
- if (centralDirectory.commentLength)
244
- that.comment = buffer.slice(pos + consts.ENDHDR,
245
- pos + consts.ENDHDR + centralDirectory.commentLength).toString();
246
- else
230
+ if (centralDirectory.commentLength) {
231
+ that.comment = buffer
232
+ .slice(
233
+ pos + consts.ENDHDR,
234
+ pos + consts.ENDHDR + centralDirectory.commentLength
235
+ )
236
+ .toString();
237
+ } else {
247
238
  that.comment = null;
239
+ }
248
240
  that.entriesCount = centralDirectory.volumeEntries;
249
241
  that.centralDirectory = centralDirectory;
250
- if (centralDirectory.volumeEntries === consts.EF_ZIP64_OR_16 && centralDirectory.totalEntries === consts.EF_ZIP64_OR_16
251
- || centralDirectory.size === consts.EF_ZIP64_OR_32 || centralDirectory.offset === consts.EF_ZIP64_OR_32) {
242
+ if (
243
+ (centralDirectory.volumeEntries === consts.EF_ZIP64_OR_16 &&
244
+ centralDirectory.totalEntries === consts.EF_ZIP64_OR_16) ||
245
+ centralDirectory.size === consts.EF_ZIP64_OR_32 ||
246
+ centralDirectory.offset === consts.EF_ZIP64_OR_32
247
+ ) {
252
248
  readZip64CentralDirectoryLocator();
253
249
  } else {
254
250
  op = {};
@@ -260,7 +256,7 @@ var StreamZip = function(config) {
260
256
  }
261
257
 
262
258
  function readZip64CentralDirectoryLocator() {
263
- var length = consts.ENDL64HDR;
259
+ const length = consts.ENDL64HDR;
264
260
  if (op.lastBufferPosition > length) {
265
261
  op.lastBufferPosition -= length;
266
262
  readZip64CentralDirectoryLocatorComplete();
@@ -273,17 +269,19 @@ var StreamZip = function(config) {
273
269
  chunkSize: op.chunkSize,
274
270
  firstByte: consts.ENDL64SIGFIRST,
275
271
  sig: consts.ENDL64SIG,
276
- complete: readZip64CentralDirectoryLocatorComplete
272
+ complete: readZip64CentralDirectoryLocatorComplete,
277
273
  };
278
274
  op.win.read(op.lastPos - op.chunkSize, op.chunkSize, readUntilFoundCallback);
279
275
  }
280
276
  }
281
277
 
282
278
  function readZip64CentralDirectoryLocatorComplete() {
283
- var buffer = op.win.buffer;
284
- var locHeader = new CentralDirectoryLoc64Header();
285
- locHeader.read(buffer.slice(op.lastBufferPosition, op.lastBufferPosition + consts.ENDL64HDR));
286
- var readLength = fileSize - locHeader.headerOffset;
279
+ const buffer = op.win.buffer;
280
+ const locHeader = new CentralDirectoryLoc64Header();
281
+ locHeader.read(
282
+ buffer.slice(op.lastBufferPosition, op.lastBufferPosition + consts.ENDL64HDR)
283
+ );
284
+ const readLength = fileSize - locHeader.headerOffset;
287
285
  op = {
288
286
  win: op.win,
289
287
  totalReadLength: readLength,
@@ -292,14 +290,14 @@ var StreamZip = function(config) {
292
290
  chunkSize: op.chunkSize,
293
291
  firstByte: consts.END64SIGFIRST,
294
292
  sig: consts.END64SIG,
295
- complete: readZip64CentralDirectoryComplete
293
+ complete: readZip64CentralDirectoryComplete,
296
294
  };
297
295
  op.win.read(fileSize - op.chunkSize, op.chunkSize, readUntilFoundCallback);
298
296
  }
299
297
 
300
298
  function readZip64CentralDirectoryComplete() {
301
- var buffer = op.win.buffer;
302
- var zip64cd = new CentralDirectoryZip64Header();
299
+ const buffer = op.win.buffer;
300
+ const zip64cd = new CentralDirectoryZip64Header();
303
301
  zip64cd.read(buffer.slice(op.lastBufferPosition, op.lastBufferPosition + consts.END64HDR));
304
302
  that.centralDirectory.volumeEntries = zip64cd.volumeEntries;
305
303
  that.centralDirectory.totalEntries = zip64cd.totalEntries;
@@ -314,20 +312,20 @@ var StreamZip = function(config) {
314
312
  op = {
315
313
  win: new FileWindowBuffer(fd),
316
314
  pos: centralDirectory.offset,
317
- chunkSize: chunkSize,
318
- entriesLeft: centralDirectory.volumeEntries
315
+ chunkSize,
316
+ entriesLeft: centralDirectory.volumeEntries,
319
317
  };
320
318
  op.win.read(op.pos, Math.min(chunkSize, fileSize - op.pos), readEntriesCallback);
321
319
  }
322
320
 
323
321
  function readEntriesCallback(err, bytesRead) {
324
- if (err || !bytesRead)
325
- return that.emit('error', err || 'Entries read error');
326
- var
327
- buffer = op.win.buffer,
328
- bufferPos = op.pos - op.win.position,
329
- bufferLength = buffer.length,
330
- entry = op.entry;
322
+ if (err || !bytesRead) {
323
+ return that.emit('error', err || new Error('Entries read error'));
324
+ }
325
+ let bufferPos = op.pos - op.win.position;
326
+ let entry = op.entry;
327
+ const buffer = op.win.buffer;
328
+ const bufferLength = buffer.length;
331
329
  try {
332
330
  while (op.entriesLeft > 0) {
333
331
  if (!entry) {
@@ -338,8 +336,8 @@ var StreamZip = function(config) {
338
336
  op.pos += consts.CENHDR;
339
337
  bufferPos += consts.CENHDR;
340
338
  }
341
- var entryHeaderSize = entry.fnameLen + entry.extraLen + entry.comLen;
342
- var advanceBytes = entryHeaderSize + (op.entriesLeft > 1 ? consts.CENHDR : 0);
339
+ const entryHeaderSize = entry.fnameLen + entry.extraLen + entry.comLen;
340
+ const advanceBytes = entryHeaderSize + (op.entriesLeft > 1 ? consts.CENHDR : 0);
343
341
  if (bufferLength - bufferPos < advanceBytes) {
344
342
  op.win.moveRight(chunkSize, readEntriesCallback, bufferPos);
345
343
  op.move = true;
@@ -349,8 +347,9 @@ var StreamZip = function(config) {
349
347
  if (!config.skipEntryNameValidation) {
350
348
  entry.validateName();
351
349
  }
352
- if (entries)
350
+ if (entries) {
353
351
  entries[entry.name] = entry;
352
+ }
354
353
  that.emit('entry', entry);
355
354
  op.entry = entry = null;
356
355
  op.entriesLeft--;
@@ -364,95 +363,118 @@ var StreamZip = function(config) {
364
363
  }
365
364
 
366
365
  function checkEntriesExist() {
367
- if (!entries)
366
+ if (!entries) {
368
367
  throw new Error('storeEntries disabled');
368
+ }
369
369
  }
370
370
 
371
- Object.defineProperty(this, 'ready', { get: function() { return ready; } });
371
+ Object.defineProperty(this, 'ready', {
372
+ get() {
373
+ return ready;
374
+ },
375
+ });
372
376
 
373
- this.entry = function(name) {
377
+ this.entry = function (name) {
374
378
  checkEntriesExist();
375
379
  return entries[name];
376
380
  };
377
381
 
378
- this.entries = function() {
382
+ this.entries = function () {
379
383
  checkEntriesExist();
380
384
  return entries;
381
385
  };
382
386
 
383
- this.stream = function(entry, callback) {
384
- return this.openEntry(entry, function(err, entry) {
385
- if (err)
386
- return callback(err);
387
- var offset = dataOffset(entry);
388
- var entryStream = new EntryDataReaderStream(fd, offset, entry.compressedSize);
389
- if (entry.method === consts.STORED) {
390
- } else if (entry.method === consts.DEFLATED) {
391
- entryStream = entryStream.pipe(zlib.createInflateRaw());
392
- } else {
393
- return callback('Unknown compression method: ' + entry.method);
394
- }
395
- if (canVerifyCrc(entry))
396
- entryStream = entryStream.pipe(new EntryVerifyStream(entryStream, entry.crc, entry.size));
397
- callback(null, entryStream);
398
- }, false);
387
+ this.stream = function (entry, callback) {
388
+ return this.openEntry(
389
+ entry,
390
+ (err, entry) => {
391
+ if (err) {
392
+ return callback(err);
393
+ }
394
+ const offset = dataOffset(entry);
395
+ let entryStream = new EntryDataReaderStream(fd, offset, entry.compressedSize);
396
+ if (entry.method === consts.STORED) {
397
+ // nothing to do
398
+ } else if (entry.method === consts.DEFLATED) {
399
+ entryStream = entryStream.pipe(zlib.createInflateRaw());
400
+ } else {
401
+ return callback(new Error('Unknown compression method: ' + entry.method));
402
+ }
403
+ if (canVerifyCrc(entry)) {
404
+ entryStream = entryStream.pipe(
405
+ new EntryVerifyStream(entryStream, entry.crc, entry.size)
406
+ );
407
+ }
408
+ callback(null, entryStream);
409
+ },
410
+ false
411
+ );
399
412
  };
400
413
 
401
- this.entryDataSync = function(entry) {
402
- var err = null;
403
- this.openEntry(entry, function(e, en) {
404
- err = e;
405
- entry = en;
406
- }, true);
407
- if (err)
414
+ this.entryDataSync = function (entry) {
415
+ let err = null;
416
+ this.openEntry(
417
+ entry,
418
+ (e, en) => {
419
+ err = e;
420
+ entry = en;
421
+ },
422
+ true
423
+ );
424
+ if (err) {
408
425
  throw err;
409
- var
410
- data = Buffer.alloc(entry.compressedSize),
411
- bytesRead;
412
- new FsRead(fd, data, 0, entry.compressedSize, dataOffset(entry), function(e, br) {
426
+ }
427
+ let data = Buffer.alloc(entry.compressedSize);
428
+ new FsRead(fd, data, 0, entry.compressedSize, dataOffset(entry), (e) => {
413
429
  err = e;
414
- bytesRead = br;
415
430
  }).read(true);
416
- if (err)
431
+ if (err) {
417
432
  throw err;
433
+ }
418
434
  if (entry.method === consts.STORED) {
435
+ // nothing to do
419
436
  } else if (entry.method === consts.DEFLATED || entry.method === consts.ENHANCED_DEFLATED) {
420
437
  data = zlib.inflateRawSync(data);
421
438
  } else {
422
439
  throw new Error('Unknown compression method: ' + entry.method);
423
440
  }
424
- if (data.length !== entry.size)
441
+ if (data.length !== entry.size) {
425
442
  throw new Error('Invalid size');
443
+ }
426
444
  if (canVerifyCrc(entry)) {
427
- var verify = new CrcVerify(entry.crc, entry.size);
445
+ const verify = new CrcVerify(entry.crc, entry.size);
428
446
  verify.data(data);
429
447
  }
430
448
  return data;
431
449
  };
432
450
 
433
- this.openEntry = function(entry, callback, sync) {
451
+ this.openEntry = function (entry, callback, sync) {
434
452
  if (typeof entry === 'string') {
435
453
  checkEntriesExist();
436
454
  entry = entries[entry];
437
- if (!entry)
438
- return callback('Entry not found');
455
+ if (!entry) {
456
+ return callback(new Error('Entry not found'));
457
+ }
458
+ }
459
+ if (!entry.isFile) {
460
+ return callback(new Error('Entry is not file'));
461
+ }
462
+ if (!fd) {
463
+ return callback(new Error('Archive closed'));
439
464
  }
440
- if (!entry.isFile)
441
- return callback('Entry is not file');
442
- if (!fd)
443
- return callback('Archive closed');
444
- var buffer = Buffer.alloc(consts.LOCHDR);
445
- new FsRead(fd, buffer, 0, buffer.length, entry.offset, function(err) {
446
- if (err)
465
+ const buffer = Buffer.alloc(consts.LOCHDR);
466
+ new FsRead(fd, buffer, 0, buffer.length, entry.offset, (err) => {
467
+ if (err) {
447
468
  return callback(err);
448
- var readEx;
469
+ }
470
+ let readEx;
449
471
  try {
450
472
  entry.readDataHeader(buffer);
451
473
  if (entry.encrypted) {
452
- readEx = 'Entry encrypted';
474
+ readEx = new Error('Entry encrypted');
453
475
  }
454
476
  } catch (ex) {
455
- readEx = ex
477
+ readEx = ex;
456
478
  }
457
479
  callback(readEx, entry);
458
480
  }).read(sync);
@@ -464,38 +486,40 @@ var StreamZip = function(config) {
464
486
 
465
487
  function canVerifyCrc(entry) {
466
488
  // if bit 3 (0x08) of the general-purpose flags field is set, then the CRC-32 and file sizes are not known when the header is written
467
- return (entry.flags & 0x8) != 0x8;
489
+ return (entry.flags & 0x8) !== 0x8;
468
490
  }
469
491
 
470
492
  function extract(entry, outPath, callback) {
471
- that.stream(entry, function (err, stm) {
493
+ that.stream(entry, (err, stm) => {
472
494
  if (err) {
473
495
  callback(err);
474
496
  } else {
475
- var fsStm, errThrown;
476
- stm.on('error', function(err) {
497
+ let fsStm, errThrown;
498
+ stm.on('error', (err) => {
477
499
  errThrown = err;
478
500
  if (fsStm) {
479
501
  stm.unpipe(fsStm);
480
- fsStm.close(function () {
502
+ fsStm.close(() => {
481
503
  callback(err);
482
504
  });
483
505
  }
484
506
  });
485
- fs.open(outPath, 'w', function(err, fdFile) {
486
- if (err)
487
- return callback(err || errThrown);
507
+ fs.open(outPath, 'w', (err, fdFile) => {
508
+ if (err) {
509
+ return callback(err);
510
+ }
488
511
  if (errThrown) {
489
- fs.close(fd, function() {
512
+ fs.close(fd, () => {
490
513
  callback(errThrown);
491
514
  });
492
515
  return;
493
516
  }
494
517
  fsStm = fs.createWriteStream(outPath, { fd: fdFile });
495
- fsStm.on('finish', function() {
518
+ fsStm.on('finish', () => {
496
519
  that.emit('extract', entry, outPath);
497
- if (!errThrown)
520
+ if (!errThrown) {
498
521
  callback();
522
+ }
499
523
  });
500
524
  stm.pipe(fsStm);
501
525
  });
@@ -504,58 +528,71 @@ var StreamZip = function(config) {
504
528
  }
505
529
 
506
530
  function createDirectories(baseDir, dirs, callback) {
507
- if (!dirs.length)
531
+ if (!dirs.length) {
508
532
  return callback();
509
- var dir = dirs.shift();
510
- dir = path.join(baseDir, path.join.apply(path, dir));
511
- fs.mkdir(dir, function(err) {
512
- if (err && err.code !== 'EEXIST')
533
+ }
534
+ let dir = dirs.shift();
535
+ dir = path.join(baseDir, path.join(...dir));
536
+ fs.mkdir(dir, (err) => {
537
+ if (err && err.code !== 'EEXIST') {
513
538
  return callback(err);
539
+ }
514
540
  createDirectories(baseDir, dirs, callback);
515
541
  });
516
542
  }
517
543
 
518
544
  function extractFiles(baseDir, baseRelPath, files, callback, extractedCount) {
519
- if (!files.length)
545
+ if (!files.length) {
520
546
  return callback(null, extractedCount);
521
- var file = files.shift();
522
- var targetPath = path.join(baseDir, file.name.replace(baseRelPath, ''));
523
- extract(file, targetPath, function (err) {
524
- if (err)
547
+ }
548
+ const file = files.shift();
549
+ const targetPath = path.join(baseDir, file.name.replace(baseRelPath, ''));
550
+ extract(file, targetPath, (err) => {
551
+ if (err) {
525
552
  return callback(err, extractedCount);
553
+ }
526
554
  extractFiles(baseDir, baseRelPath, files, callback, extractedCount + 1);
527
555
  });
528
556
  }
529
557
 
530
- this.extract = function(entry, outPath, callback) {
531
- var entryName = entry || '';
558
+ this.extract = function (entry, outPath, callback) {
559
+ let entryName = entry || '';
532
560
  if (typeof entry === 'string') {
533
561
  entry = this.entry(entry);
534
562
  if (entry) {
535
563
  entryName = entry.name;
536
564
  } else {
537
- if (entryName.length && entryName[entryName.length - 1] !== '/')
565
+ if (entryName.length && entryName[entryName.length - 1] !== '/') {
538
566
  entryName += '/';
567
+ }
539
568
  }
540
569
  }
541
570
  if (!entry || entry.isDirectory) {
542
- var files = [], dirs = [], allDirs = {};
543
- for (var e in entries) {
544
- if (Object.prototype.hasOwnProperty.call(entries, e) && e.lastIndexOf(entryName, 0) === 0) {
545
- var relPath = e.replace(entryName, '');
546
- var childEntry = entries[e];
571
+ const files = [],
572
+ dirs = [],
573
+ allDirs = {};
574
+ for (const e in entries) {
575
+ if (
576
+ Object.prototype.hasOwnProperty.call(entries, e) &&
577
+ e.lastIndexOf(entryName, 0) === 0
578
+ ) {
579
+ let relPath = e.replace(entryName, '');
580
+ const childEntry = entries[e];
547
581
  if (childEntry.isFile) {
548
582
  files.push(childEntry);
549
583
  relPath = path.dirname(relPath);
550
584
  }
551
585
  if (relPath && !allDirs[relPath] && relPath !== '.') {
552
586
  allDirs[relPath] = true;
553
- var parts = relPath.split('/').filter(function (f) { return f; });
554
- if (parts.length)
587
+ let parts = relPath.split('/').filter((f) => {
588
+ return f;
589
+ });
590
+ if (parts.length) {
555
591
  dirs.push(parts);
592
+ }
556
593
  while (parts.length > 1) {
557
594
  parts = parts.slice(0, parts.length - 1);
558
- var partsPath = parts.join('/');
595
+ const partsPath = parts.join('/');
559
596
  if (allDirs[partsPath] || partsPath === '.') {
560
597
  break;
561
598
  }
@@ -565,362 +602,448 @@ var StreamZip = function(config) {
565
602
  }
566
603
  }
567
604
  }
568
- dirs.sort(function(x, y) { return x.length - y.length; });
605
+ dirs.sort((x, y) => {
606
+ return x.length - y.length;
607
+ });
569
608
  if (dirs.length) {
570
- createDirectories(outPath, dirs, function (err) {
571
- if (err)
609
+ createDirectories(outPath, dirs, (err) => {
610
+ if (err) {
572
611
  callback(err);
573
- else
612
+ } else {
574
613
  extractFiles(outPath, entryName, files, callback, 0);
614
+ }
575
615
  });
576
616
  } else {
577
617
  extractFiles(outPath, entryName, files, callback, 0);
578
618
  }
579
619
  } else {
580
- fs.stat(outPath, function(err, stat) {
581
- if (stat && stat.isDirectory())
620
+ fs.stat(outPath, (err, stat) => {
621
+ if (stat && stat.isDirectory()) {
582
622
  extract(entry, path.join(outPath, path.basename(entry.name)), callback);
583
- else
623
+ } else {
584
624
  extract(entry, outPath, callback);
625
+ }
585
626
  });
586
627
  }
587
628
  };
588
629
 
589
- this.close = function(callback) {
630
+ this.close = function (callback) {
590
631
  if (closed || !fd) {
591
632
  closed = true;
592
- if (callback)
633
+ if (callback) {
593
634
  callback();
635
+ }
594
636
  } else {
595
637
  closed = true;
596
- fs.close(fd, function(err) {
638
+ fs.close(fd, (err) => {
597
639
  fd = null;
598
- if (callback)
640
+ if (callback) {
599
641
  callback(err);
642
+ }
600
643
  });
601
644
  }
602
645
  };
603
646
 
604
- var originalEmit = events.EventEmitter.prototype.emit;
605
- this.emit = function() {
647
+ const originalEmit = events.EventEmitter.prototype.emit;
648
+ this.emit = function (...args) {
606
649
  if (!closed) {
607
- return originalEmit.apply(this, arguments);
650
+ return originalEmit.call(this, ...args);
608
651
  }
609
652
  };
610
653
  };
611
654
 
612
- StreamZip.setFs = function(customFs) {
655
+ StreamZip.setFs = function (customFs) {
613
656
  fs = customFs;
614
657
  };
615
658
 
659
+ StreamZip.debugLog = (...args) => {
660
+ if (StreamZip.debug) {
661
+ // eslint-disable-next-line no-console
662
+ console.log(...args);
663
+ }
664
+ };
665
+
616
666
  util.inherits(StreamZip, events.EventEmitter);
617
667
 
618
- // endregion
668
+ const propZip = Symbol('zip');
619
669
 
620
- // region CentralDirectoryHeader
670
+ StreamZip.async = class StreamZipAsync extends events.EventEmitter {
671
+ constructor(config) {
672
+ super();
621
673
 
622
- var CentralDirectoryHeader = function() {
623
- };
674
+ const zip = new StreamZip(config);
624
675
 
625
- CentralDirectoryHeader.prototype.read = function(data) {
626
- if (data.length != consts.ENDHDR || data.readUInt32LE(0) != consts.ENDSIG)
627
- throw new Error('Invalid central directory');
628
- // number of entries on this volume
629
- this.volumeEntries = data.readUInt16LE(consts.ENDSUB);
630
- // total number of entries
631
- this.totalEntries = data.readUInt16LE(consts.ENDTOT);
632
- // central directory size in bytes
633
- this.size = data.readUInt32LE(consts.ENDSIZ);
634
- // offset of first CEN header
635
- this.offset = data.readUInt32LE(consts.ENDOFF);
636
- // zip file comment length
637
- this.commentLength = data.readUInt16LE(consts.ENDCOM);
638
- };
676
+ zip.on('entry', (entry) => this.emit('entry', entry));
677
+ zip.on('extract', (entry, outPath) => this.emit('extract', entry, outPath));
639
678
 
640
- // endregion
641
-
642
- // region CentralDirectoryLoc64Header
643
-
644
- var CentralDirectoryLoc64Header = function() {
645
- };
679
+ this[propZip] = new Promise((resolve, reject) => {
680
+ zip.on('ready', () => {
681
+ zip.off('error', reject);
682
+ resolve(zip);
683
+ });
684
+ zip.on('error', reject);
685
+ });
686
+ }
646
687
 
647
- CentralDirectoryLoc64Header.prototype.read = function(data) {
648
- if (data.length != consts.ENDL64HDR || data.readUInt32LE(0) != consts.ENDL64SIG)
649
- throw new Error('Invalid zip64 central directory locator');
650
- // ZIP64 EOCD header offset
651
- this.headerOffset = Util.readUInt64LE(data, consts.ENDSUB);
652
- };
688
+ get entriesCount() {
689
+ return this[propZip].then((zip) => zip.entriesCount);
690
+ }
653
691
 
654
- // endregion
692
+ get comment() {
693
+ return this[propZip].then((zip) => zip.comment);
694
+ }
655
695
 
656
- // region CentralDirectoryZip64Header
696
+ async entry(name) {
697
+ const zip = await this[propZip];
698
+ return zip.entry(name);
699
+ }
657
700
 
658
- var CentralDirectoryZip64Header = function() {
659
- };
701
+ async entries() {
702
+ const zip = await this[propZip];
703
+ return zip.entries();
704
+ }
660
705
 
661
- CentralDirectoryZip64Header.prototype.read = function(data) {
662
- if (data.length != consts.END64HDR || data.readUInt32LE(0) != consts.END64SIG)
663
- throw new Error('Invalid central directory');
664
- // number of entries on this volume
665
- this.volumeEntries = Util.readUInt64LE(data, consts.END64SUB);
666
- // total number of entries
667
- this.totalEntries = Util.readUInt64LE(data, consts.END64TOT);
668
- // central directory size in bytes
669
- this.size = Util.readUInt64LE(data, consts.END64SIZ);
670
- // offset of first CEN header
671
- this.offset = Util.readUInt64LE(data, consts.END64OFF);
672
- };
706
+ async stream(entry) {
707
+ const zip = await this[propZip];
708
+ return new Promise((resolve, reject) => {
709
+ zip.stream(entry, (err, stm) => {
710
+ if (err) {
711
+ reject(err);
712
+ } else {
713
+ resolve(stm);
714
+ }
715
+ });
716
+ });
717
+ }
673
718
 
674
- // endregion
719
+ async entryData(entry) {
720
+ const stm = await this.stream(entry);
721
+ return new Promise((resolve, reject) => {
722
+ const data = [];
723
+ stm.on('data', (chunk) => data.push(chunk));
724
+ stm.on('end', () => {
725
+ resolve(Buffer.concat(data));
726
+ });
727
+ stm.on('error', (err) => {
728
+ stm.removeAllListeners('end');
729
+ reject(err);
730
+ });
731
+ });
732
+ }
675
733
 
676
- // region ZipEntry
734
+ async extract(entry, outPath) {
735
+ const zip = await this[propZip];
736
+ return new Promise((resolve, reject) => {
737
+ zip.extract(entry, outPath, (err, res) => {
738
+ if (err) {
739
+ reject(err);
740
+ } else {
741
+ resolve(res);
742
+ }
743
+ });
744
+ });
745
+ }
677
746
 
678
- var ZipEntry = function() {
747
+ async close() {
748
+ const zip = await this[propZip];
749
+ return new Promise((resolve, reject) => {
750
+ zip.close((err) => {
751
+ if (err) {
752
+ reject(err);
753
+ } else {
754
+ resolve();
755
+ }
756
+ });
757
+ });
758
+ }
679
759
  };
680
760
 
681
- function toBits(dec, size) {
682
- var b = (dec >>> 0).toString(2);
683
- while (b.length < size)
684
- b = '0' + b;
685
- return b.split('');
761
+ class CentralDirectoryHeader {
762
+ read(data) {
763
+ if (data.length !== consts.ENDHDR || data.readUInt32LE(0) !== consts.ENDSIG) {
764
+ throw new Error('Invalid central directory');
765
+ }
766
+ // number of entries on this volume
767
+ this.volumeEntries = data.readUInt16LE(consts.ENDSUB);
768
+ // total number of entries
769
+ this.totalEntries = data.readUInt16LE(consts.ENDTOT);
770
+ // central directory size in bytes
771
+ this.size = data.readUInt32LE(consts.ENDSIZ);
772
+ // offset of first CEN header
773
+ this.offset = data.readUInt32LE(consts.ENDOFF);
774
+ // zip file comment length
775
+ this.commentLength = data.readUInt16LE(consts.ENDCOM);
776
+ }
686
777
  }
687
778
 
688
- function parseZipTime(timebytes, datebytes) {
689
- var timebits = toBits(timebytes, 16);
690
- var datebits = toBits(datebytes, 16);
691
-
692
- var mt = {
693
- h: parseInt(timebits.slice(0,5).join(''), 2),
694
- m: parseInt(timebits.slice(5,11).join(''), 2),
695
- s: parseInt(timebits.slice(11,16).join(''), 2) * 2,
696
- Y: parseInt(datebits.slice(0,7).join(''), 2) + 1980,
697
- M: parseInt(datebits.slice(7,11).join(''), 2),
698
- D: parseInt(datebits.slice(11,16).join(''), 2),
699
- };
700
- var dt_str = [mt.Y, mt.M, mt.D].join('-') + ' ' + [mt.h, mt.m, mt.s].join(':') + ' GMT+0';
701
- return new Date(dt_str).getTime();
779
+ class CentralDirectoryLoc64Header {
780
+ read(data) {
781
+ if (data.length !== consts.ENDL64HDR || data.readUInt32LE(0) !== consts.ENDL64SIG) {
782
+ throw new Error('Invalid zip64 central directory locator');
783
+ }
784
+ // ZIP64 EOCD header offset
785
+ this.headerOffset = readUInt64LE(data, consts.ENDSUB);
786
+ }
702
787
  }
703
788
 
704
- ZipEntry.prototype.readHeader = function(data, offset) {
705
- // data should be 46 bytes and start with "PK 01 02"
706
- if (data.length < offset + consts.CENHDR || data.readUInt32LE(offset) != consts.CENSIG) {
707
- throw new Error('Invalid entry header');
789
+ class CentralDirectoryZip64Header {
790
+ read(data) {
791
+ if (data.length !== consts.END64HDR || data.readUInt32LE(0) !== consts.END64SIG) {
792
+ throw new Error('Invalid central directory');
793
+ }
794
+ // number of entries on this volume
795
+ this.volumeEntries = readUInt64LE(data, consts.END64SUB);
796
+ // total number of entries
797
+ this.totalEntries = readUInt64LE(data, consts.END64TOT);
798
+ // central directory size in bytes
799
+ this.size = readUInt64LE(data, consts.END64SIZ);
800
+ // offset of first CEN header
801
+ this.offset = readUInt64LE(data, consts.END64OFF);
708
802
  }
709
- // version made by
710
- this.verMade = data.readUInt16LE(offset + consts.CENVEM);
711
- // version needed to extract
712
- this.version = data.readUInt16LE(offset + consts.CENVER);
713
- // encrypt, decrypt flags
714
- this.flags = data.readUInt16LE(offset + consts.CENFLG);
715
- // compression method
716
- this.method = data.readUInt16LE(offset + consts.CENHOW);
717
- // modification time (2 bytes time, 2 bytes date)
718
- var timebytes = data.readUInt16LE(offset + consts.CENTIM);
719
- var datebytes = data.readUInt16LE(offset + consts.CENTIM + 2);
720
- this.time = parseZipTime(timebytes, datebytes);
721
-
722
- // uncompressed file crc-32 value
723
- this.crc = data.readUInt32LE(offset + consts.CENCRC);
724
- // compressed size
725
- this.compressedSize = data.readUInt32LE(offset + consts.CENSIZ);
726
- // uncompressed size
727
- this.size = data.readUInt32LE(offset + consts.CENLEN);
728
- // filename length
729
- this.fnameLen = data.readUInt16LE(offset + consts.CENNAM);
730
- // extra field length
731
- this.extraLen = data.readUInt16LE(offset + consts.CENEXT);
732
- // file comment length
733
- this.comLen = data.readUInt16LE(offset + consts.CENCOM);
734
- // volume number start
735
- this.diskStart = data.readUInt16LE(offset + consts.CENDSK);
736
- // internal file attributes
737
- this.inattr = data.readUInt16LE(offset + consts.CENATT);
738
- // external file attributes
739
- this.attr = data.readUInt32LE(offset + consts.CENATX);
740
- // LOC header offset
741
- this.offset = data.readUInt32LE(offset + consts.CENOFF);
742
- };
803
+ }
743
804
 
744
- ZipEntry.prototype.readDataHeader = function(data) {
745
- // 30 bytes and should start with "PK\003\004"
746
- if (data.readUInt32LE(0) != consts.LOCSIG) {
747
- throw new Error('Invalid local header');
748
- }
749
- // version needed to extract
750
- this.version = data.readUInt16LE(consts.LOCVER);
751
- // general purpose bit flag
752
- this.flags = data.readUInt16LE(consts.LOCFLG);
753
- // compression method
754
- this.method = data.readUInt16LE(consts.LOCHOW);
755
- // modification time (2 bytes time ; 2 bytes date)
756
- var timebytes = data.readUInt16LE(consts.LOCTIM);
757
- var datebytes = data.readUInt16LE(consts.LOCTIM + 2);
758
- this.time = parseZipTime(timebytes, datebytes);
759
-
760
- // uncompressed file crc-32 value
761
- this.crc = data.readUInt32LE(consts.LOCCRC) || this.crc;
762
- // compressed size
763
- var compressedSize = data.readUInt32LE(consts.LOCSIZ);
764
- if (compressedSize && compressedSize !== consts.EF_ZIP64_OR_32) {
765
- this.compressedSize = compressedSize;
805
+ class ZipEntry {
806
+ readHeader(data, offset) {
807
+ // data should be 46 bytes and start with "PK 01 02"
808
+ if (data.length < offset + consts.CENHDR || data.readUInt32LE(offset) !== consts.CENSIG) {
809
+ throw new Error('Invalid entry header');
810
+ }
811
+ // version made by
812
+ this.verMade = data.readUInt16LE(offset + consts.CENVEM);
813
+ // version needed to extract
814
+ this.version = data.readUInt16LE(offset + consts.CENVER);
815
+ // encrypt, decrypt flags
816
+ this.flags = data.readUInt16LE(offset + consts.CENFLG);
817
+ // compression method
818
+ this.method = data.readUInt16LE(offset + consts.CENHOW);
819
+ // modification time (2 bytes time, 2 bytes date)
820
+ const timebytes = data.readUInt16LE(offset + consts.CENTIM);
821
+ const datebytes = data.readUInt16LE(offset + consts.CENTIM + 2);
822
+ this.time = parseZipTime(timebytes, datebytes);
823
+
824
+ // uncompressed file crc-32 value
825
+ this.crc = data.readUInt32LE(offset + consts.CENCRC);
826
+ // compressed size
827
+ this.compressedSize = data.readUInt32LE(offset + consts.CENSIZ);
828
+ // uncompressed size
829
+ this.size = data.readUInt32LE(offset + consts.CENLEN);
830
+ // filename length
831
+ this.fnameLen = data.readUInt16LE(offset + consts.CENNAM);
832
+ // extra field length
833
+ this.extraLen = data.readUInt16LE(offset + consts.CENEXT);
834
+ // file comment length
835
+ this.comLen = data.readUInt16LE(offset + consts.CENCOM);
836
+ // volume number start
837
+ this.diskStart = data.readUInt16LE(offset + consts.CENDSK);
838
+ // internal file attributes
839
+ this.inattr = data.readUInt16LE(offset + consts.CENATT);
840
+ // external file attributes
841
+ this.attr = data.readUInt32LE(offset + consts.CENATX);
842
+ // LOC header offset
843
+ this.offset = data.readUInt32LE(offset + consts.CENOFF);
766
844
  }
767
- // uncompressed size
768
- var size = data.readUInt32LE(consts.LOCLEN);
769
- if (size && size !== consts.EF_ZIP64_OR_32) {
770
- this.size = size;
845
+
846
+ readDataHeader(data) {
847
+ // 30 bytes and should start with "PK\003\004"
848
+ if (data.readUInt32LE(0) !== consts.LOCSIG) {
849
+ throw new Error('Invalid local header');
850
+ }
851
+ // version needed to extract
852
+ this.version = data.readUInt16LE(consts.LOCVER);
853
+ // general purpose bit flag
854
+ this.flags = data.readUInt16LE(consts.LOCFLG);
855
+ // compression method
856
+ this.method = data.readUInt16LE(consts.LOCHOW);
857
+ // modification time (2 bytes time ; 2 bytes date)
858
+ const timebytes = data.readUInt16LE(consts.LOCTIM);
859
+ const datebytes = data.readUInt16LE(consts.LOCTIM + 2);
860
+ this.time = parseZipTime(timebytes, datebytes);
861
+
862
+ // uncompressed file crc-32 value
863
+ this.crc = data.readUInt32LE(consts.LOCCRC) || this.crc;
864
+ // compressed size
865
+ const compressedSize = data.readUInt32LE(consts.LOCSIZ);
866
+ if (compressedSize && compressedSize !== consts.EF_ZIP64_OR_32) {
867
+ this.compressedSize = compressedSize;
868
+ }
869
+ // uncompressed size
870
+ const size = data.readUInt32LE(consts.LOCLEN);
871
+ if (size && size !== consts.EF_ZIP64_OR_32) {
872
+ this.size = size;
873
+ }
874
+ // filename length
875
+ this.fnameLen = data.readUInt16LE(consts.LOCNAM);
876
+ // extra field length
877
+ this.extraLen = data.readUInt16LE(consts.LOCEXT);
771
878
  }
772
- // filename length
773
- this.fnameLen = data.readUInt16LE(consts.LOCNAM);
774
- // extra field length
775
- this.extraLen = data.readUInt16LE(consts.LOCEXT);
776
- };
777
879
 
778
- ZipEntry.prototype.read = function(data, offset) {
779
- this.name = data.slice(offset, offset += this.fnameLen).toString();
780
- var lastChar = data[offset - 1];
781
- this.isDirectory = (lastChar == 47) || (lastChar == 92);
880
+ read(data, offset) {
881
+ this.name = data.slice(offset, (offset += this.fnameLen)).toString();
882
+ const lastChar = data[offset - 1];
883
+ this.isDirectory = lastChar === 47 || lastChar === 92;
782
884
 
783
- if (this.extraLen) {
784
- this.readExtra(data, offset);
785
- offset += this.extraLen;
885
+ if (this.extraLen) {
886
+ this.readExtra(data, offset);
887
+ offset += this.extraLen;
888
+ }
889
+ this.comment = this.comLen ? data.slice(offset, offset + this.comLen).toString() : null;
786
890
  }
787
- this.comment = this.comLen ? data.slice(offset, offset + this.comLen).toString() : null;
788
- };
789
891
 
790
- ZipEntry.prototype.validateName = function() {
791
- if (/\\|^\w+:|^\/|(^|\/)\.\.(\/|$)/.test(this.name)) {
792
- throw new Error('Malicious entry: ' + this.name);
892
+ validateName() {
893
+ if (/\\|^\w+:|^\/|(^|\/)\.\.(\/|$)/.test(this.name)) {
894
+ throw new Error('Malicious entry: ' + this.name);
895
+ }
793
896
  }
794
- };
795
897
 
796
- ZipEntry.prototype.readExtra = function(data, offset) {
797
- var signature, size, maxPos = offset + this.extraLen;
798
- while (offset < maxPos) {
799
- signature = data.readUInt16LE(offset);
800
- offset += 2;
801
- size = data.readUInt16LE(offset);
802
- offset += 2;
803
- if (consts.ID_ZIP64 === signature) {
804
- this.parseZip64Extra(data, offset, size);
898
+ readExtra(data, offset) {
899
+ let signature, size;
900
+ const maxPos = offset + this.extraLen;
901
+ while (offset < maxPos) {
902
+ signature = data.readUInt16LE(offset);
903
+ offset += 2;
904
+ size = data.readUInt16LE(offset);
905
+ offset += 2;
906
+ if (consts.ID_ZIP64 === signature) {
907
+ this.parseZip64Extra(data, offset, size);
908
+ }
909
+ offset += size;
805
910
  }
806
- offset += size;
807
911
  }
808
- };
809
912
 
810
- ZipEntry.prototype.parseZip64Extra = function(data, offset, length) {
811
- if (length >= 8 && this.size === consts.EF_ZIP64_OR_32) {
812
- this.size = Util.readUInt64LE(data, offset);
813
- offset += 8; length -= 8;
814
- }
815
- if (length >= 8 && this.compressedSize === consts.EF_ZIP64_OR_32) {
816
- this.compressedSize = Util.readUInt64LE(data, offset);
817
- offset += 8; length -= 8;
818
- }
819
- if (length >= 8 && this.offset === consts.EF_ZIP64_OR_32) {
820
- this.offset = Util.readUInt64LE(data, offset);
821
- offset += 8; length -= 8;
822
- }
823
- if (length >= 4 && this.diskStart === consts.EF_ZIP64_OR_16) {
824
- this.diskStart = data.readUInt32LE(offset);
825
- // offset += 4; length -= 4;
913
+ parseZip64Extra(data, offset, length) {
914
+ if (length >= 8 && this.size === consts.EF_ZIP64_OR_32) {
915
+ this.size = readUInt64LE(data, offset);
916
+ offset += 8;
917
+ length -= 8;
918
+ }
919
+ if (length >= 8 && this.compressedSize === consts.EF_ZIP64_OR_32) {
920
+ this.compressedSize = readUInt64LE(data, offset);
921
+ offset += 8;
922
+ length -= 8;
923
+ }
924
+ if (length >= 8 && this.offset === consts.EF_ZIP64_OR_32) {
925
+ this.offset = readUInt64LE(data, offset);
926
+ offset += 8;
927
+ length -= 8;
928
+ }
929
+ if (length >= 4 && this.diskStart === consts.EF_ZIP64_OR_16) {
930
+ this.diskStart = data.readUInt32LE(offset);
931
+ // offset += 4; length -= 4;
932
+ }
826
933
  }
827
- };
828
-
829
- Object.defineProperty(ZipEntry.prototype, 'encrypted', {
830
- get: function() { return (this.flags & consts.FLG_ENTRY_ENC) == consts.FLG_ENTRY_ENC; }
831
- });
832
-
833
- Object.defineProperty(ZipEntry.prototype, 'isFile', {
834
- get: function() { return !this.isDirectory; }
835
- });
836
-
837
- // endregion
838
-
839
- // region FsRead
840
934
 
841
- var FsRead = function(fd, buffer, offset, length, position, callback) {
842
- this.fd = fd;
843
- this.buffer = buffer;
844
- this.offset = offset;
845
- this.length = length;
846
- this.position = position;
847
- this.callback = callback;
848
- this.bytesRead = 0;
849
- this.waiting = false;
850
- };
851
-
852
- FsRead.prototype.read = function(sync) {
853
- if (StreamZip.debug) {
854
- console.log('read', this.position, this.bytesRead, this.length, this.offset);
935
+ get encrypted() {
936
+ return (this.flags & consts.FLG_ENTRY_ENC) === consts.FLG_ENTRY_ENC;
855
937
  }
856
- this.waiting = true;
857
- var err;
858
- if (sync) {
859
- try {
860
- var bytesRead = fs.readSync(this.fd, this.buffer, this.offset + this.bytesRead,
861
- this.length - this.bytesRead, this.position + this.bytesRead);
862
- } catch (e) {
863
- err = e;
864
- }
865
- this.readCallback(sync, err, err ? bytesRead : null);
866
- } else {
867
- fs.read(this.fd, this.buffer, this.offset + this.bytesRead,
868
- this.length - this.bytesRead, this.position + this.bytesRead,
869
- this.readCallback.bind(this, sync));
938
+
939
+ get isFile() {
940
+ return !this.isDirectory;
870
941
  }
871
- };
942
+ }
872
943
 
873
- FsRead.prototype.readCallback = function(sync, err, bytesRead) {
874
- if (typeof bytesRead === 'number')
875
- this.bytesRead += bytesRead;
876
- if (err || !bytesRead || this.bytesRead === this.length) {
944
+ class FsRead {
945
+ constructor(fd, buffer, offset, length, position, callback) {
946
+ this.fd = fd;
947
+ this.buffer = buffer;
948
+ this.offset = offset;
949
+ this.length = length;
950
+ this.position = position;
951
+ this.callback = callback;
952
+ this.bytesRead = 0;
877
953
  this.waiting = false;
878
- return this.callback(err, this.bytesRead);
879
- } else {
880
- this.read(sync);
881
954
  }
882
- };
883
955
 
884
- // endregion
885
-
886
- // region FileWindowBuffer
956
+ read(sync) {
957
+ StreamZip.debugLog('read', this.position, this.bytesRead, this.length, this.offset);
958
+ this.waiting = true;
959
+ let err;
960
+ if (sync) {
961
+ let bytesRead = 0;
962
+ try {
963
+ bytesRead = fs.readSync(
964
+ this.fd,
965
+ this.buffer,
966
+ this.offset + this.bytesRead,
967
+ this.length - this.bytesRead,
968
+ this.position + this.bytesRead
969
+ );
970
+ } catch (e) {
971
+ err = e;
972
+ }
973
+ this.readCallback(sync, err, err ? bytesRead : null);
974
+ } else {
975
+ fs.read(
976
+ this.fd,
977
+ this.buffer,
978
+ this.offset + this.bytesRead,
979
+ this.length - this.bytesRead,
980
+ this.position + this.bytesRead,
981
+ this.readCallback.bind(this, sync)
982
+ );
983
+ }
984
+ }
887
985
 
888
- var FileWindowBuffer = function(fd) {
889
- this.position = 0;
890
- this.buffer = Buffer.alloc(0);
986
+ readCallback(sync, err, bytesRead) {
987
+ if (typeof bytesRead === 'number') {
988
+ this.bytesRead += bytesRead;
989
+ }
990
+ if (err || !bytesRead || this.bytesRead === this.length) {
991
+ this.waiting = false;
992
+ return this.callback(err, this.bytesRead);
993
+ } else {
994
+ this.read(sync);
995
+ }
996
+ }
997
+ }
891
998
 
892
- var fsOp = null;
999
+ class FileWindowBuffer {
1000
+ constructor(fd) {
1001
+ this.position = 0;
1002
+ this.buffer = Buffer.alloc(0);
1003
+ this.fd = fd;
1004
+ this.fsOp = null;
1005
+ }
893
1006
 
894
- this.checkOp = function() {
895
- if (fsOp && fsOp.waiting)
1007
+ checkOp() {
1008
+ if (this.fsOp && this.fsOp.waiting) {
896
1009
  throw new Error('Operation in progress');
897
- };
1010
+ }
1011
+ }
898
1012
 
899
- this.read = function(pos, length, callback) {
1013
+ read(pos, length, callback) {
900
1014
  this.checkOp();
901
- if (this.buffer.length < length)
1015
+ if (this.buffer.length < length) {
902
1016
  this.buffer = Buffer.alloc(length);
1017
+ }
903
1018
  this.position = pos;
904
- fsOp = new FsRead(fd, this.buffer, 0, length, this.position, callback).read();
905
- };
1019
+ this.fsOp = new FsRead(this.fd, this.buffer, 0, length, this.position, callback).read();
1020
+ }
906
1021
 
907
- this.expandLeft = function(length, callback) {
1022
+ expandLeft(length, callback) {
908
1023
  this.checkOp();
909
1024
  this.buffer = Buffer.concat([Buffer.alloc(length), this.buffer]);
910
1025
  this.position -= length;
911
- if (this.position < 0)
1026
+ if (this.position < 0) {
912
1027
  this.position = 0;
913
- fsOp = new FsRead(fd, this.buffer, 0, length, this.position, callback).read();
914
- };
1028
+ }
1029
+ this.fsOp = new FsRead(this.fd, this.buffer, 0, length, this.position, callback).read();
1030
+ }
915
1031
 
916
- this.expandRight = function(length, callback) {
1032
+ expandRight(length, callback) {
917
1033
  this.checkOp();
918
- var offset = this.buffer.length;
1034
+ const offset = this.buffer.length;
919
1035
  this.buffer = Buffer.concat([this.buffer, Buffer.alloc(length)]);
920
- fsOp = new FsRead(fd, this.buffer, offset, length, this.position + offset, callback).read();
921
- };
1036
+ this.fsOp = new FsRead(
1037
+ this.fd,
1038
+ this.buffer,
1039
+ offset,
1040
+ length,
1041
+ this.position + offset,
1042
+ callback
1043
+ ).read();
1044
+ }
922
1045
 
923
- this.moveRight = function(length, callback, shift) {
1046
+ moveRight(length, callback, shift) {
924
1047
  this.checkOp();
925
1048
  if (shift) {
926
1049
  this.buffer.copy(this.buffer, 0, shift);
@@ -928,137 +1051,156 @@ var FileWindowBuffer = function(fd) {
928
1051
  shift = 0;
929
1052
  }
930
1053
  this.position += shift;
931
- fsOp = new FsRead(fd, this.buffer, this.buffer.length - shift, shift, this.position + this.buffer.length - shift, callback).read();
932
- };
933
- };
934
-
935
- // endregion
936
-
937
- // region EntryDataReaderStream
938
-
939
- var EntryDataReaderStream = function(fd, offset, length) {
940
- stream.Readable.prototype.constructor.call(this);
941
- this.fd = fd;
942
- this.offset = offset;
943
- this.length = length;
944
- this.pos = 0;
945
- this.readCallback = this.readCallback.bind(this);
946
- };
947
-
948
- util.inherits(EntryDataReaderStream, stream.Readable);
949
-
950
- EntryDataReaderStream.prototype._read = function(n) {
951
- var buffer = Buffer.alloc(Math.min(n, this.length - this.pos));
952
- if (buffer.length) {
953
- fs.read(this.fd, buffer, 0, buffer.length, this.offset + this.pos, this.readCallback);
954
- } else {
955
- this.push(null);
1054
+ this.fsOp = new FsRead(
1055
+ this.fd,
1056
+ this.buffer,
1057
+ this.buffer.length - shift,
1058
+ shift,
1059
+ this.position + this.buffer.length - shift,
1060
+ callback
1061
+ ).read();
956
1062
  }
957
- };
1063
+ }
958
1064
 
959
- EntryDataReaderStream.prototype.readCallback = function(err, bytesRead, buffer) {
960
- this.pos += bytesRead;
961
- if (err) {
962
- this.emit('error', err);
963
- this.push(null);
964
- } else if (!bytesRead) {
965
- this.push(null);
966
- } else {
967
- if (bytesRead !== buffer.length)
968
- buffer = buffer.slice(0, bytesRead);
969
- this.push(buffer);
1065
+ class EntryDataReaderStream extends stream.Readable {
1066
+ constructor(fd, offset, length) {
1067
+ super();
1068
+ this.fd = fd;
1069
+ this.offset = offset;
1070
+ this.length = length;
1071
+ this.pos = 0;
1072
+ this.readCallback = this.readCallback.bind(this);
970
1073
  }
971
- };
972
-
973
- // endregion
974
-
975
- // region EntryVerifyStream
976
-
977
- var EntryVerifyStream = function(baseStm, crc, size) {
978
- stream.Transform.prototype.constructor.call(this);
979
- this.verify = new CrcVerify(crc, size);
980
- var that = this;
981
- baseStm.on('error', function(e) {
982
- that.emit('error', e);
983
- });
984
- };
985
1074
 
986
- util.inherits(EntryVerifyStream, stream.Transform);
987
-
988
- EntryVerifyStream.prototype._transform = function(data, encoding, callback) {
989
- var err;
990
- try {
991
- this.verify.data(data);
992
- } catch (e) {
993
- err = e;
1075
+ _read(n) {
1076
+ const buffer = Buffer.alloc(Math.min(n, this.length - this.pos));
1077
+ if (buffer.length) {
1078
+ fs.read(this.fd, buffer, 0, buffer.length, this.offset + this.pos, this.readCallback);
1079
+ } else {
1080
+ this.push(null);
1081
+ }
994
1082
  }
995
- callback(err, data);
996
- };
997
1083
 
998
- // endregion
1084
+ readCallback(err, bytesRead, buffer) {
1085
+ this.pos += bytesRead;
1086
+ if (err) {
1087
+ this.emit('error', err);
1088
+ this.push(null);
1089
+ } else if (!bytesRead) {
1090
+ this.push(null);
1091
+ } else {
1092
+ if (bytesRead !== buffer.length) {
1093
+ buffer = buffer.slice(0, bytesRead);
1094
+ }
1095
+ this.push(buffer);
1096
+ }
1097
+ }
1098
+ }
999
1099
 
1000
- // region CrcVerify
1100
+ class EntryVerifyStream extends stream.Transform {
1101
+ constructor(baseStm, crc, size) {
1102
+ super();
1103
+ this.verify = new CrcVerify(crc, size);
1104
+ baseStm.on('error', (e) => {
1105
+ this.emit('error', e);
1106
+ });
1107
+ }
1001
1108
 
1002
- var CrcVerify = function(crc, size) {
1003
- this.crc = crc;
1004
- this.size = size;
1005
- this.state = {
1006
- crc: ~0,
1007
- size: 0
1008
- };
1009
- };
1109
+ _transform(data, encoding, callback) {
1110
+ let err;
1111
+ try {
1112
+ this.verify.data(data);
1113
+ } catch (e) {
1114
+ err = e;
1115
+ }
1116
+ callback(err, data);
1117
+ }
1118
+ }
1010
1119
 
1011
- CrcVerify.prototype.data = function(data) {
1012
- var crcTable = CrcVerify.getCrcTable();
1013
- var crc = this.state.crc, off = 0, len = data.length;
1014
- while (--len >= 0)
1015
- crc = crcTable[(crc ^ data[off++]) & 0xff] ^ (crc >>> 8);
1016
- this.state.crc = crc;
1017
- this.state.size += data.length;
1018
- if (this.state.size >= this.size) {
1019
- var buf = Buffer.alloc(4);
1020
- buf.writeInt32LE(~this.state.crc & 0xffffffff, 0);
1021
- crc = buf.readUInt32LE(0);
1022
- if (crc !== this.crc)
1023
- throw new Error('Invalid CRC');
1024
- if (this.state.size !== this.size)
1025
- throw new Error('Invalid size');
1120
+ class CrcVerify {
1121
+ constructor(crc, size) {
1122
+ this.crc = crc;
1123
+ this.size = size;
1124
+ this.state = {
1125
+ crc: ~0,
1126
+ size: 0,
1127
+ };
1026
1128
  }
1027
- };
1028
1129
 
1029
- CrcVerify.getCrcTable = function() {
1030
- var crcTable = CrcVerify.crcTable;
1031
- if (!crcTable) {
1032
- CrcVerify.crcTable = crcTable = [];
1033
- var b = Buffer.alloc(4);
1034
- for (var n = 0; n < 256; n++) {
1035
- var c = n;
1036
- for (var k = 8; --k >= 0; )
1037
- if ((c & 1) != 0) { c = 0xedb88320 ^ (c >>> 1); } else { c = c >>> 1; }
1038
- if (c < 0) {
1039
- b.writeInt32LE(c, 0);
1040
- c = b.readUInt32LE(0);
1130
+ data(data) {
1131
+ const crcTable = CrcVerify.getCrcTable();
1132
+ let crc = this.state.crc;
1133
+ let off = 0;
1134
+ let len = data.length;
1135
+ while (--len >= 0) {
1136
+ crc = crcTable[(crc ^ data[off++]) & 0xff] ^ (crc >>> 8);
1137
+ }
1138
+ this.state.crc = crc;
1139
+ this.state.size += data.length;
1140
+ if (this.state.size >= this.size) {
1141
+ const buf = Buffer.alloc(4);
1142
+ buf.writeInt32LE(~this.state.crc & 0xffffffff, 0);
1143
+ crc = buf.readUInt32LE(0);
1144
+ if (crc !== this.crc) {
1145
+ throw new Error('Invalid CRC');
1146
+ }
1147
+ if (this.state.size !== this.size) {
1148
+ throw new Error('Invalid size');
1041
1149
  }
1042
- crcTable[n] = c;
1043
1150
  }
1044
1151
  }
1045
- return crcTable;
1046
- };
1047
1152
 
1048
- // endregion
1153
+ static getCrcTable() {
1154
+ let crcTable = CrcVerify.crcTable;
1155
+ if (!crcTable) {
1156
+ CrcVerify.crcTable = crcTable = [];
1157
+ const b = Buffer.alloc(4);
1158
+ for (let n = 0; n < 256; n++) {
1159
+ let c = n;
1160
+ for (let k = 8; --k >= 0; ) {
1161
+ if ((c & 1) !== 0) {
1162
+ c = 0xedb88320 ^ (c >>> 1);
1163
+ } else {
1164
+ c = c >>> 1;
1165
+ }
1166
+ }
1167
+ if (c < 0) {
1168
+ b.writeInt32LE(c, 0);
1169
+ c = b.readUInt32LE(0);
1170
+ }
1171
+ crcTable[n] = c;
1172
+ }
1173
+ }
1174
+ return crcTable;
1175
+ }
1176
+ }
1049
1177
 
1050
- // region Util
1178
+ function parseZipTime(timebytes, datebytes) {
1179
+ const timebits = toBits(timebytes, 16);
1180
+ const datebits = toBits(datebytes, 16);
1181
+
1182
+ const mt = {
1183
+ h: parseInt(timebits.slice(0, 5).join(''), 2),
1184
+ m: parseInt(timebits.slice(5, 11).join(''), 2),
1185
+ s: parseInt(timebits.slice(11, 16).join(''), 2) * 2,
1186
+ Y: parseInt(datebits.slice(0, 7).join(''), 2) + 1980,
1187
+ M: parseInt(datebits.slice(7, 11).join(''), 2),
1188
+ D: parseInt(datebits.slice(11, 16).join(''), 2),
1189
+ };
1190
+ const dt_str = [mt.Y, mt.M, mt.D].join('-') + ' ' + [mt.h, mt.m, mt.s].join(':') + ' GMT+0';
1191
+ return new Date(dt_str).getTime();
1192
+ }
1051
1193
 
1052
- var Util = {
1053
- readUInt64LE: function(buffer, offset) {
1054
- return (buffer.readUInt32LE(offset + 4) * 0x0000000100000000) + buffer.readUInt32LE(offset);
1194
+ function toBits(dec, size) {
1195
+ let b = (dec >>> 0).toString(2);
1196
+ while (b.length < size) {
1197
+ b = '0' + b;
1055
1198
  }
1056
- };
1057
-
1058
- // endregion
1199
+ return b.split('');
1200
+ }
1059
1201
 
1060
- // region exports
1202
+ function readUInt64LE(buffer, offset) {
1203
+ return buffer.readUInt32LE(offset + 4) * 0x0000000100000000 + buffer.readUInt32LE(offset);
1204
+ }
1061
1205
 
1062
1206
  module.exports = StreamZip;
1063
-
1064
- // endregion