@zip.js/zip.js 2.6.32 → 2.6.34
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/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 +2441 -2287
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +1970 -1816
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +1969 -1815
- 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 +1971 -1817
- package/dist/zip.min.js +1 -1
- package/index-fflate.js +3 -1
- package/index.cjs +2441 -2287
- package/index.d.ts +36 -7
- package/index.js +3 -1
- package/lib/core/codec-pool.js +6 -5
- package/lib/core/codec-worker.js +321 -0
- package/lib/core/configuration.js +11 -8
- package/lib/core/constants.js +11 -5
- package/lib/core/io.js +150 -51
- package/lib/core/streams/aes-crypto-stream.js +2 -0
- package/lib/core/streams/codec-stream.js +60 -13
- package/lib/core/streams/codecs/sjcl.js +1 -1
- package/lib/core/streams/stream-adapter.js +55 -0
- package/lib/core/streams/zip-crypto-stream.js +1 -0
- package/lib/core/streams/zip-entry-stream.js +1 -0
- package/lib/core/util/stream-codec-shim.js +2 -0
- package/lib/core/z-worker-core.js +23 -12
- package/lib/core/zip-entry.js +2 -1
- package/lib/core/zip-fs-core.js +1 -0
- package/lib/core/zip-reader.js +16 -12
- package/lib/core/zip-writer.js +102 -54
- package/lib/z-worker-inline.js +1 -1
- package/lib/zip.js +1 -1
- package/package.json +5 -5
- package/rollup-es5.config.dev.js +199 -0
- package/rollup-es5.config.js +243 -0
- package/tests/all/test-http-split-zip.js +37 -0
- package/tests/all/test-readable-stream.js +1 -2
- package/tests/all/test-readable-zip-stream.js +1 -1
- package/tests/all/test-split-zip.js +25 -22
- package/tests/tests-data.js +2 -1
- package/lib/core/codec-interface.js +0 -115
- package/lib/core/codec-pool-worker.js +0 -289
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2022 Gildas Lormeau. All rights reserved.
|
|
3
|
-
|
|
4
|
-
Redistribution and use in source and binary forms, with or without
|
|
5
|
-
modification, are permitted provided that the following conditions are met:
|
|
6
|
-
|
|
7
|
-
1. Redistributions of source code must retain the above copyright notice,
|
|
8
|
-
this list of conditions and the following disclaimer.
|
|
9
|
-
|
|
10
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
-
notice, this list of conditions and the following disclaimer in
|
|
12
|
-
the documentation and/or other materials provided with the distribution.
|
|
13
|
-
|
|
14
|
-
3. The names of the authors may not be used to endorse or promote products
|
|
15
|
-
derived from this software without specific prior written permission.
|
|
16
|
-
|
|
17
|
-
THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
|
|
18
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
|
|
20
|
-
INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
21
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
22
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
23
|
-
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
24
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
25
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
26
|
-
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/* global Worker, URL, TransformStream, WritableStream */
|
|
30
|
-
|
|
31
|
-
import {
|
|
32
|
-
Codec,
|
|
33
|
-
MESSAGE_EVENT_TYPE,
|
|
34
|
-
MESSAGE_START,
|
|
35
|
-
MESSAGE_PULL,
|
|
36
|
-
MESSAGE_DATA,
|
|
37
|
-
MESSAGE_ACK_DATA,
|
|
38
|
-
MESSAGE_CLOSE
|
|
39
|
-
} from "./codec-interface.js";
|
|
40
|
-
|
|
41
|
-
let workersSupported;
|
|
42
|
-
let classicWorkersSupported = true;
|
|
43
|
-
let transferStreamsSupported = true;
|
|
44
|
-
|
|
45
|
-
export {
|
|
46
|
-
CodecWorker
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
class CodecWorker {
|
|
50
|
-
|
|
51
|
-
constructor(workerData, stream, workerOptions, onTaskFinished) {
|
|
52
|
-
const { readable, writable } = stream;
|
|
53
|
-
const { options, config, streamOptions, useWebWorkers, transferStreams, scripts } = workerOptions;
|
|
54
|
-
Object.assign(workerData, {
|
|
55
|
-
busy: true,
|
|
56
|
-
readable,
|
|
57
|
-
writable,
|
|
58
|
-
options: Object.assign({}, options),
|
|
59
|
-
scripts,
|
|
60
|
-
transferStreams,
|
|
61
|
-
terminate() {
|
|
62
|
-
if (workerData.worker && !workerData.busy) {
|
|
63
|
-
workerData.worker.terminate();
|
|
64
|
-
workerData.interface = null;
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
onTaskFinished() {
|
|
68
|
-
workerData.busy = false;
|
|
69
|
-
onTaskFinished(workerData);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
const { signal, onstart, onprogress, size, onend } = streamOptions;
|
|
73
|
-
let chunkOffset = 0;
|
|
74
|
-
const transformer = {};
|
|
75
|
-
if (onstart) {
|
|
76
|
-
transformer.start = () => callHandler(onstart, size);
|
|
77
|
-
}
|
|
78
|
-
transformer.transform = async (chunk, controller) => {
|
|
79
|
-
chunkOffset += chunk.length;
|
|
80
|
-
if (onprogress) {
|
|
81
|
-
await callHandler(onprogress, chunkOffset, size);
|
|
82
|
-
}
|
|
83
|
-
controller.enqueue(chunk);
|
|
84
|
-
};
|
|
85
|
-
transformer.flush = () => {
|
|
86
|
-
readable.size = chunkOffset;
|
|
87
|
-
if (onend) {
|
|
88
|
-
callHandler(onend, chunkOffset);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
workerData.readable = readable.pipeThrough(new TransformStream(transformer, { highWaterMark: 1, size: () => config.chunkSize }), { signal });
|
|
92
|
-
if (workersSupported === undefined) {
|
|
93
|
-
workersSupported = typeof Worker != "undefined";
|
|
94
|
-
}
|
|
95
|
-
return useWebWorkers && workersSupported ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async function callHandler(handler, ...parameters) {
|
|
100
|
-
try {
|
|
101
|
-
await handler(...parameters);
|
|
102
|
-
} catch (_error) {
|
|
103
|
-
// ignored
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function createWorkerInterface(workerData, config) {
|
|
108
|
-
const interfaceCodec = new Codec(workerData.readable, workerData.writable, workerData.options, config);
|
|
109
|
-
const { onTaskFinished } = workerData;
|
|
110
|
-
const codec = {
|
|
111
|
-
async run() {
|
|
112
|
-
try {
|
|
113
|
-
return await interfaceCodec.run();
|
|
114
|
-
} finally {
|
|
115
|
-
onTaskFinished();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
return codec;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
|
|
123
|
-
const workerOptions = { type: "module" };
|
|
124
|
-
Object.assign(workerData, {
|
|
125
|
-
streams: {},
|
|
126
|
-
result: new Promise((resolve, reject) => {
|
|
127
|
-
workerData.resolveResult = resolve;
|
|
128
|
-
workerData.rejectResult = reject;
|
|
129
|
-
})
|
|
130
|
-
});
|
|
131
|
-
if (!workerData.interface) {
|
|
132
|
-
if (!classicWorkersSupported) {
|
|
133
|
-
workerData.worker = getWorker(workerOptions);
|
|
134
|
-
} else {
|
|
135
|
-
try {
|
|
136
|
-
workerData.worker = getWorker({});
|
|
137
|
-
} catch (_error) {
|
|
138
|
-
classicWorkersSupported = false;
|
|
139
|
-
workerData.worker = getWorker(workerOptions);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
workerData.worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false);
|
|
143
|
-
workerData.interface = {
|
|
144
|
-
async run() {
|
|
145
|
-
const { readable, options } = workerData;
|
|
146
|
-
const writer = workerData.writable.getWriter();
|
|
147
|
-
let resolveStreamClosed, streamClosed;
|
|
148
|
-
streamClosed = new Promise(resolve => resolveStreamClosed = resolve);
|
|
149
|
-
const writable = new WritableStream({
|
|
150
|
-
async write(chunk) {
|
|
151
|
-
await writer.ready;
|
|
152
|
-
await writer.write(chunk);
|
|
153
|
-
},
|
|
154
|
-
async close() {
|
|
155
|
-
writer.releaseLock();
|
|
156
|
-
resolveStreamClosed();
|
|
157
|
-
},
|
|
158
|
-
abort(reason) {
|
|
159
|
-
writer.abort(reason);
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
const scripts = workerData.scripts.slice(1);
|
|
163
|
-
const message = { type: MESSAGE_START, scripts, options, config: { chunkSize } };
|
|
164
|
-
if (workerData.transferStreams && transferStreamsSupported) {
|
|
165
|
-
const streamsTransferred = sendMessage({ ...message, readable, writable });
|
|
166
|
-
if (!streamsTransferred) {
|
|
167
|
-
transferStreamsSupported = false;
|
|
168
|
-
initStreams(readable, writable);
|
|
169
|
-
}
|
|
170
|
-
} else {
|
|
171
|
-
sendMessage(message);
|
|
172
|
-
initStreams(readable, writable);
|
|
173
|
-
}
|
|
174
|
-
const result = await workerData.result;
|
|
175
|
-
try {
|
|
176
|
-
await writable.close();
|
|
177
|
-
} catch (_error) {
|
|
178
|
-
// ignored
|
|
179
|
-
}
|
|
180
|
-
await streamClosed;
|
|
181
|
-
return result;
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
return workerData.interface;
|
|
186
|
-
|
|
187
|
-
function initStreams(readable, writable) {
|
|
188
|
-
Object.assign(workerData.streams, {
|
|
189
|
-
reader: readable.getReader(),
|
|
190
|
-
writer: writable.getWriter()
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function getWorker(options) {
|
|
195
|
-
let url, scriptUrl;
|
|
196
|
-
url = workerData.scripts[0];
|
|
197
|
-
if (typeof url == "function") {
|
|
198
|
-
url = url();
|
|
199
|
-
}
|
|
200
|
-
try {
|
|
201
|
-
scriptUrl = new URL(url, baseURL);
|
|
202
|
-
} catch (_error) {
|
|
203
|
-
scriptUrl = url;
|
|
204
|
-
}
|
|
205
|
-
return new Worker(scriptUrl, options);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function sendMessage(message) {
|
|
209
|
-
const { worker, writer, onTaskFinished } = workerData;
|
|
210
|
-
try {
|
|
211
|
-
let { data, readable, writable } = message;
|
|
212
|
-
const transferrables = [];
|
|
213
|
-
if (data) {
|
|
214
|
-
const { buffer, length } = data;
|
|
215
|
-
if (length != buffer.byteLength) {
|
|
216
|
-
data = new Uint8Array(data);
|
|
217
|
-
}
|
|
218
|
-
message.data = data.buffer;
|
|
219
|
-
transferrables.push(message.data);
|
|
220
|
-
}
|
|
221
|
-
if (readable) {
|
|
222
|
-
transferrables.push(readable);
|
|
223
|
-
}
|
|
224
|
-
if (writable) {
|
|
225
|
-
transferrables.push(writable);
|
|
226
|
-
}
|
|
227
|
-
if (transferrables.length) {
|
|
228
|
-
try {
|
|
229
|
-
worker.postMessage(message, transferrables);
|
|
230
|
-
return true;
|
|
231
|
-
} catch (error) {
|
|
232
|
-
message.readable = message.writable = null;
|
|
233
|
-
worker.postMessage(message);
|
|
234
|
-
}
|
|
235
|
-
} else {
|
|
236
|
-
worker.postMessage(message);
|
|
237
|
-
}
|
|
238
|
-
} catch (error) {
|
|
239
|
-
if (writer) {
|
|
240
|
-
writer.releaseLock();
|
|
241
|
-
}
|
|
242
|
-
onTaskFinished();
|
|
243
|
-
throw error;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
async function onMessage(event) {
|
|
248
|
-
const message = event.data;
|
|
249
|
-
const { resolveResult, rejectResult, onTaskFinished } = workerData;
|
|
250
|
-
const { reader, writer } = workerData.streams;
|
|
251
|
-
const { type, data, messageId, result } = message;
|
|
252
|
-
const reponseError = message.error;
|
|
253
|
-
try {
|
|
254
|
-
if (reponseError) {
|
|
255
|
-
const { message, stack, code, name } = reponseError;
|
|
256
|
-
const error = new Error(message);
|
|
257
|
-
Object.assign(error, { stack, code, name });
|
|
258
|
-
close(error);
|
|
259
|
-
} else {
|
|
260
|
-
if (type == MESSAGE_PULL) {
|
|
261
|
-
const { value, done } = await reader.read();
|
|
262
|
-
sendMessage({ type: MESSAGE_DATA, data: value, done, messageId });
|
|
263
|
-
}
|
|
264
|
-
if (type == MESSAGE_DATA) {
|
|
265
|
-
await writer.ready;
|
|
266
|
-
await writer.write(new Uint8Array(data));
|
|
267
|
-
sendMessage({ type: MESSAGE_ACK_DATA, messageId });
|
|
268
|
-
}
|
|
269
|
-
if (type == MESSAGE_CLOSE) {
|
|
270
|
-
close(null, result);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
} catch (error) {
|
|
274
|
-
close(error);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
function close(error, result) {
|
|
278
|
-
if (error) {
|
|
279
|
-
rejectResult(error);
|
|
280
|
-
} else {
|
|
281
|
-
resolveResult(result);
|
|
282
|
-
}
|
|
283
|
-
if (writer) {
|
|
284
|
-
writer.releaseLock();
|
|
285
|
-
}
|
|
286
|
-
onTaskFinished();
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|