neozipkit 0.2.1 → 0.3.0
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/LICENSE +22 -0
- package/README.md +410 -186
- package/contracts/ABI.txt +889 -0
- package/contracts/Bytecode.txt +1 -0
- package/contracts/COMPILATION_NOTES.md +59 -0
- package/contracts/QUICK_DEPLOY.md +286 -0
- package/contracts/README.md +235 -131
- package/contracts/VERIFICATION.md +308 -0
- package/contracts/deploy-interactive.js +448 -0
- package/contracts/deployment-arbitrum-sepolia.json +12 -0
- package/contracts/deployment-arbitrum.json +12 -0
- package/contracts/deployment-eth-sepolia.json +12 -0
- package/contracts/hardhat.config.js +114 -0
- package/contracts/package.json +20 -0
- package/contracts/scripts/compile-and-extract.js +119 -0
- package/contracts/scripts/verify-contract.js +223 -0
- package/contracts/src/{NZIP-NFT-Private.sol → NZIP-NFT-v2.0.sol} +66 -151
- package/contracts/src/NZIP-NFT.sol +9 -15
- package/dist/blockchain/browser/TokenVerifierBrowser.d.ts +67 -0
- package/dist/blockchain/browser/TokenVerifierBrowser.d.ts.map +1 -0
- package/dist/blockchain/browser/TokenVerifierBrowser.js +313 -0
- package/dist/blockchain/browser/TokenVerifierBrowser.js.map +1 -0
- package/dist/blockchain/browser/WalletManagerBrowser.d.ts +98 -0
- package/dist/blockchain/browser/WalletManagerBrowser.d.ts.map +1 -0
- package/dist/blockchain/browser/WalletManagerBrowser.js +434 -0
- package/dist/blockchain/browser/WalletManagerBrowser.js.map +1 -0
- package/dist/blockchain/browser/ZipkitMinterBrowser.d.ts +58 -0
- package/dist/blockchain/browser/ZipkitMinterBrowser.d.ts.map +1 -0
- package/dist/blockchain/browser/ZipkitMinterBrowser.js +317 -0
- package/dist/blockchain/browser/ZipkitMinterBrowser.js.map +1 -0
- package/dist/blockchain/browser/index.d.ts +11 -0
- package/dist/blockchain/browser/index.d.ts.map +1 -0
- package/dist/blockchain/browser/index.js +16 -0
- package/dist/blockchain/browser/index.js.map +1 -0
- package/dist/blockchain/core/WalletManager.d.ts +124 -0
- package/dist/blockchain/core/WalletManager.d.ts.map +1 -0
- package/dist/blockchain/{ZipKitWallet.js → core/WalletManager.js} +157 -177
- package/dist/blockchain/core/WalletManager.js.map +1 -0
- package/dist/blockchain/{ZipKitMinter.d.ts → core/ZipkitMinter.d.ts} +46 -11
- package/dist/blockchain/core/ZipkitMinter.d.ts.map +1 -0
- package/dist/blockchain/core/ZipkitMinter.js +548 -0
- package/dist/blockchain/core/ZipkitMinter.js.map +1 -0
- package/dist/blockchain/{ZipKitOTS.d.ts → core/ZipkitOTS.d.ts} +6 -15
- package/dist/blockchain/core/ZipkitOTS.d.ts.map +1 -0
- package/dist/blockchain/{ZipKitOTS.js → core/ZipkitOTS.js} +26 -84
- package/dist/blockchain/core/ZipkitOTS.js.map +1 -0
- package/dist/blockchain/core/ZipkitVerifier.d.ts +177 -0
- package/dist/blockchain/core/ZipkitVerifier.d.ts.map +1 -0
- package/dist/blockchain/core/ZipkitVerifier.js +632 -0
- package/dist/blockchain/core/ZipkitVerifier.js.map +1 -0
- package/dist/blockchain/core/contracts.d.ts +83 -0
- package/dist/blockchain/core/contracts.d.ts.map +1 -0
- package/dist/blockchain/core/contracts.js +341 -0
- package/dist/blockchain/core/contracts.js.map +1 -0
- package/dist/blockchain/core/index.d.ts +12 -0
- package/dist/blockchain/core/index.d.ts.map +1 -0
- package/dist/blockchain/core/index.js +59 -0
- package/dist/blockchain/core/index.js.map +1 -0
- package/dist/blockchain/index.d.ts +11 -7
- package/dist/blockchain/index.d.ts.map +1 -0
- package/dist/blockchain/index.js +18 -34
- package/dist/blockchain/index.js.map +1 -0
- package/dist/blockchain/node/WalletManagerNode.d.ts +47 -0
- package/dist/blockchain/node/WalletManagerNode.d.ts.map +1 -0
- package/dist/blockchain/node/WalletManagerNode.js +203 -0
- package/dist/blockchain/node/WalletManagerNode.js.map +1 -0
- package/dist/blockchain/node/index.d.ts +12 -0
- package/dist/blockchain/node/index.d.ts.map +1 -0
- package/dist/blockchain/node/index.js +24 -0
- package/dist/blockchain/node/index.js.map +1 -0
- package/dist/browser/ZipkitBrowser.d.ts +27 -0
- package/dist/browser/ZipkitBrowser.d.ts.map +1 -0
- package/dist/browser/{ZipKitBrowser.js → ZipkitBrowser.js} +96 -43
- package/dist/browser/ZipkitBrowser.js.map +1 -0
- package/dist/browser/index.d.ts +12 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +42 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser-esm/index.d.ts +12 -0
- package/dist/browser-esm/index.js +59559 -0
- package/dist/browser-esm/index.js.map +7 -0
- package/dist/browser-umd/index.d.ts +12 -0
- package/dist/browser-umd/index.js +59576 -0
- package/dist/browser-umd/index.js.map +7 -0
- package/dist/browser-umd/index.min.js +63 -0
- package/dist/browser.d.ts +8 -14
- package/dist/browser.js +13 -28
- package/dist/core/ZipCompress.d.ts +99 -0
- package/dist/core/ZipCompress.d.ts.map +1 -0
- package/dist/core/ZipCompress.js +309 -0
- package/dist/core/ZipCompress.js.map +1 -0
- package/dist/core/ZipDecompress.d.ts +58 -0
- package/dist/core/ZipDecompress.d.ts.map +1 -0
- package/dist/core/ZipDecompress.js +172 -0
- package/dist/core/ZipDecompress.js.map +1 -0
- package/dist/{shared → core}/ZipEntry.d.ts +8 -1
- package/dist/core/ZipEntry.d.ts.map +1 -0
- package/dist/{shared → core}/ZipEntry.js +225 -82
- package/dist/core/ZipEntry.js.map +1 -0
- package/dist/core/Zipkit.d.ts +315 -0
- package/dist/core/Zipkit.d.ts.map +1 -0
- package/dist/core/Zipkit.js +647 -0
- package/dist/core/Zipkit.js.map +1 -0
- package/dist/core/components/HashCalculator.d.ts +138 -0
- package/dist/core/components/HashCalculator.d.ts.map +1 -0
- package/dist/core/components/HashCalculator.js +360 -0
- package/dist/core/components/HashCalculator.js.map +1 -0
- package/dist/core/components/Logger.d.ts +73 -0
- package/dist/core/components/Logger.d.ts.map +1 -0
- package/dist/core/components/Logger.js +156 -0
- package/dist/core/components/Logger.js.map +1 -0
- package/dist/core/components/ProgressTracker.d.ts +43 -0
- package/dist/core/components/ProgressTracker.d.ts.map +1 -0
- package/dist/core/components/ProgressTracker.js +112 -0
- package/dist/core/components/ProgressTracker.js.map +1 -0
- package/dist/{shared → core}/components/Support.d.ts +1 -0
- package/dist/core/components/Support.d.ts.map +1 -0
- package/dist/{shared → core}/components/Support.js +1 -0
- package/dist/core/components/Support.js.map +1 -0
- package/dist/{shared → core}/components/Util.d.ts +7 -2
- package/dist/core/components/Util.d.ts.map +1 -0
- package/dist/{shared → core}/components/Util.js +14 -34
- package/dist/core/components/Util.js.map +1 -0
- package/dist/{shared → core}/constants/Errors.d.ts +1 -2
- package/dist/core/constants/Errors.d.ts.map +1 -0
- package/dist/{shared → core}/constants/Errors.js +1 -3
- package/dist/core/constants/Errors.js.map +1 -0
- package/dist/{shared → core}/constants/Headers.d.ts +3 -0
- package/dist/core/constants/Headers.d.ts.map +1 -0
- package/dist/{shared → core}/constants/Headers.js +20 -17
- package/dist/core/constants/Headers.js.map +1 -0
- package/dist/core/encryption/Manager.d.ts +58 -0
- package/dist/core/encryption/Manager.d.ts.map +1 -0
- package/dist/core/encryption/Manager.js +121 -0
- package/dist/core/encryption/Manager.js.map +1 -0
- package/dist/core/encryption/ZipCrypto.d.ts +172 -0
- package/dist/core/encryption/ZipCrypto.d.ts.map +1 -0
- package/dist/core/encryption/ZipCrypto.js +554 -0
- package/dist/core/encryption/ZipCrypto.js.map +1 -0
- package/dist/core/encryption/index.d.ts +9 -0
- package/dist/core/encryption/index.d.ts.map +1 -0
- package/dist/core/encryption/index.js +17 -0
- package/dist/core/encryption/index.js.map +1 -0
- package/dist/core/encryption/types.d.ts +29 -0
- package/dist/core/encryption/types.d.ts.map +1 -0
- package/dist/core/encryption/types.js +12 -0
- package/dist/core/encryption/types.js.map +1 -0
- package/dist/core/index.d.ts +24 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +57 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/version.d.ts +5 -0
- package/dist/core/version.d.ts.map +1 -0
- package/dist/core/version.js +31 -0
- package/dist/core/version.js.map +1 -0
- package/dist/index.d.ts +8 -18
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -35
- package/dist/index.js.map +1 -0
- package/dist/node/ZipCompressNode.d.ts +123 -0
- package/dist/node/ZipCompressNode.d.ts.map +1 -0
- package/dist/node/ZipCompressNode.js +576 -0
- package/dist/node/ZipCompressNode.js.map +1 -0
- package/dist/node/ZipDecompressNode.d.ts +120 -0
- package/dist/node/ZipDecompressNode.d.ts.map +1 -0
- package/dist/node/ZipDecompressNode.js +461 -0
- package/dist/node/ZipDecompressNode.js.map +1 -0
- package/dist/node/ZipkitNode.d.ts +406 -0
- package/dist/node/ZipkitNode.d.ts.map +1 -0
- package/dist/node/ZipkitNode.js +1305 -0
- package/dist/node/ZipkitNode.js.map +1 -0
- package/dist/node/index.d.ts +26 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +65 -0
- package/dist/node/index.js.map +1 -0
- package/dist/types/index.d.ts +59 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +36 -1
- package/dist/types/index.js.map +1 -0
- package/examples/README.md +269 -0
- package/examples/blockchain-tokenize.ts +354 -0
- package/examples/create-zip.ts +172 -0
- package/examples/extract-zip.ts +158 -0
- package/examples/list-zip.ts +161 -0
- package/examples/test-files/data.json +116 -0
- package/examples/test-files/document.md +80 -0
- package/examples/test-files/document.txt +2 -0
- package/examples/test-files/file1.txt +48 -0
- package/examples/test-files/file2.txt +80 -0
- package/examples/tsconfig.json +44 -0
- package/examples/unzip-token.ts +491 -0
- package/examples/verify-tokenized-zip.ts +305 -0
- package/examples/zip-token.ts +604 -0
- package/package.json +108 -24
- package/src/blockchain/README.md +59 -66
- package/src/{browser/TokenVerifierBrowser.ts-remove → blockchain/browser/TokenVerifierBrowser.ts} +125 -79
- package/src/blockchain/browser/WalletManagerBrowser.ts +486 -0
- package/src/blockchain/browser/ZipkitMinterBrowser.ts +400 -0
- package/src/blockchain/browser/index.ts +13 -0
- package/src/blockchain/{ZipKitWallet.ts → core/WalletManager.ts} +241 -143
- package/src/blockchain/core/ZipkitMinter.ts +716 -0
- package/src/blockchain/{ZipKitOTS.ts → core/ZipkitOTS.ts} +28 -62
- package/src/blockchain/core/ZipkitVerifier.ts +853 -0
- package/src/blockchain/core/contracts.ts +370 -0
- package/src/blockchain/core/index.ts +71 -0
- package/src/blockchain/index.ts +21 -55
- package/src/blockchain/node/WalletManagerNode.ts +171 -0
- package/src/blockchain/node/index.ts +40 -0
- package/src/browser/{ZipKitBrowser.ts → ZipkitBrowser.ts} +104 -41
- package/src/browser/index.esm.ts +37 -0
- package/src/browser/index.ts +25 -0
- package/src/core/ZipCompress.ts +398 -0
- package/src/core/ZipDecompress.ts +212 -0
- package/src/{shared → core}/ZipEntry.ts +240 -90
- package/src/core/Zipkit.ts +794 -0
- package/src/core/components/HashCalculator.ts +384 -0
- package/src/core/components/Logger.ts +180 -0
- package/src/core/components/ProgressTracker.ts +134 -0
- package/src/{shared → core}/components/Util.ts +12 -34
- package/src/{shared → core}/constants/Errors.ts +0 -4
- package/src/{shared → core}/constants/Headers.ts +19 -17
- package/src/core/encryption/Manager.ts +137 -0
- package/src/core/encryption/ZipCrypto.ts +650 -0
- package/src/core/encryption/index.ts +15 -0
- package/src/core/encryption/types.ts +33 -0
- package/src/core/index.ts +34 -0
- package/src/core/version.ts +33 -0
- package/src/index.ts +54 -25
- package/src/node/ZipCompressNode.ts +632 -0
- package/src/node/ZipDecompressNode.ts +508 -0
- package/src/node/ZipkitNode.ts +1559 -0
- package/src/node/index.ts +69 -0
- package/src/types/index.ts +131 -1
- package/src/types/modules.d.ts +1 -11
- package/src/types/opentimestamps.d.ts +1 -23
- package/contracts/INTEGRATION.md +0 -338
- package/contracts/NETWORKS.md +0 -156
- package/contracts/NZIP-NFT-bytecode.txt +0 -1
- package/contracts/constants.ts +0 -952
- package/contracts/deploy-bytecode.mjs +0 -94
- package/dist/blockchain/CertificateToken.d.ts +0 -48
- package/dist/blockchain/CertificateToken.js +0 -386
- package/dist/blockchain/ZipKitMinter.js +0 -347
- package/dist/blockchain/ZipKitNFT.d.ts +0 -3
- package/dist/blockchain/ZipKitNFT.js +0 -7
- package/dist/blockchain/ZipKitVerifier.d.ts +0 -69
- package/dist/blockchain/ZipKitVerifier.js +0 -289
- package/dist/blockchain/ZipKitWallet.d.ts +0 -69
- package/dist/blockchain/contracts.d.ts +0 -14
- package/dist/blockchain/contracts.js +0 -77
- package/dist/blockchain/types.d.ts +0 -47
- package/dist/blockchain/types.js +0 -30
- package/dist/browser/ZipKitBrowser.d.ts +0 -18
- package/dist/browser/ZipKitStampBrowser.d.ts +0 -2
- package/dist/browser/ZipKitStampBrowser.js +0 -12
- package/dist/browser-index.d.ts +0 -18
- package/dist/browser-index.js +0 -57
- package/dist/server/ZipKitServer.d.ts +0 -74
- package/dist/server/ZipKitServer.js +0 -310
- package/dist/shared/ZipKit.d.ts +0 -243
- package/dist/shared/ZipKit.js +0 -772
- package/dist/shared/components/CertificateOTS.d.ts +0 -15
- package/dist/shared/components/CertificateOTS.js +0 -116
- package/dist/shared/components/FileSys.d.ts +0 -2
- package/dist/shared/components/FileSys.js +0 -113
- package/dist/shared/components/HashAccumulator.d.ts +0 -55
- package/dist/shared/components/HashAccumulator.js +0 -100
- package/dist/shared/components/ZipCrypto.d.ts +0 -3
- package/dist/shared/components/ZipCrypto.js +0 -78
- package/dist/shared/components/merkleTree.d.ts +0 -66
- package/dist/shared/components/merkleTree.js +0 -136
- package/dist/shared/types/index.d.ts +0 -21
- package/dist/shared/types/index.js +0 -3
- package/dist/shared/types.d.ts +0 -33
- package/dist/shared/types.js +0 -8
- package/dist/shared/version.d.ts +0 -2
- package/dist/shared/version.js +0 -6
- package/src/blockchain/CertificateToken.ts +0 -444
- package/src/blockchain/ZipKitMinter.ts +0 -470
- package/src/blockchain/ZipKitNFT.ts +0 -12
- package/src/blockchain/ZipKitVerifier.ts +0 -382
- package/src/blockchain/contracts.ts +0 -88
- package/src/blockchain/types.ts +0 -91
- package/src/browser/CertificateGeneratorBrowser.ts-remove +0 -498
- package/src/browser/ZipKitStampBrowser.ts +0 -9
- package/src/browser-index.ts +0 -36
- package/src/server/README.md +0 -25
- package/src/server/ZipKitServer.ts +0 -305
- package/src/shared/ZipKit.ts +0 -881
- package/src/shared/components/CertificateOTS.ts +0 -132
- package/src/shared/components/FileSys.ts +0 -87
- package/src/shared/components/HashAccumulator.ts +0 -113
- package/src/shared/components/ZipCrypto.ts +0 -91
- package/src/shared/components/merkleTree.ts +0 -162
- package/src/shared/types/index.ts +0 -25
- package/src/shared/types/modules.d.ts +0 -22
- package/src/shared/types/opentimestamps.d.ts +0 -23
- package/src/shared/types.d.ts +0 -8
- package/src/shared/types.ts +0 -43
- package/src/shared/version.ts +0 -3
- /package/src/{shared → core}/components/Support.ts +0 -0
package/dist/browser.d.ts
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export {
|
|
8
|
-
export { default as HashAccumulator } from './shared/components/HashAccumulator';
|
|
9
|
-
export * from './shared/components/Util';
|
|
10
|
-
export * from './shared/components/Support';
|
|
11
|
-
export * from './shared/types';
|
|
12
|
-
export * from './shared/constants/Headers';
|
|
13
|
-
export * from './shared/constants/Errors';
|
|
14
|
-
export * from './shared/version';
|
|
1
|
+
export * from "./core";
|
|
2
|
+
import Zipkit from "./core";
|
|
3
|
+
export default Zipkit;
|
|
4
|
+
export { default as ZipkitBrowser } from "./browser/ZipkitBrowser";
|
|
5
|
+
export { TokenMetadata } from "./types";
|
|
6
|
+
export * from "./blockchain/browser/index";
|
|
7
|
+
export { createTokenVerifier } from "./blockchain/browser/index";
|
|
15
8
|
export declare const PlatformUtils: {
|
|
16
9
|
isBrowser: boolean;
|
|
17
10
|
isNode: string | false;
|
|
18
11
|
};
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// =============================================================================
|
|
3
|
-
//
|
|
3
|
+
// NeoZipkit - Browser-Only Package Exports
|
|
4
4
|
// =============================================================================
|
|
5
5
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
6
|
if (k2 === undefined) k2 = k;
|
|
@@ -20,34 +20,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.PlatformUtils = exports.
|
|
24
|
-
// Core shared exports
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
Object.defineProperty(exports, "Errors", { enumerable: true, get: function () { return ZipKit_2.Errors; } });
|
|
29
|
-
Object.defineProperty(exports, "CMP_METHOD", { enumerable: true, get: function () { return ZipKit_2.CMP_METHOD; } });
|
|
30
|
-
Object.defineProperty(exports, "TIMESTAMP_METADATA", { enumerable: true, get: function () { return ZipKit_2.TIMESTAMP_METADATA; } });
|
|
31
|
-
Object.defineProperty(exports, "TIMESTAMP_SUBMITTED", { enumerable: true, get: function () { return ZipKit_2.TIMESTAMP_SUBMITTED; } });
|
|
32
|
-
__exportStar(require("./shared/ZipKit"), exports);
|
|
33
|
-
__exportStar(require("./shared/ZipEntry"), exports);
|
|
34
|
-
exports.default = ZipKit_1.default;
|
|
23
|
+
exports.PlatformUtils = exports.createTokenVerifier = exports.ZipkitBrowser = void 0;
|
|
24
|
+
// Core shared exports (re-exported from core module)
|
|
25
|
+
__exportStar(require("./core"), exports);
|
|
26
|
+
const core_1 = __importDefault(require("./core"));
|
|
27
|
+
exports.default = core_1.default;
|
|
35
28
|
// Browser-only exports
|
|
36
|
-
var
|
|
37
|
-
Object.defineProperty(exports, "
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var HashAccumulator_1 = require("./shared/components/HashAccumulator");
|
|
43
|
-
Object.defineProperty(exports, "HashAccumulator", { enumerable: true, get: function () { return __importDefault(HashAccumulator_1).default; } });
|
|
44
|
-
__exportStar(require("./shared/components/Util"), exports);
|
|
45
|
-
__exportStar(require("./shared/components/Support"), exports);
|
|
46
|
-
// Type and constant exports
|
|
47
|
-
__exportStar(require("./shared/types"), exports);
|
|
48
|
-
__exportStar(require("./shared/constants/Headers"), exports);
|
|
49
|
-
__exportStar(require("./shared/constants/Errors"), exports);
|
|
50
|
-
__exportStar(require("./shared/version"), exports);
|
|
29
|
+
var ZipkitBrowser_1 = require("./browser/ZipkitBrowser");
|
|
30
|
+
Object.defineProperty(exports, "ZipkitBrowser", { enumerable: true, get: function () { return __importDefault(ZipkitBrowser_1).default; } });
|
|
31
|
+
// Blockchain exports for browser
|
|
32
|
+
__exportStar(require("./blockchain/browser/index"), exports);
|
|
33
|
+
var browser_1 = require("./blockchain/browser/index");
|
|
34
|
+
Object.defineProperty(exports, "createTokenVerifier", { enumerable: true, get: function () { return browser_1.createTokenVerifier; } });
|
|
51
35
|
// Platform-specific conditional exports
|
|
52
36
|
exports.PlatformUtils = {
|
|
53
37
|
// Browser detection
|
|
@@ -55,3 +39,4 @@ exports.PlatformUtils = {
|
|
|
55
39
|
// Node.js detection
|
|
56
40
|
isNode: typeof process !== 'undefined' && process.versions && process.versions.node,
|
|
57
41
|
};
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import Zipkit from './Zipkit';
|
|
2
|
+
import ZipEntry from './ZipEntry';
|
|
3
|
+
/**
|
|
4
|
+
* Options for compressing files in a ZIP archive
|
|
5
|
+
*/
|
|
6
|
+
export interface CompressOptions {
|
|
7
|
+
level?: number;
|
|
8
|
+
password?: string | null;
|
|
9
|
+
useSHA256?: boolean;
|
|
10
|
+
useZstd?: boolean;
|
|
11
|
+
bufferSize?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Callbacks for ZIP file creation process
|
|
15
|
+
* Buffer-based only - no file I/O operations
|
|
16
|
+
*/
|
|
17
|
+
export interface CreateZipOptions {
|
|
18
|
+
onError?: (error: Error) => void;
|
|
19
|
+
onEntryDone?: (entry: ZipEntry, status: string) => void;
|
|
20
|
+
onOutputBuffer?: (data: Buffer) => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Compression handler for ZIP files
|
|
24
|
+
* Supports Deflate, Zstandard, and Store methods
|
|
25
|
+
*/
|
|
26
|
+
export declare class ZipCompress {
|
|
27
|
+
private zipkit;
|
|
28
|
+
private debug;
|
|
29
|
+
private static loggingEnabled;
|
|
30
|
+
/**
|
|
31
|
+
* Internal logging method - only logs if class logging is enabled
|
|
32
|
+
*/
|
|
33
|
+
private log;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new ZipCompress instance
|
|
36
|
+
* @param zipkit - Zipkit instance to use for ZIP operations
|
|
37
|
+
*/
|
|
38
|
+
constructor(zipkit: Zipkit);
|
|
39
|
+
/**
|
|
40
|
+
* Compresses data for a ZIP entry (Buffer-based only)
|
|
41
|
+
* @param entry - ZIP entry to compress
|
|
42
|
+
* @param data - Buffer containing data to compress
|
|
43
|
+
* @param options - Compression options
|
|
44
|
+
* @param onOutputBuffer - Optional callback for streaming output
|
|
45
|
+
* @returns Buffer containing compressed data
|
|
46
|
+
*/
|
|
47
|
+
compressData(entry: ZipEntry, data: Buffer, options?: CompressOptions, onOutputBuffer?: (data: Buffer) => Promise<void>): Promise<Buffer>;
|
|
48
|
+
/**
|
|
49
|
+
* Compress data using deflate algorithm with chunked processing
|
|
50
|
+
* @param data - Data to compress (Buffer or chunked reader)
|
|
51
|
+
* @param options - Compression options
|
|
52
|
+
* @param bufferSize - Buffer size for chunked processing
|
|
53
|
+
* @param entry - ZIP entry being compressed
|
|
54
|
+
* @param onOutputBuffer - Optional callback for streaming output
|
|
55
|
+
* @returns Buffer containing compressed data
|
|
56
|
+
*/
|
|
57
|
+
deflateCompress(data: Buffer | {
|
|
58
|
+
totalSize: number;
|
|
59
|
+
onReadChunk: (position: number, size: number) => Buffer;
|
|
60
|
+
onOutChunk: (chunk: Buffer) => void;
|
|
61
|
+
}, options?: CompressOptions, bufferSize?: number, entry?: ZipEntry, onOutputBuffer?: (data: Buffer) => Promise<void>): Promise<Buffer>;
|
|
62
|
+
/**
|
|
63
|
+
* Compress data using deflate algorithm (synchronous, small buffers only)
|
|
64
|
+
* @param inbuf - Buffer containing data to compress
|
|
65
|
+
* @param options - Compression options
|
|
66
|
+
* @returns Buffer containing compressed data
|
|
67
|
+
*/
|
|
68
|
+
deflate(inbuf: Buffer, options?: CompressOptions): Buffer;
|
|
69
|
+
/**
|
|
70
|
+
* Compress data using Zstandard (zstd) algorithm
|
|
71
|
+
* @param input - Input data to compress (Buffer or chunked reader)
|
|
72
|
+
* @param options - Compression options
|
|
73
|
+
* @param bufferSize - Buffer size for chunked processing
|
|
74
|
+
* @param entry - ZIP entry being compressed
|
|
75
|
+
* @param onOutputBuffer - Optional callback for streaming output
|
|
76
|
+
* @returns Buffer containing compressed data
|
|
77
|
+
*/
|
|
78
|
+
zstdCompress(input: Buffer | {
|
|
79
|
+
totalSize: number;
|
|
80
|
+
readChunk: (position: number, size: number) => Buffer;
|
|
81
|
+
}, options?: CompressOptions, bufferSize?: number, entry?: ZipEntry, onOutputBuffer?: (data: Buffer) => Promise<void>): Promise<Buffer>;
|
|
82
|
+
/**
|
|
83
|
+
* Encrypt compressed data using PKZIP encryption
|
|
84
|
+
* @param entry - ZIP entry to encrypt
|
|
85
|
+
* @param compressedData - Compressed data to encrypt
|
|
86
|
+
* @param password - Password for encryption
|
|
87
|
+
* @returns Buffer containing encrypted data (includes 12-byte header)
|
|
88
|
+
*/
|
|
89
|
+
encryptCompressedData(entry: ZipEntry, compressedData: Buffer, password: string): Buffer;
|
|
90
|
+
/**
|
|
91
|
+
* Compress file data in memory and return ZIP entry information as Buffer
|
|
92
|
+
* @param entry - ZIP entry to compress
|
|
93
|
+
* @param fileData - File data buffer to compress
|
|
94
|
+
* @param cmpOptions - Compression options
|
|
95
|
+
* @returns Buffer containing local header + compressed data
|
|
96
|
+
*/
|
|
97
|
+
compressFileBuffer(entry: ZipEntry, fileData: Buffer, cmpOptions?: CompressOptions): Promise<Buffer>;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=ZipCompress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZipCompress.d.ts","sourceRoot":"","sources":["../../src/core/ZipCompress.ts"],"names":[],"mappings":"AAiBA,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,OAAO,QAAQ,MAAM,YAAY,CAAC;AAiBlC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACxD,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAClD;AAED;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAU;IAGvB,OAAO,CAAC,MAAM,CAA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CAAC;IAgDlB;;;;;;OAMG;IACH,qBAAqB,CAAC,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAWxF;;;;;;OAMG;IACG,kBAAkB,CACtB,KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,eAAe,GAC3B,OAAO,CAAC,MAAM,CAAC;CAgCnB"}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ======================================
|
|
3
|
+
// ZipkitCompress.ts - Compression Module
|
|
4
|
+
// Copyright (c) 2025 NeoWare, Inc. All rights reserved.
|
|
5
|
+
// ======================================
|
|
6
|
+
//
|
|
7
|
+
// LOGGING INSTRUCTIONS:
|
|
8
|
+
// ---------------------
|
|
9
|
+
// To enable/disable logging, set loggingEnabled to true/false in the class:
|
|
10
|
+
// private static loggingEnabled: boolean = true; // Enable logging
|
|
11
|
+
// private static loggingEnabled: boolean = false; // Disable logging
|
|
12
|
+
//
|
|
13
|
+
// Logging respects the global Logger level (debug, info, warn, error, silent).
|
|
14
|
+
// Logger level is automatically set to 'debug' when loggingEnabled is true.
|
|
15
|
+
//
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.ZipCompress = void 0;
|
|
18
|
+
const pako = require('pako');
|
|
19
|
+
const zstd_js_1 = require("@oneidentity/zstd-js");
|
|
20
|
+
const Logger_1 = require("./components/Logger");
|
|
21
|
+
const Headers_1 = require("./constants/Headers");
|
|
22
|
+
const HashCalculator_1 = require("./components/HashCalculator");
|
|
23
|
+
const ZipCrypto_1 = require("./encryption/ZipCrypto");
|
|
24
|
+
// We'll initialize zstd when needed
|
|
25
|
+
let zstdCodec = null;
|
|
26
|
+
// Async initialization function for zstd
|
|
27
|
+
async function initZstd() {
|
|
28
|
+
if (!zstdCodec) {
|
|
29
|
+
zstdCodec = await (0, zstd_js_1.ZstdInit)();
|
|
30
|
+
}
|
|
31
|
+
return zstdCodec;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Compression handler for ZIP files
|
|
35
|
+
* Supports Deflate, Zstandard, and Store methods
|
|
36
|
+
*/
|
|
37
|
+
class ZipCompress {
|
|
38
|
+
/**
|
|
39
|
+
* Internal logging method - only logs if class logging is enabled
|
|
40
|
+
*/
|
|
41
|
+
log(...args) {
|
|
42
|
+
if (ZipCompress.loggingEnabled) {
|
|
43
|
+
Logger_1.Logger.debug(`[ZipCompress]`, ...args);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new ZipCompress instance
|
|
48
|
+
* @param zipkit - Zipkit instance to use for ZIP operations
|
|
49
|
+
*/
|
|
50
|
+
constructor(zipkit) {
|
|
51
|
+
this.zipkit = zipkit;
|
|
52
|
+
// Debug disabled by default (controlled by class-level logging)
|
|
53
|
+
this.debug = false;
|
|
54
|
+
// If logging is enabled, ensure Logger level is set to debug
|
|
55
|
+
if (ZipCompress.loggingEnabled) {
|
|
56
|
+
Logger_1.Logger.setLevel('debug');
|
|
57
|
+
}
|
|
58
|
+
this.log(`ZipCompress initialized`);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Compresses data for a ZIP entry (Buffer-based only)
|
|
62
|
+
* @param entry - ZIP entry to compress
|
|
63
|
+
* @param data - Buffer containing data to compress
|
|
64
|
+
* @param options - Compression options
|
|
65
|
+
* @param onOutputBuffer - Optional callback for streaming output
|
|
66
|
+
* @returns Buffer containing compressed data
|
|
67
|
+
*/
|
|
68
|
+
async compressData(entry, data, options, onOutputBuffer) {
|
|
69
|
+
this.log(`compressData() called for entry: ${entry.filename}`);
|
|
70
|
+
// Set uncompressed size if not already set
|
|
71
|
+
if (!entry.uncompressedSize || entry.uncompressedSize === 0) {
|
|
72
|
+
entry.uncompressedSize = data.length;
|
|
73
|
+
}
|
|
74
|
+
const totalSize = data.length;
|
|
75
|
+
const bufferSize = options?.bufferSize || this.zipkit.getBufferSize(); // Use Zipkit's bufferSize
|
|
76
|
+
this.log(`Compressing ${totalSize} bytes for entry: ${entry.filename}`);
|
|
77
|
+
this.log(`Compression options:`, { level: options?.level, useZstd: options?.useZstd, bufferSize });
|
|
78
|
+
// Determine compression method
|
|
79
|
+
let compressionMethod;
|
|
80
|
+
if (options?.level === 0) {
|
|
81
|
+
compressionMethod = Headers_1.CMP_METHOD.STORED;
|
|
82
|
+
this.log(`Using STORED method (no compression)`);
|
|
83
|
+
}
|
|
84
|
+
else if (options?.useZstd) {
|
|
85
|
+
// ZSTD fallback to STORED if file too small
|
|
86
|
+
if (totalSize < 100) {
|
|
87
|
+
compressionMethod = Headers_1.CMP_METHOD.STORED;
|
|
88
|
+
this.log(`ZSTD fallback to STORED (file too small: ${totalSize} bytes)`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
compressionMethod = Headers_1.CMP_METHOD.ZSTD;
|
|
92
|
+
this.log(`Using ZSTD method (zstd compression)`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
compressionMethod = Headers_1.CMP_METHOD.DEFLATED;
|
|
97
|
+
this.log(`Using DEFLATED method (default compression)`);
|
|
98
|
+
}
|
|
99
|
+
entry.cmpMethod = compressionMethod;
|
|
100
|
+
// Initialize hash calculator
|
|
101
|
+
const needsHashCalculation = (!entry.crc || entry.crc === 0) || (options?.useSHA256 && !entry.sha256);
|
|
102
|
+
const hashCalculator = needsHashCalculation ? new HashCalculator_1.HashCalculator({ useSHA256: options?.useSHA256 && !entry.sha256 || false }) : null;
|
|
103
|
+
// Calculate hashes if needed
|
|
104
|
+
if (hashCalculator) {
|
|
105
|
+
hashCalculator.update(data);
|
|
106
|
+
if (!entry.crc || entry.crc === 0) {
|
|
107
|
+
entry.crc = hashCalculator.finalizeCRC32();
|
|
108
|
+
}
|
|
109
|
+
if (options?.useSHA256 && !entry.sha256) {
|
|
110
|
+
entry.sha256 = hashCalculator.finalizeSHA256();
|
|
111
|
+
}
|
|
112
|
+
this.log(`Final hashes: CRC32=0x${entry.crc.toString(16).padStart(8, '0')}, SHA256=${entry.sha256 || 'N/A'}`);
|
|
113
|
+
}
|
|
114
|
+
// Encrypt if password provided
|
|
115
|
+
if (options?.password) {
|
|
116
|
+
this.log(`Encrypting compressed data for entry: ${entry.filename}`);
|
|
117
|
+
entry.gpFlag = (entry.gpFlag || 0) | Headers_1.GP_FLAG.ENCRYPTED;
|
|
118
|
+
entry.isEncrypted = true;
|
|
119
|
+
}
|
|
120
|
+
// Compress data based on method
|
|
121
|
+
let compressedData;
|
|
122
|
+
const methodName = compressionMethod === Headers_1.CMP_METHOD.ZSTD ? 'ZSTD' : compressionMethod === Headers_1.CMP_METHOD.DEFLATED ? 'DEFLATED' : 'STORED';
|
|
123
|
+
if (compressionMethod === Headers_1.CMP_METHOD.STORED) {
|
|
124
|
+
compressedData = data;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
this.log(`Processing sequence for ${methodName}: [HASH] -> [COMPRESS] -> [OUTPUT]`);
|
|
128
|
+
this.log(`Compressing: method=${methodName}, input=${totalSize} bytes, buffer size=${bufferSize} bytes`);
|
|
129
|
+
this.log(`Calculating hashes: CRC32=${!entry.crc || entry.crc === 0}, SHA256=${options?.useSHA256}`);
|
|
130
|
+
if (compressionMethod === Headers_1.CMP_METHOD.ZSTD) {
|
|
131
|
+
compressedData = await this.zstdCompress(data, options, bufferSize, entry, onOutputBuffer);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
compressedData = await this.deflateCompress(data, options, bufferSize, entry, onOutputBuffer);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Encrypt compressed data if password provided
|
|
138
|
+
if (options?.password) {
|
|
139
|
+
compressedData = this.encryptCompressedData(entry, compressedData, options.password);
|
|
140
|
+
}
|
|
141
|
+
entry.compressedSize = compressedData.length;
|
|
142
|
+
return compressedData;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Compress data using deflate algorithm with chunked processing
|
|
146
|
+
* @param data - Data to compress (Buffer or chunked reader)
|
|
147
|
+
* @param options - Compression options
|
|
148
|
+
* @param bufferSize - Buffer size for chunked processing
|
|
149
|
+
* @param entry - ZIP entry being compressed
|
|
150
|
+
* @param onOutputBuffer - Optional callback for streaming output
|
|
151
|
+
* @returns Buffer containing compressed data
|
|
152
|
+
*/
|
|
153
|
+
async deflateCompress(data, options, bufferSize, entry, onOutputBuffer) {
|
|
154
|
+
this.log(`deflateCompress() called - entry: ${entry?.filename ?? 'unknown'}, bufferSize: ${bufferSize}, level: ${options?.level ?? 6}`);
|
|
155
|
+
const effectiveBufferSize = bufferSize || this.zipkit.getBufferSize();
|
|
156
|
+
const level = options?.level ?? 6;
|
|
157
|
+
// Handle chunked reader
|
|
158
|
+
if (typeof data === 'object' && 'totalSize' in data && 'onReadChunk' in data) {
|
|
159
|
+
// Chunked reader mode - not implemented in simplified version
|
|
160
|
+
throw new Error('Chunked reader mode not supported in ZipCompress');
|
|
161
|
+
}
|
|
162
|
+
// For small data, use synchronous deflate
|
|
163
|
+
if (data.length <= effectiveBufferSize) {
|
|
164
|
+
return this.deflate(data, options);
|
|
165
|
+
}
|
|
166
|
+
// For large data, use chunked deflate
|
|
167
|
+
const deflator = new pako.Deflate({ level, raw: true });
|
|
168
|
+
const compressedChunks = [];
|
|
169
|
+
let totalProcessed = 0;
|
|
170
|
+
let totalCompressedSize = 0;
|
|
171
|
+
try {
|
|
172
|
+
// Process data in chunks
|
|
173
|
+
for (let offset = 0; offset < data.length; offset += effectiveBufferSize) {
|
|
174
|
+
const chunk = data.slice(offset, offset + effectiveBufferSize);
|
|
175
|
+
const isLast = offset + effectiveBufferSize >= data.length;
|
|
176
|
+
deflator.push(chunk, isLast);
|
|
177
|
+
// Collect compressed chunks
|
|
178
|
+
if (deflator.result && deflator.result.length > 0) {
|
|
179
|
+
const compressedChunk = Buffer.from(deflator.result);
|
|
180
|
+
compressedChunks.push(compressedChunk);
|
|
181
|
+
totalCompressedSize += compressedChunk.length;
|
|
182
|
+
// Stream output if callback provided
|
|
183
|
+
if (onOutputBuffer) {
|
|
184
|
+
await onOutputBuffer(compressedChunk);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
totalProcessed += chunk.length;
|
|
188
|
+
}
|
|
189
|
+
// Calculate compression ratio
|
|
190
|
+
const ratio = totalProcessed > 0 ? Math.round((totalCompressedSize / totalProcessed) * 100) : 0;
|
|
191
|
+
this.log(`Final hashes: CRC32=0x${entry?.crc?.toString(16).padStart(8, '0')}, SHA256=${entry?.sha256 || 'N/A'}`);
|
|
192
|
+
this.log(`Deflate compression complete: ${totalCompressedSize} bytes from ${totalProcessed} bytes (ratio=${ratio}%)`);
|
|
193
|
+
return Buffer.concat(compressedChunks);
|
|
194
|
+
}
|
|
195
|
+
catch (e) {
|
|
196
|
+
throw new Error(`Deflate compression failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Compress data using deflate algorithm (synchronous, small buffers only)
|
|
201
|
+
* @param inbuf - Buffer containing data to compress
|
|
202
|
+
* @param options - Compression options
|
|
203
|
+
* @returns Buffer containing compressed data
|
|
204
|
+
*/
|
|
205
|
+
deflate(inbuf, options) {
|
|
206
|
+
this.log(`deflate() called with buffer size: ${inbuf.length}, level: ${options?.level ?? 6}`);
|
|
207
|
+
const level = options?.level ?? 6;
|
|
208
|
+
const result = pako.deflateRaw(inbuf, { level });
|
|
209
|
+
const ratio = inbuf.length > 0 ? Math.round((result.length / inbuf.length) * 100) : 0;
|
|
210
|
+
this.log(`Deflate compression complete: ${result.length} bytes from ${inbuf.length} bytes (ratio=${ratio}%)`);
|
|
211
|
+
return Buffer.from(result.buffer, result.byteOffset, result.byteLength);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Compress data using Zstandard (zstd) algorithm
|
|
215
|
+
* @param input - Input data to compress (Buffer or chunked reader)
|
|
216
|
+
* @param options - Compression options
|
|
217
|
+
* @param bufferSize - Buffer size for chunked processing
|
|
218
|
+
* @param entry - ZIP entry being compressed
|
|
219
|
+
* @param onOutputBuffer - Optional callback for streaming output
|
|
220
|
+
* @returns Buffer containing compressed data
|
|
221
|
+
*/
|
|
222
|
+
async zstdCompress(input, options, bufferSize, entry, onOutputBuffer) {
|
|
223
|
+
this.log(`zstdCompress() called - entry: ${entry?.filename ?? 'unknown'}, bufferSize: ${bufferSize}, level: ${options?.level ?? 6}`);
|
|
224
|
+
const effectiveBufferSize = bufferSize || this.zipkit.getBufferSize();
|
|
225
|
+
const level = options?.level ?? 6;
|
|
226
|
+
// Handle chunked reader
|
|
227
|
+
if (typeof input === 'object' && 'totalSize' in input && 'readChunk' in input) {
|
|
228
|
+
// Chunked reader mode - not implemented in simplified version
|
|
229
|
+
throw new Error('Chunked reader mode not supported in ZipCompress');
|
|
230
|
+
}
|
|
231
|
+
// Lazy ZSTD initialization
|
|
232
|
+
const zstdCodec = await initZstd();
|
|
233
|
+
// Validate input
|
|
234
|
+
if (!input || input.length === 0) {
|
|
235
|
+
throw new Error('ZSTD compression: empty input buffer');
|
|
236
|
+
}
|
|
237
|
+
// Convert Buffer to Uint8Array for WASM module (same fix as decompression)
|
|
238
|
+
const inputArray = new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
239
|
+
// For small data, compress in one go
|
|
240
|
+
if (input.length <= effectiveBufferSize) {
|
|
241
|
+
const compressed = zstdCodec.ZstdSimple.compress(inputArray, level);
|
|
242
|
+
const compressedBuffer = Buffer.from(compressed);
|
|
243
|
+
if (onOutputBuffer) {
|
|
244
|
+
await onOutputBuffer(compressedBuffer);
|
|
245
|
+
}
|
|
246
|
+
return compressedBuffer;
|
|
247
|
+
}
|
|
248
|
+
// For large data, compress in chunks (ZSTD supports streaming)
|
|
249
|
+
// Note: ZSTD streaming compression is more complex, so for now we compress the whole buffer
|
|
250
|
+
// This could be optimized in the future for true streaming
|
|
251
|
+
const compressed = zstdCodec.ZstdSimple.compress(inputArray, level);
|
|
252
|
+
const compressedBuffer = Buffer.from(compressed);
|
|
253
|
+
if (onOutputBuffer) {
|
|
254
|
+
await onOutputBuffer(compressedBuffer);
|
|
255
|
+
}
|
|
256
|
+
return compressedBuffer;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Encrypt compressed data using PKZIP encryption
|
|
260
|
+
* @param entry - ZIP entry to encrypt
|
|
261
|
+
* @param compressedData - Compressed data to encrypt
|
|
262
|
+
* @param password - Password for encryption
|
|
263
|
+
* @returns Buffer containing encrypted data (includes 12-byte header)
|
|
264
|
+
*/
|
|
265
|
+
encryptCompressedData(entry, compressedData, password) {
|
|
266
|
+
this.log(`encryptCompressedData() called for entry: ${entry.filename}, compressed size: ${compressedData.length}`);
|
|
267
|
+
const zipCrypto = new ZipCrypto_1.ZipCrypto();
|
|
268
|
+
const encryptedData = zipCrypto.encryptBuffer(entry, compressedData, password);
|
|
269
|
+
this.log(`Encryption complete: ${compressedData.length} bytes compressed -> ${encryptedData.length} bytes encrypted (includes ${Headers_1.ENCRYPT_HDR_SIZE}-byte header)`);
|
|
270
|
+
return encryptedData;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Compress file data in memory and return ZIP entry information as Buffer
|
|
274
|
+
* @param entry - ZIP entry to compress
|
|
275
|
+
* @param fileData - File data buffer to compress
|
|
276
|
+
* @param cmpOptions - Compression options
|
|
277
|
+
* @returns Buffer containing local header + compressed data
|
|
278
|
+
*/
|
|
279
|
+
async compressFileBuffer(entry, fileData, cmpOptions) {
|
|
280
|
+
this.log(`compressFileBuffer() called for entry: ${entry.filename}, size: ${fileData.length}`);
|
|
281
|
+
// Set uncompressed size
|
|
282
|
+
entry.uncompressedSize = fileData.length;
|
|
283
|
+
// Initialize hash calculator
|
|
284
|
+
const hashCalculator = new HashCalculator_1.HashCalculator({ useSHA256: cmpOptions?.useSHA256 || false });
|
|
285
|
+
hashCalculator.update(fileData);
|
|
286
|
+
// Set hashes
|
|
287
|
+
entry.crc = hashCalculator.finalizeCRC32();
|
|
288
|
+
if (cmpOptions?.useSHA256) {
|
|
289
|
+
entry.sha256 = hashCalculator.finalizeSHA256();
|
|
290
|
+
this.log(`SHA-256 calculated: ${entry.sha256}`);
|
|
291
|
+
}
|
|
292
|
+
// Compress data
|
|
293
|
+
const compressedData = await this.compressData(entry, fileData, cmpOptions);
|
|
294
|
+
// Encrypt if password provided
|
|
295
|
+
if (cmpOptions?.password) {
|
|
296
|
+
this.log(`Encrypting compressed data for entry: ${entry.filename}`);
|
|
297
|
+
entry.gpFlag = (entry.gpFlag || 0) | Headers_1.GP_FLAG.ENCRYPTED;
|
|
298
|
+
entry.isEncrypted = true;
|
|
299
|
+
const zipCrypto = new ZipCrypto_1.ZipCrypto();
|
|
300
|
+
const encryptedData = zipCrypto.encryptBuffer(entry, compressedData, cmpOptions.password);
|
|
301
|
+
return encryptedData;
|
|
302
|
+
}
|
|
303
|
+
return compressedData;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
exports.ZipCompress = ZipCompress;
|
|
307
|
+
// Class-level logging control - set to true to enable logging
|
|
308
|
+
ZipCompress.loggingEnabled = false;
|
|
309
|
+
//# sourceMappingURL=ZipCompress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZipCompress.js","sourceRoot":"","sources":["../../src/core/ZipCompress.ts"],"names":[],"mappings":";AAAA,yCAAyC;AACzC,yCAAyC;AACzC,yDAAyD;AACzD,yCAAyC;AACzC,EAAE;AACF,wBAAwB;AACxB,wBAAwB;AACxB,4EAA4E;AAC5E,sEAAsE;AACtE,uEAAuE;AACvE,EAAE;AACF,+EAA+E;AAC/E,4EAA4E;AAC5E,EAAE;;;AAEF,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,kDAA4D;AAE5D,gDAA6C;AAG7C,iDAA4E;AAC5E,gEAA6D;AA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Aa,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,iBAAO,CAAC,SAAS,CAAC;YACxE,KAAa,CAAC,WAAW,GAAG,IAAI,CAAC;YAClC,MAAM,SAAS,GAAG,IAAI,qBAAS,EAAE,CAAC;YAClC,MAAM,aAAa,GAAG,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,cAAc,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;YAC1F,OAAO,aAAa,CAAC;QACvB,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;;AA/UH,kCAgVC;AA5UC,8DAA8D;AAC/C,0BAAc,GAAY,KAAK,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Zipkit from './Zipkit';
|
|
2
|
+
import ZipEntry from './ZipEntry';
|
|
3
|
+
export interface DecompressionResult {
|
|
4
|
+
success: boolean;
|
|
5
|
+
data?: Buffer;
|
|
6
|
+
error?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface DecompressionOptions {
|
|
9
|
+
method: number;
|
|
10
|
+
debug?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* ZipDecompress - Unified Decompression Module (Internal to Zipkit)
|
|
14
|
+
* Consolidates decompression functionality from ZipCompress
|
|
15
|
+
* Supports deflate, zstd, and stored compression methods with chunked processing
|
|
16
|
+
*
|
|
17
|
+
* This class is internal to Zipkit and should not be used directly.
|
|
18
|
+
* Use Zipkit methods instead.
|
|
19
|
+
*/
|
|
20
|
+
declare class ZipDecompress {
|
|
21
|
+
private zipkit;
|
|
22
|
+
private debug;
|
|
23
|
+
private zstdCodec;
|
|
24
|
+
private static loggingEnabled;
|
|
25
|
+
/**
|
|
26
|
+
* Internal logging method - only logs if class logging is enabled
|
|
27
|
+
*/
|
|
28
|
+
private log;
|
|
29
|
+
constructor(zipkit: Zipkit);
|
|
30
|
+
/**
|
|
31
|
+
* Extract file data (Buffer-based ZIP only)
|
|
32
|
+
* Public method that validates buffer mode and extracts entry
|
|
33
|
+
*
|
|
34
|
+
* @param entry ZIP entry to extract
|
|
35
|
+
* @param skipHashCheck Skip hash verification (CRC-32 or SHA-256)
|
|
36
|
+
* @returns Promise resolving to extracted data as Buffer, or null if failed
|
|
37
|
+
* @throws Error if not a Buffer-based ZIP
|
|
38
|
+
*/
|
|
39
|
+
extract(entry: ZipEntry, skipHashCheck?: boolean): Promise<Buffer | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Inflate data using pako (internal use only)
|
|
42
|
+
*/
|
|
43
|
+
private inflate;
|
|
44
|
+
/**
|
|
45
|
+
* Synchronous zstd decompress method for in-memory mode
|
|
46
|
+
* ZSTD codec is guaranteed to be initialized via factory method
|
|
47
|
+
* Internal method only
|
|
48
|
+
*/
|
|
49
|
+
private zstdDecompressSync;
|
|
50
|
+
/**
|
|
51
|
+
* Uncompress compressed data buffer (synchronous for in-memory mode)
|
|
52
|
+
* Handles decompression and hash verification
|
|
53
|
+
* Internal method only
|
|
54
|
+
*/
|
|
55
|
+
private unCompress;
|
|
56
|
+
}
|
|
57
|
+
export default ZipDecompress;
|
|
58
|
+
//# sourceMappingURL=ZipDecompress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZipDecompress.d.ts","sourceRoot":"","sources":["../../src/core/ZipDecompress.ts"],"names":[],"mappings":"AAiBA,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,OAAO,QAAQ,MAAM,YAAY,CAAC;AAKlC,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAaD;;;;;;;GAOG;AACH,cAAM,aAAa;IACjB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAU;IACvB,OAAO,CAAC,SAAS,CAAkD;IAGnE,OAAO,CAAC,MAAM,CAAC,cAAc,CAAkB;IAE/C;;OAEG;IACH,OAAO,CAAC,GAAG;gBAMC,MAAM,EAAE,MAAM;IAU1B;;;;;;;;OAQG;IACG,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,aAAa,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAsC/E;;OAEG;IACH,OAAO,CAAC,OAAO;IAOf;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAiB1B;;;;OAIG;IACH,OAAO,CAAC,UAAU;CA2CnB;AAGD,eAAe,aAAa,CAAC"}
|