piclaw 0.0.4 → 0.0.6

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 (185) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/public/assets/dist-D51xeTP2.js +12 -0
  3. package/.output/public/assets/index-B3x2_en6.css +1 -0
  4. package/.output/public/assets/index-SfjxJZSD.js +38 -0
  5. package/.output/public/assets/md4x-CNLJ57xO.wasm +0 -0
  6. package/.output/public/assets/md4x-CyfQToGJ.js +1 -0
  7. package/.output/public/assets/wasm-Cm7RZrwg.js +1 -0
  8. package/.output/public/icon.svg +25 -0
  9. package/.output/public/index.html +3 -2
  10. package/.output/public/manifest.json +1 -1
  11. package/.output/server/_chunks/bun.mjs +49 -0
  12. package/.output/server/_chunks/commands.mjs +280 -0
  13. package/.output/server/_chunks/config.mjs +2 -4
  14. package/.output/server/_chunks/db.mjs +11 -5
  15. package/.output/server/_chunks/logger.mjs +1 -1
  16. package/.output/server/_chunks/node.mjs +31 -0
  17. package/.output/server/_chunks/ntfy.mjs +45 -0
  18. package/.output/server/_chunks/pi.mjs +33 -1
  19. package/.output/server/_chunks/renderer-template.mjs +1 -1
  20. package/.output/server/_chunks/{bootstrap.mjs → server.mjs} +203 -205
  21. package/.output/server/_chunks/session.mjs +249 -40
  22. package/.output/server/_chunks/settings.mjs +1 -1
  23. package/.output/server/_chunks/terminal.mjs +35 -20
  24. package/.output/server/_chunks/virtual.mjs +129 -0
  25. package/.output/server/_jid_.delete.mjs +2 -2
  26. package/.output/server/_jid_.patch.mjs +30 -3
  27. package/.output/server/_jid_2.delete.mjs +2 -2
  28. package/.output/server/_libs/@aws-sdk/client-bedrock-runtime+[...].mjs +13148 -13149
  29. package/.output/server/_libs/@aws-sdk/credential-provider-http+[...].mjs +1 -1
  30. package/.output/server/_libs/@aws-sdk/credential-provider-ini+[...].mjs +2 -2
  31. package/.output/server/_libs/@aws-sdk/credential-provider-process+[...].mjs +1 -1
  32. package/.output/server/_libs/@aws-sdk/credential-provider-sso+[...].mjs +1 -1
  33. package/.output/server/_libs/@aws-sdk/credential-provider-web-identity+[...].mjs +1 -1
  34. package/.output/server/_libs/@google/genai.mjs +2 -2
  35. package/.output/server/_libs/@mariozechner/pi-agent-core+[...].mjs +40 -74
  36. package/.output/server/_libs/@mariozechner/pi-coding-agent+[...].mjs +1315 -1210
  37. package/.output/server/_libs/@smithy/credential-provider-imds+[...].mjs +3 -3
  38. package/.output/server/_libs/_.mjs +3 -2
  39. package/.output/server/_libs/_100.mjs +3 -0
  40. package/.output/server/_libs/_101.mjs +2 -0
  41. package/.output/server/_libs/_102.mjs +3 -0
  42. package/.output/server/_libs/_103.mjs +2 -0
  43. package/.output/server/_libs/_16.mjs +2 -5
  44. package/.output/server/_libs/_17.mjs +2 -3
  45. package/.output/server/_libs/_18.mjs +2 -3
  46. package/.output/server/_libs/_19.mjs +2 -4
  47. package/.output/server/_libs/_2.mjs +2 -3
  48. package/.output/server/_libs/_20.mjs +2 -2
  49. package/.output/server/_libs/_21.mjs +2 -0
  50. package/.output/server/_libs/_22.mjs +2 -0
  51. package/.output/server/_libs/_23.mjs +2 -0
  52. package/.output/server/_libs/_24.mjs +2 -0
  53. package/.output/server/_libs/_25.mjs +2 -0
  54. package/.output/server/_libs/_26.mjs +2 -0
  55. package/.output/server/_libs/_27.mjs +2 -0
  56. package/.output/server/_libs/_28.mjs +2 -0
  57. package/.output/server/_libs/_29.mjs +2 -0
  58. package/.output/server/_libs/_30.mjs +2 -0
  59. package/.output/server/_libs/_31.mjs +2 -0
  60. package/.output/server/_libs/_32.mjs +2 -0
  61. package/.output/server/_libs/_33.mjs +2 -0
  62. package/.output/server/_libs/_34.mjs +2 -0
  63. package/.output/server/_libs/_35.mjs +2 -0
  64. package/.output/server/_libs/_36.mjs +2 -0
  65. package/.output/server/_libs/_37.mjs +2 -0
  66. package/.output/server/_libs/_38.mjs +2 -0
  67. package/.output/server/_libs/_39.mjs +2 -0
  68. package/.output/server/_libs/_40.mjs +2 -0
  69. package/.output/server/_libs/_41.mjs +2 -0
  70. package/.output/server/_libs/_42.mjs +2 -0
  71. package/.output/server/_libs/_43.mjs +2 -0
  72. package/.output/server/_libs/_44.mjs +2 -0
  73. package/.output/server/_libs/_45.mjs +2 -0
  74. package/.output/server/_libs/_46.mjs +2 -0
  75. package/.output/server/_libs/_47.mjs +2 -0
  76. package/.output/server/_libs/_48.mjs +2 -0
  77. package/.output/server/_libs/_49.mjs +2 -0
  78. package/.output/server/_libs/_50.mjs +2 -0
  79. package/.output/server/_libs/_51.mjs +2 -0
  80. package/.output/server/_libs/_52.mjs +2 -0
  81. package/.output/server/_libs/_53.mjs +2 -0
  82. package/.output/server/_libs/_54.mjs +2 -0
  83. package/.output/server/_libs/_55.mjs +2 -0
  84. package/.output/server/_libs/_56.mjs +2 -0
  85. package/.output/server/_libs/_57.mjs +2 -0
  86. package/.output/server/_libs/_58.mjs +2 -0
  87. package/.output/server/_libs/_59.mjs +2 -0
  88. package/.output/server/_libs/_60.mjs +2 -0
  89. package/.output/server/_libs/_61.mjs +2 -0
  90. package/.output/server/_libs/_62.mjs +2 -0
  91. package/.output/server/_libs/_63.mjs +2 -0
  92. package/.output/server/_libs/_64.mjs +2 -0
  93. package/.output/server/_libs/_65.mjs +2 -0
  94. package/.output/server/_libs/_66.mjs +2 -0
  95. package/.output/server/_libs/_67.mjs +2 -0
  96. package/.output/server/_libs/_68.mjs +2 -0
  97. package/.output/server/_libs/_69.mjs +2 -0
  98. package/.output/server/_libs/_70.mjs +2 -0
  99. package/.output/server/_libs/_71.mjs +2 -0
  100. package/.output/server/_libs/_72.mjs +2 -0
  101. package/.output/server/_libs/_73.mjs +2 -0
  102. package/.output/server/_libs/_74.mjs +2 -0
  103. package/.output/server/_libs/_75.mjs +2 -0
  104. package/.output/server/_libs/_76.mjs +2 -0
  105. package/.output/server/_libs/_77.mjs +2 -0
  106. package/.output/server/_libs/_78.mjs +2 -0
  107. package/.output/server/_libs/_79.mjs +2 -0
  108. package/.output/server/_libs/_80.mjs +2 -0
  109. package/.output/server/_libs/_81.mjs +2 -0
  110. package/.output/server/_libs/_82.mjs +2 -0
  111. package/.output/server/_libs/_83.mjs +2 -0
  112. package/.output/server/_libs/_84.mjs +2 -0
  113. package/.output/server/_libs/_85.mjs +2 -0
  114. package/.output/server/_libs/_86.mjs +2 -0
  115. package/.output/server/_libs/_87.mjs +2 -0
  116. package/.output/server/_libs/_88.mjs +2 -0
  117. package/.output/server/_libs/_89.mjs +2 -0
  118. package/.output/server/_libs/_90.mjs +2 -0
  119. package/.output/server/_libs/_91.mjs +2 -0
  120. package/.output/server/_libs/_92.mjs +2 -0
  121. package/.output/server/_libs/_93.mjs +2 -0
  122. package/.output/server/_libs/_94.mjs +2 -0
  123. package/.output/server/_libs/_95.mjs +2 -0
  124. package/.output/server/_libs/_96.mjs +2 -0
  125. package/.output/server/_libs/_97.mjs +2 -0
  126. package/.output/server/_libs/_98.mjs +2 -0
  127. package/.output/server/_libs/_99.mjs +5 -0
  128. package/.output/server/_libs/amdefine.mjs +188 -0
  129. package/.output/server/_libs/aws-sdk__nested-clients.mjs +1 -1
  130. package/.output/server/_libs/compressjs.mjs +50 -0
  131. package/.output/server/_libs/diff.mjs +137 -0
  132. package/.output/server/_libs/get-uri.mjs +1 -1
  133. package/.output/server/_libs/http-proxy-agent.mjs +1 -1
  134. package/.output/server/_libs/https-proxy-agent.mjs +1 -1
  135. package/.output/server/_libs/just-bash+[...].mjs +80359 -0
  136. package/.output/server/_libs/md4x.mjs +73 -0
  137. package/.output/server/_libs/mixmark-io__domino.mjs +14801 -0
  138. package/.output/server/_libs/node-fetch.mjs +1 -1
  139. package/.output/server/_libs/node-liblzma.mjs +1107 -0
  140. package/.output/server/_libs/pac-proxy-agent+[...].mjs +1 -1
  141. package/.output/server/_libs/proxy-agent+proxy-from-env.mjs +1 -1
  142. package/.output/server/_libs/smithy__core.mjs +1 -1
  143. package/.output/server/_routes/api/files/delete.mjs +2 -2
  144. package/.output/server/_routes/api/files/groups.mjs +14 -0
  145. package/.output/server/_routes/api/files/raw.mjs +1 -1
  146. package/.output/server/_routes/api/files/read.mjs +1 -1
  147. package/.output/server/_routes/api/files/watch.mjs +1 -1
  148. package/.output/server/_routes/api/files/write.mjs +3 -2
  149. package/.output/server/_routes/api/files.mjs +1 -1
  150. package/.output/server/_routes/api/groups.mjs +2 -2
  151. package/.output/server/_routes/api/groups2.mjs +3 -2
  152. package/.output/server/_routes/api/health.mjs +2 -2
  153. package/.output/server/_routes/api/logs.mjs +4 -2
  154. package/.output/server/_routes/api/ntfy/setup.mjs +54 -0
  155. package/.output/server/_routes/api/ntfy/status.mjs +12 -0
  156. package/.output/server/_routes/api/pi/apikey.mjs +1 -1
  157. package/.output/server/_routes/api/pi/apikey_providers.mjs +1 -1
  158. package/.output/server/_routes/api/pi/commands.mjs +6 -0
  159. package/.output/server/_routes/api/pi/login/events.mjs +1 -1
  160. package/.output/server/_routes/api/pi/login/respond.mjs +1 -1
  161. package/.output/server/_routes/api/pi/login.mjs +1 -1
  162. package/.output/server/_routes/api/pi/logout.mjs +1 -1
  163. package/.output/server/_routes/api/pi/models.mjs +1 -1
  164. package/.output/server/_routes/api/pi/status.mjs +1 -1
  165. package/.output/server/_routes/api/send.mjs +22 -3
  166. package/.output/server/_routes/api/status.mjs +9 -7
  167. package/.output/server/_routes/api/tasks2.mjs +2 -2
  168. package/.output/server/_routes/api/telegram/setup.mjs +2 -2
  169. package/.output/server/_routes/api/telegram/status.mjs +2 -2
  170. package/.output/server/_routes/api/terminal2.mjs +3 -2
  171. package/.output/server/_utils.mjs +12 -4
  172. package/.output/server/build/md4x.wasm +0 -0
  173. package/.output/server/index.mjs +223 -149
  174. package/.output/server/node_modules/@mongodb-js/zstd/lib/index.js +55 -0
  175. package/.output/server/node_modules/@mongodb-js/zstd/package.json +51 -0
  176. package/.output/server/package.json +1 -0
  177. package/README.md +118 -24
  178. package/bin/piclaw.mjs +39 -1
  179. package/package.json +16 -13
  180. package/.output/public/assets/client-TIs-Ghqj.js +0 -9
  181. package/.output/public/assets/dist-BVjfG3ok.js +0 -12
  182. package/.output/public/assets/dist-DJh8l6yS.js +0 -1
  183. package/.output/public/assets/index-BNNEMkNV.js +0 -39
  184. package/.output/public/assets/index-CdWBxO5V.css +0 -1
  185. package/.output/public/assets/react-DFP7nCmh.js +0 -1
