@zip.js/zip.js 2.6.67 → 2.6.69

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.d.ts CHANGED
@@ -1185,6 +1185,10 @@ declare class ZipEntry {
1185
1185
  * The children of the entry.
1186
1186
  */
1187
1187
  children: ZipEntry[]
1188
+ /**
1189
+ * Clones the entry
1190
+ */
1191
+ clone(): ZipEntry
1188
1192
  /**
1189
1193
  * Returns the full filename of the entry
1190
1194
  */
package/lib/core/io.js CHANGED
@@ -262,8 +262,8 @@ class FetchReader extends Reader {
262
262
  }
263
263
 
264
264
  async init() {
265
- super.init();
266
265
  await initHttpReader(this, sendFetchRequest, getFetchRequestData);
266
+ super.init();
267
267
  }
268
268
 
269
269
  readUint8Array(index, length) {
@@ -279,8 +279,8 @@ class XHRReader extends Reader {
279
279
  }
280
280
 
281
281
  async init() {
282
- super.init();
283
282
  await initHttpReader(this, sendXMLHttpRequest, getXMLHttpRequestData);
283
+ super.init();
284
284
  }
285
285
 
286
286
  readUint8Array(index, length) {
@@ -467,8 +467,8 @@ class HttpReader extends Reader {
467
467
  }
468
468
 
469
469
  async init() {
470
- super.init();
471
470
  await this.reader.init();
471
+ super.init();
472
472
  }
473
473
 
474
474
  readUint8Array(index, length) {
@@ -503,11 +503,11 @@ class Uint8ArrayReader extends Reader {
503
503
  class Uint8ArrayWriter extends Writer {
504
504
 
505
505
  init(initSize = 0) {
506
- super.init();
507
506
  Object.assign(this, {
508
507
  offset: 0,
509
508
  array: new Uint8Array(initSize)
510
509
  });
510
+ super.init();
511
511
  }
512
512
 
513
513
  writeUint8Array(array) {
@@ -534,7 +534,6 @@ class SplitDataReader extends Reader {
534
534
  }
535
535
 
536
536
  async init() {
537
- super.init();
538
537
  const reader = this;
539
538
  const { readers } = reader;
540
539
  reader.lastDiskNumber = 0;
@@ -542,6 +541,7 @@ class SplitDataReader extends Reader {
542
541
  await diskReader.init();
543
542
  reader.size += diskReader.size;
544
543
  }));
544
+ super.init();
545
545
  }
546
546
 
547
547
  async readUint8Array(offset, length, diskNumber = 0) {
@@ -125,6 +125,10 @@ class ZipFileEntry extends ZipEntry {
125
125
  }
126
126
  }
127
127
 
128
+ clone() {
129
+ return new ZipFileEntry(this.fs, this.name, this);
130
+ }
131
+
128
132
  async getData(writer, options = {}) {
129
133
  const zipEntry = this;
130
134
  if (!writer || (writer.constructor == zipEntry.Writer && zipEntry.data)) {
@@ -212,6 +216,10 @@ class ZipDirectoryEntry extends ZipEntry {
212
216
  this.directory = true;
213
217
  }
214
218
 
219
+ clone() {
220
+ return new ZipDirectoryEntry(this.fs, this.name);
221
+ }
222
+
215
223
  addDirectory(name) {
216
224
  return addChild(this, name, null, true);
217
225
  }
@@ -504,12 +512,12 @@ function getZipBlobReader(options) {
504
512
  }
505
513
 
506
514
  async init() {
507
- super.init();
508
515
  const zipBlobReader = this;
509
516
  zipBlobReader.size = zipBlobReader.entry.uncompressedSize;
510
517
  const data = await zipBlobReader.entry.getData(new BlobWriter(), Object.assign({}, zipBlobReader.options, options));
511
518
  zipBlobReader.data = data;
512
519
  zipBlobReader.blobReader = new BlobReader(data);
520
+ super.init();
513
521
  }
514
522
 
515
523
  readUint8Array(index, length) {
@@ -520,7 +528,7 @@ function getZipBlobReader(options) {
520
528
 
521
529
  async function initReaders(entry) {
522
530
  if (entry.children.length) {
523
- for (const child of entry.children) {
531
+ await Promise.all(entry.children.map(async child => {
524
532
  if (child.directory) {
525
533
  await initReaders(child);
526
534
  } else {
@@ -528,17 +536,19 @@ async function initReaders(entry) {
528
536
  await initStream(reader);
529
537
  child.uncompressedSize = reader.size;
530
538
  }
531
- }
539
+ }));
532
540
  }
533
541
  }
534
542
 
535
543
  function detach(entry) {
536
- const children = entry.parent.children;
537
- children.forEach((child, index) => {
538
- if (child.id == entry.id) {
539
- children.splice(index, 1);
540
- }
541
- });
544
+ if (entry.parent) {
545
+ const children = entry.parent.children;
546
+ children.forEach((child, index) => {
547
+ if (child.id == entry.id) {
548
+ children.splice(index, 1);
549
+ }
550
+ });
551
+ }
542
552
  }
543
553
 
544
554
  async function exportZip(zipWriter, entry, totalSize, options) {
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.67",
6
+ "version": "2.6.69",
7
7
  "type": "module",
8
8
  "keywords": [
9
9
  "zip",