@zip.js/zip.js 2.6.68 → 2.6.70

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
@@ -10158,6 +10158,10 @@ class ZipFileEntry extends ZipEntry {
10158
10158
  }
10159
10159
  }
10160
10160
 
10161
+ clone() {
10162
+ return new ZipFileEntry(this.fs, this.name, this);
10163
+ }
10164
+
10161
10165
  async getData(writer, options = {}) {
10162
10166
  const zipEntry = this;
10163
10167
  if (!writer || (writer.constructor == zipEntry.Writer && zipEntry.data)) {
@@ -10245,6 +10249,15 @@ class ZipDirectoryEntry extends ZipEntry {
10245
10249
  this.directory = true;
10246
10250
  }
10247
10251
 
10252
+ clone(deepClone) {
10253
+ const zipEntry = this;
10254
+ const clone = new ZipDirectoryEntry(zipEntry.fs, zipEntry.name);
10255
+ if (deepClone) {
10256
+ clone.children = zipEntry.children.map(child => child.clone(deepClone));
10257
+ }
10258
+ return clone;
10259
+ }
10260
+
10248
10261
  addDirectory(name) {
10249
10262
  return addChild(this, name, null, true);
10250
10263
  }
@@ -10565,12 +10578,14 @@ async function initReaders(entry) {
10565
10578
  }
10566
10579
 
10567
10580
  function detach(entry) {
10568
- const children = entry.parent.children;
10569
- children.forEach((child, index) => {
10570
- if (child.id == entry.id) {
10571
- children.splice(index, 1);
10572
- }
10573
- });
10581
+ if (entry.parent) {
10582
+ const children = entry.parent.children;
10583
+ children.forEach((child, index) => {
10584
+ if (child.id == entry.id) {
10585
+ children.splice(index, 1);
10586
+ }
10587
+ });
10588
+ }
10574
10589
  }
10575
10590
 
10576
10591
  async function exportZip(zipWriter, entry, totalSize, options) {
package/index.d.ts CHANGED
@@ -1185,6 +1185,12 @@ declare class ZipEntry {
1185
1185
  * The children of the entry.
1186
1186
  */
1187
1187
  children: ZipEntry[]
1188
+ /**
1189
+ * Clones the entry
1190
+ *
1191
+ * @param deepClone `true` to clone all the descendants.
1192
+ */
1193
+ clone(deepClone: boolean): ZipEntry
1188
1194
  /**
1189
1195
  * Returns the full filename of the entry
1190
1196
  */
@@ -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,15 @@ class ZipDirectoryEntry extends ZipEntry {
212
216
  this.directory = true;
213
217
  }
214
218
 
219
+ clone(deepClone) {
220
+ const zipEntry = this;
221
+ const clone = new ZipDirectoryEntry(zipEntry.fs, zipEntry.name);
222
+ if (deepClone) {
223
+ clone.children = zipEntry.children.map(child => child.clone(deepClone));
224
+ }
225
+ return clone;
226
+ }
227
+
215
228
  addDirectory(name) {
216
229
  return addChild(this, name, null, true);
217
230
  }
@@ -533,12 +546,14 @@ async function initReaders(entry) {
533
546
  }
534
547
 
535
548
  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
- });
549
+ if (entry.parent) {
550
+ const children = entry.parent.children;
551
+ children.forEach((child, index) => {
552
+ if (child.id == entry.id) {
553
+ children.splice(index, 1);
554
+ }
555
+ });
556
+ }
542
557
  }
543
558
 
544
559
  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.68",
6
+ "version": "2.6.70",
7
7
  "type": "module",
8
8
  "keywords": [
9
9
  "zip",