node-liblzma 1.1.9 → 2.0.3

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 (54) hide show
  1. package/.gitattributes +3 -0
  2. package/.release-it.json +7 -0
  3. package/.release-it.manual.json +7 -0
  4. package/.release-it.retry.json +3 -0
  5. package/CHANGELOG.md +271 -0
  6. package/History.md +20 -0
  7. package/README.md +750 -30
  8. package/RELEASING.md +131 -0
  9. package/binding.gyp +162 -436
  10. package/biome.json +81 -0
  11. package/index.d.ts +254 -0
  12. package/lib/errors.d.ts +72 -0
  13. package/lib/errors.d.ts.map +1 -0
  14. package/lib/errors.js +153 -0
  15. package/lib/errors.js.map +1 -0
  16. package/lib/lzma.d.ts +245 -0
  17. package/lib/lzma.d.ts.map +1 -0
  18. package/lib/lzma.js +626 -345
  19. package/lib/lzma.js.map +1 -0
  20. package/lib/pool.d.ts +123 -0
  21. package/lib/pool.d.ts.map +1 -0
  22. package/lib/pool.js +188 -0
  23. package/lib/pool.js.map +1 -0
  24. package/lib/types.d.ts +27 -0
  25. package/lib/types.d.ts.map +1 -0
  26. package/lib/types.js +5 -0
  27. package/lib/types.js.map +1 -0
  28. package/package.json +61 -22
  29. package/pnpm-workspace.yaml +3 -0
  30. package/prebuilds/darwin-x64/node-liblzma.node +0 -0
  31. package/prebuilds/linux-x64/node-liblzma.node +0 -0
  32. package/prebuilds/win32-x64/node-liblzma.node +0 -0
  33. package/scripts/analyze-coverage.js +132 -0
  34. package/scripts/build_xz_with_cmake.py +390 -0
  35. package/scripts/compare-coverage-tools.js +93 -0
  36. package/scripts/copy_dll.py +51 -0
  37. package/scripts/download_xz_from_github.py +376 -0
  38. package/src/bindings/node-liblzma.cpp +411 -229
  39. package/src/bindings/node-liblzma.hpp +101 -48
  40. package/src/errors.ts +167 -0
  41. package/src/lzma.ts +839 -0
  42. package/src/pool.ts +228 -0
  43. package/src/types.ts +30 -0
  44. package/tsconfig.json +50 -0
  45. package/vitest.config.istanbul.ts +29 -0
  46. package/vitest.config.monocart.ts +44 -0
  47. package/vitest.config.ts +52 -0
  48. package/xz-version.json +8 -0
  49. package/prebuilds/darwin-x64/node.napi.node +0 -0
  50. package/prebuilds/linux-x64/node.napi.node +0 -0
  51. package/prebuilds/win32-x64/node.napi.node +0 -0
  52. package/scripts/download_extract_deps.py +0 -29
  53. package/scripts/prebuildify.py +0 -13
  54. package/src/lzma.coffee +0 -344
