@zip.js/zip.js 2.6.13 → 2.6.16
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/README.md +70 -17
- package/dist/README.md +6 -4
- package/dist/zip-fs-full.js +51 -46
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +51 -46
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +50 -45
- package/dist/zip-full.min.js +1 -1
- package/dist/zip-no-worker-deflate.min.js +1 -1
- package/dist/zip-no-worker-inflate.min.js +1 -1
- package/dist/zip-no-worker.min.js +1 -1
- package/dist/zip.js +50 -45
- package/dist/zip.min.js +1 -1
- package/index.d.ts +15 -9
- package/lib/core/io.js +11 -10
- package/lib/core/zip-fs-core.js +1 -1
- package/lib/core/zip-reader.js +2 -1
- package/lib/core/zip-writer.js +37 -34
- package/package.json +2 -2
package/lib/core/zip-writer.js
CHANGED
|
@@ -88,6 +88,7 @@ const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45,
|
|
|
88
88
|
const EXTRAFIELD_LENGTH_ZIP64 = 24;
|
|
89
89
|
|
|
90
90
|
let workers = 0;
|
|
91
|
+
const pendingEntries = [];
|
|
91
92
|
|
|
92
93
|
class ZipWriter {
|
|
93
94
|
|
|
@@ -100,7 +101,6 @@ class ZipWriter {
|
|
|
100
101
|
filenames: new Set(),
|
|
101
102
|
offset: writer.size || 0,
|
|
102
103
|
pendingCompressedSize: 0,
|
|
103
|
-
pendingEntries: [],
|
|
104
104
|
pendingAddFileCalls: new Set()
|
|
105
105
|
});
|
|
106
106
|
}
|
|
@@ -109,36 +109,34 @@ class ZipWriter {
|
|
|
109
109
|
const zipWriter = this;
|
|
110
110
|
const {
|
|
111
111
|
pendingAddFileCalls,
|
|
112
|
-
pendingEntries,
|
|
113
112
|
config
|
|
114
113
|
} = zipWriter;
|
|
115
114
|
if (workers < config.maxWorkers) {
|
|
116
115
|
workers++;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
} else {
|
|
117
|
+
await new Promise(resolve => pendingEntries.push(resolve));
|
|
118
|
+
}
|
|
119
|
+
let promiseAddFile;
|
|
120
|
+
try {
|
|
121
|
+
name = name.trim();
|
|
122
|
+
if (zipWriter.filenames.has(name)) {
|
|
123
|
+
throw new Error(ERR_DUPLICATED_NAME);
|
|
124
|
+
}
|
|
125
|
+
zipWriter.filenames.add(name);
|
|
126
|
+
promiseAddFile = addFile(zipWriter, name, reader, options);
|
|
127
|
+
pendingAddFileCalls.add(promiseAddFile);
|
|
128
|
+
return await promiseAddFile;
|
|
129
|
+
} catch (error) {
|
|
130
|
+
zipWriter.filenames.delete(name);
|
|
131
|
+
throw error;
|
|
132
|
+
} finally {
|
|
133
|
+
pendingAddFileCalls.delete(promiseAddFile);
|
|
134
|
+
const pendingEntry = pendingEntries.shift();
|
|
135
|
+
if (pendingEntry) {
|
|
136
|
+
pendingEntry();
|
|
137
|
+
} else {
|
|
132
138
|
workers--;
|
|
133
|
-
const pendingEntry = pendingEntries.shift();
|
|
134
|
-
if (pendingEntry) {
|
|
135
|
-
zipWriter.add(pendingEntry.name, pendingEntry.reader, pendingEntry.options)
|
|
136
|
-
.then(pendingEntry.resolve)
|
|
137
|
-
.catch(pendingEntry.reject);
|
|
138
|
-
}
|
|
139
139
|
}
|
|
140
|
-
} else {
|
|
141
|
-
return new Promise((resolve, reject) => pendingEntries.push({ name, reader, options, resolve, reject }));
|
|
142
140
|
}
|
|
143
141
|
}
|
|
144
142
|
|
|
@@ -321,8 +319,9 @@ async function getFileEntry(zipWriter, name, reader, options) {
|
|
|
321
319
|
let bufferedWrite;
|
|
322
320
|
let releaseLockWriter;
|
|
323
321
|
let releaseLockCurrentFileEntry;
|
|
324
|
-
let
|
|
322
|
+
let writingBufferedData;
|
|
325
323
|
let fileWriter;
|
|
324
|
+
let fileWriterSize;
|
|
326
325
|
files.set(name, fileEntry);
|
|
327
326
|
try {
|
|
328
327
|
let lockPreviousFileEntry;
|
|
@@ -339,6 +338,7 @@ async function getFileEntry(zipWriter, name, reader, options) {
|
|
|
339
338
|
await initStream(writer);
|
|
340
339
|
fileWriter = writer;
|
|
341
340
|
}
|
|
341
|
+
fileWriterSize = fileWriter.size;
|
|
342
342
|
fileEntry = await createFileEntry(reader, fileEntry, fileWriter.writable, zipWriter.config, options);
|
|
343
343
|
files.set(name, fileEntry);
|
|
344
344
|
fileEntry.filename = name;
|
|
@@ -346,7 +346,7 @@ async function getFileEntry(zipWriter, name, reader, options) {
|
|
|
346
346
|
let blob = fileWriter.getData();
|
|
347
347
|
await lockPreviousFileEntry;
|
|
348
348
|
await requestLockWriter();
|
|
349
|
-
|
|
349
|
+
writingBufferedData = true;
|
|
350
350
|
const { writable } = writer;
|
|
351
351
|
if (!dataDescriptor) {
|
|
352
352
|
const headerLength = 26;
|
|
@@ -366,7 +366,7 @@ async function getFileEntry(zipWriter, name, reader, options) {
|
|
|
366
366
|
blob = blob.slice(headerLength);
|
|
367
367
|
}
|
|
368
368
|
await blob.stream().pipeTo(writable, { preventClose: true, signal });
|
|
369
|
-
|
|
369
|
+
writingBufferedData = false;
|
|
370
370
|
}
|
|
371
371
|
fileEntry.offset = zipWriter.offset;
|
|
372
372
|
if (fileEntry.zip64) {
|
|
@@ -378,9 +378,12 @@ async function getFileEntry(zipWriter, name, reader, options) {
|
|
|
378
378
|
zipWriter.offset += fileEntry.length;
|
|
379
379
|
return fileEntry;
|
|
380
380
|
} catch (error) {
|
|
381
|
-
if ((bufferedWrite &&
|
|
382
|
-
|
|
383
|
-
|
|
381
|
+
if ((bufferedWrite && writingBufferedData) || (!bufferedWrite && fileEntry.writingData)) {
|
|
382
|
+
zipWriter.hasCorruptedEntries = true;
|
|
383
|
+
if (error) {
|
|
384
|
+
error.corruptedEntry = true;
|
|
385
|
+
}
|
|
386
|
+
zipWriter.offset += fileWriter.size - fileWriterSize;
|
|
384
387
|
}
|
|
385
388
|
files.delete(name);
|
|
386
389
|
throw error;
|
|
@@ -557,10 +560,10 @@ async function createFileEntry(reader, pendingFileEntry, writable, config, optio
|
|
|
557
560
|
arraySet(localHeaderArray, rawExtraField, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length);
|
|
558
561
|
let result;
|
|
559
562
|
let compressedSize = 0;
|
|
563
|
+
fileEntry.writingData = pendingFileEntry.writingData = true;
|
|
560
564
|
if (reader) {
|
|
561
565
|
reader.chunkSize = getChunkSize(config);
|
|
562
566
|
await writeData(writable, localHeaderArray);
|
|
563
|
-
fileEntry.dataWritten = pendingFileEntry.dataWritten = true;
|
|
564
567
|
const size = () => reader.size;
|
|
565
568
|
const readable = reader.readable;
|
|
566
569
|
readable.size = size;
|
|
@@ -587,7 +590,6 @@ async function createFileEntry(reader, pendingFileEntry, writable, config, optio
|
|
|
587
590
|
compressedSize = result.size;
|
|
588
591
|
} else {
|
|
589
592
|
await writeData(writable, localHeaderArray);
|
|
590
|
-
fileEntry.dataWritten = pendingFileEntry.dataWritten = true;
|
|
591
593
|
}
|
|
592
594
|
let dataDescriptorArray = new Uint8Array();
|
|
593
595
|
let dataDescriptorView, dataDescriptorOffset = 0;
|
|
@@ -640,7 +642,8 @@ async function createFileEntry(reader, pendingFileEntry, writable, config, optio
|
|
|
640
642
|
creationDate,
|
|
641
643
|
lastAccessDate,
|
|
642
644
|
encrypted,
|
|
643
|
-
length
|
|
645
|
+
length,
|
|
646
|
+
writingData: false
|
|
644
647
|
});
|
|
645
648
|
return fileEntry;
|
|
646
649
|
}
|
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.
|
|
6
|
+
"version": "2.6.16",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"zip",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
54
54
|
"@rollup/plugin-replace": "^4.0.0",
|
|
55
55
|
"http-server": "^14.1.1",
|
|
56
|
-
"rollup": "^2.
|
|
56
|
+
"rollup": "^2.78.0",
|
|
57
57
|
"rollup-plugin-terser": "^7.0.2",
|
|
58
58
|
"typedoc": "^0.23.10"
|
|
59
59
|
}
|