@zip.js/zip.js 2.7.34 → 2.7.36
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 +1 -1
- package/deno.json +5 -0
- package/dist/zip-fs-full.js +84 -20
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +84 -20
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +82 -18
- 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 +82 -18
- package/dist/zip.min.js +1 -1
- package/index.cjs +84 -20
- package/index.d.ts +166 -49
- package/index.js +5 -3
- package/index.min.js +1 -1
- package/lib/core/io.js +12 -10
- package/lib/core/zip-reader.js +34 -5
- package/lib/core/zip-writer.js +41 -10
- package/lib/zip-fs.js +3 -3
- package/package.json +1 -1
package/lib/core/io.js
CHANGED
|
@@ -584,8 +584,8 @@ class SplitDataWriter extends Stream {
|
|
|
584
584
|
|
|
585
585
|
constructor(writerGenerator, maxSize = 4294967295) {
|
|
586
586
|
super();
|
|
587
|
-
const
|
|
588
|
-
Object.assign(
|
|
587
|
+
const writer = this;
|
|
588
|
+
Object.assign(writer, {
|
|
589
589
|
diskNumber: 0,
|
|
590
590
|
diskOffset: 0,
|
|
591
591
|
size: 0,
|
|
@@ -595,7 +595,7 @@ class SplitDataWriter extends Stream {
|
|
|
595
595
|
let diskSourceWriter, diskWritable, diskWriter;
|
|
596
596
|
const writable = new WritableStream({
|
|
597
597
|
async write(chunk) {
|
|
598
|
-
const { availableSize } =
|
|
598
|
+
const { availableSize } = writer;
|
|
599
599
|
if (!diskWriter) {
|
|
600
600
|
const { value, done } = await writerGenerator.next();
|
|
601
601
|
if (done && !value) {
|
|
@@ -604,9 +604,9 @@ class SplitDataWriter extends Stream {
|
|
|
604
604
|
diskSourceWriter = value;
|
|
605
605
|
diskSourceWriter.size = 0;
|
|
606
606
|
if (diskSourceWriter.maxSize) {
|
|
607
|
-
|
|
607
|
+
writer.maxSize = diskSourceWriter.maxSize;
|
|
608
608
|
}
|
|
609
|
-
|
|
609
|
+
writer.availableSize = writer.maxSize;
|
|
610
610
|
await initStream(diskSourceWriter);
|
|
611
611
|
diskWritable = value.writable;
|
|
612
612
|
diskWriter = diskWritable.getWriter();
|
|
@@ -615,8 +615,8 @@ class SplitDataWriter extends Stream {
|
|
|
615
615
|
} else if (chunk.length >= availableSize) {
|
|
616
616
|
await writeChunk(chunk.slice(0, availableSize));
|
|
617
617
|
await closeDisk();
|
|
618
|
-
|
|
619
|
-
|
|
618
|
+
writer.diskOffset += diskSourceWriter.size;
|
|
619
|
+
writer.diskNumber++;
|
|
620
620
|
diskWriter = null;
|
|
621
621
|
await this.write(chunk.slice(availableSize));
|
|
622
622
|
} else {
|
|
@@ -628,7 +628,7 @@ class SplitDataWriter extends Stream {
|
|
|
628
628
|
await closeDisk();
|
|
629
629
|
}
|
|
630
630
|
});
|
|
631
|
-
Object.defineProperty(
|
|
631
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
632
632
|
get() {
|
|
633
633
|
return writable;
|
|
634
634
|
}
|
|
@@ -640,8 +640,8 @@ class SplitDataWriter extends Stream {
|
|
|
640
640
|
await diskWriter.ready;
|
|
641
641
|
await diskWriter.write(chunk);
|
|
642
642
|
diskSourceWriter.size += chunkLength;
|
|
643
|
-
|
|
644
|
-
|
|
643
|
+
writer.size += chunkLength;
|
|
644
|
+
writer.availableSize -= chunkLength;
|
|
645
645
|
}
|
|
646
646
|
}
|
|
647
647
|
|
|
@@ -661,6 +661,8 @@ function isHttpFamily(url) {
|
|
|
661
661
|
async function initStream(stream, initSize) {
|
|
662
662
|
if (stream.init && !stream.initialized) {
|
|
663
663
|
await stream.init(initSize);
|
|
664
|
+
} else {
|
|
665
|
+
return Promise.resolve();
|
|
664
666
|
}
|
|
665
667
|
}
|
|
666
668
|
|
package/lib/core/zip-reader.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
1. Redistributions of source code must retain the above copyright notice,
|
|
8
8
|
this list of conditions and the following disclaimer.
|
|
9
9
|
|
|
10
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
-
notice, this list of conditions and the following disclaimer in
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
notice, this list of conditions and the following disclaimer in
|
|
12
12
|
the documentation and/or other materials provided with the distribution.
|
|
13
13
|
|
|
14
14
|
3. The names of the authors may not be used to endorse or promote products
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
-
/* global BigInt, Response, WritableStream */
|
|
29
|
+
/* global BigInt, Response, WritableStream, ReadableStream, TransformStream */
|
|
30
30
|
// deno-lint-ignore-file no-this-alias
|
|
31
31
|
|
|
32
32
|
import {
|
|
@@ -209,7 +209,7 @@ class ZipReader {
|
|
|
209
209
|
}
|
|
210
210
|
if (directoryDataOffset >= reader.size) {
|
|
211
211
|
prependedDataLength = reader.size - directoryDataOffset - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
|
|
212
|
-
directoryDataOffset = reader.size - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
|
|
212
|
+
directoryDataOffset = reader.size - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
|
|
213
213
|
}
|
|
214
214
|
if (expectedLastDiskNumber != lastDiskNumber) {
|
|
215
215
|
throw new Error(ERR_SPLIT_ZIP_FILE);
|
|
@@ -326,8 +326,37 @@ class ZipReader {
|
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
+
class ZipReaderStream {
|
|
330
|
+
|
|
331
|
+
constructor(options = {}) {
|
|
332
|
+
const { readable, writable } = new TransformStream();
|
|
333
|
+
const gen = new ZipReader(readable, options).getEntriesGenerator();
|
|
334
|
+
this.readable = new ReadableStream({
|
|
335
|
+
async pull(controller) {
|
|
336
|
+
const { done, value } = await gen.next();
|
|
337
|
+
if (done)
|
|
338
|
+
return controller.close();
|
|
339
|
+
const chunk = {
|
|
340
|
+
...value,
|
|
341
|
+
readable: (function () {
|
|
342
|
+
const { readable, writable } = new TransformStream();
|
|
343
|
+
if (value.getData) {
|
|
344
|
+
value.getData(writable);
|
|
345
|
+
return readable;
|
|
346
|
+
}
|
|
347
|
+
})()
|
|
348
|
+
};
|
|
349
|
+
delete chunk.getData;
|
|
350
|
+
controller.enqueue(chunk);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
this.writable = writable;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
329
357
|
export {
|
|
330
358
|
ZipReader,
|
|
359
|
+
ZipReaderStream,
|
|
331
360
|
ERR_BAD_FORMAT,
|
|
332
361
|
ERR_EOCDR_NOT_FOUND,
|
|
333
362
|
ERR_EOCDR_ZIP64_NOT_FOUND,
|
|
@@ -721,4 +750,4 @@ function setUint32(view, offset, value) {
|
|
|
721
750
|
|
|
722
751
|
function getDataView(array) {
|
|
723
752
|
return new DataView(array.buffer);
|
|
724
|
-
}
|
|
753
|
+
}
|
package/lib/core/zip-writer.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
1. Redistributions of source code must retain the above copyright notice,
|
|
8
8
|
this list of conditions and the following disclaimer.
|
|
9
9
|
|
|
10
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
-
notice, this list of conditions and the following disclaimer in
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
notice, this list of conditions and the following disclaimer in
|
|
12
12
|
the documentation and/or other materials provided with the distribution.
|
|
13
13
|
|
|
14
14
|
3. The names of the authors may not be used to endorse or promote products
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
-
/* global BigInt */
|
|
29
|
+
/* global BigInt, TransformStream, Response */
|
|
30
30
|
// deno-lint-ignore-file no-this-alias
|
|
31
31
|
|
|
32
32
|
import {
|
|
@@ -75,9 +75,7 @@ import {
|
|
|
75
75
|
import {
|
|
76
76
|
initStream,
|
|
77
77
|
initReader,
|
|
78
|
-
initWriter
|
|
79
|
-
BlobWriter,
|
|
80
|
-
SplitDataWriter
|
|
78
|
+
initWriter
|
|
81
79
|
} from "./io.js";
|
|
82
80
|
import { encodeText } from "./util/encode-text.js";
|
|
83
81
|
import {
|
|
@@ -110,9 +108,12 @@ class ZipWriter {
|
|
|
110
108
|
|
|
111
109
|
constructor(writer, options = {}) {
|
|
112
110
|
writer = initWriter(writer);
|
|
111
|
+
const addSplitZipSignature =
|
|
112
|
+
writer.availableSize !== UNDEFINED_VALUE && writer.availableSize > 0 && writer.availableSize !== Infinity &&
|
|
113
|
+
writer.maxSize !== UNDEFINED_VALUE && writer.maxSize > 0 && writer.maxSize !== Infinity;
|
|
113
114
|
Object.assign(this, {
|
|
114
115
|
writer,
|
|
115
|
-
addSplitZipSignature
|
|
116
|
+
addSplitZipSignature,
|
|
116
117
|
options,
|
|
117
118
|
config: getConfiguration(),
|
|
118
119
|
files: new Map(),
|
|
@@ -175,8 +176,36 @@ class ZipWriter {
|
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
|
|
179
|
+
class ZipWriterStream {
|
|
180
|
+
|
|
181
|
+
constructor(options = {}) {
|
|
182
|
+
const { readable, writable } = new TransformStream();
|
|
183
|
+
this.readable = readable;
|
|
184
|
+
this.zipWriter = new ZipWriter(writable, options);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
transform(path) {
|
|
188
|
+
const { readable, writable } = new TransformStream({
|
|
189
|
+
flush: () => { this.zipWriter.close(); }
|
|
190
|
+
});
|
|
191
|
+
this.zipWriter.add(path, readable);
|
|
192
|
+
return { readable: this.readable, writable };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
writable(path) {
|
|
196
|
+
const { readable, writable } = new TransformStream();
|
|
197
|
+
this.zipWriter.add(path, readable);
|
|
198
|
+
return writable;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
close(comment = undefined, options = {}) {
|
|
202
|
+
return this.zipWriter.close(comment, options);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
178
206
|
export {
|
|
179
207
|
ZipWriter,
|
|
208
|
+
ZipWriterStream,
|
|
180
209
|
ERR_DUPLICATED_NAME,
|
|
181
210
|
ERR_INVALID_COMMENT,
|
|
182
211
|
ERR_INVALID_ENTRY_NAME,
|
|
@@ -358,6 +387,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
358
387
|
let writingBufferedEntryData;
|
|
359
388
|
let writingEntryData;
|
|
360
389
|
let fileWriter;
|
|
390
|
+
let blobPromise;
|
|
361
391
|
files.set(name, fileEntry);
|
|
362
392
|
try {
|
|
363
393
|
let lockPreviousFileEntry;
|
|
@@ -366,7 +396,8 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
366
396
|
requestLockCurrentFileEntry();
|
|
367
397
|
}
|
|
368
398
|
if ((options.bufferedWrite || zipWriter.writerLocked || (zipWriter.bufferedWrites && keepOrder) || !dataDescriptor) && !usdz) {
|
|
369
|
-
fileWriter = new
|
|
399
|
+
fileWriter = new TransformStream();
|
|
400
|
+
blobPromise = new Response(fileWriter.readable).blob();
|
|
370
401
|
fileWriter.writable.size = 0;
|
|
371
402
|
bufferedWrite = true;
|
|
372
403
|
zipWriter.bufferedWrites++;
|
|
@@ -402,7 +433,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
402
433
|
fileEntry.filename = name;
|
|
403
434
|
if (bufferedWrite) {
|
|
404
435
|
await fileWriter.writable.getWriter().close();
|
|
405
|
-
let blob = await
|
|
436
|
+
let blob = await blobPromise;
|
|
406
437
|
await lockPreviousFileEntry;
|
|
407
438
|
await requestLockWriter();
|
|
408
439
|
writingBufferedEntryData = true;
|
|
@@ -1145,4 +1176,4 @@ function getLength(...arrayLikes) {
|
|
|
1145
1176
|
let result = 0;
|
|
1146
1177
|
arrayLikes.forEach(arrayLike => arrayLike && (result += arrayLike.length));
|
|
1147
1178
|
return result;
|
|
1148
|
-
}
|
|
1179
|
+
}
|
package/lib/zip-fs.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
1. Redistributions of source code must retain the above copyright notice,
|
|
8
8
|
this list of conditions and the following disclaimer.
|
|
9
9
|
|
|
10
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
-
notice, this list of conditions and the following disclaimer in
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
notice, this list of conditions and the following disclaimer in
|
|
12
12
|
the documentation and/or other materials provided with the distribution.
|
|
13
13
|
|
|
14
14
|
3. The names of the authors may not be used to endorse or promote products
|
|
@@ -50,4 +50,4 @@ export {
|
|
|
50
50
|
getMimeType,
|
|
51
51
|
initShimAsyncCodec,
|
|
52
52
|
terminateWorkers
|
|
53
|
-
};
|
|
53
|
+
};
|
package/package.json
CHANGED