@ac-kit/format-zip 0.0.0-stage → 0.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/CHANGELOG.md +24 -0
- package/LICENSE +28 -0
- package/README.md +44 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/zip-archive.d.ts +70 -0
- package/dist/zip-archive.d.ts.map +1 -0
- package/dist/zip-archive.js +218 -0
- package/dist/zip-archive.js.map +1 -0
- package/dist/zip-error.d.ts +13 -0
- package/dist/zip-error.d.ts.map +1 -0
- package/dist/zip-error.js +19 -0
- package/dist/zip-error.js.map +1 -0
- package/package.json +60 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @ac-kit/format-zip
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [7f9f15d]
|
|
8
|
+
- @ac-kit/core@0.7.0
|
|
9
|
+
- @ac-kit/noncrypto-hash@0.1.6
|
|
10
|
+
|
|
11
|
+
## 0.1.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 8ee20f3: First release of `@ac-kit/format-zip`: `openZip` reads a ZIP archive's central
|
|
16
|
+
directory, ZIP64 included, and reads each entry on demand, inflated with
|
|
17
|
+
`DecompressionStream`, checked against its size and CRC-32, within required
|
|
18
|
+
limits on entries, size and compression ratio.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [47e39a2]
|
|
23
|
+
- @ac-kit/core@0.6.0
|
|
24
|
+
- @ac-kit/noncrypto-hash@0.1.5
|
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Anthony Champagne and contributors
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ac-kit/format-zip
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ZIP archives: the central directory, ZIP64 included, and each entry's content
|
|
4
|
+
read on demand within limits.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { openZip } from "@ac-kit/format-zip";
|
|
8
|
+
|
|
9
|
+
const archive = openZip(bytes, {
|
|
10
|
+
maxEntries: 1_000,
|
|
11
|
+
maxEntrySize: 64 * 1024 * 1024,
|
|
12
|
+
maxCompressionRatio: 200,
|
|
13
|
+
});
|
|
14
|
+
for (const entry of archive.entries) {
|
|
15
|
+
console.log(entry.name, entry.size);
|
|
16
|
+
}
|
|
17
|
+
const content = await archive.read(archive.entry("META-INF/container.xml")!);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## What it exposes
|
|
21
|
+
|
|
22
|
+
- `openZip` — reads the end of central directory and the directory itself
|
|
23
|
+
(APPNOTE 6.3, ZIP64 included) and returns the entries. Names are UTF-8 when
|
|
24
|
+
flagged, from an Info-ZIP Unicode Path field when present, code page 437
|
|
25
|
+
otherwise.
|
|
26
|
+
- `ZipArchive.read` — an entry's content, stored or deflated, inflated with
|
|
27
|
+
`DecompressionStream` and checked against its size and CRC-32.
|
|
28
|
+
- `ZipFormatError`, `ZipLimitError` — a broken archive, and one past a limit.
|
|
29
|
+
|
|
30
|
+
Every limit is required, since an archive states its own sizes: the number of
|
|
31
|
+
entries, an entry's uncompressed size, and its compression ratio, which stops a
|
|
32
|
+
zip bomb before it inflates. Encrypted entries, methods other than stored and
|
|
33
|
+
deflate, and archives split across disks are refused. An entry's name is data,
|
|
34
|
+
not a safe path: check it before writing anything out.
|
|
35
|
+
|
|
36
|
+
Portable: no Node.js built-ins.
|
|
37
|
+
|
|
38
|
+
See the
|
|
39
|
+
[generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/format-zip/)
|
|
40
|
+
for the full reference.
|
|
41
|
+
|
|
42
|
+
## Further reading
|
|
43
|
+
|
|
44
|
+
- [APPNOTE.TXT](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT) —
|
|
45
|
+
the ZIP file format specification.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The limits {@link openZip} holds an archive to, each required, since an
|
|
3
|
+
* archive decides its own sizes.
|
|
4
|
+
*/
|
|
5
|
+
export type ZipLimits = {
|
|
6
|
+
/** Most entries the central directory may list. */
|
|
7
|
+
readonly maxEntries: number;
|
|
8
|
+
/** Largest uncompressed entry {@link ZipArchive.read} returns, in bytes. */
|
|
9
|
+
readonly maxEntrySize: number;
|
|
10
|
+
/**
|
|
11
|
+
* Largest ratio of an entry's uncompressed to compressed size: deflate tops
|
|
12
|
+
* out near 1032, so a bomb declaring more is refused before it inflates.
|
|
13
|
+
*/
|
|
14
|
+
readonly maxCompressionRatio: number;
|
|
15
|
+
};
|
|
16
|
+
/** One entry of the central directory. */
|
|
17
|
+
export type ZipEntry = {
|
|
18
|
+
/**
|
|
19
|
+
* The path inside the archive, `/`-separated, a directory's ending with `/`.
|
|
20
|
+
* It is data, not a safe file system path: check it before writing it out.
|
|
21
|
+
*/
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly isDirectory: boolean;
|
|
24
|
+
/** `0` stored, `8` deflate; {@link ZipArchive.read} reads only these. */
|
|
25
|
+
readonly method: number;
|
|
26
|
+
readonly compressedSize: number;
|
|
27
|
+
readonly size: number;
|
|
28
|
+
readonly crc32: number;
|
|
29
|
+
/** The modification time, in the local time zone the archive was made in. */
|
|
30
|
+
readonly lastModified: Date;
|
|
31
|
+
readonly comment: string;
|
|
32
|
+
/** Whether the entry is encrypted, which {@link ZipArchive.read} refuses. */
|
|
33
|
+
readonly isEncrypted: boolean;
|
|
34
|
+
/** Offset of its local header in the archive. */
|
|
35
|
+
readonly offset: number;
|
|
36
|
+
};
|
|
37
|
+
/** An archive's entries, and their content on demand. */
|
|
38
|
+
export type ZipArchive = {
|
|
39
|
+
readonly entries: readonly ZipEntry[];
|
|
40
|
+
readonly comment: string;
|
|
41
|
+
/** The entry named `name`, exactly. */
|
|
42
|
+
entry(name: string): ZipEntry | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* The uncompressed content of `entry`, checked against its size and CRC-32.
|
|
45
|
+
*
|
|
46
|
+
* @throws {ZipLimitError} When it is larger than `maxEntrySize`, or
|
|
47
|
+
* compressed past `maxCompressionRatio`.
|
|
48
|
+
* @throws {UnsupportedError} When it is encrypted or uses a method other than
|
|
49
|
+
* stored and deflate.
|
|
50
|
+
* @throws {ZipFormatError} When its local header, size or CRC-32 does not
|
|
51
|
+
* match the central directory.
|
|
52
|
+
*/
|
|
53
|
+
read(entry: ZipEntry, signal?: AbortSignal): Promise<Uint8Array<ArrayBuffer>>;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Reads a ZIP archive's central directory (APPNOTE 6.3), ZIP64 included, and
|
|
57
|
+
* returns its entries; their content is read on demand by
|
|
58
|
+
* {@link ZipArchive.read}, inflated with `DecompressionStream`.
|
|
59
|
+
*
|
|
60
|
+
* Names are decoded as UTF-8 when flagged so, from an Info-ZIP Unicode Path
|
|
61
|
+
* field when present, and as code page 437 otherwise. Archives split across
|
|
62
|
+
* disks are refused. Time and memory are linear in the central directory.
|
|
63
|
+
*
|
|
64
|
+
* @throws {ZipFormatError} When the archive has no end of central directory, or
|
|
65
|
+
* its directory is truncated or inconsistent.
|
|
66
|
+
* @throws {ZipLimitError} When it lists more than `maxEntries`.
|
|
67
|
+
* @throws {UnsupportedError} When it spans several disks.
|
|
68
|
+
*/
|
|
69
|
+
export declare function openZip(bytes: Uint8Array<ArrayBuffer>, limits: ZipLimits): ZipArchive;
|
|
70
|
+
//# sourceMappingURL=zip-archive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip-archive.d.ts","sourceRoot":"","sources":["../src/zip-archive.ts"],"names":[],"mappings":"AAaA;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACvB,mDAAmD;IACnD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,4EAA4E;IAC5E,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;CACrC,CAAC;AAEF,0CAA0C;AAC1C,MAAM,MAAM,QAAQ,GAAG;IACtB;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,yEAAyE;IACzE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,6EAA6E;IAC7E,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,6EAA6E;IAC7E,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,iDAAiD;IACjD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,yDAAyD;AACzD,MAAM,MAAM,UAAU,GAAG;IACxB,QAAQ,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,uCAAuC;IACvC,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC1C;;;;;;;;;OASG;IACH,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;CAC9E,CAAC;AAeF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CACtB,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,EAC9B,MAAM,EAAE,SAAS,GACf,UAAU,CA4PZ"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { bigIntIsSafeNumber, decodeText, getBigUint64Le, getUint32Le, readStreamBytes, StreamLengthError, UnsupportedError, } from "@ac-kit/core";
|
|
2
|
+
import { crc_32 } from "@ac-kit/noncrypto-hash";
|
|
3
|
+
import { ZipFormatError, ZipLimitError } from "./zip-error.js";
|
|
4
|
+
const END_OF_CENTRAL_DIRECTORY_ = 0x06054b50;
|
|
5
|
+
const ZIP64_END_LOCATOR_ = 0x07064b50;
|
|
6
|
+
const ZIP64_END_OF_CENTRAL_DIRECTORY_ = 0x06064b50;
|
|
7
|
+
const CENTRAL_HEADER_ = 0x02014b50;
|
|
8
|
+
const LOCAL_HEADER_ = 0x04034b50;
|
|
9
|
+
const ZIP64_EXTRA_ = 0x0001;
|
|
10
|
+
const UNICODE_PATH_EXTRA_ = 0x7075;
|
|
11
|
+
const ENCRYPTED_FLAG_ = 0x0001;
|
|
12
|
+
const UTF8_FLAG_ = 0x0800;
|
|
13
|
+
const MAX_COMMENT_ = 0xffff;
|
|
14
|
+
const STORED_ = 0;
|
|
15
|
+
const DEFLATE_ = 8;
|
|
16
|
+
/**
|
|
17
|
+
* Reads a ZIP archive's central directory (APPNOTE 6.3), ZIP64 included, and
|
|
18
|
+
* returns its entries; their content is read on demand by
|
|
19
|
+
* {@link ZipArchive.read}, inflated with `DecompressionStream`.
|
|
20
|
+
*
|
|
21
|
+
* Names are decoded as UTF-8 when flagged so, from an Info-ZIP Unicode Path
|
|
22
|
+
* field when present, and as code page 437 otherwise. Archives split across
|
|
23
|
+
* disks are refused. Time and memory are linear in the central directory.
|
|
24
|
+
*
|
|
25
|
+
* @throws {ZipFormatError} When the archive has no end of central directory, or
|
|
26
|
+
* its directory is truncated or inconsistent.
|
|
27
|
+
* @throws {ZipLimitError} When it lists more than `maxEntries`.
|
|
28
|
+
* @throws {UnsupportedError} When it spans several disks.
|
|
29
|
+
*/
|
|
30
|
+
export function openZip(bytes, limits) {
|
|
31
|
+
const u16 = (offset) => getUint32Le(bytes, offset, 2);
|
|
32
|
+
const u32 = (offset) => getUint32Le(bytes, offset);
|
|
33
|
+
const u64 = (offset) => {
|
|
34
|
+
const value = getBigUint64Le(bytes, offset);
|
|
35
|
+
if (!bigIntIsSafeNumber(value)) {
|
|
36
|
+
throw new ZipFormatError("Size past what this reader can address", offset);
|
|
37
|
+
}
|
|
38
|
+
return Number(value);
|
|
39
|
+
};
|
|
40
|
+
const within = (offset, length, what) => {
|
|
41
|
+
if (offset < 0 || offset + length > bytes.length) {
|
|
42
|
+
throw new ZipFormatError(`Truncated ${what}`, offset);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
let end = -1;
|
|
46
|
+
for (let offset = bytes.length - 22; offset >= Math.max(0, bytes.length - 22 - MAX_COMMENT_); offset--) {
|
|
47
|
+
if (u32(offset) === END_OF_CENTRAL_DIRECTORY_ &&
|
|
48
|
+
offset + 22 + u16(offset + 20) === bytes.length) {
|
|
49
|
+
end = offset;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (end === -1) {
|
|
54
|
+
throw new ZipFormatError("No end of central directory", bytes.length);
|
|
55
|
+
}
|
|
56
|
+
const comment = decodeText(bytes.subarray(end + 22, end + 22 + u16(end + 20)), "ibm437");
|
|
57
|
+
let count = u16(end + 10);
|
|
58
|
+
let directorySize = u32(end + 12);
|
|
59
|
+
let directoryOffset = u32(end + 16);
|
|
60
|
+
if (u16(end + 4) !== 0 || u16(end + 6) !== 0 || u16(end + 8) !== count) {
|
|
61
|
+
throw new UnsupportedError("ZIP archive split across disks");
|
|
62
|
+
}
|
|
63
|
+
if (count === 0xffff ||
|
|
64
|
+
directorySize === 0xffffffff ||
|
|
65
|
+
directoryOffset === 0xffffffff) {
|
|
66
|
+
const locator = end - 20;
|
|
67
|
+
within(locator, 20, "ZIP64 locator");
|
|
68
|
+
if (u32(locator) !== ZIP64_END_LOCATOR_) {
|
|
69
|
+
throw new ZipFormatError("Missing ZIP64 end of central directory locator", locator);
|
|
70
|
+
}
|
|
71
|
+
const record = u64(locator + 8);
|
|
72
|
+
within(record, 56, "ZIP64 end of central directory");
|
|
73
|
+
if (u32(record) !== ZIP64_END_OF_CENTRAL_DIRECTORY_) {
|
|
74
|
+
throw new ZipFormatError("Missing ZIP64 end of central directory", record);
|
|
75
|
+
}
|
|
76
|
+
count = u64(record + 32);
|
|
77
|
+
directorySize = u64(record + 40);
|
|
78
|
+
directoryOffset = u64(record + 48);
|
|
79
|
+
}
|
|
80
|
+
if (count > limits.maxEntries) {
|
|
81
|
+
throw new ZipLimitError(`The archive lists ${count} entries, more than ${limits.maxEntries}`);
|
|
82
|
+
}
|
|
83
|
+
within(directoryOffset, directorySize, "central directory");
|
|
84
|
+
const entries = [];
|
|
85
|
+
let offset = directoryOffset;
|
|
86
|
+
for (let index = 0; index < count; index++) {
|
|
87
|
+
within(offset, 46, "central directory header");
|
|
88
|
+
if (u32(offset) !== CENTRAL_HEADER_) {
|
|
89
|
+
throw new ZipFormatError("Expected a central directory header", offset);
|
|
90
|
+
}
|
|
91
|
+
const flags = u16(offset + 8);
|
|
92
|
+
const nameLength = u16(offset + 28);
|
|
93
|
+
const extraLength = u16(offset + 30);
|
|
94
|
+
const commentLength = u16(offset + 32);
|
|
95
|
+
within(offset + 46, nameLength + extraLength + commentLength, "central directory header");
|
|
96
|
+
const nameBytes = bytes.subarray(offset + 46, offset + 46 + nameLength);
|
|
97
|
+
const extra = bytes.subarray(offset + 46 + nameLength, offset + 46 + nameLength + extraLength);
|
|
98
|
+
let compressedSize = u32(offset + 20);
|
|
99
|
+
let size = u32(offset + 24);
|
|
100
|
+
let localOffset = u32(offset + 42);
|
|
101
|
+
let unicodeName = null;
|
|
102
|
+
for (let field = 0; field + 4 <= extra.length;) {
|
|
103
|
+
const id = getUint32Le(extra, field, 2);
|
|
104
|
+
const length = getUint32Le(extra, field + 2, 2);
|
|
105
|
+
const data = extra.subarray(field + 4, field + 4 + length);
|
|
106
|
+
if (id === ZIP64_EXTRA_) {
|
|
107
|
+
// Only the fields whose header value is saturated are present, in order.
|
|
108
|
+
let cursor = 0;
|
|
109
|
+
const next = () => {
|
|
110
|
+
if (cursor + 8 > data.length) {
|
|
111
|
+
throw new ZipFormatError("Truncated ZIP64 field", offset);
|
|
112
|
+
}
|
|
113
|
+
const value = getBigUint64Le(data, cursor);
|
|
114
|
+
cursor += 8;
|
|
115
|
+
if (!bigIntIsSafeNumber(value)) {
|
|
116
|
+
throw new ZipFormatError("Size past what this reader can address", offset);
|
|
117
|
+
}
|
|
118
|
+
return Number(value);
|
|
119
|
+
};
|
|
120
|
+
size = size === 0xffffffff ? next() : size;
|
|
121
|
+
compressedSize =
|
|
122
|
+
compressedSize === 0xffffffff ? next() : compressedSize;
|
|
123
|
+
localOffset = localOffset === 0xffffffff ? next() : localOffset;
|
|
124
|
+
}
|
|
125
|
+
else if (id === UNICODE_PATH_EXTRA_ &&
|
|
126
|
+
data[0] === 1 &&
|
|
127
|
+
data.length >= 5 &&
|
|
128
|
+
getUint32Le(data, 1) === crc_32(nameBytes)) {
|
|
129
|
+
unicodeName = decodeUtf8_(data.subarray(5), offset);
|
|
130
|
+
}
|
|
131
|
+
field += 4 + length;
|
|
132
|
+
}
|
|
133
|
+
const name = (flags & UTF8_FLAG_) !== 0
|
|
134
|
+
? decodeUtf8_(nameBytes, offset)
|
|
135
|
+
: (unicodeName ?? decodeText(nameBytes, "ibm437"));
|
|
136
|
+
const time = u16(offset + 12);
|
|
137
|
+
const date = u16(offset + 14);
|
|
138
|
+
entries.push({
|
|
139
|
+
name,
|
|
140
|
+
isDirectory: name.endsWith("/"),
|
|
141
|
+
method: u16(offset + 10),
|
|
142
|
+
compressedSize,
|
|
143
|
+
size,
|
|
144
|
+
crc32: u32(offset + 16),
|
|
145
|
+
lastModified: new Date(1980 + (date >> 9), ((date >> 5) & 0x0f) - 1, date & 0x1f, time >> 11, (time >> 5) & 0x3f, (time & 0x1f) * 2),
|
|
146
|
+
comment: decodeText(bytes.subarray(offset + 46 + nameLength + extraLength, offset + 46 + nameLength + extraLength + commentLength), (flags & UTF8_FLAG_) !== 0 ? "utf-8" : "ibm437"),
|
|
147
|
+
isEncrypted: (flags & ENCRYPTED_FLAG_) !== 0,
|
|
148
|
+
offset: localOffset,
|
|
149
|
+
});
|
|
150
|
+
offset += 46 + nameLength + extraLength + commentLength;
|
|
151
|
+
}
|
|
152
|
+
const byName = new Map(entries.map((entry) => [entry.name, entry]));
|
|
153
|
+
return {
|
|
154
|
+
entries,
|
|
155
|
+
comment,
|
|
156
|
+
entry: (name) => byName.get(name),
|
|
157
|
+
read: async (entry, signal) => {
|
|
158
|
+
if (entry.isEncrypted) {
|
|
159
|
+
throw new UnsupportedError(`ZIP entry "${entry.name}" is encrypted`);
|
|
160
|
+
}
|
|
161
|
+
if (entry.method !== STORED_ && entry.method !== DEFLATE_) {
|
|
162
|
+
throw new UnsupportedError(`ZIP compression method ${entry.method} of "${entry.name}"`);
|
|
163
|
+
}
|
|
164
|
+
if (entry.size > limits.maxEntrySize) {
|
|
165
|
+
throw new ZipLimitError(`ZIP entry "${entry.name}" holds ${entry.size} bytes, more than ${limits.maxEntrySize}`);
|
|
166
|
+
}
|
|
167
|
+
if (entry.size >
|
|
168
|
+
Math.max(entry.compressedSize, 1) * limits.maxCompressionRatio) {
|
|
169
|
+
throw new ZipLimitError(`ZIP entry "${entry.name}" is compressed past ${limits.maxCompressionRatio}:1`);
|
|
170
|
+
}
|
|
171
|
+
within(entry.offset, 30, "local header");
|
|
172
|
+
if (u32(entry.offset) !== LOCAL_HEADER_) {
|
|
173
|
+
throw new ZipFormatError("Expected a local header", entry.offset);
|
|
174
|
+
}
|
|
175
|
+
const start = entry.offset + 30 + u16(entry.offset + 26) + u16(entry.offset + 28);
|
|
176
|
+
within(start, entry.compressedSize, "entry data");
|
|
177
|
+
const data = bytes.subarray(start, start + entry.compressedSize);
|
|
178
|
+
let content;
|
|
179
|
+
if (entry.method === STORED_) {
|
|
180
|
+
if (entry.compressedSize !== entry.size) {
|
|
181
|
+
throw new ZipFormatError(`Stored entry "${entry.name}" with two sizes`, entry.offset);
|
|
182
|
+
}
|
|
183
|
+
content = data.slice();
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
const compressed = new ReadableStream({
|
|
187
|
+
start(controller) {
|
|
188
|
+
controller.enqueue(data);
|
|
189
|
+
controller.close();
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
try {
|
|
193
|
+
content = await readStreamBytes(compressed.pipeThrough(new DecompressionStream("deflate-raw")), entry.size, signal);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
if (error instanceof StreamLengthError ||
|
|
197
|
+
error instanceof TypeError) {
|
|
198
|
+
throw new ZipFormatError(`Corrupt deflate data in "${entry.name}"`, start);
|
|
199
|
+
}
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (content.length !== entry.size || crc_32(content) !== entry.crc32) {
|
|
204
|
+
throw new ZipFormatError(`Entry "${entry.name}" does not match its size and CRC-32`, start);
|
|
205
|
+
}
|
|
206
|
+
return content;
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function decodeUtf8_(bytes, offset) {
|
|
211
|
+
try {
|
|
212
|
+
return decodeText(bytes, "utf-8", { fatal: true });
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
throw new ZipFormatError("A UTF-8 name that is not UTF-8", offset);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=zip-archive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip-archive.js","sourceRoot":"","sources":["../src/zip-archive.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,UAAU,EACV,cAAc,EACd,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,gBAAgB,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AA2D/D,MAAM,yBAAyB,GAAG,UAAU,CAAC;AAC7C,MAAM,kBAAkB,GAAG,UAAU,CAAC;AACtC,MAAM,+BAA+B,GAAG,UAAU,CAAC;AACnD,MAAM,eAAe,GAAG,UAAU,CAAC;AACnC,MAAM,aAAa,GAAG,UAAU,CAAC;AACjC,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,MAAM,mBAAmB,GAAG,MAAM,CAAC;AACnC,MAAM,eAAe,GAAG,MAAM,CAAC;AAC/B,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,MAAM,OAAO,GAAG,CAAC,CAAC;AAClB,MAAM,QAAQ,GAAG,CAAC,CAAC;AAEnB;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,OAAO,CACtB,KAA8B,EAC9B,MAAiB;IAEjB,MAAM,GAAG,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC9D,MAAM,GAAG,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,C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,EAAE,MAAc;IACrD,IAAI,CAAC;QACJ,OAAO,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC;QACR,MAAM,IAAI,cAAc,CAAC,gCAAgC,EAAE,MAAM,CAAC,CAAC;IACpE,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** A ZIP archive whose structure is broken or contradicts itself. */
|
|
2
|
+
export declare class ZipFormatError extends SyntaxError {
|
|
3
|
+
/** Byte offset in the archive where reading gave up. */
|
|
4
|
+
readonly position: number;
|
|
5
|
+
constructor(message: string,
|
|
6
|
+
/** Byte offset in the archive where reading gave up. */
|
|
7
|
+
position: number);
|
|
8
|
+
}
|
|
9
|
+
/** An archive or entry past one of the {@link ZipLimits} given. */
|
|
10
|
+
export declare class ZipLimitError extends RangeError {
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=zip-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip-error.d.ts","sourceRoot":"","sources":["../src/zip-error.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,qBAAa,cAAe,SAAQ,WAAW;IAG7C,wDAAwD;IACxD,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAH1B,YACC,OAAO,EAAE,MAAM;IACf,wDAAwD;IAC/C,QAAQ,EAAE,MAAM,EAIzB;CACD;AAED,mEAAmE;AACnE,qBAAa,aAAc,SAAQ,UAAU;IAC5C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** A ZIP archive whose structure is broken or contradicts itself. */
|
|
2
|
+
export class ZipFormatError extends SyntaxError {
|
|
3
|
+
position;
|
|
4
|
+
constructor(message,
|
|
5
|
+
/** Byte offset in the archive where reading gave up. */
|
|
6
|
+
position) {
|
|
7
|
+
super(`${message} at ${position}`);
|
|
8
|
+
this.position = position;
|
|
9
|
+
this.name = "ZipFormatError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** An archive or entry past one of the {@link ZipLimits} given. */
|
|
13
|
+
export class ZipLimitError extends RangeError {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "ZipLimitError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=zip-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip-error.js","sourceRoot":"","sources":["../src/zip-error.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,OAAO,cAAe,SAAQ,WAAW;IAIpC,QAAQ;IAHlB,YACC,OAAe;IACf,wDAAwD;IAC/C,QAAgB;QAEzB,KAAK,CAAC,GAAG,OAAO,OAAO,QAAQ,EAAE,CAAC,CAAC;wBAF1B,QAAQ;QAGjB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC9B,CAAC;CACD;AAED,mEAAmE;AACnE,MAAM,OAAO,aAAc,SAAQ,UAAU;IAC5C,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC7B,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ac-kit/format-zip",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "ZIP archives: the central directory, ZIP64 included, and entries inflated on demand within limits.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"archive",
|
|
7
|
+
"deflate",
|
|
8
|
+
"zip",
|
|
9
|
+
"zip64"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://anthochamp.pages.grenadine.io/node-essentials/api/format-zip/",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://git.grenadine.io/anthochamp/node-essentials/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "BSD-3-Clause",
|
|
16
|
+
"author": "Anthony Champagne <dev@anthonychampagne.fr>",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://git.grenadine.io/anthochamp/node-essentials.git",
|
|
20
|
+
"directory": "packages/format-zip"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"compile": "tsc -p ./tsconfig.build.json -outDir dist",
|
|
40
|
+
"compile:check": "tsc -noEmit -p ./tsconfig.json",
|
|
41
|
+
"clean": "rimraf dist",
|
|
42
|
+
"build": "yarn clean && yarn compile",
|
|
43
|
+
"test": "yarn run -T vitest run",
|
|
44
|
+
"prepack": "yarn build"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@ac-kit/core": "^0.7.0",
|
|
48
|
+
"@ac-kit/noncrypto-hash": "^0.1.6"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@ac-kit/tsconfig": "0.1.0",
|
|
52
|
+
"@ac-kit/typedoc-config": "0.1.0",
|
|
53
|
+
"@ac-kit/vitest-config": "0.1.1",
|
|
54
|
+
"@types/node": "^26.5.1",
|
|
55
|
+
"@typescript/native": "typescript@7.0.2",
|
|
56
|
+
"rimraf": "6.1.4",
|
|
57
|
+
"typedoc": "0.28.20",
|
|
58
|
+
"typescript": "@typescript/typescript6@6.0.2"
|
|
59
|
+
},
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=24"
|
|
62
|
+
}
|
|
6
63
|
}
|