package/biome.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.2.2/schema.json",
3
+ "vcs": {
4
+ "enabled": true,
5
+ "clientKind": "git",
6
+ "useIgnoreFile": true
7
+ },
8
+ "files": {
9
+ "includes": [
10
+ "**/src/**/*",
11
+ "**/test/**/*",
12
+ "**/*.ts",
13
+ "**/*.js",
14
+ "**/*.mts",
15
+ "**/*.cts",
16
+ "**/*.json",
17
+ "!**/lib/**/*",
18
+ "!**/build/**/*",
19
+ "!**/node_modules/**/*",
20
+ "!**/*.d.ts",
21
+ "!**/*.coffee"
22
+ ]
23
+ },
24
+ "formatter": {
25
+ "enabled": true,
26
+ "formatWithErrors": false,
27
+ "indentStyle": "space",
28
+ "indentWidth": 2,
29
+ "lineEnding": "lf",
30
+ "lineWidth": 100,
31
+ "attributePosition": "auto"
32
+ },
33
+ "assist": { "actions": { "source": { "organizeImports": "on" } } },
34
+ "linter": {
35
+ "enabled": true,
36
+ "rules": {
37
+ "recommended": true,
38
+ "correctness": {
39
+ "noUnusedVariables": "warn",
40
+ "noUnusedImports": "warn"
41
+ },
42
+ "style": {
43
+ "useConsistentArrayType": "error",
44
+ "useForOf": "warn",
45
+ "useTemplate": "warn"
46
+ },
47
+ "suspicious": {
48
+ "noExplicitAny": "warn",
49
+ "noArrayIndexKey": "warn"
50
+ },
51
+ "complexity": {
52
+ "noExcessiveCognitiveComplexity": "warn",
53
+ "noVoid": "off"
54
+ },
55
+ "performance": {
56
+ "noDelete": "warn"
57
+ }
58
+ }
59
+ },
60
+ "javascript": {
61
+ "formatter": {
62
+ "quoteStyle": "single",
63
+ "jsxQuoteStyle": "double",
64
+ "quoteProperties": "asNeeded",
65
+ "trailingCommas": "es5",
66
+ "semicolons": "always",
67
+ "arrowParentheses": "always",
68
+ "bracketSpacing": true,
69
+ "bracketSameLine": false,
70
+ "attributePosition": "auto"
71
+ }
72
+ },
73
+ "json": {
74
+ "formatter": {
75
+ "enabled": true
76
+ },
77
+ "linter": {
78
+ "enabled": true
79
+ }
80
+ }
81
+ }
package/index.d.ts ADDED
@@ -0,0 +1,254 @@
1
+ /**
2
+ * node-liblzma - Node.js bindings for liblzma
3
+ * TypeScript definitions
4
+ */
5
+
6
+ import { Transform, TransformOptions } from 'node:stream';
7
+
8
+ /** Internal callback for native LZMA operations */
9
+ export type NativeLZMACallback = (errno: number, availInAfter: number, availOutAfter: number) => boolean;
10
+
11
+ /** Interface for the native LZMA object */
12
+ export interface NativeLZMA {
13
+ /** Synchronous compression/decompression */
14
+ codeSync(
15
+ flushFlag: number,
16
+ chunk: Buffer | null,
17
+ inOff: number,
18
+ availInBefore: number | undefined,
19
+ buffer: Buffer,
20
+ offset: number
21
+ ): [number, number, number];
22
+
23
+ /** Asynchronous compression/decompression */
24
+ code(
25
+ flushFlag: number,
26
+ chunk: Buffer | null,
27
+ inOff: number,
28
+ availInBefore: number | undefined,
29
+ buffer: Buffer,
30
+ offset: number,
31
+ callback: NativeLZMACallback
32
+ ): void;
33
+
34
+ /** Close the LZMA stream */
35
+ close(): void;
36
+ }
37
+
38
+
39
+ export interface LZMAOptions {
40
+ /** Integrity check type */
41
+ check?: number;
42
+ /** Compression preset level */
43
+ preset?: number;
44
+ /** Array of filters to use */
45
+ filters?: number[];
46
+ /** Compression mode */
47
+ mode?: number;
48
+ /** Number of threads for compression (encoding only) */
49
+ threads?: number;
50
+ /** Chunk size for processing */
51
+ chunkSize?: number;
52
+ /** Flush flag to use */
53
+ flushFlag?: number;
54
+ }
55
+
56
+ export interface StreamOptions extends TransformOptions {
57
+ /** LZMA-specific options */
58
+ lzma?: LZMAOptions;
59
+ }
60
+
61
+ // Legacy string types for backward compatibility (deprecated)
62
+ export type CheckType = 'NONE' | 'CRC32' | 'CRC64' | 'SHA256';
63
+ export type PresetType = 'DEFAULT' | 'EXTREME';
64
+ export type FilterType = 'LZMA2' | 'X86' | 'POWERPC' | 'IA64' | 'ARM' | 'ARMTHUMB' | 'SPARC';
65
+ export type ModeType = 'FAST' | 'NORMAL';
66
+ export type FlagType = 'TELL_NO_CHECK' | 'TELL_UNSUPPORTED_CHECK' | 'TELL_ANY_CHECK' | 'CONCATENATED';
67
+
68
+ export type CompressionCallback = (error: Error | null, result?: Buffer) => void;
69
+
70
+ export declare abstract class XzStream extends Transform {
71
+ constructor(streamMode: number, opts?: LZMAOptions, options?: TransformOptions);
72
+
73
+ /** Flush the stream with specified flush type */
74
+ flush(callback?: () => void): void;
75
+ flush(kind: number, callback?: () => void): void;
76
+
77
+ /** Close the stream */
78
+ close(callback?: () => void): void;
79
+
80
+ _transform(chunk: Buffer | null, encoding: string, callback: (error?: Error) => void): void;
81
+ _flush(callback: () => void): void;
82
+ protected _processChunk(chunk: Buffer | null, flushFlag: number, callback?: (error?: Error) => void): Buffer | undefined;
83
+ }
84
+
85
+ export declare class Xz extends XzStream {
86
+ constructor(lzmaOptions?: LZMAOptions, options?: TransformOptions);
87
+ }
88
+
89
+ export declare class Unxz extends XzStream {
90
+ constructor(lzmaOptions?: LZMAOptions, options?: TransformOptions);
91
+ }
92
+
93
+ /** Check if threading support is available */
94
+ export declare function hasThreads(): boolean;
95
+
96
+ /** Create a compression stream */
97
+ export declare function createXz(lzmaOptions?: LZMAOptions, options?: TransformOptions): Xz;
98
+
99
+ /** Create a decompression stream */
100
+ export declare function createUnxz(lzmaOptions?: LZMAOptions, options?: TransformOptions): Unxz;
101
+
102
+ /** Compress a buffer asynchronously */
103
+ export declare function xz(buffer: Buffer | string, callback: CompressionCallback): void;
104
+ export declare function xz(buffer: Buffer | string, options: LZMAOptions, callback: CompressionCallback): void;
105
+
106
+ /** Decompress a buffer asynchronously */
107
+ export declare function unxz(buffer: Buffer | string, callback: CompressionCallback): void;
108
+ export declare function unxz(buffer: Buffer | string, options: LZMAOptions, callback: CompressionCallback): void;
109
+
110
+ /** Compress a buffer synchronously */
111
+ export declare function xzSync(buffer: Buffer | string, options?: LZMAOptions): Buffer;
112
+
113
+ /** Decompress a buffer synchronously */
114
+ export declare function unxzSync(buffer: Buffer | string, options?: LZMAOptions): Buffer;
115
+
116
+ /** Compress a buffer asynchronously using Promises */
117
+ export declare function xzAsync(buffer: Buffer | string, options?: LZMAOptions): Promise<Buffer>;
118
+
119
+ /** Decompress a buffer asynchronously using Promises */
120
+ export declare function unxzAsync(buffer: Buffer | string, options?: LZMAOptions): Promise<Buffer>;
121
+
122
+ /** Constants for integrity check types */
123
+ export declare const check: {
124
+ readonly NONE: number;
125
+ readonly CRC32: number;
126
+ readonly CRC64: number;
127
+ readonly SHA256: number;
128
+ };
129
+
130
+ /** Constants for compression presets */
131
+ export declare const preset: {
132
+ readonly DEFAULT: number;
133
+ readonly EXTREME: number;
134
+ };
135
+
136
+ /** Constants for compression modes */
137
+ export declare const mode: {
138
+ readonly FAST: number;
139
+ readonly NORMAL: number;
140
+ };
141
+
142
+ /** Constants for stream flags */
143
+ export declare const flag: {
144
+ readonly TELL_NO_CHECK: number;
145
+ readonly TELL_UNSUPPORTED_CHECK: number;
146
+ readonly TELL_ANY_CHECK: number;
147
+ readonly CONCATENATED: number;
148
+ };
149
+
150
+ /** Constants for compression filters */
151
+ export declare const filter: {
152
+ readonly LZMA2: number;
153
+ readonly X86: number;
154
+ readonly POWERPC: number;
155
+ readonly IA64: number;
156
+ readonly ARM: number;
157
+ readonly ARMTHUMB: number;
158
+ readonly SPARC: number;
159
+ };
160
+
161
+ /** LZMA error messages by error code */
162
+ export declare const messages: readonly string[];
163
+
164
+ // LZMA action constants
165
+ export declare const LZMA_RUN: number;
166
+ export declare const LZMA_SYNC_FLUSH: number;
167
+ export declare const LZMA_FULL_FLUSH: number;
168
+ export declare const LZMA_FINISH: number;
169
+
170
+ // LZMA status/error constants
171
+ export declare const LZMA_OK: number;
172
+ export declare const LZMA_STREAM_END: number;
173
+ export declare const LZMA_NO_CHECK: number;
174
+ export declare const LZMA_UNSUPPORTED_CHECK: number;
175
+ export declare const LZMA_GET_CHECK: number;
176
+ export declare const LZMA_MEM_ERROR: number;
177
+ export declare const LZMA_MEMLIMIT_ERROR: number;
178
+ export declare const LZMA_FORMAT_ERROR: number;
179
+ export declare const LZMA_OPTIONS_ERROR: number;
180
+ export declare const LZMA_DATA_ERROR: number;
181
+ export declare const LZMA_BUF_ERROR: number;
182
+ export declare const LZMA_PROG_ERROR: number;
183
+
184
+ // Additional filter constants
185
+ export declare const LZMA_FILTER_X86: number;
186
+ export declare const LZMA_FILTER_POWERPC: number;
187
+ export declare const LZMA_FILTER_IA64: number;
188
+ export declare const LZMA_FILTER_ARM: number;
189
+ export declare const LZMA_FILTER_ARMTHUMB: number;
190
+ export declare const LZMA_FILTERS_MAX: number;
191
+
192
+ // Grouped constants for better organization
193
+ export declare const LZMAAction: {
194
+ readonly RUN: number;
195
+ readonly SYNC_FLUSH: number;
196
+ readonly FULL_FLUSH: number;
197
+ readonly FINISH: number;
198
+ };
199
+
200
+ export declare const LZMAStatus: {
201
+ readonly OK: number;
202
+ readonly STREAM_END: number;
203
+ readonly NO_CHECK: number;
204
+ readonly UNSUPPORTED_CHECK: number;
205
+ readonly GET_CHECK: number;
206
+ readonly MEM_ERROR: number;
207
+ readonly MEMLIMIT_ERROR: number;
208
+ readonly FORMAT_ERROR: number;
209
+ readonly OPTIONS_ERROR: number;
210
+ readonly DATA_ERROR: number;
211
+ readonly BUF_ERROR: number;
212
+ readonly PROG_ERROR: number;
213
+ };
214
+
215
+ export declare const LZMAFilter: {
216
+ readonly LZMA2: number;
217
+ readonly X86: number;
218
+ readonly POWERPC: number;
219
+ readonly IA64: number;
220
+ readonly ARM: number;
221
+ readonly ARMTHUMB: number;
222
+ readonly SPARC: number;
223
+ readonly X86_ALT: number;
224
+ readonly POWERPC_ALT: number;
225
+ readonly IA64_ALT: number;
226
+ readonly ARM_ALT: number;
227
+ readonly ARMTHUMB_ALT: number;
228
+ readonly FILTERS_MAX: number;
229
+ };
230
+
231
+ // Error messages enum
232
+ export declare enum LZMAErrorMessage {
233
+ SUCCESS = 'Operation completed successfully',
234
+ STREAM_END = 'End of stream was reached',
235
+ NO_CHECK = 'Input stream has no integrity check',
236
+ UNSUPPORTED_CHECK = 'Cannot calculate the integrity check',
237
+ GET_CHECK = 'Integrity check type is not available',
238
+ MEM_ERROR = 'Cannot allocate memory',
239
+ MEMLIMIT_ERROR = 'Memory usage limit was reached',
240
+ FORMAT_ERROR = 'File format not recognized',
241
+ OPTIONS_ERROR = 'Invalid or unsupported options',
242
+ DATA_ERROR = 'Data is corrupt',
243
+ BUF_ERROR = 'No progress is possible',
244
+ PROG_ERROR = 'Programming error',
245
+ }
246
+
247
+ // Union types for better type safety
248
+ export type LZMAActionType = 0 | 1 | 2 | 3;
249
+ export type LZMAStatusType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;
250
+ export type CheckType = 0 | 1 | 4 | 10;
251
+ export type PresetType = 6 | 9;
252
+ export type FilterType = 0x21 | 0x03 | 0x04 | 0x06 | 0x07 | 0x08 | 0x09;
253
+ export type ModeType = 1 | 2;
254
+
@@ -0,0 +1,72 @@
1
+ /**
2
+ * node-liblzma - Node.js bindings for liblzma
3
+ * Copyright (C) Olivier Orabona <olivier.orabona@gmail.com>
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Lesser General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public License
16
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ /**
19
+ * Base class for all LZMA-related errors
20
+ */
21
+ export declare class LZMAError extends Error {
22
+ readonly errno: number;
23
+ readonly code: number;
24
+ constructor(message: string, errno: number);
25
+ }
26
+ /**
27
+ * Memory allocation error - thrown when LZMA cannot allocate required memory
28
+ */
29
+ export declare class LZMAMemoryError extends LZMAError {
30
+ constructor(errno: number);
31
+ }
32
+ /**
33
+ * Memory limit error - thrown when operation would exceed memory usage limit
34
+ */
35
+ export declare class LZMAMemoryLimitError extends LZMAError {
36
+ constructor(errno: number);
37
+ }
38
+ /**
39
+ * Format error - thrown when file format is not recognized
40
+ */
41
+ export declare class LZMAFormatError extends LZMAError {
42
+ constructor(errno: number);
43
+ }
44
+ /**
45
+ * Options error - thrown when invalid or unsupported options are provided
46
+ */
47
+ export declare class LZMAOptionsError extends LZMAError {
48
+ constructor(errno: number);
49
+ }
50
+ /**
51
+ * Data error - thrown when compressed data is corrupt
52
+ */
53
+ export declare class LZMADataError extends LZMAError {
54
+ constructor(errno: number);
55
+ }
56
+ /**
57
+ * Buffer error - thrown when no progress is possible (e.g., buffer too small)
58
+ */
59
+ export declare class LZMABufferError extends LZMAError {
60
+ constructor(errno: number);
61
+ }
62
+ /**
63
+ * Programming error - thrown when there's an internal programming error
64
+ */
65
+ export declare class LZMAProgrammingError extends LZMAError {
66
+ constructor(errno: number);
67
+ }
68
+ /**
69
+ * Factory function to create appropriate error instance based on errno
70
+ */
71
+ export declare function createLZMAError(errno: number, message?: string): LZMAError;
72
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,SAAgB,KAAK,EAAE,MAAM,CAAC;IAC9B,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAEjB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;CAO3C;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,SAAS;gBAChC,KAAK,EAAE,MAAM;CAI1B;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;gBACrC,KAAK,EAAE,MAAM;CAI1B;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,SAAS;gBAChC,KAAK,EAAE,MAAM;CAI1B;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;gBACjC,KAAK,EAAE,MAAM;CAI1B;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,SAAS;gBAC9B,KAAK,EAAE,MAAM;CAI1B;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,SAAS;gBAChC,KAAK,EAAE,MAAM;CAI1B;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;gBACrC,KAAK,EAAE,MAAM;CAI1B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAoC1E"}
package/lib/errors.js ADDED
@@ -0,0 +1,153 @@
1
+ /**
2
+ * node-liblzma - Node.js bindings for liblzma
3
+ * Copyright (C) Olivier Orabona <olivier.orabona@gmail.com>
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Lesser General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public License
16
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ /**
19
+ * Base class for all LZMA-related errors
20
+ */
21
+ export class LZMAError extends Error {
22
+ constructor(message, errno) {
23
+ super(message);
24
+ this.name = 'LZMAError';
25
+ this.errno = errno;
26
+ this.code = errno;
27
+ Error.captureStackTrace(this, this.constructor);
28
+ }
29
+ }
30
+ /**
31
+ * Memory allocation error - thrown when LZMA cannot allocate required memory
32
+ */
33
+ export class LZMAMemoryError extends LZMAError {
34
+ constructor(errno) {
35
+ super('Cannot allocate memory', errno);
36
+ this.name = 'LZMAMemoryError';
37
+ }
38
+ }
39
+ /**
40
+ * Memory limit error - thrown when operation would exceed memory usage limit
41
+ */
42
+ export class LZMAMemoryLimitError extends LZMAError {
43
+ constructor(errno) {
44
+ super('Memory usage limit was reached', errno);
45
+ this.name = 'LZMAMemoryLimitError';
46
+ }
47
+ }
48
+ /**
49
+ * Format error - thrown when file format is not recognized
50
+ */
51
+ export class LZMAFormatError extends LZMAError {
52
+ constructor(errno) {
53
+ super('File format not recognized', errno);
54
+ this.name = 'LZMAFormatError';
55
+ }
56
+ }
57
+ /**
58
+ * Options error - thrown when invalid or unsupported options are provided
59
+ */
60
+ export class LZMAOptionsError extends LZMAError {
61
+ constructor(errno) {
62
+ super('Invalid or unsupported options', errno);
63
+ this.name = 'LZMAOptionsError';
64
+ }
65
+ }
66
+ /**
67
+ * Data error - thrown when compressed data is corrupt
68
+ */
69
+ export class LZMADataError extends LZMAError {
70
+ constructor(errno) {
71
+ super('Data is corrupt', errno);
72
+ this.name = 'LZMADataError';
73
+ }
74
+ }
75
+ /**
76
+ * Buffer error - thrown when no progress is possible (e.g., buffer too small)
77
+ */
78
+ export class LZMABufferError extends LZMAError {
79
+ constructor(errno) {
80
+ super('No progress is possible', errno);
81
+ this.name = 'LZMABufferError';
82
+ }
83
+ }
84
+ /**
85
+ * Programming error - thrown when there's an internal programming error
86
+ */
87
+ export class LZMAProgrammingError extends LZMAError {
88
+ constructor(errno) {
89
+ super('Programming error', errno);
90
+ this.name = 'LZMAProgrammingError';
91
+ }
92
+ }
93
+ /**
94
+ * Factory function to create appropriate error instance based on errno
95
+ */
96
+ export function createLZMAError(errno, message) {
97
+ // LZMA error codes mapping
98
+ const LZMA_OK = 0;
99
+ const LZMA_STREAM_END = 1;
100
+ const LZMA_NO_CHECK = 2;
101
+ const LZMA_UNSUPPORTED_CHECK = 3;
102
+ const LZMA_GET_CHECK = 4;
103
+ const LZMA_MEM_ERROR = 5;
104
+ const LZMA_MEMLIMIT_ERROR = 6;
105
+ const LZMA_FORMAT_ERROR = 7;
106
+ const LZMA_OPTIONS_ERROR = 8;
107
+ const LZMA_DATA_ERROR = 9;
108
+ const LZMA_BUF_ERROR = 10;
109
+ const LZMA_PROG_ERROR = 11;
110
+ switch (errno) {
111
+ case LZMA_MEM_ERROR:
112
+ return new LZMAMemoryError(errno);
113
+ case LZMA_MEMLIMIT_ERROR:
114
+ return new LZMAMemoryLimitError(errno);
115
+ case LZMA_FORMAT_ERROR:
116
+ return new LZMAFormatError(errno);
117
+ case LZMA_OPTIONS_ERROR:
118
+ return new LZMAOptionsError(errno);
119
+ case LZMA_DATA_ERROR:
120
+ return new LZMADataError(errno);
121
+ case LZMA_BUF_ERROR:
122
+ return new LZMABufferError(errno);
123
+ case LZMA_PROG_ERROR:
124
+ return new LZMAProgrammingError(errno);
125
+ default: {
126
+ // For success codes and unknown errors, use base LZMAError
127
+ const errorMessage = message || getErrorMessage(errno);
128
+ return new LZMAError(errorMessage, errno);
129
+ }
130
+ }
131
+ }
132
+ /**
133
+ * Get error message for a given errno
134
+ */
135
+ function getErrorMessage(errno) {
136
+ const messages = [
137
+ 'Operation completed successfully',
138
+ 'End of stream was reached',
139
+ 'Input stream has no integrity check',
140
+ 'Cannot calculate the integrity check',
141
+ 'Integrity check type is not available',
142
+ 'Cannot allocate memory',
143
+ 'Memory usage limit was reached',
144
+ 'File format not recognized',
145
+ 'Invalid or unsupported options',
146
+ 'Data is corrupt',
147
+ 'No progress is possible',
148
+ 'Programming error',
149
+ ];
150
+ const messageIndex = Math.max(0, Math.min(errno, messages.length - 1));
151
+ return messages[messageIndex];
152
+ }
153
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAIlC,YAAY,OAAe,EAAE,KAAa;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,YAAY,KAAa;QACvB,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IACjD,YAAY,KAAa;QACvB,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,YAAY,KAAa;QACvB,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAC7C,YAAY,KAAa;QACvB,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;QA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