@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/index.cjs
CHANGED
|
@@ -8919,8 +8919,8 @@ class SplitDataWriter extends Stream {
|
|
|
8919
8919
|
|
|
8920
8920
|
constructor(writerGenerator, maxSize = 4294967295) {
|
|
8921
8921
|
super();
|
|
8922
|
-
const
|
|
8923
|
-
Object.assign(
|
|
8922
|
+
const writer = this;
|
|
8923
|
+
Object.assign(writer, {
|
|
8924
8924
|
diskNumber: 0,
|
|
8925
8925
|
diskOffset: 0,
|
|
8926
8926
|
size: 0,
|
|
@@ -8930,7 +8930,7 @@ class SplitDataWriter extends Stream {
|
|
|
8930
8930
|
let diskSourceWriter, diskWritable, diskWriter;
|
|
8931
8931
|
const writable = new WritableStream({
|
|
8932
8932
|
async write(chunk) {
|
|
8933
|
-
const { availableSize } =
|
|
8933
|
+
const { availableSize } = writer;
|
|
8934
8934
|
if (!diskWriter) {
|
|
8935
8935
|
const { value, done } = await writerGenerator.next();
|
|
8936
8936
|
if (done && !value) {
|
|
@@ -8939,9 +8939,9 @@ class SplitDataWriter extends Stream {
|
|
|
8939
8939
|
diskSourceWriter = value;
|
|
8940
8940
|
diskSourceWriter.size = 0;
|
|
8941
8941
|
if (diskSourceWriter.maxSize) {
|
|
8942
|
-
|
|
8942
|
+
writer.maxSize = diskSourceWriter.maxSize;
|
|
8943
8943
|
}
|
|
8944
|
-
|
|
8944
|
+
writer.availableSize = writer.maxSize;
|
|
8945
8945
|
await initStream(diskSourceWriter);
|
|
8946
8946
|
diskWritable = value.writable;
|
|
8947
8947
|
diskWriter = diskWritable.getWriter();
|
|
@@ -8950,8 +8950,8 @@ class SplitDataWriter extends Stream {
|
|
|
8950
8950
|
} else if (chunk.length >= availableSize) {
|
|
8951
8951
|
await writeChunk(chunk.slice(0, availableSize));
|
|
8952
8952
|
await closeDisk();
|
|
8953
|
-
|
|
8954
|
-
|
|
8953
|
+
writer.diskOffset += diskSourceWriter.size;
|
|
8954
|
+
writer.diskNumber++;
|
|
8955
8955
|
diskWriter = null;
|
|
8956
8956
|
await this.write(chunk.slice(availableSize));
|
|
8957
8957
|
} else {
|
|
@@ -8963,7 +8963,7 @@ class SplitDataWriter extends Stream {
|
|
|
8963
8963
|
await closeDisk();
|
|
8964
8964
|
}
|
|
8965
8965
|
});
|
|
8966
|
-
Object.defineProperty(
|
|
8966
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
8967
8967
|
get() {
|
|
8968
8968
|
return writable;
|
|
8969
8969
|
}
|
|
@@ -8975,8 +8975,8 @@ class SplitDataWriter extends Stream {
|
|
|
8975
8975
|
await diskWriter.ready;
|
|
8976
8976
|
await diskWriter.write(chunk);
|
|
8977
8977
|
diskSourceWriter.size += chunkLength;
|
|
8978
|
-
|
|
8979
|
-
|
|
8978
|
+
writer.size += chunkLength;
|
|
8979
|
+
writer.availableSize -= chunkLength;
|
|
8980
8980
|
}
|
|
8981
8981
|
}
|
|
8982
8982
|
|
|
@@ -8996,6 +8996,8 @@ function isHttpFamily(url) {
|
|
|
8996
8996
|
async function initStream(stream, initSize) {
|
|
8997
8997
|
if (stream.init && !stream.initialized) {
|
|
8998
8998
|
await stream.init(initSize);
|
|
8999
|
+
} else {
|
|
9000
|
+
return Promise.resolve();
|
|
8999
9001
|
}
|
|
9000
9002
|
}
|
|
9001
9003
|
|
|
@@ -9197,8 +9199,8 @@ class Entry {
|
|
|
9197
9199
|
1. Redistributions of source code must retain the above copyright notice,
|
|
9198
9200
|
this list of conditions and the following disclaimer.
|
|
9199
9201
|
|
|
9200
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
9201
|
-
notice, this list of conditions and the following disclaimer in
|
|
9202
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
9203
|
+
notice, this list of conditions and the following disclaimer in
|
|
9202
9204
|
the documentation and/or other materials provided with the distribution.
|
|
9203
9205
|
|
|
9204
9206
|
3. The names of the authors may not be used to endorse or promote products
|
|
@@ -9327,7 +9329,7 @@ class ZipReader {
|
|
|
9327
9329
|
}
|
|
9328
9330
|
if (directoryDataOffset >= reader.size) {
|
|
9329
9331
|
prependedDataLength = reader.size - directoryDataOffset - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
|
|
9330
|
-
directoryDataOffset = reader.size - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
|
|
9332
|
+
directoryDataOffset = reader.size - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
|
|
9331
9333
|
}
|
|
9332
9334
|
if (expectedLastDiskNumber != lastDiskNumber) {
|
|
9333
9335
|
throw new Error(ERR_SPLIT_ZIP_FILE);
|
|
@@ -9444,6 +9446,34 @@ class ZipReader {
|
|
|
9444
9446
|
}
|
|
9445
9447
|
}
|
|
9446
9448
|
|
|
9449
|
+
class ZipReaderStream {
|
|
9450
|
+
|
|
9451
|
+
constructor(options = {}) {
|
|
9452
|
+
const { readable, writable } = new TransformStream();
|
|
9453
|
+
const gen = new ZipReader(readable, options).getEntriesGenerator();
|
|
9454
|
+
this.readable = new ReadableStream({
|
|
9455
|
+
async pull(controller) {
|
|
9456
|
+
const { done, value } = await gen.next();
|
|
9457
|
+
if (done)
|
|
9458
|
+
return controller.close();
|
|
9459
|
+
const chunk = {
|
|
9460
|
+
...value,
|
|
9461
|
+
readable: (function () {
|
|
9462
|
+
const { readable, writable } = new TransformStream();
|
|
9463
|
+
if (value.getData) {
|
|
9464
|
+
value.getData(writable);
|
|
9465
|
+
return readable;
|
|
9466
|
+
}
|
|
9467
|
+
})()
|
|
9468
|
+
};
|
|
9469
|
+
delete chunk.getData;
|
|
9470
|
+
controller.enqueue(chunk);
|
|
9471
|
+
}
|
|
9472
|
+
});
|
|
9473
|
+
this.writable = writable;
|
|
9474
|
+
}
|
|
9475
|
+
}
|
|
9476
|
+
|
|
9447
9477
|
class ZipEntry$1 {
|
|
9448
9478
|
|
|
9449
9479
|
constructor(reader, config, options) {
|
|
@@ -9833,8 +9863,8 @@ function getDataView$1(array) {
|
|
|
9833
9863
|
1. Redistributions of source code must retain the above copyright notice,
|
|
9834
9864
|
this list of conditions and the following disclaimer.
|
|
9835
9865
|
|
|
9836
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
9837
|
-
notice, this list of conditions and the following disclaimer in
|
|
9866
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
9867
|
+
notice, this list of conditions and the following disclaimer in
|
|
9838
9868
|
the documentation and/or other materials provided with the distribution.
|
|
9839
9869
|
|
|
9840
9870
|
3. The names of the authors may not be used to endorse or promote products
|
|
@@ -9871,9 +9901,12 @@ class ZipWriter {
|
|
|
9871
9901
|
|
|
9872
9902
|
constructor(writer, options = {}) {
|
|
9873
9903
|
writer = initWriter(writer);
|
|
9904
|
+
const addSplitZipSignature =
|
|
9905
|
+
writer.availableSize !== UNDEFINED_VALUE && writer.availableSize > 0 && writer.availableSize !== Infinity &&
|
|
9906
|
+
writer.maxSize !== UNDEFINED_VALUE && writer.maxSize > 0 && writer.maxSize !== Infinity;
|
|
9874
9907
|
Object.assign(this, {
|
|
9875
9908
|
writer,
|
|
9876
|
-
addSplitZipSignature
|
|
9909
|
+
addSplitZipSignature,
|
|
9877
9910
|
options,
|
|
9878
9911
|
config: getConfiguration(),
|
|
9879
9912
|
files: new Map(),
|
|
@@ -9936,6 +9969,33 @@ class ZipWriter {
|
|
|
9936
9969
|
}
|
|
9937
9970
|
}
|
|
9938
9971
|
|
|
9972
|
+
class ZipWriterStream {
|
|
9973
|
+
|
|
9974
|
+
constructor(options = {}) {
|
|
9975
|
+
const { readable, writable } = new TransformStream();
|
|
9976
|
+
this.readable = readable;
|
|
9977
|
+
this.zipWriter = new ZipWriter(writable, options);
|
|
9978
|
+
}
|
|
9979
|
+
|
|
9980
|
+
transform(path) {
|
|
9981
|
+
const { readable, writable } = new TransformStream({
|
|
9982
|
+
flush: () => { this.zipWriter.close(); }
|
|
9983
|
+
});
|
|
9984
|
+
this.zipWriter.add(path, readable);
|
|
9985
|
+
return { readable: this.readable, writable };
|
|
9986
|
+
}
|
|
9987
|
+
|
|
9988
|
+
writable(path) {
|
|
9989
|
+
const { readable, writable } = new TransformStream();
|
|
9990
|
+
this.zipWriter.add(path, readable);
|
|
9991
|
+
return writable;
|
|
9992
|
+
}
|
|
9993
|
+
|
|
9994
|
+
close(comment = undefined, options = {}) {
|
|
9995
|
+
return this.zipWriter.close(comment, options);
|
|
9996
|
+
}
|
|
9997
|
+
}
|
|
9998
|
+
|
|
9939
9999
|
async function addFile(zipWriter, name, reader, options) {
|
|
9940
10000
|
name = name.trim();
|
|
9941
10001
|
if (options.directory && (!name.endsWith(DIRECTORY_SIGNATURE))) {
|
|
@@ -10106,6 +10166,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
10106
10166
|
let writingBufferedEntryData;
|
|
10107
10167
|
let writingEntryData;
|
|
10108
10168
|
let fileWriter;
|
|
10169
|
+
let blobPromise;
|
|
10109
10170
|
files.set(name, fileEntry);
|
|
10110
10171
|
try {
|
|
10111
10172
|
let lockPreviousFileEntry;
|
|
@@ -10114,7 +10175,8 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
10114
10175
|
requestLockCurrentFileEntry();
|
|
10115
10176
|
}
|
|
10116
10177
|
if ((options.bufferedWrite || zipWriter.writerLocked || (zipWriter.bufferedWrites && keepOrder) || !dataDescriptor) && !usdz) {
|
|
10117
|
-
fileWriter = new
|
|
10178
|
+
fileWriter = new TransformStream();
|
|
10179
|
+
blobPromise = new Response(fileWriter.readable).blob();
|
|
10118
10180
|
fileWriter.writable.size = 0;
|
|
10119
10181
|
bufferedWrite = true;
|
|
10120
10182
|
zipWriter.bufferedWrites++;
|
|
@@ -10150,7 +10212,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
10150
10212
|
fileEntry.filename = name;
|
|
10151
10213
|
if (bufferedWrite) {
|
|
10152
10214
|
await fileWriter.writable.getWriter().close();
|
|
10153
|
-
let blob = await
|
|
10215
|
+
let blob = await blobPromise;
|
|
10154
10216
|
await lockPreviousFileEntry;
|
|
10155
10217
|
await requestLockWriter();
|
|
10156
10218
|
writingBufferedEntryData = true;
|
|
@@ -11741,8 +11803,8 @@ function addChild(parent, name, params, directory) {
|
|
|
11741
11803
|
1. Redistributions of source code must retain the above copyright notice,
|
|
11742
11804
|
this list of conditions and the following disclaimer.
|
|
11743
11805
|
|
|
11744
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
11745
|
-
notice, this list of conditions and the following disclaimer in
|
|
11806
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
11807
|
+
notice, this list of conditions and the following disclaimer in
|
|
11746
11808
|
the documentation and/or other materials provided with the distribution.
|
|
11747
11809
|
|
|
11748
11810
|
3. The names of the authors may not be used to endorse or promote products
|
|
@@ -11814,7 +11876,9 @@ exports.Uint8ArrayReader = Uint8ArrayReader;
|
|
|
11814
11876
|
exports.Uint8ArrayWriter = Uint8ArrayWriter;
|
|
11815
11877
|
exports.Writer = Writer;
|
|
11816
11878
|
exports.ZipReader = ZipReader;
|
|
11879
|
+
exports.ZipReaderStream = ZipReaderStream;
|
|
11817
11880
|
exports.ZipWriter = ZipWriter;
|
|
11881
|
+
exports.ZipWriterStream = ZipWriterStream;
|
|
11818
11882
|
exports.configure = configure;
|
|
11819
11883
|
exports.fs = fs;
|
|
11820
11884
|
exports.getMimeType = getMimeType;
|
package/index.d.ts
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Represents the `FileSystemEntry` class.
|
|
3
|
+
*
|
|
4
|
+
* @see {@link https://wicg.github.io/entries-api/#api-entry|specification}
|
|
3
5
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
* @see {@link https://fs.spec.whatwg.org/#api-filesystemhandle}
|
|
16
|
-
*/
|
|
17
|
-
// deno-lint-ignore no-empty-interface
|
|
18
|
-
interface FileSystemHandle {}
|
|
19
|
-
}
|
|
6
|
+
// deno-lint-ignore no-empty-interface
|
|
7
|
+
interface FileSystemEntry {}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Represents the `FileSystemHandle` class.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://fs.spec.whatwg.org/#api-filesystemhandle}
|
|
13
|
+
*/
|
|
14
|
+
// deno-lint-ignore no-empty-interface
|
|
15
|
+
interface FileSystemHandle {}
|
|
20
16
|
|
|
21
17
|
/**
|
|
22
18
|
* Represents a generic `TransformStream` class.
|
|
@@ -38,7 +34,7 @@ export function configure(configuration: Configuration): void;
|
|
|
38
34
|
/**
|
|
39
35
|
* Represents the configuration passed to {@link configure}.
|
|
40
36
|
*/
|
|
41
|
-
interface Configuration extends WorkerConfiguration {
|
|
37
|
+
export interface Configuration extends WorkerConfiguration {
|
|
42
38
|
/**
|
|
43
39
|
* The maximum number of web workers used to compress/decompress data simultaneously.
|
|
44
40
|
*
|
|
@@ -126,7 +122,7 @@ interface Configuration extends WorkerConfiguration {
|
|
|
126
122
|
/**
|
|
127
123
|
* Represents configuration passed to {@link configure}, the constructor of {@link ZipReader}, {@link Entry#getData}, the constructor of {@link ZipWriter}, and {@link ZipWriter#add}.
|
|
128
124
|
*/
|
|
129
|
-
interface WorkerConfiguration {
|
|
125
|
+
export interface WorkerConfiguration {
|
|
130
126
|
/**
|
|
131
127
|
* `true` to use web workers to compress/decompress data in non-blocking background processes.
|
|
132
128
|
*
|
|
@@ -158,7 +154,7 @@ export function initShimAsyncCodec(
|
|
|
158
154
|
/**
|
|
159
155
|
* Represents the callback function used to register the `data` event handler.
|
|
160
156
|
*/
|
|
161
|
-
interface registerDataHandler {
|
|
157
|
+
export interface registerDataHandler {
|
|
162
158
|
/**
|
|
163
159
|
* @param codec The third-party codec instance.
|
|
164
160
|
* @param onData The `data` event handler.
|
|
@@ -169,7 +165,7 @@ interface registerDataHandler {
|
|
|
169
165
|
/**
|
|
170
166
|
* Represents the callback function used to handle `data` events.
|
|
171
167
|
*/
|
|
172
|
-
interface dataHandler {
|
|
168
|
+
export interface dataHandler {
|
|
173
169
|
/**
|
|
174
170
|
* @param data The processed chunk of data.
|
|
175
171
|
*/
|
|
@@ -184,7 +180,7 @@ export function terminateWorkers(): Promise<void>;
|
|
|
184
180
|
/**
|
|
185
181
|
* Represents event-based implementations used to compress/decompress data.
|
|
186
182
|
*/
|
|
187
|
-
interface EventBasedZipLibrary {
|
|
183
|
+
export interface EventBasedZipLibrary {
|
|
188
184
|
/**
|
|
189
185
|
* The class used to compress data.
|
|
190
186
|
*/
|
|
@@ -216,7 +212,7 @@ declare class EventBasedCodec {
|
|
|
216
212
|
/**
|
|
217
213
|
* Represents the implementations zip.js uses to compress/decompress data.
|
|
218
214
|
*/
|
|
219
|
-
interface ZipLibrary {
|
|
215
|
+
export interface ZipLibrary {
|
|
220
216
|
/**
|
|
221
217
|
* The class used to compress data.
|
|
222
218
|
*
|
|
@@ -242,7 +238,7 @@ declare class SyncCodec {
|
|
|
242
238
|
}
|
|
243
239
|
|
|
244
240
|
/**
|
|
245
|
-
* Represents an
|
|
241
|
+
* Represents an instance used to compress data.
|
|
246
242
|
*/
|
|
247
243
|
declare class ZipDeflate extends SyncCodec {
|
|
248
244
|
/**
|
|
@@ -282,7 +278,7 @@ export function getMimeType(fileExtension: string): string;
|
|
|
282
278
|
* zip.js can handle multiple types of data thanks to a generic API. This feature is based on 2 abstract constructors: {@link Reader} and {@link Writer}.
|
|
283
279
|
* The classes inheriting from {@link Reader} help to read data from a source of data. The classes inheriting from {@link Writer} help to write data into a destination.
|
|
284
280
|
*/
|
|
285
|
-
interface Initializable {
|
|
281
|
+
export interface Initializable {
|
|
286
282
|
/**
|
|
287
283
|
* Initializes the instance asynchronously
|
|
288
284
|
*/
|
|
@@ -292,7 +288,7 @@ interface Initializable {
|
|
|
292
288
|
/**
|
|
293
289
|
* Represents an instance used to read data from a `ReadableStream` instance.
|
|
294
290
|
*/
|
|
295
|
-
interface ReadableReader {
|
|
291
|
+
export interface ReadableReader {
|
|
296
292
|
/**
|
|
297
293
|
* The `ReadableStream` instance.
|
|
298
294
|
*/
|
|
@@ -424,7 +420,7 @@ export class HttpRangeReader extends HttpReader {
|
|
|
424
420
|
/**
|
|
425
421
|
* Represents the options passed to the constructor of {@link HttpReader}.
|
|
426
422
|
*/
|
|
427
|
-
interface HttpOptions extends HttpRangeOptions {
|
|
423
|
+
export interface HttpOptions extends HttpRangeOptions {
|
|
428
424
|
/**
|
|
429
425
|
* `true` to use `Range` headers when fetching data from servers returning `Accept-Ranges` headers.
|
|
430
426
|
*
|
|
@@ -448,7 +444,7 @@ interface HttpOptions extends HttpRangeOptions {
|
|
|
448
444
|
/**
|
|
449
445
|
* Represents options passed to the constructor of {@link HttpRangeReader} and {@link HttpReader}.
|
|
450
446
|
*/
|
|
451
|
-
interface HttpRangeOptions {
|
|
447
|
+
export interface HttpRangeOptions {
|
|
452
448
|
/**
|
|
453
449
|
* `true` to rely `XMLHttpRequest` instead of `fetch` to fetch data.
|
|
454
450
|
*
|
|
@@ -464,7 +460,7 @@ interface HttpRangeOptions {
|
|
|
464
460
|
/**
|
|
465
461
|
* Represents an instance used to write data into a `WritableStream` instance.
|
|
466
462
|
*/
|
|
467
|
-
interface WritableWriter {
|
|
463
|
+
export interface WritableWriter {
|
|
468
464
|
/**
|
|
469
465
|
* The `WritableStream` instance.
|
|
470
466
|
*/
|
|
@@ -599,7 +595,7 @@ export class SplitDataWriter implements Initializable, WritableWriter {
|
|
|
599
595
|
/**
|
|
600
596
|
* Creates the {@link SplitDataWriter} instance
|
|
601
597
|
*
|
|
602
|
-
* @param writerGenerator A generator of Writer
|
|
598
|
+
* @param writerGenerator A generator of Writer instances.
|
|
603
599
|
* @param maxSize The maximum size of the data written into {@link Writer} instances (default: 4GB).
|
|
604
600
|
*/
|
|
605
601
|
constructor(
|
|
@@ -616,6 +612,42 @@ export class SplitDataWriter implements Initializable, WritableWriter {
|
|
|
616
612
|
*/
|
|
617
613
|
export class Uint8ArrayWriter extends Writer<Uint8Array> {}
|
|
618
614
|
|
|
615
|
+
/**
|
|
616
|
+
* Represents an instance used to create an unzipped stream.
|
|
617
|
+
*
|
|
618
|
+
* @example
|
|
619
|
+
* This example will take a zip file, decompress it and then recompress each file in it, saving it to disk.
|
|
620
|
+
* ```
|
|
621
|
+
* for await (const entry of (await fetch(urlToZippedFile)).body.pipeThrough(new ZipWriterStream()))
|
|
622
|
+
* if (entry.readable) {
|
|
623
|
+
* console.log(entry.filename)
|
|
624
|
+
* entry.readable
|
|
625
|
+
* .pipeThrough(ZipReaderStream().transform(entry.filename))
|
|
626
|
+
* .pipeTo((await Deno.create(entry.filename + '.zip')).writable)
|
|
627
|
+
* }
|
|
628
|
+
* ```
|
|
629
|
+
*/
|
|
630
|
+
export class ZipReaderStream<T> {
|
|
631
|
+
/**
|
|
632
|
+
* Creates the stream.
|
|
633
|
+
*
|
|
634
|
+
* @param options The options.
|
|
635
|
+
*/
|
|
636
|
+
constructor(options?: ZipReaderConstructorOptions);
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* The readable stream.
|
|
640
|
+
*/
|
|
641
|
+
readable: ReadableStream<
|
|
642
|
+
Omit<Entry, "getData"> & { readable?: ReadableStream<Uint8Array> }
|
|
643
|
+
>;
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* The writable stream.
|
|
647
|
+
*/
|
|
648
|
+
writable: WritableStream<T>;
|
|
649
|
+
}
|
|
650
|
+
|
|
619
651
|
/**
|
|
620
652
|
* Represents an instance used to read a zip file.
|
|
621
653
|
*
|
|
@@ -688,7 +720,7 @@ export class ZipReader<Type> {
|
|
|
688
720
|
* Returns a generator used to iterate on all the entries in the zip file
|
|
689
721
|
*
|
|
690
722
|
* @param options The options.
|
|
691
|
-
* @returns An
|
|
723
|
+
* @returns An asynchronous generator of {@link Entry} instances.
|
|
692
724
|
*/
|
|
693
725
|
getEntriesGenerator(
|
|
694
726
|
options?: ZipReaderGetEntriesOptions,
|
|
@@ -702,7 +734,7 @@ export class ZipReader<Type> {
|
|
|
702
734
|
/**
|
|
703
735
|
* Represents the options passed to the constructor of {@link ZipReader}, and `{@link ZipDirectory}#import*`.
|
|
704
736
|
*/
|
|
705
|
-
interface ZipReaderConstructorOptions
|
|
737
|
+
export interface ZipReaderConstructorOptions
|
|
706
738
|
extends ZipReaderOptions, GetEntriesOptions, WorkerConfiguration {
|
|
707
739
|
/**
|
|
708
740
|
* `true` to extract the prepended data into {@link ZipReader#prependedData}.
|
|
@@ -721,13 +753,13 @@ interface ZipReaderConstructorOptions
|
|
|
721
753
|
/**
|
|
722
754
|
* Represents the options passed to {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
|
|
723
755
|
*/
|
|
724
|
-
interface ZipReaderGetEntriesOptions
|
|
756
|
+
export interface ZipReaderGetEntriesOptions
|
|
725
757
|
extends GetEntriesOptions, EntryOnprogressOptions {}
|
|
726
758
|
|
|
727
759
|
/**
|
|
728
760
|
* Represents options passed to the constructor of {@link ZipReader}, {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
|
|
729
761
|
*/
|
|
730
|
-
interface GetEntriesOptions {
|
|
762
|
+
export interface GetEntriesOptions {
|
|
731
763
|
/**
|
|
732
764
|
* The encoding of the filename of the entry.
|
|
733
765
|
*/
|
|
@@ -741,7 +773,7 @@ interface GetEntriesOptions {
|
|
|
741
773
|
/**
|
|
742
774
|
* Represents options passed to the constructor of {@link ZipReader} and {@link Entry#getData}.
|
|
743
775
|
*/
|
|
744
|
-
interface ZipReaderCheckPasswordOptions {
|
|
776
|
+
export interface ZipReaderCheckPasswordOptions {
|
|
745
777
|
/**
|
|
746
778
|
* `true` to check only if the password is valid.
|
|
747
779
|
*
|
|
@@ -753,7 +785,7 @@ interface ZipReaderCheckPasswordOptions {
|
|
|
753
785
|
/**
|
|
754
786
|
* Represents options passed to the constructor of {@link ZipReader} and {@link Entry#getData}.
|
|
755
787
|
*/
|
|
756
|
-
interface ZipReaderOptions {
|
|
788
|
+
export interface ZipReaderOptions {
|
|
757
789
|
/**
|
|
758
790
|
* `true` to check the signature of the entry.
|
|
759
791
|
*
|
|
@@ -938,15 +970,100 @@ export interface Entry extends EntryMetaData {
|
|
|
938
970
|
/**
|
|
939
971
|
* Represents the options passed to {@link Entry#getData} and `{@link ZipFileEntry}.get*`.
|
|
940
972
|
*/
|
|
941
|
-
interface EntryGetDataOptions
|
|
973
|
+
export interface EntryGetDataOptions
|
|
942
974
|
extends EntryDataOnprogressOptions, ZipReaderOptions, WorkerConfiguration {}
|
|
943
975
|
|
|
944
976
|
/**
|
|
945
977
|
* Represents the options passed to {@link Entry#getData} and `{@link ZipFileEntry}.get*`.
|
|
946
978
|
*/
|
|
947
|
-
interface EntryGetDataCheckPasswordOptions
|
|
979
|
+
export interface EntryGetDataCheckPasswordOptions
|
|
948
980
|
extends EntryGetDataOptions, ZipReaderCheckPasswordOptions {}
|
|
949
981
|
|
|
982
|
+
/**
|
|
983
|
+
* Represents an instance used to create a zipped stream.
|
|
984
|
+
*
|
|
985
|
+
* @example
|
|
986
|
+
* This example creates a zipped file called numbers.txt.zip containing the numbers 0 - 1000 each on their own line.
|
|
987
|
+
* ```
|
|
988
|
+
* const readable = ReadableStream.from((function* () {
|
|
989
|
+
* for (let i = 0; i < 1000; ++i)
|
|
990
|
+
* yield i + '\n'
|
|
991
|
+
* })())
|
|
992
|
+
*
|
|
993
|
+
* readable
|
|
994
|
+
* .pipeThrough(new ZipWriterStream().transform('numbers.txt'))
|
|
995
|
+
* .pipeTo((await Deno.create('numbers.txt.zip')).writable)
|
|
996
|
+
* ```
|
|
997
|
+
*
|
|
998
|
+
* @example
|
|
999
|
+
* This example creates a zipped file called Archive.zip containing two files called numbers.txt and letters.txt
|
|
1000
|
+
* ```
|
|
1001
|
+
* const readable1 = ReadableStream.from((function* () {
|
|
1002
|
+
* for (let i = 0; i < 1000; ++i)
|
|
1003
|
+
* yield i + '\n'
|
|
1004
|
+
* })())
|
|
1005
|
+
* const readable2 = ReadableStream.from((function* () {
|
|
1006
|
+
* const letters = 'abcdefghijklmnopqrstuvwxyz'.split('')
|
|
1007
|
+
* while (letters.length)
|
|
1008
|
+
* yield letters.shift() + '\n'
|
|
1009
|
+
* })())
|
|
1010
|
+
*
|
|
1011
|
+
* const zipper = new ZipWriterStream()
|
|
1012
|
+
* zipper.readable.pipeTo((await Deno.create('Archive.zip')).writable)
|
|
1013
|
+
* readable1.pipeTo(zipper.writable('numbers.txt'))
|
|
1014
|
+
* readable2.pipeTo(zipper.writable('letters.txt'))
|
|
1015
|
+
* zipper.close()
|
|
1016
|
+
* ```
|
|
1017
|
+
*/
|
|
1018
|
+
export class ZipWriterStream {
|
|
1019
|
+
/**
|
|
1020
|
+
* Creates the stream.
|
|
1021
|
+
*
|
|
1022
|
+
* @param options The options.
|
|
1023
|
+
*/
|
|
1024
|
+
constructor(options?: ZipWriterConstructorOptions);
|
|
1025
|
+
|
|
1026
|
+
/**
|
|
1027
|
+
* The readable stream.
|
|
1028
|
+
*/
|
|
1029
|
+
readable: ReadableStream<Uint8Array>;
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* The ZipWriter property.
|
|
1033
|
+
*/
|
|
1034
|
+
zipWriter: ZipWriter<unknown>;
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* Returns an object containing a readable and writable property for the .pipeThrough method
|
|
1038
|
+
*
|
|
1039
|
+
* @param path The name of the stream when unzipped.
|
|
1040
|
+
* @returns An object containing readable and writable properties
|
|
1041
|
+
*/
|
|
1042
|
+
transform<T>(
|
|
1043
|
+
path: string,
|
|
1044
|
+
): { readable: ReadableStream<T>; writable: WritableStream<T> };
|
|
1045
|
+
|
|
1046
|
+
/**
|
|
1047
|
+
* Returns a WritableStream for the .pipeTo method
|
|
1048
|
+
*
|
|
1049
|
+
* @param path The directory path of where the stream should exist in the zipped stream.
|
|
1050
|
+
* @returns A WritableStream.
|
|
1051
|
+
*/
|
|
1052
|
+
writable<T>(path: string): WritableStream<T>;
|
|
1053
|
+
|
|
1054
|
+
/**
|
|
1055
|
+
* Writes the entries directory, writes the global comment, and returns the content of the zipped file.
|
|
1056
|
+
*
|
|
1057
|
+
* @param comment The global comment of the zip file.
|
|
1058
|
+
* @param options The options.
|
|
1059
|
+
* @returns The content of the zip file.
|
|
1060
|
+
*/
|
|
1061
|
+
close(
|
|
1062
|
+
comment?: Uint8Array,
|
|
1063
|
+
options?: ZipWriterCloseOptions,
|
|
1064
|
+
): Promise<unknown>;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
950
1067
|
/**
|
|
951
1068
|
* Represents an instance used to create a zip file.
|
|
952
1069
|
*
|
|
@@ -1021,7 +1138,7 @@ export class ZipWriter<Type> {
|
|
|
1021
1138
|
/**
|
|
1022
1139
|
* Represents the options passed to {@link ZipWriter#add}.
|
|
1023
1140
|
*/
|
|
1024
|
-
interface ZipWriterAddDataOptions
|
|
1141
|
+
export interface ZipWriterAddDataOptions
|
|
1025
1142
|
extends
|
|
1026
1143
|
ZipWriterConstructorOptions,
|
|
1027
1144
|
EntryDataOnprogressOptions,
|
|
@@ -1045,7 +1162,7 @@ interface ZipWriterAddDataOptions
|
|
|
1045
1162
|
/**
|
|
1046
1163
|
* Represents the options passed to {@link ZipWriter#close}.
|
|
1047
1164
|
*/
|
|
1048
|
-
interface ZipWriterCloseOptions extends EntryOnprogressOptions {
|
|
1165
|
+
export interface ZipWriterCloseOptions extends EntryOnprogressOptions {
|
|
1049
1166
|
/**
|
|
1050
1167
|
* `true` to use Zip64 to write the entries directory.
|
|
1051
1168
|
*
|
|
@@ -1063,7 +1180,7 @@ interface ZipWriterCloseOptions extends EntryOnprogressOptions {
|
|
|
1063
1180
|
/**
|
|
1064
1181
|
* Represents options passed to the constructor of {@link ZipWriter}, {@link ZipWriter#add} and `{@link ZipDirectoryEntry}#export*`.
|
|
1065
1182
|
*/
|
|
1066
|
-
interface ZipWriterConstructorOptions {
|
|
1183
|
+
export interface ZipWriterConstructorOptions {
|
|
1067
1184
|
/**
|
|
1068
1185
|
* `true` to use Zip64 to store the entry.
|
|
1069
1186
|
*
|
|
@@ -1218,7 +1335,7 @@ interface ZipWriterConstructorOptions {
|
|
|
1218
1335
|
/**
|
|
1219
1336
|
* Represents options passed to {@link Entry#getData}, {@link ZipWriter.add} and `{@link ZipDirectory}.export*`.
|
|
1220
1337
|
*/
|
|
1221
|
-
interface EntryDataOnprogressOptions {
|
|
1338
|
+
export interface EntryDataOnprogressOptions {
|
|
1222
1339
|
/**
|
|
1223
1340
|
* The function called when starting compression/decompression.
|
|
1224
1341
|
*
|
|
@@ -1246,7 +1363,7 @@ interface EntryDataOnprogressOptions {
|
|
|
1246
1363
|
/**
|
|
1247
1364
|
* Represents options passed to {@link ZipReader#getEntries}, {@link ZipReader#getEntriesGenerator}, and {@link ZipWriter#close}.
|
|
1248
1365
|
*/
|
|
1249
|
-
interface EntryOnprogressOptions {
|
|
1366
|
+
export interface EntryOnprogressOptions {
|
|
1250
1367
|
/**
|
|
1251
1368
|
* The function called each time an entry is read/written.
|
|
1252
1369
|
*
|
|
@@ -1324,7 +1441,7 @@ declare class ZipEntry {
|
|
|
1324
1441
|
/**
|
|
1325
1442
|
* Set the name of the entry
|
|
1326
1443
|
*
|
|
1327
|
-
* @param name The new name of the
|
|
1444
|
+
* @param name The new name of the entry.
|
|
1328
1445
|
*/
|
|
1329
1446
|
rename(name: string): void;
|
|
1330
1447
|
}
|
|
@@ -1487,7 +1604,7 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
1487
1604
|
options?: ZipWriterAddDataOptions,
|
|
1488
1605
|
): ZipFileEntry<string, string>;
|
|
1489
1606
|
/**
|
|
1490
|
-
* Adds
|
|
1607
|
+
* Adds a entry entry with content provided as a `Blob` instance
|
|
1491
1608
|
*
|
|
1492
1609
|
* @param name The relative filename of the entry.
|
|
1493
1610
|
* @param blob The `Blob` instance.
|
|
@@ -1500,7 +1617,7 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
1500
1617
|
options?: ZipWriterAddDataOptions,
|
|
1501
1618
|
): ZipFileEntry<Blob, Blob>;
|
|
1502
1619
|
/**
|
|
1503
|
-
* Adds
|
|
1620
|
+
* Adds a entry entry with content provided as a Data URI `string` encoded in Base64
|
|
1504
1621
|
*
|
|
1505
1622
|
* @param name The relative filename of the entry.
|
|
1506
1623
|
* @param dataURI The Data URI `string` encoded in Base64.
|
|
@@ -1539,7 +1656,7 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
1539
1656
|
options?: HttpOptions & ZipWriterAddDataOptions,
|
|
1540
1657
|
): ZipFileEntry<string, void>;
|
|
1541
1658
|
/**
|
|
1542
|
-
* Adds
|
|
1659
|
+
* Adds a entry entry with content provided via a `ReadableStream` instance
|
|
1543
1660
|
*
|
|
1544
1661
|
* @param name The relative filename of the entry.
|
|
1545
1662
|
* @param readable The `ReadableStream` instance.
|
|
@@ -1704,13 +1821,13 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
1704
1821
|
/**
|
|
1705
1822
|
* Represents the options passed to {@link ZipDirectoryEntry#importHttpContent}.
|
|
1706
1823
|
*/
|
|
1707
|
-
interface ZipDirectoryEntryImportHttpOptions
|
|
1824
|
+
export interface ZipDirectoryEntryImportHttpOptions
|
|
1708
1825
|
extends ZipReaderConstructorOptions, HttpOptions {}
|
|
1709
1826
|
|
|
1710
1827
|
/**
|
|
1711
1828
|
* Represents the options passed to `{@link ZipDirectoryEntry}#export*()`.
|
|
1712
1829
|
*/
|
|
1713
|
-
interface ZipDirectoryEntryExportOptions
|
|
1830
|
+
export interface ZipDirectoryEntryExportOptions
|
|
1714
1831
|
extends ZipWriterConstructorOptions, EntryDataOnprogressOptions {
|
|
1715
1832
|
/**
|
|
1716
1833
|
* `true` to use filenames relative to the entry instead of full filenames.
|
package/index.js
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
1. Redistributions of source code must retain the above copyright notice,
|
|
10
10
|
this list of conditions and the following disclaimer.
|
|
11
11
|
|
|
12
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
13
|
-
notice, this list of conditions and the following disclaimer in
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
13
|
+
notice, this list of conditions and the following disclaimer in
|
|
14
14
|
the documentation and/or other materials provided with the distribution.
|
|
15
15
|
|
|
16
16
|
3. The names of the authors may not be used to endorse or promote products
|
|
@@ -42,6 +42,8 @@ export {
|
|
|
42
42
|
initShimAsyncCodec,
|
|
43
43
|
ZipReader,
|
|
44
44
|
ZipWriter,
|
|
45
|
+
ZipReaderStream,
|
|
46
|
+
ZipWriterStream,
|
|
45
47
|
Reader,
|
|
46
48
|
Writer,
|
|
47
49
|
TextReader,
|
|
@@ -83,4 +85,4 @@ export {
|
|
|
83
85
|
ERR_SPLIT_ZIP_FILE,
|
|
84
86
|
ERR_ITERATOR_COMPLETED_TOO_SOON
|
|
85
87
|
} from "./lib/zip-fs.js";
|
|
86
|
-
export { getMimeType, terminateWorkers };
|
|
88
|
+
export { getMimeType, terminateWorkers };
|