neozipkit 0.8.0 → 1.0.5
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/NEOZIP_APPNOTE.md +527 -0
- package/README.md +57 -21
- package/WHATS_NEW.md +146 -0
- package/dist/browser/ZipkitBrowser.d.ts.map +1 -1
- package/dist/browser/ZipkitBrowser.js +4 -6
- package/dist/browser/ZipkitBrowser.js.map +1 -1
- package/dist/browser/zstd-browser-shim.d.ts +28 -0
- package/dist/browser/zstd-browser-shim.d.ts.map +1 -0
- package/dist/browser/zstd-browser-shim.js +66 -0
- package/dist/browser/zstd-browser-shim.js.map +1 -0
- package/dist/browser-esm/index.js +2110 -41755
- package/dist/browser-esm/index.js.map +4 -4
- package/dist/browser-umd/index.js +2110 -41755
- package/dist/browser-umd/index.js.map +4 -4
- package/dist/browser-umd/index.min.js +3 -21
- package/dist/core/ZipCompress.d.ts +2 -7
- package/dist/core/ZipCompress.d.ts.map +1 -1
- package/dist/core/ZipCompress.js +57 -33
- package/dist/core/ZipCompress.js.map +1 -1
- package/dist/core/ZipDecompress.d.ts +1 -3
- package/dist/core/ZipDecompress.d.ts.map +1 -1
- package/dist/core/ZipDecompress.js +27 -17
- package/dist/core/ZipDecompress.js.map +1 -1
- package/dist/core/ZipEntry.d.ts +6 -0
- package/dist/core/ZipEntry.d.ts.map +1 -1
- package/dist/core/ZipEntry.js +7 -1
- package/dist/core/ZipEntry.js.map +1 -1
- package/dist/core/Zipkit.d.ts +43 -11
- package/dist/core/Zipkit.d.ts.map +1 -1
- package/dist/core/Zipkit.js +106 -63
- package/dist/core/Zipkit.js.map +1 -1
- package/dist/core/components/HashCalculator.d.ts +22 -1
- package/dist/core/components/HashCalculator.d.ts.map +1 -1
- package/dist/core/components/HashCalculator.js +49 -6
- package/dist/core/components/HashCalculator.js.map +1 -1
- package/dist/core/components/Util.d.ts +3 -4
- package/dist/core/components/Util.d.ts.map +1 -1
- package/dist/core/components/Util.js +10 -8
- package/dist/core/components/Util.js.map +1 -1
- package/dist/core/constants/Headers.d.ts +1 -3
- package/dist/core/constants/Headers.d.ts.map +1 -1
- package/dist/core/constants/Headers.js +14 -5
- package/dist/core/constants/Headers.js.map +1 -1
- package/dist/core/constants/MetaPaths.d.ts +38 -0
- package/dist/core/constants/MetaPaths.d.ts.map +1 -0
- package/dist/core/constants/MetaPaths.js +79 -0
- package/dist/core/constants/MetaPaths.js.map +1 -0
- package/dist/core/encryption/AesCrypto.d.ts +55 -11
- package/dist/core/encryption/AesCrypto.d.ts.map +1 -1
- package/dist/core/encryption/AesCrypto.js +223 -68
- package/dist/core/encryption/AesCrypto.js.map +1 -1
- package/dist/core/encryption/index.d.ts +1 -1
- package/dist/core/encryption/index.d.ts.map +1 -1
- package/dist/core/encryption/index.js +3 -1
- package/dist/core/encryption/index.js.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +14 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/merkle/MerkleRoot.d.ts +109 -0
- package/dist/core/merkle/MerkleRoot.d.ts.map +1 -0
- package/dist/core/merkle/MerkleRoot.js +275 -0
- package/dist/core/merkle/MerkleRoot.js.map +1 -0
- package/dist/core/version.js +1 -1
- package/dist/node/LegacyZstd.d.ts +67 -0
- package/dist/node/LegacyZstd.d.ts.map +1 -0
- package/dist/node/LegacyZstd.js +209 -0
- package/dist/node/LegacyZstd.js.map +1 -0
- package/dist/node/ZipCompressNode.d.ts +9 -7
- package/dist/node/ZipCompressNode.d.ts.map +1 -1
- package/dist/node/ZipCompressNode.js +105 -75
- package/dist/node/ZipCompressNode.js.map +1 -1
- package/dist/node/ZipDecompressNode.d.ts +7 -3
- package/dist/node/ZipDecompressNode.d.ts.map +1 -1
- package/dist/node/ZipDecompressNode.js +68 -56
- package/dist/node/ZipDecompressNode.js.map +1 -1
- package/dist/node/ZipkitNode.d.ts +23 -0
- package/dist/node/ZipkitNode.d.ts.map +1 -1
- package/dist/node/ZipkitNode.js +195 -41
- package/dist/node/ZipkitNode.js.map +1 -1
- package/dist/node/ZstdNode.d.ts +39 -0
- package/dist/node/ZstdNode.d.ts.map +1 -0
- package/dist/node/ZstdNode.js +171 -0
- package/dist/node/ZstdNode.js.map +1 -0
- package/dist/node/index.d.ts +3 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +11 -1
- package/dist/node/index.js.map +1 -1
- package/package.json +4 -3
- package/src/browser/ZipkitBrowser.ts +4 -6
- package/src/browser/zstd-browser-shim.ts +76 -0
- package/src/core/ZipCompress.ts +71 -42
- package/src/core/ZipDecompress.ts +35 -18
- package/src/core/ZipEntry.ts +8 -1
- package/src/core/Zipkit.ts +149 -76
- package/src/core/components/HashCalculator.ts +58 -6
- package/src/core/components/Util.ts +16 -7
- package/src/core/constants/Headers.ts +14 -4
- package/src/core/constants/MetaPaths.ts +86 -0
- package/src/core/encryption/AesCrypto.ts +265 -86
- package/src/core/encryption/index.ts +1 -1
- package/src/core/index.ts +14 -0
- package/src/core/merkle/MerkleRoot.ts +312 -0
- package/src/core/version.ts +1 -1
- package/src/node/LegacyZstd.ts +270 -0
- package/src/node/ZipCompressNode.ts +127 -84
- package/src/node/ZipDecompressNode.ts +93 -67
- package/src/node/ZipkitNode.ts +230 -42
- package/src/node/ZstdNode.ts +155 -0
- package/src/node/index.ts +10 -0
- package/dist/core/ZstdManager.d.ts +0 -56
- package/dist/core/ZstdManager.d.ts.map +0 -1
- package/dist/core/ZstdManager.js +0 -144
- package/dist/core/ZstdManager.js.map +0 -1
- package/src/core/ZstdManager.ts +0 -165
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ======================================
|
|
3
|
+
// MerkleRoot.ts — NeoZip APPNOTE §6
|
|
4
|
+
// v0 (legacy Bitcoin-style) and v1 (RFC 6962–style domain separation)
|
|
5
|
+
// ======================================
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.normalizeMerklePath = normalizeMerklePath;
|
|
41
|
+
exports.contentDigest = contentDigest;
|
|
42
|
+
exports.leafHashV0 = leafHashV0;
|
|
43
|
+
exports.leafHashV1 = leafHashV1;
|
|
44
|
+
exports.parentHash = parentHash;
|
|
45
|
+
exports.merkleRootFromLeaves = merkleRootFromLeaves;
|
|
46
|
+
exports.computeArchiveMerkleRoot = computeArchiveMerkleRoot;
|
|
47
|
+
exports.computeMerkleRootV0FromDigests = computeMerkleRootV0FromDigests;
|
|
48
|
+
exports.computeMerkleRootV1FromContents = computeMerkleRootV1FromContents;
|
|
49
|
+
exports.computeMerkleRootV1FromLeaves = computeMerkleRootV1FromLeaves;
|
|
50
|
+
exports.matchMerkleRoot = matchMerkleRoot;
|
|
51
|
+
const crypto = __importStar(require("crypto"));
|
|
52
|
+
const MetaPaths_1 = require("../constants/MetaPaths");
|
|
53
|
+
const LEAF_DOMAIN = Buffer.from([0x00]);
|
|
54
|
+
const NODE_DOMAIN = Buffer.from([0x01]);
|
|
55
|
+
function sha256(data) {
|
|
56
|
+
const h = crypto.createHash('sha256');
|
|
57
|
+
if (Array.isArray(data)) {
|
|
58
|
+
for (const part of data) {
|
|
59
|
+
h.update(part);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
h.update(data);
|
|
64
|
+
}
|
|
65
|
+
return h.digest();
|
|
66
|
+
}
|
|
67
|
+
function asBuffer(data, encoding) {
|
|
68
|
+
if (typeof data === 'string') {
|
|
69
|
+
return Buffer.from(data, encoding ?? 'hex');
|
|
70
|
+
}
|
|
71
|
+
return Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Normalize a ZIP entry path for v1 leaf ordering (APPNOTE §6.3):
|
|
75
|
+
* POSIX separators, strip leading `./` and `/`, Unicode NFC, UTF-8 byte order when compared.
|
|
76
|
+
*/
|
|
77
|
+
function normalizeMerklePath(path) {
|
|
78
|
+
let p = path.replace(/\\/g, '/');
|
|
79
|
+
if (p.startsWith('./')) {
|
|
80
|
+
p = p.slice(2);
|
|
81
|
+
}
|
|
82
|
+
while (p.startsWith('/')) {
|
|
83
|
+
p = p.slice(1);
|
|
84
|
+
}
|
|
85
|
+
if (typeof p.normalize === 'function') {
|
|
86
|
+
p = p.normalize('NFC');
|
|
87
|
+
}
|
|
88
|
+
return p;
|
|
89
|
+
}
|
|
90
|
+
/** Sort key for path comparison (UTF-8 byte order). */
|
|
91
|
+
function pathSortKey(path, algorithm) {
|
|
92
|
+
const normalized = algorithm === 'v1' ? normalizeMerklePath(path) : path;
|
|
93
|
+
return Buffer.from(normalized, 'utf8');
|
|
94
|
+
}
|
|
95
|
+
/** Bare content digest (= 0x014E value). */
|
|
96
|
+
function contentDigest(content) {
|
|
97
|
+
return sha256(asBuffer(content));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* v0 leaf: SHA-256(uncompressed bytes) — same as Extra Field 0x014E.
|
|
101
|
+
*/
|
|
102
|
+
function leafHashV0(contentOrDigest, isDigest = false) {
|
|
103
|
+
const buf = asBuffer(contentOrDigest);
|
|
104
|
+
return isDigest ? buf : sha256(buf);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* v1 leaf: SHA-256(0x00 ‖ uncompressed_bytes).
|
|
108
|
+
* Must not be confused with the bare 0x014E digest (APPNOTE §6.3).
|
|
109
|
+
*/
|
|
110
|
+
function leafHashV1(content) {
|
|
111
|
+
return sha256([LEAF_DOMAIN, asBuffer(content)]);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Parent node hashes.
|
|
115
|
+
* v0: SHA-256(H_left ‖ H_right) — order preserved, no pair sorting.
|
|
116
|
+
* v1: SHA-256(0x01 ‖ H_left ‖ H_right).
|
|
117
|
+
*/
|
|
118
|
+
function parentHash(left, right, algorithm) {
|
|
119
|
+
if (algorithm === 'v1') {
|
|
120
|
+
return sha256([NODE_DOMAIN, left, right]);
|
|
121
|
+
}
|
|
122
|
+
return sha256([left, right]);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Fold an ordered list of leaf hashes into a single root (hex lowercase).
|
|
126
|
+
* Odd-count rule:
|
|
127
|
+
* - v0: duplicate last leaf (Bitcoin-style)
|
|
128
|
+
* - v1: promote last node unhashed (RFC 6962–style)
|
|
129
|
+
*/
|
|
130
|
+
function merkleRootFromLeaves(leaves, algorithm) {
|
|
131
|
+
if (leaves.length === 0) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
let level = leaves.map((l) => Buffer.from(l));
|
|
135
|
+
while (level.length > 1) {
|
|
136
|
+
const next = [];
|
|
137
|
+
for (let i = 0; i + 1 < level.length; i += 2) {
|
|
138
|
+
next.push(parentHash(level[i], level[i + 1], algorithm));
|
|
139
|
+
}
|
|
140
|
+
if (level.length % 2 === 1) {
|
|
141
|
+
const last = level[level.length - 1];
|
|
142
|
+
if (algorithm === 'v0') {
|
|
143
|
+
// Duplicate last leaf, then hash the pair
|
|
144
|
+
next.push(parentHash(last, last, algorithm));
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
// Promote unhashed
|
|
148
|
+
next.push(last);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
level = next;
|
|
152
|
+
}
|
|
153
|
+
return level[0].toString('hex');
|
|
154
|
+
}
|
|
155
|
+
function resolveLeaf(entry, algorithm) {
|
|
156
|
+
if (algorithm === 'v0') {
|
|
157
|
+
if (entry.contentSha256) {
|
|
158
|
+
const d = asBuffer(entry.contentSha256, typeof entry.contentSha256 === 'string' ? 'hex' : undefined);
|
|
159
|
+
if (d.length !== 32) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
return d;
|
|
163
|
+
}
|
|
164
|
+
if (entry.content) {
|
|
165
|
+
return contentDigest(entry.content);
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
// v1: prefer precomputed domain-separated leaf from the same hashing pass as 0x014E
|
|
170
|
+
if (entry.merkleLeafV1) {
|
|
171
|
+
const d = asBuffer(entry.merkleLeafV1, typeof entry.merkleLeafV1 === 'string' ? 'hex' : undefined);
|
|
172
|
+
if (d.length !== 32) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
return d;
|
|
176
|
+
}
|
|
177
|
+
// Domain-separated hash of uncompressed payload (re-hash only if leaf not available)
|
|
178
|
+
if (entry.content) {
|
|
179
|
+
return leafHashV1(entry.content);
|
|
180
|
+
}
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Compute archive Merkle root per APPNOTE §6 from content entries
|
|
185
|
+
* (caller already excluded META-INF/** if desired).
|
|
186
|
+
*
|
|
187
|
+
* @returns lowercase hex root, or null if no usable leaves
|
|
188
|
+
*/
|
|
189
|
+
function computeArchiveMerkleRoot(entries, algorithm = 'v1') {
|
|
190
|
+
const prepared = [];
|
|
191
|
+
for (const entry of entries) {
|
|
192
|
+
if ((0, MetaPaths_1.isMetaInfPath)(entry.path || '')) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
const leaf = resolveLeaf(entry, algorithm);
|
|
196
|
+
if (!leaf) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
prepared.push({
|
|
200
|
+
key: pathSortKey(entry.path || '', algorithm),
|
|
201
|
+
leaf,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
if (prepared.length === 0) {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
prepared.sort((a, b) => Buffer.compare(a.key, b.key));
|
|
208
|
+
return merkleRootFromLeaves(prepared.map((p) => p.leaf), algorithm);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Build v0 root from path + bare content digests only (0x014E extras).
|
|
212
|
+
* Path order: central-directory bytes as stored (no NFC / strip).
|
|
213
|
+
*/
|
|
214
|
+
function computeMerkleRootV0FromDigests(entries) {
|
|
215
|
+
return computeArchiveMerkleRoot(entries.map((e) => ({ path: e.path, contentSha256: e.sha256 })), 'v0');
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Build v1 root from path + uncompressed payloads (APPNOTE §6.3).
|
|
219
|
+
* Paths are normalized before sorting.
|
|
220
|
+
*/
|
|
221
|
+
function computeMerkleRootV1FromContents(entries) {
|
|
222
|
+
return computeArchiveMerkleRoot(entries.map((e) => ({ path: e.path, content: e.content })), 'v1');
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Build v1 root from path + precomputed domain-separated leaves (APPNOTE §6.3).
|
|
226
|
+
* Prefer this after create/extract when HashCalculator produced merkleLeafV1 in one stream pass.
|
|
227
|
+
*/
|
|
228
|
+
function computeMerkleRootV1FromLeaves(entries) {
|
|
229
|
+
return computeArchiveMerkleRoot(entries.map((e) => ({ path: e.path, merkleLeafV1: e.merkleLeafV1 })), 'v1');
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Verify a declared root (APPNOTE §6.4): try v1 first (when content or leaves available),
|
|
233
|
+
* then v0 digests. Returns which algorithm matched, or null on failure.
|
|
234
|
+
*
|
|
235
|
+
* When only bare 0x014E digests are available, only v0 can match APPNOTE correctly.
|
|
236
|
+
* Pass `merkleLeafV1` or content for full v1 verification without re-hashing from scratch
|
|
237
|
+
* when leaves were computed in the decompress stream.
|
|
238
|
+
*/
|
|
239
|
+
function matchMerkleRoot(entries, declaredRoot) {
|
|
240
|
+
const expected = declaredRoot.toLowerCase().replace(/^0x/, '');
|
|
241
|
+
if (!/^[0-9a-f]{64}$/.test(expected)) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
const hasV1Material = entries.some((e) => !(0, MetaPaths_1.isMetaInfPath)(e.path || '') &&
|
|
245
|
+
(!!e.merkleLeafV1 || !!e.content));
|
|
246
|
+
if (hasV1Material) {
|
|
247
|
+
const v1 = computeArchiveMerkleRoot(entries, 'v1');
|
|
248
|
+
if (v1 && v1 === expected) {
|
|
249
|
+
return { algorithm: 'v1', security: 'high' };
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const v0 = computeArchiveMerkleRoot(entries, 'v0');
|
|
253
|
+
if (v0 && v0 === expected) {
|
|
254
|
+
return { algorithm: 'v0', security: 'legacy' };
|
|
255
|
+
}
|
|
256
|
+
// If v1 was not tried (no leaves/content), v0 was the only attempt.
|
|
257
|
+
if (hasV1Material) {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
exports.default = {
|
|
263
|
+
normalizeMerklePath,
|
|
264
|
+
contentDigest,
|
|
265
|
+
leafHashV0,
|
|
266
|
+
leafHashV1,
|
|
267
|
+
parentHash,
|
|
268
|
+
merkleRootFromLeaves,
|
|
269
|
+
computeArchiveMerkleRoot,
|
|
270
|
+
computeMerkleRootV0FromDigests,
|
|
271
|
+
computeMerkleRootV1FromContents,
|
|
272
|
+
computeMerkleRootV1FromLeaves,
|
|
273
|
+
matchMerkleRoot,
|
|
274
|
+
};
|
|
275
|
+
//# sourceMappingURL=MerkleRoot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MerkleRoot.js","sourceRoot":"","sources":["../../../src/core/merkle/MerkleRoot.ts"],"names":[],"mappings":";AAAA,yCAAyC;AACzC,qCAAqC;AACrC,uEAAuE;AACvE,yCAAyC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDzC,kDAYC;AASD,sCAEC;AAKD,gCAGC;AAMD,gCAEC;AAOD,gCAKC;AAQD,oDA0BC;AA4CD,4DA6BC;AAMD,wEAOC;AAMD,0EAOC;AAMD,sEAOC;AAUD,0CAgCC;AApSD,+CAAiC;AACjC,sDAAuD;AA0BvD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACxC,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAExC,SAAS,MAAM,CAAC,IAAoC;IAClD,MAAM,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IACtC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,E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exports.VERSION = void 0;
|
|
|
25
25
|
const currentDate = new Date();
|
|
26
26
|
const releaseDate = `${String(currentDate.getMonth() + 1).padStart(2, '0')}-${String(currentDate.getDate()).padStart(2, '0')}-${currentDate.getFullYear()}`;
|
|
27
27
|
exports.VERSION = {
|
|
28
|
-
number: '0.
|
|
28
|
+
number: '1.0.5', // packageJson.version
|
|
29
29
|
date: releaseDate
|
|
30
30
|
};
|
|
31
31
|
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect legacy NeoZipKit WASM zstd (`@oneidentity/zstd-js`).
|
|
3
|
+
*
|
|
4
|
+
* That codec wrote valid-looking zstd frames but declared Frame_Content_Size as
|
|
5
|
+
* `uncompressed_size + 18`. Standard libzstd / Node zlib decode to the real
|
|
6
|
+
* payload plus 18 trailing zero bytes. CRC of the truncated payload matches
|
|
7
|
+
* the ZIP entry CRC.
|
|
8
|
+
*
|
|
9
|
+
* Header-only checks do not require decompressing. Verified checks decompress
|
|
10
|
+
* with native zlib and confirm trailing zeros + optional CRC.
|
|
11
|
+
*/
|
|
12
|
+
/** Fixed extra bytes declared/emitted by the broken WASM codec. */
|
|
13
|
+
export declare const LEGACY_WASM_ZSTD_PADDING = 18;
|
|
14
|
+
export type LegacyZstdConfidence = 'none' | 'header' | 'verified';
|
|
15
|
+
export interface LegacyZstdDetectResult {
|
|
16
|
+
/** True when this looks like (or verifies as) legacy WASM zstd. */
|
|
17
|
+
isLegacyWasm: boolean;
|
|
18
|
+
/** How the decision was made. */
|
|
19
|
+
confidence: LegacyZstdConfidence;
|
|
20
|
+
/** Parsed Frame_Content_Size, if present in the frame header. */
|
|
21
|
+
frameContentSize: number | null;
|
|
22
|
+
/** Expected plaintext size from the ZIP entry (or caller). */
|
|
23
|
+
expectedUncompressedSize: number;
|
|
24
|
+
/** Declared/observed padding past expected size (typically 18). */
|
|
25
|
+
paddingBytes: number;
|
|
26
|
+
/** Human-readable reason. */
|
|
27
|
+
reason: string;
|
|
28
|
+
}
|
|
29
|
+
export interface DetectLegacyZstdOptions {
|
|
30
|
+
/**
|
|
31
|
+
* When true (default), decompress with native zlib and confirm
|
|
32
|
+
* trailing zeros (+ optional CRC) instead of trusting the header alone.
|
|
33
|
+
*/
|
|
34
|
+
verify?: boolean;
|
|
35
|
+
/** ZIP CRC-32 of the original uncompressed data (strengthens verified check). */
|
|
36
|
+
crc?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Read Frame_Content_Size from a zstd frame header, or null if absent / unparseable.
|
|
40
|
+
* @see https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md
|
|
41
|
+
*/
|
|
42
|
+
export declare function parseZstdFrameContentSize(compressed: Buffer): number | null;
|
|
43
|
+
/**
|
|
44
|
+
* Fast header heuristic: FCS === expectedUncompressedSize + 18.
|
|
45
|
+
*/
|
|
46
|
+
export declare function looksLikeLegacyWasmZstd(compressed: Buffer, expectedUncompressedSize: number): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Detect legacy WASM zstd frames for a single compressed payload.
|
|
49
|
+
*/
|
|
50
|
+
export declare function detectLegacyWasmZstd(compressed: Buffer, expectedUncompressedSize: number, options?: DetectLegacyZstdOptions): Promise<LegacyZstdDetectResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Truncate plaintext if it matches the legacy +18 zero padding pattern.
|
|
53
|
+
* Returns the original buffer when not legacy-shaped.
|
|
54
|
+
*/
|
|
55
|
+
export declare function repairLegacyWasmZstdPlaintext(decoded: Buffer, expectedUncompressedSize: number, crc?: number): {
|
|
56
|
+
repaired: Buffer;
|
|
57
|
+
wasLegacy: boolean;
|
|
58
|
+
};
|
|
59
|
+
export declare const LegacyZstd: {
|
|
60
|
+
LEGACY_WASM_ZSTD_PADDING: number;
|
|
61
|
+
parseZstdFrameContentSize: typeof parseZstdFrameContentSize;
|
|
62
|
+
looksLikeLegacyWasmZstd: typeof looksLikeLegacyWasmZstd;
|
|
63
|
+
detectLegacyWasmZstd: typeof detectLegacyWasmZstd;
|
|
64
|
+
repairLegacyWasmZstdPlaintext: typeof repairLegacyWasmZstdPlaintext;
|
|
65
|
+
};
|
|
66
|
+
export default LegacyZstd;
|
|
67
|
+
//# sourceMappingURL=LegacyZstd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LegacyZstd.d.ts","sourceRoot":"","sources":["../../src/node/LegacyZstd.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,mEAAmE;AACnE,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAI3C,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAC;AAElE,MAAM,WAAW,sBAAsB;IACrC,mEAAmE;IACnE,YAAY,EAAE,OAAO,CAAC;IACtB,iCAAiC;IACjC,UAAU,EAAE,oBAAoB,CAAC;IACjC,iEAAiE;IACjE,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,8DAA8D;IAC9D,wBAAwB,EAAE,MAAM,CAAC;IACjC,mEAAmE;IACnE,YAAY,EAAE,MAAM,CAAC;IACrB,6BAA6B;IAC7B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,iFAAiF;IACjF,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAwD3E;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,MAAM,EAClB,wBAAwB,EAAE,MAAM,GAC/B,OAAO,CAST;AAQD;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,MAAM,EAClB,wBAAwB,EAAE,MAAM,EAChC,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,sBAAsB,CAAC,CAwFjC;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,MAAM,EACf,wBAAwB,EAAE,MAAM,EAChC,GAAG,CAAC,EAAE,MAAM,GACX;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAsB1C;AAED,eAAO,MAAM,UAAU;;;;;;CAMtB,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Detect legacy NeoZipKit WASM zstd (`@oneidentity/zstd-js`).
|
|
4
|
+
*
|
|
5
|
+
* That codec wrote valid-looking zstd frames but declared Frame_Content_Size as
|
|
6
|
+
* `uncompressed_size + 18`. Standard libzstd / Node zlib decode to the real
|
|
7
|
+
* payload plus 18 trailing zero bytes. CRC of the truncated payload matches
|
|
8
|
+
* the ZIP entry CRC.
|
|
9
|
+
*
|
|
10
|
+
* Header-only checks do not require decompressing. Verified checks decompress
|
|
11
|
+
* with native zlib and confirm trailing zeros + optional CRC.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.LegacyZstd = exports.LEGACY_WASM_ZSTD_PADDING = void 0;
|
|
15
|
+
exports.parseZstdFrameContentSize = parseZstdFrameContentSize;
|
|
16
|
+
exports.looksLikeLegacyWasmZstd = looksLikeLegacyWasmZstd;
|
|
17
|
+
exports.detectLegacyWasmZstd = detectLegacyWasmZstd;
|
|
18
|
+
exports.repairLegacyWasmZstdPlaintext = repairLegacyWasmZstdPlaintext;
|
|
19
|
+
const ZstdNode_1 = require("./ZstdNode");
|
|
20
|
+
const HashCalculator_1 = require("../core/components/HashCalculator");
|
|
21
|
+
/** Fixed extra bytes declared/emitted by the broken WASM codec. */
|
|
22
|
+
exports.LEGACY_WASM_ZSTD_PADDING = 18;
|
|
23
|
+
const ZSTD_MAGIC = Buffer.from([0x28, 0xb5, 0x2f, 0xfd]);
|
|
24
|
+
/**
|
|
25
|
+
* Read Frame_Content_Size from a zstd frame header, or null if absent / unparseable.
|
|
26
|
+
* @see https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md
|
|
27
|
+
*/
|
|
28
|
+
function parseZstdFrameContentSize(compressed) {
|
|
29
|
+
if (!compressed || compressed.length < 6) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
if (compressed[0] !== ZSTD_MAGIC[0] ||
|
|
33
|
+
compressed[1] !== ZSTD_MAGIC[1] ||
|
|
34
|
+
compressed[2] !== ZSTD_MAGIC[2] ||
|
|
35
|
+
compressed[3] !== ZSTD_MAGIC[3]) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const descriptor = compressed[4];
|
|
39
|
+
const fcsFlag = (descriptor >> 6) & 0x3;
|
|
40
|
+
const singleSegment = ((descriptor >> 5) & 0x1) === 1;
|
|
41
|
+
const dictIdFlag = descriptor & 0x3;
|
|
42
|
+
const dictIdSizes = [0, 1, 2, 4];
|
|
43
|
+
let pos = 5 + dictIdSizes[dictIdFlag];
|
|
44
|
+
if (fcsFlag === 0) {
|
|
45
|
+
if (!singleSegment) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
if (pos >= compressed.length) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return compressed[pos];
|
|
52
|
+
}
|
|
53
|
+
const fcsSizes = [0, 2, 4, 8];
|
|
54
|
+
const n = fcsSizes[fcsFlag];
|
|
55
|
+
if (pos + n > compressed.length) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
let fcs;
|
|
59
|
+
if (n === 2) {
|
|
60
|
+
fcs = compressed.readUInt16LE(pos);
|
|
61
|
+
}
|
|
62
|
+
else if (n === 4) {
|
|
63
|
+
fcs = compressed.readUInt32LE(pos);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const lo = compressed.readUInt32LE(pos);
|
|
67
|
+
const hi = compressed.readUInt32LE(pos + 4);
|
|
68
|
+
// Content sizes that do not fit in JS safe integers are not our legacy case.
|
|
69
|
+
if (hi !== 0) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
fcs = lo;
|
|
73
|
+
}
|
|
74
|
+
// Spec: when FCS_Flag == 1, stored value is (size - 256).
|
|
75
|
+
if (fcsFlag === 1) {
|
|
76
|
+
fcs += 256;
|
|
77
|
+
}
|
|
78
|
+
return fcs;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Fast header heuristic: FCS === expectedUncompressedSize + 18.
|
|
82
|
+
*/
|
|
83
|
+
function looksLikeLegacyWasmZstd(compressed, expectedUncompressedSize) {
|
|
84
|
+
if (expectedUncompressedSize < 0 || !Number.isFinite(expectedUncompressedSize)) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
const fcs = parseZstdFrameContentSize(compressed);
|
|
88
|
+
if (fcs === null) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
return fcs === expectedUncompressedSize + exports.LEGACY_WASM_ZSTD_PADDING;
|
|
92
|
+
}
|
|
93
|
+
function crc32Of(data) {
|
|
94
|
+
const h = new HashCalculator_1.HashCalculator();
|
|
95
|
+
h.update(data);
|
|
96
|
+
return h.finalizeCRC32();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Detect legacy WASM zstd frames for a single compressed payload.
|
|
100
|
+
*/
|
|
101
|
+
async function detectLegacyWasmZstd(compressed, expectedUncompressedSize, options) {
|
|
102
|
+
const expected = expectedUncompressedSize >>> 0;
|
|
103
|
+
const fcs = parseZstdFrameContentSize(compressed);
|
|
104
|
+
const headerMatch = fcs !== null && fcs === expected + exports.LEGACY_WASM_ZSTD_PADDING;
|
|
105
|
+
const base = {
|
|
106
|
+
frameContentSize: fcs,
|
|
107
|
+
expectedUncompressedSize: expected,
|
|
108
|
+
paddingBytes: exports.LEGACY_WASM_ZSTD_PADDING,
|
|
109
|
+
};
|
|
110
|
+
if (!headerMatch && options?.verify === false) {
|
|
111
|
+
return {
|
|
112
|
+
...base,
|
|
113
|
+
isLegacyWasm: false,
|
|
114
|
+
confidence: 'none',
|
|
115
|
+
reason: fcs === null
|
|
116
|
+
? 'No Frame_Content_Size in zstd header (or not a zstd frame)'
|
|
117
|
+
: `Frame_Content_Size ${fcs} does not equal expected ${expected} + ${exports.LEGACY_WASM_ZSTD_PADDING}`,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (options?.verify === false) {
|
|
121
|
+
return {
|
|
122
|
+
...base,
|
|
123
|
+
isLegacyWasm: true,
|
|
124
|
+
confidence: 'header',
|
|
125
|
+
reason: `Frame_Content_Size is expected+${exports.LEGACY_WASM_ZSTD_PADDING} (legacy WASM heuristic)`,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
// Verified path (default): decompress and check padding / CRC.
|
|
129
|
+
let decoded;
|
|
130
|
+
try {
|
|
131
|
+
decoded = await ZstdNode_1.ZstdNode.decompress(compressed);
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
return {
|
|
135
|
+
...base,
|
|
136
|
+
isLegacyWasm: false,
|
|
137
|
+
confidence: 'none',
|
|
138
|
+
reason: `Native decompress failed: ${e instanceof Error ? e.message : String(e)}`,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const pad = decoded.length - expected;
|
|
142
|
+
const trailingZeros = pad === exports.LEGACY_WASM_ZSTD_PADDING &&
|
|
143
|
+
decoded.subarray(expected).equals(Buffer.alloc(exports.LEGACY_WASM_ZSTD_PADDING));
|
|
144
|
+
const truncated = decoded.subarray(0, Math.min(expected, decoded.length));
|
|
145
|
+
const crcOk = options?.crc === undefined ||
|
|
146
|
+
options.crc === 0 ||
|
|
147
|
+
crc32Of(truncated) === (options.crc >>> 0);
|
|
148
|
+
if (trailingZeros && crcOk && decoded.length === expected + exports.LEGACY_WASM_ZSTD_PADDING) {
|
|
149
|
+
return {
|
|
150
|
+
...base,
|
|
151
|
+
isLegacyWasm: true,
|
|
152
|
+
confidence: 'verified',
|
|
153
|
+
reason: options?.crc && options.crc !== 0
|
|
154
|
+
? `Decoded length is +${exports.LEGACY_WASM_ZSTD_PADDING} with trailing zeros; truncated CRC matches`
|
|
155
|
+
: `Decoded length is +${exports.LEGACY_WASM_ZSTD_PADDING} with trailing zeros`,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
if (headerMatch && !trailingZeros) {
|
|
159
|
+
return {
|
|
160
|
+
...base,
|
|
161
|
+
isLegacyWasm: false,
|
|
162
|
+
confidence: 'none',
|
|
163
|
+
reason: 'Header suggested legacy WASM but decoded payload did not have 18 trailing zeros',
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
...base,
|
|
168
|
+
isLegacyWasm: false,
|
|
169
|
+
confidence: 'none',
|
|
170
|
+
paddingBytes: Math.max(0, pad),
|
|
171
|
+
reason: decoded.length === expected
|
|
172
|
+
? 'Standard zstd frame (decoded size matches expected)'
|
|
173
|
+
: `Decoded size ${decoded.length} does not match legacy pattern (expected ${expected} or ${expected + exports.LEGACY_WASM_ZSTD_PADDING})`,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Truncate plaintext if it matches the legacy +18 zero padding pattern.
|
|
178
|
+
* Returns the original buffer when not legacy-shaped.
|
|
179
|
+
*/
|
|
180
|
+
function repairLegacyWasmZstdPlaintext(decoded, expectedUncompressedSize, crc) {
|
|
181
|
+
const expected = expectedUncompressedSize >>> 0;
|
|
182
|
+
if (decoded.length === expected + exports.LEGACY_WASM_ZSTD_PADDING &&
|
|
183
|
+
decoded.subarray(expected).equals(Buffer.alloc(exports.LEGACY_WASM_ZSTD_PADDING))) {
|
|
184
|
+
const repaired = decoded.subarray(0, expected);
|
|
185
|
+
if (crc !== undefined && crc !== 0) {
|
|
186
|
+
if (crc32Of(repaired) !== (crc >>> 0)) {
|
|
187
|
+
return { repaired: decoded, wasLegacy: false };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return { repaired, wasLegacy: true };
|
|
191
|
+
}
|
|
192
|
+
if (decoded.length > expected && expected > 0) {
|
|
193
|
+
// Match Rust extract behavior: bound to declared uncompressed size for zstd.
|
|
194
|
+
const repaired = decoded.subarray(0, expected);
|
|
195
|
+
if (crc !== undefined && crc !== 0 && crc32Of(repaired) === (crc >>> 0)) {
|
|
196
|
+
return { repaired, wasLegacy: true };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return { repaired: decoded, wasLegacy: false };
|
|
200
|
+
}
|
|
201
|
+
exports.LegacyZstd = {
|
|
202
|
+
LEGACY_WASM_ZSTD_PADDING: exports.LEGACY_WASM_ZSTD_PADDING,
|
|
203
|
+
parseZstdFrameContentSize,
|
|
204
|
+
looksLikeLegacyWasmZstd,
|
|
205
|
+
detectLegacyWasmZstd,
|
|
206
|
+
repairLegacyWasmZstdPlaintext,
|
|
207
|
+
};
|
|
208
|
+
exports.default = exports.LegacyZstd;
|
|
209
|
+
//# sourceMappingURL=LegacyZstd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LegacyZstd.js","sourceRoot":"","sources":["../../src/node/LegacyZstd.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAyCH,8DAwDC;AAKD,0DAYC;AAWD,oDA4FC;AAMD,sEA0BC;AAvPD,yCAAsC;AACtC,sEAAmE;AAEnE,mEAAmE;AACtD,QAAA,wBAAwB,GAAG,EAAE,CAAC;AAE3C,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AA6BzD;;;GAGG;AACH,SAAgB,yBAAyB,CAAC,UAAkB;IAC1D,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzC,OA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AAK,CAAC,CAAC,EAAE,CAAC;YACxE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;QACvC,CAAC;IACH,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AACjD,CAAC;AAEY,QAAA,UAAU,GAAG;IACxB,wBAAwB,EAAxB,gCAAwB;IACxB,yBAAyB;IACzB,uBAAuB;IACvB,oBAAoB;IACpB,6BAA6B;CAC9B,CAAC;AAEF,kBAAe,kBAAU,CAAC"}
|
|
@@ -58,17 +58,19 @@ export declare class ZipCompressNode {
|
|
|
58
58
|
*/
|
|
59
59
|
deflate(inbuf: Buffer, options?: CompressOptions): Buffer;
|
|
60
60
|
/**
|
|
61
|
-
* Compresses data using Zstandard
|
|
62
|
-
*
|
|
61
|
+
* Compresses data using Zstandard via Node native zlib chunked streaming.
|
|
62
|
+
*
|
|
63
|
+
* @param input - Buffer OR chunked reader (`onReadChunk` preferred; `readChunk` accepted)
|
|
63
64
|
* @param options - Compression options
|
|
64
|
-
* @param bufferSize -
|
|
65
|
-
* @param entry - Optional ZIP entry for hash
|
|
66
|
-
* @param onOutputBuffer - Optional callback for streaming output
|
|
67
|
-
* @returns Compressed
|
|
65
|
+
* @param bufferSize - Chunk size for streaming reads (default: 512KB)
|
|
66
|
+
* @param entry - Optional ZIP entry for hash / compressedSize
|
|
67
|
+
* @param onOutputBuffer - Optional callback for streaming compressed output
|
|
68
|
+
* @returns Compressed buffer, or empty buffer when streamed via onOutputBuffer
|
|
68
69
|
*/
|
|
69
70
|
zstdCompress(input: Buffer | {
|
|
70
71
|
totalSize: number;
|
|
71
|
-
|
|
72
|
+
onReadChunk?: (position: number, size: number) => Buffer;
|
|
73
|
+
readChunk?: (position: number, size: number) => Buffer;
|
|
72
74
|
}, options?: CompressOptions, bufferSize?: number, entry?: ZipEntry, onOutputBuffer?: (data: Buffer) => Promise<void>): Promise<Buffer>;
|
|
73
75
|
/**
|
|
74
76
|
* Encrypt compressed data using PKZIP encryption
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZipCompressNode.d.ts","sourceRoot":"","sources":["../../src/node/ZipCompressNode.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,QAAQ,MAAM,kBAAkB,CAAC;AACxC,OAAO,UAAU,MAAM,cAAc,CAAC;AAetC,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D;;;;;;;;;;;;GAYG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,UAAU,CAAa;IAG/B,OAAO,CAAC,MAAM,CAAC,cAAc,CAAkB;IAE/C;;OAEG;IACH,OAAO,CAAC,GAAG;IAMX;;;OAGG;gBACS,UAAU,EAAE,UAAU;IAYlC;;;;;;;OAOG;IACG,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,EAAE,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"ZipCompressNode.d.ts","sourceRoot":"","sources":["../../src/node/ZipCompressNode.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,QAAQ,MAAM,kBAAkB,CAAC;AACxC,OAAO,UAAU,MAAM,cAAc,CAAC;AAetC,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D;;;;;;;;;;;;GAYG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,UAAU,CAAa;IAG/B,OAAO,CAAC,MAAM,CAAC,cAAc,CAAkB;IAE/C;;OAEG;IACH,OAAO,CAAC,GAAG;IAMX;;;OAGG;gBACS,UAAU,EAAE,UAAU;IAYlC;;;;;;;OAOG;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