@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/lib/core/codec-pool.js
CHANGED
|
@@ -32,8 +32,7 @@ import {
|
|
|
32
32
|
CODEC_INFLATE,
|
|
33
33
|
CODEC_DEFLATE,
|
|
34
34
|
ERR_INVALID_SIGNATURE,
|
|
35
|
-
ERR_INVALID_PASSWORD
|
|
36
|
-
ERR_ABORT
|
|
35
|
+
ERR_INVALID_PASSWORD
|
|
37
36
|
} from "./codec-interface.js";
|
|
38
37
|
import { CodecWorker } from "./codec-pool-worker.js";
|
|
39
38
|
|
|
@@ -46,14 +45,13 @@ export {
|
|
|
46
45
|
CODEC_DEFLATE,
|
|
47
46
|
CODEC_INFLATE,
|
|
48
47
|
ERR_INVALID_SIGNATURE,
|
|
49
|
-
ERR_INVALID_PASSWORD
|
|
50
|
-
ERR_ABORT
|
|
48
|
+
ERR_INVALID_PASSWORD
|
|
51
49
|
};
|
|
52
50
|
|
|
53
51
|
let indexWorker = 0;
|
|
54
52
|
|
|
55
53
|
async function runWorker(stream, workerOptions) {
|
|
56
|
-
const { options, config
|
|
54
|
+
const { options, config } = workerOptions;
|
|
57
55
|
const streamCopy = !options.compressed && !options.signed && !options.encrypted;
|
|
58
56
|
const { useWebWorkers, useCompressionStream, codecType } = options;
|
|
59
57
|
const { workerScripts } = config;
|
|
@@ -75,16 +73,7 @@ async function runWorker(stream, workerOptions) {
|
|
|
75
73
|
worker = await new Promise(resolve => pendingRequests.push({ resolve, stream, workerOptions }));
|
|
76
74
|
}
|
|
77
75
|
}
|
|
78
|
-
|
|
79
|
-
return await worker.run();
|
|
80
|
-
} catch (error) {
|
|
81
|
-
const { signal } = streamOptions;
|
|
82
|
-
if (signal && signal.aborted && (signal.reason == error || error.name == ERR_ABORT)) {
|
|
83
|
-
throw new Error(ERR_ABORT);
|
|
84
|
-
} else {
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
76
|
+
return worker.run();
|
|
88
77
|
|
|
89
78
|
function onTaskFinished(workerData) {
|
|
90
79
|
if (pendingRequests.length) {
|
package/lib/core/io.js
CHANGED
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
|
|
31
31
|
const ERR_HTTP_STATUS = "HTTP error ";
|
|
32
32
|
const ERR_HTTP_RANGE = "HTTP Range not supported";
|
|
33
|
-
const ERR_NOT_SEEKABLE_READER = "Reader is not seekable";
|
|
34
33
|
|
|
35
34
|
const CONTENT_TYPE_TEXT_PLAIN = "text/plain";
|
|
36
35
|
const HTTP_HEADER_CONTENT_LENGTH = "Content-Length";
|
|
@@ -267,32 +266,6 @@ function flushArrayBuffers(blobWriter) {
|
|
|
267
266
|
blobWriter.arrayBuffers = [];
|
|
268
267
|
}
|
|
269
268
|
|
|
270
|
-
class ReadableStreamReader extends Stream {
|
|
271
|
-
|
|
272
|
-
constructor(readable) {
|
|
273
|
-
super();
|
|
274
|
-
if (!readable) {
|
|
275
|
-
this.readable = new ReadableStream({});
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
class WritableStreamWriter extends Writer {
|
|
281
|
-
|
|
282
|
-
constructor(writable, { preventClose } = {}) {
|
|
283
|
-
super();
|
|
284
|
-
this.preventClose = preventClose;
|
|
285
|
-
if (!writable) {
|
|
286
|
-
writable = new WritableStream({});
|
|
287
|
-
}
|
|
288
|
-
Object.defineProperty(this, "writable", {
|
|
289
|
-
get() {
|
|
290
|
-
return writable;
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
269
|
class FetchReader extends Reader {
|
|
297
270
|
|
|
298
271
|
constructor(url, options) {
|
|
@@ -559,8 +532,5 @@ export {
|
|
|
559
532
|
Uint8ArrayWriter,
|
|
560
533
|
HttpReader,
|
|
561
534
|
HttpRangeReader,
|
|
562
|
-
|
|
563
|
-
WritableStreamWriter,
|
|
564
|
-
ERR_HTTP_RANGE,
|
|
565
|
-
ERR_NOT_SEEKABLE_READER
|
|
535
|
+
ERR_HTTP_RANGE
|
|
566
536
|
};
|
package/lib/core/zip-fs-core.js
CHANGED
package/lib/core/zip-reader.js
CHANGED
|
@@ -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, Response */
|
|
30
30
|
|
|
31
31
|
import {
|
|
32
32
|
MAX_32_BITS,
|
|
@@ -66,6 +66,7 @@ import {
|
|
|
66
66
|
ERR_INVALID_SIGNATURE,
|
|
67
67
|
ERR_INVALID_PASSWORD
|
|
68
68
|
} from "./codec-pool.js";
|
|
69
|
+
import { BlobReader } from "./io.js";
|
|
69
70
|
import decodeText from "./util/decode-text.js";
|
|
70
71
|
import Crc32 from "./streams/codecs/crc32.js";
|
|
71
72
|
import Entry from "./zip-entry.js";
|
|
@@ -96,14 +97,19 @@ class ZipReader {
|
|
|
96
97
|
|
|
97
98
|
async* getEntriesGenerator(options = {}) {
|
|
98
99
|
const zipReader = this;
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
let { reader } = zipReader;
|
|
101
|
+
const { config } = zipReader;
|
|
102
|
+
if (!reader.initialized && reader.init) {
|
|
101
103
|
await reader.init();
|
|
102
104
|
}
|
|
103
|
-
reader.
|
|
105
|
+
if (reader.size === undefined || !reader.readUint8Array) {
|
|
106
|
+
const blob = await new Response(reader.readable).blob();
|
|
107
|
+
reader = new BlobReader(blob);
|
|
108
|
+
}
|
|
104
109
|
if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
|
|
105
110
|
throw new Error(ERR_BAD_FORMAT);
|
|
106
111
|
}
|
|
112
|
+
reader.chunkSize = getChunkSize(config);
|
|
107
113
|
const endOfDirectoryInfo = await seekSignature(reader, END_OF_CENTRAL_DIR_SIGNATURE, reader.size, END_OF_CENTRAL_DIR_LENGTH, MAX_16_BITS * 16);
|
|
108
114
|
if (!endOfDirectoryInfo) {
|
|
109
115
|
throw new Error(ERR_EOCDR_NOT_FOUND);
|
package/lib/zip-fs.js
CHANGED
|
@@ -30,10 +30,7 @@ import { configure } from "./core/configuration.js";
|
|
|
30
30
|
import configureWebWorker from "./z-worker-inline.js";
|
|
31
31
|
import { getMimeType } from "./core/util/default-mime-type.js";
|
|
32
32
|
import initShimAsyncCodec from "./core/util/stream-codec-shim.js";
|
|
33
|
-
import {
|
|
34
|
-
terminateWorkers,
|
|
35
|
-
ERR_ABORT
|
|
36
|
-
} from "./core/codec-pool.js";
|
|
33
|
+
import { terminateWorkers } from "./core/codec-pool.js";
|
|
37
34
|
|
|
38
35
|
let baseURL;
|
|
39
36
|
try {
|
|
@@ -52,6 +49,5 @@ export {
|
|
|
52
49
|
configure,
|
|
53
50
|
getMimeType,
|
|
54
51
|
initShimAsyncCodec,
|
|
55
|
-
terminateWorkers
|
|
56
|
-
ERR_ABORT
|
|
52
|
+
terminateWorkers
|
|
57
53
|
};
|
package/lib/zip-full-fflate.js
CHANGED
|
@@ -31,10 +31,7 @@ import { configure } from "./core/configuration.js";
|
|
|
31
31
|
import configureWebWorker from "./z-worker-inline.js";
|
|
32
32
|
import { getMimeType } from "./core/util/default-mime-type.js";
|
|
33
33
|
import initShimAsyncCodec from "./core/util/stream-codec-shim.js";
|
|
34
|
-
import {
|
|
35
|
-
terminateWorkers,
|
|
36
|
-
ERR_ABORT
|
|
37
|
-
} from "./core/codec-pool.js";
|
|
34
|
+
import { terminateWorkers } from "./core/codec-pool.js";
|
|
38
35
|
|
|
39
36
|
let baseURL;
|
|
40
37
|
try {
|
|
@@ -52,6 +49,5 @@ export {
|
|
|
52
49
|
configure,
|
|
53
50
|
getMimeType,
|
|
54
51
|
initShimAsyncCodec,
|
|
55
|
-
terminateWorkers
|
|
56
|
-
ERR_ABORT
|
|
52
|
+
terminateWorkers
|
|
57
53
|
};
|
package/lib/zip-full.js
CHANGED
|
@@ -32,10 +32,7 @@ import { configure } from "./core/configuration.js";
|
|
|
32
32
|
import configureWebWorker from "./z-worker-inline.js";
|
|
33
33
|
import { getMimeType } from "./core/util/default-mime-type.js";
|
|
34
34
|
import initShimAsyncCodec from "./core/util/stream-codec-shim.js";
|
|
35
|
-
import {
|
|
36
|
-
terminateWorkers,
|
|
37
|
-
ERR_ABORT
|
|
38
|
-
} from "./core/codec-pool.js";
|
|
35
|
+
import { terminateWorkers } from "./core/codec-pool.js";
|
|
39
36
|
|
|
40
37
|
let baseURL;
|
|
41
38
|
try {
|
|
@@ -53,6 +50,5 @@ export {
|
|
|
53
50
|
configure,
|
|
54
51
|
getMimeType,
|
|
55
52
|
initShimAsyncCodec,
|
|
56
|
-
terminateWorkers
|
|
57
|
-
ERR_ABORT
|
|
53
|
+
terminateWorkers
|
|
58
54
|
};
|
|
@@ -29,10 +29,7 @@
|
|
|
29
29
|
import Deflate from "./core/streams/codecs/deflate.js";
|
|
30
30
|
import { configure } from "./core/configuration.js";
|
|
31
31
|
import { getMimeType } from "./core/util/default-mime-type.js";
|
|
32
|
-
import {
|
|
33
|
-
terminateWorkers,
|
|
34
|
-
ERR_ABORT
|
|
35
|
-
} from "./core/codec-pool.js";
|
|
32
|
+
import { terminateWorkers } from "./core/codec-pool.js";
|
|
36
33
|
|
|
37
34
|
configure({ Deflate });
|
|
38
35
|
|
|
@@ -41,6 +38,5 @@ export * from "./core/zip-writer.js";
|
|
|
41
38
|
export {
|
|
42
39
|
configure,
|
|
43
40
|
getMimeType,
|
|
44
|
-
terminateWorkers
|
|
45
|
-
ERR_ABORT
|
|
41
|
+
terminateWorkers
|
|
46
42
|
};
|
|
@@ -29,10 +29,7 @@
|
|
|
29
29
|
import { Deflate } from "./zip-fflate-shim.js";
|
|
30
30
|
import { configure } from "./core/configuration.js";
|
|
31
31
|
import { getMimeType } from "./core/util/default-mime-type.js";
|
|
32
|
-
import {
|
|
33
|
-
terminateWorkers,
|
|
34
|
-
ERR_ABORT
|
|
35
|
-
} from "./core/codec-pool.js";
|
|
32
|
+
import { terminateWorkers } from "./core/codec-pool.js";
|
|
36
33
|
|
|
37
34
|
configure({ Deflate });
|
|
38
35
|
|
|
@@ -41,6 +38,5 @@ export * from "./core/zip-writer.js";
|
|
|
41
38
|
export {
|
|
42
39
|
configure,
|
|
43
40
|
getMimeType,
|
|
44
|
-
terminateWorkers
|
|
45
|
-
ERR_ABORT
|
|
41
|
+
terminateWorkers
|
|
46
42
|
};
|
|
@@ -29,10 +29,7 @@
|
|
|
29
29
|
import { Inflate } from "./zip-fflate-shim.js";
|
|
30
30
|
import { configure } from "./core/configuration.js";
|
|
31
31
|
import { getMimeType } from "./core/util/default-mime-type.js";
|
|
32
|
-
import {
|
|
33
|
-
terminateWorkers,
|
|
34
|
-
ERR_ABORT
|
|
35
|
-
} from "./core/codec-pool.js";
|
|
32
|
+
import { terminateWorkers } from "./core/codec-pool.js";
|
|
36
33
|
|
|
37
34
|
configure({ Inflate });
|
|
38
35
|
|
|
@@ -41,6 +38,5 @@ export * from "./core/zip-reader.js";
|
|
|
41
38
|
export {
|
|
42
39
|
configure,
|
|
43
40
|
getMimeType,
|
|
44
|
-
terminateWorkers
|
|
45
|
-
ERR_ABORT
|
|
41
|
+
terminateWorkers
|
|
46
42
|
};
|
|
@@ -29,10 +29,7 @@
|
|
|
29
29
|
import { Deflate, Inflate } from "./zip-fflate-shim.js";
|
|
30
30
|
import { configure } from "./core/configuration.js";
|
|
31
31
|
import { getMimeType } from "./core/util/default-mime-type.js";
|
|
32
|
-
import {
|
|
33
|
-
terminateWorkers,
|
|
34
|
-
ERR_ABORT
|
|
35
|
-
} from "./core/codec-pool.js";
|
|
32
|
+
import { terminateWorkers } from "./core/codec-pool.js";
|
|
36
33
|
|
|
37
34
|
configure({ Deflate, Inflate });
|
|
38
35
|
|
|
@@ -42,6 +39,5 @@ export * from "./core/zip-writer.js";
|
|
|
42
39
|
export {
|
|
43
40
|
configure,
|
|
44
41
|
getMimeType,
|
|
45
|
-
terminateWorkers
|
|
46
|
-
ERR_ABORT
|
|
42
|
+
terminateWorkers
|
|
47
43
|
};
|
|
@@ -29,10 +29,7 @@
|
|
|
29
29
|
import Inflate from "./core/streams/codecs/inflate.js";
|
|
30
30
|
import { configure } from "./core/configuration.js";
|
|
31
31
|
import { getMimeType } from "./core/util/default-mime-type.js";
|
|
32
|
-
import {
|
|
33
|
-
terminateWorkers,
|
|
34
|
-
ERR_ABORT
|
|
35
|
-
} from "./core/codec-pool.js";
|
|
32
|
+
import { terminateWorkers } from "./core/codec-pool.js";
|
|
36
33
|
|
|
37
34
|
configure({ Inflate });
|
|
38
35
|
|
|
@@ -41,6 +38,5 @@ export * from "./core/zip-reader.js";
|
|
|
41
38
|
export {
|
|
42
39
|
configure,
|
|
43
40
|
getMimeType,
|
|
44
|
-
terminateWorkers
|
|
45
|
-
ERR_ABORT
|
|
41
|
+
terminateWorkers
|
|
46
42
|
};
|
package/lib/zip-no-worker.js
CHANGED
|
@@ -30,10 +30,7 @@ import Deflate from "./core/streams/codecs/deflate.js";
|
|
|
30
30
|
import Inflate from "./core/streams/codecs/inflate.js";
|
|
31
31
|
import { configure } from "./core/configuration.js";
|
|
32
32
|
import { getMimeType } from "./core/util/default-mime-type.js";
|
|
33
|
-
import {
|
|
34
|
-
terminateWorkers,
|
|
35
|
-
ERR_ABORT
|
|
36
|
-
} from "./core/codec-pool.js";
|
|
33
|
+
import { terminateWorkers } from "./core/codec-pool.js";
|
|
37
34
|
|
|
38
35
|
configure({ Deflate, Inflate });
|
|
39
36
|
|
|
@@ -43,6 +40,5 @@ export * from "./core/zip-writer.js";
|
|
|
43
40
|
export {
|
|
44
41
|
configure,
|
|
45
42
|
getMimeType,
|
|
46
|
-
terminateWorkers
|
|
47
|
-
ERR_ABORT
|
|
43
|
+
terminateWorkers
|
|
48
44
|
};
|
package/lib/zip.js
CHANGED
|
@@ -30,10 +30,7 @@ import { configure } from "./core/configuration.js";
|
|
|
30
30
|
import configureWebWorker from "./z-worker-inline.js";
|
|
31
31
|
import { getMimeType } from "./core/util/default-mime-type.js";
|
|
32
32
|
import initShimAsyncCodec from "./core/util/stream-codec-shim.js";
|
|
33
|
-
import {
|
|
34
|
-
terminateWorkers,
|
|
35
|
-
ERR_ABORT
|
|
36
|
-
} from "./core/codec-pool.js";
|
|
33
|
+
import { terminateWorkers } from "./core/codec-pool.js";
|
|
37
34
|
|
|
38
35
|
let baseURL;
|
|
39
36
|
try {
|
|
@@ -51,6 +48,5 @@ export {
|
|
|
51
48
|
configure,
|
|
52
49
|
getMimeType,
|
|
53
50
|
initShimAsyncCodec,
|
|
54
|
-
terminateWorkers
|
|
55
|
-
ERR_ABORT
|
|
51
|
+
terminateWorkers
|
|
56
52
|
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* global fetch, URL */
|
|
2
|
+
|
|
3
|
+
import * as zip from "../../index.js";
|
|
4
|
+
|
|
5
|
+
const TEXT_CONTENT = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.";
|
|
6
|
+
const FILENAME = "lorem.txt";
|
|
7
|
+
|
|
8
|
+
export { test };
|
|
9
|
+
|
|
10
|
+
async function test() {
|
|
11
|
+
zip.configure({ chunkSize: 128, useWebWorkers: true });
|
|
12
|
+
const readable = (await fetch(new URL("../data/lorem.zip", import.meta.url))).body;
|
|
13
|
+
const zipReader = new zip.ZipReader({ readable });
|
|
14
|
+
const entries = await zipReader.getEntries();
|
|
15
|
+
const data = await entries[0].getData(new zip.BlobWriter(zip.getMimeType(entries[0].filename)));
|
|
16
|
+
await zipReader.close();
|
|
17
|
+
zip.terminateWorkers();
|
|
18
|
+
return TEXT_CONTENT == (await data.text()) && entries[0].uncompressedSize == TEXT_CONTENT.length && entries[0].filename == FILENAME;
|
|
19
|
+
}
|
package/tests/tests-data.js
CHANGED
|
@@ -33,6 +33,7 @@ export default ([
|
|
|
33
33
|
{ title: "Parallel writes (ordered)", script: "./test-parallel-writes-ordered.js" },
|
|
34
34
|
{ title: "Parallel writes", script: "./test-parallel-writes.js" },
|
|
35
35
|
{ title: "Readable Stream", script: "./test-readable-stream.js" },
|
|
36
|
+
{ title: "Readable Zip Stream", script: "./test-readable-zip-stream.js" },
|
|
36
37
|
{ title: "Safe closing", script: "./test-safe-closing.js" },
|
|
37
38
|
{ title: "Service worker", script: "./test-sw.js", env: "browser" },
|
|
38
39
|
{ title: "Store", script: "./test-store.js" },
|