xz-compat 0.3.0 → 0.3.1

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.
@@ -24,8 +24,5 @@ interface NativeModule {
24
24
  * Returns null if not available or Node version is too old
25
25
  */
26
26
  export declare function tryLoadNative(): NativeModule | null;
27
- /**
28
- * Check if native acceleration is available
29
- */
30
27
  export declare function isNativeAvailable(): boolean;
31
28
  export {};
@@ -24,8 +24,5 @@ interface NativeModule {
24
24
  * Returns null if not available or Node version is too old
25
25
  */
26
26
  export declare function tryLoadNative(): NativeModule | null;
27
- /**
28
- * Check if native acceleration is available
29
- */
30
27
  export declare function isNativeAvailable(): boolean;
31
28
  export {};
@@ -35,83 +35,30 @@ var _require = typeof require === 'undefined' ? _module.default.createRequire(re
35
35
  var __dirname = _path.default.dirname(typeof __filename !== 'undefined' ? __filename : _url.default.fileURLToPath(require("url").pathToFileURL(__filename).toString()));
36
36
  // Get node_modules path (go up from dist/cjs to package root, then to node_modules)
37
37
  var nodeModulesPath = _path.default.join(__dirname, '..', '..', 'node_modules');
38
+ var major = +process.versions.node.split('.')[0];
38
39
  // Cache for native module loading result
39
- var nativeModule;
40
- var nodeVersionChecked = false;
41
- var nodeVersionSupported = false;
40
+ var nativeModule = null;
42
41
  var installationAttempted = false;
43
- /**
44
- * Check if Node.js version supports native module (14+)
45
- */ function checkNodeVersion() {
46
- if (nodeVersionChecked) return nodeVersionSupported;
47
- nodeVersionChecked = true;
48
- try {
49
- var version = process.versions.node;
50
- var major = parseInt(version.split('.')[0], 10);
51
- nodeVersionSupported = major >= 14;
52
- } catch (unused) {
53
- nodeVersionSupported = false;
54
- }
55
- return nodeVersionSupported;
56
- }
57
- /**
58
- * Install @napi-rs/lzma using install-module-linked
59
- */ function installNativeModule(callback) {
60
- // Only attempt installation once
61
- if (installationAttempted) {
62
- callback(new Error('Installation already attempted'));
63
- return;
64
- }
42
+ function tryLoadNative() {
43
+ if (major < 14) return null;
44
+ if (installationAttempted) return nativeModule;
65
45
  installationAttempted = true;
46
+ // check if installed already
66
47
  try {
67
- // eslint-disable-next-line @typescript-eslint/no-var-requires
68
- var installModule = _require('install-module-linked').default;
69
- console.log('Installing @napi-rs/lzma for native acceleration...');
70
- installModule('@napi-rs/lzma', nodeModulesPath, {}, function(err) {
71
- if (err) {
72
- console.warn('Failed to install @napi-rs/lzma:', err.message);
73
- } else {
74
- console.log('Successfully installed @napi-rs/lzma');
75
- }
76
- callback(err);
77
- });
78
- } catch (err) {
79
- callback(err);
80
- }
81
- }
82
- function tryLoadNative() {
83
- // Return cached result
84
- if (nativeModule !== undefined) return nativeModule;
85
- // Check Node version first
86
- if (!checkNodeVersion()) {
87
- nativeModule = null;
88
- return null;
89
- }
90
- // Try to load native module (it should be installed at module load time)
48
+ nativeModule = _require('@napi-rs/lzma');
49
+ return nativeModule;
50
+ } catch (unused) {}
51
+ // try to install
91
52
  try {
92
- // eslint-disable-next-line @typescript-eslint/no-require-imports
53
+ console.log('Installing @napi-rs/lzma for native acceleration...');
54
+ var installModule = _require('install-module-linked').default;
55
+ installModule.sync('@napi-rs/lzma', nodeModulesPath, {});
93
56
  nativeModule = _require('@napi-rs/lzma');
94
57
  return nativeModule;
95
58
  } catch (unused) {
96
- // Module not installed yet - return null
97
- nativeModule = null;
98
59
  return null;
99
60
  }
100
61
  }
101
- // At module load time, attempt to install @napi-rs/lzma on Node 14+
102
- // This is done asynchronously so it doesn't block module initialization
103
- if (checkNodeVersion()) {
104
- installNativeModule(function() {
105
- // Installation complete - clear cache and try to load
106
- nativeModule = undefined; // Clear cache to force re-check
107
- try {
108
- nativeModule = _require('@napi-rs/lzma');
109
- } catch (unused) {
110
- // Module still not available
111
- nativeModule = null;
112
- }
113
- });
114
- }
115
62
  function isNativeAvailable() {
116
63
  return tryLoadNative() !== null;
117
64
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/native.ts"],"sourcesContent":["/**\n * Native Acceleration Module\n *\n * Provides optional native acceleration via @napi-rs/lzma on Node.js 14+.\n * Falls back gracefully to pure JS implementation on older Node versions\n * or when the native module is not available.\n */\n\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\n// Get __dirname for ES modules\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\n// Get node_modules path (go up from dist/cjs to package root, then to node_modules)\nconst nodeModulesPath = path.join(__dirname, '..', '..', 'node_modules');\n\n// Cache for native module loading result\nlet nativeModule: NativeModule | null | undefined;\nlet nodeVersionChecked = false;\nlet nodeVersionSupported = false;\nlet installationAttempted = false;\n\ninterface NativeModule {\n xz: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n lzma: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n lzma2: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n}\n\n/**\n * Check if Node.js version supports native module (14+)\n */\nfunction checkNodeVersion(): boolean {\n if (nodeVersionChecked) return nodeVersionSupported;\n nodeVersionChecked = true;\n\n try {\n const version = process.versions.node;\n const major = parseInt(version.split('.')[0], 10);\n nodeVersionSupported = major >= 14;\n } catch {\n nodeVersionSupported = false;\n }\n\n return nodeVersionSupported;\n}\n\n/**\n * Install @napi-rs/lzma using install-module-linked\n */\nfunction installNativeModule(callback: (err: Error | null) => void): void {\n // Only attempt installation once\n if (installationAttempted) {\n callback(new Error('Installation already attempted'));\n return;\n }\n installationAttempted = true;\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const installModule = _require('install-module-linked').default;\n\n console.log('Installing @napi-rs/lzma for native acceleration...');\n installModule('@napi-rs/lzma', nodeModulesPath, {}, (err: Error | null) => {\n if (err) {\n console.warn('Failed to install @napi-rs/lzma:', err.message);\n } else {\n console.log('Successfully installed @napi-rs/lzma');\n }\n callback(err);\n });\n } catch (err) {\n callback(err as Error);\n }\n}\n\n/**\n * Try to load the native @napi-rs/lzma module\n * Returns null if not available or Node version is too old\n */\nexport function tryLoadNative(): NativeModule | null {\n // Return cached result\n if (nativeModule !== undefined) return nativeModule;\n\n // Check Node version first\n if (!checkNodeVersion()) {\n nativeModule = null;\n return null;\n }\n\n // Try to load native module (it should be installed at module load time)\n try {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n nativeModule = _require('@napi-rs/lzma') as NativeModule;\n return nativeModule;\n } catch {\n // Module not installed yet - return null\n nativeModule = null;\n return null;\n }\n}\n\n// At module load time, attempt to install @napi-rs/lzma on Node 14+\n// This is done asynchronously so it doesn't block module initialization\nif (checkNodeVersion()) {\n installNativeModule(() => {\n // Installation complete - clear cache and try to load\n nativeModule = undefined; // Clear cache to force re-check\n try {\n nativeModule = _require('@napi-rs/lzma') as NativeModule;\n } catch {\n // Module still not available\n nativeModule = null;\n }\n });\n}\n\n/**\n * Check if native acceleration is available\n */\nexport function isNativeAvailable(): boolean {\n return tryLoadNative() !== null;\n}\n"],"names":["isNativeAvailable","tryLoadNative","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","nodeModulesPath","join","nativeModule","nodeVersionChecked","nodeVersionSupported","installationAttempted","checkNodeVersion","version","process","versions","node","major","parseInt","split","installNativeModule","callback","Error","installModule","default","console","log","err","warn","message","undefined"],"mappings":"AAAA;;;;;;CAMC;;;;;;;;;;;QA6HeA;eAAAA;;QAxCAC;eAAAA;;;6DAnFG;2DACF;0DACD;;;;;;AAEhB,+BAA+B;AAC/B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;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AAoB;IACtBQ,oBAAoB;QAClB,sDAAsD;QACtDZ,eAAesB,WAAW,gCAAgC;QAC1D,IAAI;YACFtB,eAAeZ,SAAS;QAC1B,EAAE,eAAM;YACN,6BAA6B;YAC7BY,eAAe;QACjB;IACF;AACF;AAKO,SAASd;IACd,OAAOC,oBAAoB;AAC7B"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/native.ts"],"sourcesContent":["/**\n * Native Acceleration Module\n *\n * Provides optional native acceleration via @napi-rs/lzma on Node.js 14+.\n * Falls back gracefully to pure JS implementation on older Node versions\n * or when the native module is not available.\n */\n\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\n// Get __dirname for ES modules\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\n// Get node_modules path (go up from dist/cjs to package root, then to node_modules)\nconst nodeModulesPath = path.join(__dirname, '..', '..', 'node_modules');\nconst major = +process.versions.node.split('.')[0];\n\n// Cache for native module loading result\nlet nativeModule: NativeModule | null = null;\nlet installationAttempted = false;\n\ninterface NativeModule {\n xz: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n lzma: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n lzma2: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n}\n\n/**\n * Try to load the native @napi-rs/lzma module\n * Returns null if not available or Node version is too old\n */\nexport function tryLoadNative(): NativeModule | null {\n if (major < 14) return null;\n if (installationAttempted) return nativeModule;\n installationAttempted = true;\n\n // check if installed already\n try {\n nativeModule = _require('@napi-rs/lzma') as NativeModule;\n return nativeModule;\n } catch {}\n\n // try to install\n try {\n console.log('Installing @napi-rs/lzma for native acceleration...');\n const installModule = _require('install-module-linked').default;\n installModule.sync('@napi-rs/lzma', nodeModulesPath, {});\n nativeModule = _require('@napi-rs/lzma') as NativeModule;\n return nativeModule;\n } catch {\n return null;\n }\n}\n\nexport function isNativeAvailable(): boolean {\n return tryLoadNative() !== null;\n}\n"],"names":["isNativeAvailable","tryLoadNative","_require","require","Module","createRequire","__dirname","path","dirname","__filename","url","fileURLToPath","nodeModulesPath","join","major","process","versions","node","split","nativeModule","installationAttempted","console","log","installModule","default","sync"],"mappings":"AAAA;;;;;;CAMC;;;;;;;;;;;QA4DeA;eAAAA;;QAvBAC;eAAAA;;;6DAnCG;2DACF;0DACD;;;;;;AAEhB,+BAA+B;AAC/B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,YAAYC,aAAI,CAACC,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaC,YAAG,CAACC,aAAa,CAAC;AAElG,oFAAoF;AACpF,IAAMC,kBAAkBL,aAAI,CAACM,IAAI,CAACP,WAAW,MAAM,MAAM;AACzD,IAAMQ,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAElD,yCAAyC;AACzC,IAAIC,eAAoC;AACxC,IAAIC,wBAAwB;AAqBrB,SAASnB;IACd,IAAIa,QAAQ,IAAI,OAAO;IACvB,IAAIM,uBAAuB,OAAOD;IAClCC,wBAAwB;IAExB,6BAA6B;IAC7B,IAAI;QACFD,eAAejB,SAAS;QACxB,OAAOiB;IACT,EAAE,eAAM,CAAC;IAET,iBAAiB;IACjB,IAAI;QACFE,QAAQC,GAAG,CAAC;QACZ,IAAMC,gBAAgBrB,SAAS,yBAAyBsB,OAAO;QAC/DD,cAAcE,IAAI,CAAC,iBAAiBb,iBAAiB,CAAC;QACtDO,eAAejB,SAAS;QACxB,OAAOiB;IACT,EAAE,eAAM;QACN,OAAO;IACT;AACF;AAEO,SAASnB;IACd,OAAOC,oBAAoB;AAC7B"}
@@ -24,8 +24,5 @@ interface NativeModule {
24
24
  * Returns null if not available or Node version is too old
25
25
  */
26
26
  export declare function tryLoadNative(): NativeModule | null;
27
- /**
28
- * Check if native acceleration is available
29
- */
30
27
  export declare function isNativeAvailable(): boolean;
31
28
  export {};
@@ -12,88 +12,33 @@ const _require = typeof require === 'undefined' ? Module.createRequire(import.me
12
12
  const __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));
13
13
  // Get node_modules path (go up from dist/cjs to package root, then to node_modules)
14
14
  const nodeModulesPath = path.join(__dirname, '..', '..', 'node_modules');
15
+ const major = +process.versions.node.split('.')[0];
15
16
  // Cache for native module loading result
16
- let nativeModule;
17
- let nodeVersionChecked = false;
18
- let nodeVersionSupported = false;
17
+ let nativeModule = null;
19
18
  let installationAttempted = false;
20
- /**
21
- * Check if Node.js version supports native module (14+)
22
- */ function checkNodeVersion() {
23
- if (nodeVersionChecked) return nodeVersionSupported;
24
- nodeVersionChecked = true;
25
- try {
26
- const version = process.versions.node;
27
- const major = parseInt(version.split('.')[0], 10);
28
- nodeVersionSupported = major >= 14;
29
- } catch {
30
- nodeVersionSupported = false;
31
- }
32
- return nodeVersionSupported;
33
- }
34
- /**
35
- * Install @napi-rs/lzma using install-module-linked
36
- */ function installNativeModule(callback) {
37
- // Only attempt installation once
38
- if (installationAttempted) {
39
- callback(new Error('Installation already attempted'));
40
- return;
41
- }
42
- installationAttempted = true;
43
- try {
44
- // eslint-disable-next-line @typescript-eslint/no-var-requires
45
- const installModule = _require('install-module-linked').default;
46
- console.log('Installing @napi-rs/lzma for native acceleration...');
47
- installModule('@napi-rs/lzma', nodeModulesPath, {}, (err)=>{
48
- if (err) {
49
- console.warn('Failed to install @napi-rs/lzma:', err.message);
50
- } else {
51
- console.log('Successfully installed @napi-rs/lzma');
52
- }
53
- callback(err);
54
- });
55
- } catch (err) {
56
- callback(err);
57
- }
58
- }
59
19
  /**
60
20
  * Try to load the native @napi-rs/lzma module
61
21
  * Returns null if not available or Node version is too old
62
22
  */ export function tryLoadNative() {
63
- // Return cached result
64
- if (nativeModule !== undefined) return nativeModule;
65
- // Check Node version first
66
- if (!checkNodeVersion()) {
67
- nativeModule = null;
68
- return null;
69
- }
70
- // Try to load native module (it should be installed at module load time)
23
+ if (major < 14) return null;
24
+ if (installationAttempted) return nativeModule;
25
+ installationAttempted = true;
26
+ // check if installed already
71
27
  try {
72
- // eslint-disable-next-line @typescript-eslint/no-require-imports
28
+ nativeModule = _require('@napi-rs/lzma');
29
+ return nativeModule;
30
+ } catch {}
31
+ // try to install
32
+ try {
33
+ console.log('Installing @napi-rs/lzma for native acceleration...');
34
+ const installModule = _require('install-module-linked').default;
35
+ installModule.sync('@napi-rs/lzma', nodeModulesPath, {});
73
36
  nativeModule = _require('@napi-rs/lzma');
74
37
  return nativeModule;
75
38
  } catch {
76
- // Module not installed yet - return null
77
- nativeModule = null;
78
39
  return null;
79
40
  }
80
41
  }
81
- // At module load time, attempt to install @napi-rs/lzma on Node 14+
82
- // This is done asynchronously so it doesn't block module initialization
83
- if (checkNodeVersion()) {
84
- installNativeModule(()=>{
85
- // Installation complete - clear cache and try to load
86
- nativeModule = undefined; // Clear cache to force re-check
87
- try {
88
- nativeModule = _require('@napi-rs/lzma');
89
- } catch {
90
- // Module still not available
91
- nativeModule = null;
92
- }
93
- });
94
- }
95
- /**
96
- * Check if native acceleration is available
97
- */ export function isNativeAvailable() {
42
+ export function isNativeAvailable() {
98
43
  return tryLoadNative() !== null;
99
44
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/native.ts"],"sourcesContent":["/**\n * Native Acceleration Module\n *\n * Provides optional native acceleration via @napi-rs/lzma on Node.js 14+.\n * Falls back gracefully to pure JS implementation on older Node versions\n * or when the native module is not available.\n */\n\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\n// Get __dirname for ES modules\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\n// Get node_modules path (go up from dist/cjs to package root, then to node_modules)\nconst nodeModulesPath = path.join(__dirname, '..', '..', 'node_modules');\n\n// Cache for native module loading result\nlet nativeModule: NativeModule | null | undefined;\nlet nodeVersionChecked = false;\nlet nodeVersionSupported = false;\nlet installationAttempted = false;\n\ninterface NativeModule {\n xz: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n lzma: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n lzma2: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n}\n\n/**\n * Check if Node.js version supports native module (14+)\n */\nfunction checkNodeVersion(): boolean {\n if (nodeVersionChecked) return nodeVersionSupported;\n nodeVersionChecked = true;\n\n try {\n const version = process.versions.node;\n const major = parseInt(version.split('.')[0], 10);\n nodeVersionSupported = major >= 14;\n } catch {\n nodeVersionSupported = false;\n }\n\n return nodeVersionSupported;\n}\n\n/**\n * Install @napi-rs/lzma using install-module-linked\n */\nfunction installNativeModule(callback: (err: Error | null) => void): void {\n // Only attempt installation once\n if (installationAttempted) {\n callback(new Error('Installation already attempted'));\n return;\n }\n installationAttempted = true;\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const installModule = _require('install-module-linked').default;\n\n console.log('Installing @napi-rs/lzma for native acceleration...');\n installModule('@napi-rs/lzma', nodeModulesPath, {}, (err: Error | null) => {\n if (err) {\n console.warn('Failed to install @napi-rs/lzma:', err.message);\n } else {\n console.log('Successfully installed @napi-rs/lzma');\n }\n callback(err);\n });\n } catch (err) {\n callback(err as Error);\n }\n}\n\n/**\n * Try to load the native @napi-rs/lzma module\n * Returns null if not available or Node version is too old\n */\nexport function tryLoadNative(): NativeModule | null {\n // Return cached result\n if (nativeModule !== undefined) return nativeModule;\n\n // Check Node version first\n if (!checkNodeVersion()) {\n nativeModule = null;\n return null;\n }\n\n // Try to load native module (it should be installed at module load time)\n try {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n nativeModule = _require('@napi-rs/lzma') as NativeModule;\n return nativeModule;\n } catch {\n // Module not installed yet - return null\n nativeModule = null;\n return null;\n }\n}\n\n// At module load time, attempt to install @napi-rs/lzma on Node 14+\n// This is done asynchronously so it doesn't block module initialization\nif (checkNodeVersion()) {\n installNativeModule(() => {\n // Installation complete - clear cache and try to load\n nativeModule = undefined; // Clear cache to force re-check\n try {\n nativeModule = _require('@napi-rs/lzma') as NativeModule;\n } catch {\n // Module still not available\n nativeModule = null;\n }\n });\n}\n\n/**\n * Check if native acceleration is available\n */\nexport function isNativeAvailable(): boolean {\n return tryLoadNative() !== null;\n}\n"],"names":["Module","path","url","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","nodeModulesPath","join","nativeModule","nodeVersionChecked","nodeVersionSupported","installationAttempted","checkNodeVersion","version","process","versions","node","major","parseInt","split","installNativeModule","callback","Error","installModule","default","console","log","err","warn","message","tryLoadNative","undefined","isNativeAvailable"],"mappings":"AAAA;;;;;;CAMC,GAED,OAAOA,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,+BAA+B;AAC/B,MAAMC,WAAW,OAAOC,YAAY,cAAcJ,OAAOK,aAAa,CAAC,YAAYH,GAAG,IAAIE;AAC1F,MAAME,YAAYL,KAAKM,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaN,IAAIO,aAAa,CAAC,YAAYP,GAAG;AAEjH,oFAAoF;AACpF,MAAMQ,kBAAkBT,KAAKU,IAAI,CAACL,WAAW,MAAM,MAAM;AAEzD,yCAAyC;AACzC,IAAIM;AACJ,IAAIC,qBAAqB;AACzB,IAAIC,uBAAuB;A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7BS,eAAe;QACjB;IACF;AACF;AAEA;;CAEC,GACD,OAAO,SAASwB;IACd,OAAOF,oBAAoB;AAC7B"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/native.ts"],"sourcesContent":["/**\n * Native Acceleration Module\n *\n * Provides optional native acceleration via @napi-rs/lzma on Node.js 14+.\n * Falls back gracefully to pure JS implementation on older Node versions\n * or when the native module is not available.\n */\n\nimport Module from 'module';\nimport path from 'path';\nimport url from 'url';\n\n// Get __dirname for ES modules\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst __dirname = path.dirname(typeof __filename !== 'undefined' ? __filename : url.fileURLToPath(import.meta.url));\n\n// Get node_modules path (go up from dist/cjs to package root, then to node_modules)\nconst nodeModulesPath = path.join(__dirname, '..', '..', 'node_modules');\nconst major = +process.versions.node.split('.')[0];\n\n// Cache for native module loading result\nlet nativeModule: NativeModule | null = null;\nlet installationAttempted = false;\n\ninterface NativeModule {\n xz: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n lzma: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n lzma2: {\n decompressSync(input: Uint8Array): Buffer;\n decompress(input: Uint8Array, signal?: AbortSignal | null): Promise<Buffer>;\n };\n}\n\n/**\n * Try to load the native @napi-rs/lzma module\n * Returns null if not available or Node version is too old\n */\nexport function tryLoadNative(): NativeModule | null {\n if (major < 14) return null;\n if (installationAttempted) return nativeModule;\n installationAttempted = true;\n\n // check if installed already\n try {\n nativeModule = _require('@napi-rs/lzma') as NativeModule;\n return nativeModule;\n } catch {}\n\n // try to install\n try {\n console.log('Installing @napi-rs/lzma for native acceleration...');\n const installModule = _require('install-module-linked').default;\n installModule.sync('@napi-rs/lzma', nodeModulesPath, {});\n nativeModule = _require('@napi-rs/lzma') as NativeModule;\n return nativeModule;\n } catch {\n return null;\n }\n}\n\nexport function isNativeAvailable(): boolean {\n return tryLoadNative() !== null;\n}\n"],"names":["Module","path","url","_require","require","createRequire","__dirname","dirname","__filename","fileURLToPath","nodeModulesPath","join","major","process","versions","node","split","nativeModule","installationAttempted","tryLoadNative","console","log","installModule","default","sync","isNativeAvailable"],"mappings":"AAAA;;;;;;CAMC,GAED,OAAOA,YAAY,SAAS;AAC5B,OAAOC,UAAU,OAAO;AACxB,OAAOC,SAAS,MAAM;AAEtB,+BAA+B;AAC/B,MAAMC,WAAW,OAAOC,YAAY,cAAcJ,OAAOK,aAAa,CAAC,YAAYH,GAAG,IAAIE;AAC1F,MAAME,YAAYL,KAAKM,OAAO,CAAC,OAAOC,eAAe,cAAcA,aAAaN,IAAIO,aAAa,CAAC,YAAYP,GAAG;AAEjH,oFAAoF;AACpF,MAAMQ,kBAAkBT,KAAKU,IAAI,CAACL,WAAW,MAAM,MAAM;AACzD,MAAMM,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAElD,yCAAyC;AACzC,IAAIC,eAAoC;AACxC,IAAIC,wBAAwB;AAiB5B;;;CAGC,GACD,OAAO,SAASC;IACd,IAAIP,QAAQ,IAAI,OAAO;IACvB,IAAIM,uBAAuB,OAAOD;IAClCC,wBAAwB;IAExB,6BAA6B;IAC7B,IAAI;QACFD,eAAed,SAAS;QACxB,OAAOc;IACT,EAAE,OAAM,CAAC;IAET,iBAAiB;IACjB,IAAI;QACFG,QAAQC,GAAG,CAAC;QACZ,MAAMC,gBAAgBnB,SAAS,yBAAyBoB,OAAO;QAC/DD,cAAcE,IAAI,CAAC,iBAAiBd,iBAAiB,CAAC;QACtDO,eAAed,SAAS;QACxB,OAAOc;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAEA,OAAO,SAASQ;IACd,OAAON,oBAAoB;AAC7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xz-compat",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "XZ Decompression Library",
5
5
  "keywords": [
6
6
  "extract",