@zip.js/zip.js 2.5.26 → 2.6.2
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 +60 -0
- package/cli-deno/mc-zip.js +1 -3
- package/dist/zip-fs-full.js +10 -46
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +10 -46
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +10 -46
- 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 +10 -46
- package/dist/zip.min.js +1 -1
- package/index-fflate.js +1 -5
- package/index.d.ts +7 -19
- package/index.js +1 -5
- package/lib/core/codec-interface.js +1 -3
- package/lib/core/codec-pool.js +4 -15
- package/lib/core/io.js +1 -31
- package/lib/core/zip-fs-core.js +0 -1
- package/lib/core/zip-reader.js +10 -4
- package/lib/zip-fs.js +2 -6
- package/lib/zip-full-fflate.js +2 -6
- package/lib/zip-full.js +2 -6
- package/lib/zip-no-worker-deflate.js +2 -6
- package/lib/zip-no-worker-fflate-deflate.js +2 -6
- package/lib/zip-no-worker-fflate-inflate.js +2 -6
- package/lib/zip-no-worker-fflate.js +2 -6
- package/lib/zip-no-worker-inflate.js +2 -6
- package/lib/zip-no-worker.js +2 -6
- package/lib/zip.js +2 -6
- package/package.json +1 -1
- package/tests/all/test-abort-signal-read.js +1 -1
- package/tests/all/test-abort-signal-write.js +1 -1
- package/tests/all/test-readable-zip-stream.js +19 -0
- package/tests/tests-data.js +1 -0
package/README.md
CHANGED
|
@@ -2,3 +2,63 @@ zip.js is an open-source library (BSD-3-Clause license) for zipping and unzippin
|
|
|
2
2
|
|
|
3
3
|
See here for more info:
|
|
4
4
|
https://gildas-lormeau.github.io/zip.js/
|
|
5
|
+
|
|
6
|
+
```js
|
|
7
|
+
// Hello world with zip.js (and Streams)
|
|
8
|
+
|
|
9
|
+
import { ZipWriter, ZipReader, BlobReader } from "https://deno.land/x/zipjs/index.js";
|
|
10
|
+
|
|
11
|
+
// ----
|
|
12
|
+
// Write the zip file
|
|
13
|
+
// ----
|
|
14
|
+
|
|
15
|
+
// Creates a TransformStream object where the zip content will be written.
|
|
16
|
+
const zipStream = new TransformStream();
|
|
17
|
+
// Creates a Promise object resolved to the zip content returned as a Blob object.
|
|
18
|
+
const zipBlobPromise = new Response(zipStream.readable).blob();
|
|
19
|
+
// Creates a ReadableStream object containing the text of the entry to add in the zip.
|
|
20
|
+
const helloWorldReadable = new Blob(["Hello world!"], { type: "text/plain" }).stream();
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
// Creates a ZipWriter object writing data via zipStream, adds the file "hello.txt" containing
|
|
24
|
+
// the text "Hello world!" via helloWorldReadable in the zip, and closes the writer.
|
|
25
|
+
const zipWriter = new ZipWriter(zipStream);
|
|
26
|
+
await zipWriter.add("hello.txt", { readable: helloWorldReadable });
|
|
27
|
+
await zipWriter.close();
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// Retrieves the Blob object containing the zip content.
|
|
31
|
+
const zipBlob = await zipBlobPromise;
|
|
32
|
+
|
|
33
|
+
// Uncomment the following code to download the zip file (in a browser)
|
|
34
|
+
//
|
|
35
|
+
// const anchorElement = document.createElement("a");
|
|
36
|
+
// anchorElement.href = URL.createObjectURL(zipBlob);
|
|
37
|
+
// anchorElement.download = "hello.zip";
|
|
38
|
+
// anchorElement.click();
|
|
39
|
+
//
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// ----
|
|
43
|
+
// Read the zip file
|
|
44
|
+
// ----
|
|
45
|
+
|
|
46
|
+
// Creates a TransformStream object where the content of the first entry in the zip will be written.
|
|
47
|
+
const contentStream = new TransformStream();
|
|
48
|
+
// Creates a Promise object resolved to the first entry content returned as text.
|
|
49
|
+
const contentTextPromise = new Response(contentStream.readable).text();
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// Reads zipBlob via a BlobReader object, retrieves metadata (name, dates, etc.) of the first entry,
|
|
53
|
+
// retrieves its content via contentStream, and closes the reader.
|
|
54
|
+
const zipReader = new ZipReader(new BlobReader(zipBlob));
|
|
55
|
+
const firstEntry = (await zipReader.getEntries()).shift();
|
|
56
|
+
await firstEntry.getData(contentStream);
|
|
57
|
+
await zipReader.close();
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
// Displays "Hello world!".
|
|
61
|
+
const contentText = await contentTextPromise;
|
|
62
|
+
console.log(contentText);
|
|
63
|
+
```
|
|
64
|
+
See here for more examples: https://github.com/gildas-lormeau/zip.js/tree/master/tests/all
|
package/cli-deno/mc-zip.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/* global Deno, fetch, URL, TextEncoderStream */
|
|
4
4
|
|
|
5
5
|
import { parse as parseArgs } from "https://deno.land/std@0.147.0/flags/mod.ts";
|
|
6
|
-
import {
|
|
6
|
+
import { normalize as normalizePath, resolve as resolvePath, extname } from "https://deno.land/std@0.147.0/path/mod.ts";
|
|
7
7
|
import { configure, ZipWriter, terminateWorkers } from "../index.js";
|
|
8
8
|
|
|
9
9
|
const args = parseArgs(Deno.args);
|
|
@@ -99,8 +99,6 @@ async function getFileInfo(file, options) {
|
|
|
99
99
|
if (!extname(name)) {
|
|
100
100
|
name += ".html";
|
|
101
101
|
}
|
|
102
|
-
} else if (file.startsWith("file:")) {
|
|
103
|
-
name = fromFileUrl(file);
|
|
104
102
|
} else {
|
|
105
103
|
name = file;
|
|
106
104
|
resolvedName = resolvePath(name);
|
package/dist/zip-fs-full.js
CHANGED
|
@@ -7017,7 +7017,6 @@
|
|
|
7017
7017
|
const MESSAGE_PULL = "pull";
|
|
7018
7018
|
const MESSAGE_DATA = "data";
|
|
7019
7019
|
const MESSAGE_CLOSE = "close";
|
|
7020
|
-
const ERR_ABORT = "AbortError";
|
|
7021
7020
|
|
|
7022
7021
|
class Codec {
|
|
7023
7022
|
|
|
@@ -7285,7 +7284,7 @@
|
|
|
7285
7284
|
let indexWorker = 0;
|
|
7286
7285
|
|
|
7287
7286
|
async function runWorker(stream, workerOptions) {
|
|
7288
|
-
const { options, config
|
|
7287
|
+
const { options, config } = workerOptions;
|
|
7289
7288
|
const streamCopy = !options.compressed && !options.signed && !options.encrypted;
|
|
7290
7289
|
const { useWebWorkers, useCompressionStream, codecType } = options;
|
|
7291
7290
|
const { workerScripts } = config;
|
|
@@ -7307,16 +7306,7 @@
|
|
|
7307
7306
|
worker = await new Promise(resolve => pendingRequests.push({ resolve, stream, workerOptions }));
|
|
7308
7307
|
}
|
|
7309
7308
|
}
|
|
7310
|
-
|
|
7311
|
-
return await worker.run();
|
|
7312
|
-
} catch (error) {
|
|
7313
|
-
const { signal } = streamOptions;
|
|
7314
|
-
if (signal && signal.aborted && (signal.reason == error || error.name == ERR_ABORT)) {
|
|
7315
|
-
throw new Error(ERR_ABORT);
|
|
7316
|
-
} else {
|
|
7317
|
-
throw error;
|
|
7318
|
-
}
|
|
7319
|
-
}
|
|
7309
|
+
return worker.run();
|
|
7320
7310
|
|
|
7321
7311
|
function onTaskFinished(workerData) {
|
|
7322
7312
|
if (pendingRequests.length) {
|
|
@@ -7463,7 +7453,6 @@
|
|
|
7463
7453
|
|
|
7464
7454
|
const ERR_HTTP_STATUS = "HTTP error ";
|
|
7465
7455
|
const ERR_HTTP_RANGE = "HTTP Range not supported";
|
|
7466
|
-
const ERR_NOT_SEEKABLE_READER = "Reader is not seekable";
|
|
7467
7456
|
|
|
7468
7457
|
const CONTENT_TYPE_TEXT_PLAIN = "text/plain";
|
|
7469
7458
|
const HTTP_HEADER_CONTENT_LENGTH = "Content-Length";
|
|
@@ -7698,32 +7687,6 @@
|
|
|
7698
7687
|
blobWriter.arrayBuffers = [];
|
|
7699
7688
|
}
|
|
7700
7689
|
|
|
7701
|
-
class ReadableStreamReader extends Stream {
|
|
7702
|
-
|
|
7703
|
-
constructor(readable) {
|
|
7704
|
-
super();
|
|
7705
|
-
if (!readable) {
|
|
7706
|
-
this.readable = new ReadableStream({});
|
|
7707
|
-
}
|
|
7708
|
-
}
|
|
7709
|
-
}
|
|
7710
|
-
|
|
7711
|
-
class WritableStreamWriter extends Writer {
|
|
7712
|
-
|
|
7713
|
-
constructor(writable, { preventClose } = {}) {
|
|
7714
|
-
super();
|
|
7715
|
-
this.preventClose = preventClose;
|
|
7716
|
-
if (!writable) {
|
|
7717
|
-
writable = new WritableStream({});
|
|
7718
|
-
}
|
|
7719
|
-
Object.defineProperty(this, "writable", {
|
|
7720
|
-
get() {
|
|
7721
|
-
return writable;
|
|
7722
|
-
}
|
|
7723
|
-
});
|
|
7724
|
-
}
|
|
7725
|
-
}
|
|
7726
|
-
|
|
7727
7690
|
class FetchReader extends Reader {
|
|
7728
7691
|
|
|
7729
7692
|
constructor(url, options) {
|
|
@@ -8219,14 +8182,19 @@
|
|
|
8219
8182
|
|
|
8220
8183
|
async* getEntriesGenerator(options = {}) {
|
|
8221
8184
|
const zipReader = this;
|
|
8222
|
-
|
|
8223
|
-
|
|
8185
|
+
let { reader } = zipReader;
|
|
8186
|
+
const { config } = zipReader;
|
|
8187
|
+
if (!reader.initialized && reader.init) {
|
|
8224
8188
|
await reader.init();
|
|
8225
8189
|
}
|
|
8226
|
-
reader.
|
|
8190
|
+
if (reader.size === undefined || !reader.readUint8Array) {
|
|
8191
|
+
const blob = await new Response(reader.readable).blob();
|
|
8192
|
+
reader = new BlobReader(blob);
|
|
8193
|
+
}
|
|
8227
8194
|
if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
|
|
8228
8195
|
throw new Error(ERR_BAD_FORMAT);
|
|
8229
8196
|
}
|
|
8197
|
+
reader.chunkSize = getChunkSize(config);
|
|
8230
8198
|
const endOfDirectoryInfo = await seekSignature(reader, END_OF_CENTRAL_DIR_SIGNATURE, reader.size, END_OF_CENTRAL_DIR_LENGTH, MAX_16_BITS * 16);
|
|
8231
8199
|
if (!endOfDirectoryInfo) {
|
|
8232
8200
|
throw new Error(ERR_EOCDR_NOT_FOUND);
|
|
@@ -10096,7 +10064,6 @@
|
|
|
10096
10064
|
exports.BlobWriter = BlobWriter;
|
|
10097
10065
|
exports.Data64URIReader = Data64URIReader;
|
|
10098
10066
|
exports.Data64URIWriter = Data64URIWriter;
|
|
10099
|
-
exports.ERR_ABORT = ERR_ABORT;
|
|
10100
10067
|
exports.ERR_BAD_FORMAT = ERR_BAD_FORMAT;
|
|
10101
10068
|
exports.ERR_CENTRAL_DIRECTORY_NOT_FOUND = ERR_CENTRAL_DIRECTORY_NOT_FOUND;
|
|
10102
10069
|
exports.ERR_DUPLICATED_NAME = ERR_DUPLICATED_NAME;
|
|
@@ -10116,19 +10083,16 @@
|
|
|
10116
10083
|
exports.ERR_INVALID_SIGNATURE = ERR_INVALID_SIGNATURE;
|
|
10117
10084
|
exports.ERR_INVALID_VERSION = ERR_INVALID_VERSION;
|
|
10118
10085
|
exports.ERR_LOCAL_FILE_HEADER_NOT_FOUND = ERR_LOCAL_FILE_HEADER_NOT_FOUND;
|
|
10119
|
-
exports.ERR_NOT_SEEKABLE_READER = ERR_NOT_SEEKABLE_READER;
|
|
10120
10086
|
exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION;
|
|
10121
10087
|
exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
|
|
10122
10088
|
exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
|
|
10123
10089
|
exports.HttpRangeReader = HttpRangeReader;
|
|
10124
10090
|
exports.HttpReader = HttpReader;
|
|
10125
|
-
exports.ReadableStreamReader = ReadableStreamReader;
|
|
10126
10091
|
exports.Reader = Reader;
|
|
10127
10092
|
exports.TextReader = TextReader;
|
|
10128
10093
|
exports.TextWriter = TextWriter;
|
|
10129
10094
|
exports.Uint8ArrayReader = Uint8ArrayReader;
|
|
10130
10095
|
exports.Uint8ArrayWriter = Uint8ArrayWriter;
|
|
10131
|
-
exports.WritableStreamWriter = WritableStreamWriter;
|
|
10132
10096
|
exports.Writer = Writer;
|
|
10133
10097
|
exports.ZipReader = ZipReader;
|
|
10134
10098
|
exports.ZipWriter = ZipWriter;
|