@zip.js/zip.js 2.6.78 → 2.6.80

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/index.cjs CHANGED
@@ -10096,6 +10096,7 @@ class ZipEntry {
10096
10096
  fs,
10097
10097
  name,
10098
10098
  data: params.data,
10099
+ options: params.options,
10099
10100
  id: fs.entries.length,
10100
10101
  parent,
10101
10102
  children: [],
@@ -10262,39 +10263,43 @@ class ZipDirectoryEntry extends ZipEntry {
10262
10263
  return clonedEntry;
10263
10264
  }
10264
10265
 
10265
- addDirectory(name) {
10266
- return addChild(this, name, null, true);
10266
+ addDirectory(name, options) {
10267
+ return addChild(this, name, { options }, true);
10267
10268
  }
10268
10269
 
10269
- addText(name, text) {
10270
+ addText(name, text, options = {}) {
10270
10271
  return addChild(this, name, {
10271
10272
  data: text,
10272
10273
  Reader: TextReader,
10273
- Writer: TextWriter
10274
+ Writer: TextWriter,
10275
+ options
10274
10276
  });
10275
10277
  }
10276
10278
 
10277
- addBlob(name, blob) {
10279
+ addBlob(name, blob, options = {}) {
10278
10280
  return addChild(this, name, {
10279
10281
  data: blob,
10280
10282
  Reader: BlobReader,
10281
- Writer: BlobWriter
10283
+ Writer: BlobWriter,
10284
+ options
10282
10285
  });
10283
10286
  }
10284
10287
 
10285
- addData64URI(name, dataURI) {
10288
+ addData64URI(name, dataURI, options = {}) {
10286
10289
  return addChild(this, name, {
10287
10290
  data: dataURI,
10288
10291
  Reader: Data64URIReader,
10289
- Writer: Data64URIWriter
10292
+ Writer: Data64URIWriter,
10293
+ options
10290
10294
  });
10291
10295
  }
10292
10296
 
10293
- addUint8Array(name, array) {
10297
+ addUint8Array(name, array, options = {}) {
10294
10298
  return addChild(this, name, {
10295
10299
  data: array,
10296
10300
  Reader: Uint8ArrayReader,
10297
- Writer: Uint8ArrayWriter
10301
+ Writer: Uint8ArrayWriter,
10302
+ options
10298
10303
  });
10299
10304
  }
10300
10305
 
@@ -10305,18 +10310,20 @@ class ZipDirectoryEntry extends ZipEntry {
10305
10310
  constructor(url) {
10306
10311
  super(url, options);
10307
10312
  }
10308
- }
10313
+ },
10314
+ options
10309
10315
  });
10310
10316
  }
10311
10317
 
10312
- addReadable(name, readable) {
10318
+ addReadable(name, readable, options = {}) {
10313
10319
  return addChild(this, name, {
10314
- Reader: function () { return { readable }; }
10320
+ Reader: function () { return { readable }; },
10321
+ options
10315
10322
  });
10316
10323
  }
10317
10324
 
10318
- addFileSystemEntry(fileSystemEntry) {
10319
- return addFileSystemEntry(this, fileSystemEntry);
10325
+ addFileSystemEntry(fileSystemEntry, options = {}) {
10326
+ return addFileSystemEntry(this, fileSystemEntry, options);
10320
10327
  }
10321
10328
 
10322
10329
  addData(name, params) {
@@ -10454,32 +10461,32 @@ class FS {
10454
10461
  return this.root.getChildByName(name);
10455
10462
  }
10456
10463
 
10457
- addDirectory(name) {
10458
- return this.root.addDirectory(name);
10464
+ addDirectory(name, options) {
10465
+ return this.root.addDirectory(name, options);
10459
10466
  }
10460
10467
 
10461
- addText(name, text) {
10462
- return this.root.addText(name, text);
10468
+ addText(name, text, options) {
10469
+ return this.root.addText(name, text, options);
10463
10470
  }
10464
10471
 
10465
- addBlob(name, blob) {
10466
- return this.root.addBlob(name, blob);
10472
+ addBlob(name, blob, options) {
10473
+ return this.root.addBlob(name, blob, options);
10467
10474
  }
10468
10475
 
10469
- addData64URI(name, dataURI) {
10470
- return this.root.addData64URI(name, dataURI);
10476
+ addData64URI(name, dataURI, options) {
10477
+ return this.root.addData64URI(name, dataURI, options);
10471
10478
  }
10472
10479
 
10473
10480
  addHttpContent(name, url, options) {
10474
10481
  return this.root.addHttpContent(name, url, options);
10475
10482
  }
10476
10483
 
10477
- addReadable(name, readable) {
10478
- return this.root.addReadable(name, readable);
10484
+ addReadable(name, readable, options) {
10485
+ return this.root.addReadable(name, readable, options);
10479
10486
  }
10480
10487
 
10481
- addFileSystemEntry(fileSystemEntry) {
10482
- return this.root.addFileSystemEntry(fileSystemEntry);
10488
+ addFileSystemEntry(fileSystemEntry, options) {
10489
+ return this.root.addFileSystemEntry(fileSystemEntry, options);
10483
10490
  }
10484
10491
 
10485
10492
  addData(name, params) {
@@ -10574,7 +10581,16 @@ async function initReaders(entry, options) {
10574
10581
  await initReaders(child, options);
10575
10582
  } else {
10576
10583
  const reader = child.reader = new child.Reader(child.data, options);
10577
- await initStream(reader);
10584
+ try {
10585
+ await initStream(reader);
10586
+ } catch (error) {
10587
+ try {
10588
+ error.entryId = child.id;
10589
+ } catch (_error) {
10590
+ // ignored
10591
+ }
10592
+ throw error;
10593
+ }
10578
10594
  child.uncompressedSize = reader.size;
10579
10595
  }
10580
10596
  }));
@@ -10612,9 +10628,32 @@ async function exportZip(zipWriter, entry, totalSize, options) {
10612
10628
 
10613
10629
  async function processChild(child) {
10614
10630
  const name = options.relativePath ? child.getRelativeName(selectedEntry) : child.getFullname();
10631
+ let externalFileAttribute;
10632
+ let versionMadeBy;
10633
+ let comment;
10634
+ let lastModDate;
10635
+ let lastAccessDate;
10636
+ let creationDate;
10637
+ let childOptions = child.options || {};
10638
+ if (child.data instanceof Entry) {
10639
+ ({
10640
+ externalFileAttribute,
10641
+ versionMadeBy,
10642
+ comment,
10643
+ lastModDate,
10644
+ lastAccessDate,
10645
+ creationDate
10646
+ } = child.data);
10647
+ }
10615
10648
  await zipWriter.add(name, child.reader, Object.assign({
10616
10649
  directory: child.directory
10617
10650
  }, Object.assign({}, options, {
10651
+ externalFileAttribute,
10652
+ versionMadeBy,
10653
+ comment,
10654
+ lastModDate,
10655
+ lastAccessDate,
10656
+ creationDate,
10618
10657
  onprogress: async indexProgress => {
10619
10658
  if (options.onprogress) {
10620
10659
  entryOffsets.set(name, indexProgress);
@@ -10625,30 +10664,30 @@ async function exportZip(zipWriter, entry, totalSize, options) {
10625
10664
  }
10626
10665
  }
10627
10666
  }
10628
- })));
10667
+ }, childOptions)));
10629
10668
  await process(zipWriter, child);
10630
10669
  }
10631
10670
  }
10632
10671
  }
10633
10672
 
10634
- async function addFileSystemEntry(zipEntry, fileSystemEntry) {
10673
+ async function addFileSystemEntry(zipEntry, fileSystemEntry, options) {
10635
10674
  if (fileSystemEntry.isDirectory) {
10636
- const entry = zipEntry.addDirectory(fileSystemEntry.name);
10675
+ const entry = zipEntry.addDirectory(fileSystemEntry.name, options);
10637
10676
  await addDirectory(entry, fileSystemEntry);
10638
10677
  return entry;
10639
10678
  } else {
10640
- return new Promise((resolve, reject) => fileSystemEntry.file(file => resolve(zipEntry.addBlob(fileSystemEntry.name, file)), reject));
10679
+ return new Promise((resolve, reject) => fileSystemEntry.file(file => resolve(zipEntry.addBlob(fileSystemEntry.name, file, options)), reject));
10641
10680
  }
10642
10681
 
10643
10682
  async function addDirectory(zipEntry, fileEntry) {
10644
10683
  const children = await getChildren(fileEntry);
10645
10684
  for (const child of children) {
10646
10685
  if (child.isDirectory) {
10647
- await addDirectory(zipEntry.addDirectory(child.name), child);
10686
+ await addDirectory(zipEntry.addDirectory(child.name, options), child);
10648
10687
  } else {
10649
10688
  await new Promise((resolve, reject) => {
10650
10689
  child.file(file => {
10651
- const childZipEntry = zipEntry.addBlob(child.name, file);
10690
+ const childZipEntry = zipEntry.addBlob(child.name, file, options);
10652
10691
  childZipEntry.uncompressedSize = file.size;
10653
10692
  resolve(childZipEntry);
10654
10693
  }, reject);
package/index.d.ts CHANGED
@@ -1326,66 +1326,73 @@ export class ZipDirectoryEntry extends ZipEntry {
1326
1326
  /**
1327
1327
  * Adds a directory
1328
1328
  *
1329
- * @param name The relative filename of the directory
1329
+ * @param name The relative filename of the directory.
1330
+ * @param options The options.
1330
1331
  * @returns A {@link ZipDirectoryEntry} instance.
1331
1332
  */
1332
- addDirectory(name: string): ZipDirectoryEntry
1333
+ addDirectory(name: string, options?: ZipWriterAddDataOptions): ZipDirectoryEntry
1333
1334
  /**
1334
1335
  * Adds an entry with content provided as text
1335
1336
  *
1336
1337
  * @param name The relative filename of the entry.
1337
- * @param text The text.
1338
+ * @param text The text.
1339
+ * @param options The options.
1338
1340
  * @returns A {@link ZipFileEntry} instance.
1339
1341
  */
1340
- addText(name: string, text: string): ZipFileEntry<string, string>
1342
+ addText(name: string, text: string, options?: ZipWriterAddDataOptions): ZipFileEntry<string, string>
1341
1343
  /**
1342
1344
  * Adds aentry entry with content provided as a `Blob` instance
1343
1345
  *
1344
1346
  * @param name The relative filename of the entry.
1345
- * @param blob The `Blob` instance.
1347
+ * @param blob The `Blob` instance.
1348
+ * @param options The options.
1346
1349
  * @returns A {@link ZipFileEntry} instance.
1347
1350
  */
1348
- addBlob(name: string, blob: Blob): ZipFileEntry<Blob, Blob>
1351
+ addBlob(name: string, blob: Blob, options?: ZipWriterAddDataOptions): ZipFileEntry<Blob, Blob>
1349
1352
  /**
1350
1353
  * Adds aentry entry with content provided as a Data URI `string` encoded in Base64
1351
1354
  *
1352
1355
  * @param name The relative filename of the entry.
1353
1356
  * @param dataURI The Data URI `string` encoded in Base64.
1357
+ * @param options The options.
1354
1358
  * @returns A {@link ZipFileEntry} instance.
1355
1359
  */
1356
- addData64URI(name: string, dataURI: string): ZipFileEntry<string, string>
1360
+ addData64URI(name: string, dataURI: string, options?: ZipWriterAddDataOptions): ZipFileEntry<string, string>
1357
1361
  /**
1358
1362
  * Adds an entry with content provided as a `Uint8Array` instance
1359
1363
  *
1360
1364
  * @param name The relative filename of the entry.
1361
- * @param array The `Uint8Array` instance.
1365
+ * @param array The `Uint8Array` instance.
1366
+ * @param options The options.
1362
1367
  * @returns A {@link ZipFileEntry} instance.
1363
1368
  */
1364
- addUint8Array(name: string, array: Uint8Array): ZipFileEntry<Uint8Array, Uint8Array>
1369
+ addUint8Array(name: string, array: Uint8Array, options?: ZipWriterAddDataOptions): ZipFileEntry<Uint8Array, Uint8Array>
1365
1370
  /**
1366
1371
  * Adds an entry with content fetched from a URL
1367
1372
  *
1368
1373
  * @param name The relative filename of the entry.
1369
1374
  * @param url The URL.
1370
- * @param options The options.
1375
+ * @param options The options.
1371
1376
  * @returns A {@link ZipFileEntry} instance.
1372
1377
  */
1373
- addHttpContent(name: string, url: string, options?: HttpOptions): ZipFileEntry<string, void>
1378
+ addHttpContent(name: string, url: string, options?: HttpOptions & ZipWriterAddDataOptions): ZipFileEntry<string, void>
1374
1379
  /**
1375
1380
  * Adds aentry entry with content provided via a `ReadableStream` instance
1376
1381
  *
1377
1382
  * @param name The relative filename of the entry.
1378
- * @param readable The `ReadableStream` instance.
1383
+ * @param readable The `ReadableStream` instance.
1384
+ * @param options The options.
1379
1385
  * @returns A {@link ZipFileEntry} instance.
1380
1386
  */
1381
- addReadable(name: string, readable: ReadableStream): ZipFileEntry<ReadableStream, void>
1387
+ addReadable(name: string, readable: ReadableStream, options?: ZipWriterAddDataOptions): ZipFileEntry<ReadableStream, void>
1382
1388
  /**
1383
1389
  * Adds an entry with content provided via a `FileSystemEntry` instance
1384
1390
  *
1385
- * @param fileSystemEntry The `FileSystemEntry` instance.
1391
+ * @param fileSystemEntry The `FileSystemEntry` instance.
1392
+ * @param options The options.
1386
1393
  * @returns A promise resolving to a {@link ZipFileEntry} or a {@link ZipDirectoryEntry} instance.
1387
1394
  */
1388
- addFileSystemEntry(fileSystemEntry: FileSystemEntry): Promise<ZipEntry>
1395
+ addFileSystemEntry(fileSystemEntry: FileSystemEntry, options?: ZipWriterAddDataOptions): Promise<ZipEntry>
1389
1396
  /**
1390
1397
  * Extracts a zip file provided as a `Blob` instance into the entry
1391
1398
  *
@@ -48,6 +48,9 @@ import {
48
48
  import {
49
49
  ZipWriter
50
50
  } from "./zip-writer.js";
51
+ import {
52
+ Entry
53
+ } from "./zip-entry.js";
51
54
 
52
55
  class ZipEntry {
53
56
 
@@ -63,6 +66,7 @@ class ZipEntry {
63
66
  fs,
64
67
  name,
65
68
  data: params.data,
69
+ options: params.options,
66
70
  id: fs.entries.length,
67
71
  parent,
68
72
  children: [],
@@ -229,39 +233,43 @@ class ZipDirectoryEntry extends ZipEntry {
229
233
  return clonedEntry;
230
234
  }
231
235
 
232
- addDirectory(name) {
233
- return addChild(this, name, null, true);
236
+ addDirectory(name, options) {
237
+ return addChild(this, name, { options }, true);
234
238
  }
235
239
 
236
- addText(name, text) {
240
+ addText(name, text, options = {}) {
237
241
  return addChild(this, name, {
238
242
  data: text,
239
243
  Reader: TextReader,
240
- Writer: TextWriter
244
+ Writer: TextWriter,
245
+ options
241
246
  });
242
247
  }
243
248
 
244
- addBlob(name, blob) {
249
+ addBlob(name, blob, options = {}) {
245
250
  return addChild(this, name, {
246
251
  data: blob,
247
252
  Reader: BlobReader,
248
- Writer: BlobWriter
253
+ Writer: BlobWriter,
254
+ options
249
255
  });
250
256
  }
251
257
 
252
- addData64URI(name, dataURI) {
258
+ addData64URI(name, dataURI, options = {}) {
253
259
  return addChild(this, name, {
254
260
  data: dataURI,
255
261
  Reader: Data64URIReader,
256
- Writer: Data64URIWriter
262
+ Writer: Data64URIWriter,
263
+ options
257
264
  });
258
265
  }
259
266
 
260
- addUint8Array(name, array) {
267
+ addUint8Array(name, array, options = {}) {
261
268
  return addChild(this, name, {
262
269
  data: array,
263
270
  Reader: Uint8ArrayReader,
264
- Writer: Uint8ArrayWriter
271
+ Writer: Uint8ArrayWriter,
272
+ options
265
273
  });
266
274
  }
267
275
 
@@ -272,18 +280,20 @@ class ZipDirectoryEntry extends ZipEntry {
272
280
  constructor(url) {
273
281
  super(url, options);
274
282
  }
275
- }
283
+ },
284
+ options
276
285
  });
277
286
  }
278
287
 
279
- addReadable(name, readable) {
288
+ addReadable(name, readable, options = {}) {
280
289
  return addChild(this, name, {
281
- Reader: function () { return { readable }; }
290
+ Reader: function () { return { readable }; },
291
+ options
282
292
  });
283
293
  }
284
294
 
285
- addFileSystemEntry(fileSystemEntry) {
286
- return addFileSystemEntry(this, fileSystemEntry);
295
+ addFileSystemEntry(fileSystemEntry, options = {}) {
296
+ return addFileSystemEntry(this, fileSystemEntry, options);
287
297
  }
288
298
 
289
299
  addData(name, params) {
@@ -421,32 +431,32 @@ class FS {
421
431
  return this.root.getChildByName(name);
422
432
  }
423
433
 
424
- addDirectory(name) {
425
- return this.root.addDirectory(name);
434
+ addDirectory(name, options) {
435
+ return this.root.addDirectory(name, options);
426
436
  }
427
437
 
428
- addText(name, text) {
429
- return this.root.addText(name, text);
438
+ addText(name, text, options) {
439
+ return this.root.addText(name, text, options);
430
440
  }
431
441
 
432
- addBlob(name, blob) {
433
- return this.root.addBlob(name, blob);
442
+ addBlob(name, blob, options) {
443
+ return this.root.addBlob(name, blob, options);
434
444
  }
435
445
 
436
- addData64URI(name, dataURI) {
437
- return this.root.addData64URI(name, dataURI);
446
+ addData64URI(name, dataURI, options) {
447
+ return this.root.addData64URI(name, dataURI, options);
438
448
  }
439
449
 
440
450
  addHttpContent(name, url, options) {
441
451
  return this.root.addHttpContent(name, url, options);
442
452
  }
443
453
 
444
- addReadable(name, readable) {
445
- return this.root.addReadable(name, readable);
454
+ addReadable(name, readable, options) {
455
+ return this.root.addReadable(name, readable, options);
446
456
  }
447
457
 
448
- addFileSystemEntry(fileSystemEntry) {
449
- return this.root.addFileSystemEntry(fileSystemEntry);
458
+ addFileSystemEntry(fileSystemEntry, options) {
459
+ return this.root.addFileSystemEntry(fileSystemEntry, options);
450
460
  }
451
461
 
452
462
  addData(name, params) {
@@ -542,7 +552,16 @@ async function initReaders(entry, options) {
542
552
  await initReaders(child, options);
543
553
  } else {
544
554
  const reader = child.reader = new child.Reader(child.data, options);
545
- await initStream(reader);
555
+ try {
556
+ await initStream(reader);
557
+ } catch (error) {
558
+ try {
559
+ error.entryId = child.id;
560
+ } catch (_error) {
561
+ // ignored
562
+ }
563
+ throw error;
564
+ }
546
565
  child.uncompressedSize = reader.size;
547
566
  }
548
567
  }));
@@ -580,9 +599,32 @@ async function exportZip(zipWriter, entry, totalSize, options) {
580
599
 
581
600
  async function processChild(child) {
582
601
  const name = options.relativePath ? child.getRelativeName(selectedEntry) : child.getFullname();
602
+ let externalFileAttribute;
603
+ let versionMadeBy;
604
+ let comment;
605
+ let lastModDate;
606
+ let lastAccessDate;
607
+ let creationDate;
608
+ let childOptions = child.options || {};
609
+ if (child.data instanceof Entry) {
610
+ ({
611
+ externalFileAttribute,
612
+ versionMadeBy,
613
+ comment,
614
+ lastModDate,
615
+ lastAccessDate,
616
+ creationDate
617
+ } = child.data);
618
+ }
583
619
  await zipWriter.add(name, child.reader, Object.assign({
584
620
  directory: child.directory
585
621
  }, Object.assign({}, options, {
622
+ externalFileAttribute,
623
+ versionMadeBy,
624
+ comment,
625
+ lastModDate,
626
+ lastAccessDate,
627
+ creationDate,
586
628
  onprogress: async indexProgress => {
587
629
  if (options.onprogress) {
588
630
  entryOffsets.set(name, indexProgress);
@@ -593,30 +635,30 @@ async function exportZip(zipWriter, entry, totalSize, options) {
593
635
  }
594
636
  }
595
637
  }
596
- })));
638
+ }, childOptions)));
597
639
  await process(zipWriter, child);
598
640
  }
599
641
  }
600
642
  }
601
643
 
602
- async function addFileSystemEntry(zipEntry, fileSystemEntry) {
644
+ async function addFileSystemEntry(zipEntry, fileSystemEntry, options) {
603
645
  if (fileSystemEntry.isDirectory) {
604
- const entry = zipEntry.addDirectory(fileSystemEntry.name);
646
+ const entry = zipEntry.addDirectory(fileSystemEntry.name, options);
605
647
  await addDirectory(entry, fileSystemEntry);
606
648
  return entry;
607
649
  } else {
608
- return new Promise((resolve, reject) => fileSystemEntry.file(file => resolve(zipEntry.addBlob(fileSystemEntry.name, file)), reject));
650
+ return new Promise((resolve, reject) => fileSystemEntry.file(file => resolve(zipEntry.addBlob(fileSystemEntry.name, file, options)), reject));
609
651
  }
610
652
 
611
653
  async function addDirectory(zipEntry, fileEntry) {
612
654
  const children = await getChildren(fileEntry);
613
655
  for (const child of children) {
614
656
  if (child.isDirectory) {
615
- await addDirectory(zipEntry.addDirectory(child.name), child);
657
+ await addDirectory(zipEntry.addDirectory(child.name, options), child);
616
658
  } else {
617
659
  await new Promise((resolve, reject) => {
618
660
  child.file(file => {
619
- const childZipEntry = zipEntry.addBlob(child.name, file);
661
+ const childZipEntry = zipEntry.addBlob(child.name, file, options);
620
662
  childZipEntry.uncompressedSize = file.size;
621
663
  resolve(childZipEntry);
622
664
  }, reject);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A JavaScript library to zip and unzip files in the browser, Deno and Node.js",
4
4
  "author": "Gildas Lormeau",
5
5
  "license": "BSD-3-Clause",
6
- "version": "2.6.78",
6
+ "version": "2.6.80",
7
7
  "type": "module",
8
8
  "keywords": [
9
9
  "zip",