node-liblzma 2.0.3 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/History.md DELETED
@@ -1,79 +0,0 @@
1
- # History.md
2
-
3
- > **Note**: This file is deprecated. Please see [CHANGELOG.md](./CHANGELOG.md) for the current changelog following the [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) format.
4
-
5
- # 2.0.0
6
- * **Breaking**: Modernized testing framework from Mocha to Vitest
7
- * **Breaking**: Modernized stack from Coffeescript to Typescript
8
- * **Feature**: Added 100% code coverage (51 tests covering all statements, branches, functions, and lines)
9
- * **Feature**: Implemented automatic filter reordering (LZMA2 filter automatically moved to end as required by liblzma)
10
- * **Fix**: Resolved C++ exception handling issues with NAPI_DISABLE_CPP_EXCEPTIONS for better performance
11
- * **Fix**: Corrected memory management in async operations (Ref/Unref balance)
12
- * **Fix**: Fixed filter validation bug causing LZMA_OPTIONS_ERROR with multiple filters
13
- * **CI**: Consolidated GitHub Actions workflows from 5 separate workflows to 1 unified pipeline
14
- * **CI**: Enhanced caching strategy and matrix testing with conditional execution
15
- * **CI**: Added path filters to avoid unnecessary CI runs for documentation-only changes
16
- * **CI**: Optimized XZ source downloading with single download shared across all jobs
17
- * **Performance**: Improved async callback handling and error management
18
- * **Testing**: Added comprehensive edge case coverage including malformed inputs and threading tests
19
- * **Testing**: Enhanced TypeScript configuration for better test reliability
20
-
21
- # 1.1.9
22
- * Fix building if no prebuilt binary found
23
-
24
- # 1.1.7
25
- * Fix build system
26
- * Fix release system
27
- * Fix documentation
28
-
29
- # 1.1.0
30
- * Refactor to deprecate Nan in favor of N-API
31
- * Drop UBS building system to use standard `node-gyp`
32
- * Support building on Linux, MacOSX and Windows
33
- * Ability to build from preinstalled libraries as well as download from XZ website
34
- * Deprecate Travis CI and AppVeyor to use GitHub Workflows
35
-
36
- # 1.0.5
37
- * Added CI for OSX and Windows
38
- * Implemented use of node-pre-gyp instead of node-gyp
39
- * Better build script, bug fixing.
40
-
41
- # 1.0.3
42
- * Updated to latest versions of dependencies
43
- * NodeJS 6.x is now supported
44
-
45
- # 1.0.2
46
- * Fixed build.yml to work with new UBS 0.6.1.
47
-
48
- # 1.0.1
49
- * Fixed minor bugs
50
-
51
- # 1.0.0
52
- * All known bugs have been fixed
53
- * JS Library has been renamed to ```lzma```, no big deal :smile:
54
-
55
- # 0.5.0
56
- * Rewrote large parts with Nan so now it supports 0.12+, 3+, 4+
57
- * BUG: Apparently not anymore 0.10 ...
58
- * Fixed syntax in XzStream.coffee
59
-
60
- # 0.4.3
61
- * Changes in build system (now using ubs to compile/run tests)
62
- * Applied a fix for 'availInAfter' in stream callback, after [#6032](https://github.com/joyent/node/issues/6032)
63
- * Fixed bad variable init in binding module
64
-
65
- # 0.3.0
66
- * Added multithread support
67
- * ENABLE_MT is now available to compile with thread support
68
- * Added new test cases
69
-
70
- # 0.2.0
71
- * Bug fixes :)
72
- * Completed import of NodeJS Zlib API
73
- * Full sync support
74
- * Added new test cases (sync/async)
75
-
76
- # 0.1.0
77
- * Initial version
78
- * C++ binding support ENCODE/DECODE
79
- * Async support
package/RELEASING.md DELETED
@@ -1,131 +0,0 @@
1
- # Release Process
2
-
3
- ## Prerequisites
4
-
5
- 1. Ensure all tests pass: `pnpm test`
6
- 2. Ensure build succeeds: `pnpm build`
7
- 3. Ensure working directory is clean: `git status`
8
- 4. Ensure you're on `master` branch: `git branch`
9
- 5. Ensure you have npm credentials: `npm whoami`
10
-
11
- ## Standard Release
12
-
13
- ### Step 1: Run release-it locally
14
-
15
- ```bash
16
- # For patch release (1.1.9 → 1.1.10)
17
- pnpm release patch
18
-
19
- # For minor release (1.1.9 → 1.2.0)
20
- pnpm release minor
21
-
22
- # For major release (1.1.9 → 2.0.0)
23
- pnpm release major
24
- ```
25
-
26
- This will:
27
- 1. Update CHANGELOG.md (move [Unreleased] to new version section)
28
- 2. Bump version in package.json
29
- 3. Git commit with message "release: bump vX.Y.Z"
30
- 4. Create git tag vX.Y.Z
31
- 5. Push to GitHub
32
-
33
- ### Step 2: Wait for automated workflow
34
-
35
- GitHub Actions will automatically:
36
- 1. Run full test suite
37
- 2. Build prebuilds for all platforms (3 OS × 4 Node versions)
38
- 3. Publish to npm with provenance
39
- 4. Create GitHub release
40
-
41
- Monitor: https://github.com/oorabona/node-liblzma/actions
42
-
43
- ### Step 3: Verify release
44
-
45
- 1. Check npm: https://www.npmjs.com/package/node-liblzma
46
- 2. Check GitHub releases: https://github.com/oorabona/node-liblzma/releases
47
- 3. Test installation: `pnpm add node-liblzma@latest`
48
-
49
- ## Pre-release
50
-
51
- For alpha/beta/rc releases, use the pre-release workflow:
52
-
53
- ```bash
54
- # Trigger manually via GitHub UI
55
- # https://github.com/oorabona/node-liblzma/actions/workflows/pre-release.yml
56
- ```
57
-
58
- ## Hotfix Release
59
-
60
- For emergency patches on older versions:
61
-
62
- ```bash
63
- pnpm release:hotfix
64
- ```
65
-
66
- ## Dry Run (Test Before Release)
67
-
68
- Always test the release process without actually publishing:
69
-
70
- ```bash
71
- # Dry run mode (no git push, no npm publish)
72
- pnpm release major --dry-run
73
- ```
74
-
75
- This will:
76
- - Show you exactly what will happen
77
- - Update local files (you can review)
78
- - NOT push to GitHub
79
- - NOT publish to npm
80
-
81
- ## Troubleshooting
82
-
83
- ### release-it fails with "Not authenticated"
84
-
85
- Run: `npm login`
86
-
87
- ### Workflow fails with "NPM_TOKEN not found"
88
-
89
- Contact repository admin to add NPM_TOKEN secret to GitHub repository settings.
90
-
91
- ### Tag already exists
92
-
93
- Delete local and remote tag:
94
-
95
- ```bash
96
- git tag -d v2.0.0
97
- git push origin :refs/tags/v2.0.0
98
- ```
99
-
100
- Then re-run: `pnpm release`
101
-
102
- ### Wrong branch
103
-
104
- Ensure you're on `master`:
105
-
106
- ```bash
107
- git checkout master
108
- git pull origin master
109
- ```
110
-
111
- ## Release Architecture
112
-
113
- The release process uses a **separation of concerns** approach:
114
-
115
- 1. **Local (Developer)**: Version management via `@oorabona/release-it-preset`
116
- - Updates CHANGELOG.md
117
- - Bumps package.json version
118
- - Creates git tag
119
- - Pushes to GitHub
120
-
121
- 2. **CI/CD (GitHub Actions)**: Build and publishing via `release.yml`
122
- - Runs tests
123
- - Builds platform-specific prebuilds
124
- - Publishes to npm with provenance
125
- - Creates GitHub release
126
-
127
- This ensures:
128
- - Developer controls version and changelog
129
- - CI handles platform-specific builds (which can't be done locally)
130
- - Clear audit trail for releases
131
- - Automated quality gates before publishing
package/biome.json DELETED
@@ -1,81 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- onlyBuiltDependencies:
2
- - esbuild
3
- - simple-git-hooks
@@ -1,132 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from 'fs';
4
- import path from 'path';
5
-
6
- const COVERAGE_FILE = './coverage/coverage-final.json';
7
- const SOURCE_FILE = './src/lzma.ts';
8
-
9
- if (!fs.existsSync(COVERAGE_FILE)) {
10
- console.log("❌ Fichier de coverage non trouvé. Lancez `pnpm test -- --coverage` d'abord.");
11
- process.exit(1);
12
- }
13
-
14
- const coverage = JSON.parse(fs.readFileSync(COVERAGE_FILE, 'utf8'));
15
- const sourceLines = fs.readFileSync(SOURCE_FILE, 'utf8').split('\n');
16
-
17
- // Analyser le fichier principal
18
- const filePath = path.resolve(SOURCE_FILE);
19
- const data = coverage[filePath] || coverage[Object.keys(coverage)[0]];
20
-
21
- if (!data) {
22
- console.log('❌ Données de coverage non trouvées');
23
- process.exit(1);
24
- }
25
-
26
- console.log('🔍 ANALYSE DE PRÉCISION DU COVERAGE\n');
27
-
28
- // Fonctions non couvertes
29
- const uncoveredFunctions = Object.entries(data.f).filter(([, count]) => count === 0);
30
- console.log(`📊 FONCTIONS NON COUVERTES (${uncoveredFunctions.length}):`);
31
- uncoveredFunctions.forEach(([key, count]) => {
32
- const fn = data.fnMap[key];
33
- const startLine = fn.loc.start.line;
34
- const endLine = fn.loc.end.line;
35
-
36
- console.log(` Function ${key}: "${fn.name}" (lignes ${startLine}-${endLine})`);
37
- console.log(` Code: ${sourceLines[startLine - 1]?.trim() || 'N/A'}`);
38
-
39
- // Vérifier si c'est un artefact
40
- const isArtifact =
41
- sourceLines[startLine - 1]?.includes('/* v8 ignore') ||
42
- sourceLines[startLine - 1]?.includes('export const') ||
43
- fn.name.includes('anonymous');
44
-
45
- if (isArtifact) {
46
- console.log(` ⚠️ Probablement un artefact V8`);
47
- } else {
48
- console.log(` 🎯 VRAIE fonction non testée`);
49
- }
50
- console.log('');
51
- });
52
-
53
- // Statements non couverts
54
- const uncoveredStatements = Object.entries(data.s).filter(([, count]) => count === 0);
55
- console.log(`📊 STATEMENTS NON COUVERTS (${uncoveredStatements.length}):`);
56
- uncoveredStatements.slice(0, 10).forEach(([key, count]) => {
57
- const stmt = data.statementMap[key];
58
- const line = stmt.start.line;
59
-
60
- console.log(` Statement ${key}: ligne ${line}`);
61
- console.log(` Code: ${sourceLines[line - 1]?.trim() || 'N/A'}`);
62
-
63
- // Vérifier si c'est vraiment du code exécutable
64
- const codeLine = sourceLines[line - 1]?.trim() || '';
65
- const isIgnorable =
66
- codeLine.includes('/* v8 ignore') ||
67
- codeLine === '' ||
68
- codeLine.includes('//') ||
69
- codeLine === '}' ||
70
- codeLine === '{' ||
71
- codeLine.includes('export const');
72
-
73
- if (isIgnorable) {
74
- console.log(` ⚠️ Ligne probablement ignorable`);
75
- } else {
76
- console.log(` 🎯 VRAI code non testé`);
77
- }
78
- console.log('');
79
- });
80
-
81
- // Branches critiques non couvertes
82
- const uncoveredBranches = Object.entries(data.b)
83
- .filter(([, counts]) => counts.includes(0))
84
- .filter(([key]) => {
85
- const branch = data.branchMap[key];
86
- const line = sourceLines[branch.line - 1]?.trim() || '';
87
- return !line.includes('/* v8 ignore') && line.length > 0;
88
- });
89
-
90
- console.log(`📊 BRANCHES CRITIQUES NON COUVERTES (${uncoveredBranches.length}):`);
91
- uncoveredBranches.slice(0, 10).forEach(([key, counts]) => {
92
- const branch = data.branchMap[key];
93
- const line = branch.line;
94
-
95
- console.log(` Branch ${key}: ligne ${line} - ${counts}`);
96
- console.log(` Code: ${sourceLines[line - 1]?.trim() || 'N/A'}`);
97
- console.log(` Type: ${branch.type}`);
98
- console.log(` 🎯 VRAIE condition non testée`);
99
- console.log('');
100
- });
101
-
102
- console.log('💡 RÉSUMÉ:');
103
- console.log(
104
- ` - Fonctions vraiment non testées: ${
105
- uncoveredFunctions.filter(([key]) => {
106
- const fn = data.fnMap[key];
107
- return (
108
- !fn.name.includes('anonymous') &&
109
- !sourceLines[fn.loc.start.line - 1]?.includes('export const')
110
- );
111
- }).length
112
- }`
113
- );
114
-
115
- console.log(
116
- ` - Statements vraiment non testés: ${
117
- uncoveredStatements.filter(([key]) => {
118
- const stmt = data.statementMap[key];
119
- const codeLine = sourceLines[stmt.start.line - 1]?.trim() || '';
120
- return (
121
- !codeLine.includes('/* v8 ignore') &&
122
- codeLine !== '' &&
123
- !codeLine.includes('//') &&
124
- codeLine !== '}' &&
125
- codeLine !== '{' &&
126
- !codeLine.includes('export const')
127
- );
128
- }).length
129
- }`
130
- );
131
-
132
- console.log(` - Branches vraiment non testées: ${uncoveredBranches.length}`);
@@ -1,93 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from 'fs';
4
- import path from 'path';
5
-
6
- const V8_COVERAGE = './coverage/coverage-final.json';
7
- const MONOCART_DATA = './coverage-reports/coverage-data.js';
8
- const SOURCE_FILE = './src/lzma.ts';
9
-
10
- console.log('🔍 COMPARAISON V8 vs MONOCART\n');
11
-
12
- // Lire V8
13
- if (!fs.existsSync(V8_COVERAGE)) {
14
- console.log('❌ V8 coverage manquant');
15
- process.exit(1);
16
- }
17
- const v8Coverage = JSON.parse(fs.readFileSync(V8_COVERAGE, 'utf8'));
18
- const sourceLines = fs.readFileSync(SOURCE_FILE, 'utf8').split('\n');
19
- const filePath = path.resolve(SOURCE_FILE);
20
- const v8Data = v8Coverage[filePath] || v8Coverage[Object.keys(v8Coverage)[0]];
21
-
22
- // Lire Monocart
23
- if (!fs.existsSync(MONOCART_DATA)) {
24
- console.log('❌ Monocart data manquant');
25
- process.exit(1);
26
- }
27
-
28
- // Extraire les données Monocart du fichier JS
29
- const monocartContent = fs.readFileSync(MONOCART_DATA, 'utf8');
30
- const monocartMatch = monocartContent.match(/window\.reportData\s*=\s*'([^']+)'/);
31
- if (!monocartMatch) {
32
- console.log('❌ Format Monocart non reconnu');
33
- process.exit(1);
34
- }
35
-
36
- // Monocart utilise un format compressé, on doit le décoder
37
- console.log('⚠️ Monocart utilise un format de données compressé, analyse simplifiée...');
38
- const monocartData = { summary: null };
39
- const summaryData = monocartData.summary;
40
-
41
- console.log('📊 COMPARAISON GLOBALE:');
42
- console.log(
43
- `V8 : ${v8Data.s ? Object.values(v8Data.s).filter((x) => x > 0).length : 0} statements couverts / ${v8Data.s ? Object.keys(v8Data.s).length : 0} total`
44
- );
45
- console.log(
46
- `Monocart : ${summaryData.statements.covered} statements couverts / ${summaryData.statements.total} total`
47
- );
48
- console.log('');
49
-
50
- console.log(
51
- `V8 : ${v8Data.b ? Object.values(v8Data.b).filter((arr) => arr.every((x) => x > 0)).length : 0} branches couvertes / ${v8Data.b ? Object.keys(v8Data.b).length : 0} total`
52
- );
53
- console.log(
54
- `Monocart : ${summaryData.branches.covered} branches couvertes / ${summaryData.branches.total} total`
55
- );
56
- console.log('');
57
-
58
- console.log(
59
- `V8 : ${v8Data.f ? Object.values(v8Data.f).filter((x) => x > 0).length : 0} fonctions couvertes / ${v8Data.f ? Object.keys(v8Data.f).length : 0} total`
60
- );
61
- console.log(
62
- `Monocart : ${summaryData.functions.covered} fonctions couvertes / ${summaryData.functions.total} total`
63
- );
64
- console.log('');
65
-
66
- // Analyse des statements non couverts
67
- const v8UncoveredStmts = Object.entries(v8Data.s || {}).filter(([, count]) => count === 0);
68
- console.log(`🎯 V8 STATEMENTS NON COUVERTS: ${v8UncoveredStmts.length}`);
69
- v8UncoveredStmts.slice(0, 5).forEach(([key]) => {
70
- const stmt = v8Data.statementMap[key];
71
- const line = stmt.start.line;
72
- console.log(` Ligne ${line}: ${sourceLines[line - 1]?.trim() || 'N/A'}`);
73
- });
74
-
75
- console.log('\n💡 VERDICT:');
76
- if (summaryData.statements.total !== Object.keys(v8Data.s || {}).length) {
77
- console.log('⚠️ Monocart détecte un nombre différent de statements');
78
- }
79
-
80
- const v8Pct = (
81
- (Object.values(v8Data.s || {}).filter((x) => x > 0).length / Object.keys(v8Data.s || {}).length) *
82
- 100
83
- ).toFixed(2);
84
- const monocartPct = summaryData.statements.pct;
85
-
86
- console.log(`V8 : ${v8Pct}% statements coverage`);
87
- console.log(`Monocart : ${monocartPct}% statements coverage`);
88
-
89
- if (Math.abs(parseFloat(monocartPct) - parseFloat(v8Pct)) > 1) {
90
- console.log('✨ Monocart montre une différence significative !');
91
- } else {
92
- console.log('📊 Résultats similaires entre V8 et Monocart');
93
- }
package/src/errors.ts DELETED
@@ -1,167 +0,0 @@
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
- /**
20
- * Base class for all LZMA-related errors
21
- */
22
- export class LZMAError extends Error {
23
- public readonly errno: number;
24
- public readonly code: number;
25
-
26
- constructor(message: string, errno: number) {
27
- super(message);
28
- this.name = 'LZMAError';
29
- this.errno = errno;
30
- this.code = errno;
31
- Error.captureStackTrace(this, this.constructor);
32
- }
33
- }
34
-
35
- /**
36
- * Memory allocation error - thrown when LZMA cannot allocate required memory
37
- */
38
- export class LZMAMemoryError extends LZMAError {
39
- constructor(errno: number) {
40
- super('Cannot allocate memory', errno);
41
- this.name = 'LZMAMemoryError';
42
- }
43
- }
44
-
45
- /**
46
- * Memory limit error - thrown when operation would exceed memory usage limit
47
- */
48
- export class LZMAMemoryLimitError extends LZMAError {
49
- constructor(errno: number) {
50
- super('Memory usage limit was reached', errno);
51
- this.name = 'LZMAMemoryLimitError';
52
- }
53
- }
54
-
55
- /**
56
- * Format error - thrown when file format is not recognized
57
- */
58
- export class LZMAFormatError extends LZMAError {
59
- constructor(errno: number) {
60
- super('File format not recognized', errno);
61
- this.name = 'LZMAFormatError';
62
- }
63
- }
64
-
65
- /**
66
- * Options error - thrown when invalid or unsupported options are provided
67
- */
68
- export class LZMAOptionsError extends LZMAError {
69
- constructor(errno: number) {
70
- super('Invalid or unsupported options', errno);
71
- this.name = 'LZMAOptionsError';
72
- }
73
- }
74
-
75
- /**
76
- * Data error - thrown when compressed data is corrupt
77
- */
78
- export class LZMADataError extends LZMAError {
79
- constructor(errno: number) {
80
- super('Data is corrupt', errno);
81
- this.name = 'LZMADataError';
82
- }
83
- }
84
-
85
- /**
86
- * Buffer error - thrown when no progress is possible (e.g., buffer too small)
87
- */
88
- export class LZMABufferError extends LZMAError {
89
- constructor(errno: number) {
90
- super('No progress is possible', errno);
91
- this.name = 'LZMABufferError';
92
- }
93
- }
94
-
95
- /**
96
- * Programming error - thrown when there's an internal programming error
97
- */
98
- export class LZMAProgrammingError extends LZMAError {
99
- constructor(errno: number) {
100
- super('Programming error', errno);
101
- this.name = 'LZMAProgrammingError';
102
- }
103
- }
104
-
105
- /**
106
- * Factory function to create appropriate error instance based on errno
107
- */
108
- export function createLZMAError(errno: number, message?: string): LZMAError {
109
- // LZMA error codes mapping
110
- const LZMA_OK = 0;
111
- const LZMA_STREAM_END = 1;
112
- const LZMA_NO_CHECK = 2;
113
- const LZMA_UNSUPPORTED_CHECK = 3;
114
- const LZMA_GET_CHECK = 4;
115
- const LZMA_MEM_ERROR = 5;
116
- const LZMA_MEMLIMIT_ERROR = 6;
117
- const LZMA_FORMAT_ERROR = 7;
118
- const LZMA_OPTIONS_ERROR = 8;
119
- const LZMA_DATA_ERROR = 9;
120
- const LZMA_BUF_ERROR = 10;
121
- const LZMA_PROG_ERROR = 11;
122
-
123
- switch (errno) {
124
- case LZMA_MEM_ERROR:
125
- return new LZMAMemoryError(errno);
126
- case LZMA_MEMLIMIT_ERROR:
127
- return new LZMAMemoryLimitError(errno);
128
- case LZMA_FORMAT_ERROR:
129
- return new LZMAFormatError(errno);
130
- case LZMA_OPTIONS_ERROR:
131
- return new LZMAOptionsError(errno);
132
- case LZMA_DATA_ERROR:
133
- return new LZMADataError(errno);
134
- case LZMA_BUF_ERROR:
135
- return new LZMABufferError(errno);
136
- case LZMA_PROG_ERROR:
137
- return new LZMAProgrammingError(errno);
138
- default: {
139
- // For success codes and unknown errors, use base LZMAError
140
- const errorMessage = message || getErrorMessage(errno);
141
- return new LZMAError(errorMessage, errno);
142
- }
143
- }
144
- }
145
-
146
- /**
147
- * Get error message for a given errno
148
- */
149
- function getErrorMessage(errno: number): string {
150
- const messages = [
151
- 'Operation completed successfully',
152
- 'End of stream was reached',
153
- 'Input stream has no integrity check',
154
- 'Cannot calculate the integrity check',
155
- 'Integrity check type is not available',
156
- 'Cannot allocate memory',
157
- 'Memory usage limit was reached',
158
- 'File format not recognized',
159
- 'Invalid or unsupported options',
160
- 'Data is corrupt',
161
- 'No progress is possible',
162
- 'Programming error',
163
- ];
164
-
165
- const messageIndex = Math.max(0, Math.min(errno, messages.length - 1));
166
- return messages[messageIndex];
167
- }