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
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ZipKitServer
|
|
3
|
-
* Copyright (c) 2025 NeoWare, Inc. All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* Server-side implementation of ZipKit that passes through all functions
|
|
6
|
-
* directly to the parent ZipKit class. This class provides a consistent interface
|
|
7
|
-
* for server environments and ensures all ZipKit functionality is available.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import * as fs from 'fs';
|
|
11
|
-
import * as path from 'path';
|
|
12
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
13
|
-
import { exit } from 'process';
|
|
14
|
-
|
|
15
|
-
import ZipKit,{ CompressOptions, ZipEntry, TIMESTAMP_METADATA, TIMESTAMP_SUBMITTED, CMP_METHOD } from '../shared/ZipKit';
|
|
16
|
-
import * as Headers from '../shared/constants/Headers';
|
|
17
|
-
import { upgradeOTS as upgradeZipOts, createCertificateOts as createCertificateOtsFile, createOtsMetadataEntry } from '../blockchain/ZipKitOTS';
|
|
18
|
-
|
|
19
|
-
// Re-export everything from ZipKit
|
|
20
|
-
export * from '../shared/ZipKit';
|
|
21
|
-
export { Headers };
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* This implementation is optimized for server environments and handles all
|
|
25
|
-
* ZIP operations including compression, extraction, encryption, and file management.
|
|
26
|
-
*/
|
|
27
|
-
export default class ZipKitServer extends ZipKit {
|
|
28
|
-
/**
|
|
29
|
-
* Creates a new ZipKitServer instance
|
|
30
|
-
*
|
|
31
|
-
* Initializes the parent ZipKit class and logs environment support information
|
|
32
|
-
* for diagnostic purposes.
|
|
33
|
-
*/
|
|
34
|
-
constructor() {
|
|
35
|
-
super(); // Call the parent constructor
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Loads a ZIP file from the filesystem for updating/creating operations
|
|
40
|
-
*
|
|
41
|
-
* Attempts to read an existing ZIP file, but creates a new empty archive if
|
|
42
|
-
* the file doesn't exist. This method is used when adding or updating entries
|
|
43
|
-
* in an archive, handling both new and existing ZIP files gracefully.
|
|
44
|
-
*
|
|
45
|
-
* @param zipFile - Path to the ZIP file to load or create
|
|
46
|
-
*/
|
|
47
|
-
loadZipFile(zipFile: string): void {
|
|
48
|
-
let inBuffer: Buffer | null = null;
|
|
49
|
-
let fdIn: number | null = null;
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
if (fs.existsSync(zipFile)) {
|
|
53
|
-
fdIn = fs.openSync(zipFile, 'r');
|
|
54
|
-
const stats = fs.fstatSync(fdIn);
|
|
55
|
-
inBuffer = Buffer.alloc(stats.size);
|
|
56
|
-
// inBuffer is allocated above; ensure non-null for readSync
|
|
57
|
-
fs.readSync(fdIn, inBuffer as Buffer, 0, stats.size, 0);
|
|
58
|
-
} else {
|
|
59
|
-
// File doesn't exist, use an empty buffer
|
|
60
|
-
inBuffer = Buffer.alloc(0);
|
|
61
|
-
}
|
|
62
|
-
} catch (error) {
|
|
63
|
-
console.log('Warning: Could not open existing file. Creating new archive.');
|
|
64
|
-
inBuffer = Buffer.alloc(0);
|
|
65
|
-
} finally {
|
|
66
|
-
if (fdIn !== null) {
|
|
67
|
-
fs.closeSync(fdIn);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Initialize empty buffer if null
|
|
72
|
-
const buffer: Buffer = inBuffer ?? Buffer.alloc(0);
|
|
73
|
-
super.loadZip(buffer);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Loads a ZIP file from the filesystem for extraction and listing operations
|
|
78
|
-
*
|
|
79
|
-
* Reads an existing ZIP file and throws an error if the file doesn't exist.
|
|
80
|
-
* Use this method when working with existing archives that need to be extracted.
|
|
81
|
-
*
|
|
82
|
-
* @param zipFile - Path to the ZIP file to load
|
|
83
|
-
* @throws Error if the file doesn't exist or can't be read
|
|
84
|
-
*/
|
|
85
|
-
loadUnzipFile(zipFile: string): void {
|
|
86
|
-
try {
|
|
87
|
-
// Check if the file exists before trying to read it
|
|
88
|
-
if (!fs.existsSync(zipFile)) {
|
|
89
|
-
console.error(`Error: Zip file "${zipFile}" does not exist`);
|
|
90
|
-
exit(1);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const inBuffer = fs.readFileSync(zipFile);
|
|
94
|
-
super.loadZip(inBuffer);
|
|
95
|
-
} catch (error) {
|
|
96
|
-
console.error(`Error: Failed to read zip file "${zipFile}"`);
|
|
97
|
-
exit(1);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Adds a single file to the ZIP archive
|
|
103
|
-
* @param filename - Path to the file to be added
|
|
104
|
-
* @param comment - Optional comment for the file entry
|
|
105
|
-
*
|
|
106
|
-
* Handles:
|
|
107
|
-
* - Creating/updating ZipEntry objects
|
|
108
|
-
* - Setting file attributes and timestamps
|
|
109
|
-
* - Respecting freshen (-f) and update (-u) flags
|
|
110
|
-
* - Setting compression method
|
|
111
|
-
*/
|
|
112
|
-
addFile(filename: string, freshen: boolean = false, update: boolean = false): void {
|
|
113
|
-
let entry = super.getZipEntry(filename);
|
|
114
|
-
if (!entry) {
|
|
115
|
-
// Check for Freshen option
|
|
116
|
-
if (freshen) return;
|
|
117
|
-
entry = super.createZipEntry(filename);
|
|
118
|
-
} else if (!update) {
|
|
119
|
-
// Mark this entry as not being updated
|
|
120
|
-
entry.isUpdated = false;
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
entry.platform = process.platform;
|
|
124
|
-
|
|
125
|
-
// Correctly retrieve file stats
|
|
126
|
-
let attr = fs.statSync(filename); // Synchronously get the stats of the file
|
|
127
|
-
|
|
128
|
-
entry.uncompressedSize = attr.size;
|
|
129
|
-
|
|
130
|
-
// Set the DOS file time/date based on the Date stamp of the file.
|
|
131
|
-
const utcDate = new Date(attr.mtime.getTime());
|
|
132
|
-
entry.timeDateDOS = entry.setDateTime(utcDate);
|
|
133
|
-
entry.universalTime = Math.floor(attr.mtime.getTime() / 1000); // Store Unix timestamp
|
|
134
|
-
|
|
135
|
-
// Set Unix UID/GID if on Unix-like system
|
|
136
|
-
if (process.platform !== 'win32') {
|
|
137
|
-
entry.uid = attr.uid;
|
|
138
|
-
entry.gid = attr.gid;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Use attr.mode for file permissions
|
|
142
|
-
entry.isDirectory = attr.isDirectory();
|
|
143
|
-
let _fattr = (attr.mode & 0xfff) | (entry.isDirectory ? 0x4000 : 0x8000);
|
|
144
|
-
entry.extFileAttr = ((_fattr << 16) | (entry.isDirectory ? 0x10 : 0)) >>> 0;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Processes files to be added to the ZIP archive
|
|
149
|
-
* Creates ZipEntry objects for each file and initiates the compression process
|
|
150
|
-
*/
|
|
151
|
-
addFiles(files: string[], freshen: boolean = false, update: boolean = false) {
|
|
152
|
-
let filesAdded = 0;
|
|
153
|
-
for (var i=0; files[i] != undefined; i++) {
|
|
154
|
-
const filename = String(files[i]);
|
|
155
|
-
// Skip arguments that look like options (start with hyphen but aren't files)
|
|
156
|
-
if (filename.startsWith('-') && !fs.existsSync(filename)) {
|
|
157
|
-
console.warn(`Warning: Skipping '${filename}' which appears to be an option, not a file.`);
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
this.addFile(filename, freshen, update);
|
|
162
|
-
filesAdded++;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return filesAdded;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Creates a ZIP file
|
|
170
|
-
*/
|
|
171
|
-
async createZip(zipFile: string, compressOptions: CompressOptions) {
|
|
172
|
-
|
|
173
|
-
// Ensure the directory structure for the output file exists
|
|
174
|
-
const outputDir = path.dirname(zipFile);
|
|
175
|
-
if (!fs.existsSync(outputDir)) {
|
|
176
|
-
fs.mkdirSync(outputDir, { recursive: true });
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Generate a unique temporary file name in the output directory
|
|
180
|
-
const _tempZipFile = path.join(outputDir, `neozip-${uuidv4()}.zip`);
|
|
181
|
-
|
|
182
|
-
// Open or create the .zip file for writing
|
|
183
|
-
const fd = fs.openSync(_tempZipFile, 'w');
|
|
184
|
-
|
|
185
|
-
let offset = await super.createZipFileData(compressOptions, {
|
|
186
|
-
onReadEntryData: (entry: ZipEntry) => {
|
|
187
|
-
try {
|
|
188
|
-
return fs.readFileSync(entry.filename);
|
|
189
|
-
} catch (error) {
|
|
190
|
-
throw new Error(`Failed to read file: ${entry.filename}`);
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
onOutputBuffer: (buffer: Buffer) => {
|
|
194
|
-
fs.writeSync(fd, buffer);
|
|
195
|
-
},
|
|
196
|
-
onEntryDone: (entry: ZipEntry, status: string) => {
|
|
197
|
-
console.log(`${status} ${entry.filename} to ${zipFile}`);
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
// Write the metadata entry to the .zip fi
|
|
202
|
-
await super.finishZipFileData(
|
|
203
|
-
offset,
|
|
204
|
-
function onOutputBuffer(buffer: Buffer) {
|
|
205
|
-
fs.writeSync(fd, buffer);
|
|
206
|
-
},
|
|
207
|
-
undefined
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
// Close the .zip file
|
|
211
|
-
fs.closeSync(fd);
|
|
212
|
-
|
|
213
|
-
// Delete the existing .zip file if it exists
|
|
214
|
-
if (fs.existsSync(zipFile)) {
|
|
215
|
-
fs.unlinkSync(zipFile);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// Replace the existing .zip file with the temporary file
|
|
219
|
-
fs.renameSync(_tempZipFile, zipFile);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Creates a ZIP file with OpenTimestamps (OTS) metadata
|
|
224
|
-
*/
|
|
225
|
-
// async createZipOTS(zipFile: string, compressOptions: CompressOptions) {
|
|
226
|
-
|
|
227
|
-
// // Ensure the directory structure for the output file exists
|
|
228
|
-
// const outputDir = path.dirname(zipFile);
|
|
229
|
-
// if (!fs.existsSync(outputDir)) {
|
|
230
|
-
// fs.mkdirSync(outputDir, { recursive: true });
|
|
231
|
-
// }
|
|
232
|
-
|
|
233
|
-
// // Generate a unique temporary file name in the output directory
|
|
234
|
-
// const _tempZipFile = path.join(outputDir, `neozip-${uuidv4()}.zip`);
|
|
235
|
-
|
|
236
|
-
// // Open or create the .zip file for writing
|
|
237
|
-
// const fd = fs.openSync(_tempZipFile, 'w');
|
|
238
|
-
|
|
239
|
-
// let offset = await super.createZipFileData(compressOptions, {
|
|
240
|
-
// onReadEntryData: (entry: ZipEntry) => {
|
|
241
|
-
// try {
|
|
242
|
-
// return fs.readFileSync(entry.filename);
|
|
243
|
-
// } catch (error) {
|
|
244
|
-
// throw new Error(`Failed to read file: ${entry.filename}`);
|
|
245
|
-
// }
|
|
246
|
-
// },
|
|
247
|
-
// onOutputBuffer: (buffer: Buffer) => {
|
|
248
|
-
// fs.writeSync(fd, buffer);
|
|
249
|
-
// },
|
|
250
|
-
// onEntryDone: (entry: ZipEntry, status: string) => {
|
|
251
|
-
// console.log(`${status} ${entry.filename} to ${zipFile}`);
|
|
252
|
-
// }
|
|
253
|
-
// });
|
|
254
|
-
|
|
255
|
-
// // Timestamp the zip file to the Bitcoin blockchain
|
|
256
|
-
// let _metadataEntry = null;
|
|
257
|
-
|
|
258
|
-
// console.log('Timestamping to Bitcoin blockchain...');
|
|
259
|
-
// const _merkleRoot = super.getMerkleRoot();
|
|
260
|
-
// console.log('Merkle Root: ' + _merkleRoot);
|
|
261
|
-
// const _ots = await createTimestamp(_merkleRoot);
|
|
262
|
-
// _metadataEntry = super.createTimestampMetadataEntry(_ots);
|
|
263
|
-
|
|
264
|
-
// // Write the metadata entry to the .zip fi
|
|
265
|
-
// await super.finishZipFileData(
|
|
266
|
-
// offset,
|
|
267
|
-
// function onOutputBuffer(buffer: Buffer) {
|
|
268
|
-
// fs.writeSync(fd, buffer);
|
|
269
|
-
// },
|
|
270
|
-
// _metadataEntry || undefined
|
|
271
|
-
// );
|
|
272
|
-
|
|
273
|
-
// // Close the .zip file
|
|
274
|
-
// fs.closeSync(fd);
|
|
275
|
-
|
|
276
|
-
// // Delete the existing .zip file if it exists
|
|
277
|
-
// if (fs.existsSync(zipFile)) {
|
|
278
|
-
// fs.unlinkSync(zipFile);
|
|
279
|
-
// }
|
|
280
|
-
|
|
281
|
-
// // Replace the existing .zip file with the temporary file
|
|
282
|
-
// fs.renameSync(_tempZipFile, zipFile);
|
|
283
|
-
// }
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Removes specified files from the ZIP archive
|
|
287
|
-
* Deletes matching ZipEntry objects and rebuilds the archive if any files were removed
|
|
288
|
-
*/
|
|
289
|
-
deleteFiles(delFiles: string[]): number {
|
|
290
|
-
|
|
291
|
-
super.getDirectory();
|
|
292
|
-
let filesDel = 0;
|
|
293
|
-
delFiles.forEach(fname => {
|
|
294
|
-
const deleted = super.deleteFile(fname);
|
|
295
|
-
if (deleted) {
|
|
296
|
-
console.log(' deleting: ' + fname + "\n");
|
|
297
|
-
++filesDel;
|
|
298
|
-
} else {
|
|
299
|
-
console.log(' warning: name not found: ' + fname + "\n");
|
|
300
|
-
}
|
|
301
|
-
})
|
|
302
|
-
|
|
303
|
-
return filesDel;
|
|
304
|
-
}
|
|
305
|
-
}
|