@zip.js/zip.js 2.6.31 → 2.6.33
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/zip-fs-full.js +192 -153
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +192 -153
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +192 -153
- 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 +192 -153
- package/dist/zip.min.js +1 -1
- package/index.cjs +192 -153
- package/index.d.ts +3 -5
- package/lib/core/codec-pool-worker.js +7 -3
- package/lib/core/codec-pool.js +4 -3
- package/lib/core/configuration.js +8 -5
- package/lib/core/constants.js +6 -1
- package/lib/core/io.js +86 -50
- package/lib/core/z-worker-core.js +2 -1
- package/lib/core/zip-reader.js +10 -8
- package/lib/core/zip-writer.js +15 -13
- package/package.json +1 -1
- package/rollup-es5.config.dev.js +199 -0
- package/rollup-es5.config.js +243 -0
- package/tests/all/test-readable-stream.js +1 -2
- package/tests/all/test-readable-zip-stream.js +1 -1
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
|
|
29
29
|
/* global Worker, URL, TransformStream, WritableStream */
|
|
30
30
|
|
|
31
|
+
import {
|
|
32
|
+
UNDEFINED_VALUE,
|
|
33
|
+
UNDEFINED_TYPE
|
|
34
|
+
} from "./constants.js";
|
|
31
35
|
import {
|
|
32
36
|
Codec,
|
|
33
37
|
MESSAGE_EVENT_TYPE,
|
|
@@ -89,8 +93,8 @@ class CodecWorker {
|
|
|
89
93
|
}
|
|
90
94
|
};
|
|
91
95
|
workerData.readable = readable.pipeThrough(new TransformStream(transformer, { highWaterMark: 1, size: () => config.chunkSize }), { signal });
|
|
92
|
-
if (workersSupported ===
|
|
93
|
-
workersSupported = typeof Worker !=
|
|
96
|
+
if (workersSupported === UNDEFINED_VALUE) {
|
|
97
|
+
workersSupported = typeof Worker != UNDEFINED_TYPE;
|
|
94
98
|
}
|
|
95
99
|
return useWebWorkers && workersSupported ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);
|
|
96
100
|
}
|
|
@@ -149,7 +153,7 @@ function createWebWorkerInterface(workerData, { baseURL, chunkSize }) {
|
|
|
149
153
|
const writable = new WritableStream({
|
|
150
154
|
async write(chunk) {
|
|
151
155
|
await writer.ready;
|
|
152
|
-
await writer.write(
|
|
156
|
+
await writer.write(chunk);
|
|
153
157
|
},
|
|
154
158
|
async close() {
|
|
155
159
|
writer.releaseLock();
|
package/lib/core/codec-pool.js
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
/* global setTimeout, clearTimeout */
|
|
30
30
|
|
|
31
|
+
import { UNDEFINED_VALUE } from "./constants.js";
|
|
31
32
|
import {
|
|
32
33
|
CODEC_INFLATE,
|
|
33
34
|
CODEC_DEFLATE,
|
|
@@ -54,11 +55,11 @@ async function runWorker(stream, workerOptions) {
|
|
|
54
55
|
const { options, config } = workerOptions;
|
|
55
56
|
const { transferStreams, useWebWorkers, useCompressionStream, codecType, compressed, signed, encrypted } = options;
|
|
56
57
|
const { workerScripts } = config;
|
|
57
|
-
workerOptions.transferStreams = transferStreams || transferStreams ===
|
|
58
|
+
workerOptions.transferStreams = transferStreams || transferStreams === UNDEFINED_VALUE;
|
|
58
59
|
const streamCopy = !compressed && !signed && !encrypted && !workerOptions.transferStreams;
|
|
59
|
-
workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers ===
|
|
60
|
+
workerOptions.useWebWorkers = !streamCopy && (useWebWorkers || (useWebWorkers === UNDEFINED_VALUE && config.useWebWorkers));
|
|
60
61
|
workerOptions.scripts = workerOptions.useWebWorkers && workerScripts ? workerScripts[codecType] : [];
|
|
61
|
-
options.useCompressionStream = useCompressionStream || (useCompressionStream ===
|
|
62
|
+
options.useCompressionStream = useCompressionStream || (useCompressionStream === UNDEFINED_VALUE && config.useCompressionStream);
|
|
62
63
|
let worker;
|
|
63
64
|
if (pool.length < config.maxWorkers) {
|
|
64
65
|
const workerData = { indexWorker };
|
|
@@ -29,12 +29,15 @@
|
|
|
29
29
|
/* global navigator, CompressionStream, DecompressionStream */
|
|
30
30
|
|
|
31
31
|
import { getCodecStreamClass } from "./codec-interface.js";
|
|
32
|
+
import {
|
|
33
|
+
UNDEFINED_VALUE,
|
|
34
|
+
UNDEFINED_TYPE
|
|
35
|
+
} from "./constants.js";
|
|
32
36
|
|
|
33
37
|
const MINIMUM_CHUNK_SIZE = 64;
|
|
34
|
-
const UNDEFINED_VALUE = undefined;
|
|
35
38
|
let maxWorkers = 2;
|
|
36
39
|
try {
|
|
37
|
-
if (typeof navigator !=
|
|
40
|
+
if (typeof navigator != UNDEFINED_TYPE && navigator.hardwareConcurrency) {
|
|
38
41
|
maxWorkers = navigator.hardwareConcurrency;
|
|
39
42
|
}
|
|
40
43
|
} catch (_error) {
|
|
@@ -46,9 +49,9 @@ const DEFAULT_CONFIGURATION = {
|
|
|
46
49
|
terminateWorkerTimeout: 5000,
|
|
47
50
|
useWebWorkers: true,
|
|
48
51
|
useCompressionStream: true,
|
|
49
|
-
workerScripts:
|
|
50
|
-
CompressionStreamNative: typeof CompressionStream !=
|
|
51
|
-
DecompressionStreamNative: typeof DecompressionStream !=
|
|
52
|
+
workerScripts: UNDEFINED_VALUE,
|
|
53
|
+
CompressionStreamNative: typeof CompressionStream != UNDEFINED_TYPE && CompressionStream,
|
|
54
|
+
DecompressionStreamNative: typeof DecompressionStream != UNDEFINED_TYPE && DecompressionStream
|
|
52
55
|
};
|
|
53
56
|
|
|
54
57
|
const config = Object.assign({}, DEFAULT_CONFIGURATION);
|
package/lib/core/constants.js
CHANGED
|
@@ -68,6 +68,9 @@ const DIRECTORY_SIGNATURE = "/";
|
|
|
68
68
|
const MAX_DATE = new Date(2107, 11, 31);
|
|
69
69
|
const MIN_DATE = new Date(1980, 0, 1);
|
|
70
70
|
|
|
71
|
+
const UNDEFINED_VALUE = undefined;
|
|
72
|
+
const UNDEFINED_TYPE = "undefined";
|
|
73
|
+
|
|
71
74
|
export {
|
|
72
75
|
MAX_32_BITS,
|
|
73
76
|
MAX_16_BITS,
|
|
@@ -102,5 +105,7 @@ export {
|
|
|
102
105
|
VERSION_AES,
|
|
103
106
|
DIRECTORY_SIGNATURE,
|
|
104
107
|
MIN_DATE,
|
|
105
|
-
MAX_DATE
|
|
108
|
+
MAX_DATE,
|
|
109
|
+
UNDEFINED_VALUE,
|
|
110
|
+
UNDEFINED_TYPE
|
|
106
111
|
};
|
package/lib/core/io.js
CHANGED
|
@@ -36,11 +36,15 @@ const HTTP_HEADER_CONTENT_LENGTH = "Content-Length";
|
|
|
36
36
|
const HTTP_HEADER_CONTENT_RANGE = "Content-Range";
|
|
37
37
|
const HTTP_HEADER_ACCEPT_RANGES = "Accept-Ranges";
|
|
38
38
|
const HTTP_HEADER_RANGE = "Range";
|
|
39
|
+
const HTTP_HEADER_CONTENT_TYPE = "Content-Type";
|
|
39
40
|
const HTTP_METHOD_HEAD = "HEAD";
|
|
40
41
|
const HTTP_METHOD_GET = "GET";
|
|
41
42
|
const HTTP_RANGE_UNIT = "bytes";
|
|
42
43
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
43
44
|
|
|
45
|
+
const PROPERTY_NAME_WRITABLE = "writable";
|
|
46
|
+
|
|
47
|
+
import { UNDEFINED_VALUE } from "./constants.js";
|
|
44
48
|
import { getConfiguration } from "./configuration.js";
|
|
45
49
|
|
|
46
50
|
class Stream {
|
|
@@ -88,7 +92,7 @@ class Writer extends Stream {
|
|
|
88
92
|
return writer.writeUint8Array(chunk);
|
|
89
93
|
}
|
|
90
94
|
});
|
|
91
|
-
Object.defineProperty(writer,
|
|
95
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
92
96
|
get() {
|
|
93
97
|
return writable;
|
|
94
98
|
}
|
|
@@ -104,21 +108,26 @@ class Data64URIReader extends Reader {
|
|
|
104
108
|
|
|
105
109
|
constructor(dataURI) {
|
|
106
110
|
super();
|
|
107
|
-
const reader = this;
|
|
108
|
-
reader.dataURI = dataURI;
|
|
109
111
|
let dataEnd = dataURI.length;
|
|
110
112
|
while (dataURI.charAt(dataEnd - 1) == "=") {
|
|
111
113
|
dataEnd--;
|
|
112
114
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
const dataStart = dataURI.indexOf(",") + 1;
|
|
116
|
+
Object.assign(this, {
|
|
117
|
+
dataURI,
|
|
118
|
+
dataStart,
|
|
119
|
+
size: Math.floor((dataEnd - dataStart) * 0.75)
|
|
120
|
+
});
|
|
115
121
|
}
|
|
116
122
|
|
|
117
123
|
readUint8Array(offset, length) {
|
|
124
|
+
const {
|
|
125
|
+
dataStart,
|
|
126
|
+
dataURI
|
|
127
|
+
} = this;
|
|
118
128
|
const dataArray = new Uint8Array(length);
|
|
119
129
|
const start = Math.floor(offset / 3) * 4;
|
|
120
|
-
const
|
|
121
|
-
const bytes = atob(this.dataURI.substring(start + dataStart, Math.ceil((offset + length) / 3) * 4 + dataStart));
|
|
130
|
+
const bytes = atob(dataURI.substring(start + dataStart, Math.ceil((offset + length) / 3) * 4 + dataStart));
|
|
122
131
|
const delta = offset - Math.floor(start / 4) * 3;
|
|
123
132
|
for (let indexByte = delta; indexByte < delta + length; indexByte++) {
|
|
124
133
|
dataArray[indexByte - delta] = bytes.charCodeAt(indexByte);
|
|
@@ -131,8 +140,10 @@ class Data64URIWriter extends Writer {
|
|
|
131
140
|
|
|
132
141
|
constructor(contentType) {
|
|
133
142
|
super();
|
|
134
|
-
|
|
135
|
-
|
|
143
|
+
Object.assign(this, {
|
|
144
|
+
data: "data:" + (contentType || "") + ";base64,",
|
|
145
|
+
pending: []
|
|
146
|
+
});
|
|
136
147
|
}
|
|
137
148
|
|
|
138
149
|
writeUint8Array(array) {
|
|
@@ -163,8 +174,10 @@ class BlobReader extends Reader {
|
|
|
163
174
|
|
|
164
175
|
constructor(blob) {
|
|
165
176
|
super();
|
|
166
|
-
this
|
|
167
|
-
|
|
177
|
+
Object.assign(this, {
|
|
178
|
+
blob,
|
|
179
|
+
size: blob.size
|
|
180
|
+
});
|
|
168
181
|
}
|
|
169
182
|
|
|
170
183
|
async readUint8Array(offset, length) {
|
|
@@ -181,9 +194,9 @@ class BlobWriter extends Stream {
|
|
|
181
194
|
const transformStream = new TransformStream();
|
|
182
195
|
const headers = [];
|
|
183
196
|
if (contentType) {
|
|
184
|
-
headers.push([
|
|
197
|
+
headers.push([HTTP_HEADER_CONTENT_TYPE, contentType]);
|
|
185
198
|
}
|
|
186
|
-
Object.defineProperty(writer,
|
|
199
|
+
Object.defineProperty(writer, PROPERTY_NAME_WRITABLE, {
|
|
187
200
|
get() {
|
|
188
201
|
return transformStream.writable;
|
|
189
202
|
}
|
|
@@ -224,8 +237,10 @@ class TextWriter extends BlobWriter {
|
|
|
224
237
|
} else {
|
|
225
238
|
const reader = new FileReader();
|
|
226
239
|
return new Promise((resolve, reject) => {
|
|
227
|
-
reader
|
|
228
|
-
|
|
240
|
+
Object.assign(reader, {
|
|
241
|
+
onload: ({ target }) => resolve(target.result),
|
|
242
|
+
onerror: () => reject(reader.error)
|
|
243
|
+
});
|
|
229
244
|
reader.readAsText(blob, encoding);
|
|
230
245
|
});
|
|
231
246
|
}
|
|
@@ -236,16 +251,7 @@ class FetchReader extends Reader {
|
|
|
236
251
|
|
|
237
252
|
constructor(url, options) {
|
|
238
253
|
super();
|
|
239
|
-
|
|
240
|
-
reader.url = url;
|
|
241
|
-
reader.preventHeadRequest = options.preventHeadRequest;
|
|
242
|
-
reader.useRangeHeader = options.useRangeHeader;
|
|
243
|
-
reader.forceRangeRequests = options.forceRangeRequests;
|
|
244
|
-
reader.options = options = Object.assign({}, options);
|
|
245
|
-
delete options.preventHeadRequest;
|
|
246
|
-
delete options.useRangeHeader;
|
|
247
|
-
delete options.forceRangeRequests;
|
|
248
|
-
delete options.useXHR;
|
|
254
|
+
createHtpReader(this, url, options);
|
|
249
255
|
}
|
|
250
256
|
|
|
251
257
|
async init() {
|
|
@@ -262,12 +268,7 @@ class XHRReader extends Reader {
|
|
|
262
268
|
|
|
263
269
|
constructor(url, options) {
|
|
264
270
|
super();
|
|
265
|
-
|
|
266
|
-
reader.url = url;
|
|
267
|
-
reader.preventHeadRequest = options.preventHeadRequest;
|
|
268
|
-
reader.useRangeHeader = options.useRangeHeader;
|
|
269
|
-
reader.forceRangeRequests = options.forceRangeRequests;
|
|
270
|
-
reader.options = options;
|
|
271
|
+
createHtpReader(this, url, options);
|
|
271
272
|
}
|
|
272
273
|
|
|
273
274
|
async init() {
|
|
@@ -280,14 +281,39 @@ class XHRReader extends Reader {
|
|
|
280
281
|
}
|
|
281
282
|
}
|
|
282
283
|
|
|
284
|
+
function createHtpReader(httpReader, url, options) {
|
|
285
|
+
const {
|
|
286
|
+
preventHeadRequest,
|
|
287
|
+
useRangeHeader,
|
|
288
|
+
forceRangeRequests
|
|
289
|
+
} = options;
|
|
290
|
+
options = Object.assign({}, options);
|
|
291
|
+
delete options.preventHeadRequest;
|
|
292
|
+
delete options.useRangeHeader;
|
|
293
|
+
delete options.forceRangeRequests;
|
|
294
|
+
delete options.useXHR;
|
|
295
|
+
Object.assign(httpReader, {
|
|
296
|
+
url,
|
|
297
|
+
options,
|
|
298
|
+
preventHeadRequest,
|
|
299
|
+
useRangeHeader,
|
|
300
|
+
forceRangeRequests
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
|
|
283
304
|
async function initHttpReader(httpReader, sendRequest, getRequestData) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
305
|
+
const {
|
|
306
|
+
url,
|
|
307
|
+
useRangeHeader,
|
|
308
|
+
forceRangeRequests
|
|
309
|
+
} = httpReader;
|
|
310
|
+
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests)) {
|
|
311
|
+
const { headers } = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
|
|
312
|
+
if (!forceRangeRequests && headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
|
|
287
313
|
throw new Error(ERR_HTTP_RANGE);
|
|
288
314
|
} else {
|
|
289
315
|
let contentSize;
|
|
290
|
-
const contentRangeHeader =
|
|
316
|
+
const contentRangeHeader = headers.get(HTTP_HEADER_CONTENT_RANGE);
|
|
291
317
|
if (contentRangeHeader) {
|
|
292
318
|
const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
|
|
293
319
|
if (splitHeader.length) {
|
|
@@ -297,7 +323,7 @@ async function initHttpReader(httpReader, sendRequest, getRequestData) {
|
|
|
297
323
|
}
|
|
298
324
|
}
|
|
299
325
|
}
|
|
300
|
-
if (contentSize ===
|
|
326
|
+
if (contentSize === UNDEFINED_VALUE) {
|
|
301
327
|
await getContentLength(httpReader, sendRequest, getRequestData);
|
|
302
328
|
} else {
|
|
303
329
|
httpReader.size = contentSize;
|
|
@@ -309,17 +335,23 @@ async function initHttpReader(httpReader, sendRequest, getRequestData) {
|
|
|
309
335
|
}
|
|
310
336
|
|
|
311
337
|
async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest, getRequestData) {
|
|
312
|
-
|
|
338
|
+
const {
|
|
339
|
+
data,
|
|
340
|
+
useRangeHeader,
|
|
341
|
+
forceRangeRequests,
|
|
342
|
+
options
|
|
343
|
+
} = httpReader;
|
|
344
|
+
if (useRangeHeader || forceRangeRequests) {
|
|
313
345
|
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
|
|
314
346
|
if (response.status != 206) {
|
|
315
347
|
throw new Error(ERR_HTTP_RANGE);
|
|
316
348
|
}
|
|
317
349
|
return new Uint8Array(await response.arrayBuffer());
|
|
318
350
|
} else {
|
|
319
|
-
if (!
|
|
320
|
-
await getRequestData(httpReader,
|
|
351
|
+
if (!data) {
|
|
352
|
+
await getRequestData(httpReader, options);
|
|
321
353
|
}
|
|
322
|
-
return new Uint8Array(
|
|
354
|
+
return new Uint8Array(data.subarray(index, index + length));
|
|
323
355
|
}
|
|
324
356
|
}
|
|
325
357
|
|
|
@@ -327,8 +359,8 @@ function getRangeHeaders(httpReader, index = 0, length = 1) {
|
|
|
327
359
|
return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
|
|
328
360
|
}
|
|
329
361
|
|
|
330
|
-
function getHeaders(
|
|
331
|
-
const headers =
|
|
362
|
+
function getHeaders({ options }) {
|
|
363
|
+
const { headers } = options;
|
|
332
364
|
if (headers) {
|
|
333
365
|
if (Symbol.iterator in headers) {
|
|
334
366
|
return Object.fromEntries(headers);
|
|
@@ -413,9 +445,10 @@ class HttpReader extends Reader {
|
|
|
413
445
|
|
|
414
446
|
constructor(url, options = {}) {
|
|
415
447
|
super();
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
448
|
+
Object.assign(this, {
|
|
449
|
+
url,
|
|
450
|
+
reader: options.useXHR ? new XHRReader(url, options) : new FetchReader(url, options)
|
|
451
|
+
});
|
|
419
452
|
}
|
|
420
453
|
|
|
421
454
|
set size(value) {
|
|
@@ -449,8 +482,10 @@ class Uint8ArrayReader extends Reader {
|
|
|
449
482
|
|
|
450
483
|
constructor(array) {
|
|
451
484
|
super();
|
|
452
|
-
this
|
|
453
|
-
|
|
485
|
+
Object.assign(this, {
|
|
486
|
+
array,
|
|
487
|
+
size: array.length
|
|
488
|
+
});
|
|
454
489
|
}
|
|
455
490
|
|
|
456
491
|
readUint8Array(index, length) {
|
|
@@ -462,9 +497,10 @@ class Uint8ArrayWriter extends Writer {
|
|
|
462
497
|
|
|
463
498
|
init(initSize = 0) {
|
|
464
499
|
super.init();
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
500
|
+
Object.assign(this, {
|
|
501
|
+
offset: 0,
|
|
502
|
+
array: new Uint8Array(initSize)
|
|
503
|
+
});
|
|
468
504
|
}
|
|
469
505
|
|
|
470
506
|
writeUint8Array(array) {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
/* global self, importScripts, addEventListener, postMessage, ReadableStream, WritableStream */
|
|
30
30
|
|
|
31
|
+
import { UNDEFINED_VALUE } from "./constants.js";
|
|
31
32
|
import {
|
|
32
33
|
Codec,
|
|
33
34
|
getCodecStreamClass,
|
|
@@ -70,7 +71,7 @@ async function init(message) {
|
|
|
70
71
|
try {
|
|
71
72
|
const { options, scripts, config } = message;
|
|
72
73
|
if (scripts && scripts.length) {
|
|
73
|
-
importScripts.apply(
|
|
74
|
+
importScripts.apply(UNDEFINED_VALUE, scripts);
|
|
74
75
|
}
|
|
75
76
|
if (self.initCodec) {
|
|
76
77
|
self.initCodec();
|
package/lib/core/zip-reader.js
CHANGED
|
@@ -54,7 +54,8 @@ import {
|
|
|
54
54
|
BITFLAG_DATA_DESCRIPTOR,
|
|
55
55
|
BITFLAG_LANG_ENCODING_FLAG,
|
|
56
56
|
FILE_ATTR_MSDOS_DIR_MASK,
|
|
57
|
-
DIRECTORY_SIGNATURE
|
|
57
|
+
DIRECTORY_SIGNATURE,
|
|
58
|
+
UNDEFINED_VALUE
|
|
58
59
|
} from "./constants.js";
|
|
59
60
|
import {
|
|
60
61
|
getConfiguration,
|
|
@@ -127,7 +128,7 @@ class ZipReader {
|
|
|
127
128
|
let { reader } = zipReader;
|
|
128
129
|
const { config } = zipReader;
|
|
129
130
|
await initStream(reader);
|
|
130
|
-
if (reader.size ===
|
|
131
|
+
if (reader.size === UNDEFINED_VALUE || !reader.readUint8Array) {
|
|
131
132
|
if (Array.isArray(reader)) {
|
|
132
133
|
reader = new SplitZipReader(reader);
|
|
133
134
|
} else {
|
|
@@ -157,7 +158,7 @@ class ZipReader {
|
|
|
157
158
|
const commentLength = getUint16(endOfDirectoryView, 20);
|
|
158
159
|
const appendedDataOffset = commentOffset + END_OF_CENTRAL_DIR_LENGTH + commentLength;
|
|
159
160
|
let diskNumber = getUint16(endOfDirectoryView, 4);
|
|
160
|
-
if (lastDiskNumber !==
|
|
161
|
+
if (lastDiskNumber !== UNDEFINED_VALUE && diskNumber != lastDiskNumber) {
|
|
161
162
|
throw new Error(ERR_SPLIT_ZIP_FILE);
|
|
162
163
|
}
|
|
163
164
|
let filesLength = getUint16(endOfDirectoryView, 8);
|
|
@@ -359,8 +360,9 @@ class ZipEntry {
|
|
|
359
360
|
throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
|
|
360
361
|
}
|
|
361
362
|
readCommonHeader(localDirectory, dataView, 4);
|
|
362
|
-
|
|
363
|
-
|
|
363
|
+
localDirectory.rawExtraField = localDirectory.extraFieldLength ?
|
|
364
|
+
await readUint8Array(reader, offset + 30 + localDirectory.filenameLength, localDirectory.extraFieldLength, diskNumberStart) :
|
|
365
|
+
new Uint8Array();
|
|
364
366
|
await readCommonFooter(zipEntry, localDirectory, dataView, 4);
|
|
365
367
|
Object.assign(fileEntry, {
|
|
366
368
|
lastAccessDate: localDirectory.lastAccessDate,
|
|
@@ -369,7 +371,7 @@ class ZipEntry {
|
|
|
369
371
|
const encrypted = zipEntry.encrypted && localDirectory.encrypted;
|
|
370
372
|
const zipCrypto = encrypted && !extraFieldAES;
|
|
371
373
|
if (encrypted) {
|
|
372
|
-
if (!zipCrypto && extraFieldAES.strength ===
|
|
374
|
+
if (!zipCrypto && extraFieldAES.strength === UNDEFINED_VALUE) {
|
|
373
375
|
throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
|
|
374
376
|
} else if (!password) {
|
|
375
377
|
throw new Error(ERR_ENCRYPTED);
|
|
@@ -386,7 +388,7 @@ class ZipEntry {
|
|
|
386
388
|
};
|
|
387
389
|
}
|
|
388
390
|
const { writable } = writer;
|
|
389
|
-
if (writable.size ===
|
|
391
|
+
if (writable.size === UNDEFINED_VALUE) {
|
|
390
392
|
writable.size = 0;
|
|
391
393
|
}
|
|
392
394
|
const signal = getOptionValue(zipEntry, options, "signal");
|
|
@@ -634,7 +636,7 @@ async function seekSignature(reader, signature, startOffset, minimumBytes, maxim
|
|
|
634
636
|
}
|
|
635
637
|
|
|
636
638
|
function getOptionValue(zipReader, options, name) {
|
|
637
|
-
return options[name] ===
|
|
639
|
+
return options[name] === UNDEFINED_VALUE ? zipReader.options[name] : options[name];
|
|
638
640
|
}
|
|
639
641
|
|
|
640
642
|
function getDate(timeRaw) {
|
package/lib/core/zip-writer.js
CHANGED
|
@@ -57,7 +57,8 @@ import {
|
|
|
57
57
|
VERSION_AES,
|
|
58
58
|
DIRECTORY_SIGNATURE,
|
|
59
59
|
MIN_DATE,
|
|
60
|
-
MAX_DATE
|
|
60
|
+
MAX_DATE,
|
|
61
|
+
UNDEFINED_VALUE
|
|
61
62
|
} from "./constants.js";
|
|
62
63
|
import {
|
|
63
64
|
getConfiguration,
|
|
@@ -96,7 +97,7 @@ class ZipWriter {
|
|
|
96
97
|
if (writer instanceof WritableStream) {
|
|
97
98
|
writer = { writable: writer };
|
|
98
99
|
}
|
|
99
|
-
if (writer.writable.size ===
|
|
100
|
+
if (writer.writable.size === UNDEFINED_VALUE) {
|
|
100
101
|
writer.writable.size = 0;
|
|
101
102
|
}
|
|
102
103
|
Object.assign(this, {
|
|
@@ -203,7 +204,7 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
203
204
|
const password = getOptionValue(zipWriter, options, "password");
|
|
204
205
|
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
|
|
205
206
|
const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
|
|
206
|
-
if (password !==
|
|
207
|
+
if (password !== UNDEFINED_VALUE && encryptionStrength !== UNDEFINED_VALUE && (encryptionStrength < 1 || encryptionStrength > 3)) {
|
|
207
208
|
throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
|
|
208
209
|
}
|
|
209
210
|
let rawExtraField = new Uint8Array();
|
|
@@ -227,18 +228,18 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
227
228
|
});
|
|
228
229
|
}
|
|
229
230
|
let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
|
|
230
|
-
if (extendedTimestamp ===
|
|
231
|
+
if (extendedTimestamp === UNDEFINED_VALUE) {
|
|
231
232
|
extendedTimestamp = true;
|
|
232
233
|
}
|
|
233
234
|
let maximumCompressedSize = 0;
|
|
234
235
|
let maximumEntrySize = 0;
|
|
235
236
|
let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
|
|
236
|
-
if (keepOrder ===
|
|
237
|
+
if (keepOrder === UNDEFINED_VALUE) {
|
|
237
238
|
keepOrder = true;
|
|
238
239
|
}
|
|
239
240
|
let uncompressedSize = 0;
|
|
240
241
|
let msDosCompatible = getOptionValue(zipWriter, options, "msDosCompatible");
|
|
241
|
-
if (msDosCompatible ===
|
|
242
|
+
if (msDosCompatible === UNDEFINED_VALUE) {
|
|
242
243
|
msDosCompatible = true;
|
|
243
244
|
}
|
|
244
245
|
const internalFileAttribute = getOptionValue(zipWriter, options, "internalFileAttribute") || 0;
|
|
@@ -251,15 +252,16 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
251
252
|
};
|
|
252
253
|
}
|
|
253
254
|
await initStream(reader);
|
|
254
|
-
if (reader.size ===
|
|
255
|
+
if (reader.size === UNDEFINED_VALUE) {
|
|
255
256
|
options.dataDescriptor = true;
|
|
256
|
-
if (zip64 ===
|
|
257
|
+
if (zip64 || zip64 === UNDEFINED_VALUE) {
|
|
257
258
|
zip64 = true;
|
|
259
|
+
maximumCompressedSize = MAX_32_BITS;
|
|
258
260
|
}
|
|
259
261
|
} else {
|
|
260
262
|
uncompressedSize = reader.size;
|
|
263
|
+
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
261
264
|
}
|
|
262
|
-
maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
|
|
263
265
|
}
|
|
264
266
|
if (zipWriter.offset + zipWriter.pendingEntriesSize >= MAX_32_BITS ||
|
|
265
267
|
uncompressedSize >= MAX_32_BITS ||
|
|
@@ -278,10 +280,10 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
278
280
|
let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
|
|
279
281
|
const signal = getOptionValue(zipWriter, options, "signal");
|
|
280
282
|
const useCompressionStream = getOptionValue(zipWriter, options, "useCompressionStream");
|
|
281
|
-
if (dataDescriptor ===
|
|
283
|
+
if (dataDescriptor === UNDEFINED_VALUE) {
|
|
282
284
|
dataDescriptor = true;
|
|
283
285
|
}
|
|
284
|
-
if (dataDescriptor && dataDescriptorSignature ===
|
|
286
|
+
if (dataDescriptor && dataDescriptorSignature === UNDEFINED_VALUE) {
|
|
285
287
|
dataDescriptorSignature = false;
|
|
286
288
|
}
|
|
287
289
|
options = Object.assign({}, options, {
|
|
@@ -748,7 +750,7 @@ function setEntryInfo(entryInfo, options) {
|
|
|
748
750
|
zipCrypto,
|
|
749
751
|
dataDescriptor
|
|
750
752
|
} = options;
|
|
751
|
-
if ((!encrypted || zipCrypto) && signature !==
|
|
753
|
+
if ((!encrypted || zipCrypto) && signature !== UNDEFINED_VALUE) {
|
|
752
754
|
setUint32(headerView, 10, signature);
|
|
753
755
|
if (dataDescriptor) {
|
|
754
756
|
setUint32(dataDescriptorView, dataDescriptorOffset, signature);
|
|
@@ -935,7 +937,7 @@ function getTimeNTFS(date) {
|
|
|
935
937
|
}
|
|
936
938
|
|
|
937
939
|
function getOptionValue(zipWriter, options, name) {
|
|
938
|
-
return options[name] ===
|
|
940
|
+
return options[name] === UNDEFINED_VALUE ? zipWriter.options[name] : options[name];
|
|
939
941
|
}
|
|
940
942
|
|
|
941
943
|
function getMaximumCompressedSize(uncompressedSize) {
|
package/package.json
CHANGED