@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.
Files changed (171) hide show
  1. package/README.md +134 -0
  2. package/dist/browser/ZipkitBrowser.d.ts +27 -0
  3. package/dist/browser/ZipkitBrowser.d.ts.map +1 -0
  4. package/dist/browser/ZipkitBrowser.js +303 -0
  5. package/dist/browser/ZipkitBrowser.js.map +1 -0
  6. package/dist/browser/index.d.ts +9 -0
  7. package/dist/browser/index.d.ts.map +1 -0
  8. package/dist/browser/index.esm.d.ts +12 -0
  9. package/dist/browser/index.esm.d.ts.map +1 -0
  10. package/dist/browser/index.esm.js +46 -0
  11. package/dist/browser/index.esm.js.map +1 -0
  12. package/dist/browser/index.js +38 -0
  13. package/dist/browser/index.js.map +1 -0
  14. package/dist/browser-esm/index.d.ts +9 -0
  15. package/dist/browser-esm/index.js +50211 -0
  16. package/dist/browser-esm/index.js.map +7 -0
  17. package/dist/browser-umd/index.d.ts +9 -0
  18. package/dist/browser-umd/index.js +50221 -0
  19. package/dist/browser-umd/index.js.map +7 -0
  20. package/dist/browser-umd/index.min.js +39 -0
  21. package/dist/browser.d.ts +9 -0
  22. package/dist/browser.js +38 -0
  23. package/dist/core/ZipCompress.d.ts +99 -0
  24. package/dist/core/ZipCompress.d.ts.map +1 -0
  25. package/dist/core/ZipCompress.js +287 -0
  26. package/dist/core/ZipCompress.js.map +1 -0
  27. package/dist/core/ZipCopy.d.ts +175 -0
  28. package/dist/core/ZipCopy.d.ts.map +1 -0
  29. package/dist/core/ZipCopy.js +310 -0
  30. package/dist/core/ZipCopy.js.map +1 -0
  31. package/dist/core/ZipDecompress.d.ts +57 -0
  32. package/dist/core/ZipDecompress.d.ts.map +1 -0
  33. package/dist/core/ZipDecompress.js +155 -0
  34. package/dist/core/ZipDecompress.js.map +1 -0
  35. package/dist/core/ZipEntry.d.ts +138 -0
  36. package/dist/core/ZipEntry.d.ts.map +1 -0
  37. package/dist/core/ZipEntry.js +829 -0
  38. package/dist/core/ZipEntry.js.map +1 -0
  39. package/dist/core/Zipkit.d.ts +315 -0
  40. package/dist/core/Zipkit.d.ts.map +1 -0
  41. package/dist/core/Zipkit.js +647 -0
  42. package/dist/core/Zipkit.js.map +1 -0
  43. package/dist/core/ZstdManager.d.ts +56 -0
  44. package/dist/core/ZstdManager.d.ts.map +1 -0
  45. package/dist/core/ZstdManager.js +144 -0
  46. package/dist/core/ZstdManager.js.map +1 -0
  47. package/dist/core/components/HashCalculator.d.ts +138 -0
  48. package/dist/core/components/HashCalculator.d.ts.map +1 -0
  49. package/dist/core/components/HashCalculator.js +360 -0
  50. package/dist/core/components/HashCalculator.js.map +1 -0
  51. package/dist/core/components/Logger.d.ts +73 -0
  52. package/dist/core/components/Logger.d.ts.map +1 -0
  53. package/dist/core/components/Logger.js +156 -0
  54. package/dist/core/components/Logger.js.map +1 -0
  55. package/dist/core/components/ProgressTracker.d.ts +43 -0
  56. package/dist/core/components/ProgressTracker.d.ts.map +1 -0
  57. package/dist/core/components/ProgressTracker.js +112 -0
  58. package/dist/core/components/ProgressTracker.js.map +1 -0
  59. package/dist/core/components/Support.d.ts +64 -0
  60. package/dist/core/components/Support.d.ts.map +1 -0
  61. package/dist/core/components/Support.js +71 -0
  62. package/dist/core/components/Support.js.map +1 -0
  63. package/dist/core/components/Util.d.ts +26 -0
  64. package/dist/core/components/Util.d.ts.map +1 -0
  65. package/dist/core/components/Util.js +95 -0
  66. package/dist/core/components/Util.js.map +1 -0
  67. package/dist/core/constants/Errors.d.ts +52 -0
  68. package/dist/core/constants/Errors.d.ts.map +1 -0
  69. package/dist/core/constants/Errors.js +67 -0
  70. package/dist/core/constants/Errors.js.map +1 -0
  71. package/dist/core/constants/Headers.d.ts +170 -0
  72. package/dist/core/constants/Headers.d.ts.map +1 -0
  73. package/dist/core/constants/Headers.js +194 -0
  74. package/dist/core/constants/Headers.js.map +1 -0
  75. package/dist/core/encryption/Manager.d.ts +58 -0
  76. package/dist/core/encryption/Manager.d.ts.map +1 -0
  77. package/dist/core/encryption/Manager.js +121 -0
  78. package/dist/core/encryption/Manager.js.map +1 -0
  79. package/dist/core/encryption/ZipCrypto.d.ts +172 -0
  80. package/dist/core/encryption/ZipCrypto.d.ts.map +1 -0
  81. package/dist/core/encryption/ZipCrypto.js +554 -0
  82. package/dist/core/encryption/ZipCrypto.js.map +1 -0
  83. package/dist/core/encryption/index.d.ts +9 -0
  84. package/dist/core/encryption/index.d.ts.map +1 -0
  85. package/dist/core/encryption/index.js +17 -0
  86. package/dist/core/encryption/index.js.map +1 -0
  87. package/dist/core/encryption/types.d.ts +29 -0
  88. package/dist/core/encryption/types.d.ts.map +1 -0
  89. package/dist/core/encryption/types.js +12 -0
  90. package/dist/core/encryption/types.js.map +1 -0
  91. package/dist/core/index.d.ts +27 -0
  92. package/dist/core/index.d.ts.map +1 -0
  93. package/dist/core/index.js +59 -0
  94. package/dist/core/index.js.map +1 -0
  95. package/dist/core/version.d.ts +5 -0
  96. package/dist/core/version.d.ts.map +1 -0
  97. package/dist/core/version.js +31 -0
  98. package/dist/core/version.js.map +1 -0
  99. package/dist/index.d.ts +9 -0
  100. package/dist/index.d.ts.map +1 -0
  101. package/dist/index.js +38 -0
  102. package/dist/index.js.map +1 -0
  103. package/dist/node/ZipCompressNode.d.ts +123 -0
  104. package/dist/node/ZipCompressNode.d.ts.map +1 -0
  105. package/dist/node/ZipCompressNode.js +565 -0
  106. package/dist/node/ZipCompressNode.js.map +1 -0
  107. package/dist/node/ZipCopyNode.d.ts +165 -0
  108. package/dist/node/ZipCopyNode.d.ts.map +1 -0
  109. package/dist/node/ZipCopyNode.js +347 -0
  110. package/dist/node/ZipCopyNode.js.map +1 -0
  111. package/dist/node/ZipDecompressNode.d.ts +197 -0
  112. package/dist/node/ZipDecompressNode.d.ts.map +1 -0
  113. package/dist/node/ZipDecompressNode.js +678 -0
  114. package/dist/node/ZipDecompressNode.js.map +1 -0
  115. package/dist/node/ZipkitNode.d.ts +466 -0
  116. package/dist/node/ZipkitNode.d.ts.map +1 -0
  117. package/dist/node/ZipkitNode.js +1426 -0
  118. package/dist/node/ZipkitNode.js.map +1 -0
  119. package/dist/node/index.d.ts +25 -0
  120. package/dist/node/index.d.ts.map +1 -0
  121. package/dist/node/index.js +54 -0
  122. package/dist/node/index.js.map +1 -0
  123. package/dist/types/index.d.ts +45 -0
  124. package/dist/types/index.d.ts.map +1 -0
  125. package/dist/types/index.js +11 -0
  126. package/dist/types/index.js.map +1 -0
  127. package/examples/README.md +261 -0
  128. package/examples/append-data.json +44 -0
  129. package/examples/copy-zip-append.ts +139 -0
  130. package/examples/copy-zip.ts +152 -0
  131. package/examples/create-zip.ts +172 -0
  132. package/examples/extract-zip.ts +118 -0
  133. package/examples/list-zip.ts +161 -0
  134. package/examples/test-files/data.json +116 -0
  135. package/examples/test-files/document.md +80 -0
  136. package/examples/test-files/document.txt +6 -0
  137. package/examples/test-files/file1.txt +48 -0
  138. package/examples/test-files/file2.txt +80 -0
  139. package/examples/tsconfig.json +44 -0
  140. package/package.json +167 -0
  141. package/src/browser/ZipkitBrowser.ts +305 -0
  142. package/src/browser/index.esm.ts +32 -0
  143. package/src/browser/index.ts +19 -0
  144. package/src/core/ZipCompress.ts +370 -0
  145. package/src/core/ZipCopy.ts +434 -0
  146. package/src/core/ZipDecompress.ts +191 -0
  147. package/src/core/ZipEntry.ts +917 -0
  148. package/src/core/Zipkit.ts +794 -0
  149. package/src/core/ZstdManager.ts +165 -0
  150. package/src/core/components/HashCalculator.ts +384 -0
  151. package/src/core/components/Logger.ts +180 -0
  152. package/src/core/components/ProgressTracker.ts +134 -0
  153. package/src/core/components/Support.ts +77 -0
  154. package/src/core/components/Util.ts +91 -0
  155. package/src/core/constants/Errors.ts +78 -0
  156. package/src/core/constants/Headers.ts +205 -0
  157. package/src/core/encryption/Manager.ts +137 -0
  158. package/src/core/encryption/ZipCrypto.ts +650 -0
  159. package/src/core/encryption/index.ts +15 -0
  160. package/src/core/encryption/types.ts +33 -0
  161. package/src/core/index.ts +42 -0
  162. package/src/core/version.ts +33 -0
  163. package/src/index.ts +19 -0
  164. package/src/node/ZipCompressNode.ts +618 -0
  165. package/src/node/ZipCopyNode.ts +437 -0
  166. package/src/node/ZipDecompressNode.ts +793 -0
  167. package/src/node/ZipkitNode.ts +1706 -0
  168. package/src/node/index.ts +40 -0
  169. package/src/types/index.ts +68 -0
  170. package/src/types/modules.d.ts +22 -0
  171. package/src/types/opentimestamps.d.ts +1 -0
