7z-iterator 1.1.0 → 1.1.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.
- package/dist/cjs/sevenz/codecs/Lzma.d.cts +1 -4
- package/dist/cjs/sevenz/codecs/Lzma.d.ts +1 -4
- package/dist/cjs/sevenz/codecs/Lzma.js +2 -30
- package/dist/cjs/sevenz/codecs/Lzma.js.map +1 -1
- package/dist/cjs/sevenz/codecs/Lzma2.d.cts +0 -3
- package/dist/cjs/sevenz/codecs/Lzma2.d.ts +0 -3
- package/dist/cjs/sevenz/codecs/Lzma2.js +0 -10
- package/dist/cjs/sevenz/codecs/Lzma2.js.map +1 -1
- package/dist/esm/sevenz/codecs/Lzma.d.ts +1 -4
- package/dist/esm/sevenz/codecs/Lzma.js +2 -33
- package/dist/esm/sevenz/codecs/Lzma.js.map +1 -1
- package/dist/esm/sevenz/codecs/Lzma2.d.ts +0 -3
- package/dist/esm/sevenz/codecs/Lzma2.js +1 -18
- package/dist/esm/sevenz/codecs/Lzma2.js.map +1 -1
- package/package.json +1 -5
- package/dist/cjs/sevenz/codecs/lzmaCompat.d.cts +0 -41
- package/dist/cjs/sevenz/codecs/lzmaCompat.d.ts +0 -41
- package/dist/cjs/sevenz/codecs/lzmaCompat.js +0 -66
- package/dist/cjs/sevenz/codecs/lzmaCompat.js.map +0 -1
- package/dist/esm/sevenz/codecs/lzmaCompat.d.ts +0 -41
- package/dist/esm/sevenz/codecs/lzmaCompat.js +0 -65
- package/dist/esm/sevenz/codecs/lzmaCompat.js.map +0 -1
|
@@ -10,8 +10,5 @@ import type { Transform } from 'readable-stream';
|
|
|
10
10
|
export declare function decodeLzma(input: Buffer, properties?: Buffer, unpackSize?: number): Buffer;
|
|
11
11
|
/**
|
|
12
12
|
* Create an LZMA decoder Transform stream
|
|
13
|
-
*
|
|
14
|
-
* Uses native lzma-native when available for better performance,
|
|
15
|
-
* falls back to lzma-purejs buffering decoder for Node.js 0.8+ compatibility.
|
|
16
13
|
*/
|
|
17
|
-
export declare function createLzmaDecoder(properties?: Buffer,
|
|
14
|
+
export declare function createLzmaDecoder(properties?: Buffer, unpackSize?: number): Transform;
|
|
@@ -10,8 +10,5 @@ import type { Transform } from 'readable-stream';
|
|
|
10
10
|
export declare function decodeLzma(input: Buffer, properties?: Buffer, unpackSize?: number): Buffer;
|
|
11
11
|
/**
|
|
12
12
|
* Create an LZMA decoder Transform stream
|
|
13
|
-
*
|
|
14
|
-
* Uses native lzma-native when available for better performance,
|
|
15
|
-
* falls back to lzma-purejs buffering decoder for Node.js 0.8+ compatibility.
|
|
16
13
|
*/
|
|
17
|
-
export declare function createLzmaDecoder(properties?: Buffer,
|
|
14
|
+
export declare function createLzmaDecoder(properties?: Buffer, unpackSize?: number): Transform;
|
|
@@ -18,7 +18,6 @@ _export(exports, {
|
|
|
18
18
|
});
|
|
19
19
|
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
20
20
|
var _createBufferingDecoderts = /*#__PURE__*/ _interop_require_default(require("./createBufferingDecoder.js"));
|
|
21
|
-
var _lzmaCompatts = require("./lzmaCompat.js");
|
|
22
21
|
var _streamsts = require("./streams.js");
|
|
23
22
|
function _interop_require_default(obj) {
|
|
24
23
|
return obj && obj.__esModule ? obj : {
|
|
@@ -30,24 +29,6 @@ var _require = typeof require === 'undefined' ? _module.default.createRequire(re
|
|
|
30
29
|
// Path accounts for build output in dist/esm/sevenz/codecs/
|
|
31
30
|
var LZMA = _require('../../../../assets/lzma-purejs').LZMA;
|
|
32
31
|
var LzmaDecoder = LZMA.Decoder;
|
|
33
|
-
/**
|
|
34
|
-
* Parse LZMA properties from 5-byte buffer
|
|
35
|
-
* First byte: lc + lp*9 + pb*45
|
|
36
|
-
* Next 4 bytes: dictionary size (little-endian)
|
|
37
|
-
*/ function parseLzmaProperties(properties) {
|
|
38
|
-
var propByte = properties[0];
|
|
39
|
-
var lc = propByte % 9;
|
|
40
|
-
var remainder = Math.floor(propByte / 9);
|
|
41
|
-
var lp = remainder % 5;
|
|
42
|
-
var pb = Math.floor(remainder / 5);
|
|
43
|
-
var dictSize = properties.readUInt32LE(1);
|
|
44
|
-
return {
|
|
45
|
-
lc: lc,
|
|
46
|
-
lp: lp,
|
|
47
|
-
pb: pb,
|
|
48
|
-
dictSize: dictSize
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
32
|
function decodeLzma(input, properties, unpackSize) {
|
|
52
33
|
if (!properties || properties.length < 5) {
|
|
53
34
|
throw new Error('LZMA requires 5-byte properties');
|
|
@@ -68,16 +49,7 @@ function decodeLzma(input, properties, unpackSize) {
|
|
|
68
49
|
}
|
|
69
50
|
return outStream.toBuffer();
|
|
70
51
|
}
|
|
71
|
-
function createLzmaDecoder(properties,
|
|
72
|
-
|
|
73
|
-
if (_lzmaCompatts.hasNativeLzma && properties && properties.length >= 5) {
|
|
74
|
-
var props = parseLzmaProperties(properties);
|
|
75
|
-
var nativeDecoder = (0, _lzmaCompatts.createNativeLzma1Decoder)(props.lc, props.lp, props.pb, props.dictSize);
|
|
76
|
-
if (nativeDecoder) {
|
|
77
|
-
return nativeDecoder;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// Fall back to buffering decoder with pure JS implementation
|
|
81
|
-
return (0, _createBufferingDecoderts.default)(decodeLzma, properties, _unpackSize);
|
|
52
|
+
function createLzmaDecoder(properties, unpackSize) {
|
|
53
|
+
return (0, _createBufferingDecoderts.default)(decodeLzma, properties, unpackSize);
|
|
82
54
|
}
|
|
83
55
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Lzma.ts"],"sourcesContent":["import Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// LZMA codec
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Lzma.ts"],"sourcesContent":["import Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// LZMA codec using lzma-purejs\n// LZMA properties in 7z are 5 bytes: 1 byte lc/lp/pb + 4 bytes dictionary size (little-endian)\n\nimport type { Transform } from 'readable-stream';\nimport createBufferingDecoder from './createBufferingDecoder.ts';\nimport { createInputStream, createOutputStream } from './streams.ts';\n\n// Import vendored lzma-purejs - provides raw LZMA decoder (patched for LZMA2 support)\n// Path accounts for build output in dist/esm/sevenz/codecs/\nconst { LZMA } = _require('../../../../assets/lzma-purejs');\nconst LzmaDecoder = LZMA.Decoder;\n\n/**\n * Decode LZMA compressed data to buffer\n *\n * @param input - LZMA compressed data\n * @param properties - Properties buffer (5 bytes: lc/lp/pb + dict size)\n * @param unpackSize - Expected output size (optional, -1 for unknown)\n * @returns Decompressed data\n */\nexport function decodeLzma(input: Buffer, properties?: Buffer, unpackSize?: number): Buffer {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n\n const decoder = new LzmaDecoder();\n\n // setDecoderProperties expects array-like with 5 bytes\n if (!decoder.setDecoderProperties(properties)) {\n throw new Error('Invalid LZMA properties');\n }\n\n const inStream = createInputStream(input, 0, input.length);\n\n // Use -1 for unknown size (decoder will use end marker)\n const size = typeof unpackSize === 'number' ? unpackSize : -1;\n\n // Pre-allocate output stream if size is known (memory optimization)\n const outStream = createOutputStream(size > 0 ? size : undefined);\n\n const success = decoder.code(inStream, outStream, size);\n if (!success) {\n throw new Error('LZMA decompression failed');\n }\n\n return outStream.toBuffer();\n}\n\n/**\n * Create an LZMA decoder Transform stream\n */\nexport function createLzmaDecoder(properties?: Buffer, unpackSize?: number): Transform {\n return createBufferingDecoder(decodeLzma, properties, unpackSize);\n}\n"],"names":["createLzmaDecoder","decodeLzma","_require","require","Module","createRequire","LZMA","LzmaDecoder","Decoder","input","properties","unpackSize","length","Error","decoder","setDecoderProperties","inStream","createInputStream","size","outStream","createOutputStream","undefined","success","code","toBuffer","createBufferingDecoder"],"mappings":";;;;;;;;;;;QAuDgBA;eAAAA;;QA/BAC;eAAAA;;;6DAxBG;+EAQgB;yBACmB;;;;;;AAPtD,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAS1F,sFAAsF;AACtF,4DAA4D;AAC5D,IAAM,AAAEG,OAASJ,SAAS,kCAAlBI;AACR,IAAMC,cAAcD,KAAKE,OAAO;AAUzB,SAASP,WAAWQ,KAAa,EAAEC,UAAmB,EAAEC,UAAmB;IAChF,IAAI,CAACD,cAAcA,WAAWE,MAAM,GAAG,GAAG;QACxC,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAMC,UAAU,IAAIP;IAEpB,uDAAuD;IACvD,IAAI,CAACO,QAAQC,oBAAoB,CAACL,aAAa;QAC7C,MAAM,IAAIG,MAAM;IAClB;IAEA,IAAMG,WAAWC,IAAAA,4BAAiB,EAACR,OAAO,GAAGA,MAAMG,MAAM;IAEzD,wDAAwD;IACxD,IAAMM,OAAO,OAAOP,eAAe,WAAWA,aAAa,CAAC;IAE5D,oEAAoE;IACpE,IAAMQ,YAAYC,IAAAA,6BAAkB,EAACF,OAAO,IAAIA,OAAOG;IAEvD,IAAMC,UAAUR,QAAQS,IAAI,CAACP,UAAUG,WAAWD;IAClD,IAAI,CAACI,SAAS;QACZ,MAAM,IAAIT,MAAM;IAClB;IAEA,OAAOM,UAAUK,QAAQ;AAC3B;AAKO,SAASxB,kBAAkBU,UAAmB,EAAEC,UAAmB;IACxE,OAAOc,IAAAA,iCAAsB,EAACxB,YAAYS,YAAYC;AACxD"}
|
|
@@ -10,8 +10,5 @@ import type { Transform } from 'readable-stream';
|
|
|
10
10
|
export declare function decodeLzma2(input: Buffer, properties?: Buffer, unpackSize?: number): Buffer;
|
|
11
11
|
/**
|
|
12
12
|
* Create an LZMA2 decoder Transform stream
|
|
13
|
-
*
|
|
14
|
-
* Uses native lzma-native when available for better performance,
|
|
15
|
-
* falls back to lzma-purejs buffering decoder for Node.js 0.8+ compatibility.
|
|
16
13
|
*/
|
|
17
14
|
export declare function createLzma2Decoder(properties?: Buffer, unpackSize?: number): Transform;
|
|
@@ -10,8 +10,5 @@ import type { Transform } from 'readable-stream';
|
|
|
10
10
|
export declare function decodeLzma2(input: Buffer, properties?: Buffer, unpackSize?: number): Buffer;
|
|
11
11
|
/**
|
|
12
12
|
* Create an LZMA2 decoder Transform stream
|
|
13
|
-
*
|
|
14
|
-
* Uses native lzma-native when available for better performance,
|
|
15
|
-
* falls back to lzma-purejs buffering decoder for Node.js 0.8+ compatibility.
|
|
16
13
|
*/
|
|
17
14
|
export declare function createLzma2Decoder(properties?: Buffer, unpackSize?: number): Transform;
|
|
@@ -19,7 +19,6 @@ _export(exports, {
|
|
|
19
19
|
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
20
20
|
var _extractbaseiterator = require("extract-base-iterator");
|
|
21
21
|
var _createBufferingDecoderts = /*#__PURE__*/ _interop_require_default(require("./createBufferingDecoder.js"));
|
|
22
|
-
var _lzmaCompatts = require("./lzmaCompat.js");
|
|
23
22
|
var _streamsts = require("./streams.js");
|
|
24
23
|
function _interop_require_default(obj) {
|
|
25
24
|
return obj && obj.__esModule ? obj : {
|
|
@@ -219,15 +218,6 @@ function decodeLzma2(input, properties, unpackSize) {
|
|
|
219
218
|
return Buffer.concat(outputChunks);
|
|
220
219
|
}
|
|
221
220
|
function createLzma2Decoder(properties, unpackSize) {
|
|
222
|
-
// Try native decoder first (available on Node.js 8+ with lzma-native installed)
|
|
223
|
-
if (_lzmaCompatts.hasNativeLzma && properties && properties.length >= 1) {
|
|
224
|
-
var dictSize = decodeDictionarySize(properties[0]);
|
|
225
|
-
var nativeDecoder = (0, _lzmaCompatts.createNativeLzma2Decoder)(dictSize);
|
|
226
|
-
if (nativeDecoder) {
|
|
227
|
-
return nativeDecoder;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
// Fall back to buffering decoder with pure JS implementation
|
|
231
221
|
return (0, _createBufferingDecoderts.default)(decodeLzma2, properties, unpackSize);
|
|
232
222
|
}
|
|
233
223
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Lzma2.ts"],"sourcesContent":["import Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// LZMA2 codec - uses native lzma-native when available, falls back to lzma-purejs\n// LZMA2 is a container format that wraps LZMA chunks with framing\n//\n// LZMA2 format specification:\n// https://github.com/ulikunitz/xz/blob/master/doc/LZMA2.md\n//\n// Control byte values:\n// 0x00 = End of stream\n// 0x01 = Uncompressed chunk, dictionary reset\n// 0x02 = Uncompressed chunk, no dictionary reset\n// 0x80-0xFF = LZMA compressed chunk (bits encode reset flags and size)\n//\n// Native optimization: On Node.js 8+, lzma-native provides liblzma bindings\n// that decode LZMA2 streams natively for better performance.\n// Falls back to lzma-purejs for Node.js 0.8-7.x compatibility.\n\nimport { allocBufferUnsafe } from 'extract-base-iterator';\nimport type { Transform } from 'readable-stream';\nimport createBufferingDecoder from './createBufferingDecoder.ts';\nimport { createNativeLzma2Decoder, hasNativeLzma } from './lzmaCompat.ts';\nimport { createInputStream, createOutputStream } from './streams.ts';\n\n// Import vendored lzma-purejs - provides raw LZMA decoder (patched for LZMA2 support)\n// Path accounts for build output in dist/esm/sevenz/codecs/\nconst { LZMA } = _require('../../../../assets/lzma-purejs');\nconst LzmaDecoder = LZMA.Decoder;\n\n/**\n * Decode LZMA2 dictionary size from properties byte\n * Properties byte encodes dictionary size as: 2^(dictByte/2 + 12) or similar\n *\n * Per XZ spec, dictionary sizes are:\n * 0x00 = 4 KiB (2^12)\n * 0x01 = 6 KiB\n * 0x02 = 8 KiB (2^13)\n * ...\n * 0x28 = 1.5 GiB\n */\nfunction decodeDictionarySize(propByte: number): number {\n if (propByte > 40) {\n throw new Error(`Invalid LZMA2 dictionary size property: ${propByte}`);\n }\n if (propByte === 40) {\n // Max dictionary size: 4 GiB - 1\n return 0xffffffff;\n }\n // Dictionary size = 2 | (propByte & 1) << (propByte / 2 + 11)\n const base = 2 | (propByte & 1);\n const shift = Math.floor(propByte / 2) + 11;\n return base << shift;\n}\n\n/**\n * Decode LZMA2 compressed data to buffer\n *\n * @param input - LZMA2 compressed data\n * @param properties - Properties buffer (1 byte: dictionary size)\n * @param unpackSize - Expected output size (used for pre-allocation to reduce memory)\n * @returns Decompressed data\n */\nexport function decodeLzma2(input: Buffer, properties?: Buffer, unpackSize?: number): Buffer {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n\n const dictSize = decodeDictionarySize(properties[0]);\n\n // Memory optimization: pre-allocate output buffer if size is known\n // This avoids double-memory during Buffer.concat\n let outputBuffer: Buffer | null = null;\n let outputPos = 0;\n const outputChunks: Buffer[] = [];\n\n if (unpackSize && unpackSize > 0) {\n outputBuffer = allocBufferUnsafe(unpackSize);\n }\n\n let offset = 0;\n\n // LZMA decoder instance - reused across chunks\n // The vendored decoder supports setSolid() for LZMA2 state preservation\n // The decoder also has _nowPos64 which tracks cumulative position for rep0 validation\n // and _prevByte which is used for literal decoder context selection\n const decoder = new LzmaDecoder() as InstanceType<typeof LzmaDecoder> & {\n setSolid: (solid: boolean) => void;\n resetProbabilities: () => void;\n _nowPos64: number;\n _prevByte: number;\n };\n decoder.setDictionarySize(dictSize);\n\n // Access internal _outWindow for dictionary management\n // We need to preserve dictionary state across LZMA2 chunks\n type OutWindowType = {\n _buffer: Buffer;\n _pos: number;\n _streamPos: number;\n _windowSize: number;\n init: (solid: boolean) => void;\n };\n const outWindow = (decoder as unknown as { _outWindow: OutWindowType })._outWindow;\n\n // Track current LZMA properties (lc, lp, pb)\n let propsSet = false;\n\n while (offset < input.length) {\n const control = input[offset++];\n\n if (control === 0x00) {\n // End of LZMA2 stream\n break;\n }\n\n if (control === 0x01 || control === 0x02) {\n // Uncompressed chunk\n // 0x01 = dictionary reset + uncompressed\n // 0x02 = uncompressed (no reset)\n\n // Handle dictionary reset for 0x01\n if (control === 0x01) {\n outWindow._pos = 0;\n outWindow._streamPos = 0;\n decoder._nowPos64 = 0;\n }\n\n if (offset + 2 > input.length) {\n throw new Error('Truncated LZMA2 uncompressed chunk header');\n }\n\n // Size is big-endian, 16-bit, value + 1\n const uncompSize = ((input[offset] << 8) | input[offset + 1]) + 1;\n offset += 2;\n\n if (offset + uncompSize > input.length) {\n throw new Error('Truncated LZMA2 uncompressed data');\n }\n\n // Get the uncompressed data\n const uncompData = input.slice(offset, offset + uncompSize);\n\n // Copy uncompressed data to output\n if (outputBuffer) {\n uncompData.copy(outputBuffer, outputPos);\n outputPos += uncompData.length;\n } else {\n outputChunks?.push(uncompData);\n }\n\n // Also update the decoder's internal dictionary so subsequent LZMA chunks can reference it\n // The decoder needs to track this data for LZ77 back-references\n // We write directly to _buffer to avoid flush() which requires _stream to be set\n // We must also update _streamPos to match _pos so that flush() doesn't try to write\n for (let i = 0; i < uncompData.length; i++) {\n outWindow._buffer[outWindow._pos++] = uncompData[i];\n // Handle circular buffer wrap-around\n if (outWindow._pos >= outWindow._windowSize) {\n outWindow._pos = 0;\n }\n }\n // Keep _streamPos in sync so flush() doesn't try to write these bytes\n // (they're already in our output buffer)\n outWindow._streamPos = outWindow._pos;\n\n // Update decoder's cumulative position so subsequent LZMA chunks have correct rep0 validation\n decoder._nowPos64 += uncompSize;\n\n // Update prevByte for literal decoder context in subsequent LZMA chunks\n decoder._prevByte = uncompData[uncompData.length - 1];\n\n offset += uncompSize;\n } else if (control >= 0x80) {\n // LZMA compressed chunk\n // Control byte format (bits 7-0):\n // Bit 7: always 1 for LZMA chunk\n // Bits 6-5: reset mode (00=nothing, 01=state, 10=state+props, 11=all)\n // Bits 4-0: high 5 bits of uncompressed size - 1\n\n // Control byte ranges (based on bits 6-5):\n // 0x80-0x9F (00): no reset - continue existing state (solid mode)\n // 0xA0-0xBF (01): reset state only\n // 0xC0-0xDF (10): reset state + new properties\n // 0xE0-0xFF (11): reset dictionary + state + new properties\n const resetState = control >= 0xa0;\n const newProps = control >= 0xc0;\n const dictReset = control >= 0xe0;\n const useSolidMode = !resetState;\n\n // Handle dictionary reset for control bytes 0xE0-0xFF\n if (dictReset) {\n outWindow._pos = 0;\n outWindow._streamPos = 0;\n }\n\n if (offset + 4 > input.length) {\n throw new Error('Truncated LZMA2 LZMA chunk header');\n }\n\n // Uncompressed size: 5 bits from control + 16 bits from next 2 bytes + 1\n const uncompHigh = control & 0x1f;\n const uncompSize2 = ((uncompHigh << 16) | (input[offset] << 8) | input[offset + 1]) + 1;\n offset += 2;\n\n // Compressed size: 16 bits + 1\n const compSize = ((input[offset] << 8) | input[offset + 1]) + 1;\n offset += 2;\n\n // If new properties, read 1-byte LZMA properties\n if (newProps) {\n if (offset >= input.length) {\n throw new Error('Truncated LZMA2 properties byte');\n }\n const propsByte = input[offset++];\n\n // Properties byte: pb * 45 + lp * 9 + lc\n // where pb, lp, lc are LZMA parameters\n const lc = propsByte % 9;\n const remainder = Math.floor(propsByte / 9);\n const lp = remainder % 5;\n const pb = Math.floor(remainder / 5);\n\n if (!decoder.setLcLpPb(lc, lp, pb)) {\n throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);\n }\n propsSet = true;\n }\n\n if (!propsSet) {\n throw new Error('LZMA chunk without properties');\n }\n\n if (offset + compSize > input.length) {\n throw new Error('Truncated LZMA2 compressed data');\n }\n\n // Decode LZMA chunk\n const inStream = createInputStream(input, offset, compSize);\n const outStream = createOutputStream(uncompSize2); // Pre-allocate for memory efficiency\n\n // Set solid mode based on control byte - this preserves state across code() calls\n // For state reset WITHOUT dict reset (0xa0-0xdf), use resetProbabilities() to\n // reset probability tables while preserving _nowPos64 for dictionary references\n if (resetState && !dictReset) {\n decoder.resetProbabilities();\n decoder.setSolid(true); // Preserve _nowPos64 in code()\n } else {\n decoder.setSolid(useSolidMode);\n }\n\n // Decode the chunk\n const success = decoder.code(inStream, outStream, uncompSize2);\n if (!success) {\n throw new Error('LZMA decompression failed');\n }\n\n const chunkOutput = outStream.toBuffer();\n if (outputBuffer) {\n chunkOutput.copy(outputBuffer, outputPos);\n outputPos += chunkOutput.length;\n } else {\n outputChunks?.push(chunkOutput);\n }\n\n offset += compSize;\n } else {\n throw new Error(`Invalid LZMA2 control byte: 0x${control.toString(16)}`);\n }\n }\n\n // Return pre-allocated buffer or concatenated chunks\n if (outputBuffer) {\n // Return only the used portion if we didn't fill the buffer\n return outputPos < outputBuffer.length ? outputBuffer.slice(0, outputPos) : outputBuffer;\n }\n return Buffer.concat(outputChunks);\n}\n\n/**\n * Create an LZMA2 decoder Transform stream\n *\n * Uses native lzma-native when available for better performance,\n * falls back to lzma-purejs buffering decoder for Node.js 0.8+ compatibility.\n */\nexport function createLzma2Decoder(properties?: Buffer, unpackSize?: number): Transform {\n // Try native decoder first (available on Node.js 8+ with lzma-native installed)\n if (hasNativeLzma && properties && properties.length >= 1) {\n const dictSize = decodeDictionarySize(properties[0]);\n const nativeDecoder = createNativeLzma2Decoder(dictSize);\n if (nativeDecoder) {\n return nativeDecoder;\n }\n }\n\n // Fall back to buffering decoder with pure JS implementation\n return createBufferingDecoder(decodeLzma2, properties, unpackSize);\n}\n"],"names":["createLzma2Decoder","decodeLzma2","_require","require","Module","createRequire","LZMA","LzmaDecoder","Decoder","decodeDictionarySize","propByte","Error","base","shift","Math","floor","input","properties","unpackSize","length","dictSize","outputBuffer","outputPos","outputChunks","allocBufferUnsafe","offset","decoder","setDictionarySize","outWindow","_outWindow","propsSet","control","_pos","_streamPos","_nowPos64","uncompSize","uncompData","slice","copy","push","i","_buffer","_windowSize","_prevByte","resetState","newProps","dictReset","useSolidMode","uncompHigh","uncompSize2","compSize","propsByte","lc","remainder","lp","pb","setLcLpPb","inStream","createInputStream","outStream","createOutputStream","resetProbabilities","setSolid","success","code","chunkOutput","toBuffer","toString","Buffer","concat","hasNativeLzma","nativeDecoder","createNativeLzma2Decoder","createBufferingDecoder"],"mappings":";;;;;;;;;;;QA8RgBA;eAAAA;;QA9NAC;eAAAA;;;6DAhEG;mCAoBe;+EAEC;4BACqB;yBACF;;;;;;AAtBtD,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAwB1F,sFAAsF;AACtF,4DAA4D;AAC5D,IAAM,AAAEG,OAASJ,SAAS,kCAAlBI;AACR,IAAMC,cAAcD,KAAKE,OAAO;AAEhC;;;;;;;;;;CAUC,GACD,SAASC,qBAAqBC,QAAgB;IAC5C,IAAIA,WAAW,IAAI;QACjB,MAAM,IAAIC,MAAM,AAAC,2CAAmD,OAATD;IAC7D;IACA,IAAIA,aAAa,IAAI;QACnB,iCAAiC;QACjC,OAAO;IACT;IACA,8DAA8D;IAC9D,IAAME,OAAO,IAAKF,WAAW;IAC7B,IAAMG,QAAQC,KAAKC,KAAK,CAACL,WAAW,KAAK;IACzC,OAAOE,QAAQC;AACjB;AAUO,SAASZ,YAAYe,KAAa,EAAEC,UAAmB,EAAEC,UAAmB;IACjF,IAAI,CAACD,cAAcA,WAAWE,MAAM,GAAG,GAAG;QACxC,MAAM,IAAIR,MAAM;IAClB;IAEA,IAAMS,WAAWX,qBAAqBQ,UAAU,CAAC,EAAE;IAEnD,mEAAmE;IACnE,iDAAiD;IACjD,IAAII,eAA8B;IAClC,IAAIC,YAAY;IAChB,IAAMC,eAAyB,EAAE;IAEjC,IAAIL,cAAcA,aAAa,GAAG;QAChCG,eAAeG,IAAAA,sCAAiB,EAACN;IACnC;IAEA,IAAIO,SAAS;IAEb,+CAA+C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IvC,MAAM,AAAC,iCAAqD,OAArBoB,QAAQoC,QAAQ,CAAC;QACpE;IACF;IAEA,qDAAqD;IACrD,IAAI9C,cAAc;QAChB,4DAA4D;QAC5D,OAAOC,YAAYD,aAAaF,MAAM,GAAGE,aAAagB,KAAK,CAAC,GAAGf,aAAaD;IAC9E;IACA,OAAO+C,OAAOC,MAAM,CAAC9C;AACvB;AAQO,SAASvB,mBAAmBiB,UAAmB,EAAEC,UAAmB;IACzE,gFAAgF;IAChF,IAAIoD,2BAAa,IAAIrD,cAAcA,WAAWE,MAAM,IAAI,GAAG;QACzD,IAAMC,WAAWX,qBAAqBQ,UAAU,CAAC,EAAE;QACnD,IAAMsD,gBAAgBC,IAAAA,sCAAwB,EAACpD;QAC/C,IAAImD,eAAe;YACjB,OAAOA;QACT;IACF;IAEA,6DAA6D;IAC7D,OAAOE,IAAAA,iCAAsB,EAACxE,aAAagB,YAAYC;AACzD"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Lzma2.ts"],"sourcesContent":["import Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// LZMA2 codec using lzma-purejs\n// LZMA2 is a container format that wraps LZMA chunks with framing\n//\n// LZMA2 format specification:\n// https://github.com/ulikunitz/xz/blob/master/doc/LZMA2.md\n//\n// Control byte values:\n// 0x00 = End of stream\n// 0x01 = Uncompressed chunk, dictionary reset\n// 0x02 = Uncompressed chunk, no dictionary reset\n// 0x80-0xFF = LZMA compressed chunk (bits encode reset flags and size)\n\nimport { allocBufferUnsafe } from 'extract-base-iterator';\nimport type { Transform } from 'readable-stream';\nimport createBufferingDecoder from './createBufferingDecoder.ts';\nimport { createInputStream, createOutputStream } from './streams.ts';\n\n// Import vendored lzma-purejs - provides raw LZMA decoder (patched for LZMA2 support)\n// Path accounts for build output in dist/esm/sevenz/codecs/\nconst { LZMA } = _require('../../../../assets/lzma-purejs');\nconst LzmaDecoder = LZMA.Decoder;\n\n/**\n * Decode LZMA2 dictionary size from properties byte\n * Properties byte encodes dictionary size as: 2^(dictByte/2 + 12) or similar\n *\n * Per XZ spec, dictionary sizes are:\n * 0x00 = 4 KiB (2^12)\n * 0x01 = 6 KiB\n * 0x02 = 8 KiB (2^13)\n * ...\n * 0x28 = 1.5 GiB\n */\nfunction decodeDictionarySize(propByte: number): number {\n if (propByte > 40) {\n throw new Error(`Invalid LZMA2 dictionary size property: ${propByte}`);\n }\n if (propByte === 40) {\n // Max dictionary size: 4 GiB - 1\n return 0xffffffff;\n }\n // Dictionary size = 2 | (propByte & 1) << (propByte / 2 + 11)\n const base = 2 | (propByte & 1);\n const shift = Math.floor(propByte / 2) + 11;\n return base << shift;\n}\n\n/**\n * Decode LZMA2 compressed data to buffer\n *\n * @param input - LZMA2 compressed data\n * @param properties - Properties buffer (1 byte: dictionary size)\n * @param unpackSize - Expected output size (used for pre-allocation to reduce memory)\n * @returns Decompressed data\n */\nexport function decodeLzma2(input: Buffer, properties?: Buffer, unpackSize?: number): Buffer {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n\n const dictSize = decodeDictionarySize(properties[0]);\n\n // Memory optimization: pre-allocate output buffer if size is known\n // This avoids double-memory during Buffer.concat\n let outputBuffer: Buffer | null = null;\n let outputPos = 0;\n const outputChunks: Buffer[] = [];\n\n if (unpackSize && unpackSize > 0) {\n outputBuffer = allocBufferUnsafe(unpackSize);\n }\n\n let offset = 0;\n\n // LZMA decoder instance - reused across chunks\n // The vendored decoder supports setSolid() for LZMA2 state preservation\n // The decoder also has _nowPos64 which tracks cumulative position for rep0 validation\n // and _prevByte which is used for literal decoder context selection\n const decoder = new LzmaDecoder() as InstanceType<typeof LzmaDecoder> & {\n setSolid: (solid: boolean) => void;\n resetProbabilities: () => void;\n _nowPos64: number;\n _prevByte: number;\n };\n decoder.setDictionarySize(dictSize);\n\n // Access internal _outWindow for dictionary management\n // We need to preserve dictionary state across LZMA2 chunks\n type OutWindowType = {\n _buffer: Buffer;\n _pos: number;\n _streamPos: number;\n _windowSize: number;\n init: (solid: boolean) => void;\n };\n const outWindow = (decoder as unknown as { _outWindow: OutWindowType })._outWindow;\n\n // Track current LZMA properties (lc, lp, pb)\n let propsSet = false;\n\n while (offset < input.length) {\n const control = input[offset++];\n\n if (control === 0x00) {\n // End of LZMA2 stream\n break;\n }\n\n if (control === 0x01 || control === 0x02) {\n // Uncompressed chunk\n // 0x01 = dictionary reset + uncompressed\n // 0x02 = uncompressed (no reset)\n\n // Handle dictionary reset for 0x01\n if (control === 0x01) {\n outWindow._pos = 0;\n outWindow._streamPos = 0;\n decoder._nowPos64 = 0;\n }\n\n if (offset + 2 > input.length) {\n throw new Error('Truncated LZMA2 uncompressed chunk header');\n }\n\n // Size is big-endian, 16-bit, value + 1\n const uncompSize = ((input[offset] << 8) | input[offset + 1]) + 1;\n offset += 2;\n\n if (offset + uncompSize > input.length) {\n throw new Error('Truncated LZMA2 uncompressed data');\n }\n\n // Get the uncompressed data\n const uncompData = input.slice(offset, offset + uncompSize);\n\n // Copy uncompressed data to output\n if (outputBuffer) {\n uncompData.copy(outputBuffer, outputPos);\n outputPos += uncompData.length;\n } else {\n outputChunks?.push(uncompData);\n }\n\n // Also update the decoder's internal dictionary so subsequent LZMA chunks can reference it\n // The decoder needs to track this data for LZ77 back-references\n // We write directly to _buffer to avoid flush() which requires _stream to be set\n // We must also update _streamPos to match _pos so that flush() doesn't try to write\n for (let i = 0; i < uncompData.length; i++) {\n outWindow._buffer[outWindow._pos++] = uncompData[i];\n // Handle circular buffer wrap-around\n if (outWindow._pos >= outWindow._windowSize) {\n outWindow._pos = 0;\n }\n }\n // Keep _streamPos in sync so flush() doesn't try to write these bytes\n // (they're already in our output buffer)\n outWindow._streamPos = outWindow._pos;\n\n // Update decoder's cumulative position so subsequent LZMA chunks have correct rep0 validation\n decoder._nowPos64 += uncompSize;\n\n // Update prevByte for literal decoder context in subsequent LZMA chunks\n decoder._prevByte = uncompData[uncompData.length - 1];\n\n offset += uncompSize;\n } else if (control >= 0x80) {\n // LZMA compressed chunk\n // Control byte format (bits 7-0):\n // Bit 7: always 1 for LZMA chunk\n // Bits 6-5: reset mode (00=nothing, 01=state, 10=state+props, 11=all)\n // Bits 4-0: high 5 bits of uncompressed size - 1\n\n // Control byte ranges (based on bits 6-5):\n // 0x80-0x9F (00): no reset - continue existing state (solid mode)\n // 0xA0-0xBF (01): reset state only\n // 0xC0-0xDF (10): reset state + new properties\n // 0xE0-0xFF (11): reset dictionary + state + new properties\n const resetState = control >= 0xa0;\n const newProps = control >= 0xc0;\n const dictReset = control >= 0xe0;\n const useSolidMode = !resetState;\n\n // Handle dictionary reset for control bytes 0xE0-0xFF\n if (dictReset) {\n outWindow._pos = 0;\n outWindow._streamPos = 0;\n }\n\n if (offset + 4 > input.length) {\n throw new Error('Truncated LZMA2 LZMA chunk header');\n }\n\n // Uncompressed size: 5 bits from control + 16 bits from next 2 bytes + 1\n const uncompHigh = control & 0x1f;\n const uncompSize2 = ((uncompHigh << 16) | (input[offset] << 8) | input[offset + 1]) + 1;\n offset += 2;\n\n // Compressed size: 16 bits + 1\n const compSize = ((input[offset] << 8) | input[offset + 1]) + 1;\n offset += 2;\n\n // If new properties, read 1-byte LZMA properties\n if (newProps) {\n if (offset >= input.length) {\n throw new Error('Truncated LZMA2 properties byte');\n }\n const propsByte = input[offset++];\n\n // Properties byte: pb * 45 + lp * 9 + lc\n // where pb, lp, lc are LZMA parameters\n const lc = propsByte % 9;\n const remainder = Math.floor(propsByte / 9);\n const lp = remainder % 5;\n const pb = Math.floor(remainder / 5);\n\n if (!decoder.setLcLpPb(lc, lp, pb)) {\n throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);\n }\n propsSet = true;\n }\n\n if (!propsSet) {\n throw new Error('LZMA chunk without properties');\n }\n\n if (offset + compSize > input.length) {\n throw new Error('Truncated LZMA2 compressed data');\n }\n\n // Decode LZMA chunk\n const inStream = createInputStream(input, offset, compSize);\n const outStream = createOutputStream(uncompSize2); // Pre-allocate for memory efficiency\n\n // Set solid mode based on control byte - this preserves state across code() calls\n // For state reset WITHOUT dict reset (0xa0-0xdf), use resetProbabilities() to\n // reset probability tables while preserving _nowPos64 for dictionary references\n if (resetState && !dictReset) {\n decoder.resetProbabilities();\n decoder.setSolid(true); // Preserve _nowPos64 in code()\n } else {\n decoder.setSolid(useSolidMode);\n }\n\n // Decode the chunk\n const success = decoder.code(inStream, outStream, uncompSize2);\n if (!success) {\n throw new Error('LZMA decompression failed');\n }\n\n const chunkOutput = outStream.toBuffer();\n if (outputBuffer) {\n chunkOutput.copy(outputBuffer, outputPos);\n outputPos += chunkOutput.length;\n } else {\n outputChunks?.push(chunkOutput);\n }\n\n offset += compSize;\n } else {\n throw new Error(`Invalid LZMA2 control byte: 0x${control.toString(16)}`);\n }\n }\n\n // Return pre-allocated buffer or concatenated chunks\n if (outputBuffer) {\n // Return only the used portion if we didn't fill the buffer\n return outputPos < outputBuffer.length ? outputBuffer.slice(0, outputPos) : outputBuffer;\n }\n return Buffer.concat(outputChunks);\n}\n\n/**\n * Create an LZMA2 decoder Transform stream\n */\nexport function createLzma2Decoder(properties?: Buffer, unpackSize?: number): Transform {\n return createBufferingDecoder(decodeLzma2, properties, unpackSize);\n}\n"],"names":["createLzma2Decoder","decodeLzma2","_require","require","Module","createRequire","LZMA","LzmaDecoder","Decoder","decodeDictionarySize","propByte","Error","base","shift","Math","floor","input","properties","unpackSize","length","dictSize","outputBuffer","outputPos","outputChunks","allocBufferUnsafe","offset","decoder","setDictionarySize","outWindow","_outWindow","propsSet","control","_pos","_streamPos","_nowPos64","uncompSize","uncompData","slice","copy","push","i","_buffer","_windowSize","_prevByte","resetState","newProps","dictReset","useSolidMode","uncompHigh","uncompSize2","compSize","propsByte","lc","remainder","lp","pb","setLcLpPb","inStream","createInputStream","outStream","createOutputStream","resetProbabilities","setSolid","success","code","chunkOutput","toBuffer","toString","Buffer","concat","createB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,SAASvB,mBAAmBiB,UAAmB,EAAEC,UAAmB;IACzE,OAAOoD,IAAAA,iCAAsB,EAACrE,aAAagB,YAAYC;AACzD"}
|
|
@@ -10,8 +10,5 @@ import type { Transform } from 'readable-stream';
|
|
|
10
10
|
export declare function decodeLzma(input: Buffer, properties?: Buffer, unpackSize?: number): Buffer;
|
|
11
11
|
/**
|
|
12
12
|
* Create an LZMA decoder Transform stream
|
|
13
|
-
*
|
|
14
|
-
* Uses native lzma-native when available for better performance,
|
|
15
|
-
* falls back to lzma-purejs buffering decoder for Node.js 0.8+ compatibility.
|
|
16
13
|
*/
|
|
17
|
-
export declare function createLzmaDecoder(properties?: Buffer,
|
|
14
|
+
export declare function createLzmaDecoder(properties?: Buffer, unpackSize?: number): Transform;
|
|
@@ -1,30 +1,11 @@
|
|
|
1
1
|
import Module from 'module';
|
|
2
2
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
3
3
|
import createBufferingDecoder from './createBufferingDecoder.js';
|
|
4
|
-
import { createNativeLzma1Decoder, hasNativeLzma } from './lzmaCompat.js';
|
|
5
4
|
import { createInputStream, createOutputStream } from './streams.js';
|
|
6
5
|
// Import vendored lzma-purejs - provides raw LZMA decoder (patched for LZMA2 support)
|
|
7
6
|
// Path accounts for build output in dist/esm/sevenz/codecs/
|
|
8
7
|
const { LZMA } = _require('../../../../assets/lzma-purejs');
|
|
9
8
|
const LzmaDecoder = LZMA.Decoder;
|
|
10
|
-
/**
|
|
11
|
-
* Parse LZMA properties from 5-byte buffer
|
|
12
|
-
* First byte: lc + lp*9 + pb*45
|
|
13
|
-
* Next 4 bytes: dictionary size (little-endian)
|
|
14
|
-
*/ function parseLzmaProperties(properties) {
|
|
15
|
-
const propByte = properties[0];
|
|
16
|
-
const lc = propByte % 9;
|
|
17
|
-
const remainder = Math.floor(propByte / 9);
|
|
18
|
-
const lp = remainder % 5;
|
|
19
|
-
const pb = Math.floor(remainder / 5);
|
|
20
|
-
const dictSize = properties.readUInt32LE(1);
|
|
21
|
-
return {
|
|
22
|
-
lc: lc,
|
|
23
|
-
lp: lp,
|
|
24
|
-
pb: pb,
|
|
25
|
-
dictSize: dictSize
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
9
|
/**
|
|
29
10
|
* Decode LZMA compressed data to buffer
|
|
30
11
|
*
|
|
@@ -54,18 +35,6 @@ const LzmaDecoder = LZMA.Decoder;
|
|
|
54
35
|
}
|
|
55
36
|
/**
|
|
56
37
|
* Create an LZMA decoder Transform stream
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* falls back to lzma-purejs buffering decoder for Node.js 0.8+ compatibility.
|
|
60
|
-
*/ export function createLzmaDecoder(properties, _unpackSize) {
|
|
61
|
-
// Try native decoder first (available on Node.js 8+ with lzma-native installed)
|
|
62
|
-
if (hasNativeLzma && properties && properties.length >= 5) {
|
|
63
|
-
const props = parseLzmaProperties(properties);
|
|
64
|
-
const nativeDecoder = createNativeLzma1Decoder(props.lc, props.lp, props.pb, props.dictSize);
|
|
65
|
-
if (nativeDecoder) {
|
|
66
|
-
return nativeDecoder;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// Fall back to buffering decoder with pure JS implementation
|
|
70
|
-
return createBufferingDecoder(decodeLzma, properties, _unpackSize);
|
|
38
|
+
*/ export function createLzmaDecoder(properties, unpackSize) {
|
|
39
|
+
return createBufferingDecoder(decodeLzma, properties, unpackSize);
|
|
71
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Lzma.ts"],"sourcesContent":["import Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// LZMA codec
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Lzma.ts"],"sourcesContent":["import Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// LZMA codec using lzma-purejs\n// LZMA properties in 7z are 5 bytes: 1 byte lc/lp/pb + 4 bytes dictionary size (little-endian)\n\nimport type { Transform } from 'readable-stream';\nimport createBufferingDecoder from './createBufferingDecoder.ts';\nimport { createInputStream, createOutputStream } from './streams.ts';\n\n// Import vendored lzma-purejs - provides raw LZMA decoder (patched for LZMA2 support)\n// Path accounts for build output in dist/esm/sevenz/codecs/\nconst { LZMA } = _require('../../../../assets/lzma-purejs');\nconst LzmaDecoder = LZMA.Decoder;\n\n/**\n * Decode LZMA compressed data to buffer\n *\n * @param input - LZMA compressed data\n * @param properties - Properties buffer (5 bytes: lc/lp/pb + dict size)\n * @param unpackSize - Expected output size (optional, -1 for unknown)\n * @returns Decompressed data\n */\nexport function decodeLzma(input: Buffer, properties?: Buffer, unpackSize?: number): Buffer {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n\n const decoder = new LzmaDecoder();\n\n // setDecoderProperties expects array-like with 5 bytes\n if (!decoder.setDecoderProperties(properties)) {\n throw new Error('Invalid LZMA properties');\n }\n\n const inStream = createInputStream(input, 0, input.length);\n\n // Use -1 for unknown size (decoder will use end marker)\n const size = typeof unpackSize === 'number' ? unpackSize : -1;\n\n // Pre-allocate output stream if size is known (memory optimization)\n const outStream = createOutputStream(size > 0 ? size : undefined);\n\n const success = decoder.code(inStream, outStream, size);\n if (!success) {\n throw new Error('LZMA decompression failed');\n }\n\n return outStream.toBuffer();\n}\n\n/**\n * Create an LZMA decoder Transform stream\n */\nexport function createLzmaDecoder(properties?: Buffer, unpackSize?: number): Transform {\n return createBufferingDecoder(decodeLzma, properties, unpackSize);\n}\n"],"names":["Module","_require","require","createRequire","url","createBufferingDecoder","createInputStream","createOutputStream","LZMA","LzmaDecoder","Decoder","decodeLzma","input","properties","unpackSize","length","Error","decoder","setDecoderProperties","inStream","size","outStream","undefined","success","code","toBuffer","createLzmaDecoder"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAM1F,OAAOG,4BAA4B,8BAA8B;AACjE,SAASC,iBAAiB,EAAEC,kBAAkB,QAAQ,eAAe;AAErE,sFAAsF;AACtF,4DAA4D;AAC5D,MAAM,EAAEC,IAAI,EAAE,GAAGP,SAAS;AAC1B,MAAMQ,cAAcD,KAAKE,OAAO;AAEhC;;;;;;;CAOC,GACD,OAAO,SAASC,WAAWC,KAAa,EAAEC,UAAmB,EAAEC,UAAmB;IAChF,IAAI,CAACD,cAAcA,WAAWE,MAAM,GAAG,GAAG;QACxC,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,UAAU,IAAIR;IAEpB,uDAAuD;IACvD,IAAI,CAACQ,QAAQC,oBAAoB,CAACL,aAAa;QAC7C,MAAM,IAAIG,MAAM;IAClB;IAEA,MAAMG,WAAWb,kBAAkBM,OAAO,GAAGA,MAAMG,MAAM;IAEzD,wDAAwD;IACxD,MAAMK,OAAO,OAAON,eAAe,WAAWA,aAAa,CAAC;IAE5D,oEAAoE;IACpE,MAAMO,YAAYd,mBAAmBa,OAAO,IAAIA,OAAOE;IAEvD,MAAMC,UAAUN,QAAQO,IAAI,CAACL,UAAUE,WAAWD;IAClD,IAAI,CAACG,SAAS;QACZ,MAAM,IAAIP,MAAM;IAClB;IAEA,OAAOK,UAAUI,QAAQ;AAC3B;AAEA;;CAEC,GACD,OAAO,SAASC,kBAAkBb,UAAmB,EAAEC,UAAmB;IACxE,OAAOT,uBAAuBM,YAAYE,YAAYC;AACxD"}
|
|
@@ -10,8 +10,5 @@ import type { Transform } from 'readable-stream';
|
|
|
10
10
|
export declare function decodeLzma2(input: Buffer, properties?: Buffer, unpackSize?: number): Buffer;
|
|
11
11
|
/**
|
|
12
12
|
* Create an LZMA2 decoder Transform stream
|
|
13
|
-
*
|
|
14
|
-
* Uses native lzma-native when available for better performance,
|
|
15
|
-
* falls back to lzma-purejs buffering decoder for Node.js 0.8+ compatibility.
|
|
16
13
|
*/
|
|
17
14
|
export declare function createLzma2Decoder(properties?: Buffer, unpackSize?: number): Transform;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Module from 'module';
|
|
2
2
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
3
|
-
// LZMA2 codec
|
|
3
|
+
// LZMA2 codec using lzma-purejs
|
|
4
4
|
// LZMA2 is a container format that wraps LZMA chunks with framing
|
|
5
5
|
//
|
|
6
6
|
// LZMA2 format specification:
|
|
@@ -11,13 +11,8 @@ const _require = typeof require === 'undefined' ? Module.createRequire(import.me
|
|
|
11
11
|
// 0x01 = Uncompressed chunk, dictionary reset
|
|
12
12
|
// 0x02 = Uncompressed chunk, no dictionary reset
|
|
13
13
|
// 0x80-0xFF = LZMA compressed chunk (bits encode reset flags and size)
|
|
14
|
-
//
|
|
15
|
-
// Native optimization: On Node.js 8+, lzma-native provides liblzma bindings
|
|
16
|
-
// that decode LZMA2 streams natively for better performance.
|
|
17
|
-
// Falls back to lzma-purejs for Node.js 0.8-7.x compatibility.
|
|
18
14
|
import { allocBufferUnsafe } from 'extract-base-iterator';
|
|
19
15
|
import createBufferingDecoder from './createBufferingDecoder.js';
|
|
20
|
-
import { createNativeLzma2Decoder, hasNativeLzma } from './lzmaCompat.js';
|
|
21
16
|
import { createInputStream, createOutputStream } from './streams.js';
|
|
22
17
|
// Import vendored lzma-purejs - provides raw LZMA decoder (patched for LZMA2 support)
|
|
23
18
|
// Path accounts for build output in dist/esm/sevenz/codecs/
|
|
@@ -219,18 +214,6 @@ const LzmaDecoder = LZMA.Decoder;
|
|
|
219
214
|
}
|
|
220
215
|
/**
|
|
221
216
|
* Create an LZMA2 decoder Transform stream
|
|
222
|
-
*
|
|
223
|
-
* Uses native lzma-native when available for better performance,
|
|
224
|
-
* falls back to lzma-purejs buffering decoder for Node.js 0.8+ compatibility.
|
|
225
217
|
*/ export function createLzma2Decoder(properties, unpackSize) {
|
|
226
|
-
// Try native decoder first (available on Node.js 8+ with lzma-native installed)
|
|
227
|
-
if (hasNativeLzma && properties && properties.length >= 1) {
|
|
228
|
-
const dictSize = decodeDictionarySize(properties[0]);
|
|
229
|
-
const nativeDecoder = createNativeLzma2Decoder(dictSize);
|
|
230
|
-
if (nativeDecoder) {
|
|
231
|
-
return nativeDecoder;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
// Fall back to buffering decoder with pure JS implementation
|
|
235
218
|
return createBufferingDecoder(decodeLzma2, properties, unpackSize);
|
|
236
219
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Lzma2.ts"],"sourcesContent":["import Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// LZMA2 codec - uses native lzma-native when available, falls back to lzma-purejs\n// LZMA2 is a container format that wraps LZMA chunks with framing\n//\n// LZMA2 format specification:\n// https://github.com/ulikunitz/xz/blob/master/doc/LZMA2.md\n//\n// Control byte values:\n// 0x00 = End of stream\n// 0x01 = Uncompressed chunk, dictionary reset\n// 0x02 = Uncompressed chunk, no dictionary reset\n// 0x80-0xFF = LZMA compressed chunk (bits encode reset flags and size)\n//\n// Native optimization: On Node.js 8+, lzma-native provides liblzma bindings\n// that decode LZMA2 streams natively for better performance.\n// Falls back to lzma-purejs for Node.js 0.8-7.x compatibility.\n\nimport { allocBufferUnsafe } from 'extract-base-iterator';\nimport type { Transform } from 'readable-stream';\nimport createBufferingDecoder from './createBufferingDecoder.ts';\nimport { createNativeLzma2Decoder, hasNativeLzma } from './lzmaCompat.ts';\nimport { createInputStream, createOutputStream } from './streams.ts';\n\n// Import vendored lzma-purejs - provides raw LZMA decoder (patched for LZMA2 support)\n// Path accounts for build output in dist/esm/sevenz/codecs/\nconst { LZMA } = _require('../../../../assets/lzma-purejs');\nconst LzmaDecoder = LZMA.Decoder;\n\n/**\n * Decode LZMA2 dictionary size from properties byte\n * Properties byte encodes dictionary size as: 2^(dictByte/2 + 12) or similar\n *\n * Per XZ spec, dictionary sizes are:\n * 0x00 = 4 KiB (2^12)\n * 0x01 = 6 KiB\n * 0x02 = 8 KiB (2^13)\n * ...\n * 0x28 = 1.5 GiB\n */\nfunction decodeDictionarySize(propByte: number): number {\n if (propByte > 40) {\n throw new Error(`Invalid LZMA2 dictionary size property: ${propByte}`);\n }\n if (propByte === 40) {\n // Max dictionary size: 4 GiB - 1\n return 0xffffffff;\n }\n // Dictionary size = 2 | (propByte & 1) << (propByte / 2 + 11)\n const base = 2 | (propByte & 1);\n const shift = Math.floor(propByte / 2) + 11;\n return base << shift;\n}\n\n/**\n * Decode LZMA2 compressed data to buffer\n *\n * @param input - LZMA2 compressed data\n * @param properties - Properties buffer (1 byte: dictionary size)\n * @param unpackSize - Expected output size (used for pre-allocation to reduce memory)\n * @returns Decompressed data\n */\nexport function decodeLzma2(input: Buffer, properties?: Buffer, unpackSize?: number): Buffer {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n\n const dictSize = decodeDictionarySize(properties[0]);\n\n // Memory optimization: pre-allocate output buffer if size is known\n // This avoids double-memory during Buffer.concat\n let outputBuffer: Buffer | null = null;\n let outputPos = 0;\n const outputChunks: Buffer[] = [];\n\n if (unpackSize && unpackSize > 0) {\n outputBuffer = allocBufferUnsafe(unpackSize);\n }\n\n let offset = 0;\n\n // LZMA decoder instance - reused across chunks\n // The vendored decoder supports setSolid() for LZMA2 state preservation\n // The decoder also has _nowPos64 which tracks cumulative position for rep0 validation\n // and _prevByte which is used for literal decoder context selection\n const decoder = new LzmaDecoder() as InstanceType<typeof LzmaDecoder> & {\n setSolid: (solid: boolean) => void;\n resetProbabilities: () => void;\n _nowPos64: number;\n _prevByte: number;\n };\n decoder.setDictionarySize(dictSize);\n\n // Access internal _outWindow for dictionary management\n // We need to preserve dictionary state across LZMA2 chunks\n type OutWindowType = {\n _buffer: Buffer;\n _pos: number;\n _streamPos: number;\n _windowSize: number;\n init: (solid: boolean) => void;\n };\n const outWindow = (decoder as unknown as { _outWindow: OutWindowType })._outWindow;\n\n // Track current LZMA properties (lc, lp, pb)\n let propsSet = false;\n\n while (offset < input.length) {\n const control = input[offset++];\n\n if (control === 0x00) {\n // End of LZMA2 stream\n break;\n }\n\n if (control === 0x01 || control === 0x02) {\n // Uncompressed chunk\n // 0x01 = dictionary reset + uncompressed\n // 0x02 = uncompressed (no reset)\n\n // Handle dictionary reset for 0x01\n if (control === 0x01) {\n outWindow._pos = 0;\n outWindow._streamPos = 0;\n decoder._nowPos64 = 0;\n }\n\n if (offset + 2 > input.length) {\n throw new Error('Truncated LZMA2 uncompressed chunk header');\n }\n\n // Size is big-endian, 16-bit, value + 1\n const uncompSize = ((input[offset] << 8) | input[offset + 1]) + 1;\n offset += 2;\n\n if (offset + uncompSize > input.length) {\n throw new Error('Truncated LZMA2 uncompressed data');\n }\n\n // Get the uncompressed data\n const uncompData = input.slice(offset, offset + uncompSize);\n\n // Copy uncompressed data to output\n if (outputBuffer) {\n uncompData.copy(outputBuffer, outputPos);\n outputPos += uncompData.length;\n } else {\n outputChunks?.push(uncompData);\n }\n\n // Also update the decoder's internal dictionary so subsequent LZMA chunks can reference it\n // The decoder needs to track this data for LZ77 back-references\n // We write directly to _buffer to avoid flush() which requires _stream to be set\n // We must also update _streamPos to match _pos so that flush() doesn't try to write\n for (let i = 0; i < uncompData.length; i++) {\n outWindow._buffer[outWindow._pos++] = uncompData[i];\n // Handle circular buffer wrap-around\n if (outWindow._pos >= outWindow._windowSize) {\n outWindow._pos = 0;\n }\n }\n // Keep _streamPos in sync so flush() doesn't try to write these bytes\n // (they're already in our output buffer)\n outWindow._streamPos = outWindow._pos;\n\n // Update decoder's cumulative position so subsequent LZMA chunks have correct rep0 validation\n decoder._nowPos64 += uncompSize;\n\n // Update prevByte for literal decoder context in subsequent LZMA chunks\n decoder._prevByte = uncompData[uncompData.length - 1];\n\n offset += uncompSize;\n } else if (control >= 0x80) {\n // LZMA compressed chunk\n // Control byte format (bits 7-0):\n // Bit 7: always 1 for LZMA chunk\n // Bits 6-5: reset mode (00=nothing, 01=state, 10=state+props, 11=all)\n // Bits 4-0: high 5 bits of uncompressed size - 1\n\n // Control byte ranges (based on bits 6-5):\n // 0x80-0x9F (00): no reset - continue existing state (solid mode)\n // 0xA0-0xBF (01): reset state only\n // 0xC0-0xDF (10): reset state + new properties\n // 0xE0-0xFF (11): reset dictionary + state + new properties\n const resetState = control >= 0xa0;\n const newProps = control >= 0xc0;\n const dictReset = control >= 0xe0;\n const useSolidMode = !resetState;\n\n // Handle dictionary reset for control bytes 0xE0-0xFF\n if (dictReset) {\n outWindow._pos = 0;\n outWindow._streamPos = 0;\n }\n\n if (offset + 4 > input.length) {\n throw new Error('Truncated LZMA2 LZMA chunk header');\n }\n\n // Uncompressed size: 5 bits from control + 16 bits from next 2 bytes + 1\n const uncompHigh = control & 0x1f;\n const uncompSize2 = ((uncompHigh << 16) | (input[offset] << 8) | input[offset + 1]) + 1;\n offset += 2;\n\n // Compressed size: 16 bits + 1\n const compSize = ((input[offset] << 8) | input[offset + 1]) + 1;\n offset += 2;\n\n // If new properties, read 1-byte LZMA properties\n if (newProps) {\n if (offset >= input.length) {\n throw new Error('Truncated LZMA2 properties byte');\n }\n const propsByte = input[offset++];\n\n // Properties byte: pb * 45 + lp * 9 + lc\n // where pb, lp, lc are LZMA parameters\n const lc = propsByte % 9;\n const remainder = Math.floor(propsByte / 9);\n const lp = remainder % 5;\n const pb = Math.floor(remainder / 5);\n\n if (!decoder.setLcLpPb(lc, lp, pb)) {\n throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);\n }\n propsSet = true;\n }\n\n if (!propsSet) {\n throw new Error('LZMA chunk without properties');\n }\n\n if (offset + compSize > input.length) {\n throw new Error('Truncated LZMA2 compressed data');\n }\n\n // Decode LZMA chunk\n const inStream = createInputStream(input, offset, compSize);\n const outStream = createOutputStream(uncompSize2); // Pre-allocate for memory efficiency\n\n // Set solid mode based on control byte - this preserves state across code() calls\n // For state reset WITHOUT dict reset (0xa0-0xdf), use resetProbabilities() to\n // reset probability tables while preserving _nowPos64 for dictionary references\n if (resetState && !dictReset) {\n decoder.resetProbabilities();\n decoder.setSolid(true); // Preserve _nowPos64 in code()\n } else {\n decoder.setSolid(useSolidMode);\n }\n\n // Decode the chunk\n const success = decoder.code(inStream, outStream, uncompSize2);\n if (!success) {\n throw new Error('LZMA decompression failed');\n }\n\n const chunkOutput = outStream.toBuffer();\n if (outputBuffer) {\n chunkOutput.copy(outputBuffer, outputPos);\n outputPos += chunkOutput.length;\n } else {\n outputChunks?.push(chunkOutput);\n }\n\n offset += compSize;\n } else {\n throw new Error(`Invalid LZMA2 control byte: 0x${control.toString(16)}`);\n }\n }\n\n // Return pre-allocated buffer or concatenated chunks\n if (outputBuffer) {\n // Return only the used portion if we didn't fill the buffer\n return outputPos < outputBuffer.length ? outputBuffer.slice(0, outputPos) : outputBuffer;\n }\n return Buffer.concat(outputChunks);\n}\n\n/**\n * Create an LZMA2 decoder Transform stream\n *\n * Uses native lzma-native when available for better performance,\n * falls back to lzma-purejs buffering decoder for Node.js 0.8+ compatibility.\n */\nexport function createLzma2Decoder(properties?: Buffer, unpackSize?: number): Transform {\n // Try native decoder first (available on Node.js 8+ with lzma-native installed)\n if (hasNativeLzma && properties && properties.length >= 1) {\n const dictSize = decodeDictionarySize(properties[0]);\n const nativeDecoder = createNativeLzma2Decoder(dictSize);\n if (nativeDecoder) {\n return nativeDecoder;\n }\n }\n\n // Fall back to buffering decoder with pure JS implementation\n return createBufferingDecoder(decodeLzma2, properties, unpackSize);\n}\n"],"names":["Module","_require","require","createRequire","url","allocBufferUnsafe","createBufferingDecoder","createNativeLzma2Decoder","hasNativeLzma","createInputStream","createOutputStream","LZMA","LzmaDecoder","Decoder","decodeDictionarySize","propByte","Error","base","shift","Math","floor","decodeLzma2","input","properties","unpackSize","length","dictSize","outputBuffer","outputPos","outputChunks","offset","decoder","setDictionarySize","outWindow","_outWindow","propsSet","control","_pos","_streamPos","_nowPos64","uncompSize","uncompData","slice","copy","push","i","_buffer","_windowSize","_prevByte","resetState","newProps","dictReset","useSolidMode","uncompHigh","uncompSize2","compSize","propsByte","lc","remainder","lp","pb","setLcLpPb","inStream","outStream","resetProbabilities","setSolid","success","code","chunkOutput","toBuffer","toString","Buffer","concat","createLzma2Decoder","nativeDecoder"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE1F,kFAAkF;AAClF,kEAAkE;AAClE,EAAE;AACF,8BAA8B;AAC9B,2DAA2D;AAC3D,EAAE;AACF,uBAAuB;AACvB,+BAA+B;AAC/B,sDAAsD;AACtD,yDAAyD;AACzD,0EAA0E;AAC1E,EAAE;AACF,4EAA4E;AAC5E,6DAA6D;AAC7D,+DAA+D;AAE/D,SAASG,iBAAiB,QAAQ,wBAAwB;AAE1D,OAAOC,4BAA4B,8BAA8B;AACjE,SAASC,wBAAwB,EAAEC,aAAa,QAAQ,kBAAkB;AAC1E,SAASC,iBAAiB,EAAEC,kBAAkB,QAAQ,eAAe;AAErE,sFAAsF;AACtF,4DAA4D;AAC5D,MAAM,EAAEC,IAAI,EAAE,GAAGV,SAAS;AAC1B,MAAMW,cAAcD,KAAKE,OAAO;AAEhC;;;;;;;;;;CAUC,GACD,SAASC,qBAAqBC,QAAgB;IAC5C,IAAIA,WAAW,IAAI;QACjB,MAAM,IAAIC,MAAM,CAAC,wCAAwC,EAAED,UAAU;IACvE;IACA,IAAIA,aAAa,IAAI;QACnB,iCAAiC;QACjC,OAAO;IACT;IACA,8DAA8D;IAC9D,MAAME,OAAO,IAAKF,WAAW;IAC7B,MAAMG,QAAQC,KAAKC,KAAK,CAACL,WAAW,KAAK;IACzC,OAAOE,QAAQC;AACjB;AAEA;;;;;;;CAOC,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AACb;YACnB;YAEA,mBAAmB;YACnB,MAAMc,UAAUnC,QAAQoC,IAAI,CAACL,UAAUC,WAAWT;YAClD,IAAI,CAACY,SAAS;gBACZ,MAAM,IAAIlD,MAAM;YAClB;YAEA,MAAMoD,cAAcL,UAAUM,QAAQ;YACtC,IAAI1C,cAAc;gBAChByC,YAAYzB,IAAI,CAAChB,cAAcC;gBAC/BA,aAAawC,YAAY3C,MAAM;YACjC,OAAO;gBACLI,yBAAAA,mCAAAA,aAAce,IAAI,CAACwB;YACrB;YAEAtC,UAAUyB;QACZ,OAAO;YACL,MAAM,IAAIvC,MAAM,CAAC,8BAA8B,EAAEoB,QAAQkC,QAAQ,CAAC,KAAK;QACzE;IACF;IAEA,qDAAqD;IACrD,IAAI3C,cAAc;QAChB,4DAA4D;QAC5D,OAAOC,YAAYD,aAAaF,MAAM,GAAGE,aAAae,KAAK,CAAC,GAAGd,aAAaD;IAC9E;IACA,OAAO4C,OAAOC,MAAM,CAAC3C;AACvB;AAEA;;;;;CAKC,GACD,OAAO,SAAS4C,mBAAmBlD,UAAmB,EAAEC,UAAmB;IACzE,gFAAgF;IAChF,IAAIhB,iBAAiBe,cAAcA,WAAWE,MAAM,IAAI,GAAG;QACzD,MAAMC,WAAWZ,qBAAqBS,UAAU,CAAC,EAAE;QACnD,MAAMmD,gBAAgBnE,yBAAyBmB;QAC/C,IAAIgD,eAAe;YACjB,OAAOA;QACT;IACF;IAEA,6DAA6D;IAC7D,OAAOpE,uBAAuBe,aAAaE,YAAYC;AACzD"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Lzma2.ts"],"sourcesContent":["import Module from 'module';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// LZMA2 codec using lzma-purejs\n// LZMA2 is a container format that wraps LZMA chunks with framing\n//\n// LZMA2 format specification:\n// https://github.com/ulikunitz/xz/blob/master/doc/LZMA2.md\n//\n// Control byte values:\n// 0x00 = End of stream\n// 0x01 = Uncompressed chunk, dictionary reset\n// 0x02 = Uncompressed chunk, no dictionary reset\n// 0x80-0xFF = LZMA compressed chunk (bits encode reset flags and size)\n\nimport { allocBufferUnsafe } from 'extract-base-iterator';\nimport type { Transform } from 'readable-stream';\nimport createBufferingDecoder from './createBufferingDecoder.ts';\nimport { createInputStream, createOutputStream } from './streams.ts';\n\n// Import vendored lzma-purejs - provides raw LZMA decoder (patched for LZMA2 support)\n// Path accounts for build output in dist/esm/sevenz/codecs/\nconst { LZMA } = _require('../../../../assets/lzma-purejs');\nconst LzmaDecoder = LZMA.Decoder;\n\n/**\n * Decode LZMA2 dictionary size from properties byte\n * Properties byte encodes dictionary size as: 2^(dictByte/2 + 12) or similar\n *\n * Per XZ spec, dictionary sizes are:\n * 0x00 = 4 KiB (2^12)\n * 0x01 = 6 KiB\n * 0x02 = 8 KiB (2^13)\n * ...\n * 0x28 = 1.5 GiB\n */\nfunction decodeDictionarySize(propByte: number): number {\n if (propByte > 40) {\n throw new Error(`Invalid LZMA2 dictionary size property: ${propByte}`);\n }\n if (propByte === 40) {\n // Max dictionary size: 4 GiB - 1\n return 0xffffffff;\n }\n // Dictionary size = 2 | (propByte & 1) << (propByte / 2 + 11)\n const base = 2 | (propByte & 1);\n const shift = Math.floor(propByte / 2) + 11;\n return base << shift;\n}\n\n/**\n * Decode LZMA2 compressed data to buffer\n *\n * @param input - LZMA2 compressed data\n * @param properties - Properties buffer (1 byte: dictionary size)\n * @param unpackSize - Expected output size (used for pre-allocation to reduce memory)\n * @returns Decompressed data\n */\nexport function decodeLzma2(input: Buffer, properties?: Buffer, unpackSize?: number): Buffer {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n\n const dictSize = decodeDictionarySize(properties[0]);\n\n // Memory optimization: pre-allocate output buffer if size is known\n // This avoids double-memory during Buffer.concat\n let outputBuffer: Buffer | null = null;\n let outputPos = 0;\n const outputChunks: Buffer[] = [];\n\n if (unpackSize && unpackSize > 0) {\n outputBuffer = allocBufferUnsafe(unpackSize);\n }\n\n let offset = 0;\n\n // LZMA decoder instance - reused across chunks\n // The vendored decoder supports setSolid() for LZMA2 state preservation\n // The decoder also has _nowPos64 which tracks cumulative position for rep0 validation\n // and _prevByte which is used for literal decoder context selection\n const decoder = new LzmaDecoder() as InstanceType<typeof LzmaDecoder> & {\n setSolid: (solid: boolean) => void;\n resetProbabilities: () => void;\n _nowPos64: number;\n _prevByte: number;\n };\n decoder.setDictionarySize(dictSize);\n\n // Access internal _outWindow for dictionary management\n // We need to preserve dictionary state across LZMA2 chunks\n type OutWindowType = {\n _buffer: Buffer;\n _pos: number;\n _streamPos: number;\n _windowSize: number;\n init: (solid: boolean) => void;\n };\n const outWindow = (decoder as unknown as { _outWindow: OutWindowType })._outWindow;\n\n // Track current LZMA properties (lc, lp, pb)\n let propsSet = false;\n\n while (offset < input.length) {\n const control = input[offset++];\n\n if (control === 0x00) {\n // End of LZMA2 stream\n break;\n }\n\n if (control === 0x01 || control === 0x02) {\n // Uncompressed chunk\n // 0x01 = dictionary reset + uncompressed\n // 0x02 = uncompressed (no reset)\n\n // Handle dictionary reset for 0x01\n if (control === 0x01) {\n outWindow._pos = 0;\n outWindow._streamPos = 0;\n decoder._nowPos64 = 0;\n }\n\n if (offset + 2 > input.length) {\n throw new Error('Truncated LZMA2 uncompressed chunk header');\n }\n\n // Size is big-endian, 16-bit, value + 1\n const uncompSize = ((input[offset] << 8) | input[offset + 1]) + 1;\n offset += 2;\n\n if (offset + uncompSize > input.length) {\n throw new Error('Truncated LZMA2 uncompressed data');\n }\n\n // Get the uncompressed data\n const uncompData = input.slice(offset, offset + uncompSize);\n\n // Copy uncompressed data to output\n if (outputBuffer) {\n uncompData.copy(outputBuffer, outputPos);\n outputPos += uncompData.length;\n } else {\n outputChunks?.push(uncompData);\n }\n\n // Also update the decoder's internal dictionary so subsequent LZMA chunks can reference it\n // The decoder needs to track this data for LZ77 back-references\n // We write directly to _buffer to avoid flush() which requires _stream to be set\n // We must also update _streamPos to match _pos so that flush() doesn't try to write\n for (let i = 0; i < uncompData.length; i++) {\n outWindow._buffer[outWindow._pos++] = uncompData[i];\n // Handle circular buffer wrap-around\n if (outWindow._pos >= outWindow._windowSize) {\n outWindow._pos = 0;\n }\n }\n // Keep _streamPos in sync so flush() doesn't try to write these bytes\n // (they're already in our output buffer)\n outWindow._streamPos = outWindow._pos;\n\n // Update decoder's cumulative position so subsequent LZMA chunks have correct rep0 validation\n decoder._nowPos64 += uncompSize;\n\n // Update prevByte for literal decoder context in subsequent LZMA chunks\n decoder._prevByte = uncompData[uncompData.length - 1];\n\n offset += uncompSize;\n } else if (control >= 0x80) {\n // LZMA compressed chunk\n // Control byte format (bits 7-0):\n // Bit 7: always 1 for LZMA chunk\n // Bits 6-5: reset mode (00=nothing, 01=state, 10=state+props, 11=all)\n // Bits 4-0: high 5 bits of uncompressed size - 1\n\n // Control byte ranges (based on bits 6-5):\n // 0x80-0x9F (00): no reset - continue existing state (solid mode)\n // 0xA0-0xBF (01): reset state only\n // 0xC0-0xDF (10): reset state + new properties\n // 0xE0-0xFF (11): reset dictionary + state + new properties\n const resetState = control >= 0xa0;\n const newProps = control >= 0xc0;\n const dictReset = control >= 0xe0;\n const useSolidMode = !resetState;\n\n // Handle dictionary reset for control bytes 0xE0-0xFF\n if (dictReset) {\n outWindow._pos = 0;\n outWindow._streamPos = 0;\n }\n\n if (offset + 4 > input.length) {\n throw new Error('Truncated LZMA2 LZMA chunk header');\n }\n\n // Uncompressed size: 5 bits from control + 16 bits from next 2 bytes + 1\n const uncompHigh = control & 0x1f;\n const uncompSize2 = ((uncompHigh << 16) | (input[offset] << 8) | input[offset + 1]) + 1;\n offset += 2;\n\n // Compressed size: 16 bits + 1\n const compSize = ((input[offset] << 8) | input[offset + 1]) + 1;\n offset += 2;\n\n // If new properties, read 1-byte LZMA properties\n if (newProps) {\n if (offset >= input.length) {\n throw new Error('Truncated LZMA2 properties byte');\n }\n const propsByte = input[offset++];\n\n // Properties byte: pb * 45 + lp * 9 + lc\n // where pb, lp, lc are LZMA parameters\n const lc = propsByte % 9;\n const remainder = Math.floor(propsByte / 9);\n const lp = remainder % 5;\n const pb = Math.floor(remainder / 5);\n\n if (!decoder.setLcLpPb(lc, lp, pb)) {\n throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);\n }\n propsSet = true;\n }\n\n if (!propsSet) {\n throw new Error('LZMA chunk without properties');\n }\n\n if (offset + compSize > input.length) {\n throw new Error('Truncated LZMA2 compressed data');\n }\n\n // Decode LZMA chunk\n const inStream = createInputStream(input, offset, compSize);\n const outStream = createOutputStream(uncompSize2); // Pre-allocate for memory efficiency\n\n // Set solid mode based on control byte - this preserves state across code() calls\n // For state reset WITHOUT dict reset (0xa0-0xdf), use resetProbabilities() to\n // reset probability tables while preserving _nowPos64 for dictionary references\n if (resetState && !dictReset) {\n decoder.resetProbabilities();\n decoder.setSolid(true); // Preserve _nowPos64 in code()\n } else {\n decoder.setSolid(useSolidMode);\n }\n\n // Decode the chunk\n const success = decoder.code(inStream, outStream, uncompSize2);\n if (!success) {\n throw new Error('LZMA decompression failed');\n }\n\n const chunkOutput = outStream.toBuffer();\n if (outputBuffer) {\n chunkOutput.copy(outputBuffer, outputPos);\n outputPos += chunkOutput.length;\n } else {\n outputChunks?.push(chunkOutput);\n }\n\n offset += compSize;\n } else {\n throw new Error(`Invalid LZMA2 control byte: 0x${control.toString(16)}`);\n }\n }\n\n // Return pre-allocated buffer or concatenated chunks\n if (outputBuffer) {\n // Return only the used portion if we didn't fill the buffer\n return outputPos < outputBuffer.length ? outputBuffer.slice(0, outputPos) : outputBuffer;\n }\n return Buffer.concat(outputChunks);\n}\n\n/**\n * Create an LZMA2 decoder Transform stream\n */\nexport function createLzma2Decoder(properties?: Buffer, unpackSize?: number): Transform {\n return createBufferingDecoder(decodeLzma2, properties, unpackSize);\n}\n"],"names":["Module","_require","require","createRequire","url","allocBufferUnsafe","createBufferingDecoder","createInputStream","createOutputStream","LZMA","LzmaDecoder","Decoder","decodeDictionarySize","propByte","Error","base","shift","Math","floor","decodeLzma2","input","properties","unpackSize","length","dictSize","outputBuffer","outputPos","outputChunks","offset","decoder","setDictionarySize","outWindow","_outWindow","propsSet","control","_pos","_streamPos","_nowPos64","uncompSize","uncompData","slice","copy","push","i","_buffer","_windowSize","_prevByte","resetState","newProps","dictReset","useSolidMode","uncompHigh","uncompSize2","compSize","propsByte","lc","remainder","lp","pb","setLcLpPb","inStream","outStream","resetProbabilities","setSolid","success","code","chunkOutput","toBuffer","toString","Buffer","concat","createLzma2Decoder"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE1F,gCAAgC;AAChC,kEAAkE;AAClE,EAAE;AACF,8BAA8B;AAC9B,2DAA2D;AAC3D,EAAE;AACF,uBAAuB;AACvB,+BAA+B;AAC/B,sDAAsD;AACtD,yDAAyD;AACzD,0EAA0E;AAE1E,SAASG,iBAAiB,QAAQ,wBAAwB;AAE1D,OAAOC,4BAA4B,8BAA8B;AACjE,SAASC,iBAAiB,EAAEC,kBAAkB,QAAQ,eAAe;AAErE,sFAAsF;AACtF,4DAA4D;AAC5D,MAAM,EAAEC,IAAI,EAAE,GAAGR,SAAS;AAC1B,MAAMS,cAAcD,KAAKE,OAAO;AAEhC;;;;;;;;;;CAUC,GACD,SAASC,qBAAqBC,QAAgB;IAC5C,IAAIA,WAAW,IAAI;QACjB,MAAM,IAAIC,MAAM,CAAC,wCAAwC,EAAED,UAAU;IACvE;IACA,IAAIA,aAAa,IAAI;QACnB,iCAAiC;QACjC,OAAO;IACT;IACA,8DAA8D;IAC9D,MAAME,OAAO,IAAKF,WAAW;IAC7B,MAAMG,QAAQC,KAAKC,KAAK,CAACL,WAAW,KAAK;IACzC,OAAOE,QAAQC;AACjB;AAEA;;;;;;;CAOC,GACD,OAAO,SAASG,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mBAAmB;YACnB,MAAMc,UAAUnC,QAAQoC,IAAI,CAACL,UAAUC,WAAWT;YAClD,IAAI,CAACY,SAAS;gBACZ,MAAM,IAAIlD,MAAM;YAClB;YAEA,MAAMoD,cAAcL,UAAUM,QAAQ;YACtC,IAAI1C,cAAc;gBAChByC,YAAYzB,IAAI,CAAChB,cAAcC;gBAC/BA,aAAawC,YAAY3C,MAAM;YACjC,OAAO;gBACLI,yBAAAA,mCAAAA,aAAce,IAAI,CAACwB;YACrB;YAEAtC,UAAUyB;QACZ,OAAO;YACL,MAAM,IAAIvC,MAAM,CAAC,8BAA8B,EAAEoB,QAAQkC,QAAQ,CAAC,KAAK;QACzE;IACF;IAEA,qDAAqD;IACrD,IAAI3C,cAAc;QAChB,4DAA4D;QAC5D,OAAOC,YAAYD,aAAaF,MAAM,GAAGE,aAAae,KAAK,CAAC,GAAGd,aAAaD;IAC9E;IACA,OAAO4C,OAAOC,MAAM,CAAC3C;AACvB;AAEA;;CAEC,GACD,OAAO,SAAS4C,mBAAmBlD,UAAmB,EAAEC,UAAmB;IACzE,OAAOhB,uBAAuBa,aAAaE,YAAYC;AACzD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "7z-iterator",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Extract contents from 7z archives using an iterator API. Pure JavaScript, works on Node.js 0.8+",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"extract",
|
|
@@ -66,15 +66,11 @@
|
|
|
66
66
|
"fs-iterator": "^7.0.0",
|
|
67
67
|
"fs-stats-spys": "^1.0.0",
|
|
68
68
|
"get-file-compat": "^2.0.0",
|
|
69
|
-
"lzma-native": "^8.0.6",
|
|
70
69
|
"node-version-use": "*",
|
|
71
70
|
"pinkie-promise": "*",
|
|
72
71
|
"ts-dev-stack": "*",
|
|
73
72
|
"tsds-config": "*"
|
|
74
73
|
},
|
|
75
|
-
"optionalDependencies": {
|
|
76
|
-
"lzma-native": "^8.0.6"
|
|
77
|
-
},
|
|
78
74
|
"engines": {
|
|
79
75
|
"node": ">=0.8"
|
|
80
76
|
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LZMA compatibility layer - uses native lzma when available, falls back to lzma-purejs
|
|
3
|
-
*
|
|
4
|
-
* lzma-native provides native liblzma bindings with rawDecoder support.
|
|
5
|
-
* This gives significant performance improvements on Node.js 8+ while
|
|
6
|
-
* maintaining compatibility with Node.js 0.8+ via lzma-purejs fallback.
|
|
7
|
-
*
|
|
8
|
-
* The native decoder uses Node.js streams which integrate naturally with
|
|
9
|
-
* the callback-based async pattern used throughout the iterator libraries.
|
|
10
|
-
*/
|
|
11
|
-
import type { Transform } from 'readable-stream';
|
|
12
|
-
export declare const hasNativeLzma: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Create a native LZMA2 decoder stream
|
|
15
|
-
* Returns a Transform stream that decodes LZMA2 data
|
|
16
|
-
*
|
|
17
|
-
* Note: Native LZMA2 decoder disabled due to LZMA_DATA_ERROR issues with
|
|
18
|
-
* lzma-native's rawDecoder for LZMA2. The native decoder fails partway through
|
|
19
|
-
* decompression on certain archives (e.g., Node.js Windows releases), reporting
|
|
20
|
-
* "Data is corrupt" even when the data is valid. Falls back to lzma-purejs
|
|
21
|
-
* which handles all LZMA2 streams correctly.
|
|
22
|
-
*
|
|
23
|
-
* @param _dictSize - Dictionary size (unused, native disabled)
|
|
24
|
-
* @returns null - always falls back to pure JS decoder
|
|
25
|
-
*/
|
|
26
|
-
export declare function createNativeLzma2Decoder(_dictSize?: number): Transform | null;
|
|
27
|
-
/**
|
|
28
|
-
* Create a native LZMA1 decoder stream
|
|
29
|
-
* Returns a Transform stream that decodes LZMA1 data
|
|
30
|
-
*
|
|
31
|
-
* Note: Native LZMA1 decoder disabled due to LZMA_BUF_ERROR issues with
|
|
32
|
-
* lzma-native's rawDecoder for LZMA1. Falls back to lzma-purejs which
|
|
33
|
-
* handles 7z's LZMA1 format correctly. LZMA2 native works fine.
|
|
34
|
-
*
|
|
35
|
-
* @param _lc - Literal context bits (0-8)
|
|
36
|
-
* @param _lp - Literal position bits (0-4)
|
|
37
|
-
* @param _pb - Position bits (0-4)
|
|
38
|
-
* @param _dictSize - Dictionary size
|
|
39
|
-
* @returns null - always falls back to pure JS decoder
|
|
40
|
-
*/
|
|
41
|
-
export declare function createNativeLzma1Decoder(_lc: number, _lp: number, _pb: number, _dictSize: number): Transform | null;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LZMA compatibility layer - uses native lzma when available, falls back to lzma-purejs
|
|
3
|
-
*
|
|
4
|
-
* lzma-native provides native liblzma bindings with rawDecoder support.
|
|
5
|
-
* This gives significant performance improvements on Node.js 8+ while
|
|
6
|
-
* maintaining compatibility with Node.js 0.8+ via lzma-purejs fallback.
|
|
7
|
-
*
|
|
8
|
-
* The native decoder uses Node.js streams which integrate naturally with
|
|
9
|
-
* the callback-based async pattern used throughout the iterator libraries.
|
|
10
|
-
*/
|
|
11
|
-
import type { Transform } from 'readable-stream';
|
|
12
|
-
export declare const hasNativeLzma: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Create a native LZMA2 decoder stream
|
|
15
|
-
* Returns a Transform stream that decodes LZMA2 data
|
|
16
|
-
*
|
|
17
|
-
* Note: Native LZMA2 decoder disabled due to LZMA_DATA_ERROR issues with
|
|
18
|
-
* lzma-native's rawDecoder for LZMA2. The native decoder fails partway through
|
|
19
|
-
* decompression on certain archives (e.g., Node.js Windows releases), reporting
|
|
20
|
-
* "Data is corrupt" even when the data is valid. Falls back to lzma-purejs
|
|
21
|
-
* which handles all LZMA2 streams correctly.
|
|
22
|
-
*
|
|
23
|
-
* @param _dictSize - Dictionary size (unused, native disabled)
|
|
24
|
-
* @returns null - always falls back to pure JS decoder
|
|
25
|
-
*/
|
|
26
|
-
export declare function createNativeLzma2Decoder(_dictSize?: number): Transform | null;
|
|
27
|
-
/**
|
|
28
|
-
* Create a native LZMA1 decoder stream
|
|
29
|
-
* Returns a Transform stream that decodes LZMA1 data
|
|
30
|
-
*
|
|
31
|
-
* Note: Native LZMA1 decoder disabled due to LZMA_BUF_ERROR issues with
|
|
32
|
-
* lzma-native's rawDecoder for LZMA1. Falls back to lzma-purejs which
|
|
33
|
-
* handles 7z's LZMA1 format correctly. LZMA2 native works fine.
|
|
34
|
-
*
|
|
35
|
-
* @param _lc - Literal context bits (0-8)
|
|
36
|
-
* @param _lp - Literal position bits (0-4)
|
|
37
|
-
* @param _pb - Position bits (0-4)
|
|
38
|
-
* @param _dictSize - Dictionary size
|
|
39
|
-
* @returns null - always falls back to pure JS decoder
|
|
40
|
-
*/
|
|
41
|
-
export declare function createNativeLzma1Decoder(_lc: number, _lp: number, _pb: number, _dictSize: number): Transform | null;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LZMA compatibility layer - uses native lzma when available, falls back to lzma-purejs
|
|
3
|
-
*
|
|
4
|
-
* lzma-native provides native liblzma bindings with rawDecoder support.
|
|
5
|
-
* This gives significant performance improvements on Node.js 8+ while
|
|
6
|
-
* maintaining compatibility with Node.js 0.8+ via lzma-purejs fallback.
|
|
7
|
-
*
|
|
8
|
-
* The native decoder uses Node.js streams which integrate naturally with
|
|
9
|
-
* the callback-based async pattern used throughout the iterator libraries.
|
|
10
|
-
*/ "use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", {
|
|
12
|
-
value: true
|
|
13
|
-
});
|
|
14
|
-
function _export(target, all) {
|
|
15
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
_export(exports, {
|
|
21
|
-
get createNativeLzma1Decoder () {
|
|
22
|
-
return createNativeLzma1Decoder;
|
|
23
|
-
},
|
|
24
|
-
get createNativeLzma2Decoder () {
|
|
25
|
-
return createNativeLzma2Decoder;
|
|
26
|
-
},
|
|
27
|
-
get hasNativeLzma () {
|
|
28
|
-
return hasNativeLzma;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
var _module = /*#__PURE__*/ _interop_require_default(require("module"));
|
|
32
|
-
function _interop_require_default(obj) {
|
|
33
|
-
return obj && obj.__esModule ? obj : {
|
|
34
|
-
default: obj
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
|
|
38
|
-
// Try to load lzma-native (only on Node 10+ where ES6 class syntax is supported)
|
|
39
|
-
// Note: We must check the version BEFORE requiring because syntax errors during
|
|
40
|
-
// module parsing cannot be caught by try/catch
|
|
41
|
-
var lzmaNative = null;
|
|
42
|
-
var _hasNativeLzmaLib = false;
|
|
43
|
-
var major = +process.versions.node.split('.')[0];
|
|
44
|
-
if (major >= 10) {
|
|
45
|
-
try {
|
|
46
|
-
lzmaNative = _require('lzma-native');
|
|
47
|
-
// Verify rawDecoder support
|
|
48
|
-
_hasNativeLzmaLib = lzmaNative !== null && typeof lzmaNative.createStream === 'function';
|
|
49
|
-
} catch (_e) {
|
|
50
|
-
// lzma-native not available - will use lzma-purejs
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
var hasNativeLzma = _hasNativeLzmaLib;
|
|
54
|
-
function createNativeLzma2Decoder(_dictSize) {
|
|
55
|
-
// Native LZMA2 disabled - lzma-native's rawDecoder has issues with certain
|
|
56
|
-
// LZMA2 streams (LZMA_DATA_ERROR: Data is corrupt), even when data is valid.
|
|
57
|
-
// The pure JS lzma-purejs implementation handles all streams correctly.
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
function createNativeLzma1Decoder(_lc, _lp, _pb, _dictSize) {
|
|
61
|
-
// Native LZMA1 disabled - lzma-native's rawDecoder has issues with 7z's LZMA1 format
|
|
62
|
-
// (LZMA_BUF_ERROR: No progress is possible)
|
|
63
|
-
// LZMA2 native works correctly and is more common in modern 7z files
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/lzmaCompat.ts"],"sourcesContent":["/**\n * LZMA compatibility layer - uses native lzma when available, falls back to lzma-purejs\n *\n * lzma-native provides native liblzma bindings with rawDecoder support.\n * This gives significant performance improvements on Node.js 8+ while\n * maintaining compatibility with Node.js 0.8+ via lzma-purejs fallback.\n *\n * The native decoder uses Node.js streams which integrate naturally with\n * the callback-based async pattern used throughout the iterator libraries.\n */\n\nimport Module from 'module';\nimport type { Transform } from 'readable-stream';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// Try to load lzma-native (only on Node 10+ where ES6 class syntax is supported)\n// Note: We must check the version BEFORE requiring because syntax errors during\n// module parsing cannot be caught by try/catch\nlet lzmaNative: typeof import('lzma-native') | null = null;\nlet _hasNativeLzmaLib = false;\nconst major = +process.versions.node.split('.')[0];\n\nif (major >= 10) {\n try {\n lzmaNative = _require('lzma-native');\n // Verify rawDecoder support\n _hasNativeLzmaLib = lzmaNative !== null && typeof lzmaNative.createStream === 'function';\n } catch (_e) {\n // lzma-native not available - will use lzma-purejs\n }\n}\n\n// Export whether native lzma is available for streaming\nexport const hasNativeLzma = _hasNativeLzmaLib;\n\n/**\n * Create a native LZMA2 decoder stream\n * Returns a Transform stream that decodes LZMA2 data\n *\n * Note: Native LZMA2 decoder disabled due to LZMA_DATA_ERROR issues with\n * lzma-native's rawDecoder for LZMA2. The native decoder fails partway through\n * decompression on certain archives (e.g., Node.js Windows releases), reporting\n * \"Data is corrupt\" even when the data is valid. Falls back to lzma-purejs\n * which handles all LZMA2 streams correctly.\n *\n * @param _dictSize - Dictionary size (unused, native disabled)\n * @returns null - always falls back to pure JS decoder\n */\nexport function createNativeLzma2Decoder(_dictSize?: number): Transform | null {\n // Native LZMA2 disabled - lzma-native's rawDecoder has issues with certain\n // LZMA2 streams (LZMA_DATA_ERROR: Data is corrupt), even when data is valid.\n // The pure JS lzma-purejs implementation handles all streams correctly.\n return null;\n}\n\n/**\n * Create a native LZMA1 decoder stream\n * Returns a Transform stream that decodes LZMA1 data\n *\n * Note: Native LZMA1 decoder disabled due to LZMA_BUF_ERROR issues with\n * lzma-native's rawDecoder for LZMA1. Falls back to lzma-purejs which\n * handles 7z's LZMA1 format correctly. LZMA2 native works fine.\n *\n * @param _lc - Literal context bits (0-8)\n * @param _lp - Literal position bits (0-4)\n * @param _pb - Position bits (0-4)\n * @param _dictSize - Dictionary size\n * @returns null - always falls back to pure JS decoder\n */\nexport function createNativeLzma1Decoder(_lc: number, _lp: number, _pb: number, _dictSize: number): Transform | null {\n // Native LZMA1 disabled - lzma-native's rawDecoder has issues with 7z's LZMA1 format\n // (LZMA_BUF_ERROR: No progress is possible)\n // LZMA2 native works correctly and is more common in modern 7z files\n return null;\n}\n"],"names":["createNativeLzma1Decoder","createNativeLzma2Decoder","hasNativeLzma","_require","require","Module","createRequire","lzmaNative","_hasNativeLzmaLib","major","process","versions","node","split","createStream","_e","_dictSize","_lc","_lp","_pb"],"mappings":"AAAA;;;;;;;;;CASC;;;;;;;;;;;QA6DeA;eAAAA;;QArBAC;eAAAA;;QAfHC;eAAAA;;;6DAvBM;;;;;;AAGnB,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAE1F,iFAAiF;AACjF,gFAAgF;AAChF,+CAA+C;AAC/C,IAAIG,aAAkD;AACtD,IAAIC,oBAAoB;AACxB,IAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAElD,IAAIJ,SAAS,IAAI;IACf,IAAI;QACFF,aAAaJ,SAAS;QACtB,4BAA4B;QAC5BK,oBAAoBD,eAAe,QAAQ,OAAOA,WAAWO,YAAY,KAAK;IAChF,EAAE,OAAOC,IAAI;IACX,mDAAmD;IACrD;AACF;AAGO,IAAMb,gBAAgBM;AAetB,SAASP,yBAAyBe,SAAkB;IACzD,2EAA2E;IAC3E,6EAA6E;IAC7E,wEAAwE;IACxE,OAAO;AACT;AAgBO,SAAShB,yBAAyBiB,GAAW,EAAEC,GAAW,EAAEC,GAAW,EAAEH,SAAiB;IAC/F,qFAAqF;IACrF,4CAA4C;IAC5C,qEAAqE;IACrE,OAAO;AACT"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LZMA compatibility layer - uses native lzma when available, falls back to lzma-purejs
|
|
3
|
-
*
|
|
4
|
-
* lzma-native provides native liblzma bindings with rawDecoder support.
|
|
5
|
-
* This gives significant performance improvements on Node.js 8+ while
|
|
6
|
-
* maintaining compatibility with Node.js 0.8+ via lzma-purejs fallback.
|
|
7
|
-
*
|
|
8
|
-
* The native decoder uses Node.js streams which integrate naturally with
|
|
9
|
-
* the callback-based async pattern used throughout the iterator libraries.
|
|
10
|
-
*/
|
|
11
|
-
import type { Transform } from 'readable-stream';
|
|
12
|
-
export declare const hasNativeLzma: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Create a native LZMA2 decoder stream
|
|
15
|
-
* Returns a Transform stream that decodes LZMA2 data
|
|
16
|
-
*
|
|
17
|
-
* Note: Native LZMA2 decoder disabled due to LZMA_DATA_ERROR issues with
|
|
18
|
-
* lzma-native's rawDecoder for LZMA2. The native decoder fails partway through
|
|
19
|
-
* decompression on certain archives (e.g., Node.js Windows releases), reporting
|
|
20
|
-
* "Data is corrupt" even when the data is valid. Falls back to lzma-purejs
|
|
21
|
-
* which handles all LZMA2 streams correctly.
|
|
22
|
-
*
|
|
23
|
-
* @param _dictSize - Dictionary size (unused, native disabled)
|
|
24
|
-
* @returns null - always falls back to pure JS decoder
|
|
25
|
-
*/
|
|
26
|
-
export declare function createNativeLzma2Decoder(_dictSize?: number): Transform | null;
|
|
27
|
-
/**
|
|
28
|
-
* Create a native LZMA1 decoder stream
|
|
29
|
-
* Returns a Transform stream that decodes LZMA1 data
|
|
30
|
-
*
|
|
31
|
-
* Note: Native LZMA1 decoder disabled due to LZMA_BUF_ERROR issues with
|
|
32
|
-
* lzma-native's rawDecoder for LZMA1. Falls back to lzma-purejs which
|
|
33
|
-
* handles 7z's LZMA1 format correctly. LZMA2 native works fine.
|
|
34
|
-
*
|
|
35
|
-
* @param _lc - Literal context bits (0-8)
|
|
36
|
-
* @param _lp - Literal position bits (0-4)
|
|
37
|
-
* @param _pb - Position bits (0-4)
|
|
38
|
-
* @param _dictSize - Dictionary size
|
|
39
|
-
* @returns null - always falls back to pure JS decoder
|
|
40
|
-
*/
|
|
41
|
-
export declare function createNativeLzma1Decoder(_lc: number, _lp: number, _pb: number, _dictSize: number): Transform | null;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LZMA compatibility layer - uses native lzma when available, falls back to lzma-purejs
|
|
3
|
-
*
|
|
4
|
-
* lzma-native provides native liblzma bindings with rawDecoder support.
|
|
5
|
-
* This gives significant performance improvements on Node.js 8+ while
|
|
6
|
-
* maintaining compatibility with Node.js 0.8+ via lzma-purejs fallback.
|
|
7
|
-
*
|
|
8
|
-
* The native decoder uses Node.js streams which integrate naturally with
|
|
9
|
-
* the callback-based async pattern used throughout the iterator libraries.
|
|
10
|
-
*/ import Module from 'module';
|
|
11
|
-
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
12
|
-
// Try to load lzma-native (only on Node 10+ where ES6 class syntax is supported)
|
|
13
|
-
// Note: We must check the version BEFORE requiring because syntax errors during
|
|
14
|
-
// module parsing cannot be caught by try/catch
|
|
15
|
-
let lzmaNative = null;
|
|
16
|
-
let _hasNativeLzmaLib = false;
|
|
17
|
-
const major = +process.versions.node.split('.')[0];
|
|
18
|
-
if (major >= 10) {
|
|
19
|
-
try {
|
|
20
|
-
lzmaNative = _require('lzma-native');
|
|
21
|
-
// Verify rawDecoder support
|
|
22
|
-
_hasNativeLzmaLib = lzmaNative !== null && typeof lzmaNative.createStream === 'function';
|
|
23
|
-
} catch (_e) {
|
|
24
|
-
// lzma-native not available - will use lzma-purejs
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
// Export whether native lzma is available for streaming
|
|
28
|
-
export const hasNativeLzma = _hasNativeLzmaLib;
|
|
29
|
-
/**
|
|
30
|
-
* Create a native LZMA2 decoder stream
|
|
31
|
-
* Returns a Transform stream that decodes LZMA2 data
|
|
32
|
-
*
|
|
33
|
-
* Note: Native LZMA2 decoder disabled due to LZMA_DATA_ERROR issues with
|
|
34
|
-
* lzma-native's rawDecoder for LZMA2. The native decoder fails partway through
|
|
35
|
-
* decompression on certain archives (e.g., Node.js Windows releases), reporting
|
|
36
|
-
* "Data is corrupt" even when the data is valid. Falls back to lzma-purejs
|
|
37
|
-
* which handles all LZMA2 streams correctly.
|
|
38
|
-
*
|
|
39
|
-
* @param _dictSize - Dictionary size (unused, native disabled)
|
|
40
|
-
* @returns null - always falls back to pure JS decoder
|
|
41
|
-
*/ export function createNativeLzma2Decoder(_dictSize) {
|
|
42
|
-
// Native LZMA2 disabled - lzma-native's rawDecoder has issues with certain
|
|
43
|
-
// LZMA2 streams (LZMA_DATA_ERROR: Data is corrupt), even when data is valid.
|
|
44
|
-
// The pure JS lzma-purejs implementation handles all streams correctly.
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Create a native LZMA1 decoder stream
|
|
49
|
-
* Returns a Transform stream that decodes LZMA1 data
|
|
50
|
-
*
|
|
51
|
-
* Note: Native LZMA1 decoder disabled due to LZMA_BUF_ERROR issues with
|
|
52
|
-
* lzma-native's rawDecoder for LZMA1. Falls back to lzma-purejs which
|
|
53
|
-
* handles 7z's LZMA1 format correctly. LZMA2 native works fine.
|
|
54
|
-
*
|
|
55
|
-
* @param _lc - Literal context bits (0-8)
|
|
56
|
-
* @param _lp - Literal position bits (0-4)
|
|
57
|
-
* @param _pb - Position bits (0-4)
|
|
58
|
-
* @param _dictSize - Dictionary size
|
|
59
|
-
* @returns null - always falls back to pure JS decoder
|
|
60
|
-
*/ export function createNativeLzma1Decoder(_lc, _lp, _pb, _dictSize) {
|
|
61
|
-
// Native LZMA1 disabled - lzma-native's rawDecoder has issues with 7z's LZMA1 format
|
|
62
|
-
// (LZMA_BUF_ERROR: No progress is possible)
|
|
63
|
-
// LZMA2 native works correctly and is more common in modern 7z files
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/lzmaCompat.ts"],"sourcesContent":["/**\n * LZMA compatibility layer - uses native lzma when available, falls back to lzma-purejs\n *\n * lzma-native provides native liblzma bindings with rawDecoder support.\n * This gives significant performance improvements on Node.js 8+ while\n * maintaining compatibility with Node.js 0.8+ via lzma-purejs fallback.\n *\n * The native decoder uses Node.js streams which integrate naturally with\n * the callback-based async pattern used throughout the iterator libraries.\n */\n\nimport Module from 'module';\nimport type { Transform } from 'readable-stream';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n// Try to load lzma-native (only on Node 10+ where ES6 class syntax is supported)\n// Note: We must check the version BEFORE requiring because syntax errors during\n// module parsing cannot be caught by try/catch\nlet lzmaNative: typeof import('lzma-native') | null = null;\nlet _hasNativeLzmaLib = false;\nconst major = +process.versions.node.split('.')[0];\n\nif (major >= 10) {\n try {\n lzmaNative = _require('lzma-native');\n // Verify rawDecoder support\n _hasNativeLzmaLib = lzmaNative !== null && typeof lzmaNative.createStream === 'function';\n } catch (_e) {\n // lzma-native not available - will use lzma-purejs\n }\n}\n\n// Export whether native lzma is available for streaming\nexport const hasNativeLzma = _hasNativeLzmaLib;\n\n/**\n * Create a native LZMA2 decoder stream\n * Returns a Transform stream that decodes LZMA2 data\n *\n * Note: Native LZMA2 decoder disabled due to LZMA_DATA_ERROR issues with\n * lzma-native's rawDecoder for LZMA2. The native decoder fails partway through\n * decompression on certain archives (e.g., Node.js Windows releases), reporting\n * \"Data is corrupt\" even when the data is valid. Falls back to lzma-purejs\n * which handles all LZMA2 streams correctly.\n *\n * @param _dictSize - Dictionary size (unused, native disabled)\n * @returns null - always falls back to pure JS decoder\n */\nexport function createNativeLzma2Decoder(_dictSize?: number): Transform | null {\n // Native LZMA2 disabled - lzma-native's rawDecoder has issues with certain\n // LZMA2 streams (LZMA_DATA_ERROR: Data is corrupt), even when data is valid.\n // The pure JS lzma-purejs implementation handles all streams correctly.\n return null;\n}\n\n/**\n * Create a native LZMA1 decoder stream\n * Returns a Transform stream that decodes LZMA1 data\n *\n * Note: Native LZMA1 decoder disabled due to LZMA_BUF_ERROR issues with\n * lzma-native's rawDecoder for LZMA1. Falls back to lzma-purejs which\n * handles 7z's LZMA1 format correctly. LZMA2 native works fine.\n *\n * @param _lc - Literal context bits (0-8)\n * @param _lp - Literal position bits (0-4)\n * @param _pb - Position bits (0-4)\n * @param _dictSize - Dictionary size\n * @returns null - always falls back to pure JS decoder\n */\nexport function createNativeLzma1Decoder(_lc: number, _lp: number, _pb: number, _dictSize: number): Transform | null {\n // Native LZMA1 disabled - lzma-native's rawDecoder has issues with 7z's LZMA1 format\n // (LZMA_BUF_ERROR: No progress is possible)\n // LZMA2 native works correctly and is more common in modern 7z files\n return null;\n}\n"],"names":["Module","_require","require","createRequire","url","lzmaNative","_hasNativeLzmaLib","major","process","versions","node","split","createStream","_e","hasNativeLzma","createNativeLzma2Decoder","_dictSize","createNativeLzma1Decoder","_lc","_lp","_pb"],"mappings":"AAAA;;;;;;;;;CASC,GAED,OAAOA,YAAY,SAAS;AAG5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAE1F,iFAAiF;AACjF,gFAAgF;AAChF,+CAA+C;AAC/C,IAAIG,aAAkD;AACtD,IAAIC,oBAAoB;AACxB,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAElD,IAAIJ,SAAS,IAAI;IACf,IAAI;QACFF,aAAaJ,SAAS;QACtB,4BAA4B;QAC5BK,oBAAoBD,eAAe,QAAQ,OAAOA,WAAWO,YAAY,KAAK;IAChF,EAAE,OAAOC,IAAI;IACX,mDAAmD;IACrD;AACF;AAEA,wDAAwD;AACxD,OAAO,MAAMC,gBAAgBR,kBAAkB;AAE/C;;;;;;;;;;;;CAYC,GACD,OAAO,SAASS,yBAAyBC,SAAkB;IACzD,2EAA2E;IAC3E,6EAA6E;IAC7E,wEAAwE;IACxE,OAAO;AACT;AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASC,yBAAyBC,GAAW,EAAEC,GAAW,EAAEC,GAAW,EAAEJ,SAAiB;IAC/F,qFAAqF;IACrF,4CAA4C;IAC5C,qEAAqE;IACrE,OAAO;AACT"}
|