@zip.js/zip.js 2.6.14 → 2.6.15
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 +66 -13
- package/dist/zip-fs-full.js +14 -9
- package/dist/zip-fs-full.min.js +1 -1
- package/dist/zip-fs.js +14 -9
- package/dist/zip-fs.min.js +1 -1
- package/dist/zip-full.js +14 -9
- package/dist/zip-full.min.js +1 -1
- package/dist/zip-no-worker-deflate.min.js +1 -1
- package/dist/zip-no-worker.min.js +1 -1
- package/dist/zip.js +14 -9
- package/dist/zip.min.js +1 -1
- package/index.d.ts +13 -8
- package/lib/core/zip-writer.js +14 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,13 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# Introduction
|
|
2
|
+
|
|
3
|
+
zip.js is an open-source library (BSD-3-Clause license) implemented in
|
|
4
|
+
JavaScript to compress and decompress zip files. It has been designed to handle
|
|
5
|
+
large amounts of data and notably supports multi-core compression, compression
|
|
6
|
+
streams, Zip64 and encryption.
|
|
7
|
+
|
|
8
|
+
# Documentation
|
|
3
9
|
|
|
4
10
|
See here for more info: https://gildas-lormeau.github.io/zip.js/
|
|
5
11
|
|
|
12
|
+
# Examples
|
|
13
|
+
|
|
14
|
+
## Hello world
|
|
15
|
+
|
|
6
16
|
```js
|
|
17
|
+
import {
|
|
18
|
+
BlobReader,
|
|
19
|
+
BlobWriter,
|
|
20
|
+
TextReader,
|
|
21
|
+
TextWriter,
|
|
22
|
+
ZipReader,
|
|
23
|
+
ZipWriter,
|
|
24
|
+
} from "https://deno.land/x/zipjs/index.js";
|
|
25
|
+
|
|
7
26
|
// ----
|
|
8
|
-
//
|
|
27
|
+
// Write the zip file
|
|
9
28
|
// ----
|
|
10
29
|
|
|
30
|
+
// Creates a BlobWriter object where the zip content will be written.
|
|
31
|
+
const zipFileWriter = new BlobWriter();
|
|
32
|
+
// Creates a TextReader object storing the text of the entry to add in the zip
|
|
33
|
+
// (i.e. "Hello world!").
|
|
34
|
+
const helloWorldReader = new TextReader("Hello world!");
|
|
35
|
+
|
|
36
|
+
// Creates a ZipWriter object writing data via `zipFileWriter`, adds the entry
|
|
37
|
+
// "hello.txt" containing the text "Hello world!" via `helloWorldReader`, and
|
|
38
|
+
// closes the writer.
|
|
39
|
+
const zipWriter = new ZipWriter(zipFileWriter);
|
|
40
|
+
await zipWriter.add("hello.txt", helloWorldReader);
|
|
41
|
+
await zipWriter.close();
|
|
42
|
+
|
|
43
|
+
// Retrieves the Blob object containing the zip content into `zipFileBlob`. It
|
|
44
|
+
// is also returned by zipWriter.close() for more convenience.
|
|
45
|
+
const zipFileBlob = await zipFileWriter.getData();
|
|
46
|
+
|
|
47
|
+
// ----
|
|
48
|
+
// Read the zip file
|
|
49
|
+
// ----
|
|
50
|
+
|
|
51
|
+
// Creates a BlobReader object used to read `zipFileBlob`.
|
|
52
|
+
const zipFileReader = new BlobReader(zipFileBlob);
|
|
53
|
+
// Creates a TextWriter object where the content of the first entry in the zip
|
|
54
|
+
// will be written.
|
|
55
|
+
const helloWorldWriter = new TextWriter();
|
|
56
|
+
|
|
57
|
+
// Creates a ZipReader object reading the zip content via `zipFileReader`,
|
|
58
|
+
// retrieves metadata (name, dates, etc.) of the first entry, retrieves its
|
|
59
|
+
// content via `helloWorldWriter`, and closes the reader.
|
|
60
|
+
const zipReader = new ZipReader(zipFileReader);
|
|
61
|
+
const firstEntry = (await zipReader.getEntries()).shift();
|
|
62
|
+
const helloWorldText = await firstEntry.getData(helloWorldWriter);
|
|
63
|
+
await zipReader.close();
|
|
64
|
+
|
|
65
|
+
// Displays "Hello world!".
|
|
66
|
+
console.log(helloWorldText);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Hello world with Streams
|
|
70
|
+
|
|
71
|
+
```js
|
|
11
72
|
import {
|
|
12
73
|
BlobReader,
|
|
13
74
|
ZipReader,
|
|
@@ -30,8 +91,8 @@ const zipFileBlobPromise = new Response(zipFileWriter.readable).blob();
|
|
|
30
91
|
const helloWorldReader = { readable: new Blob(["Hello world!"]).stream() };
|
|
31
92
|
|
|
32
93
|
// Creates a ZipWriter object writing data via `zipFileWriter`, adds the entry
|
|
33
|
-
// "hello.txt" containing the text "Hello world!" via `helloWorldReader
|
|
34
|
-
//
|
|
94
|
+
// "hello.txt" containing the text "Hello world!" via `helloWorldReader`, and
|
|
95
|
+
// closes the writer.
|
|
35
96
|
const zipWriter = new ZipWriter(zipFileWriter);
|
|
36
97
|
await zipWriter.add("hello.txt", helloWorldReader);
|
|
37
98
|
await zipWriter.close();
|
|
@@ -39,14 +100,6 @@ await zipWriter.close();
|
|
|
39
100
|
// Retrieves the Blob object containing the zip content into `zipFileBlob`.
|
|
40
101
|
const zipFileBlob = await zipFileBlobPromise;
|
|
41
102
|
|
|
42
|
-
// Uncomment the following code to download the zip file (in a browser)
|
|
43
|
-
//
|
|
44
|
-
// const anchorElement = document.createElement("a");
|
|
45
|
-
// anchorElement.href = URL.createObjectURL(zipFileBlob);
|
|
46
|
-
// anchorElement.download = "hello.zip";
|
|
47
|
-
// anchorElement.click();
|
|
48
|
-
//
|
|
49
|
-
|
|
50
103
|
// ----
|
|
51
104
|
// Read the zip file
|
|
52
105
|
// ----
|
package/dist/zip-fs-full.js
CHANGED
|
@@ -8987,8 +8987,9 @@
|
|
|
8987
8987
|
let bufferedWrite;
|
|
8988
8988
|
let releaseLockWriter;
|
|
8989
8989
|
let releaseLockCurrentFileEntry;
|
|
8990
|
-
let
|
|
8990
|
+
let writingBufferedData;
|
|
8991
8991
|
let fileWriter;
|
|
8992
|
+
let fileWriterSize;
|
|
8992
8993
|
files.set(name, fileEntry);
|
|
8993
8994
|
try {
|
|
8994
8995
|
let lockPreviousFileEntry;
|
|
@@ -9005,6 +9006,7 @@
|
|
|
9005
9006
|
await initStream(writer);
|
|
9006
9007
|
fileWriter = writer;
|
|
9007
9008
|
}
|
|
9009
|
+
fileWriterSize = fileWriter.size;
|
|
9008
9010
|
fileEntry = await createFileEntry(reader, fileEntry, fileWriter.writable, zipWriter.config, options);
|
|
9009
9011
|
files.set(name, fileEntry);
|
|
9010
9012
|
fileEntry.filename = name;
|
|
@@ -9012,7 +9014,7 @@
|
|
|
9012
9014
|
let blob = fileWriter.getData();
|
|
9013
9015
|
await lockPreviousFileEntry;
|
|
9014
9016
|
await requestLockWriter();
|
|
9015
|
-
|
|
9017
|
+
writingBufferedData = true;
|
|
9016
9018
|
const { writable } = writer;
|
|
9017
9019
|
if (!dataDescriptor) {
|
|
9018
9020
|
const headerLength = 26;
|
|
@@ -9032,7 +9034,7 @@
|
|
|
9032
9034
|
blob = blob.slice(headerLength);
|
|
9033
9035
|
}
|
|
9034
9036
|
await blob.stream().pipeTo(writable, { preventClose: true, signal });
|
|
9035
|
-
|
|
9037
|
+
writingBufferedData = false;
|
|
9036
9038
|
}
|
|
9037
9039
|
fileEntry.offset = zipWriter.offset;
|
|
9038
9040
|
if (fileEntry.zip64) {
|
|
@@ -9044,9 +9046,12 @@
|
|
|
9044
9046
|
zipWriter.offset += fileEntry.length;
|
|
9045
9047
|
return fileEntry;
|
|
9046
9048
|
} catch (error) {
|
|
9047
|
-
if ((bufferedWrite &&
|
|
9048
|
-
|
|
9049
|
-
|
|
9049
|
+
if ((bufferedWrite && writingBufferedData) || (!bufferedWrite && fileEntry.writingData)) {
|
|
9050
|
+
zipWriter.hasCorruptedEntries = true;
|
|
9051
|
+
if (error) {
|
|
9052
|
+
error.corruptedEntry = true;
|
|
9053
|
+
}
|
|
9054
|
+
zipWriter.offset += fileWriter.size - fileWriterSize;
|
|
9050
9055
|
}
|
|
9051
9056
|
files.delete(name);
|
|
9052
9057
|
throw error;
|
|
@@ -9223,10 +9228,10 @@
|
|
|
9223
9228
|
arraySet(localHeaderArray, rawExtraField, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length);
|
|
9224
9229
|
let result;
|
|
9225
9230
|
let compressedSize = 0;
|
|
9231
|
+
fileEntry.writingData = pendingFileEntry.writingData = true;
|
|
9226
9232
|
if (reader) {
|
|
9227
9233
|
reader.chunkSize = getChunkSize(config);
|
|
9228
9234
|
await writeData(writable, localHeaderArray);
|
|
9229
|
-
fileEntry.dataWritten = pendingFileEntry.dataWritten = true;
|
|
9230
9235
|
const size = () => reader.size;
|
|
9231
9236
|
const readable = reader.readable;
|
|
9232
9237
|
readable.size = size;
|
|
@@ -9253,7 +9258,6 @@
|
|
|
9253
9258
|
compressedSize = result.size;
|
|
9254
9259
|
} else {
|
|
9255
9260
|
await writeData(writable, localHeaderArray);
|
|
9256
|
-
fileEntry.dataWritten = pendingFileEntry.dataWritten = true;
|
|
9257
9261
|
}
|
|
9258
9262
|
let dataDescriptorArray = new Uint8Array();
|
|
9259
9263
|
let dataDescriptorView, dataDescriptorOffset = 0;
|
|
@@ -9306,7 +9310,8 @@
|
|
|
9306
9310
|
creationDate,
|
|
9307
9311
|
lastAccessDate,
|
|
9308
9312
|
encrypted,
|
|
9309
|
-
length
|
|
9313
|
+
length,
|
|
9314
|
+
writingData: false
|
|
9310
9315
|
});
|
|
9311
9316
|
return fileEntry;
|
|
9312
9317
|
}
|