@@ -0,0 +1,565 @@
1
+ "use strict";
2
+ // ======================================
3
+ // ZipCompressNode.ts - Node.js File-Based Compression
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ var desc = Object.getOwnPropertyDescriptor(m, k);
19
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
20
+ desc = { enumerable: true, get: function() { return m[k]; } };
21
+ }
22
+ Object.defineProperty(o, k2, desc);
23
+ }) : (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ o[k2] = m[k];
26
+ }));
27
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
28
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
29
+ }) : function(o, v) {
30
+ o["default"] = v;
31
+ });
32
+ var __importStar = (this && this.__importStar) || (function () {
33
+ var ownKeys = function(o) {
34
+ ownKeys = Object.getOwnPropertyNames || function (o) {
35
+ var ar = [];
36
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
37
+ return ar;
38
+ };
39
+ return ownKeys(o);
40
+ };
41
+ return function (mod) {
42
+ if (mod && mod.__esModule) return mod;
43
+ var result = {};
44
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
45
+ __setModuleDefault(result, mod);
46
+ return result;
47
+ };
48
+ })();
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.ZipCompressNode = void 0;
54
+ const Logger_1 = require("../core/components/Logger");
55
+ const Headers_1 = require("../core/constants/Headers");
56
+ const HashCalculator_1 = require("../core/components/HashCalculator");
57
+ const ZipCrypto_1 = require("../core/encryption/ZipCrypto");
58
+ const ZstdManager_1 = require("../core/ZstdManager");
59
+ const Errors_1 = __importDefault(require("../core/constants/Errors"));
60
+ const fs = __importStar(require("fs"));
61
+ const path = __importStar(require("path"));
62
+ const pako = require('pako');
63
+ /**
64
+ * ZipCompressNode - Node.js file-based compression operations
65
+ *
66
+ * Independent compression implementation for Node.js environments.
67
+ * All compression logic is implemented directly without delegating to ZipCompress.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const zipkitNode = new ZipkitNode();
72
+ * const compressNode = new ZipCompressNode(zipkitNode);
73
+ * const compressed = await compressNode.compressFile('/path/to/file.txt', entry);
74
+ * ```
75
+ */
76
+ class ZipCompressNode {
77
+ /**
78
+ * Internal logging method - only logs if class logging is enabled
79
+ */
80
+ log(...args) {
81
+ if (ZipCompressNode.loggingEnabled) {
82
+ Logger_1.Logger.debug(`[ZipCompressNode]`, ...args);
83
+ }
84
+ }
85
+ /**
86
+ * Creates a new ZipCompressNode instance
87
+ * @param zipkitNode - ZipkitNode instance to use for ZIP operations
88
+ */
89
+ constructor(zipkitNode) {
90
+ this.zipkitNode = zipkitNode;
91
+ // If logging is enabled, ensure Logger level is set to debug
92
+ if (ZipCompressNode.loggingEnabled) {
93
+ Logger_1.Logger.setLevel('debug');
94
+ }
95
+ }
96
+ // ============================================================================
97
+ // Compression Methods
98
+ // ============================================================================
99
+ /**
100
+ * Compress data for a ZIP entry (Buffer-based only)
101
+ * @param entry - ZIP entry to compress
102
+ * @param data - Buffer containing data to compress
103
+ * @param options - Compression options
104
+ * @param onOutputBuffer - Optional callback for streaming output
105
+ * @returns Buffer containing compressed data
106
+ */
107
+ async compressData(entry, data, options, onOutputBuffer) {
108
+ // Set uncompressed size if not already set
109
+ if (!entry.uncompressedSize || entry.uncompressedSize === 0) {
110
+ entry.uncompressedSize = data.length;
111
+ }
112
+ const totalSize = data.length;
113
+ const bufferSize = options?.bufferSize || this.zipkitNode.getBufferSize();
114
+ // Determine compression method
115
+ let compressionMethod;
116
+ if (options?.level === 0) {
117
+ compressionMethod = Headers_1.CMP_METHOD.STORED;
118
+ }
119
+ else if (options?.useZstd) {
120
+ // ZSTD fallback to STORED if file too small
121
+ if (totalSize < 100) {
122
+ compressionMethod = Headers_1.CMP_METHOD.STORED;
123
+ }
124
+ else {
125
+ compressionMethod = Headers_1.CMP_METHOD.ZSTD;
126
+ }
127
+ }
128
+ else {
129
+ compressionMethod = Headers_1.CMP_METHOD.DEFLATED;
130
+ }
131
+ entry.cmpMethod = compressionMethod;
132
+ // Initialize hash calculator
133
+ const needsHashCalculation = (!entry.crc || entry.crc === 0) || (options?.useSHA256 && !entry.sha256);
134
+ const hashCalculator = needsHashCalculation ? new HashCalculator_1.HashCalculator({ useSHA256: options?.useSHA256 && !entry.sha256 || false }) : null;
135
+ // Calculate hashes if needed
136
+ let buffer = Buffer.alloc(0);
137
+ if (hashCalculator) {
138
+ hashCalculator.update(data);
139
+ if (!entry.crc || entry.crc === 0) {
140
+ entry.crc = hashCalculator.finalizeCRC32();
141
+ }
142
+ if (options?.useSHA256 && !entry.sha256) {
143
+ entry.sha256 = hashCalculator.finalizeSHA256();
144
+ }
145
+ }
146
+ // Compress based on method
147
+ if (compressionMethod === Headers_1.CMP_METHOD.STORED) {
148
+ buffer = data;
149
+ entry.compressedSize = data.length;
150
+ }
151
+ else if (compressionMethod === Headers_1.CMP_METHOD.ZSTD) {
152
+ buffer = await this.zstdCompress(data, options, bufferSize, entry, onOutputBuffer);
153
+ }
154
+ else {
155
+ // DEFLATED
156
+ buffer = await this.deflateCompress(data, options, bufferSize, entry, onOutputBuffer);
157
+ }
158
+ // Only set compressed size if it hasn't been set already
159
+ if (entry.compressedSize === undefined || entry.compressedSize === 0) {
160
+ entry.compressedSize = buffer.length;
161
+ }
162
+ // Apply encryption if password is provided
163
+ if (options?.password && buffer.length > 0) {
164
+ buffer = this.encryptCompressedData(buffer, entry, options.password);
165
+ }
166
+ return buffer;
167
+ }
168
+ /**
169
+ * Compresses data using deflate algorithm with chunked processing
170
+ * @param data - Data to compress (Buffer or chunked reader)
171
+ * @param options - Compression options
172
+ * @param bufferSize - Size of buffer to read (default: 512KB)
173
+ * @param entry - Optional ZIP entry for hash calculation
174
+ * @param onOutputBuffer - Optional callback for streaming output
175
+ * @returns Compressed data buffer
176
+ */
177
+ async deflateCompress(data, options, bufferSize, entry, onOutputBuffer) {
178
+ const effectiveBufferSize = bufferSize || options?.bufferSize || this.zipkitNode.getBufferSize();
179
+ // Initialize hash calculator for incremental hash calculation during chunk reads
180
+ const needsHashCalculation = entry && ((!entry.crc || entry.crc === 0) || (options?.useSHA256 && !entry.sha256));
181
+ const hashCalculator = needsHashCalculation ? new HashCalculator_1.HashCalculator({ useSHA256: options?.useSHA256 && !entry.sha256 || false }) : null;
182
+ if (options?.level === 0) {
183
+ // Store without compression
184
+ if (Buffer.isBuffer(data)) {
185
+ // For buffer, calculate hashes if needed
186
+ if (hashCalculator && entry) {
187
+ hashCalculator.update(data);
188
+ if (!entry.crc || entry.crc === 0) {
189
+ entry.crc = hashCalculator.finalizeCRC32();
190
+ }
191
+ if (options?.useSHA256 && !entry.sha256) {
192
+ entry.sha256 = hashCalculator.finalizeSHA256();
193
+ }
194
+ }
195
+ return data;
196
+ }
197
+ else {
198
+ // For chunked reader, process in chunks and call onOutputBuffer
199
+ let position = 0;
200
+ let totalProcessed = 0;
201
+ while (position < data.totalSize) {
202
+ const readSize = Math.min(effectiveBufferSize, data.totalSize - position);
203
+ const chunk = data.onReadChunk(position, readSize);
204
+ // [READ] -> [HASH] -> [OUTPUT] sequence
205
+ if (hashCalculator) {
206
+ hashCalculator.update(chunk);
207
+ }
208
+ if (onOutputBuffer) {
209
+ await onOutputBuffer(chunk);
210
+ }
211
+ totalProcessed += chunk.length;
212
+ position += chunk.length;
213
+ }
214
+ // Finalize hashes
215
+ if (hashCalculator && entry) {
216
+ if (!entry.crc || entry.crc === 0) {
217
+ entry.crc = hashCalculator.finalizeCRC32();
218
+ }
219
+ if (options?.useSHA256 && !entry.sha256) {
220
+ entry.sha256 = hashCalculator.finalizeSHA256();
221
+ }
222
+ }
223
+ return Buffer.alloc(0);
224
+ }
225
+ }
226
+ try {
227
+ const level = options?.level;
228
+ const isBuffer = Buffer.isBuffer(data);
229
+ const totalSize = isBuffer ? data.length : data.totalSize;
230
+ const compressedChunks = [];
231
+ let totalProcessed = 0;
232
+ let totalCompressedSize = 0;
233
+ let position = 0;
234
+ if (isBuffer) {
235
+ // Buffer-based processing
236
+ if (hashCalculator && entry) {
237
+ hashCalculator.update(data);
238
+ // Always set CRC if hash calculator was used (it calculated the correct CRC)
239
+ entry.crc = hashCalculator.finalizeCRC32();
240
+ if (options?.useSHA256 && !entry.sha256) {
241
+ entry.sha256 = hashCalculator.finalizeSHA256();
242
+ }
243
+ }
244
+ const result = pako.deflateRaw(data, { level: level ?? 6 });
245
+ const compressed = Buffer.from(result.buffer, result.byteOffset, result.byteLength);
246
+ if (onOutputBuffer) {
247
+ await onOutputBuffer(compressed);
248
+ }
249
+ return compressed;
250
+ }
251
+ else {
252
+ // Chunked reader processing - use streaming deflator to maintain state across chunks
253
+ const deflator = new pako.Deflate({ level: level ?? 6, raw: true });
254
+ const compressedChunks = [];
255
+ let resultOffset = 0; // Track how much of deflator.result we've already processed
256
+ while (position < totalSize) {
257
+ const readSize = Math.min(effectiveBufferSize, totalSize - position);
258
+ const chunk = data.onReadChunk(position, readSize);
259
+ const isLast = position + readSize >= totalSize;
260
+ // [READ] -> [HASH] sequence
261
+ if (hashCalculator) {
262
+ hashCalculator.update(chunk);
263
+ }
264
+ // Push chunk to streaming deflator (maintains state across chunks)
265
+ deflator.push(chunk, isLast);
266
+ // Collect compressed chunks from deflator
267
+ // deflator.result accumulates compressed data, so we need to process only new data
268
+ if (deflator.result && deflator.result.length > resultOffset) {
269
+ const newCompressed = Buffer.from(deflator.result.subarray(resultOffset));
270
+ compressedChunks.push(newCompressed);
271
+ totalCompressedSize += newCompressed.length;
272
+ resultOffset = deflator.result.length;
273
+ if (onOutputBuffer) {
274
+ await onOutputBuffer(newCompressed);
275
+ }
276
+ }
277
+ totalProcessed += chunk.length;
278
+ position += chunk.length;
279
+ }
280
+ // Finalize hashes after all chunks processed and compressed
281
+ if (hashCalculator && entry) {
282
+ // Always set CRC if hash calculator was used (it calculated the correct CRC)
283
+ entry.crc = hashCalculator.finalizeCRC32();
284
+ if (options?.useSHA256 && !entry.sha256) {
285
+ entry.sha256 = hashCalculator.finalizeSHA256();
286
+ }
287
+ }
288
+ // For chunked processing, return empty buffer (data already written via onOutputBuffer)
289
+ if (entry) {
290
+ entry.compressedSize = totalCompressedSize;
291
+ }
292
+ return Buffer.alloc(0);
293
+ }
294
+ }
295
+ catch (e) {
296
+ Logger_1.Logger.error('Error during chunked deflate compression:', e);
297
+ throw new Error(Errors_1.default.COMPRESSION_ERROR);
298
+ }
299
+ }
300
+ /**
301
+ * Compresses data using deflate algorithm (legacy method for small buffers)
302
+ * @param inbuf - Data to compress
303
+ * @param options - Compression options
304
+ * @returns Compressed data buffer
305
+ */
306
+ deflate(inbuf, options) {
307
+ if (options?.level == 0) {
308
+ return inbuf; // Store without compression
309
+ }
310
+ try {
311
+ const level = options?.level;
312
+ const result = pako.deflateRaw(inbuf, {
313
+ level: level ?? 6
314
+ });
315
+ return Buffer.from(result.buffer, result.byteOffset, result.byteLength);
316
+ }
317
+ catch (e) {
318
+ Logger_1.Logger.error('Error during compression:', e);
319
+ throw new Error(Errors_1.default.COMPRESSION_ERROR);
320
+ }
321
+ }
322
+ /**
323
+ * Compresses data using Zstandard (zstd) algorithm
324
+ * @param input - Buffer to compress OR chunked reader object with totalSize and readChunk callback
325
+ * @param options - Compression options
326
+ * @param bufferSize - Size of buffer to read if using chunked reader (default: 512KB)
327
+ * @param entry - Optional ZIP entry for hash calculation
328
+ * @param onOutputBuffer - Optional callback for streaming output
329
+ * @returns Compressed data buffer
330
+ */
331
+ async zstdCompress(input, options, bufferSize, entry, onOutputBuffer) {
332
+ const effectiveBufferSize = bufferSize || options?.bufferSize || this.zipkitNode.getBufferSize();
333
+ const isBuffer = Buffer.isBuffer(input);
334
+ const totalSize = isBuffer ? input.length : input.totalSize;
335
+ if (options?.level == 0) {
336
+ // For store mode, return as-is
337
+ if (isBuffer) {
338
+ return input;
339
+ }
340
+ else {
341
+ // Read all chunks
342
+ const chunks = [];
343
+ let position = 0;
344
+ while (position < totalSize) {
345
+ const size = Math.min(effectiveBufferSize, totalSize - position);
346
+ const chunk = input.readChunk(position, size);
347
+ chunks.push(chunk);
348
+ position += size;
349
+ }
350
+ return Buffer.concat(chunks);
351
+ }
352
+ }
353
+ try {
354
+ // Zstd compression levels range from 1 (fastest) to 22 (highest compression)
355
+ // Map our 1-9 level to a reasonable zstd range (1-19)
356
+ const level = options?.level ?? 6;
357
+ const zstdLevel = Math.min(Math.max(1, Math.floor(level * 2.1)), 19);
358
+ // Get the full buffer (zstd doesn't support true streaming compression)
359
+ const inbuf = isBuffer ? input : (() => {
360
+ const chunks = [];
361
+ let position = 0;
362
+ while (position < totalSize) {
363
+ const size = Math.min(effectiveBufferSize, totalSize - position);
364
+ const chunk = input.readChunk(position, size);
365
+ chunks.push(chunk);
366
+ position += size;
367
+ }
368
+ return Buffer.concat(chunks);
369
+ })();
370
+ // Validate input
371
+ if (!inbuf || inbuf.length === 0) {
372
+ throw new Error('ZSTD compression: empty input buffer');
373
+ }
374
+ // Convert Buffer to Uint8Array for WASM module
375
+ const inputArray = new Uint8Array(inbuf.buffer, inbuf.byteOffset, inbuf.byteLength);
376
+ // Compress the data with zstd using global ZstdManager
377
+ const compressedData = await ZstdManager_1.ZstdManager.compress(inputArray, zstdLevel);
378
+ const compressedBuffer = Buffer.from(compressedData);
379
+ // Set the compressed size in the entry for ZIP file structure
380
+ if (entry) {
381
+ entry.compressedSize = compressedBuffer.length;
382
+ }
383
+ if (onOutputBuffer) {
384
+ await onOutputBuffer(compressedBuffer);
385
+ }
386
+ return compressedBuffer;
387
+ }
388
+ catch (e) {
389
+ Logger_1.Logger.error('Error during zstd compression:', e);
390
+ throw new Error(Errors_1.default.COMPRESSION_ERROR);
391
+ }
392
+ }
393
+ /**
394
+ * Encrypt compressed data using PKZIP encryption
395
+ * Creates encryption header, encrypts compressed data, and updates entry flags
396
+ * @param compressedData - Compressed data to encrypt
397
+ * @param entry - ZIP entry to encrypt
398
+ * @param password - Password for encryption
399
+ * @returns Encrypted buffer (encrypted header + encrypted compressed data)
400
+ */
401
+ encryptCompressedData(compressedData, entry, password) {
402
+ // Create ZipCrypto instance
403
+ const zipCrypto = new ZipCrypto_1.ZipCrypto();
404
+ // Encrypt the compressed data (includes header creation and encryption)
405
+ const encryptedData = zipCrypto.encryptBuffer(entry, compressedData, password);
406
+ // Set encryption flags on entry
407
+ entry.isEncrypted = true;
408
+ entry.bitFlags |= Headers_1.GP_FLAG.ENCRYPTED;
409
+ // Update compressed size to include encryption header (12 bytes)
410
+ entry.compressedSize = encryptedData.length;
411
+ return encryptedData;
412
+ }
413
+ // ============================================================================
414
+ // File-Based Compression Methods
415
+ // ============================================================================
416
+ /**
417
+ * Compress a file from disk
418
+ *
419
+ * Reads file from disk, sets entry metadata from file stats, and compresses the data.
420
+ *
421
+ * @param filePath - Path to the file to compress
422
+ * @param entry - ZIP entry to compress (filename should already be set)
423
+ * @param options - Optional compression options
424
+ * @returns Promise resolving to Buffer containing compressed data
425
+ * @throws Error if file not found or not a file
426
+ */
427
+ async compressFile(filePath, entry, options) {
428
+ // Validate file exists
429
+ if (!fs.existsSync(filePath)) {
430
+ throw new Error(`File not found: ${filePath}`);
431
+ }
432
+ const stats = fs.statSync(filePath);
433
+ if (!stats.isFile()) {
434
+ throw new Error(`Path is not a file: ${filePath}`);
435
+ }
436
+ // Set entry metadata from file stats
437
+ entry.uncompressedSize = stats.size;
438
+ entry.timeDateDOS = entry.setDateTime(stats.mtime);
439
+ // Read file data
440
+ const fileData = fs.readFileSync(filePath);
441
+ // Compress the buffer using compressData (buffer-based compression)
442
+ return await this.compressData(entry, fileData, options);
443
+ }
444
+ /**
445
+ * Compress a file from disk using streaming for large files
446
+ *
447
+ * Streams file in chunks for memory-efficient compression of large files.
448
+ * All chunk reading logic is handled in this server class.
449
+ *
450
+ * @param filePath - Path to the file to compress
451
+ * @param entry - ZIP entry to compress (filename should already be set)
452
+ * @param options - Optional compression options
453
+ * @param onOutputBuffer - Optional callback for streaming output
454
+ * @returns Promise resolving to Buffer containing compressed data
455
+ * @throws Error if file not found or not a file
456
+ */
457
+ async compressFileStream(filePath, entry, options, onOutputBuffer) {
458
+ // Validate file exists
459
+ if (!fs.existsSync(filePath)) {
460
+ throw new Error(`File not found: ${filePath}`);
461
+ }
462
+ const stats = fs.statSync(filePath);
463
+ if (!stats.isFile()) {
464
+ throw new Error(`Path is not a file: ${filePath}`);
465
+ }
466
+ // Set entry metadata from file stats
467
+ entry.uncompressedSize = stats.size;
468
+ entry.timeDateDOS = entry.setDateTime(stats.mtime);
469
+ // Determine buffer size for chunked reading
470
+ const bufferSize = options?.bufferSize || this.zipkitNode.getBufferSize();
471
+ // Create chunked reader for streaming compression
472
+ // All chunk reading logic is in this server class
473
+ const chunkedReader = {
474
+ totalSize: stats.size,
475
+ onReadChunk: (position, size) => {
476
+ const fd = fs.openSync(filePath, 'r');
477
+ try {
478
+ const buffer = Buffer.alloc(size);
479
+ const bytesRead = fs.readSync(fd, buffer, 0, size, position);
480
+ return buffer.subarray(0, bytesRead);
481
+ }
482
+ finally {
483
+ fs.closeSync(fd);
484
+ }
485
+ },
486
+ onOutChunk: (chunk) => {
487
+ // Output chunks are accumulated in compression methods
488
+ }
489
+ };
490
+ // Determine compression method and call appropriate method
491
+ const compressionMethod = options?.level === 0 ? 'STORED' :
492
+ options?.useZstd ? 'ZSTD' : 'DEFLATED';
493
+ // Set entry compression method before compression
494
+ if (compressionMethod === 'STORED') {
495
+ entry.cmpMethod = Headers_1.CMP_METHOD.STORED;
496
+ }
497
+ else if (compressionMethod === 'ZSTD') {
498
+ entry.cmpMethod = Headers_1.CMP_METHOD.ZSTD;
499
+ }
500
+ else {
501
+ entry.cmpMethod = Headers_1.CMP_METHOD.DEFLATED;
502
+ }
503
+ if (compressionMethod === 'STORED') {
504
+ // For STORED, read file and pass as buffer
505
+ const fileData = fs.readFileSync(filePath);
506
+ return await this.compressData(entry, fileData, options, onOutputBuffer);
507
+ }
508
+ else if (compressionMethod === 'ZSTD') {
509
+ // ZSTD requires full buffer, so read file first
510
+ const fileData = fs.readFileSync(filePath);
511
+ return await this.compressData(entry, fileData, options, onOutputBuffer);
512
+ }
513
+ else {
514
+ // DEFLATED: Use deflateCompress with chunked reader
515
+ return await this.deflateCompress(chunkedReader, options, bufferSize, entry, onOutputBuffer);
516
+ }
517
+ }
518
+ /**
519
+ * Compress multiple files from disk to a ZIP file
520
+ *
521
+ * Batch compression from file paths. Creates entries for each file and writes
522
+ * to output ZIP file. This is a simplified implementation - full implementation
523
+ * would need to write ZIP structure incrementally.
524
+ *
525
+ * @param filePaths - Array of file paths to compress
526
+ * @param outputPath - Path where the ZIP file should be created
527
+ * @param options - Optional compression options
528
+ * @returns Promise that resolves when ZIP creation is complete
529
+ * @throws Error if any file not found
530
+ */
531
+ async compressFiles(filePaths, outputPath, options) {
532
+ // This is a placeholder for future implementation
533
+ // Full implementation would need to:
534
+ // 1. Create ZIP file structure
535
+ // 2. Write local headers and compressed data for each file
536
+ // 3. Write central directory
537
+ // 4. Write end of central directory record
538
+ // For now, this is a simplified version that compresses files but doesn't write ZIP structure
539
+ const entries = [];
540
+ const compressedData = [];
541
+ for (const filePath of filePaths) {
542
+ if (!fs.existsSync(filePath)) {
543
+ throw new Error(`File not found: ${filePath}`);
544
+ }
545
+ const stats = fs.statSync(filePath);
546
+ if (!stats.isFile()) {
547
+ continue; // Skip directories
548
+ }
549
+ // Create entry
550
+ const entryName = path.relative(process.cwd(), filePath) || path.basename(filePath);
551
+ const entry = this.zipkitNode.createZipEntry(entryName);
552
+ // Compress file
553
+ const compressed = await this.compressFile(filePath, entry, options);
554
+ entries.push(entry);
555
+ compressedData.push(compressed);
556
+ }
557
+ // For now, this is a placeholder
558
+ // Full implementation would write ZIP structure to outputPath
559
+ throw new Error('compressFiles() - Full implementation pending. Use neozip CLI for now.');
560
+ }
561
+ }
562
+ exports.ZipCompressNode = ZipCompressNode;
563
+ // Class-level logging control - set to true to enable logging
564
+ ZipCompressNode.loggingEnabled = false;
565
+ //# sourceMappingURL=ZipCompressNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZipCompressNode.js","sourceRoot":"","sources":["../../src/node/ZipCompressNode.ts"],"names":[],"mappings":";AAAA,yCAAyC;AACzC,sDAAsD;AACtD,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKF,sDAAmD;AACnD,uDAAkF;AAClF,sEAAmE;AACnE,4DAAyD;AACzD,qDAAkD;AAClD,sEAA8C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