@neoware_inc/neozipkit 0.5.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/README.md +134 -0
- package/dist/browser/ZipkitBrowser.d.ts +27 -0
- package/dist/browser/ZipkitBrowser.d.ts.map +1 -0
- package/dist/browser/ZipkitBrowser.js +303 -0
- package/dist/browser/ZipkitBrowser.js.map +1 -0
- package/dist/browser/index.d.ts +9 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.esm.d.ts +12 -0
- package/dist/browser/index.esm.d.ts.map +1 -0
- package/dist/browser/index.esm.js +46 -0
- package/dist/browser/index.esm.js.map +1 -0
- package/dist/browser/index.js +38 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser-esm/index.d.ts +9 -0
- package/dist/browser-esm/index.js +50211 -0
- package/dist/browser-esm/index.js.map +7 -0
- package/dist/browser-umd/index.d.ts +9 -0
- package/dist/browser-umd/index.js +50221 -0
- package/dist/browser-umd/index.js.map +7 -0
- package/dist/browser-umd/index.min.js +39 -0
- package/dist/browser.d.ts +9 -0
- package/dist/browser.js +38 -0
- package/dist/core/ZipCompress.d.ts +99 -0
- package/dist/core/ZipCompress.d.ts.map +1 -0
- package/dist/core/ZipCompress.js +287 -0
- package/dist/core/ZipCompress.js.map +1 -0
- package/dist/core/ZipCopy.d.ts +175 -0
- package/dist/core/ZipCopy.d.ts.map +1 -0
- package/dist/core/ZipCopy.js +310 -0
- package/dist/core/ZipCopy.js.map +1 -0
- package/dist/core/ZipDecompress.d.ts +57 -0
- package/dist/core/ZipDecompress.d.ts.map +1 -0
- package/dist/core/ZipDecompress.js +155 -0
- package/dist/core/ZipDecompress.js.map +1 -0
- package/dist/core/ZipEntry.d.ts +138 -0
- package/dist/core/ZipEntry.d.ts.map +1 -0
- package/dist/core/ZipEntry.js +829 -0
- 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/ZstdManager.d.ts +56 -0
- package/dist/core/ZstdManager.d.ts.map +1 -0
- package/dist/core/ZstdManager.js +144 -0
- package/dist/core/ZstdManager.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/core/components/Support.d.ts +64 -0
- package/dist/core/components/Support.d.ts.map +1 -0
- package/dist/core/components/Support.js +71 -0
- package/dist/core/components/Support.js.map +1 -0
- package/dist/core/components/Util.d.ts +26 -0
- package/dist/core/components/Util.d.ts.map +1 -0
- package/dist/core/components/Util.js +95 -0
- package/dist/core/components/Util.js.map +1 -0
- package/dist/core/constants/Errors.d.ts +52 -0
- package/dist/core/constants/Errors.d.ts.map +1 -0
- package/dist/core/constants/Errors.js +67 -0
- package/dist/core/constants/Errors.js.map +1 -0
- package/dist/core/constants/Headers.d.ts +170 -0
- package/dist/core/constants/Headers.d.ts.map +1 -0
- package/dist/core/constants/Headers.js +194 -0
- 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 +27 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +59 -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 +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- 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 +565 -0
- package/dist/node/ZipCompressNode.js.map +1 -0
- package/dist/node/ZipCopyNode.d.ts +165 -0
- package/dist/node/ZipCopyNode.d.ts.map +1 -0
- package/dist/node/ZipCopyNode.js +347 -0
- package/dist/node/ZipCopyNode.js.map +1 -0
- package/dist/node/ZipDecompressNode.d.ts +197 -0
- package/dist/node/ZipDecompressNode.d.ts.map +1 -0
- package/dist/node/ZipDecompressNode.js +678 -0
- package/dist/node/ZipDecompressNode.js.map +1 -0
- package/dist/node/ZipkitNode.d.ts +466 -0
- package/dist/node/ZipkitNode.d.ts.map +1 -0
- package/dist/node/ZipkitNode.js +1426 -0
- package/dist/node/ZipkitNode.js.map +1 -0
- package/dist/node/index.d.ts +25 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +54 -0
- package/dist/node/index.js.map +1 -0
- package/dist/types/index.d.ts +45 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/examples/README.md +261 -0
- package/examples/append-data.json +44 -0
- package/examples/copy-zip-append.ts +139 -0
- package/examples/copy-zip.ts +152 -0
- package/examples/create-zip.ts +172 -0
- package/examples/extract-zip.ts +118 -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 +6 -0
- package/examples/test-files/file1.txt +48 -0
- package/examples/test-files/file2.txt +80 -0
- package/examples/tsconfig.json +44 -0
- package/package.json +167 -0
- package/src/browser/ZipkitBrowser.ts +305 -0
- package/src/browser/index.esm.ts +32 -0
- package/src/browser/index.ts +19 -0
- package/src/core/ZipCompress.ts +370 -0
- package/src/core/ZipCopy.ts +434 -0
- package/src/core/ZipDecompress.ts +191 -0
- package/src/core/ZipEntry.ts +917 -0
- package/src/core/Zipkit.ts +794 -0
- package/src/core/ZstdManager.ts +165 -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/core/components/Support.ts +77 -0
- package/src/core/components/Util.ts +91 -0
- package/src/core/constants/Errors.ts +78 -0
- package/src/core/constants/Headers.ts +205 -0
- 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 +42 -0
- package/src/core/version.ts +33 -0
- package/src/index.ts +19 -0
- package/src/node/ZipCompressNode.ts +618 -0
- package/src/node/ZipCopyNode.ts +437 -0
- package/src/node/ZipDecompressNode.ts +793 -0
- package/src/node/ZipkitNode.ts +1706 -0
- package/src/node/index.ts +40 -0
- package/src/types/index.ts +68 -0
- package/src/types/modules.d.ts +22 -0
- package/src/types/opentimestamps.d.ts +1 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./core";
|
|
2
|
+
import Zipkit from "./core";
|
|
3
|
+
export default Zipkit;
|
|
4
|
+
export { default as ZipkitBrowser } from "./browser/ZipkitBrowser";
|
|
5
|
+
export declare const PlatformUtils: {
|
|
6
|
+
isBrowser: boolean;
|
|
7
|
+
isNode: string | false;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// =============================================================================
|
|
3
|
+
// NeoZipkit - Browser-Only Package Exports
|
|
4
|
+
// =============================================================================
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
20
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.PlatformUtils = 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;
|
|
28
|
+
// Browser-only exports
|
|
29
|
+
var ZipkitBrowser_1 = require("./browser/ZipkitBrowser");
|
|
30
|
+
Object.defineProperty(exports, "ZipkitBrowser", { enumerable: true, get: function () { return __importDefault(ZipkitBrowser_1).default; } });
|
|
31
|
+
// Platform-specific conditional exports
|
|
32
|
+
exports.PlatformUtils = {
|
|
33
|
+
// Browser detection
|
|
34
|
+
isBrowser: typeof window !== 'undefined' && typeof document !== 'undefined',
|
|
35
|
+
// Node.js detection
|
|
36
|
+
isNode: typeof process !== 'undefined' && process.versions && process.versions.node,
|
|
37
|
+
};
|
|
38
|
+
//# 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;AAMlC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,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AC,GAC/C,OAAO,CAAC,MAAM,CAAC;IAyDlB;;;;;OAKG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,MAAM;IASzD;;;;;;;;OAQG;IACG,YAAY,CAChB,KAAK,EAAE,MAAM,GAAG;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;KAAE,EAC5F,OAAO,CAAC,EAAE,eAAe,EACzB,UAAU,CAAC,EAAE,MAAM,EACnB,KAAK,CAAC,EAAE,QAAQ,EAChB,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GAC/C,OAAO,CAAC,MAAM,CAAC;IA+BlB;;;;;;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,287 @@
|
|
|
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 ZstdManager_1 = require("./ZstdManager");
|
|
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
|
+
/**
|
|
25
|
+
* Compression handler for ZIP files
|
|
26
|
+
* Supports Deflate, Zstandard, and Store methods
|
|
27
|
+
*/
|
|
28
|
+
class ZipCompress {
|
|
29
|
+
/**
|
|
30
|
+
* Internal logging method - only logs if class logging is enabled
|
|
31
|
+
*/
|
|
32
|
+
log(...args) {
|
|
33
|
+
if (ZipCompress.loggingEnabled) {
|
|
34
|
+
Logger_1.Logger.debug(`[ZipCompress]`, ...args);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new ZipCompress instance
|
|
39
|
+
* @param zipkit - Zipkit instance to use for ZIP operations
|
|
40
|
+
*/
|
|
41
|
+
constructor(zipkit) {
|
|
42
|
+
this.zipkit = zipkit;
|
|
43
|
+
// Debug disabled by default (controlled by class-level logging)
|
|
44
|
+
this.debug = false;
|
|
45
|
+
// If logging is enabled, ensure Logger level is set to debug
|
|
46
|
+
if (ZipCompress.loggingEnabled) {
|
|
47
|
+
Logger_1.Logger.setLevel('debug');
|
|
48
|
+
}
|
|
49
|
+
this.log(`ZipCompress initialized`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Compresses data for a ZIP entry (Buffer-based only)
|
|
53
|
+
* @param entry - ZIP entry to compress
|
|
54
|
+
* @param data - Buffer containing data to compress
|
|
55
|
+
* @param options - Compression options
|
|
56
|
+
* @param onOutputBuffer - Optional callback for streaming output
|
|
57
|
+
* @returns Buffer containing compressed data
|
|
58
|
+
*/
|
|
59
|
+
async compressData(entry, data, options, onOutputBuffer) {
|
|
60
|
+
this.log(`compressData() called for entry: ${entry.filename}`);
|
|
61
|
+
// Set uncompressed size if not already set
|
|
62
|
+
if (!entry.uncompressedSize || entry.uncompressedSize === 0) {
|
|
63
|
+
entry.uncompressedSize = data.length;
|
|
64
|
+
}
|
|
65
|
+
const totalSize = data.length;
|
|
66
|
+
const bufferSize = options?.bufferSize || this.zipkit.getBufferSize(); // Use Zipkit's bufferSize
|
|
67
|
+
this.log(`Compressing ${totalSize} bytes for entry: ${entry.filename}`);
|
|
68
|
+
this.log(`Compression options:`, { level: options?.level, useZstd: options?.useZstd, bufferSize });
|
|
69
|
+
// Determine compression method
|
|
70
|
+
let compressionMethod;
|
|
71
|
+
if (options?.level === 0) {
|
|
72
|
+
compressionMethod = Headers_1.CMP_METHOD.STORED;
|
|
73
|
+
this.log(`Using STORED method (no compression)`);
|
|
74
|
+
}
|
|
75
|
+
else if (options?.useZstd) {
|
|
76
|
+
// ZSTD fallback to STORED if file too small
|
|
77
|
+
if (totalSize < 100) {
|
|
78
|
+
compressionMethod = Headers_1.CMP_METHOD.STORED;
|
|
79
|
+
this.log(`ZSTD fallback to STORED (file too small: ${totalSize} bytes)`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
compressionMethod = Headers_1.CMP_METHOD.ZSTD;
|
|
83
|
+
this.log(`Using ZSTD method (zstd compression)`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
compressionMethod = Headers_1.CMP_METHOD.DEFLATED;
|
|
88
|
+
this.log(`Using DEFLATED method (default compression)`);
|
|
89
|
+
}
|
|
90
|
+
entry.cmpMethod = compressionMethod;
|
|
91
|
+
// Initialize hash calculator
|
|
92
|
+
const needsHashCalculation = (!entry.crc || entry.crc === 0) || (options?.useSHA256 && !entry.sha256);
|
|
93
|
+
const hashCalculator = needsHashCalculation ? new HashCalculator_1.HashCalculator({ useSHA256: options?.useSHA256 && !entry.sha256 || false }) : null;
|
|
94
|
+
// Calculate hashes if needed
|
|
95
|
+
if (hashCalculator) {
|
|
96
|
+
hashCalculator.update(data);
|
|
97
|
+
if (!entry.crc || entry.crc === 0) {
|
|
98
|
+
entry.crc = hashCalculator.finalizeCRC32();
|
|
99
|
+
}
|
|
100
|
+
if (options?.useSHA256 && !entry.sha256) {
|
|
101
|
+
entry.sha256 = hashCalculator.finalizeSHA256();
|
|
102
|
+
}
|
|
103
|
+
this.log(`Final hashes: CRC32=0x${entry.crc.toString(16).padStart(8, '0')}, SHA256=${entry.sha256 || 'N/A'}`);
|
|
104
|
+
}
|
|
105
|
+
// Encrypt if password provided
|
|
106
|
+
if (options?.password) {
|
|
107
|
+
this.log(`Encrypting compressed data for entry: ${entry.filename}`);
|
|
108
|
+
entry.gpFlag = (entry.gpFlag || 0) | Headers_1.GP_FLAG.ENCRYPTED;
|
|
109
|
+
entry.isEncrypted = true;
|
|
110
|
+
}
|
|
111
|
+
// Compress data based on method
|
|
112
|
+
let compressedData;
|
|
113
|
+
const methodName = compressionMethod === Headers_1.CMP_METHOD.ZSTD ? 'ZSTD' : compressionMethod === Headers_1.CMP_METHOD.DEFLATED ? 'DEFLATED' : 'STORED';
|
|
114
|
+
if (compressionMethod === Headers_1.CMP_METHOD.STORED) {
|
|
115
|
+
compressedData = data;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
this.log(`Processing sequence for ${methodName}: [HASH] -> [COMPRESS] -> [OUTPUT]`);
|
|
119
|
+
this.log(`Compressing: method=${methodName}, input=${totalSize} bytes, buffer size=${bufferSize} bytes`);
|
|
120
|
+
this.log(`Calculating hashes: CRC32=${!entry.crc || entry.crc === 0}, SHA256=${options?.useSHA256}`);
|
|
121
|
+
if (compressionMethod === Headers_1.CMP_METHOD.ZSTD) {
|
|
122
|
+
compressedData = await this.zstdCompress(data, options, bufferSize, entry, onOutputBuffer);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
compressedData = await this.deflateCompress(data, options, bufferSize, entry, onOutputBuffer);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
// Encrypt compressed data if password provided
|
|
129
|
+
if (options?.password) {
|
|
130
|
+
compressedData = this.encryptCompressedData(entry, compressedData, options.password);
|
|
131
|
+
}
|
|
132
|
+
entry.compressedSize = compressedData.length;
|
|
133
|
+
return compressedData;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Compress data using deflate algorithm with chunked processing
|
|
137
|
+
* @param data - Data to compress (Buffer or chunked reader)
|
|
138
|
+
* @param options - Compression options
|
|
139
|
+
* @param bufferSize - Buffer size for chunked processing
|
|
140
|
+
* @param entry - ZIP entry being compressed
|
|
141
|
+
* @param onOutputBuffer - Optional callback for streaming output
|
|
142
|
+
* @returns Buffer containing compressed data
|
|
143
|
+
*/
|
|
144
|
+
async deflateCompress(data, options, bufferSize, entry, onOutputBuffer) {
|
|
145
|
+
this.log(`deflateCompress() called - entry: ${entry?.filename ?? 'unknown'}, bufferSize: ${bufferSize}, level: ${options?.level ?? 6}`);
|
|
146
|
+
const effectiveBufferSize = bufferSize || this.zipkit.getBufferSize();
|
|
147
|
+
const level = options?.level ?? 6;
|
|
148
|
+
// Handle chunked reader
|
|
149
|
+
if (typeof data === 'object' && 'totalSize' in data && 'onReadChunk' in data) {
|
|
150
|
+
// Chunked reader mode - not implemented in simplified version
|
|
151
|
+
throw new Error('Chunked reader mode not supported in ZipCompress');
|
|
152
|
+
}
|
|
153
|
+
// For small data, use synchronous deflate
|
|
154
|
+
if (data.length <= effectiveBufferSize) {
|
|
155
|
+
return this.deflate(data, options);
|
|
156
|
+
}
|
|
157
|
+
// For large data, use chunked deflate
|
|
158
|
+
const deflator = new pako.Deflate({ level, raw: true });
|
|
159
|
+
const compressedChunks = [];
|
|
160
|
+
let totalProcessed = 0;
|
|
161
|
+
let totalCompressedSize = 0;
|
|
162
|
+
try {
|
|
163
|
+
// Process data in chunks
|
|
164
|
+
for (let offset = 0; offset < data.length; offset += effectiveBufferSize) {
|
|
165
|
+
const chunk = data.slice(offset, offset + effectiveBufferSize);
|
|
166
|
+
const isLast = offset + effectiveBufferSize >= data.length;
|
|
167
|
+
deflator.push(chunk, isLast);
|
|
168
|
+
// Collect compressed chunks
|
|
169
|
+
if (deflator.result && deflator.result.length > 0) {
|
|
170
|
+
const compressedChunk = Buffer.from(deflator.result);
|
|
171
|
+
compressedChunks.push(compressedChunk);
|
|
172
|
+
totalCompressedSize += compressedChunk.length;
|
|
173
|
+
// Stream output if callback provided
|
|
174
|
+
if (onOutputBuffer) {
|
|
175
|
+
await onOutputBuffer(compressedChunk);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
totalProcessed += chunk.length;
|
|
179
|
+
}
|
|
180
|
+
// Calculate compression ratio
|
|
181
|
+
const ratio = totalProcessed > 0 ? Math.round((totalCompressedSize / totalProcessed) * 100) : 0;
|
|
182
|
+
this.log(`Final hashes: CRC32=0x${entry?.crc?.toString(16).padStart(8, '0')}, SHA256=${entry?.sha256 || 'N/A'}`);
|
|
183
|
+
this.log(`Deflate compression complete: ${totalCompressedSize} bytes from ${totalProcessed} bytes (ratio=${ratio}%)`);
|
|
184
|
+
return Buffer.concat(compressedChunks);
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
throw new Error(`Deflate compression failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Compress data using deflate algorithm (synchronous, small buffers only)
|
|
192
|
+
* @param inbuf - Buffer containing data to compress
|
|
193
|
+
* @param options - Compression options
|
|
194
|
+
* @returns Buffer containing compressed data
|
|
195
|
+
*/
|
|
196
|
+
deflate(inbuf, options) {
|
|
197
|
+
this.log(`deflate() called with buffer size: ${inbuf.length}, level: ${options?.level ?? 6}`);
|
|
198
|
+
const level = options?.level ?? 6;
|
|
199
|
+
const result = pako.deflateRaw(inbuf, { level });
|
|
200
|
+
const ratio = inbuf.length > 0 ? Math.round((result.length / inbuf.length) * 100) : 0;
|
|
201
|
+
this.log(`Deflate compression complete: ${result.length} bytes from ${inbuf.length} bytes (ratio=${ratio}%)`);
|
|
202
|
+
return Buffer.from(result.buffer, result.byteOffset, result.byteLength);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Compress data using Zstandard (zstd) algorithm
|
|
206
|
+
* @param input - Input data to compress (Buffer or chunked reader)
|
|
207
|
+
* @param options - Compression options
|
|
208
|
+
* @param bufferSize - Buffer size for chunked processing
|
|
209
|
+
* @param entry - ZIP entry being compressed
|
|
210
|
+
* @param onOutputBuffer - Optional callback for streaming output
|
|
211
|
+
* @returns Buffer containing compressed data
|
|
212
|
+
*/
|
|
213
|
+
async zstdCompress(input, options, bufferSize, entry, onOutputBuffer) {
|
|
214
|
+
this.log(`zstdCompress() called - entry: ${entry?.filename ?? 'unknown'}, bufferSize: ${bufferSize}, level: ${options?.level ?? 6}`);
|
|
215
|
+
const effectiveBufferSize = bufferSize || this.zipkit.getBufferSize();
|
|
216
|
+
const level = options?.level ?? 6;
|
|
217
|
+
// Handle chunked reader
|
|
218
|
+
if (typeof input === 'object' && 'totalSize' in input && 'readChunk' in input) {
|
|
219
|
+
// Chunked reader mode - not implemented in simplified version
|
|
220
|
+
throw new Error('Chunked reader mode not supported in ZipCompress');
|
|
221
|
+
}
|
|
222
|
+
// Validate input
|
|
223
|
+
if (!input || input.length === 0) {
|
|
224
|
+
throw new Error('ZSTD compression: empty input buffer');
|
|
225
|
+
}
|
|
226
|
+
// Convert Buffer to Uint8Array for WASM module
|
|
227
|
+
const inputArray = new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
228
|
+
// Use global ZstdManager for compression (handles queuing and initialization)
|
|
229
|
+
const compressed = await ZstdManager_1.ZstdManager.compress(inputArray, level);
|
|
230
|
+
const compressedBuffer = Buffer.from(compressed);
|
|
231
|
+
if (onOutputBuffer) {
|
|
232
|
+
await onOutputBuffer(compressedBuffer);
|
|
233
|
+
}
|
|
234
|
+
return compressedBuffer;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Encrypt compressed data using PKZIP encryption
|
|
238
|
+
* @param entry - ZIP entry to encrypt
|
|
239
|
+
* @param compressedData - Compressed data to encrypt
|
|
240
|
+
* @param password - Password for encryption
|
|
241
|
+
* @returns Buffer containing encrypted data (includes 12-byte header)
|
|
242
|
+
*/
|
|
243
|
+
encryptCompressedData(entry, compressedData, password) {
|
|
244
|
+
this.log(`encryptCompressedData() called for entry: ${entry.filename}, compressed size: ${compressedData.length}`);
|
|
245
|
+
const zipCrypto = new ZipCrypto_1.ZipCrypto();
|
|
246
|
+
const encryptedData = zipCrypto.encryptBuffer(entry, compressedData, password);
|
|
247
|
+
this.log(`Encryption complete: ${compressedData.length} bytes compressed -> ${encryptedData.length} bytes encrypted (includes ${Headers_1.ENCRYPT_HDR_SIZE}-byte header)`);
|
|
248
|
+
return encryptedData;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Compress file data in memory and return ZIP entry information as Buffer
|
|
252
|
+
* @param entry - ZIP entry to compress
|
|
253
|
+
* @param fileData - File data buffer to compress
|
|
254
|
+
* @param cmpOptions - Compression options
|
|
255
|
+
* @returns Buffer containing local header + compressed data
|
|
256
|
+
*/
|
|
257
|
+
async compressFileBuffer(entry, fileData, cmpOptions) {
|
|
258
|
+
this.log(`compressFileBuffer() called for entry: ${entry.filename}, size: ${fileData.length}`);
|
|
259
|
+
// Set uncompressed size
|
|
260
|
+
entry.uncompressedSize = fileData.length;
|
|
261
|
+
// Initialize hash calculator
|
|
262
|
+
const hashCalculator = new HashCalculator_1.HashCalculator({ useSHA256: cmpOptions?.useSHA256 || false });
|
|
263
|
+
hashCalculator.update(fileData);
|
|
264
|
+
// Set hashes
|
|
265
|
+
entry.crc = hashCalculator.finalizeCRC32();
|
|
266
|
+
if (cmpOptions?.useSHA256) {
|
|
267
|
+
entry.sha256 = hashCalculator.finalizeSHA256();
|
|
268
|
+
this.log(`SHA-256 calculated: ${entry.sha256}`);
|
|
269
|
+
}
|
|
270
|
+
// Compress data
|
|
271
|
+
const compressedData = await this.compressData(entry, fileData, cmpOptions);
|
|
272
|
+
// Encrypt if password provided
|
|
273
|
+
if (cmpOptions?.password) {
|
|
274
|
+
this.log(`Encrypting compressed data for entry: ${entry.filename}`);
|
|
275
|
+
entry.gpFlag = (entry.gpFlag || 0) | Headers_1.GP_FLAG.ENCRYPTED;
|
|
276
|
+
entry.isEncrypted = true;
|
|
277
|
+
const zipCrypto = new ZipCrypto_1.ZipCrypto();
|
|
278
|
+
const encryptedData = zipCrypto.encryptBuffer(entry, compressedData, cmpOptions.password);
|
|
279
|
+
return encryptedData;
|
|
280
|
+
}
|
|
281
|
+
return compressedData;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
exports.ZipCompress = ZipCompress;
|
|
285
|
+
// Class-level logging control - set to true to enable logging
|
|
286
|
+
ZipCompress.loggingEnabled = false;
|
|
287
|
+
//# 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,+CAA4C;AAE5C,gDAA6C;AAG7C,iDAA4E;AAC5E,gEAA6D;AAC7D,sDAAmD;AAuBnD;;;GAGG;AACH,MAAa,WAAW;IAOtB;;OAEG;IACK,GAAG,CAAC,GAAG,IAAW;QACxB,IAAI,WAAW,CAAC,cAAc,EAAE,CAAC;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AAM,GAAG,cAAc,CAAC,cAAc,EAAE,CAAC;YAC/C,IAAI,CAAC,GAAG,CAAC,uBAAuB,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QAClD,CAAC;QAED,gBAAgB;QAChB,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;QAE5E,+BAA+B;QAC/B,IAAI,UAAU,EAAE,QAAQ,EAAE,CAAC;YACzB,IAAI,CAAC,GAAG,CAAC,yCAAyC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YACnE,KAAa,CAAC,MAAM,GAAG,CAAE,KAAa,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;;AA9TH,kCA+TC;AA3TC,8DAA8D;AAC/C,0BAAc,GAAY,KAAK,CAAC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import ZipEntry from './ZipEntry';
|
|
2
|
+
import Zipkit from './Zipkit';
|
|
3
|
+
/**
|
|
4
|
+
* Options for copying ZIP files
|
|
5
|
+
*/
|
|
6
|
+
export interface CopyOptions {
|
|
7
|
+
/** Filter function to determine which entries to copy */
|
|
8
|
+
entryFilter?: (entry: ZipEntry) => boolean;
|
|
9
|
+
/** Sort function to reorder entries before copying */
|
|
10
|
+
entrySorter?: (a: ZipEntry, b: ZipEntry) => number;
|
|
11
|
+
/** Whether to preserve the ZIP file comment (default: true) */
|
|
12
|
+
preserveComments?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Result of copying a ZIP file
|
|
16
|
+
*/
|
|
17
|
+
export interface CopyResult {
|
|
18
|
+
/** Information about copied entries */
|
|
19
|
+
entries: Array<{
|
|
20
|
+
filename: string;
|
|
21
|
+
localHeaderOffset: number;
|
|
22
|
+
compressedSize: number;
|
|
23
|
+
}>;
|
|
24
|
+
/** Offset to the start of the central directory */
|
|
25
|
+
centralDirOffset: number;
|
|
26
|
+
/** Total number of entries copied */
|
|
27
|
+
totalEntries: number;
|
|
28
|
+
/** Buffer containing the complete copied ZIP file */
|
|
29
|
+
zipBuffer: Buffer;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Result of copying only ZIP entry data (no central directory or EOCD).
|
|
33
|
+
* Use with writeCentralDirectoryAndEOCD after optionally appending more entry data
|
|
34
|
+
* to build a ZIP that includes both copied and new entries.
|
|
35
|
+
*/
|
|
36
|
+
export interface CopyEntriesOnlyResult {
|
|
37
|
+
/** Buffer containing only entry data (local headers + compressed data); not yet a valid ZIP */
|
|
38
|
+
entryDataBuffer: Buffer;
|
|
39
|
+
/** Offset at which entry data ends; central directory should start here after any new entries are appended (equals entryDataBuffer.length) */
|
|
40
|
+
dataEndOffset: number;
|
|
41
|
+
/** Copied entries with localHdrOffset set for the destination buffer */
|
|
42
|
+
copiedEntries: ZipEntry[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Options for finalizing a ZIP (writing central directory and EOCD)
|
|
46
|
+
*/
|
|
47
|
+
export interface FinalizeZipOptions {
|
|
48
|
+
/** ZIP file comment (default: empty) */
|
|
49
|
+
zipComment?: string;
|
|
50
|
+
/** Offset at which the central directory will start in the final buffer (required for buffer-based finalization; e.g. entryDataBuffer.length) */
|
|
51
|
+
centralDirOffset?: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Efficient ZIP file copying class (Buffer-based)
|
|
55
|
+
*
|
|
56
|
+
* Uses ZipEntry instances directly to copy entries without decompression/recompression.
|
|
57
|
+
* Supports filtering and reordering entries while maintaining ZIP file validity.
|
|
58
|
+
* Works entirely with buffers for in-memory operations.
|
|
59
|
+
*
|
|
60
|
+
* Entry data and the central directory / EOCD are separated so you can append
|
|
61
|
+
* more entry data before finalizing: use copyZipEntriesOnly, append new entry
|
|
62
|
+
* data to the buffer, then call writeCentralDirectoryAndEOCD with all entries
|
|
63
|
+
* and concatenate to form the final ZIP buffer.
|
|
64
|
+
*
|
|
65
|
+
* @example Full copy (one shot)
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const zipCopy = new ZipCopy(zipkit);
|
|
68
|
+
* const result = await zipCopy.copyZipBuffer(sourceZipBuffer, {
|
|
69
|
+
* entryFilter: (entry) => !entry.filename.startsWith('.'),
|
|
70
|
+
* entrySorter: (a, b) => a.filename.localeCompare(b.filename)
|
|
71
|
+
* });
|
|
72
|
+
* // result.zipBuffer contains the complete copied ZIP file
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example Copy then append entries before finalizing
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const { entryDataBuffer, dataEndOffset, copiedEntries } = await zipCopy.copyZipEntriesOnly(sourceZipBuffer);
|
|
78
|
+
* // ... append new entry data (local header + data), collect new ZipEntry[] with localHdrOffset set ...
|
|
79
|
+
* const allEntryData = Buffer.concat([entryDataBuffer, newEntryDataBuffer]);
|
|
80
|
+
* const allEntries = [...copiedEntries, ...newEntries];
|
|
81
|
+
* const centralAndEocd = zipCopy.writeCentralDirectoryAndEOCD(allEntries, {
|
|
82
|
+
* zipComment: '',
|
|
83
|
+
* centralDirOffset: allEntryData.length
|
|
84
|
+
* });
|
|
85
|
+
* const zipBuffer = Buffer.concat([allEntryData, centralAndEocd]);
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare class ZipCopy {
|
|
89
|
+
private zipkit;
|
|
90
|
+
/**
|
|
91
|
+
* Creates a new ZipCopy instance
|
|
92
|
+
* @param zipkit - Zipkit instance to use for ZIP operations
|
|
93
|
+
*/
|
|
94
|
+
constructor(zipkit: Zipkit);
|
|
95
|
+
/**
|
|
96
|
+
* Calculate local header size by reading from buffer
|
|
97
|
+
*
|
|
98
|
+
* Reads the first 30 bytes of the local header to get the exact
|
|
99
|
+
* filename and extra field lengths, ensuring accuracy even when
|
|
100
|
+
* local header differs from central directory.
|
|
101
|
+
*
|
|
102
|
+
* @param sourceBuffer - Buffer containing the source ZIP file
|
|
103
|
+
* @param entry - ZipEntry with localHdrOffset
|
|
104
|
+
* @returns Size of the local header in bytes
|
|
105
|
+
*/
|
|
106
|
+
private calculateLocalHeaderSize;
|
|
107
|
+
/**
|
|
108
|
+
* Copy entry bytes directly from source buffer
|
|
109
|
+
*
|
|
110
|
+
* Copies the local header and compressed data as a single operation.
|
|
111
|
+
*
|
|
112
|
+
* Handles various entry types:
|
|
113
|
+
* - Normal entries: [local header][filename][extra][compressed data]
|
|
114
|
+
* - Encrypted entries: compressedSize includes 12-byte encryption header
|
|
115
|
+
* - Data descriptor entries: [local header][filename][extra][data][data descriptor (16 bytes)]
|
|
116
|
+
*
|
|
117
|
+
* For data descriptor entries, the local header has compressed size = 0,
|
|
118
|
+
* but the actual size is in the central directory (entry.compressedSize).
|
|
119
|
+
*
|
|
120
|
+
* @param sourceBuffer - Buffer containing the source ZIP file
|
|
121
|
+
* @param entry - ZipEntry with source offset information
|
|
122
|
+
* @returns Buffer containing the copied entry (local header + compressed data + data descriptor if present)
|
|
123
|
+
*/
|
|
124
|
+
private copyEntryBytes;
|
|
125
|
+
/**
|
|
126
|
+
* Clone a ZipEntry with a new local header offset
|
|
127
|
+
*
|
|
128
|
+
* Creates a new ZipEntry instance with all properties copied from the source,
|
|
129
|
+
* but with an updated localHdrOffset for the destination buffer.
|
|
130
|
+
*
|
|
131
|
+
* @param entry - Source ZipEntry to clone
|
|
132
|
+
* @param newLocalHdrOffset - New local header offset for the destination
|
|
133
|
+
* @returns New ZipEntry instance with updated offset
|
|
134
|
+
*/
|
|
135
|
+
private cloneEntryWithOffset;
|
|
136
|
+
/**
|
|
137
|
+
* Build central directory and End of Central Directory buffer.
|
|
138
|
+
* Used internally by copyZipBuffer and by writeCentralDirectoryAndEOCD.
|
|
139
|
+
*/
|
|
140
|
+
private buildCentralDirectoryAndEOCDBuffer;
|
|
141
|
+
/**
|
|
142
|
+
* Copy only ZIP entry data from the source buffer (no central directory or EOCD).
|
|
143
|
+
* Use when you want to append more entry data before finalizing. Then call
|
|
144
|
+
* writeCentralDirectoryAndEOCD with all entries (copied + new) and concatenate
|
|
145
|
+
* to form the final ZIP buffer.
|
|
146
|
+
*
|
|
147
|
+
* @param sourceZipBuffer - Buffer containing the source ZIP file
|
|
148
|
+
* @param options - Optional copy options (filtering, sorting)
|
|
149
|
+
* @returns Result with entryDataBuffer and copiedEntries for use when appending and finalizing
|
|
150
|
+
*/
|
|
151
|
+
copyZipEntriesOnly(sourceZipBuffer: Buffer, options?: CopyOptions): Promise<CopyEntriesOnlyResult>;
|
|
152
|
+
/**
|
|
153
|
+
* Build central directory and End of Central Directory buffer for the given entries.
|
|
154
|
+
* Concatenate this with entry data (e.g. from copyZipEntriesOnly + any appended entries)
|
|
155
|
+
* to form a valid ZIP buffer. When concatenating, pass centralDirOffset equal to the
|
|
156
|
+
* length of the entry data buffer that will precede this (so EOCD has the correct offset).
|
|
157
|
+
*
|
|
158
|
+
* @param entries - All entries in order (copied + any new), each with localHdrOffset set
|
|
159
|
+
* @param options - Optional finalize options (zipComment; centralDirOffset for correct EOCD when concatenating)
|
|
160
|
+
* @returns Buffer containing central directory + EOCD
|
|
161
|
+
*/
|
|
162
|
+
writeCentralDirectoryAndEOCD(entries: ZipEntry[], options?: FinalizeZipOptions): Buffer;
|
|
163
|
+
/**
|
|
164
|
+
* Copy ZIP file entries efficiently from buffer to buffer
|
|
165
|
+
*
|
|
166
|
+
* Main method that copies entries from source ZIP buffer to destination ZIP buffer.
|
|
167
|
+
* Uses ZipEntry instances directly to avoid unnecessary parsing.
|
|
168
|
+
*
|
|
169
|
+
* @param sourceZipBuffer - Buffer containing the source ZIP file
|
|
170
|
+
* @param options - Optional copy options (filtering, sorting, etc.)
|
|
171
|
+
* @returns Copy result with entry information and the complete ZIP buffer
|
|
172
|
+
*/
|
|
173
|
+
copyZipBuffer(sourceZipBuffer: Buffer, options?: CopyOptions): Promise<CopyResult>;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=ZipCopy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZipCopy.d.ts","sourceRoot":"","sources":["../../src/core/ZipCopy.ts"],"names":[],"mappings":"AAUA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,MAAM,MAAM,UAAU,CAAC;AAG9B;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,yDAAyD;IACzD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC;IAC3C,sDAAsD;IACtD,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,KAAK,MAAM,CAAC;IACnD,+DAA+D;IAC/D,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,uCAAuC;IACvC,OAAO,EAAE,KAAK,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC,CAAC;IACH,mDAAmD;IACnD,gBAAgB,EAAE,MAAM,CAAC;IACzB,qCAAqC;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,+FAA+F;IAC/F,eAAe,EAAE,MAAM,CAAC;IACxB,8IAA8I;IAC9I,aAAa,EAAE,MAAM,CAAC;IACtB,wEAAwE;IACxE,aAA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