@zip.js/zip.js 2.6.22 → 2.6.25
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/.eslintrc.json +0 -0
- package/README.md +36 -0
- package/cli-deno/mc-zip.js +0 -0
- package/dist/README.md +0 -0
- package/dist/z-worker-fflate.js +1 -1
- package/dist/z-worker-pako.js +1 -1
- package/dist/z-worker.js +1 -1
- package/dist/zip-fs-full.js +159 -116
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +159 -116
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +158 -114
- 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 +158 -114
- package/dist/zip.min.js +1 -1
- package/index-fflate.js +0 -0
- package/index.d.ts +14 -8
- package/index.js +0 -0
- package/lib/core/codec-interface.js +36 -18
- package/lib/core/codec-pool-worker.js +57 -24
- package/lib/core/codec-pool.js +5 -4
- package/lib/core/configuration.js +14 -24
- package/lib/core/constants.js +0 -0
- package/lib/core/io.js +9 -15
- package/lib/core/streams/aes-crypto-stream.js +0 -0
- package/lib/core/streams/codec-stream.js +0 -0
- package/lib/core/streams/codecs/crc32.js +0 -0
- package/lib/core/streams/codecs/deflate.js +0 -0
- package/lib/core/streams/codecs/inflate.js +0 -0
- package/lib/core/streams/codecs/sjcl.js +0 -0
- package/lib/core/streams/common-crypto.js +0 -0
- package/lib/core/streams/crc32-stream.js +0 -0
- package/lib/core/streams/zip-crypto-stream.js +0 -0
- package/lib/core/streams/zip-entry-stream.js +0 -0
- package/lib/core/util/cp437-decode.js +0 -0
- package/lib/core/util/decode-text.js +0 -0
- package/lib/core/util/default-mime-type.js +0 -0
- package/lib/core/util/encode-text.js +0 -0
- package/lib/core/util/mime-type.js +0 -0
- package/lib/core/util/stream-codec-shim.js +0 -0
- package/lib/core/z-worker-core.js +12 -5
- package/lib/core/zip-entry.js +0 -0
- package/lib/core/zip-fs-core.js +1 -2
- package/lib/core/zip-reader.js +14 -7
- package/lib/core/zip-writer.js +10 -9
- package/lib/z-worker-bootstrap-fflate.js +0 -0
- package/lib/z-worker-bootstrap-pako.js +0 -0
- package/lib/z-worker-fflate.js +0 -0
- package/lib/z-worker-inline-template-base64.js +0 -0
- package/lib/z-worker-inline-template.js +0 -0
- package/lib/z-worker-inline.js +1 -1
- package/lib/z-worker.js +0 -0
- package/lib/zip-fflate-shim.js +0 -0
- package/lib/zip-fs.js +0 -0
- package/lib/zip-full-fflate.js +0 -0
- package/lib/zip-full.js +0 -0
- package/lib/zip-no-worker-deflate.js +0 -0
- package/lib/zip-no-worker-fflate-deflate.js +0 -0
- package/lib/zip-no-worker-fflate-inflate.js +0 -0
- package/lib/zip-no-worker-fflate.js +0 -0
- package/lib/zip-no-worker-inflate.js +0 -0
- package/lib/zip-no-worker.js +0 -0
- package/lib/zip.js +0 -0
- package/package.json +4 -4
- package/rollup-fflate.config.dev.js +0 -0
- package/rollup-fflate.config.js +0 -0
- package/rollup.config.dev.js +0 -0
- package/rollup.config.js +1 -1
- package/tests/all/loader.html +0 -0
- package/tests/all/test-abort-signal-read.js +0 -0
- package/tests/all/test-abort-signal-write.js +0 -0
- package/tests/all/test-array.js +0 -0
- package/tests/all/test-base64.js +0 -0
- package/tests/all/test-blob.js +0 -0
- package/tests/all/test-codecs-interoperability.js +0 -0
- package/tests/all/test-crc.js +0 -0
- package/tests/all/test-crypto.js +0 -0
- package/tests/all/test-custom-io.js +0 -0
- package/tests/all/test-data-descriptor-signature.js +0 -0
- package/tests/all/test-data-descriptor.js +0 -0
- package/tests/all/test-duplicated-filename.js +0 -0
- package/tests/all/test-empty.js +0 -0
- package/tests/all/test-extended-timestamp.js +0 -0
- package/tests/all/test-extra-field.js +0 -0
- package/tests/all/test-fflate-no-worker.js +0 -0
- package/tests/all/test-fflate.js +0 -0
- package/tests/all/test-fs-base64.js +0 -0
- package/tests/all/test-fs-export-options.js +0 -0
- package/tests/all/test-fs-http-import.js +0 -0
- package/tests/all/test-fs-http-reader.js +0 -0
- package/tests/all/test-fs-replace.js +0 -0
- package/tests/all/test-fs-streams.js +0 -0
- package/tests/all/test-fs-text.js +0 -0
- package/tests/all/test-fs-unzip-store.js +0 -0
- package/tests/all/test-fs.js +0 -0
- package/tests/all/test-http-crypto.js +0 -0
- package/tests/all/test-http-range.js +0 -0
- package/tests/all/test-http-zip64.js +0 -0
- package/tests/all/test-invalid-crc.js +0 -0
- package/tests/all/test-multiple-writers.js +0 -0
- package/tests/all/test-no-worker.js +0 -0
- package/tests/all/test-pako-no-worker.js +0 -0
- package/tests/all/test-pako.js +0 -0
- package/tests/all/test-parallel-reads.js +0 -0
- package/tests/all/test-parallel-writes-auto-buffered.js +0 -0
- package/tests/all/test-parallel-writes-ordered.js +0 -0
- package/tests/all/test-parallel-writes.js +0 -0
- package/tests/all/test-readable-stream.js +0 -0
- package/tests/all/test-readable-zip-stream.js +0 -0
- package/tests/all/test-safe-closing.js +0 -0
- package/tests/all/test-store.js +0 -0
- package/tests/all/test-sw-worker.js +0 -0
- package/tests/all/test-sw.js +0 -0
- package/tests/all/test-worker-timeout.js +0 -0
- package/tests/all/test-wrapped.js +0 -0
- package/tests/all/test-writable-stream.js +0 -0
- package/tests/all/test-zip64-auto.js +0 -0
- package/tests/all/test-zip64-crypto.js +0 -0
- package/tests/all/test-zip64.js +0 -0
- package/tests/all/test-zipcrypto.js +0 -0
- package/tests/data/lorem-encrypted.zip +0 -0
- package/tests/data/lorem-invalid-crc.zip +0 -0
- package/tests/data/lorem-store.zip +0 -0
- package/tests/data/lorem-zip64.zip +0 -0
- package/tests/data/lorem.txt +0 -0
- package/tests/data/lorem.zip +0 -0
- package/tests/deno-runner.js +0 -0
- package/tests/index.html +0 -0
- package/tests/node-runner.js +0 -0
- package/tests/tests-data.js +0 -0
- package/tests/vendor/fflate-es2019.min.js +0 -0
- package/tests/vendor/fflate.min.js +0 -0
- package/tests/vendor/pako.min.js +0 -0
- package/tests/vendor/pako_deflate.min.js +0 -0
- package/tests/vendor/pako_inflate.min.js +0 -0
- package/tests/web-runner.js +0 -0
- package/tsconfig.json +0 -0
|
@@ -61,29 +61,47 @@ export {
|
|
|
61
61
|
|
|
62
62
|
class Codec {
|
|
63
63
|
|
|
64
|
-
constructor(
|
|
64
|
+
constructor(CodecConstructor, readable, writable, options, config) {
|
|
65
65
|
const { codecType } = options;
|
|
66
|
+
let StreamConstructor;
|
|
66
67
|
if (codecType.startsWith(CODEC_DEFLATE)) {
|
|
67
|
-
|
|
68
|
+
StreamConstructor = DeflateStream;
|
|
68
69
|
} else if (codecType.startsWith(CODEC_INFLATE)) {
|
|
69
|
-
|
|
70
|
+
StreamConstructor = InflateStream;
|
|
70
71
|
}
|
|
72
|
+
Object.assign(this, {
|
|
73
|
+
StreamConstructor,
|
|
74
|
+
CodecConstructor,
|
|
75
|
+
readable,
|
|
76
|
+
writable,
|
|
77
|
+
options,
|
|
78
|
+
config
|
|
79
|
+
});
|
|
80
|
+
}
|
|
71
81
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
async run() {
|
|
83
|
+
const {
|
|
84
|
+
StreamConstructor,
|
|
85
|
+
CodecConstructor,
|
|
86
|
+
readable,
|
|
87
|
+
writable,
|
|
88
|
+
options,
|
|
89
|
+
config
|
|
90
|
+
} = this;
|
|
91
|
+
const stream = new StreamConstructor(CodecConstructor, options, config);
|
|
92
|
+
let size = 0;
|
|
93
|
+
await readable
|
|
94
|
+
.pipeThrough(stream)
|
|
95
|
+
.pipeThrough(new TransformStream({
|
|
96
|
+
transform(chunk, controller) {
|
|
97
|
+
if (chunk && chunk.length) {
|
|
98
|
+
size += chunk.length;
|
|
99
|
+
controller.enqueue(chunk);
|
|
82
100
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
101
|
+
}
|
|
102
|
+
}))
|
|
103
|
+
.pipeTo(writable, { preventClose: true, preventAbort: true });
|
|
104
|
+
const { signature } = stream;
|
|
105
|
+
return { size, signature };
|
|
88
106
|
}
|
|
89
107
|
}
|
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
|
|
41
41
|
let workersSupported;
|
|
42
42
|
let classicWorkersSupported = true;
|
|
43
|
+
let transferStreamsSupported = true;
|
|
43
44
|
|
|
44
45
|
export {
|
|
45
46
|
CodecWorker
|
|
@@ -49,7 +50,7 @@ class CodecWorker {
|
|
|
49
50
|
|
|
50
51
|
constructor(workerData, stream, workerOptions, onTaskFinished) {
|
|
51
52
|
const { readable, writable } = stream;
|
|
52
|
-
const { options, config, streamOptions,
|
|
53
|
+
const { options, config, streamOptions, useWebWorkers, transferStreams, scripts, codecConstructor } = workerOptions;
|
|
53
54
|
Object.assign(workerData, {
|
|
54
55
|
busy: true,
|
|
55
56
|
codecConstructor,
|
|
@@ -57,6 +58,7 @@ class CodecWorker {
|
|
|
57
58
|
writable,
|
|
58
59
|
options: Object.assign({}, options),
|
|
59
60
|
scripts,
|
|
61
|
+
transferStreams,
|
|
60
62
|
terminate() {
|
|
61
63
|
if (workerData.worker && !workerData.busy) {
|
|
62
64
|
workerData.worker.terminate();
|
|
@@ -72,17 +74,17 @@ class CodecWorker {
|
|
|
72
74
|
let chunkOffset = 0;
|
|
73
75
|
const transformer = {};
|
|
74
76
|
if (onstart) {
|
|
75
|
-
transformer.start = () => callHandler(onstart, size
|
|
77
|
+
transformer.start = () => callHandler(onstart, size);
|
|
76
78
|
}
|
|
77
79
|
transformer.transform = async (chunk, controller) => {
|
|
78
80
|
chunkOffset += chunk.length;
|
|
79
81
|
if (onprogress) {
|
|
80
|
-
await callHandler(onprogress, chunkOffset, size
|
|
82
|
+
await callHandler(onprogress, chunkOffset, size);
|
|
81
83
|
}
|
|
82
84
|
controller.enqueue(chunk);
|
|
83
85
|
};
|
|
84
86
|
transformer.flush = () => {
|
|
85
|
-
readable.size =
|
|
87
|
+
readable.size = chunkOffset;
|
|
86
88
|
if (onend) {
|
|
87
89
|
callHandler(onend, chunkOffset);
|
|
88
90
|
}
|
|
@@ -91,7 +93,7 @@ class CodecWorker {
|
|
|
91
93
|
if (workersSupported === undefined) {
|
|
92
94
|
workersSupported = typeof Worker != "undefined";
|
|
93
95
|
}
|
|
94
|
-
return
|
|
96
|
+
return useWebWorkers && workersSupported ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
99
|
|
|
@@ -120,10 +122,8 @@ function createWorkerInterface(workerData, config) {
|
|
|
120
122
|
|
|
121
123
|
function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
|
|
122
124
|
const workerOptions = { type: "module" };
|
|
123
|
-
const { readable, writable } = workerData;
|
|
124
125
|
Object.assign(workerData, {
|
|
125
|
-
|
|
126
|
-
writer: writable.getWriter(),
|
|
126
|
+
streams: {},
|
|
127
127
|
result: new Promise((resolve, reject) => {
|
|
128
128
|
workerData.resolveResult = resolve;
|
|
129
129
|
workerData.rejectResult = reject;
|
|
@@ -143,15 +143,32 @@ function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
|
|
|
143
143
|
workerData.worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false);
|
|
144
144
|
workerData.interface = {
|
|
145
145
|
run() {
|
|
146
|
-
const { options } = workerData;
|
|
146
|
+
const { readable, writable, options } = workerData;
|
|
147
147
|
const scripts = workerData.scripts.slice(1);
|
|
148
|
-
|
|
148
|
+
const message = { type: MESSAGE_START, scripts, options, config: { chunkSize } };
|
|
149
|
+
if (workerData.transferStreams && transferStreamsSupported) {
|
|
150
|
+
const streamsTransferred = sendMessage({ ...message, readable, writable });
|
|
151
|
+
if (!streamsTransferred) {
|
|
152
|
+
transferStreamsSupported = false;
|
|
153
|
+
initStreams(readable, writable);
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
sendMessage(message);
|
|
157
|
+
initStreams(readable, writable);
|
|
158
|
+
}
|
|
149
159
|
return workerData.result;
|
|
150
160
|
}
|
|
151
161
|
};
|
|
152
162
|
}
|
|
153
163
|
return workerData.interface;
|
|
154
164
|
|
|
165
|
+
function initStreams(readable, writable) {
|
|
166
|
+
Object.assign(workerData.streams, {
|
|
167
|
+
reader: readable.getReader(),
|
|
168
|
+
writer: writable.getWriter()
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
155
172
|
function getWorker(options) {
|
|
156
173
|
let url, scriptUrl;
|
|
157
174
|
url = workerData.scripts[0];
|
|
@@ -169,23 +186,37 @@ function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
|
|
|
169
186
|
function sendMessage(message) {
|
|
170
187
|
const { worker, writer, onTaskFinished } = workerData;
|
|
171
188
|
try {
|
|
172
|
-
let { data } = message;
|
|
189
|
+
let { data, readable, writable } = message;
|
|
190
|
+
const transferrables = [];
|
|
173
191
|
if (data) {
|
|
192
|
+
const { buffer, length } = data;
|
|
193
|
+
if (length != buffer.byteLength) {
|
|
194
|
+
data = new Uint8Array(data);
|
|
195
|
+
}
|
|
196
|
+
message.data = data.buffer;
|
|
197
|
+
transferrables.push(message.data);
|
|
198
|
+
}
|
|
199
|
+
if (readable) {
|
|
200
|
+
transferrables.push(readable);
|
|
201
|
+
}
|
|
202
|
+
if (writable) {
|
|
203
|
+
transferrables.push(writable);
|
|
204
|
+
}
|
|
205
|
+
if (transferrables.length) {
|
|
174
206
|
try {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
message.data = data.buffer;
|
|
180
|
-
worker.postMessage(message, [message.data]);
|
|
181
|
-
} catch (_error) {
|
|
207
|
+
worker.postMessage(message, transferrables);
|
|
208
|
+
return true;
|
|
209
|
+
} catch (error) {
|
|
210
|
+
message.readable = message.writable = null;
|
|
182
211
|
worker.postMessage(message);
|
|
183
212
|
}
|
|
184
213
|
} else {
|
|
185
214
|
worker.postMessage(message);
|
|
186
215
|
}
|
|
187
216
|
} catch (error) {
|
|
188
|
-
writer
|
|
217
|
+
if (writer) {
|
|
218
|
+
writer.releaseLock();
|
|
219
|
+
}
|
|
189
220
|
onTaskFinished();
|
|
190
221
|
throw error;
|
|
191
222
|
}
|
|
@@ -193,14 +224,15 @@ function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
|
|
|
193
224
|
|
|
194
225
|
async function onMessage(event) {
|
|
195
226
|
const message = event.data;
|
|
196
|
-
const {
|
|
227
|
+
const { resolveResult, rejectResult, onTaskFinished } = workerData;
|
|
228
|
+
const { reader, writer } = workerData.streams;
|
|
197
229
|
const { type, data, messageId, result } = message;
|
|
198
230
|
const reponseError = message.error;
|
|
199
231
|
try {
|
|
200
232
|
if (reponseError) {
|
|
201
|
-
const { message, stack } = reponseError;
|
|
233
|
+
const { message, stack, code, name } = reponseError;
|
|
202
234
|
const error = new Error(message);
|
|
203
|
-
error
|
|
235
|
+
Object.assign(error, { stack, code, name });
|
|
204
236
|
close(error);
|
|
205
237
|
} else {
|
|
206
238
|
if (type == MESSAGE_PULL) {
|
|
@@ -209,7 +241,6 @@ function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
|
|
|
209
241
|
}
|
|
210
242
|
if (type == MESSAGE_DATA) {
|
|
211
243
|
await writer.ready;
|
|
212
|
-
workerData.writable.size += data.byteLength;
|
|
213
244
|
await writer.write(new Uint8Array(data));
|
|
214
245
|
sendMessage({ type: MESSAGE_ACK_DATA, messageId });
|
|
215
246
|
}
|
|
@@ -227,7 +258,9 @@ function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
|
|
|
227
258
|
} else {
|
|
228
259
|
resolveResult(result);
|
|
229
260
|
}
|
|
230
|
-
writer
|
|
261
|
+
if (writer) {
|
|
262
|
+
writer.releaseLock();
|
|
263
|
+
}
|
|
231
264
|
onTaskFinished();
|
|
232
265
|
}
|
|
233
266
|
}
|
package/lib/core/codec-pool.js
CHANGED
|
@@ -52,11 +52,12 @@ let indexWorker = 0;
|
|
|
52
52
|
|
|
53
53
|
async function runWorker(stream, workerOptions) {
|
|
54
54
|
const { options, config } = workerOptions;
|
|
55
|
-
const
|
|
56
|
-
const { useWebWorkers, useCompressionStream, codecType } = options;
|
|
55
|
+
const { transferStreams, useWebWorkers, useCompressionStream, codecType, compressed, signed, encrypted } = options;
|
|
57
56
|
const { workerScripts } = config;
|
|
58
|
-
workerOptions.
|
|
59
|
-
|
|
57
|
+
workerOptions.transferStreams = transferStreams || transferStreams === undefined;
|
|
58
|
+
const streamCopy = !compressed && !signed && !encrypted && !workerOptions.transferStreams;
|
|
59
|
+
workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers === undefined && config.useWebWorkers));
|
|
60
|
+
workerOptions.scripts = workerOptions.useWebWorkers && workerScripts ? workerScripts[codecType] : [];
|
|
60
61
|
options.useCompressionStream = useCompressionStream === undefined ? config.useCompressionStream : useCompressionStream;
|
|
61
62
|
let worker;
|
|
62
63
|
if (pool.length < config.maxWorkers) {
|
|
@@ -66,30 +66,14 @@ function configure(configuration) {
|
|
|
66
66
|
Inflate,
|
|
67
67
|
workerScripts
|
|
68
68
|
} = configuration;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
if (terminateWorkerTimeout !== UNDEFINED_TYPE) {
|
|
79
|
-
config.terminateWorkerTimeout = terminateWorkerTimeout;
|
|
80
|
-
}
|
|
81
|
-
if (useCompressionStream !== UNDEFINED_TYPE) {
|
|
82
|
-
config.useCompressionStream = useCompressionStream;
|
|
83
|
-
}
|
|
84
|
-
if (useWebWorkers !== UNDEFINED_TYPE) {
|
|
85
|
-
config.useWebWorkers = useWebWorkers;
|
|
86
|
-
}
|
|
87
|
-
if (Deflate !== UNDEFINED_TYPE) {
|
|
88
|
-
config.Deflate = Deflate;
|
|
89
|
-
}
|
|
90
|
-
if (Inflate !== UNDEFINED_TYPE) {
|
|
91
|
-
config.Inflate = Inflate;
|
|
92
|
-
}
|
|
69
|
+
setIfDefined("baseURL", baseURL);
|
|
70
|
+
setIfDefined("chunkSize", chunkSize);
|
|
71
|
+
setIfDefined("maxWorkers", maxWorkers);
|
|
72
|
+
setIfDefined("terminateWorkerTimeout", terminateWorkerTimeout);
|
|
73
|
+
setIfDefined("useCompressionStream", useCompressionStream);
|
|
74
|
+
setIfDefined("useWebWorkers", useWebWorkers);
|
|
75
|
+
setIfDefined("Deflate", Deflate);
|
|
76
|
+
setIfDefined("Inflate", Inflate);
|
|
93
77
|
if (workerScripts !== UNDEFINED_TYPE) {
|
|
94
78
|
const { deflate, inflate } = workerScripts;
|
|
95
79
|
if (deflate || inflate) {
|
|
@@ -111,3 +95,9 @@ function configure(configuration) {
|
|
|
111
95
|
}
|
|
112
96
|
}
|
|
113
97
|
}
|
|
98
|
+
|
|
99
|
+
function setIfDefined(propertyName, propertyValue) {
|
|
100
|
+
if (propertyValue !== UNDEFINED_TYPE) {
|
|
101
|
+
config[propertyName] = propertyValue;
|
|
102
|
+
}
|
|
103
|
+
}
|
package/lib/core/constants.js
CHANGED
|
File without changes
|
package/lib/core/io.js
CHANGED
|
@@ -66,8 +66,8 @@ class Reader extends Stream {
|
|
|
66
66
|
async pull(controller) {
|
|
67
67
|
const { offset = 0, size } = readable;
|
|
68
68
|
const { chunkOffset } = this;
|
|
69
|
-
controller.enqueue(await reader.readUint8Array(offset + chunkOffset, Math.min(chunkSize, size
|
|
70
|
-
if (chunkOffset + chunkSize > size
|
|
69
|
+
controller.enqueue(await reader.readUint8Array(offset + chunkOffset, Math.min(chunkSize, size - chunkOffset)));
|
|
70
|
+
if (chunkOffset + chunkSize > size) {
|
|
71
71
|
controller.close();
|
|
72
72
|
} else {
|
|
73
73
|
this.chunkOffset += chunkSize;
|
|
@@ -224,23 +224,17 @@ class BlobWriter extends Stream {
|
|
|
224
224
|
constructor(contentType) {
|
|
225
225
|
super();
|
|
226
226
|
const writer = this;
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
const transformStream = new TransformStream();
|
|
228
|
+
const headers = [];
|
|
229
|
+
if (contentType) {
|
|
230
|
+
headers.push(["content-type", contentType]);
|
|
231
|
+
}
|
|
229
232
|
Object.defineProperty(writer, "writable", {
|
|
230
233
|
get() {
|
|
231
|
-
return
|
|
234
|
+
return transformStream.writable;
|
|
232
235
|
}
|
|
233
236
|
});
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
init() {
|
|
237
|
-
super.init();
|
|
238
|
-
const writer = this;
|
|
239
|
-
const {
|
|
240
|
-
transformStream,
|
|
241
|
-
contentType
|
|
242
|
-
} = writer;
|
|
243
|
-
writer.blob = new Response(transformStream.readable, { headers: [["content-type", contentType]] }).blob();
|
|
237
|
+
writer.blob = new Response(transformStream.readable, { headers }).blob();
|
|
244
238
|
}
|
|
245
239
|
|
|
246
240
|
getData() {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -63,7 +63,7 @@ addEventListener(MESSAGE_EVENT_TYPE, async event => {
|
|
|
63
63
|
resolve();
|
|
64
64
|
}
|
|
65
65
|
} catch (error) {
|
|
66
|
-
|
|
66
|
+
sendErrorMessage(error);
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
|
|
@@ -84,7 +84,7 @@ async function init(message) {
|
|
|
84
84
|
codecConstructor = self.Inflate;
|
|
85
85
|
}
|
|
86
86
|
const strategy = { highWaterMark: 1, size: () => config.chunkSize };
|
|
87
|
-
const readable = new ReadableStream({
|
|
87
|
+
const readable = message.readable || new ReadableStream({
|
|
88
88
|
async pull(controller) {
|
|
89
89
|
let result = new Promise(resolve => pendingPullMessages.set(messageId, resolve));
|
|
90
90
|
sendMessage({ type: MESSAGE_PULL, messageId });
|
|
@@ -96,7 +96,7 @@ async function init(message) {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
}, strategy);
|
|
99
|
-
const writable = new WritableStream({
|
|
99
|
+
const writable = message.writable || new WritableStream({
|
|
100
100
|
async write(data) {
|
|
101
101
|
let resolveAckData;
|
|
102
102
|
const ackData = new Promise(resolve => resolveAckData = resolve);
|
|
@@ -108,10 +108,12 @@ async function init(message) {
|
|
|
108
108
|
}, strategy);
|
|
109
109
|
codec = new Codec(codecConstructor, readable, writable, options, config);
|
|
110
110
|
const result = await codec.run();
|
|
111
|
+
if (message.writable && !options.preventClose) {
|
|
112
|
+
await message.writable.close();
|
|
113
|
+
}
|
|
111
114
|
sendMessage({ type: MESSAGE_CLOSE, result });
|
|
112
115
|
} catch (error) {
|
|
113
|
-
|
|
114
|
-
postMessage({ error: { message, stack } });
|
|
116
|
+
sendErrorMessage(error);
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
119
|
|
|
@@ -132,4 +134,9 @@ function sendMessage(message) {
|
|
|
132
134
|
} else {
|
|
133
135
|
postMessage(message);
|
|
134
136
|
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function sendErrorMessage(error) {
|
|
140
|
+
const { message, stack, code, name } = error;
|
|
141
|
+
postMessage({ error: { message, stack, code, name } });
|
|
135
142
|
}
|
package/lib/core/zip-entry.js
CHANGED
|
File without changes
|
package/lib/core/zip-fs-core.js
CHANGED
|
@@ -122,9 +122,8 @@ class ZipFileEntry extends ZipEntry {
|
|
|
122
122
|
} else {
|
|
123
123
|
const reader = zipEntry.reader = new zipEntry.Reader(zipEntry.data, options);
|
|
124
124
|
await Promise.all([initStream(reader), initStream(writer, zipEntry.data.uncompressedSize)]);
|
|
125
|
-
zipEntry.uncompressedSize = reader.size;
|
|
126
125
|
const readable = reader.readable;
|
|
127
|
-
readable.size =
|
|
126
|
+
readable.size = zipEntry.uncompressedSize = reader.size;
|
|
128
127
|
await readable.pipeTo(writer.writable);
|
|
129
128
|
return writer.getData ? writer.getData() : writer.writable;
|
|
130
129
|
}
|
package/lib/core/zip-reader.js
CHANGED
|
@@ -317,13 +317,15 @@ class ZipEntry {
|
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
const dataOffset = offset + 30 + localDirectory.filenameLength + localDirectory.extraFieldLength;
|
|
320
|
-
const size = () => compressedSize;
|
|
321
320
|
const readable = reader.readable;
|
|
322
321
|
readable.offset = dataOffset;
|
|
323
|
-
readable.size =
|
|
322
|
+
const size = readable.size = compressedSize;
|
|
324
323
|
const { writable } = writer;
|
|
325
|
-
writable.size
|
|
324
|
+
if (writable.size === undefined) {
|
|
325
|
+
writable.size = 0;
|
|
326
|
+
}
|
|
326
327
|
const signal = getOptionValue(zipEntry, options, "signal");
|
|
328
|
+
const preventClose = getOptionValue(zipEntry, options, "preventClose");
|
|
327
329
|
await initStream(writer, uncompressedSize);
|
|
328
330
|
const { onstart, onprogress, onend } = options;
|
|
329
331
|
const workerOptions = {
|
|
@@ -338,16 +340,21 @@ class ZipEntry {
|
|
|
338
340
|
compressed: compressionMethod != 0,
|
|
339
341
|
encrypted,
|
|
340
342
|
useWebWorkers: getOptionValue(zipEntry, options, "useWebWorkers"),
|
|
341
|
-
useCompressionStream: getOptionValue(zipEntry, options, "useCompressionStream")
|
|
343
|
+
useCompressionStream: getOptionValue(zipEntry, options, "useCompressionStream"),
|
|
344
|
+
transferStreams: getOptionValue(zipEntry, options, "transferStreams"),
|
|
345
|
+
preventClose
|
|
342
346
|
},
|
|
343
347
|
config,
|
|
344
348
|
streamOptions: { signal, size, onstart, onprogress, onend },
|
|
345
349
|
codecConstructor: config.Inflate
|
|
346
350
|
};
|
|
347
|
-
await runWorker({ readable, writable }, workerOptions);
|
|
348
|
-
const preventClose = getOptionValue(zipEntry, options, "preventClose");
|
|
351
|
+
writable.size += (await runWorker({ readable, writable }, workerOptions)).size;
|
|
349
352
|
if (!preventClose) {
|
|
350
|
-
|
|
353
|
+
try {
|
|
354
|
+
await writable.close();
|
|
355
|
+
} catch (_error) {
|
|
356
|
+
// ignored
|
|
357
|
+
}
|
|
351
358
|
}
|
|
352
359
|
return writer.getData ? writer.getData() : writable;
|
|
353
360
|
}
|
package/lib/core/zip-writer.js
CHANGED
|
@@ -151,7 +151,7 @@ class ZipWriter {
|
|
|
151
151
|
}
|
|
152
152
|
await closeFile(this, comment, options);
|
|
153
153
|
if (!writer.preventClose && !options.preventClose) {
|
|
154
|
-
await writable.
|
|
154
|
+
await writable.close();
|
|
155
155
|
}
|
|
156
156
|
return writer.getData ? writer.getData() : writable;
|
|
157
157
|
}
|
|
@@ -354,7 +354,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
|
|
|
354
354
|
files.set(name, fileEntry);
|
|
355
355
|
fileEntry.filename = name;
|
|
356
356
|
if (bufferedWrite) {
|
|
357
|
-
await fileWriter.writable.
|
|
357
|
+
await fileWriter.writable.close();
|
|
358
358
|
let blob = await fileWriter.getData();
|
|
359
359
|
await lockPreviousFileEntry;
|
|
360
360
|
await requestLockWriter();
|
|
@@ -495,9 +495,8 @@ async function createFileEntry(reader, writer, pendingFileEntry, entryInfo, conf
|
|
|
495
495
|
if (reader) {
|
|
496
496
|
reader.chunkSize = getChunkSize(config);
|
|
497
497
|
await writeData(writable, localHeaderArray);
|
|
498
|
-
const size = () => reader.size;
|
|
499
498
|
const readable = reader.readable;
|
|
500
|
-
readable.size = size;
|
|
499
|
+
const size = readable.size = reader.size;
|
|
501
500
|
const workerOptions = {
|
|
502
501
|
options: {
|
|
503
502
|
codecType: CODEC_DEFLATE,
|
|
@@ -510,16 +509,18 @@ async function createFileEntry(reader, writer, pendingFileEntry, entryInfo, conf
|
|
|
510
509
|
compressed,
|
|
511
510
|
encrypted,
|
|
512
511
|
useWebWorkers,
|
|
513
|
-
useCompressionStream
|
|
512
|
+
useCompressionStream,
|
|
513
|
+
transferStreams: false
|
|
514
514
|
},
|
|
515
515
|
config,
|
|
516
516
|
streamOptions: { signal, size, onstart, onprogress, onend },
|
|
517
517
|
codecConstructor: config.Deflate
|
|
518
518
|
};
|
|
519
|
-
const
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
519
|
+
const result = await runWorker({ readable, writable }, workerOptions);
|
|
520
|
+
writable.size += result.size;
|
|
521
|
+
signature = result.signature;
|
|
522
|
+
uncompressedSize = reader.size = readable.size;
|
|
523
|
+
compressedSize = result.size;
|
|
523
524
|
} else {
|
|
524
525
|
await writeData(writable, localHeaderArray);
|
|
525
526
|
}
|
|
File without changes
|
|
File without changes
|
package/lib/z-worker-fflate.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|