zip-writer 1.0.1 → 1.1.1
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 +427 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -1
- package/dist/{crc.d.ts → crc-browser.d.ts} +1 -1
- package/dist/crc-browser.d.ts.map +1 -0
- package/dist/{crc.js → crc-browser.js} +22 -2
- package/dist/crc-browser.js.map +1 -0
- package/dist/crc-node.d.ts +2 -0
- package/dist/crc-node.d.ts.map +1 -0
- package/dist/crc-node.js +3 -0
- package/dist/crc-node.js.map +1 -0
- package/dist/index.d.ts +44 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -11
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +11 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +16 -0
- package/dist/utils.js.map +1 -1
- package/dist/write-central-directory.d.ts.map +1 -1
- package/dist/write-central-directory.js +157 -202
- package/dist/write-central-directory.js.map +1 -1
- package/dist/write-entry.d.ts +5 -1
- package/dist/write-entry.d.ts.map +1 -1
- package/dist/write-entry.js +54 -68
- package/dist/write-entry.js.map +1 -1
- package/package.json +21 -3
- package/dist/crc-lookup.d.ts +0 -6
- package/dist/crc-lookup.d.ts.map +0 -1
- package/dist/crc-lookup.js +0 -22
- package/dist/crc-lookup.js.map +0 -1
- package/dist/crc.d.ts.map +0 -1
- package/dist/crc.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -2,11 +2,11 @@ import { writeZipEntry } from "./write-entry.js";
|
|
|
2
2
|
import { getCDFH, getEOCDZip64, getEOCDStandard, } from "./write-central-directory.js";
|
|
3
3
|
import { ZIP64_LIMIT } from "./constants.js";
|
|
4
4
|
import { noop } from "./utils.js";
|
|
5
|
+
import { crc32 as crc32Default } from "#crc32";
|
|
5
6
|
const BUFFER_SIZE = 16 * 1024; // 16 KB
|
|
6
7
|
const bufferedQueue = new ByteLengthQueuingStrategy({
|
|
7
8
|
highWaterMark: BUFFER_SIZE,
|
|
8
9
|
});
|
|
9
|
-
const unbufferedQueue = { highWaterMark: 0 };
|
|
10
10
|
export class ZipWriter {
|
|
11
11
|
#offset = BigInt(0);
|
|
12
12
|
#zipStream = new TransformStream({
|
|
@@ -15,8 +15,8 @@ export class ZipWriter {
|
|
|
15
15
|
this.#offset += BigInt(chunk.byteLength);
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
|
-
//
|
|
19
|
-
|
|
18
|
+
// default buffer on the writable side, we already queue entries
|
|
19
|
+
bufferedQueue,
|
|
20
20
|
// Readable buffer, so that temporary delays on writable consumers don't
|
|
21
21
|
// block the zip writing.
|
|
22
22
|
bufferedQueue);
|
|
@@ -24,6 +24,13 @@ export class ZipWriter {
|
|
|
24
24
|
#queued = Promise.resolve();
|
|
25
25
|
#entryCount = 0;
|
|
26
26
|
#finalized = false;
|
|
27
|
+
#crc32;
|
|
28
|
+
/**
|
|
29
|
+
* @param crc Optional CRC32 function to use. Defaults to zlib.crc32 on Node and a pure JS implementation in browsers.
|
|
30
|
+
*/
|
|
31
|
+
constructor({ crc32 = crc32Default, } = {}) {
|
|
32
|
+
this.#crc32 = crc32;
|
|
33
|
+
}
|
|
27
34
|
get readable() {
|
|
28
35
|
return this.#zipStream.readable;
|
|
29
36
|
}
|
|
@@ -38,10 +45,38 @@ export class ZipWriter {
|
|
|
38
45
|
await this.#queued;
|
|
39
46
|
}
|
|
40
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Convenience wrapper around `createEntryStream` to write all data at once.
|
|
50
|
+
* Use `createEntryStream` for more efficient streaming writes. Calls to
|
|
51
|
+
* createEntry() will be queued internally and each will resolve once it's
|
|
52
|
+
* written to the archive.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const data = new TextEncoder().encode("Hello, World!");
|
|
57
|
+
* const entryInfo = await zipWriter.createEntry(data, { name: "hello.txt" });
|
|
58
|
+
* console.log(entryInfo);
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @param data Entry data
|
|
62
|
+
* @param options Entry filename, comment, compression method, etc.
|
|
63
|
+
* @returns Entry information once the entry has been written.
|
|
64
|
+
*/
|
|
65
|
+
async createEntry(data, options) {
|
|
66
|
+
const entryWriter = this.createEntryStream(options);
|
|
67
|
+
const writer = entryWriter.writable.getWriter();
|
|
68
|
+
try {
|
|
69
|
+
await writer.write(data);
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
await writer.close();
|
|
73
|
+
}
|
|
74
|
+
return entryWriter.getEntryInfo();
|
|
75
|
+
}
|
|
41
76
|
/**
|
|
42
77
|
* Create a new entry in the Zip archive. Use the returned
|
|
43
78
|
* entryWriter.writable to write data to the entry. You can await
|
|
44
|
-
* entryWriter.
|
|
79
|
+
* entryWriter.getEntryInfo() to get the entry info once all data has been written.
|
|
45
80
|
*
|
|
46
81
|
* @example
|
|
47
82
|
* ```ts
|
|
@@ -59,12 +94,12 @@ export class ZipWriter {
|
|
|
59
94
|
* new TextEncoder().encode("Hello, World!")
|
|
60
95
|
* );
|
|
61
96
|
* await writer.close();
|
|
62
|
-
* console.log(await entryWriter.
|
|
97
|
+
* console.log(await entryWriter.getEntryInfo()); // Entry info
|
|
63
98
|
* ```
|
|
64
99
|
*
|
|
65
100
|
* @param options Entry options
|
|
66
101
|
*/
|
|
67
|
-
|
|
102
|
+
createEntryStream(options) {
|
|
68
103
|
if (this.#finalized) {
|
|
69
104
|
throw new TypeError("Cannot add entry after finalize() has been called");
|
|
70
105
|
}
|
|
@@ -88,6 +123,7 @@ export class ZipWriter {
|
|
|
88
123
|
const reader = readable.getReader();
|
|
89
124
|
try {
|
|
90
125
|
const entryInfo = await writeZipEntry({
|
|
126
|
+
crc32: this.#crc32,
|
|
91
127
|
writer,
|
|
92
128
|
reader,
|
|
93
129
|
entryOptions: options,
|
|
@@ -120,7 +156,7 @@ export class ZipWriter {
|
|
|
120
156
|
*
|
|
121
157
|
* @param entries New entries array
|
|
122
158
|
*/
|
|
123
|
-
setEntries(entries) {
|
|
159
|
+
#setEntries(entries) {
|
|
124
160
|
const currentEntriesByOffset = new Map();
|
|
125
161
|
for (const entry of this.#entries) {
|
|
126
162
|
currentEntriesByOffset.set(BigInt(entry.startOffset), entry);
|
|
@@ -145,11 +181,29 @@ export class ZipWriter {
|
|
|
145
181
|
}
|
|
146
182
|
this.#entries = entries.map((entry) => ({ ...entry }));
|
|
147
183
|
}
|
|
148
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Finalize the ZIP archive by writing the central directory and end of
|
|
186
|
+
* central directory records. You may not add any more entries after calling
|
|
187
|
+
* this method. This will await any pending entries to finish writing before
|
|
188
|
+
* finalizing.
|
|
189
|
+
*
|
|
190
|
+
* @param options.entries (Advanced) Optionally override the entries to write
|
|
191
|
+
* in the central directory. This can be used to reorder, remove, or rename
|
|
192
|
+
* entries before finalizing the archive, however you cannot add invalid
|
|
193
|
+
* entries, add additional entries, or modify their crc32, offsets or sizes.
|
|
194
|
+
* Use zipWriter.entries or entryWriter.getEntryInfo() to get the current
|
|
195
|
+
* entries for sorting or filtering.
|
|
196
|
+
*
|
|
197
|
+
* @returns Information about the finalized archive.
|
|
198
|
+
*/
|
|
199
|
+
async finalize({ entries, } = {}) {
|
|
149
200
|
if (this.#finalized) {
|
|
150
201
|
throw new TypeError("finalize() has already been called");
|
|
151
202
|
}
|
|
152
203
|
this.#finalized = true;
|
|
204
|
+
if (entries) {
|
|
205
|
+
this.#setEntries(entries);
|
|
206
|
+
}
|
|
153
207
|
// We do this as an IIFE to avoid an unhandled error, so that a user can
|
|
154
208
|
// call finalize() without needing to await and catch an error. Any error
|
|
155
209
|
// will be propagated to the stream output, but the user can optionally
|
|
@@ -206,8 +260,7 @@ export class ZipWriter {
|
|
|
206
260
|
}
|
|
207
261
|
}
|
|
208
262
|
class EntryWriter {
|
|
209
|
-
|
|
210
|
-
#entryStream = new TransformStream(undefined, unbufferedQueue, unbufferedQueue);
|
|
263
|
+
#entryStream = new TransformStream(undefined, bufferedQueue, bufferedQueue);
|
|
211
264
|
#written;
|
|
212
265
|
/**
|
|
213
266
|
* @param enqueueAndPipe Function that enqueues the entry data readable, pipes it to the Zip stream, and returns a promise that resolves to the entry info once done.
|
|
@@ -238,7 +291,7 @@ class EntryWriter {
|
|
|
238
291
|
/**
|
|
239
292
|
* Get entry info. Resolves once all data has been written to the Zip stream.
|
|
240
293
|
*/
|
|
241
|
-
async
|
|
294
|
+
async getEntryInfo() {
|
|
242
295
|
return this.#written;
|
|
243
296
|
}
|
|
244
297
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,OAAO,EACP,YAAY,EACZ,eAAe,GAChB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,OAAO,EACP,YAAY,EACZ,eAAe,GAChB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE/C,MAAM,WAAW,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,QAAQ;AACvC,MAAM,aAAa,GAAG,IAAI,yBAAyB,CAAC;IAClD,aAAa,EAAE,W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AAQ,EAAE,IAAI,CAAC,OAAO;iBACvB,CAAC;YACJ,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACxB,MAAM,GAAG,CAAC;YACZ,CAAC;oBAAS,CAAC;gBACT,MAAM,CAAC,WAAW,EAAE,CAAC;YACvB,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QACL,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,8BAA8B;QAC3D,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AAED,MAAM,WAAW;IACf,YAAY,GAAG,IAAI,eAAe,CAChC,SAAS,EACT,aAAa,EACb,aAAa,CACd,CAAC;IACF,QAAQ,CAAqB;IAE7B;;OAEG;IACH,YACE,cAEuB;QAEvB,uEAAuE;QACvE,4EAA4E;QAC5E,wCAAwC;QACxC,IAAI,CAAC,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;QAC3D,uEAAuE;QACvE,2BAA2B;QAC3B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;YAC7B,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;OAQG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
export declare function getDosTime(date: Date): number;
|
|
2
2
|
export declare function getDosDate(date: Date): number;
|
|
3
3
|
export declare function noop(): void;
|
|
4
|
+
type DataViewValue<T extends keyof typeof OFFSETS = keyof typeof OFFSETS> = T extends "setBigUint64" ? [T, bigint, boolean] : [T, number, boolean];
|
|
5
|
+
export declare const UINT16 = "setUint16";
|
|
6
|
+
export declare const UINT32 = "setUint32";
|
|
7
|
+
export declare const UINT64 = "setBigUint64";
|
|
8
|
+
declare const OFFSETS: {
|
|
9
|
+
setUint16: number;
|
|
10
|
+
setUint32: number;
|
|
11
|
+
setBigUint64: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function writeDataView(view: DataView, values: DataViewValue[], offset?: number): number;
|
|
14
|
+
export {};
|
|
4
15
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAM7C;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAM7C;AAED,wBAAgB,IAAI,SAAK"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAM7C;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAM7C;AAED,wBAAgB,IAAI,SAAK;AAEzB,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,OAAO,OAAO,GAAG,MAAM,OAAO,OAAO,IACtE,CAAC,SAAS,cAAc,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAEzE,eAAO,MAAM,MAAM,cAAc,CAAC;AAClC,eAAO,MAAM,MAAM,cAAc,CAAC;AAClC,eAAO,MAAM,MAAM,iBAAiB,CAAC;AAGrC,QAAA,MAAM,OAAO;;;;CAImB,CAAC;AAEjC,wBAAgB,aAAa,CAC3B,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,aAAa,EAAE,EACvB,MAAM,GAAE,MAAU,GACjB,MAAM,CAOR"}
|
package/dist/utils.js
CHANGED
|
@@ -9,4 +9,20 @@ export function getDosDate(date) {
|
|
|
9
9
|
date.getDate());
|
|
10
10
|
}
|
|
11
11
|
export function noop() { }
|
|
12
|
+
export const UINT16 = "setUint16";
|
|
13
|
+
export const UINT32 = "setUint32";
|
|
14
|
+
export const UINT64 = "setBigUint64";
|
|
15
|
+
const OFFSETS = {
|
|
16
|
+
setUint16: 2,
|
|
17
|
+
setUint32: 4,
|
|
18
|
+
setBigUint64: 8,
|
|
19
|
+
};
|
|
20
|
+
export function writeDataView(view, values, offset = 0) {
|
|
21
|
+
for (const [method, value, littleEndian] of values) {
|
|
22
|
+
// @ts-expect-error
|
|
23
|
+
view[method](offset, value, littleEndian);
|
|
24
|
+
offset += OFFSETS[method];
|
|
25
|
+
}
|
|
26
|
+
return offset;
|
|
27
|
+
}
|
|
12
28
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU,CAAC,IAAU;IACnC,OAAO,CACL,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;QACvB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACxB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CACzB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAU;IACnC,OAAO,CACL,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;QAC5B,I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C5B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-central-directory.d.ts","sourceRoot":"","sources":["../src/write-central-directory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAqC,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"write-central-directory.d.ts","sourceRoot":"","sources":["../src/write-central-directory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAqC,MAAM,YAAY,CAAC;AA+B/E;;GAEG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,SAAS,GAAG,UAAU,CAAC,WAAW,CAAC,CAMrE;AA2JD;;GAEG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,MAAM,EACpB,sBAAsB,EAAE,MAAM,EAC9B,oBAAoB,EAAE,MAAM,GAC3B,UAAU,CAAC,WAAW,CAAC,CAwBzB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,YAAY,EAAE,MAAM,EACpB,sBAAsB,EAAE,MAAM,EAC9B,oBAAoB,EAAE,MAAM,GAC3B,UAAU,CAAC,WAAW,CAAC,CA6DzB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CENTRAL_DIRECTORY_SIGNATURE, END_OF_CENTRAL_DIR_SIGNATURE, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE, VERSION_MADE_BY, VERSION_NEEDED_STANDARD, VERSION_NEEDED_ZIP64, GENERAL_PURPOSE_FLAGS, COMPRESSION_METHOD_STORE, COMPRESSION_METHOD_DEFLATE, ZIP64_LIMIT, CENTRAL_DIRECTORY_HEADER_SIZE, EOCD_SIZE, EOCD64_SIZE, EOCD64_LOCATOR_SIZE, } from "./constants.js";
|
|
2
|
-
import { getDosTime, getDosDate } from "./utils.js";
|
|
1
|
+
import { CENTRAL_DIRECTORY_SIGNATURE, END_OF_CENTRAL_DIR_SIGNATURE, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE, VERSION_MADE_BY, VERSION_NEEDED_STANDARD, VERSION_NEEDED_ZIP64, GENERAL_PURPOSE_FLAGS, COMPRESSION_METHOD_STORE, COMPRESSION_METHOD_DEFLATE, ZIP64_LIMIT, CENTRAL_DIRECTORY_HEADER_SIZE, EOCD_SIZE, EOCD64_SIZE, EOCD64_LOCATOR_SIZE, BIG_ENDIAN, LITTLE_ENDIAN, } from "./constants.js";
|
|
2
|
+
import { getDosTime, getDosDate, writeDataView, UINT16, UINT32, UINT64, } from "./utils.js";
|
|
3
3
|
const textEncoder = new TextEncoder();
|
|
4
4
|
/**
|
|
5
5
|
* Generate the Central Directory File Header for the given entry info.
|
|
@@ -20,59 +20,46 @@ function getCDFHStandard(entryInfo) {
|
|
|
20
20
|
const headerSize = CENTRAL_DIRECTORY_HEADER_SIZE + nameBytes.length + commentBytes.length;
|
|
21
21
|
const header = new Uint8Array(headerSize);
|
|
22
22
|
const view = new DataView(header.buffer);
|
|
23
|
-
let offset = 0;
|
|
24
|
-
// Central directory file header signature
|
|
25
|
-
view.setUint32(offset, CENTRAL_DIRECTORY_SIGNATURE);
|
|
26
|
-
offset += 4;
|
|
27
|
-
// Version made by
|
|
28
|
-
view.setUint16(offset, VERSION_MADE_BY, true);
|
|
29
|
-
offset += 2;
|
|
30
|
-
// Version needed to extract
|
|
31
|
-
view.setUint16(offset, VERSION_NEEDED_STANDARD, true);
|
|
32
|
-
offset += 2;
|
|
33
|
-
// General purpose bit flag
|
|
34
|
-
view.setUint16(offset, GENERAL_PURPOSE_FLAGS);
|
|
35
|
-
offset += 2;
|
|
36
|
-
// Compression method
|
|
37
|
-
view.setUint16(offset, entryInfo.store ? COMPRESSION_METHOD_STORE : COMPRESSION_METHOD_DEFLATE, true);
|
|
38
|
-
offset += 2;
|
|
39
|
-
// Last mod file time & date
|
|
40
23
|
const date = entryInfo.date || new Date();
|
|
41
|
-
view.setUint16(offset, getDosTime(date), true);
|
|
42
|
-
offset += 2;
|
|
43
|
-
view.setUint16(offset, getDosDate(date), true);
|
|
44
|
-
offset += 2;
|
|
45
|
-
// CRC-32
|
|
46
|
-
view.setUint32(offset, entryInfo.crc32, true);
|
|
47
|
-
offset += 4;
|
|
48
|
-
// Compressed size
|
|
49
|
-
view.setUint32(offset, entryInfo.compressedSize, true);
|
|
50
|
-
offset += 4;
|
|
51
|
-
// Uncompressed size
|
|
52
|
-
view.setUint32(offset, entryInfo.uncompressedSize, true);
|
|
53
|
-
offset += 4;
|
|
54
|
-
// File name length
|
|
55
|
-
view.setUint16(offset, nameBytes.length, true);
|
|
56
|
-
offset += 2;
|
|
57
|
-
// Extra field length
|
|
58
|
-
view.setUint16(offset, 0, true);
|
|
59
|
-
offset += 2;
|
|
60
|
-
// File comment length
|
|
61
|
-
view.setUint16(offset, commentBytes.length, true);
|
|
62
|
-
offset += 2;
|
|
63
|
-
// Disk number start
|
|
64
|
-
view.setUint16(offset, 0, true);
|
|
65
|
-
offset += 2;
|
|
66
|
-
// Internal file attributes
|
|
67
|
-
view.setUint16(offset, 0, true);
|
|
68
|
-
offset += 2;
|
|
69
|
-
// External file attributes (Unix permissions if provided)
|
|
70
24
|
const externalAttrs = entryInfo.mode ? entryInfo.mode << 16 : 0;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
25
|
+
const compressionMethod = entryInfo.store
|
|
26
|
+
? COMPRESSION_METHOD_STORE
|
|
27
|
+
: COMPRESSION_METHOD_DEFLATE;
|
|
28
|
+
let offset = writeDataView(view, [
|
|
29
|
+
// Central directory file header signature
|
|
30
|
+
[UINT32, CENTRAL_DIRECTORY_SIGNATURE, BIG_ENDIAN],
|
|
31
|
+
// Version made by
|
|
32
|
+
[UINT16, VERSION_MADE_BY, LITTLE_ENDIAN],
|
|
33
|
+
// Version needed to extract
|
|
34
|
+
[UINT16, VERSION_NEEDED_STANDARD, LITTLE_ENDIAN],
|
|
35
|
+
// General purpose bit flag
|
|
36
|
+
[UINT16, GENERAL_PURPOSE_FLAGS, LITTLE_ENDIAN],
|
|
37
|
+
// Compression method
|
|
38
|
+
[UINT16, compressionMethod, LITTLE_ENDIAN],
|
|
39
|
+
// Last mod file time & date
|
|
40
|
+
[UINT16, getDosTime(date), LITTLE_ENDIAN],
|
|
41
|
+
[UINT16, getDosDate(date), LITTLE_ENDIAN],
|
|
42
|
+
// CRC-32
|
|
43
|
+
[UINT32, entryInfo.crc32, LITTLE_ENDIAN],
|
|
44
|
+
// Compressed size
|
|
45
|
+
[UINT32, entryInfo.compressedSize, LITTLE_ENDIAN],
|
|
46
|
+
// Uncompressed size
|
|
47
|
+
[UINT32, entryInfo.uncompressedSize, LITTLE_ENDIAN],
|
|
48
|
+
// File name length
|
|
49
|
+
[UINT16, nameBytes.length, LITTLE_ENDIAN],
|
|
50
|
+
// Extra field length
|
|
51
|
+
[UINT16, 0, LITTLE_ENDIAN],
|
|
52
|
+
// File comment length
|
|
53
|
+
[UINT16, commentBytes.length, LITTLE_ENDIAN],
|
|
54
|
+
// Disk number start
|
|
55
|
+
[UINT16, 0, LITTLE_ENDIAN],
|
|
56
|
+
// Internal file attributes
|
|
57
|
+
[UINT16, 0, LITTLE_ENDIAN],
|
|
58
|
+
// External file attributes (Unix permissions if provided)
|
|
59
|
+
[UINT32, externalAttrs, LITTLE_ENDIAN],
|
|
60
|
+
// Relative offset of local header
|
|
61
|
+
[UINT32, entryInfo.startOffset, LITTLE_ENDIAN],
|
|
62
|
+
]);
|
|
76
63
|
// File name
|
|
77
64
|
header.set(nameBytes, offset);
|
|
78
65
|
offset += nameBytes.length;
|
|
@@ -90,70 +77,64 @@ function getCDFHZip64(entryInfo) {
|
|
|
90
77
|
// Extra field for ZIP64
|
|
91
78
|
const extraField = new Uint8Array(28); // ZIP64 extra field
|
|
92
79
|
const extraView = new DataView(extraField.buffer);
|
|
93
|
-
extraView
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
80
|
+
writeDataView(extraView, [
|
|
81
|
+
// ZIP64 extra field tag
|
|
82
|
+
[UINT16, 0x0001, LITTLE_ENDIAN],
|
|
83
|
+
// Size of extra field data (3x 8-byte fields)
|
|
84
|
+
[UINT16, 24, LITTLE_ENDIAN],
|
|
85
|
+
// Original size
|
|
86
|
+
[UINT64, entryInfo.uncompressedSize, LITTLE_ENDIAN],
|
|
87
|
+
// Compressed size
|
|
88
|
+
[UINT64, entryInfo.compressedSize, LITTLE_ENDIAN],
|
|
89
|
+
// Relative header offset
|
|
90
|
+
[UINT64, entryInfo.startOffset, LITTLE_ENDIAN],
|
|
91
|
+
]);
|
|
98
92
|
const headerSize = CENTRAL_DIRECTORY_HEADER_SIZE +
|
|
99
93
|
nameBytes.length +
|
|
100
94
|
extraField.length +
|
|
101
95
|
commentBytes.length;
|
|
102
96
|
const header = new Uint8Array(headerSize);
|
|
103
97
|
const view = new DataView(header.buffer);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
offset += 4;
|
|
108
|
-
// Version made by
|
|
109
|
-
view.setUint16(offset, VERSION_MADE_BY, true);
|
|
110
|
-
offset += 2;
|
|
111
|
-
// Version needed to extract
|
|
112
|
-
view.setUint16(offset, VERSION_NEEDED_ZIP64, true);
|
|
113
|
-
offset += 2;
|
|
114
|
-
// General purpose bit flag
|
|
115
|
-
view.setUint16(offset, GENERAL_PURPOSE_FLAGS);
|
|
116
|
-
offset += 2;
|
|
117
|
-
// Compression method
|
|
118
|
-
view.setUint16(offset, entryInfo.store ? COMPRESSION_METHOD_STORE : COMPRESSION_METHOD_DEFLATE, true);
|
|
119
|
-
offset += 2;
|
|
120
|
-
// Last mod file time & date
|
|
98
|
+
const compressionMethod = entryInfo.store
|
|
99
|
+
? COMPRESSION_METHOD_STORE
|
|
100
|
+
: COMPRESSION_METHOD_DEFLATE;
|
|
121
101
|
const date = entryInfo.date || new Date();
|
|
122
|
-
view.setUint16(offset, getDosTime(date), true);
|
|
123
|
-
offset += 2;
|
|
124
|
-
view.setUint16(offset, getDosDate(date), true);
|
|
125
|
-
offset += 2;
|
|
126
|
-
// CRC-32
|
|
127
|
-
view.setUint32(offset, entryInfo.crc32, true);
|
|
128
|
-
offset += 4;
|
|
129
|
-
// Compressed size (0xFFFFFFFF for ZIP64)
|
|
130
|
-
view.setUint32(offset, 0xffffffff, true);
|
|
131
|
-
offset += 4;
|
|
132
|
-
// Uncompressed size (0xFFFFFFFF for ZIP64)
|
|
133
|
-
view.setUint32(offset, 0xffffffff, true);
|
|
134
|
-
offset += 4;
|
|
135
|
-
// File name length
|
|
136
|
-
view.setUint16(offset, nameBytes.length, true);
|
|
137
|
-
offset += 2;
|
|
138
|
-
// Extra field length
|
|
139
|
-
view.setUint16(offset, extraField.length, true);
|
|
140
|
-
offset += 2;
|
|
141
|
-
// File comment length
|
|
142
|
-
view.setUint16(offset, commentBytes.length, true);
|
|
143
|
-
offset += 2;
|
|
144
|
-
// Disk number start
|
|
145
|
-
view.setUint16(offset, 0, true);
|
|
146
|
-
offset += 2;
|
|
147
|
-
// Internal file attributes
|
|
148
|
-
view.setUint16(offset, 0, true);
|
|
149
|
-
offset += 2;
|
|
150
|
-
// External file attributes (Unix permissions if provided)
|
|
151
102
|
const externalAttrs = entryInfo.mode ? entryInfo.mode << 16 : 0;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
103
|
+
let offset = writeDataView(view, [
|
|
104
|
+
// Central directory file header signature
|
|
105
|
+
[UINT32, CENTRAL_DIRECTORY_SIGNATURE, BIG_ENDIAN],
|
|
106
|
+
// Version made by
|
|
107
|
+
[UINT16, VERSION_MADE_BY, LITTLE_ENDIAN],
|
|
108
|
+
// Version needed to extract
|
|
109
|
+
[UINT16, VERSION_NEEDED_ZIP64, LITTLE_ENDIAN],
|
|
110
|
+
// General purpose bit flag
|
|
111
|
+
[UINT16, GENERAL_PURPOSE_FLAGS, LITTLE_ENDIAN],
|
|
112
|
+
// Compression method
|
|
113
|
+
[UINT16, compressionMethod, LITTLE_ENDIAN],
|
|
114
|
+
// Last mod file time & date
|
|
115
|
+
[UINT16, getDosTime(date), LITTLE_ENDIAN],
|
|
116
|
+
[UINT16, getDosDate(date), LITTLE_ENDIAN],
|
|
117
|
+
// CRC-32
|
|
118
|
+
[UINT32, entryInfo.crc32, LITTLE_ENDIAN],
|
|
119
|
+
// Compressed size (0xFFFFFFFF for ZIP64)
|
|
120
|
+
[UINT32, 0xffffffff, LITTLE_ENDIAN],
|
|
121
|
+
// Uncompressed size (0xFFFFFFFF for ZIP64)
|
|
122
|
+
[UINT32, 0xffffffff, LITTLE_ENDIAN],
|
|
123
|
+
// File name length
|
|
124
|
+
[UINT16, nameBytes.length, LITTLE_ENDIAN],
|
|
125
|
+
// Extra field length
|
|
126
|
+
[UINT16, extraField.length, LITTLE_ENDIAN],
|
|
127
|
+
// File comment length
|
|
128
|
+
[UINT16, commentBytes.length, LITTLE_ENDIAN],
|
|
129
|
+
// Disk number start
|
|
130
|
+
[UINT16, 0, LITTLE_ENDIAN],
|
|
131
|
+
// Internal file attributes
|
|
132
|
+
[UINT16, 0, LITTLE_ENDIAN],
|
|
133
|
+
// External file attributes (Unix permissions if provided)
|
|
134
|
+
[UINT32, externalAttrs, LITTLE_ENDIAN],
|
|
135
|
+
// Relative offset of local header (0xFFFFFFFF for ZIP64)
|
|
136
|
+
[UINT32, 0xffffffff, LITTLE_ENDIAN],
|
|
137
|
+
]);
|
|
157
138
|
// File name
|
|
158
139
|
header.set(nameBytes, offset);
|
|
159
140
|
offset += nameBytes.length;
|
|
@@ -172,30 +153,24 @@ function getCDFHZip64(entryInfo) {
|
|
|
172
153
|
export function getEOCDStandard(entriesCount, centralDirectoryOffset, centralDirectorySize) {
|
|
173
154
|
const eocd = new Uint8Array(EOCD_SIZE);
|
|
174
155
|
const view = new DataView(eocd.buffer);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
offset += 4;
|
|
194
|
-
// Offset of start of central directory
|
|
195
|
-
view.setUint32(offset, Number(centralDirectoryOffset), true);
|
|
196
|
-
offset += 4;
|
|
197
|
-
// ZIP file comment length
|
|
198
|
-
view.setUint16(offset, 0, true);
|
|
156
|
+
writeDataView(view, [
|
|
157
|
+
// End of central dir signature
|
|
158
|
+
[UINT32, END_OF_CENTRAL_DIR_SIGNATURE, BIG_ENDIAN],
|
|
159
|
+
// Number of this disk
|
|
160
|
+
[UINT16, 0, LITTLE_ENDIAN],
|
|
161
|
+
// Disk where central directory starts
|
|
162
|
+
[UINT16, 0, LITTLE_ENDIAN],
|
|
163
|
+
// Number of central directory records on this disk
|
|
164
|
+
[UINT16, entriesCount, LITTLE_ENDIAN],
|
|
165
|
+
// Total number of central directory records
|
|
166
|
+
[UINT16, entriesCount, LITTLE_ENDIAN],
|
|
167
|
+
// Size of central directory
|
|
168
|
+
[UINT32, centralDirectorySize, LITTLE_ENDIAN],
|
|
169
|
+
// Offset of start of central directory
|
|
170
|
+
[UINT32, centralDirectoryOffset, LITTLE_ENDIAN],
|
|
171
|
+
// ZIP file comment length
|
|
172
|
+
[UINT16, 0, LITTLE_ENDIAN],
|
|
173
|
+
]);
|
|
199
174
|
return eocd;
|
|
200
175
|
}
|
|
201
176
|
/**
|
|
@@ -205,75 +180,55 @@ export function getEOCDZip64(entriesCount, centralDirectoryOffset, centralDirect
|
|
|
205
180
|
const totalSize = EOCD64_SIZE + EOCD64_LOCATOR_SIZE + EOCD_SIZE;
|
|
206
181
|
const buffer = new Uint8Array(totalSize);
|
|
207
182
|
const view = new DataView(buffer.buffer);
|
|
208
|
-
let offset =
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
// Number of this disk
|
|
258
|
-
view.setUint16(offset, 0xffff, true);
|
|
259
|
-
offset += 2;
|
|
260
|
-
// Disk where central directory starts
|
|
261
|
-
view.setUint16(offset, 0xffff, true);
|
|
262
|
-
offset += 2;
|
|
263
|
-
// Number of central directory records on this disk
|
|
264
|
-
view.setUint16(offset, 0xffff, true);
|
|
265
|
-
offset += 2;
|
|
266
|
-
// Total number of central directory records
|
|
267
|
-
view.setUint16(offset, 0xffff, true);
|
|
268
|
-
offset += 2;
|
|
269
|
-
// Size of central directory
|
|
270
|
-
view.setUint32(offset, 0xffffffff, true);
|
|
271
|
-
offset += 4;
|
|
272
|
-
// Offset of start of central directory
|
|
273
|
-
view.setUint32(offset, 0xffffffff, true);
|
|
274
|
-
offset += 4;
|
|
275
|
-
// ZIP file comment length
|
|
276
|
-
view.setUint16(offset, 0, true);
|
|
183
|
+
let offset = writeDataView(view, [
|
|
184
|
+
// === ZIP64 End of Central Directory Record ===
|
|
185
|
+
// End of central dir signature
|
|
186
|
+
[UINT32, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE, BIG_ENDIAN],
|
|
187
|
+
// Size of zip64 end of central directory record excluding the leading 12 bytes
|
|
188
|
+
[UINT64, BigInt(EOCD64_SIZE - 12), LITTLE_ENDIAN],
|
|
189
|
+
// Version made by
|
|
190
|
+
[UINT16, VERSION_MADE_BY, LITTLE_ENDIAN],
|
|
191
|
+
// Version needed to extract
|
|
192
|
+
[UINT16, VERSION_NEEDED_ZIP64, LITTLE_ENDIAN],
|
|
193
|
+
// Number of this disk
|
|
194
|
+
[UINT32, 0, LITTLE_ENDIAN],
|
|
195
|
+
// Disk where central directory starts
|
|
196
|
+
[UINT32, 0, LITTLE_ENDIAN],
|
|
197
|
+
// Number of central directory records on this disk
|
|
198
|
+
[UINT64, entriesCount, LITTLE_ENDIAN],
|
|
199
|
+
// Total number of central directory records
|
|
200
|
+
[UINT64, entriesCount, LITTLE_ENDIAN],
|
|
201
|
+
// Size of central directory
|
|
202
|
+
[UINT64, centralDirectorySize, LITTLE_ENDIAN],
|
|
203
|
+
// Offset of start of central directory
|
|
204
|
+
[UINT64, centralDirectoryOffset, LITTLE_ENDIAN],
|
|
205
|
+
// === ZIP64 End of Central Directory Locator ===
|
|
206
|
+
// Zip64 end of central dir locator signature
|
|
207
|
+
[UINT32, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE, BIG_ENDIAN],
|
|
208
|
+
// Number of the disk with the start of the zip64 end of central directory
|
|
209
|
+
[UINT32, 0, LITTLE_ENDIAN],
|
|
210
|
+
// Relative offset of the zip64 end of central directory record
|
|
211
|
+
[UINT64, centralDirectoryOffset + centralDirectorySize, LITTLE_ENDIAN],
|
|
212
|
+
// Total number of disks
|
|
213
|
+
[UINT32, 1, LITTLE_ENDIAN],
|
|
214
|
+
// === Standard End of Central Directory Record ===
|
|
215
|
+
// End of central dir signature
|
|
216
|
+
[UINT32, END_OF_CENTRAL_DIR_SIGNATURE, BIG_ENDIAN],
|
|
217
|
+
// Number of this disk
|
|
218
|
+
[UINT16, 0, LITTLE_ENDIAN],
|
|
219
|
+
// Disk where central directory starts
|
|
220
|
+
[UINT16, 0, LITTLE_ENDIAN],
|
|
221
|
+
// Number of central directory records on this disk
|
|
222
|
+
[UINT16, 0xffff, LITTLE_ENDIAN],
|
|
223
|
+
// Total number of central directory records
|
|
224
|
+
[UINT16, 0xffff, LITTLE_ENDIAN],
|
|
225
|
+
// Size of central directory
|
|
226
|
+
[UINT32, 0xffffffff, LITTLE_ENDIAN],
|
|
227
|
+
// Offset of start of central directory
|
|
228
|
+
[UINT32, 0xffffffff, LITTLE_ENDIAN],
|
|
229
|
+
// ZIP file comment length
|
|
230
|
+
[UINT16, 0, LITTLE_ENDIAN],
|
|
231
|
+
]);
|
|
277
232
|
return buffer;
|
|
278
233
|
}
|
|
279
234
|
//# sourceMappingURL=write-central-directory.js.map
|