@zip.js/zip.js 2.6.41 → 2.6.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/README.md +6 -5
- package/cli-deno/mc-zip.js +19 -13
- package/dist/zip-fs-full.js +52 -31
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +51 -30
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +51 -30
- 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 +51 -30
- package/dist/zip.min.js +1 -1
- package/index.cjs +52 -31
- package/index.d.ts +54 -29
- package/index.js +1 -1
- package/lib/core/zip-entry.js +45 -7
- package/lib/core/zip-reader.js +29 -13
- package/lib/core/zip-writer.js +22 -12
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# Introduction
|
|
2
2
|
|
|
3
|
-
zip.js is
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
streams, Zip64 and
|
|
3
|
+
zip.js is a JavaScript open-source library (BSD-3-Clause license) for
|
|
4
|
+
compressing and decompressing zip files. It was designed to handle large amounts
|
|
5
|
+
of data. It supports notably multi-core compression, native compression with
|
|
6
|
+
compression streams, files larger than 4GB with Zip64, split zip files and data
|
|
7
|
+
encryption.
|
|
7
8
|
|
|
8
9
|
# Documentation
|
|
9
10
|
|
|
@@ -92,7 +93,7 @@ const zipFileBlobPromise = new Response(zipFileStream.readable).blob();
|
|
|
92
93
|
const helloWorldReadable = new Blob(["Hello world!"]).stream();
|
|
93
94
|
|
|
94
95
|
// Creates a ZipWriter object writing data into `zipFileStream.writable`, adds
|
|
95
|
-
// the entry "hello.txt" containing the text "Hello world!" retrieved from
|
|
96
|
+
// the entry "hello.txt" containing the text "Hello world!" retrieved from
|
|
96
97
|
// `helloWorldReadable`, and closes the writer.
|
|
97
98
|
const zipWriter = new ZipWriter(zipFileStream.writable);
|
|
98
99
|
await zipWriter.add("hello.txt", helloWorldReadable);
|
package/cli-deno/mc-zip.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env -S deno run --allow-write --allow-read --allow-net
|
|
2
2
|
|
|
3
|
-
/* global Deno,
|
|
3
|
+
/* global Deno, URL, TextEncoderStream */
|
|
4
4
|
|
|
5
5
|
import { parse as parseArgs } from "https://deno.land/std@0.147.0/flags/mod.ts";
|
|
6
6
|
import { normalize as normalizePath, resolve as resolvePath, extname } from "https://deno.land/std@0.147.0/path/mod.ts";
|
|
7
|
-
import { configure, ZipWriter, terminateWorkers } from "../index.js";
|
|
7
|
+
import { configure, ZipWriter, terminateWorkers, HttpReader } from "../index.js";
|
|
8
8
|
|
|
9
9
|
const args = parseArgs(Deno.args);
|
|
10
10
|
const stdout = getTextWriter(Deno.stdout);
|
|
@@ -81,9 +81,9 @@ async function addFile(zipWriter, file) {
|
|
|
81
81
|
onstart: () => stdout.write(" adding: " + file.name + "\n")
|
|
82
82
|
};
|
|
83
83
|
try {
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
86
|
-
await zipWriter.add(file.name,
|
|
84
|
+
const reader = await getReader(file);
|
|
85
|
+
if (reader) {
|
|
86
|
+
await zipWriter.add(file.name, reader, options);
|
|
87
87
|
}
|
|
88
88
|
} catch (error) {
|
|
89
89
|
await stdout.write(" error: " + error.message + ", file: " + file.url + "\n");
|
|
@@ -91,7 +91,7 @@ async function addFile(zipWriter, file) {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
async function getFileInfo(file, options) {
|
|
94
|
-
let name, isFile, isDirectory, resolvedName;
|
|
94
|
+
let name, isFile, isDirectory, resolvedName, size;
|
|
95
95
|
const remote = isRemote(file);
|
|
96
96
|
if (remote) {
|
|
97
97
|
const url = new URL(file, import.meta.url);
|
|
@@ -111,9 +111,10 @@ async function getFileInfo(file, options) {
|
|
|
111
111
|
const stat = await Deno.stat(resolvedName);
|
|
112
112
|
isFile = stat.isFile;
|
|
113
113
|
isDirectory = stat.isDirectory;
|
|
114
|
+
size = stat.size;
|
|
114
115
|
}
|
|
115
116
|
return {
|
|
116
|
-
url: file, name, remote, isFile, isDirectory, resolvedName
|
|
117
|
+
url: file, name, remote, isFile, size, isDirectory, resolvedName
|
|
117
118
|
};
|
|
118
119
|
}
|
|
119
120
|
|
|
@@ -134,12 +135,17 @@ async function addDirectories(file, options) {
|
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
|
|
137
|
-
async function
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
async function getReader(file) {
|
|
139
|
+
if (file.remote) {
|
|
140
|
+
return new HttpReader(file.url);
|
|
141
|
+
} else if (file.isFile) {
|
|
142
|
+
const { size } = file;
|
|
143
|
+
const { readable } = await Deno.open(resolvePath(file.url), { read: true });
|
|
144
|
+
return {
|
|
145
|
+
readable,
|
|
146
|
+
size
|
|
147
|
+
};
|
|
148
|
+
}
|
|
143
149
|
}
|
|
144
150
|
|
|
145
151
|
function isRemote(path) {
|
package/dist/zip-fs-full.js
CHANGED
|
@@ -8343,14 +8343,34 @@
|
|
|
8343
8343
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
8344
8344
|
*/
|
|
8345
8345
|
|
|
8346
|
+
const PROPERTY_NAME_FILENAME = "filename";
|
|
8347
|
+
const PROPERTY_NAME_RAW_FILENAME = "rawFilename";
|
|
8348
|
+
const PROPERTY_NAME_COMMENT = "comment";
|
|
8349
|
+
const PROPERTY_NAME_RAW_COMMENT = "rawComment";
|
|
8350
|
+
const PROPERTY_NAME_UNCOMPPRESSED_SIZE = "uncompressedSize";
|
|
8351
|
+
const PROPERTY_NAME_COMPPRESSED_SIZE = "compressedSize";
|
|
8352
|
+
const PROPERTY_NAME_OFFSET = "offset";
|
|
8353
|
+
const PROPERTY_NAME_DISK_NUMBER_START = "diskNumberStart";
|
|
8354
|
+
const PROPERTY_NAME_LAST_MODIFICATION_DATE = "lastModDate";
|
|
8355
|
+
const PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE = "rawLastModDate";
|
|
8356
|
+
const PROPERTY_NAME_LAST_ACCESS_DATE = "lastAccessDate";
|
|
8357
|
+
const PROPERTY_NAME_RAW_LAST_ACCESS_DATE = "rawLastAccessDate";
|
|
8358
|
+
const PROPERTY_NAME_CREATION_DATE = "creationDate";
|
|
8359
|
+
const PROPERTY_NAME_RAW_CREATION_DATE = "rawCreationDate";
|
|
8360
|
+
const PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE = "internalFileAttribute";
|
|
8361
|
+
const PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE = "externalFileAttribute";
|
|
8362
|
+
const PROPERTY_NAME_MS_DOS_COMPATIBLE = "msDosCompatible";
|
|
8363
|
+
const PROPERTY_NAME_ZIP64 = "zip64";
|
|
8364
|
+
|
|
8346
8365
|
const PROPERTY_NAMES = [
|
|
8347
|
-
|
|
8348
|
-
|
|
8349
|
-
|
|
8350
|
-
|
|
8351
|
-
|
|
8352
|
-
"
|
|
8353
|
-
"
|
|
8366
|
+
PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, PROPERTY_NAME_COMPPRESSED_SIZE, PROPERTY_NAME_UNCOMPPRESSED_SIZE,
|
|
8367
|
+
PROPERTY_NAME_LAST_MODIFICATION_DATE, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT,
|
|
8368
|
+
PROPERTY_NAME_LAST_ACCESS_DATE, PROPERTY_NAME_CREATION_DATE, PROPERTY_NAME_OFFSET, PROPERTY_NAME_DISK_NUMBER_START,
|
|
8369
|
+
PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE,
|
|
8370
|
+
PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64,
|
|
8371
|
+
"directory", "bitFlag", "encrypted", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "version", "versionMadeBy",
|
|
8372
|
+
"extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS",
|
|
8373
|
+
"extraFieldExtendedTimestamp"];
|
|
8354
8374
|
|
|
8355
8375
|
class Entry {
|
|
8356
8376
|
|
|
@@ -8402,10 +8422,10 @@
|
|
|
8402
8422
|
const CHARSET_UTF8 = "utf-8";
|
|
8403
8423
|
const CHARSET_CP437 = "cp437";
|
|
8404
8424
|
const ZIP64_PROPERTIES = [
|
|
8405
|
-
[
|
|
8406
|
-
[
|
|
8407
|
-
[
|
|
8408
|
-
[
|
|
8425
|
+
[PROPERTY_NAME_UNCOMPPRESSED_SIZE, MAX_32_BITS],
|
|
8426
|
+
[PROPERTY_NAME_COMPPRESSED_SIZE, MAX_32_BITS],
|
|
8427
|
+
[PROPERTY_NAME_OFFSET, MAX_32_BITS],
|
|
8428
|
+
[PROPERTY_NAME_DISK_NUMBER_START, MAX_16_BITS]
|
|
8409
8429
|
];
|
|
8410
8430
|
const ZIP64_EXTRACTION = {
|
|
8411
8431
|
[MAX_16_BITS]: {
|
|
@@ -8765,12 +8785,12 @@
|
|
|
8765
8785
|
}
|
|
8766
8786
|
const extraFieldUnicodePath = extraField.get(EXTRAFIELD_TYPE_UNICODE_PATH);
|
|
8767
8787
|
if (extraFieldUnicodePath) {
|
|
8768
|
-
await readExtraFieldUnicode(extraFieldUnicodePath,
|
|
8788
|
+
await readExtraFieldUnicode(extraFieldUnicodePath, PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, directory, fileEntry);
|
|
8769
8789
|
directory.extraFieldUnicodePath = extraFieldUnicodePath;
|
|
8770
8790
|
}
|
|
8771
8791
|
const extraFieldUnicodeComment = extraField.get(EXTRAFIELD_TYPE_UNICODE_COMMENT);
|
|
8772
8792
|
if (extraFieldUnicodeComment) {
|
|
8773
|
-
await readExtraFieldUnicode(extraFieldUnicodeComment,
|
|
8793
|
+
await readExtraFieldUnicode(extraFieldUnicodeComment, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT, directory, fileEntry);
|
|
8774
8794
|
directory.extraFieldUnicodeComment = extraFieldUnicodeComment;
|
|
8775
8795
|
}
|
|
8776
8796
|
const extraFieldAES = extraField.get(EXTRAFIELD_TYPE_AES);
|
|
@@ -8884,16 +8904,16 @@
|
|
|
8884
8904
|
const timeProperties = [];
|
|
8885
8905
|
const timeRawProperties = [];
|
|
8886
8906
|
if ((flags & 0x1) == 0x1) {
|
|
8887
|
-
timeProperties.push(
|
|
8888
|
-
timeRawProperties.push(
|
|
8907
|
+
timeProperties.push(PROPERTY_NAME_LAST_MODIFICATION_DATE);
|
|
8908
|
+
timeRawProperties.push(PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE);
|
|
8889
8909
|
}
|
|
8890
8910
|
if ((flags & 0x2) == 0x2) {
|
|
8891
|
-
timeProperties.push(
|
|
8892
|
-
timeRawProperties.push(
|
|
8911
|
+
timeProperties.push(PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
8912
|
+
timeRawProperties.push(PROPERTY_NAME_RAW_LAST_ACCESS_DATE);
|
|
8893
8913
|
}
|
|
8894
8914
|
if ((flags & 0x4) == 0x4) {
|
|
8895
|
-
timeProperties.push(
|
|
8896
|
-
timeRawProperties.push(
|
|
8915
|
+
timeProperties.push(PROPERTY_NAME_CREATION_DATE);
|
|
8916
|
+
timeRawProperties.push(PROPERTY_NAME_RAW_CREATION_DATE);
|
|
8897
8917
|
}
|
|
8898
8918
|
let offset = 1;
|
|
8899
8919
|
timeProperties.forEach((propertyName, indexProperty) => {
|
|
@@ -9120,9 +9140,9 @@
|
|
|
9120
9140
|
if (versionMadeBy > MAX_16_BITS) {
|
|
9121
9141
|
throw new Error(ERR_INVALID_VERSION);
|
|
9122
9142
|
}
|
|
9123
|
-
const lastModDate = getOptionValue(zipWriter, options,
|
|
9124
|
-
const lastAccessDate = getOptionValue(zipWriter, options,
|
|
9125
|
-
const creationDate = getOptionValue(zipWriter, options,
|
|
9143
|
+
const lastModDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_MODIFICATION_DATE) || new Date();
|
|
9144
|
+
const lastAccessDate = getOptionValue(zipWriter, options, PROPERTY_NAME_LAST_ACCESS_DATE);
|
|
9145
|
+
const creationDate = getOptionValue(zipWriter, options, PROPERTY_NAME_CREATION_DATE);
|
|
9126
9146
|
const password = getOptionValue(zipWriter, options, "password");
|
|
9127
9147
|
const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
|
|
9128
9148
|
const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
|
|
@@ -9160,13 +9180,13 @@
|
|
|
9160
9180
|
keepOrder = true;
|
|
9161
9181
|
}
|
|
9162
9182
|
let uncompressedSize = 0;
|
|
9163
|
-
let msDosCompatible = getOptionValue(zipWriter, options,
|
|
9183
|
+
let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
|
|
9164
9184
|
if (msDosCompatible === UNDEFINED_VALUE) {
|
|
9165
9185
|
msDosCompatible = true;
|
|
9166
9186
|
}
|
|
9167
|
-
const internalFileAttribute = getOptionValue(zipWriter, options,
|
|
9168
|
-
const externalFileAttribute = getOptionValue(zipWriter, options,
|
|
9169
|
-
let zip64 = getOptionValue(zipWriter, options,
|
|
9187
|
+
const internalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE) || 0;
|
|
9188
|
+
const externalFileAttribute = getOptionValue(zipWriter, options, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE) || 0;
|
|
9189
|
+
let zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
|
|
9170
9190
|
if (reader) {
|
|
9171
9191
|
if (reader instanceof ReadableStream) {
|
|
9172
9192
|
reader = {
|
|
@@ -9242,8 +9262,9 @@
|
|
|
9242
9262
|
let fileEntry;
|
|
9243
9263
|
try {
|
|
9244
9264
|
fileEntry = await getFileEntry(zipWriter, name, reader, { headerInfo, dataDescriptorInfo }, options);
|
|
9265
|
+
zipWriter.pendingEntriesSize -= maximumEntrySize;
|
|
9245
9266
|
} catch (error) {
|
|
9246
|
-
if (!error.corruptedEntry
|
|
9267
|
+
if (!error.corruptedEntry) {
|
|
9247
9268
|
zipWriter.pendingEntriesSize -= maximumEntrySize;
|
|
9248
9269
|
}
|
|
9249
9270
|
throw error;
|
|
@@ -9293,7 +9314,7 @@
|
|
|
9293
9314
|
if (zipWriter.addSplitZipSignature) {
|
|
9294
9315
|
delete zipWriter.addSplitZipSignature;
|
|
9295
9316
|
const signatureArray = new Uint8Array(4);
|
|
9296
|
-
const signatureArrayView =
|
|
9317
|
+
const signatureArrayView = getDataView(signatureArray);
|
|
9297
9318
|
setUint32(signatureArrayView, 0, SPLIT_ZIP_FILE_SIGNATURE);
|
|
9298
9319
|
await writeData(writable, signatureArray);
|
|
9299
9320
|
zipWriter.offset += 4;
|
|
@@ -9431,9 +9452,9 @@
|
|
|
9431
9452
|
externalFileAttribute,
|
|
9432
9453
|
diskNumberStart
|
|
9433
9454
|
};
|
|
9455
|
+
let compressedSize = 0;
|
|
9434
9456
|
let uncompressedSize = 0;
|
|
9435
9457
|
let signature;
|
|
9436
|
-
let compressedSize = 0;
|
|
9437
9458
|
const { writable } = writer;
|
|
9438
9459
|
if (reader) {
|
|
9439
9460
|
reader.chunkSize = getChunkSize(config);
|
|
@@ -9828,7 +9849,7 @@
|
|
|
9828
9849
|
const endOfdirectoryView = getDataView(endOfdirectoryArray);
|
|
9829
9850
|
let lastDiskNumber = writer.diskNumber;
|
|
9830
9851
|
const { availableSize } = writer;
|
|
9831
|
-
if (availableSize < endOfdirectoryArray
|
|
9852
|
+
if (availableSize < getLength(endOfdirectoryArray)) {
|
|
9832
9853
|
lastDiskNumber++;
|
|
9833
9854
|
}
|
|
9834
9855
|
offset = 0;
|
|
@@ -10582,7 +10603,7 @@
|
|
|
10582
10603
|
configure({ baseURL });
|
|
10583
10604
|
e(configure);
|
|
10584
10605
|
|
|
10585
|
-
/// <reference types="./index
|
|
10606
|
+
/// <reference types="./index" />
|
|
10586
10607
|
|
|
10587
10608
|
configure({ Deflate: ZipDeflate, Inflate: ZipInflate });
|
|
10588
10609
|
|