@zip.js/zip.js 2.8.47 → 2.8.48
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/deno.json +1 -1
- package/dist/zip-core-external.js +45 -26
- package/dist/zip-core-external.min.js +1 -1
- package/dist/zip-core.js +45 -26
- package/dist/zip-core.min.js +1 -1
- package/dist/zip-fs-core-external.js +46 -27
- package/dist/zip-fs-core-external.min.js +1 -1
- package/dist/zip-fs-core.js +29 -24
- package/dist/zip-fs-core.min.js +1 -1
- package/dist/zip-fs-external.js +46 -27
- package/dist/zip-fs-external.min.js +1 -1
- package/dist/zip-fs-native.js +46 -27
- package/dist/zip-fs-native.min.js +1 -1
- package/dist/zip-fs.js +46 -27
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-legacy.js +45 -26
- package/dist/zip-legacy.min.js +1 -1
- package/dist/zip-native.js +45 -26
- package/dist/zip-native.min.js +1 -1
- package/dist/zip.js +45 -26
- package/dist/zip.min.js +1 -1
- package/index-native.cjs +46 -27
- package/index-native.min.js +1 -1
- package/index.cjs +46 -27
- package/index.min.js +1 -1
- package/lib/core/io.js +3 -23
- package/lib/core/util/blob-temp-stream.js +4 -2
- package/lib/core/util/compatible-streams.js +30 -2
- package/lib/core/util/opfs-temp-stream.js +8 -1
- package/lib/core/util/sync-access-handle-temp-stream.js +8 -1
- package/lib/core/zip-fs.js +2 -1
- package/lib/core/zip-reader.js +4 -4
- package/package.json +2 -1
package/lib/core/io.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
-
/* global Blob, atob, btoa, XMLHttpRequest, URL, fetch, ReadableStream, WritableStream, FileReader, TransformStream
|
|
29
|
+
/* global Blob, atob, btoa, XMLHttpRequest, URL, fetch, ReadableStream, WritableStream, FileReader, TransformStream */
|
|
30
30
|
// deno-lint-ignore-file no-this-alias
|
|
31
31
|
|
|
32
32
|
import {
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
} from "./constants.js";
|
|
38
38
|
import { getConfiguration, getChunkSize } from "./configuration.js";
|
|
39
39
|
import { concat, toExactUint8Array } from "./util/array.js";
|
|
40
|
-
import { toCompatibleReadable, toCompatibleWritable } from "./util/compatible-streams.js";
|
|
40
|
+
import { toCompatibleReadable, toCompatibleWritable, streamToBlob } from "./util/compatible-streams.js";
|
|
41
41
|
|
|
42
42
|
const ERR_HTTP_STATUS = "HTTP error ";
|
|
43
43
|
const ERR_HTTP_RANGE = "HTTP Range not supported";
|
|
@@ -51,7 +51,6 @@ const HTTP_HEADER_CONTENT_ENCODING = "Content-Encoding";
|
|
|
51
51
|
const HTTP_HEADER_CONTENT_RANGE = "Content-Range";
|
|
52
52
|
const HTTP_HEADER_ACCEPT_RANGES = "Accept-Ranges";
|
|
53
53
|
const HTTP_HEADER_RANGE = "Range";
|
|
54
|
-
const HTTP_HEADER_CONTENT_TYPE = "Content-Type";
|
|
55
54
|
const HTTP_HEADER_ETAG = "Etag";
|
|
56
55
|
const HTTP_HEADER_LAST_MODIFIED = "Last-Modified";
|
|
57
56
|
const HTTP_METHOD_HEAD = "HEAD";
|
|
@@ -256,10 +255,6 @@ class BlobReader extends Reader {
|
|
|
256
255
|
}
|
|
257
256
|
}
|
|
258
257
|
|
|
259
|
-
function responseSupportsGlobalReadable() {
|
|
260
|
-
return typeof Blob.prototype.stream != FUNCTION_TYPE || new Blob([]).stream() instanceof ReadableStream;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
258
|
class BlobWriter extends Stream {
|
|
264
259
|
|
|
265
260
|
constructor(contentType) {
|
|
@@ -271,22 +266,7 @@ class BlobWriter extends Stream {
|
|
|
271
266
|
return transformStream.writable;
|
|
272
267
|
}
|
|
273
268
|
});
|
|
274
|
-
|
|
275
|
-
const headers = [];
|
|
276
|
-
if (contentType) {
|
|
277
|
-
headers.push([HTTP_HEADER_CONTENT_TYPE, contentType]);
|
|
278
|
-
}
|
|
279
|
-
writer.blob = new Response(transformStream.readable, { headers }).blob();
|
|
280
|
-
} else {
|
|
281
|
-
const chunks = [];
|
|
282
|
-
writer.blob = transformStream.readable
|
|
283
|
-
.pipeTo(new WritableStream({
|
|
284
|
-
write(chunk) {
|
|
285
|
-
chunks.push(chunk);
|
|
286
|
-
}
|
|
287
|
-
}))
|
|
288
|
-
.then(() => new Blob(chunks, { type: contentType }));
|
|
289
|
-
}
|
|
269
|
+
writer.blob = streamToBlob(transformStream.readable, contentType);
|
|
290
270
|
writer.blob.catch(() => { });
|
|
291
271
|
}
|
|
292
272
|
|
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
-
/* global
|
|
29
|
+
/* global ReadableStream, WritableStream, TransformStream */
|
|
30
|
+
|
|
31
|
+
import { streamToBlob } from "./compatible-streams.js";
|
|
30
32
|
|
|
31
33
|
export {
|
|
32
34
|
createBlobTempStream
|
|
@@ -46,7 +48,7 @@ function createBlobTempStream(options = {}) {
|
|
|
46
48
|
|
|
47
49
|
async function spillToBlob() {
|
|
48
50
|
const transformStream = new TransformStream();
|
|
49
|
-
blobPromise =
|
|
51
|
+
blobPromise = streamToBlob(transformStream.readable);
|
|
50
52
|
blobWriter = transformStream.writable.getWriter();
|
|
51
53
|
spilled = true;
|
|
52
54
|
for (const chunk of memoryChunks) {
|
|
@@ -26,13 +26,18 @@
|
|
|
26
26
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
-
/* global ReadableStream, WritableStream */
|
|
29
|
+
/* global Blob, Response, ReadableStream, WritableStream */
|
|
30
|
+
|
|
31
|
+
import { FUNCTION_TYPE } from "../constants.js";
|
|
30
32
|
|
|
31
33
|
export {
|
|
32
34
|
toCompatibleReadable,
|
|
33
|
-
toCompatibleWritable
|
|
35
|
+
toCompatibleWritable,
|
|
36
|
+
streamToBlob
|
|
34
37
|
};
|
|
35
38
|
|
|
39
|
+
const HTTP_HEADER_CONTENT_TYPE = "Content-Type";
|
|
40
|
+
|
|
36
41
|
function toCompatibleReadable(readable) {
|
|
37
42
|
if (readable instanceof ReadableStream) {
|
|
38
43
|
return readable;
|
|
@@ -53,6 +58,29 @@ function toCompatibleReadable(readable) {
|
|
|
53
58
|
});
|
|
54
59
|
}
|
|
55
60
|
|
|
61
|
+
function streamToBlob(readable, contentType) {
|
|
62
|
+
readable = toCompatibleReadable(readable);
|
|
63
|
+
if (responseSupportsGlobalReadable()) {
|
|
64
|
+
const options = {};
|
|
65
|
+
if (contentType) {
|
|
66
|
+
options.headers = [[HTTP_HEADER_CONTENT_TYPE, contentType]];
|
|
67
|
+
}
|
|
68
|
+
return new Response(readable, options).blob();
|
|
69
|
+
}
|
|
70
|
+
const chunks = [];
|
|
71
|
+
return readable
|
|
72
|
+
.pipeTo(new WritableStream({
|
|
73
|
+
write(chunk) {
|
|
74
|
+
chunks.push(chunk);
|
|
75
|
+
}
|
|
76
|
+
}))
|
|
77
|
+
.then(() => new Blob(chunks, contentType ? { type: contentType } : {}));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function responseSupportsGlobalReadable() {
|
|
81
|
+
return typeof Blob.prototype.stream != FUNCTION_TYPE || new Blob([]).stream() instanceof ReadableStream;
|
|
82
|
+
}
|
|
83
|
+
|
|
56
84
|
function toCompatibleWritable(writable) {
|
|
57
85
|
if (writable instanceof WritableStream) {
|
|
58
86
|
return writable;
|
|
@@ -57,7 +57,7 @@ function createOPFSTempStream(options = {}) {
|
|
|
57
57
|
|
|
58
58
|
async function spillToFile() {
|
|
59
59
|
const directoryHandle = await getTempDirectory();
|
|
60
|
-
fileName =
|
|
60
|
+
fileName = getRandomFileName();
|
|
61
61
|
fileHandle = await directoryHandle.getFileHandle(fileName, { create: true });
|
|
62
62
|
fileWriter = (await fileHandle.createWritable()).getWriter();
|
|
63
63
|
spilled = true;
|
|
@@ -137,3 +137,10 @@ function createOPFSTempStream(options = {}) {
|
|
|
137
137
|
return { writable, readable, dispose };
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
|
+
|
|
141
|
+
function getRandomFileName() {
|
|
142
|
+
if (crypto.randomUUID) {
|
|
143
|
+
return crypto.randomUUID();
|
|
144
|
+
}
|
|
145
|
+
return Array.from(crypto.getRandomValues(new Uint8Array(16)), byteValue => byteValue.toString(16).padStart(2, "0")).join("");
|
|
146
|
+
}
|
|
@@ -67,7 +67,7 @@ function createSyncAccessHandleTempStream(options = {}) {
|
|
|
67
67
|
|
|
68
68
|
async function spillToFile() {
|
|
69
69
|
const directoryHandle = await getTempDirectory();
|
|
70
|
-
fileName =
|
|
70
|
+
fileName = getRandomFileName();
|
|
71
71
|
const fileHandle = await directoryHandle.getFileHandle(fileName, { create: true });
|
|
72
72
|
accessHandle = await fileHandle.createSyncAccessHandle();
|
|
73
73
|
spilled = true;
|
|
@@ -146,3 +146,10 @@ function createSyncAccessHandleTempStream(options = {}) {
|
|
|
146
146
|
return { writable, readable, dispose };
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
+
|
|
150
|
+
function getRandomFileName() {
|
|
151
|
+
if (crypto.randomUUID) {
|
|
152
|
+
return crypto.randomUUID();
|
|
153
|
+
}
|
|
154
|
+
return Array.from(crypto.getRandomValues(new Uint8Array(16)), byteValue => byteValue.toString(16).padStart(2, "0")).join("");
|
|
155
|
+
}
|
package/lib/core/zip-fs.js
CHANGED
|
@@ -67,6 +67,7 @@ import {
|
|
|
67
67
|
EXTRAFIELD_TYPE_PKWARE_UNIX
|
|
68
68
|
} from "./constants.js";
|
|
69
69
|
import { toExactUint8Array } from "./util/array.js";
|
|
70
|
+
import { toCompatibleReadable, toCompatibleWritable } from "./util/compatible-streams.js";
|
|
70
71
|
|
|
71
72
|
const ERR_ENTRY_EXISTS = "Entry filename already exists";
|
|
72
73
|
const ERR_READABLE_CONSUMED = "Readable stream already consumed";
|
|
@@ -179,7 +180,7 @@ class ZipFileEntry extends ZipEntry {
|
|
|
179
180
|
await Promise.all([initStream(reader), initStream(writer, uncompressedSize)]);
|
|
180
181
|
const { readable } = reader;
|
|
181
182
|
zipEntry.uncompressedSize = reader.size;
|
|
182
|
-
await readable.pipeTo(writer.writable);
|
|
183
|
+
await toCompatibleReadable(readable).pipeTo(toCompatibleWritable(writer.writable));
|
|
183
184
|
return writer.getData ? writer.getData() : writer.writable;
|
|
184
185
|
}
|
|
185
186
|
}
|
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
|
|
29
|
+
/* global WritableStream, ReadableStream, TransformStream */
|
|
30
30
|
// deno-lint-ignore-file no-this-alias
|
|
31
31
|
|
|
32
32
|
import {
|
|
@@ -113,7 +113,7 @@ import {
|
|
|
113
113
|
} from "./io.js";
|
|
114
114
|
import { decodeText } from "./util/decode-text.js";
|
|
115
115
|
import { getDataView } from "./util/array.js";
|
|
116
|
-
import { toCompatibleReadable } from "./util/compatible-streams.js";
|
|
116
|
+
import { toCompatibleReadable, streamToBlob } from "./util/compatible-streams.js";
|
|
117
117
|
import { Crc32 } from "./streams/codecs/crc32.js";
|
|
118
118
|
import {
|
|
119
119
|
PROPERTY_NAME_RAW_FILENAME,
|
|
@@ -213,7 +213,7 @@ class ZipReader {
|
|
|
213
213
|
const { config } = zipReader;
|
|
214
214
|
await initStream(reader);
|
|
215
215
|
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
216
|
-
reader = new BlobReader(await
|
|
216
|
+
reader = new BlobReader(await streamToBlob(reader.readable));
|
|
217
217
|
await initStream(reader);
|
|
218
218
|
}
|
|
219
219
|
if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
|
|
@@ -482,7 +482,7 @@ class ZipReader {
|
|
|
482
482
|
entry.arrayBuffer = async options => {
|
|
483
483
|
const writer = new TransformStream();
|
|
484
484
|
const [arrayBuffer] = await Promise.all([
|
|
485
|
-
|
|
485
|
+
streamToBlob(writer.readable).then(blob => blob.arrayBuffer()),
|
|
486
486
|
fileEntry.getData(writer, entry, zipReader.readRanges, options)]);
|
|
487
487
|
return arrayBuffer;
|
|
488
488
|
};
|
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.8.
|
|
6
|
+
"version": "2.8.48",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"zip",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"lint": "npx eslint . && deno lint",
|
|
38
38
|
"test": "npm run test-node && npm run test-deno && npm run test-bun && npm run test-node-dist && npm run test-deno-dist && npm run test-bun-dist && npm run test-web-streams-polyfill && npm run test-types",
|
|
39
39
|
"test-browsers": "npm run test-chrome && npm run test-firefox && npm run test-webkit",
|
|
40
|
+
"serve-tests": "http-server -p 8888 -c-1 .",
|
|
40
41
|
"test-all": "npm run lint && npm run test && npm run test-browsers",
|
|
41
42
|
"build": "npx rollup -c",
|
|
42
43
|
"build-dev": "npx rollup -c --environment DEV",
|