@@ -0,0 +1,1107 @@
1
+ import { createRequire } from "node:module";
2
+ import { Transform } from "node:stream";
3
+ import { createReadStream, createWriteStream } from "node:fs";
4
+ import * as path$1 from "node:path";
5
+ import * as os$1 from "node:os";
6
+ import { pipeline as pipeline$1 } from "node:stream/promises";
7
+ import { fileURLToPath } from "node:url";
8
+ import * as assert from "node:assert";
9
+ import { EventEmitter } from "node:events";
10
+ /**
11
+ * node-liblzma - Node.js bindings for liblzma
12
+ * Copyright (C) Olivier Orabona <olivier.orabona@gmail.com>
13
+ *
14
+ * This program is free software: you can redistribute it and/or modify
15
+ * it under the terms of the GNU Lesser General Public License as published by
16
+ * the Free Software Foundation, either version 3 of the License, or
17
+ * (at your option) any later version.
18
+ *
19
+ * This program is distributed in the hope that it will be useful,
20
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ * GNU General Public License for more details.
23
+ *
24
+ * You should have received a copy of the GNU Lesser General Public License
25
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
26
+ */
27
+ /**
28
+ * Base class for all LZMA-related errors
29
+ */
30
+ var LZMAError = class extends Error {
31
+ constructor(message, errno) {
32
+ super(message);
33
+ this.name = "LZMAError";
34
+ this.errno = errno;
35
+ this.code = errno;
36
+ Error.captureStackTrace(this, this.constructor);
37
+ }
38
+ };
39
+ /**
40
+ * Memory allocation error - thrown when LZMA cannot allocate required memory
41
+ */
42
+ var LZMAMemoryError = class extends LZMAError {
43
+ constructor(errno) {
44
+ super("Cannot allocate memory", errno);
45
+ this.name = "LZMAMemoryError";
46
+ }
47
+ };
48
+ /**
49
+ * Memory limit error - thrown when operation would exceed memory usage limit
50
+ */
51
+ var LZMAMemoryLimitError = class extends LZMAError {
52
+ constructor(errno) {
53
+ super("Memory usage limit was reached", errno);
54
+ this.name = "LZMAMemoryLimitError";
55
+ }
56
+ };
57
+ /**
58
+ * Format error - thrown when file format is not recognized
59
+ */
60
+ var LZMAFormatError = class extends LZMAError {
61
+ constructor(errno) {
62
+ super("File format not recognized", errno);
63
+ this.name = "LZMAFormatError";
64
+ }
65
+ };
66
+ /**
67
+ * Options error - thrown when invalid or unsupported options are provided
68
+ */
69
+ var LZMAOptionsError = class extends LZMAError {
70
+ constructor(errno) {
71
+ super("Invalid or unsupported options", errno);
72
+ this.name = "LZMAOptionsError";
73
+ }
74
+ };
75
+ /**
76
+ * Data error - thrown when compressed data is corrupt
77
+ */
78
+ var LZMADataError = class extends LZMAError {
79
+ constructor(errno) {
80
+ super("Data is corrupt", errno);
81
+ this.name = "LZMADataError";
82
+ }
83
+ };
84
+ /**
85
+ * Buffer error - thrown when no progress is possible (e.g., buffer too small)
86
+ */
87
+ var LZMABufferError = class extends LZMAError {
88
+ constructor(errno) {
89
+ super("No progress is possible", errno);
90
+ this.name = "LZMABufferError";
91
+ }
92
+ };
93
+ /**
94
+ * Programming error - thrown when there's an internal programming error
95
+ */
96
+ var LZMAProgrammingError = class extends LZMAError {
97
+ constructor(errno) {
98
+ super("Programming error", errno);
99
+ this.name = "LZMAProgrammingError";
100
+ }
101
+ };
102
+ /**
103
+ * Factory function to create appropriate error instance based on errno
104
+ */
105
+ function createLZMAError(errno, message) {
106
+ const LZMA_MEM_ERROR = 5;
107
+ const LZMA_MEMLIMIT_ERROR = 6;
108
+ const LZMA_FORMAT_ERROR = 7;
109
+ const LZMA_OPTIONS_ERROR = 8;
110
+ const LZMA_DATA_ERROR = 9;
111
+ const LZMA_BUF_ERROR = 10;
112
+ const LZMA_PROG_ERROR = 11;
113
+ switch (errno) {
114
+ case LZMA_MEM_ERROR: return new LZMAMemoryError(errno);
115
+ case LZMA_MEMLIMIT_ERROR: return new LZMAMemoryLimitError(errno);
116
+ case LZMA_FORMAT_ERROR: return new LZMAFormatError(errno);
117
+ case LZMA_OPTIONS_ERROR: return new LZMAOptionsError(errno);
118
+ case LZMA_DATA_ERROR: return new LZMADataError(errno);
119
+ case LZMA_BUF_ERROR: return new LZMABufferError(errno);
120
+ case LZMA_PROG_ERROR: return new LZMAProgrammingError(errno);
121
+ default: return new LZMAError(message || getErrorMessage(errno), errno);
122
+ }
123
+ }
124
+ /**
125
+ * Get error message for a given errno
126
+ */
127
+ function getErrorMessage(errno) {
128
+ const messages = [
129
+ "Operation completed successfully",
130
+ "End of stream was reached",
131
+ "Input stream has no integrity check",
132
+ "Cannot calculate the integrity check",
133
+ "Integrity check type is not available",
134
+ "Cannot allocate memory",
135
+ "Memory usage limit was reached",
136
+ "File format not recognized",
137
+ "Invalid or unsupported options",
138
+ "Data is corrupt",
139
+ "No progress is possible",
140
+ "Programming error"
141
+ ];
142
+ if (errno < 0 || errno >= messages.length) return `Unknown LZMA error code: ${errno}`;
143
+ return messages[errno];
144
+ }
145
+ /**
146
+ * node-liblzma - Node.js bindings for liblzma
147
+ * Copyright (C) Olivier Orabona <olivier.orabona@gmail.com>
148
+ *
149
+ * This program is free software: you can redistribute it and/or modify
150
+ * it under the terms of the GNU Lesser General Public License as published by
151
+ * the Free Software Foundation, either version 3 of the License, or
152
+ * (at your option) any later version.
153
+ *
154
+ * This program is distributed in the hope that it will be useful,
155
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
156
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
157
+ * GNU General Public License for more details.
158
+ *
159
+ * You should have received a copy of the GNU Lesser General Public License
160
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
161
+ */
162
+ /**
163
+ * LZMA Pool with concurrency control and event monitoring
164
+ *
165
+ * Provides rate limiting and backpressure for LZMA operations.
166
+ * Emits events for monitoring and metrics collection in production.
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * const pool = new LZMAPool(10); // Max 10 concurrent operations
171
+ *
172
+ * pool.on('metrics', (metrics) => {
173
+ * console.log(`Active: ${metrics.active}, Queued: ${metrics.queued}`);
174
+ * });
175
+ *
176
+ * const compressed = await pool.compress(buffer);
177
+ * ```
178
+ *
179
+ * Events:
180
+ * - 'queue': Emitted when task added to queue
181
+ * - 'start': Emitted when task starts processing
182
+ * - 'complete': Emitted when task completes successfully
183
+ * - 'error-task': Emitted when task fails
184
+ * - 'metrics': Emitted after each state change with current metrics
185
+ */
186
+ var LZMAPool = class extends EventEmitter {
187
+ /**
188
+ * Create a new LZMA pool
189
+ * @param maxConcurrent Maximum number of concurrent operations (default: 10)
190
+ */
191
+ constructor(maxConcurrent = 10) {
192
+ super();
193
+ this.maxConcurrent = maxConcurrent;
194
+ this.queue = [];
195
+ this.metrics = {
196
+ active: 0,
197
+ queued: 0,
198
+ completed: 0,
199
+ failed: 0
200
+ };
201
+ if (maxConcurrent < 1) throw new RangeError("maxConcurrent must be at least 1");
202
+ }
203
+ /**
204
+ * Compress data with automatic queue management
205
+ * @param data Buffer to compress
206
+ * @param opts LZMA compression options
207
+ * @returns Promise that resolves to compressed buffer
208
+ */
209
+ async compress(data, opts) {
210
+ return this.enqueue(() => xzAsync(data, opts));
211
+ }
212
+ /**
213
+ * Decompress data with automatic queue management
214
+ * @param data Compressed buffer to decompress
215
+ * @param opts LZMA decompression options
216
+ * @returns Promise that resolves to decompressed buffer
217
+ */
218
+ async decompress(data, opts) {
219
+ return this.enqueue(() => unxzAsync(data, opts));
220
+ }
221
+ /**
222
+ * Get current pool metrics
223
+ * @returns Copy of current metrics
224
+ */
225
+ getMetrics() {
226
+ return { ...this.metrics };
227
+ }
228
+ /**
229
+ * Get number of tasks waiting in queue
230
+ * @returns Queue length
231
+ */
232
+ get queueLength() {
233
+ return this.queue.length;
234
+ }
235
+ /**
236
+ * Get number of currently active tasks
237
+ * @returns Active task count
238
+ */
239
+ get activeCount() {
240
+ return this.metrics.active;
241
+ }
242
+ /**
243
+ * Check if pool is at maximum capacity
244
+ * @returns True if at capacity
245
+ */
246
+ get isAtCapacity() {
247
+ return this.metrics.active >= this.maxConcurrent;
248
+ }
249
+ /**
250
+ * Enqueue a task for execution
251
+ * @param fn Task function returning Promise<Buffer>
252
+ * @returns Promise that resolves when task completes
253
+ */
254
+ async enqueue(fn) {
255
+ return new Promise((resolve, reject) => {
256
+ this.queue.push({
257
+ fn,
258
+ resolve,
259
+ reject
260
+ });
261
+ this.metrics.queued = this.queue.length;
262
+ this.emit("queue", { ...this.metrics });
263
+ this.processQueue();
264
+ });
265
+ }
266
+ /**
267
+ * Process tasks from queue respecting concurrency limit
268
+ */
269
+ processQueue() {
270
+ if (this.metrics.active >= this.maxConcurrent || this.queue.length === 0) return;
271
+ const item = this.queue.shift();
272
+ /* c8 ignore next - should never happen because we check queue length before */
273
+ if (!item) return;
274
+ this.metrics.active++;
275
+ this.metrics.queued = this.queue.length;
276
+ this.emit("start", { ...this.metrics });
277
+ Promise.resolve().then(() => item.fn()).then((result) => {
278
+ this.metrics.completed++;
279
+ item.resolve(result);
280
+ this.emit("complete", { ...this.metrics });
281
+ }).catch((error) => {
282
+ this.metrics.failed++;
283
+ item.reject(error);
284
+ this.emit("error-task", error, { ...this.metrics });
285
+ }).finally(() => {
286
+ this.metrics.active--;
287
+ this.emit("metrics", { ...this.metrics });
288
+ this.processQueue();
289
+ });
290
+ }
291
+ /**
292
+ * Wait for all active tasks to complete
293
+ * Does not process new tasks added while waiting
294
+ * @returns Promise that resolves when all active tasks are done
295
+ */
296
+ async drain() {
297
+ if (this.metrics.active === 0) return Promise.resolve();
298
+ return new Promise((resolve) => {
299
+ const checkDrained = () => {
300
+ if (this.metrics.active === 0) {
301
+ this.off("metrics", checkDrained);
302
+ resolve();
303
+ }
304
+ };
305
+ this.on("metrics", checkDrained);
306
+ });
307
+ }
308
+ /**
309
+ * Clear all pending tasks from the queue
310
+ * Active tasks will continue to run
311
+ * @returns Number of tasks removed from queue
312
+ */
313
+ clearQueue() {
314
+ const cleared = this.queue.length;
315
+ const error = /* @__PURE__ */ new Error("Task cancelled: queue cleared");
316
+ for (const task of this.queue) task.reject(error);
317
+ this.queue = [];
318
+ this.metrics.queued = 0;
319
+ this.emit("metrics", { ...this.metrics });
320
+ return cleared;
321
+ }
322
+ };
323
+ /**
324
+ * node-liblzma - Node.js bindings for liblzma
325
+ * Copyright (C) Olivier Orabona <olivier.orabona@gmail.com>
326
+ *
327
+ * This program is free software: you can redistribute it and/or modify
328
+ * it under the terms of the GNU Lesser General Public License as published by
329
+ * the Free Software Foundation, either version 3 of the License, or
330
+ * (at your option) any later version.
331
+ *
332
+ * This program is distributed in the hope that it will be useful,
333
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
334
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
335
+ * GNU General Public License for more details.
336
+ *
337
+ * You should have received a copy of the GNU Lesser General Public License
338
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
339
+ */
340
+ var __filename = fileURLToPath(import.meta.url);
341
+ var __dirname = path$1.dirname(__filename);
342
+ var require = createRequire(import.meta.url);
343
+ var bindingPath = path$1.resolve(path$1.join(__dirname, ".."));
344
+ var liblzma = require("node-gyp-build")(bindingPath);
345
+ var maxThreads = os$1.cpus().length;
346
+ /**
347
+ * Integrity check types for XZ streams.
348
+ * Use CRC64 for best balance of speed and error detection.
349
+ * @example
350
+ * ```ts
351
+ * const compressor = createXz({ check: check.CRC64 });
352
+ * ```
353
+ */
354
+ const check = {
355
+ NONE: liblzma.LZMA_CHECK_NONE,
356
+ CRC32: liblzma.LZMA_CHECK_CRC32,
357
+ CRC64: liblzma.LZMA_CHECK_CRC64,
358
+ SHA256: liblzma.LZMA_CHECK_SHA256
359
+ };
360
+ /**
361
+ * Compression preset flags.
362
+ * Can be combined with preset level using bitwise OR.
363
+ * @example
364
+ * ```ts
365
+ * const compressor = createXz({ preset: 6 | preset.EXTREME });
366
+ * ```
367
+ */
368
+ const preset = {
369
+ DEFAULT: liblzma.LZMA_PRESET_DEFAULT,
370
+ EXTREME: liblzma.LZMA_PRESET_EXTREME
371
+ };
372
+ /**
373
+ * Decoder flags for controlling decompression behavior.
374
+ * @example
375
+ * ```ts
376
+ * const decompressor = createUnxz({ flushFlag: flag.CONCATENATED });
377
+ * ```
378
+ */
379
+ const flag = {
380
+ TELL_NO_CHECK: liblzma.LZMA_TELL_NO_CHECK,
381
+ TELL_UNSUPPORTED_CHECK: liblzma.LZMA_TELL_UNSUPPORTED_CHECK,
382
+ TELL_ANY_CHECK: liblzma.LZMA_TELL_ANY_CHECK,
383
+ CONCATENATED: liblzma.LZMA_CONCATENATED
384
+ };
385
+ /**
386
+ * Compression filters for preprocessing data before LZMA2.
387
+ * BCJ filters improve compression for executable code.
388
+ * @example
389
+ * ```ts
390
+ * // Compress x86 executable with BCJ filter
391
+ * const compressor = createXz({ filters: [filter.X86, filter.LZMA2] });
392
+ * ```
393
+ */
394
+ const filter = {
395
+ LZMA2: liblzma.LZMA_FILTER_LZMA2,
396
+ X86: liblzma.LZMA_FILTER_X86,
397
+ POWERPC: liblzma.LZMA_FILTER_POWERPC,
398
+ IA64: liblzma.LZMA_FILTER_IA64,
399
+ ARM: liblzma.LZMA_FILTER_ARM,
400
+ ARMTHUMB: liblzma.LZMA_FILTER_ARMTHUMB,
401
+ SPARC: liblzma.LZMA_FILTER_SPARC
402
+ };
403
+ /* v8 ignore next */
404
+ /**
405
+ * Compression mode selection.
406
+ * FAST uses less memory, NORMAL provides better compression.
407
+ */
408
+ const mode = {
409
+ FAST: liblzma.LZMA_MODE_FAST,
410
+ NORMAL: liblzma.LZMA_MODE_NORMAL
411
+ };
412
+ /* v8 ignore next 2 */
413
+ /**
414
+ * LZMA stream action constants.
415
+ * Control how the encoder/decoder processes input.
416
+ */
417
+ const LZMAAction = {
418
+ RUN: liblzma.LZMA_RUN,
419
+ SYNC_FLUSH: liblzma.LZMA_SYNC_FLUSH,
420
+ FULL_FLUSH: liblzma.LZMA_FULL_FLUSH,
421
+ FINISH: liblzma.LZMA_FINISH
422
+ };
423
+ /* v8 ignore next 2 */
424
+ /**
425
+ * LZMA operation status/return codes.
426
+ * Used to indicate the result of encoding/decoding operations.
427
+ */
428
+ const LZMAStatus = {
429
+ OK: liblzma.LZMA_OK,
430
+ STREAM_END: liblzma.LZMA_STREAM_END,
431
+ NO_CHECK: liblzma.LZMA_NO_CHECK,
432
+ UNSUPPORTED_CHECK: liblzma.LZMA_UNSUPPORTED_CHECK,
433
+ GET_CHECK: liblzma.LZMA_GET_CHECK,
434
+ MEM_ERROR: liblzma.LZMA_MEM_ERROR,
435
+ MEMLIMIT_ERROR: liblzma.LZMA_MEMLIMIT_ERROR,
436
+ FORMAT_ERROR: liblzma.LZMA_FORMAT_ERROR,
437
+ OPTIONS_ERROR: liblzma.LZMA_OPTIONS_ERROR,
438
+ DATA_ERROR: liblzma.LZMA_DATA_ERROR,
439
+ BUF_ERROR: liblzma.LZMA_BUF_ERROR,
440
+ PROG_ERROR: liblzma.LZMA_PROG_ERROR
441
+ };
442
+ const LZMAFilter = {
443
+ ...filter,
444
+ X86_ALT: liblzma.LZMA_FILTER_X86,
445
+ POWERPC_ALT: liblzma.LZMA_FILTER_POWERPC,
446
+ IA64_ALT: liblzma.LZMA_FILTER_IA64,
447
+ ARM_ALT: liblzma.LZMA_FILTER_ARM,
448
+ ARMTHUMB_ALT: liblzma.LZMA_FILTER_ARMTHUMB,
449
+ FILTERS_MAX: liblzma.LZMA_FILTERS_MAX
450
+ };
451
+ const LZMA_RUN = LZMAAction.RUN;
452
+ const LZMA_SYNC_FLUSH = LZMAAction.SYNC_FLUSH;
453
+ const LZMA_FULL_FLUSH = LZMAAction.FULL_FLUSH;
454
+ const LZMA_FINISH = LZMAAction.FINISH;
455
+ const LZMA_OK = LZMAStatus.OK;
456
+ const LZMA_STREAM_END = LZMAStatus.STREAM_END;
457
+ const LZMA_NO_CHECK = LZMAStatus.NO_CHECK;
458
+ const LZMA_UNSUPPORTED_CHECK = LZMAStatus.UNSUPPORTED_CHECK;
459
+ const LZMA_GET_CHECK = LZMAStatus.GET_CHECK;
460
+ const LZMA_MEM_ERROR = LZMAStatus.MEM_ERROR;
461
+ const LZMA_MEMLIMIT_ERROR = LZMAStatus.MEMLIMIT_ERROR;
462
+ const LZMA_FORMAT_ERROR = LZMAStatus.FORMAT_ERROR;
463
+ const LZMA_OPTIONS_ERROR = LZMAStatus.OPTIONS_ERROR;
464
+ const LZMA_DATA_ERROR = LZMAStatus.DATA_ERROR;
465
+ const LZMA_BUF_ERROR = LZMAStatus.BUF_ERROR;
466
+ const LZMA_PROG_ERROR = LZMAStatus.PROG_ERROR;
467
+ const LZMA_FILTER_X86 = LZMAFilter.X86_ALT;
468
+ const LZMA_FILTER_POWERPC = LZMAFilter.POWERPC_ALT;
469
+ const LZMA_FILTER_IA64 = LZMAFilter.IA64_ALT;
470
+ const LZMA_FILTER_ARM = LZMAFilter.ARM_ALT;
471
+ const LZMA_FILTER_ARMTHUMB = LZMAFilter.ARMTHUMB_ALT;
472
+ const LZMA_FILTERS_MAX = LZMAFilter.FILTERS_MAX;
473
+ /**
474
+ * Abstract base class for XZ compression/decompression streams.
475
+ * Extends Node.js Transform stream with LZMA2 encoding/decoding.
476
+ *
477
+ * @example
478
+ * ```ts
479
+ * // Use Xz or Unxz classes instead of XzStream directly
480
+ * const compressor = new Xz({ preset: 6 });
481
+ * readStream.pipe(compressor).pipe(writeStream);
482
+ * ```
483
+ *
484
+ * Emits `progress` event after each chunk with `{bytesRead, bytesWritten}` info.
485
+ */
486
+ var XzStream = class extends Transform {
487
+ constructor(streamMode, opts = {}, options) {
488
+ super(options);
489
+ let clonedFilters;
490
+ if (opts.filters) {
491
+ if (!Array.isArray(opts.filters)) throw new Error("Filters need to be in an array!");
492
+ try {
493
+ clonedFilters = [...opts.filters];
494
+ } catch (_error) {
495
+ throw new Error("Filters need to be in an array!");
496
+ }
497
+ } else clonedFilters = [filter.LZMA2];
498
+ this._opts = {
499
+ check: opts.check ?? check.NONE,
500
+ preset: opts.preset ?? preset.DEFAULT,
501
+ filters: clonedFilters,
502
+ mode: opts.mode ?? mode.NORMAL,
503
+ threads: opts.threads ?? 1,
504
+ chunkSize: opts.chunkSize ?? liblzma.BUFSIZ,
505
+ flushFlag: opts.flushFlag ?? liblzma.LZMA_RUN
506
+ };
507
+ this._chunkSize = this._opts.chunkSize;
508
+ this._flushFlag = this._opts.flushFlag;
509
+ assert.ok(Array.isArray(this._opts.filters), "Filters need to be in an array!");
510
+ /* v8 ignore next 2 */
511
+ if (this._opts.filters.indexOf(filter.LZMA2) === -1) this._opts.filters.push(filter.LZMA2);
512
+ const lzma2Index = this._opts.filters.indexOf(filter.LZMA2);
513
+ if (lzma2Index !== -1 && lzma2Index !== this._opts.filters.length - 1) {
514
+ this._opts.filters.splice(lzma2Index, 1);
515
+ this._opts.filters.push(filter.LZMA2);
516
+ }
517
+ if (streamMode === liblzma.STREAM_ENCODE) {
518
+ /* c8 ignore start */
519
+ if (!liblzma.HAS_THREADS_SUPPORT) this._opts.threads = 1;
520
+ /* c8 ignore stop */
521
+ if (this._opts.threads === 0) this._opts.threads = maxThreads;
522
+ }
523
+ this.lzma = new liblzma.LZMA(streamMode, this._opts);
524
+ this._closed = false;
525
+ this._hadError = false;
526
+ this._offset = 0;
527
+ this._buffer = Buffer.alloc(this._chunkSize);
528
+ this._bytesRead = 0;
529
+ this._bytesWritten = 0;
530
+ /* v8 ignore next */
531
+ this.on("onerror", (errno) => {
532
+ this._hadError = true;
533
+ const error = this._createLZMAError(errno);
534
+ this.emit("error", error);
535
+ });
536
+ /* v8 ignore next */
537
+ this.once("end", () => this.close());
538
+ }
539
+ _createLZMAError(errno) {
540
+ return createLZMAError(errno);
541
+ }
542
+ /** Get total bytes read from input so far */
543
+ get bytesRead() {
544
+ return this._bytesRead;
545
+ }
546
+ /** Get total bytes written to output so far */
547
+ get bytesWritten() {
548
+ return this._bytesWritten;
549
+ }
550
+ /**
551
+ * Emit a progress event with current bytesRead and bytesWritten
552
+ */
553
+ _emitProgress() {
554
+ const info = {
555
+ bytesRead: this._bytesRead,
556
+ bytesWritten: this._bytesWritten
557
+ };
558
+ this.emit("progress", info);
559
+ }
560
+ _reallocateBuffer() {
561
+ this._offset = 0;
562
+ this._buffer = Buffer.alloc(this._chunkSize);
563
+ }
564
+ flush(kindOrCallback, callback) {
565
+ const ws = this._writableState;
566
+ let kind;
567
+ let cb;
568
+ /* v8 ignore next */
569
+ if (typeof kindOrCallback === "function" || typeof kindOrCallback === "undefined" && !callback) {
570
+ cb = kindOrCallback;
571
+ kind = liblzma.LZMA_SYNC_FLUSH;
572
+ } else {
573
+ kind = kindOrCallback;
574
+ cb = callback;
575
+ }
576
+ if (ws.ended) {
577
+ if (cb) process.nextTick(cb);
578
+ } else if (ws.ending) {
579
+ if (cb) this.once("end", cb);
580
+ } else if (ws.needDrain) this.once("drain", () => {
581
+ this.flush(cb);
582
+ });
583
+ else {
584
+ this._flushFlag = kind;
585
+ this.write(Buffer.alloc(0), "utf8", cb);
586
+ }
587
+ }
588
+ close(callback) {
589
+ if (callback) process.nextTick(callback);
590
+ if (this._closed) return;
591
+ /* v8 ignore next */
592
+ this.lzma.close();
593
+ this._closed = true;
594
+ /* v8 ignore next */
595
+ process.nextTick(() => {
596
+ this.emit("close");
597
+ });
598
+ }
599
+ /* v8 ignore next */
600
+ _transform(chunk, _encoding, callback) {
601
+ const ws = this._writableState;
602
+ const last = (ws.ending || ws.ended) && (!chunk || ws.length === chunk.length);
603
+ if (chunk !== null && !(chunk instanceof Buffer)) {
604
+ callback(/* @__PURE__ */ new Error("invalid input"));
605
+ return;
606
+ }
607
+ if (this._closed) {
608
+ callback(/* @__PURE__ */ new Error("lzma binding closed"));
609
+ return;
610
+ }
611
+ if (chunk) this._bytesRead += chunk.length;
612
+ /* v8 ignore next */
613
+ let flushFlag;
614
+ if (last) flushFlag = liblzma.LZMA_FINISH;
615
+ else {
616
+ flushFlag = this._flushFlag;
617
+ if (chunk && chunk.length >= ws.length) this._flushFlag = this._opts.flushFlag;
618
+ }
619
+ /* v8 ignore next */
620
+ this._processChunk(chunk, flushFlag, callback);
621
+ }
622
+ _flush(callback) {
623
+ /* v8 ignore next 4 - Defensive check for double close scenario */
624
+ if (this._closed) {
625
+ process.nextTick(() => callback());
626
+ return;
627
+ }
628
+ this._transform(Buffer.alloc(0), "utf8", callback);
629
+ }
630
+ _processChunk(chunk, flushFlag, cb) {
631
+ const async = typeof cb === "function";
632
+ assert.ok(!this._closed, "Stream closed!");
633
+ let availInBefore = chunk?.length;
634
+ let availOutBefore = this._chunkSize - this._offset;
635
+ let inOff = 0;
636
+ /* v8 ignore next 3 */
637
+ if (!async) {
638
+ const buffers = [];
639
+ let nread = 0;
640
+ let error = null;
641
+ /* v8 ignore next */
642
+ const callback = (errno, availInAfter, availOutAfter) => {
643
+ /* v8 ignore start */
644
+ if (this._hadError) return false;
645
+ if (errno !== liblzma.LZMA_OK && errno !== liblzma.LZMA_STREAM_END) {
646
+ this.emit("onerror", errno);
647
+ return false;
648
+ }
649
+ /* v8 ignore stop */
650
+ const used = availOutBefore - availOutAfter;
651
+ assert.ok(used >= 0, `More bytes after than before! Delta = ${used}`);
652
+ if (used > 0) {
653
+ const out = this._buffer.subarray(this._offset, this._offset + used);
654
+ this._offset += used;
655
+ buffers.push(out);
656
+ nread += used;
657
+ }
658
+ /* v8 ignore start */
659
+ if (availOutAfter === 0 || this._offset >= this._chunkSize) {
660
+ availOutBefore = this._chunkSize;
661
+ this._reallocateBuffer();
662
+ }
663
+ if (availOutAfter === 0 || availInAfter > 0) {
664
+ inOff += (availInBefore ?? 0) - availInAfter;
665
+ availInBefore = availInAfter;
666
+ return true;
667
+ }
668
+ /* v8 ignore stop */
669
+ return false;
670
+ };
671
+ /* v8 ignore start */
672
+ this.on("error", (e) => {
673
+ error = e;
674
+ });
675
+ /* v8 ignore stop */
676
+ /* v8 ignore next - processing loop entry */
677
+ while (true) {
678
+ const [status, availInAfter, availOutAfter] = this.lzma.codeSync(flushFlag, chunk, inOff, availInBefore, this._buffer, this._offset);
679
+ /* v8 ignore start */
680
+ if (this._hadError || !callback(status, availInAfter, availOutAfter)) break;
681
+ }
682
+ try {
683
+ /* v8 ignore start */
684
+ if (this._hadError) throw error ?? /* @__PURE__ */ new Error("Unknown LZMA error");
685
+ return Buffer.concat(buffers, nread);
686
+ } finally {
687
+ /* v8 ignore next - cleanup path */
688
+ this.close();
689
+ }
690
+ }
691
+ const callback = (errno, availInAfter, availOutAfter) => {
692
+ /* v8 ignore next 3 - error state handling is difficult to test */
693
+ if (this._hadError) return false;
694
+ /* v8 ignore next 5 - async error path handling */
695
+ if (errno !== liblzma.LZMA_OK && errno !== liblzma.LZMA_STREAM_END) {
696
+ this.emit("onerror", errno);
697
+ return false;
698
+ }
699
+ /* v8 ignore next */
700
+ const used = availOutBefore - availOutAfter;
701
+ assert.ok(used >= 0, `More bytes after than before! Delta = ${used}`);
702
+ if (used > 0) {
703
+ const out = this._buffer.subarray(this._offset, this._offset + used);
704
+ this._offset += used;
705
+ this._bytesWritten += used;
706
+ this.push(out);
707
+ this._emitProgress();
708
+ }
709
+ if (availOutAfter === 0 || this._offset >= this._chunkSize) {
710
+ availOutBefore = this._chunkSize;
711
+ this._reallocateBuffer();
712
+ }
713
+ if (availOutAfter === 0 || availInAfter > 0) {
714
+ /* v8 ignore next 2 - complex async processing continuation */
715
+ inOff += (availInBefore ?? 0) - availInAfter;
716
+ availInBefore = availInAfter;
717
+ this.lzma.code(flushFlag, chunk, inOff, availInBefore, this._buffer, this._offset, callback);
718
+ return false;
719
+ }
720
+ if (cb && !this._closed) try {
721
+ cb();
722
+ } catch (_error) {
723
+ this.emit("onerror", liblzma.LZMA_PROG_ERROR);
724
+ }
725
+ return false;
726
+ };
727
+ this.lzma.code(flushFlag, chunk, inOff, availInBefore, this._buffer, this._offset, callback);
728
+ }
729
+ };
730
+ /**
731
+ * XZ compression stream.
732
+ * Compresses data using LZMA2 algorithm.
733
+ *
734
+ * @example
735
+ * ```ts
736
+ * const compressor = new Xz({ preset: 6 });
737
+ * input.pipe(compressor).pipe(output);
738
+ * ```
739
+ */
740
+ var Xz = class extends XzStream {
741
+ constructor(lzmaOptions, options) {
742
+ super(liblzma.STREAM_ENCODE, lzmaOptions, options);
743
+ }
744
+ };
745
+ /**
746
+ * XZ decompression stream.
747
+ * Decompresses data compressed with XZ/LZMA2.
748
+ *
749
+ * @example
750
+ * ```ts
751
+ * const decompressor = new Unxz();
752
+ * compressedInput.pipe(decompressor).pipe(output);
753
+ * ```
754
+ */
755
+ var Unxz = class extends XzStream {
756
+ constructor(lzmaOptions, options) {
757
+ super(liblzma.STREAM_DECODE, lzmaOptions, options);
758
+ }
759
+ };
760
+ /* v8 ignore next */
761
+ /**
762
+ * Create a new XZ compression stream.
763
+ * @param lzmaOptions - LZMA compression options
764
+ * @param options - Node.js Transform stream options
765
+ * @returns New Xz compression stream
766
+ *
767
+ * @example
768
+ * ```ts
769
+ * const compressor = createXz({ preset: 9 });
770
+ * ```
771
+ */
772
+ function createXz(lzmaOptions, options) {
773
+ return new Xz(lzmaOptions, options);
774
+ }
775
+ /* v8 ignore next */
776
+ /**
777
+ * Create a new XZ decompression stream.
778
+ * @param lzmaOptions - LZMA decompression options
779
+ * @param options - Node.js Transform stream options
780
+ * @returns New Unxz decompression stream
781
+ *
782
+ * @example
783
+ * ```ts
784
+ * const decompressor = createUnxz();
785
+ * ```
786
+ */
787
+ function createUnxz(lzmaOptions, options) {
788
+ return new Unxz(lzmaOptions, options);
789
+ }
790
+ /* v8 ignore next */
791
+ /**
792
+ * Check if liblzma was built with threading support.
793
+ * @returns true if multi-threaded compression is available
794
+ */
795
+ function hasThreads() {
796
+ return liblzma.HAS_THREADS_SUPPORT;
797
+ }
798
+ /**
799
+ * Check if a buffer contains XZ compressed data by examining magic bytes.
800
+ * @param buffer - Buffer to check (needs at least 6 bytes)
801
+ * @returns true if the buffer starts with XZ magic bytes
802
+ * @example
803
+ * ```ts
804
+ * const compressed = await xzAsync(Buffer.from('Hello'));
805
+ * console.log(isXZ(compressed)); // true
806
+ * console.log(isXZ(Buffer.from('Hello'))); // false
807
+ * ```
808
+ */
809
+ function isXZ(buffer) {
810
+ return liblzma.isXZ(buffer);
811
+ }
812
+ /**
813
+ * Get the runtime version of liblzma as a string.
814
+ * @returns Version string like "5.4.1"
815
+ * @example
816
+ * ```ts
817
+ * console.log(versionString()); // "5.4.1"
818
+ * ```
819
+ */
820
+ function versionString() {
821
+ return liblzma.versionString();
822
+ }
823
+ /**
824
+ * Get the runtime version of liblzma as a number.
825
+ * Format: MAJOR * 10000000 + MINOR * 10000 + PATCH * 10
826
+ * @returns Version number (e.g., 50040010 for 5.4.1)
827
+ * @example
828
+ * ```ts
829
+ * console.log(versionNumber()); // 50040010
830
+ * ```
831
+ */
832
+ function versionNumber() {
833
+ return liblzma.versionNumber();
834
+ }
835
+ /**
836
+ * Get the memory usage estimate for encoding with a given preset.
837
+ * @param presetLevel - Compression preset (0-9, optionally OR'd with preset.EXTREME)
838
+ * @returns Memory usage in bytes, or 0 if preset is invalid
839
+ * @example
840
+ * ```ts
841
+ * console.log(easyEncoderMemusage(6)); // ~104857600 (100 MB)
842
+ * console.log(easyEncoderMemusage(9 | preset.EXTREME)); // ~712507392 (680 MB)
843
+ * ```
844
+ */
845
+ function easyEncoderMemusage(presetLevel) {
846
+ return liblzma.easyEncoderMemusage(presetLevel);
847
+ }
848
+ /**
849
+ * Get the memory usage estimate for decoding.
850
+ * @returns Memory usage in bytes for decoder initialization
851
+ * @example
852
+ * ```ts
853
+ * console.log(easyDecoderMemusage()); // ~18874368 (18 MB)
854
+ * ```
855
+ */
856
+ function easyDecoderMemusage() {
857
+ return liblzma.easyDecoderMemusage();
858
+ }
859
+ /**
860
+ * Parse the index from a complete XZ file buffer to get metadata.
861
+ * This allows you to know the uncompressed size before decompressing.
862
+ * @param buffer - Complete XZ file buffer
863
+ * @returns Object with file metadata
864
+ * @throws Error if buffer is not a valid XZ stream
865
+ * @example
866
+ * ```ts
867
+ * const compressed = await xzAsync(largeBuffer);
868
+ * const info = parseFileIndex(compressed);
869
+ * console.log(`Uncompressed: ${info.uncompressedSize}, Compressed: ${info.compressedSize}`);
870
+ * console.log(`Ratio: ${(info.compressedSize / info.uncompressedSize * 100).toFixed(1)}%`);
871
+ * ```
872
+ */
873
+ function parseFileIndex(buffer) {
874
+ return liblzma.parseFileIndex(buffer);
875
+ }
876
+ /* v8 ignore next */
877
+ /**
878
+ * Human-readable error messages for LZMA status codes.
879
+ */
880
+ var LZMAErrorMessage;
881
+ (function(LZMAErrorMessage) {
882
+ LZMAErrorMessage["SUCCESS"] = "Operation completed successfully";
883
+ LZMAErrorMessage["STREAM_END"] = "End of stream was reached";
884
+ LZMAErrorMessage["NO_CHECK"] = "Input stream has no integrity check";
885
+ LZMAErrorMessage["UNSUPPORTED_CHECK"] = "Cannot calculate the integrity check";
886
+ LZMAErrorMessage["GET_CHECK"] = "Integrity check type is not available";
887
+ LZMAErrorMessage["MEM_ERROR"] = "Cannot allocate memory";
888
+ LZMAErrorMessage["MEMLIMIT_ERROR"] = "Memory usage limit was reached";
889
+ LZMAErrorMessage["FORMAT_ERROR"] = "File format not recognized";
890
+ LZMAErrorMessage["OPTIONS_ERROR"] = "Invalid or unsupported options";
891
+ LZMAErrorMessage["DATA_ERROR"] = "Data is corrupt";
892
+ LZMAErrorMessage["BUF_ERROR"] = "No progress is possible";
893
+ LZMAErrorMessage["PROG_ERROR"] = "Programming error";
894
+ })(LZMAErrorMessage || (LZMAErrorMessage = {}));
895
+ /**
896
+ * Array of error messages indexed by LZMA status code.
897
+ * @deprecated Use LZMAErrorMessage enum instead
898
+ */
899
+ const messages = [
900
+ LZMAErrorMessage.SUCCESS,
901
+ LZMAErrorMessage.STREAM_END,
902
+ LZMAErrorMessage.NO_CHECK,
903
+ LZMAErrorMessage.UNSUPPORTED_CHECK,
904
+ LZMAErrorMessage.GET_CHECK,
905
+ LZMAErrorMessage.MEM_ERROR,
906
+ LZMAErrorMessage.MEMLIMIT_ERROR,
907
+ LZMAErrorMessage.FORMAT_ERROR,
908
+ LZMAErrorMessage.OPTIONS_ERROR,
909
+ LZMAErrorMessage.DATA_ERROR,
910
+ LZMAErrorMessage.BUF_ERROR,
911
+ LZMAErrorMessage.PROG_ERROR
912
+ ];
913
+ function unxz(buffer, optsOrCallback, callback) {
914
+ let opts;
915
+ let cb;
916
+ /* v8 ignore next - simple parameter parsing */
917
+ if (typeof optsOrCallback === "function") {
918
+ cb = optsOrCallback;
919
+ opts = {};
920
+ } else {
921
+ opts = optsOrCallback;
922
+ cb = callback;
923
+ }
924
+ xzBuffer(new Unxz(opts), buffer, cb);
925
+ }
926
+ /**
927
+ * Decompress a buffer synchronously.
928
+ * @param buffer - Compressed data to decompress
929
+ * @param opts - LZMA decompression options
930
+ * @returns Decompressed data buffer
931
+ *
932
+ * @example
933
+ * ```ts
934
+ * const decompressed = unxzSync(compressedBuffer);
935
+ * ```
936
+ */
937
+ function unxzSync(buffer, opts) {
938
+ return xzBufferSync(new Unxz(opts), buffer);
939
+ }
940
+ function xz(buffer, optsOrCallback, callback) {
941
+ let opts;
942
+ let cb;
943
+ /* v8 ignore next - simple parameter parsing */
944
+ if (typeof optsOrCallback === "function") {
945
+ cb = optsOrCallback;
946
+ opts = {};
947
+ } else {
948
+ opts = optsOrCallback;
949
+ cb = callback;
950
+ }
951
+ xzBuffer(new Xz(opts), buffer, cb);
952
+ }
953
+ /**
954
+ * Compress a buffer synchronously.
955
+ * @param buffer - Data to compress
956
+ * @param opts - LZMA compression options
957
+ * @returns Compressed data buffer
958
+ *
959
+ * @example
960
+ * ```ts
961
+ * const compressed = xzSync(data, { preset: 9 });
962
+ * ```
963
+ */
964
+ function xzSync(buffer, opts) {
965
+ return xzBufferSync(new Xz(opts), buffer);
966
+ }
967
+ /**
968
+ * Compress a buffer asynchronously using Promise.
969
+ * @param buffer - Data to compress
970
+ * @param opts - LZMA compression options
971
+ * @returns Promise resolving to compressed data buffer
972
+ *
973
+ * @example
974
+ * ```ts
975
+ * const compressed = await xzAsync(data, { preset: 6 });
976
+ * ```
977
+ */
978
+ function xzAsync(buffer, opts) {
979
+ return new Promise((resolve, reject) => {
980
+ xz(buffer, opts || {}, (error, result) => {
981
+ /* v8 ignore next 3 - error handling is tested in callback-based tests */
982
+ if (error) reject(error);
983
+ else resolve(result);
984
+ });
985
+ });
986
+ }
987
+ /**
988
+ * Decompress a buffer asynchronously using Promise.
989
+ * @param buffer - Compressed data to decompress
990
+ * @param opts - LZMA decompression options
991
+ * @returns Promise resolving to decompressed data buffer
992
+ *
993
+ * @example
994
+ * ```ts
995
+ * const decompressed = await unxzAsync(compressedBuffer);
996
+ * console.log(decompressed.toString());
997
+ * ```
998
+ */
999
+ function unxzAsync(buffer, opts) {
1000
+ return new Promise((resolve, reject) => {
1001
+ unxz(buffer, opts || {}, (error, result) => {
1002
+ /* v8 ignore next 2 - error handling is tested in callback-based tests */
1003
+ if (error) reject(error);
1004
+ else resolve(result);
1005
+ });
1006
+ });
1007
+ }
1008
+ function xzBuffer(engine, buffer, callback) {
1009
+ const buffers = [];
1010
+ let nread = 0;
1011
+ const flow = () => {
1012
+ let chunk;
1013
+ while ((chunk = engine.read()) !== null) {
1014
+ buffers.push(chunk);
1015
+ nread += chunk.length;
1016
+ }
1017
+ engine.once("readable", flow);
1018
+ };
1019
+ const onEnd = () => {
1020
+ callback(null, Buffer.concat(buffers, nread));
1021
+ engine.close();
1022
+ };
1023
+ /* v8 ignore next 5 - error callback path */
1024
+ const onError = (err) => {
1025
+ engine.removeListener("end", onEnd);
1026
+ engine.removeListener("readable", flow);
1027
+ callback(err);
1028
+ };
1029
+ engine.on("error", onError);
1030
+ engine.on("end", onEnd);
1031
+ engine.end(buffer);
1032
+ flow();
1033
+ }
1034
+ function xzBufferSync(engine, buffer) {
1035
+ let buf;
1036
+ if (typeof buffer === "string") buf = Buffer.from(buffer);
1037
+ else if (buffer instanceof Buffer) buf = buffer;
1038
+ else throw new TypeError("Not a string or buffer");
1039
+ return engine._processChunk(buf, liblzma.LZMA_FINISH);
1040
+ }
1041
+ /**
1042
+ * Compress a file using XZ compression
1043
+ * @param inputPath Path to input file
1044
+ * @param outputPath Path to output compressed file
1045
+ * @param opts LZMA compression options
1046
+ * @returns Promise that resolves when compression is complete
1047
+ */
1048
+ async function xzFile(inputPath, outputPath, opts) {
1049
+ const input = createReadStream(inputPath);
1050
+ const output = createWriteStream(outputPath);
1051
+ await pipeline$1(input, createXz(opts), output);
1052
+ }
1053
+ /**
1054
+ * Decompress an XZ compressed file
1055
+ * @param inputPath Path to compressed input file
1056
+ * @param outputPath Path to output decompressed file
1057
+ * @param opts LZMA decompression options
1058
+ * @returns Promise that resolves when decompression is complete
1059
+ */
1060
+ async function unxzFile(inputPath, outputPath, opts) {
1061
+ const input = createReadStream(inputPath);
1062
+ const output = createWriteStream(outputPath);
1063
+ await pipeline$1(input, createUnxz(opts), output);
1064
+ }
1065
+ var lzma_default = {
1066
+ Xz,
1067
+ Unxz,
1068
+ XzStream,
1069
+ hasThreads,
1070
+ messages,
1071
+ check,
1072
+ preset,
1073
+ flag,
1074
+ filter,
1075
+ mode,
1076
+ createXz,
1077
+ createUnxz,
1078
+ unxz,
1079
+ unxzSync,
1080
+ xz,
1081
+ xzSync,
1082
+ xzAsync,
1083
+ unxzAsync,
1084
+ LZMA_RUN,
1085
+ LZMA_SYNC_FLUSH,
1086
+ LZMA_FULL_FLUSH,
1087
+ LZMA_FINISH,
1088
+ LZMA_OK,
1089
+ LZMA_STREAM_END,
1090
+ LZMA_NO_CHECK,
1091
+ LZMA_UNSUPPORTED_CHECK,
1092
+ LZMA_GET_CHECK,
1093
+ LZMA_MEM_ERROR,
1094
+ LZMA_MEMLIMIT_ERROR,
1095
+ LZMA_FORMAT_ERROR,
1096
+ LZMA_OPTIONS_ERROR,
1097
+ LZMA_DATA_ERROR,
1098
+ LZMA_BUF_ERROR,
1099
+ LZMA_PROG_ERROR,
1100
+ LZMA_FILTER_X86,
1101
+ LZMA_FILTER_POWERPC,
1102
+ LZMA_FILTER_IA64,
1103
+ LZMA_FILTER_ARM,
1104
+ LZMA_FILTER_ARMTHUMB,
1105
+ LZMA_FILTERS_MAX
1106
+ };
1107
+ export { xzSync as $, check as A, messages as B, LZMA_RUN as C, Unxz as D, LZMA_UNSUPPORTED_CHECK as E, filter as F, unxzAsync as G, parseFileIndex as H, flag as I, versionNumber as J, unxzFile as K, hasThreads as L, createXz as M, easyDecoderMemusage as N, Xz as O, easyEncoderMemusage as P, xzFile as Q, isXZ as R, LZMA_PROG_ERROR as S, LZMA_SYNC_FLUSH as T, preset as U, mode as V, unxz as W, xz as X, versionString as Y, xzAsync as Z, LZMA_MEMLIMIT_ERROR as _, LZMA_BUF_ERROR as a, LZMAMemoryError as at, LZMA_OK as b, LZMA_FILTER_ARM as c, LZMAProgrammingError as ct, LZMA_FILTER_POWERPC as d, LZMAPool as et, LZMA_FILTER_X86 as f, LZMA_GET_CHECK as g, LZMA_FULL_FLUSH as h, LZMAStatus as i, LZMAFormatError as it, createUnxz as j, XzStream as k, LZMA_FILTER_ARMTHUMB as l, LZMA_FORMAT_ERROR as m, LZMAErrorMessage as n, LZMADataError as nt, LZMA_DATA_ERROR as o, LZMAMemoryLimitError as ot, LZMA_FINISH as p, unxzSync as q, LZMAFilter as r, LZMAError as rt, LZMA_FILTERS_MAX as s, LZMAOptionsError as st, LZMAAction as t, LZMABufferError as tt, LZMA_FILTER_IA64 as u, LZMA_MEM_ERROR as v, LZMA_STREAM_END as w, LZMA_OPTIONS_ERROR as x, LZMA_NO_CHECK as y, lzma_default as z };