@zip.js/zip.js 2.7.40 → 2.7.42
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-fs-full.js +28 -13
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +28 -13
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +28 -13
- 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 +28 -13
- package/dist/zip.min.js +1 -1
- package/index.cjs +28 -13
- package/index.d.ts +41 -19
- package/index.min.js +1 -1
- package/lib/core/io.js +23 -9
- package/lib/core/zip-reader.js +3 -2
- package/lib/core/zip-writer.js +4 -3
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -8629,35 +8629,43 @@ function createHttpReader(httpReader, url, options) {
|
|
|
8629
8629
|
const {
|
|
8630
8630
|
preventHeadRequest,
|
|
8631
8631
|
useRangeHeader,
|
|
8632
|
-
forceRangeRequests
|
|
8632
|
+
forceRangeRequests,
|
|
8633
|
+
combineSizeEocd
|
|
8633
8634
|
} = options;
|
|
8634
8635
|
options = Object.assign({}, options);
|
|
8635
8636
|
delete options.preventHeadRequest;
|
|
8636
8637
|
delete options.useRangeHeader;
|
|
8637
8638
|
delete options.forceRangeRequests;
|
|
8639
|
+
delete options.combineSizeEocd;
|
|
8638
8640
|
delete options.useXHR;
|
|
8639
8641
|
Object.assign(httpReader, {
|
|
8640
8642
|
url,
|
|
8641
8643
|
options,
|
|
8642
8644
|
preventHeadRequest,
|
|
8643
8645
|
useRangeHeader,
|
|
8644
|
-
forceRangeRequests
|
|
8646
|
+
forceRangeRequests,
|
|
8647
|
+
combineSizeEocd
|
|
8645
8648
|
});
|
|
8646
8649
|
}
|
|
8647
8650
|
|
|
8648
8651
|
async function initHttpReader(httpReader, sendRequest, getRequestData) {
|
|
8649
8652
|
const {
|
|
8650
8653
|
url,
|
|
8654
|
+
preventHeadRequest,
|
|
8651
8655
|
useRangeHeader,
|
|
8652
|
-
forceRangeRequests
|
|
8656
|
+
forceRangeRequests,
|
|
8657
|
+
combineSizeEocd
|
|
8653
8658
|
} = httpReader;
|
|
8654
|
-
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests)) {
|
|
8655
|
-
const
|
|
8656
|
-
if (!forceRangeRequests && headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
|
|
8659
|
+
if (isHttpFamily(url) && (useRangeHeader || forceRangeRequests) && (typeof preventHeadRequest == "undefined" || preventHeadRequest)) {
|
|
8660
|
+
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, combineSizeEocd ? -END_OF_CENTRAL_DIR_LENGTH : undefined));
|
|
8661
|
+
if (!forceRangeRequests && response.headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
|
|
8657
8662
|
throw new Error(ERR_HTTP_RANGE);
|
|
8658
8663
|
} else {
|
|
8664
|
+
if (combineSizeEocd) {
|
|
8665
|
+
httpReader.eocdCache = new Uint8Array(await response.arrayBuffer());
|
|
8666
|
+
}
|
|
8659
8667
|
let contentSize;
|
|
8660
|
-
const contentRangeHeader = headers.get(HTTP_HEADER_CONTENT_RANGE);
|
|
8668
|
+
const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
|
|
8661
8669
|
if (contentRangeHeader) {
|
|
8662
8670
|
const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
|
|
8663
8671
|
if (splitHeader.length) {
|
|
@@ -8682,9 +8690,14 @@ async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest,
|
|
|
8682
8690
|
const {
|
|
8683
8691
|
useRangeHeader,
|
|
8684
8692
|
forceRangeRequests,
|
|
8693
|
+
eocdCache,
|
|
8694
|
+
size,
|
|
8685
8695
|
options
|
|
8686
8696
|
} = httpReader;
|
|
8687
8697
|
if (useRangeHeader || forceRangeRequests) {
|
|
8698
|
+
if (eocdCache && index == size - END_OF_CENTRAL_DIR_LENGTH && length == END_OF_CENTRAL_DIR_LENGTH) {
|
|
8699
|
+
return eocdCache;
|
|
8700
|
+
}
|
|
8688
8701
|
const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
|
|
8689
8702
|
if (response.status != 206) {
|
|
8690
8703
|
throw new Error(ERR_HTTP_RANGE);
|
|
@@ -8700,7 +8713,7 @@ async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest,
|
|
|
8700
8713
|
}
|
|
8701
8714
|
|
|
8702
8715
|
function getRangeHeaders(httpReader, index = 0, length = 1) {
|
|
8703
|
-
return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
|
|
8716
|
+
return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + (index < 0 ? index : index + "-" + (index + length - 1)) });
|
|
8704
8717
|
}
|
|
8705
8718
|
|
|
8706
8719
|
function getHeaders({ options }) {
|
|
@@ -9395,9 +9408,10 @@ class ZipReader {
|
|
|
9395
9408
|
commentUTF8,
|
|
9396
9409
|
rawExtraField: directoryArray.subarray(extraFieldOffset, commentOffset)
|
|
9397
9410
|
});
|
|
9411
|
+
const decode = getOptionValue$1(zipReader, options, "decodeText") || decodeText;
|
|
9398
9412
|
const [filename, comment] = await Promise.all([
|
|
9399
|
-
|
|
9400
|
-
|
|
9413
|
+
decode(rawFilename, filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437),
|
|
9414
|
+
decode(rawComment, commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437)
|
|
9401
9415
|
]);
|
|
9402
9416
|
Object.assign(fileEntry, {
|
|
9403
9417
|
rawComment,
|
|
@@ -10001,12 +10015,13 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
10001
10015
|
} else {
|
|
10002
10016
|
options.directory = name.endsWith(DIRECTORY_SIGNATURE);
|
|
10003
10017
|
}
|
|
10004
|
-
const
|
|
10018
|
+
const encode = getOptionValue(zipWriter, options, "encodeText", encodeText);
|
|
10019
|
+
const rawFilename = encode(name);
|
|
10005
10020
|
if (getLength(rawFilename) > MAX_16_BITS) {
|
|
10006
10021
|
throw new Error(ERR_INVALID_ENTRY_NAME);
|
|
10007
10022
|
}
|
|
10008
10023
|
const comment = options.comment || "";
|
|
10009
|
-
const rawComment =
|
|
10024
|
+
const rawComment = encode(comment);
|
|
10010
10025
|
if (getLength(rawComment) > MAX_16_BITS) {
|
|
10011
10026
|
throw new Error(ERR_INVALID_ENTRY_COMMENT);
|
|
10012
10027
|
}
|
|
@@ -10109,7 +10124,7 @@ async function addFile(zipWriter, name, reader, options) {
|
|
|
10109
10124
|
zip64DiskNumberStart,
|
|
10110
10125
|
password,
|
|
10111
10126
|
rawPassword,
|
|
10112
|
-
level,
|
|
10127
|
+
level: !useCompressionStream && zipWriter.config.CompressionStream === UNDEFINED_VALUE ? 0 : level,
|
|
10113
10128
|
useWebWorkers,
|
|
10114
10129
|
encryptionStrength,
|
|
10115
10130
|
extendedTimestamp,
|
package/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @see {@link https://wicg.github.io/entries-api/#api-entry|specification}
|
|
5
5
|
*/
|
|
6
6
|
// deno-lint-ignore no-empty-interface
|
|
7
|
-
interface FileSystemEntryLike {}
|
|
7
|
+
interface FileSystemEntryLike { }
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Represents the `FileSystemHandle` class.
|
|
@@ -12,7 +12,7 @@ interface FileSystemEntryLike {}
|
|
|
12
12
|
* @see {@link https://fs.spec.whatwg.org/#api-filesystemhandle}
|
|
13
13
|
*/
|
|
14
14
|
// deno-lint-ignore no-empty-interface
|
|
15
|
-
interface FileSystemHandleLike {}
|
|
15
|
+
interface FileSystemHandleLike { }
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Represents a generic `TransformStream` class.
|
|
@@ -268,7 +268,7 @@ declare class ZipInflate extends SyncCodec {
|
|
|
268
268
|
/**
|
|
269
269
|
* Represents a class implementing `CompressionStream` or `DecompressionStream` interfaces.
|
|
270
270
|
*/
|
|
271
|
-
declare class CodecStream extends TransformStream {}
|
|
271
|
+
declare class CodecStream extends TransformStream { }
|
|
272
272
|
|
|
273
273
|
/**
|
|
274
274
|
* Returns the MIME type corresponding to a filename extension.
|
|
@@ -361,41 +361,41 @@ export class Reader<Type> implements Initializable, ReadableReader {
|
|
|
361
361
|
/**
|
|
362
362
|
* Represents a {@link Reader} instance used to read data provided as a `string`.
|
|
363
363
|
*/
|
|
364
|
-
export class TextReader extends Reader<string> {}
|
|
364
|
+
export class TextReader extends Reader<string> { }
|
|
365
365
|
|
|
366
366
|
/**
|
|
367
367
|
* Represents a {@link Reader} instance used to read data provided as a `Blob` instance.
|
|
368
368
|
*/
|
|
369
|
-
export class BlobReader extends Reader<Blob> {}
|
|
369
|
+
export class BlobReader extends Reader<Blob> { }
|
|
370
370
|
|
|
371
371
|
/**
|
|
372
372
|
* Represents a {@link Reader} instance used to read data provided as a Data URI `string` encoded in Base64.
|
|
373
373
|
*/
|
|
374
|
-
export class Data64URIReader extends Reader<string> {}
|
|
374
|
+
export class Data64URIReader extends Reader<string> { }
|
|
375
375
|
|
|
376
376
|
/**
|
|
377
377
|
* Represents a {@link Reader} instance used to read data provided as a `Uint8Array` instance.
|
|
378
378
|
*/
|
|
379
|
-
export class Uint8ArrayReader extends Reader<Uint8Array> {}
|
|
379
|
+
export class Uint8ArrayReader extends Reader<Uint8Array> { }
|
|
380
380
|
|
|
381
381
|
/**
|
|
382
382
|
* Represents a {@link Reader} instance used to read data provided as an array of {@link ReadableReader} instances (e.g. split zip files).
|
|
383
383
|
*
|
|
384
384
|
* @deprecated Use {@link SplitDataReader} instead.
|
|
385
385
|
*/
|
|
386
|
-
export class SplitZipReader extends SplitDataReader {}
|
|
386
|
+
export class SplitZipReader extends SplitDataReader { }
|
|
387
387
|
|
|
388
388
|
/**
|
|
389
389
|
* Represents a {@link Reader} instance used to read data provided as an array of {@link ReadableReader} instances (e.g. split zip files).
|
|
390
390
|
*/
|
|
391
391
|
export class SplitDataReader
|
|
392
|
-
extends Reader<Reader<unknown>[] | ReadableReader[] | ReadableStream[]> {}
|
|
392
|
+
extends Reader<Reader<unknown>[] | ReadableReader[] | ReadableStream[]> { }
|
|
393
393
|
|
|
394
394
|
/**
|
|
395
395
|
* Represents a URL stored into a `string`.
|
|
396
396
|
*/
|
|
397
397
|
// deno-lint-ignore no-empty-interface
|
|
398
|
-
interface URLString extends String {}
|
|
398
|
+
interface URLString extends String { }
|
|
399
399
|
|
|
400
400
|
/**
|
|
401
401
|
* Represents a {@link Reader} instance used to fetch data from a URL.
|
|
@@ -441,10 +441,17 @@ export interface HttpOptions extends HttpRangeOptions {
|
|
|
441
441
|
forceRangeRequests?: boolean;
|
|
442
442
|
/**
|
|
443
443
|
* `true` to prevent using `HEAD` HTTP request in order the get the size of the content.
|
|
444
|
+
* `false` to explicitly use `HEAD`, this is useful in case of CORS where `Access-Control-Expose-Headers: Content-Range` is not returned by the server.
|
|
444
445
|
*
|
|
445
446
|
* @defaultValue false
|
|
446
447
|
*/
|
|
447
448
|
preventHeadRequest?: boolean;
|
|
449
|
+
/**
|
|
450
|
+
* `true` to use `Range: bytes=-22` on the first request and cache the EOCD, make sure beforehand that the server supports a suffix range request.
|
|
451
|
+
*
|
|
452
|
+
* @defaultValue false
|
|
453
|
+
*/
|
|
454
|
+
combineSizeEocd?: boolean;
|
|
448
455
|
}
|
|
449
456
|
|
|
450
457
|
/**
|
|
@@ -584,7 +591,7 @@ export class Data64URIWriter extends Writer<string> {
|
|
|
584
591
|
*
|
|
585
592
|
* @deprecated Use {@link SplitDataWriter} instead.
|
|
586
593
|
*/
|
|
587
|
-
export class SplitZipWriter extends SplitDataWriter {}
|
|
594
|
+
export class SplitZipWriter extends SplitDataWriter { }
|
|
588
595
|
|
|
589
596
|
/**
|
|
590
597
|
* Represents a {@link Writer} instance used to retrieve the written data from a generator of {@link WritableWriter} instances (i.e. split zip files).
|
|
@@ -616,7 +623,7 @@ export class SplitDataWriter implements Initializable, WritableWriter {
|
|
|
616
623
|
/**
|
|
617
624
|
* Represents a {@link Writer} instance used to retrieve the written data as a `Uint8Array` instance.
|
|
618
625
|
*/
|
|
619
|
-
export class Uint8ArrayWriter extends Writer<Uint8Array> {}
|
|
626
|
+
export class Uint8ArrayWriter extends Writer<Uint8Array> { }
|
|
620
627
|
|
|
621
628
|
/**
|
|
622
629
|
* Represents an instance used to create an unzipped stream.
|
|
@@ -760,7 +767,7 @@ export interface ZipReaderConstructorOptions
|
|
|
760
767
|
* Represents the options passed to {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
|
|
761
768
|
*/
|
|
762
769
|
export interface ZipReaderGetEntriesOptions
|
|
763
|
-
extends GetEntriesOptions, EntryOnprogressOptions {}
|
|
770
|
+
extends GetEntriesOptions, EntryOnprogressOptions { }
|
|
764
771
|
|
|
765
772
|
/**
|
|
766
773
|
* Represents options passed to the constructor of {@link ZipReader}, {@link ZipReader#getEntries} and {@link ZipReader#getEntriesGenerator}.
|
|
@@ -774,6 +781,14 @@ export interface GetEntriesOptions {
|
|
|
774
781
|
* The encoding of the comment of the entry.
|
|
775
782
|
*/
|
|
776
783
|
commentEncoding?: string;
|
|
784
|
+
/**
|
|
785
|
+
* Decodes the filename and the comment of the entry.
|
|
786
|
+
*
|
|
787
|
+
* @param value The raw text value.
|
|
788
|
+
* @param encoding The encoding of the text.
|
|
789
|
+
* @returns The decoded text value.
|
|
790
|
+
*/
|
|
791
|
+
decodeText?(value: Uint8Array, encoding: string): string
|
|
777
792
|
}
|
|
778
793
|
|
|
779
794
|
/**
|
|
@@ -977,13 +992,13 @@ export interface Entry extends EntryMetaData {
|
|
|
977
992
|
* Represents the options passed to {@link Entry#getData} and `{@link ZipFileEntry}.get*`.
|
|
978
993
|
*/
|
|
979
994
|
export interface EntryGetDataOptions
|
|
980
|
-
extends EntryDataOnprogressOptions, ZipReaderOptions, WorkerConfiguration {}
|
|
995
|
+
extends EntryDataOnprogressOptions, ZipReaderOptions, WorkerConfiguration { }
|
|
981
996
|
|
|
982
997
|
/**
|
|
983
998
|
* Represents the options passed to {@link Entry#getData} and `{@link ZipFileEntry}.get*`.
|
|
984
999
|
*/
|
|
985
1000
|
export interface EntryGetDataCheckPasswordOptions
|
|
986
|
-
extends EntryGetDataOptions, ZipReaderCheckPasswordOptions {}
|
|
1001
|
+
extends EntryGetDataOptions, ZipReaderCheckPasswordOptions { }
|
|
987
1002
|
|
|
988
1003
|
/**
|
|
989
1004
|
* Represents an instance used to create a zipped stream.
|
|
@@ -1146,9 +1161,9 @@ export class ZipWriter<Type> {
|
|
|
1146
1161
|
*/
|
|
1147
1162
|
export interface ZipWriterAddDataOptions
|
|
1148
1163
|
extends
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1164
|
+
ZipWriterConstructorOptions,
|
|
1165
|
+
EntryDataOnprogressOptions,
|
|
1166
|
+
WorkerConfiguration {
|
|
1152
1167
|
/**
|
|
1153
1168
|
* `true` if the entry is a directory.
|
|
1154
1169
|
*
|
|
@@ -1336,6 +1351,13 @@ export interface ZipWriterConstructorOptions {
|
|
|
1336
1351
|
* @defaultValue false
|
|
1337
1352
|
*/
|
|
1338
1353
|
usdz?: boolean;
|
|
1354
|
+
/**
|
|
1355
|
+
* Encode the filename and the comment of the entry.
|
|
1356
|
+
*
|
|
1357
|
+
* @param text The text to encode.
|
|
1358
|
+
* @returns The encoded text.
|
|
1359
|
+
*/
|
|
1360
|
+
encodeText?(text: string): Uint8Array
|
|
1339
1361
|
}
|
|
1340
1362
|
|
|
1341
1363
|
/**
|
|
@@ -1828,7 +1850,7 @@ export class ZipDirectoryEntry extends ZipEntry {
|
|
|
1828
1850
|
* Represents the options passed to {@link ZipDirectoryEntry#importHttpContent}.
|
|
1829
1851
|
*/
|
|
1830
1852
|
export interface ZipDirectoryEntryImportHttpOptions
|
|
1831
|
-
extends ZipReaderConstructorOptions, HttpOptions {}
|
|
1853
|
+
extends ZipReaderConstructorOptions, HttpOptions { }
|
|
1832
1854
|
|
|
1833
1855
|
/**
|
|
1834
1856
|
* Represents the options passed to `{@link ZipDirectoryEntry}#export*()`.
|