7z-iterator 0.2.9 → 0.2.10
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/FileEntry.js.map +1 -1
- package/dist/cjs/SevenZipIterator.js.map +1 -1
- package/dist/cjs/compat.js.map +1 -1
- package/dist/cjs/lib/streamToSource.js.map +1 -1
- package/dist/cjs/nextEntry.js.map +1 -1
- package/dist/cjs/sevenz/NumberCodec.js.map +1 -1
- package/dist/cjs/sevenz/SevenZipParser.js.map +1 -1
- package/dist/cjs/sevenz/codecs/Aes.js.map +1 -1
- package/dist/cjs/sevenz/codecs/Bcj.js +1 -1
- package/dist/cjs/sevenz/codecs/Bcj.js.map +1 -1
- package/dist/cjs/sevenz/codecs/Bcj2.js.map +1 -1
- package/dist/cjs/sevenz/codecs/BcjArm.js.map +1 -1
- package/dist/cjs/sevenz/codecs/BcjArm64.js.map +1 -1
- package/dist/cjs/sevenz/codecs/BcjArmt.js.map +1 -1
- package/dist/cjs/sevenz/codecs/BcjIa64.js.map +1 -1
- package/dist/cjs/sevenz/codecs/BcjPpc.js.map +1 -1
- package/dist/cjs/sevenz/codecs/BcjSparc.js.map +1 -1
- package/dist/cjs/sevenz/codecs/Delta.js.map +1 -1
- package/dist/cjs/sevenz/codecs/Lzma.js.map +1 -1
- package/dist/cjs/sevenz/codecs/Lzma2.js.map +1 -1
- package/dist/cjs/sevenz/codecs/createBufferingDecoder.js.map +1 -1
- package/dist/cjs/sevenz/codecs/index.js.map +1 -1
- package/dist/cjs/sevenz/codecs/lzmaCompat.d.cts +1 -1
- package/dist/cjs/sevenz/codecs/lzmaCompat.d.ts +1 -1
- package/dist/cjs/sevenz/codecs/lzmaCompat.js.map +1 -1
- package/dist/cjs/sevenz/codecs/streams.js.map +1 -1
- package/dist/cjs/sevenz/constants.d.cts +8 -8
- package/dist/cjs/sevenz/constants.d.ts +8 -8
- package/dist/cjs/sevenz/constants.js.map +1 -1
- package/dist/cjs/sevenz/headers.js +1 -1
- package/dist/cjs/sevenz/headers.js.map +1 -1
- package/dist/esm/FileEntry.js +1 -1
- package/dist/esm/FileEntry.js.map +1 -1
- package/dist/esm/SevenZipIterator.js +6 -6
- package/dist/esm/SevenZipIterator.js.map +1 -1
- package/dist/esm/compat.js +2 -2
- package/dist/esm/compat.js.map +1 -1
- package/dist/esm/lib/streamToSource.js +12 -12
- package/dist/esm/lib/streamToSource.js.map +1 -1
- package/dist/esm/nextEntry.js +11 -11
- package/dist/esm/nextEntry.js.map +1 -1
- package/dist/esm/sevenz/NumberCodec.js +19 -19
- package/dist/esm/sevenz/NumberCodec.js.map +1 -1
- package/dist/esm/sevenz/SevenZipParser.js +191 -191
- package/dist/esm/sevenz/SevenZipParser.js.map +1 -1
- package/dist/esm/sevenz/codecs/Aes.js +29 -29
- package/dist/esm/sevenz/codecs/Aes.js.map +1 -1
- package/dist/esm/sevenz/codecs/Bcj.js +8 -8
- package/dist/esm/sevenz/codecs/Bcj.js.map +1 -1
- package/dist/esm/sevenz/codecs/Bcj2.js +35 -35
- package/dist/esm/sevenz/codecs/Bcj2.js.map +1 -1
- package/dist/esm/sevenz/codecs/BcjArm.js +4 -4
- package/dist/esm/sevenz/codecs/BcjArm.js.map +1 -1
- package/dist/esm/sevenz/codecs/BcjArm64.js +5 -5
- package/dist/esm/sevenz/codecs/BcjArm64.js.map +1 -1
- package/dist/esm/sevenz/codecs/BcjArmt.js +10 -10
- package/dist/esm/sevenz/codecs/BcjArmt.js.map +1 -1
- package/dist/esm/sevenz/codecs/BcjIa64.js +24 -24
- package/dist/esm/sevenz/codecs/BcjIa64.js.map +1 -1
- package/dist/esm/sevenz/codecs/BcjPpc.js +5 -5
- package/dist/esm/sevenz/codecs/BcjPpc.js.map +1 -1
- package/dist/esm/sevenz/codecs/BcjSparc.js +8 -8
- package/dist/esm/sevenz/codecs/BcjSparc.js.map +1 -1
- package/dist/esm/sevenz/codecs/Delta.js +6 -6
- package/dist/esm/sevenz/codecs/Delta.js.map +1 -1
- package/dist/esm/sevenz/codecs/Lzma.js +16 -16
- package/dist/esm/sevenz/codecs/Lzma.js.map +1 -1
- package/dist/esm/sevenz/codecs/Lzma2.js +35 -35
- package/dist/esm/sevenz/codecs/Lzma2.js.map +1 -1
- package/dist/esm/sevenz/codecs/createBufferingDecoder.js +3 -3
- package/dist/esm/sevenz/codecs/createBufferingDecoder.js.map +1 -1
- package/dist/esm/sevenz/codecs/index.js +6 -6
- package/dist/esm/sevenz/codecs/index.js.map +1 -1
- package/dist/esm/sevenz/codecs/lzmaCompat.d.ts +1 -1
- package/dist/esm/sevenz/codecs/lzmaCompat.js +5 -5
- package/dist/esm/sevenz/codecs/lzmaCompat.js.map +1 -1
- package/dist/esm/sevenz/codecs/streams.js +13 -13
- package/dist/esm/sevenz/codecs/streams.js.map +1 -1
- package/dist/esm/sevenz/constants.d.ts +8 -8
- package/dist/esm/sevenz/constants.js +9 -9
- package/dist/esm/sevenz/constants.js.map +1 -1
- package/dist/esm/sevenz/headers.js +134 -134
- package/dist/esm/sevenz/headers.js.map +1 -1
- package/package.json +20 -20
|
@@ -20,27 +20,27 @@ import createBufferingDecoder from './createBufferingDecoder.js';
|
|
|
20
20
|
* @param _unpackSize - Unused for SPARC BCJ
|
|
21
21
|
* @returns Unfiltered data
|
|
22
22
|
*/ export function decodeBcjSparc(input, _properties, _unpackSize) {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const output = bufferFrom(input); // Copy since we modify in place
|
|
24
|
+
let pos = 0;
|
|
25
25
|
// Process 4-byte aligned positions
|
|
26
26
|
while(pos + 4 <= output.length){
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const b0 = output[pos];
|
|
28
|
+
const b1 = output[pos + 1];
|
|
29
29
|
// Check for CALL instruction with specific byte patterns:
|
|
30
30
|
// (b0 == 0x40 && (b1 & 0xC0) == 0x00) || (b0 == 0x7F && (b1 & 0xC0) == 0xC0)
|
|
31
31
|
if (b0 === 0x40 && (b1 & 0xc0) === 0x00 || b0 === 0x7f && (b1 & 0xc0) === 0xc0) {
|
|
32
32
|
// Read 32-bit value (big-endian)
|
|
33
|
-
|
|
33
|
+
let src = b0 << 24 | b1 << 16 | output[pos + 2] << 8 | output[pos + 3];
|
|
34
34
|
// Shift left by 2 (multiply by 4 for word addressing)
|
|
35
35
|
src <<= 2;
|
|
36
36
|
// Decoding: subtract position
|
|
37
|
-
|
|
37
|
+
let dest = src - pos;
|
|
38
38
|
// Shift right by 2
|
|
39
39
|
dest >>>= 2;
|
|
40
40
|
// Reconstruct with sign extension and opcode
|
|
41
41
|
// (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const signBit = dest >>> 22 & 1;
|
|
43
|
+
const signExtend = signBit ? 0x3fc00000 : 0;
|
|
44
44
|
dest = signExtend | dest & 0x3fffff | 0x40000000;
|
|
45
45
|
// Write back (big-endian)
|
|
46
46
|
output[pos] = dest >>> 24 & 0xff;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/BcjSparc.ts"],"sourcesContent":["// BCJ (SPARC) filter codec - converts SPARC branch instruction addresses\n// This filter makes SPARC executables more compressible by LZMA\n//\n// SPARC is big-endian. CALL instructions use 30-bit signed offsets.\n// The filter only transforms CALL instructions with specific byte patterns.\n//\n// Reference: https://github.com/kornelski/7z/blob/main/C/Bra.c\n\nimport { bufferFrom } from 'extract-base-iterator';\nimport type { Transform } from 'readable-stream';\nimport createBufferingDecoder from './createBufferingDecoder.ts';\n\n/**\n * Decode SPARC BCJ filtered data\n * Reverses the BCJ transformation by converting absolute addresses back to relative\n *\n * SPARC CALL instruction matching (big-endian):\n * - First byte 0x40 and (second byte & 0xC0) == 0x00, OR\n * - First byte 0x7F and (second byte & 0xC0) == 0xC0\n *\n * @param input - SPARC BCJ filtered data\n * @param _properties - Unused for SPARC BCJ\n * @param _unpackSize - Unused for SPARC BCJ\n * @returns Unfiltered data\n */\nexport function decodeBcjSparc(input: Buffer, _properties?: Buffer, _unpackSize?: number): Buffer {\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/BcjSparc.ts"],"sourcesContent":["// BCJ (SPARC) filter codec - converts SPARC branch instruction addresses\n// This filter makes SPARC executables more compressible by LZMA\n//\n// SPARC is big-endian. CALL instructions use 30-bit signed offsets.\n// The filter only transforms CALL instructions with specific byte patterns.\n//\n// Reference: https://github.com/kornelski/7z/blob/main/C/Bra.c\n\nimport { bufferFrom } from 'extract-base-iterator';\nimport type { Transform } from 'readable-stream';\nimport createBufferingDecoder from './createBufferingDecoder.ts';\n\n/**\n * Decode SPARC BCJ filtered data\n * Reverses the BCJ transformation by converting absolute addresses back to relative\n *\n * SPARC CALL instruction matching (big-endian):\n * - First byte 0x40 and (second byte & 0xC0) == 0x00, OR\n * - First byte 0x7F and (second byte & 0xC0) == 0xC0\n *\n * @param input - SPARC BCJ filtered data\n * @param _properties - Unused for SPARC BCJ\n * @param _unpackSize - Unused for SPARC BCJ\n * @returns Unfiltered data\n */\nexport function decodeBcjSparc(input: Buffer, _properties?: Buffer, _unpackSize?: number): Buffer {\n const output = bufferFrom(input); // Copy since we modify in place\n let pos = 0;\n\n // Process 4-byte aligned positions\n while (pos + 4 <= output.length) {\n const b0 = output[pos];\n const b1 = output[pos + 1];\n\n // Check for CALL instruction with specific byte patterns:\n // (b0 == 0x40 && (b1 & 0xC0) == 0x00) || (b0 == 0x7F && (b1 & 0xC0) == 0xC0)\n if ((b0 === 0x40 && (b1 & 0xc0) === 0x00) || (b0 === 0x7f && (b1 & 0xc0) === 0xc0)) {\n // Read 32-bit value (big-endian)\n let src = (b0 << 24) | (b1 << 16) | (output[pos + 2] << 8) | output[pos + 3];\n\n // Shift left by 2 (multiply by 4 for word addressing)\n src <<= 2;\n\n // Decoding: subtract position\n let dest = src - pos;\n\n // Shift right by 2\n dest >>>= 2;\n\n // Reconstruct with sign extension and opcode\n // (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000\n const signBit = (dest >>> 22) & 1;\n const signExtend = signBit ? 0x3fc00000 : 0;\n dest = signExtend | (dest & 0x3fffff) | 0x40000000;\n\n // Write back (big-endian)\n output[pos] = (dest >>> 24) & 0xff;\n output[pos + 1] = (dest >>> 16) & 0xff;\n output[pos + 2] = (dest >>> 8) & 0xff;\n output[pos + 3] = dest & 0xff;\n }\n\n pos += 4;\n }\n\n return output;\n}\n\n/**\n * Create a SPARC BCJ decoder Transform stream\n */\nexport function createBcjSparcDecoder(properties?: Buffer, unpackSize?: number): Transform {\n return createBufferingDecoder(decodeBcjSparc, properties, unpackSize);\n}\n"],"names":["bufferFrom","createBufferingDecoder","decodeBcjSparc","input","_properties","_unpackSize","output","pos","length","b0","b1","src","dest","signBit","signExtend","createBcjSparcDecoder","properties","unpackSize"],"mappings":"AAAA,yEAAyE;AACzE,gEAAgE;AAChE,EAAE;AACF,oEAAoE;AACpE,4EAA4E;AAC5E,EAAE;AACF,+DAA+D;AAE/D,SAASA,UAAU,QAAQ,wBAAwB;AAEnD,OAAOC,4BAA4B,8BAA8B;AAEjE;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,eAAeC,KAAa,EAAEC,WAAoB,EAAEC,WAAoB;IACtF,MAAMC,SAASN,WAAWG,QAAQ,gCAAgC;IAClE,IAAII,MAAM;IAEV,mCAAmC;IACnC,MAAOA,MAAM,KAAKD,OAAOE,MAAM,CAAE;QAC/B,MAAMC,KAAKH,MAAM,CAACC,IAAI;QACtB,MAAMG,KAAKJ,MAAM,CAACC,MAAM,EAAE;QAE1B,0DAA0D;QAC1D,6EAA6E;QAC7E,IAAI,AAACE,OAAO,QAAQ,AAACC,CAAAA,KAAK,IAAG,MAAO,QAAUD,OAAO,QAAQ,AAACC,CAAAA,KAAK,IAAG,MAAO,MAAO;YAClF,iCAAiC;YACjC,IAAIC,MAAM,AAACF,MAAM,KAAOC,MAAM,KAAOJ,MAAM,CAACC,MAAM,EAAE,IAAI,IAAKD,MAAM,CAACC,MAAM,EAAE;YAE5E,sDAAsD;YACtDI,QAAQ;YAER,8BAA8B;YAC9B,IAAIC,OAAOD,MAAMJ;YAEjB,mBAAmB;YACnBK,UAAU;YAEV,6CAA6C;YAC7C,mFAAmF;YACnF,MAAMC,UAAU,AAACD,SAAS,KAAM;YAChC,MAAME,aAAaD,UAAU,aAAa;YAC1CD,OAAOE,aAAcF,OAAO,WAAY;YAExC,0BAA0B;YAC1BN,MAAM,CAACC,IAAI,GAAG,AAACK,SAAS,KAAM;YAC9BN,MAAM,CAACC,MAAM,EAAE,GAAG,AAACK,SAAS,KAAM;YAClCN,MAAM,CAACC,MAAM,EAAE,GAAG,AAACK,SAAS,IAAK;YACjCN,MAAM,CAACC,MAAM,EAAE,GAAGK,OAAO;QAC3B;QAEAL,OAAO;IACT;IAEA,OAAOD;AACT;AAEA;;CAEC,GACD,OAAO,SAASS,sBAAsBC,UAAmB,EAAEC,UAAmB;IAC5E,OAAOhB,uBAAuBC,gBAAgBc,YAAYC;AAC5D"}
|
|
@@ -16,19 +16,19 @@ import createBufferingDecoder from './createBufferingDecoder.js';
|
|
|
16
16
|
* @returns Unfiltered data
|
|
17
17
|
*/ export function decodeDelta(input, properties, _unpackSize) {
|
|
18
18
|
// Distance parameter: default is 1
|
|
19
|
-
|
|
19
|
+
let distance = 1;
|
|
20
20
|
if (properties && properties.length >= 1) {
|
|
21
21
|
// Properties byte contains (distance - 1)
|
|
22
22
|
distance = properties[0] + 1;
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
const output = bufferFrom(input); // Copy since we modify in place
|
|
25
25
|
// State buffer for multi-byte distance
|
|
26
|
-
|
|
27
|
-
for(
|
|
26
|
+
const state = new Array(distance);
|
|
27
|
+
for(let i = 0; i < distance; i++){
|
|
28
28
|
state[i] = 0;
|
|
29
29
|
}
|
|
30
|
-
for(
|
|
31
|
-
|
|
30
|
+
for(let j = 0; j < output.length; j++){
|
|
31
|
+
const idx = j % distance;
|
|
32
32
|
state[idx] = state[idx] + output[j] & 0xff;
|
|
33
33
|
output[j] = state[idx];
|
|
34
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Delta.ts"],"sourcesContent":["// Delta filter codec - stores differences between consecutive bytes\n// Useful for data with gradual changes (images, audio, sensor data)\n//\n// The Delta filter stores the difference between each byte and the byte\n// N positions before it, where N is the \"distance\" parameter (default 1).\n// This makes data with regular patterns more compressible.\n\nimport { bufferFrom } from 'extract-base-iterator';\nimport type { Transform } from 'readable-stream';\nimport createBufferingDecoder from './createBufferingDecoder.ts';\n\n/**\n * Decode Delta filtered data\n * Reverses the delta transformation by adding previous values\n *\n * @param input - Delta filtered data\n * @param properties - Optional 1-byte properties (distance - 1)\n * @param _unpackSize - Unused for Delta\n * @returns Unfiltered data\n */\nexport function decodeDelta(input: Buffer, properties?: Buffer, _unpackSize?: number): Buffer {\n // Distance parameter: default is 1\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Delta.ts"],"sourcesContent":["// Delta filter codec - stores differences between consecutive bytes\n// Useful for data with gradual changes (images, audio, sensor data)\n//\n// The Delta filter stores the difference between each byte and the byte\n// N positions before it, where N is the \"distance\" parameter (default 1).\n// This makes data with regular patterns more compressible.\n\nimport { bufferFrom } from 'extract-base-iterator';\nimport type { Transform } from 'readable-stream';\nimport createBufferingDecoder from './createBufferingDecoder.ts';\n\n/**\n * Decode Delta filtered data\n * Reverses the delta transformation by adding previous values\n *\n * @param input - Delta filtered data\n * @param properties - Optional 1-byte properties (distance - 1)\n * @param _unpackSize - Unused for Delta\n * @returns Unfiltered data\n */\nexport function decodeDelta(input: Buffer, properties?: Buffer, _unpackSize?: number): Buffer {\n // Distance parameter: default is 1\n let distance = 1;\n if (properties && properties.length >= 1) {\n // Properties byte contains (distance - 1)\n distance = properties[0] + 1;\n }\n\n const output = bufferFrom(input); // Copy since we modify in place\n\n // State buffer for multi-byte distance\n const state = new Array(distance);\n for (let i = 0; i < distance; i++) {\n state[i] = 0;\n }\n\n for (let j = 0; j < output.length; j++) {\n const idx = j % distance;\n state[idx] = (state[idx] + output[j]) & 0xff;\n output[j] = state[idx];\n }\n\n return output;\n}\n\n/**\n * Create a Delta decoder Transform stream\n */\nexport function createDeltaDecoder(properties?: Buffer, unpackSize?: number): Transform {\n return createBufferingDecoder(decodeDelta, properties, unpackSize);\n}\n"],"names":["bufferFrom","createBufferingDecoder","decodeDelta","input","properties","_unpackSize","distance","length","output","state","Array","i","j","idx","createDeltaDecoder","unpackSize"],"mappings":"AAAA,oEAAoE;AACpE,oEAAoE;AACpE,EAAE;AACF,wEAAwE;AACxE,0EAA0E;AAC1E,2DAA2D;AAE3D,SAASA,UAAU,QAAQ,wBAAwB;AAEnD,OAAOC,4BAA4B,8BAA8B;AAEjE;;;;;;;;CAQC,GACD,OAAO,SAASC,YAAYC,KAAa,EAAEC,UAAmB,EAAEC,WAAoB;IAClF,mCAAmC;IACnC,IAAIC,WAAW;IACf,IAAIF,cAAcA,WAAWG,MAAM,IAAI,GAAG;QACxC,0CAA0C;QAC1CD,WAAWF,UAAU,CAAC,EAAE,GAAG;IAC7B;IAEA,MAAMI,SAASR,WAAWG,QAAQ,gCAAgC;IAElE,uCAAuC;IACvC,MAAMM,QAAQ,IAAIC,MAAMJ;IACxB,IAAK,IAAIK,IAAI,GAAGA,IAAIL,UAAUK,IAAK;QACjCF,KAAK,CAACE,EAAE,GAAG;IACb;IAEA,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,OAAOD,MAAM,EAAEK,IAAK;QACtC,MAAMC,MAAMD,IAAIN;QAChBG,KAAK,CAACI,IAAI,GAAG,AAACJ,KAAK,CAACI,IAAI,GAAGL,MAAM,CAACI,EAAE,GAAI;QACxCJ,MAAM,CAACI,EAAE,GAAGH,KAAK,CAACI,IAAI;IACxB;IAEA,OAAOL;AACT;AAEA;;CAEC,GACD,OAAO,SAASM,mBAAmBV,UAAmB,EAAEW,UAAmB;IACzE,OAAOd,uBAAuBC,aAAaE,YAAYW;AACzD"}
|
|
@@ -1,23 +1,23 @@
|
|
|
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
4
|
import { createNativeLzma1Decoder, hasNativeLzma } from './lzmaCompat.js';
|
|
5
5
|
import { createInputStream, createOutputStream } from './streams.js';
|
|
6
6
|
// Import vendored lzma-purejs - provides raw LZMA decoder (patched for LZMA2 support)
|
|
7
7
|
// Path accounts for build output in dist/esm/sevenz/codecs/
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const { LZMA } = _require('../../../../assets/lzma-purejs');
|
|
9
|
+
const LzmaDecoder = LZMA.Decoder;
|
|
10
10
|
/**
|
|
11
11
|
* Parse LZMA properties from 5-byte buffer
|
|
12
12
|
* First byte: lc + lp*9 + pb*45
|
|
13
13
|
* Next 4 bytes: dictionary size (little-endian)
|
|
14
14
|
*/ function parseLzmaProperties(properties) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
21
|
return {
|
|
22
22
|
lc: lc,
|
|
23
23
|
lp: lp,
|
|
@@ -36,17 +36,17 @@ var LzmaDecoder = LZMA.Decoder;
|
|
|
36
36
|
if (!properties || properties.length < 5) {
|
|
37
37
|
throw new Error('LZMA requires 5-byte properties');
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
const decoder = new LzmaDecoder();
|
|
40
40
|
// setDecoderProperties expects array-like with 5 bytes
|
|
41
41
|
if (!decoder.setDecoderProperties(properties)) {
|
|
42
42
|
throw new Error('Invalid LZMA properties');
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
const inStream = createInputStream(input, 0, input.length);
|
|
45
45
|
// Use -1 for unknown size (decoder will use end marker)
|
|
46
|
-
|
|
46
|
+
const size = typeof unpackSize === 'number' ? unpackSize : -1;
|
|
47
47
|
// Pre-allocate output stream if size is known (memory optimization)
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const outStream = createOutputStream(size > 0 ? size : undefined);
|
|
49
|
+
const success = decoder.code(inStream, outStream, size);
|
|
50
50
|
if (!success) {
|
|
51
51
|
throw new Error('LZMA decompression failed');
|
|
52
52
|
}
|
|
@@ -60,8 +60,8 @@ var LzmaDecoder = LZMA.Decoder;
|
|
|
60
60
|
*/ export function createLzmaDecoder(properties, _unpackSize) {
|
|
61
61
|
// Try native decoder first (available on Node.js 8+ with lzma-native installed)
|
|
62
62
|
if (hasNativeLzma && properties && properties.length >= 5) {
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
const props = parseLzmaProperties(properties);
|
|
64
|
+
const nativeDecoder = createNativeLzma1Decoder(props.lc, props.lp, props.pb, props.dictSize);
|
|
65
65
|
if (nativeDecoder) {
|
|
66
66
|
return nativeDecoder;
|
|
67
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Lzma.ts"],"sourcesContent":["import Module from 'module';\n\
|
|
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 - uses native lzma-native when available, falls back to lzma-purejs\n// LZMA properties in 7z are 5 bytes: 1 byte lc/lp/pb + 4 bytes dictionary size (little-endian)\n//\n// Native optimization: On Node.js 8+, lzma-native provides liblzma bindings\n// that decode LZMA1 streams natively for better performance.\n// Falls back to lzma-purejs for Node.js 0.8-7.x compatibility.\n\nimport type { Transform } from 'readable-stream';\nimport createBufferingDecoder from './createBufferingDecoder.ts';\nimport { createNativeLzma1Decoder, 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 * Parse LZMA properties from 5-byte buffer\n * First byte: lc + lp*9 + pb*45\n * Next 4 bytes: dictionary size (little-endian)\n */\nfunction parseLzmaProperties(properties: Buffer): { lc: number; lp: number; pb: number; dictSize: number } {\n const propByte = properties[0];\n const lc = propByte % 9;\n const remainder = Math.floor(propByte / 9);\n const lp = remainder % 5;\n const pb = Math.floor(remainder / 5);\n const dictSize = properties.readUInt32LE(1);\n return { lc: lc, lp: lp, pb: pb, dictSize: dictSize };\n}\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 *\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 createLzmaDecoder(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 >= 5) {\n const props = parseLzmaProperties(properties);\n const nativeDecoder = createNativeLzma1Decoder(props.lc, props.lp, props.pb, props.dictSize);\n if (nativeDecoder) {\n return nativeDecoder;\n }\n }\n\n // Fall back to buffering decoder with pure JS implementation\n return createBufferingDecoder(decodeLzma, properties, _unpackSize);\n}\n"],"names":["Module","_require","require","createRequire","url","createBufferingDecoder","createNativeLzma1Decoder","hasNativeLzma","createInputStream","createOutputStream","LZMA","LzmaDecoder","Decoder","parseLzmaProperties","properties","propByte","lc","remainder","Math","floor","lp","pb","dictSize","readUInt32LE","decodeLzma","input","unpackSize","length","Error","decoder","setDecoderProperties","inStream","size","outStream","undefined","success","code","toBuffer","createLzmaDecoder","_unpackSize","props","nativeDecoder"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAE5B,MAAMC,WAAW,OAAOC,YAAY,cAAcF,OAAOG,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAU1F,OAAOG,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,GAAGT,SAAS;AAC1B,MAAMU,cAAcD,KAAKE,OAAO;AAEhC;;;;CAIC,GACD,SAASC,oBAAoBC,UAAkB;IAC7C,MA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jB,OAAOA;QACT;IACF;IAEA,6DAA6D;IAC7D,OAAOpC,uBAAuBmB,YAAYV,YAAYyB;AACxD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Module from 'module';
|
|
2
|
-
|
|
2
|
+
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
3
3
|
// LZMA2 codec - uses native lzma-native when available, falls back to lzma-purejs
|
|
4
4
|
// LZMA2 is a container format that wraps LZMA chunks with framing
|
|
5
5
|
//
|
|
@@ -21,8 +21,8 @@ import { createNativeLzma2Decoder, hasNativeLzma } from './lzmaCompat.js';
|
|
|
21
21
|
import { createInputStream, createOutputStream } from './streams.js';
|
|
22
22
|
// Import vendored lzma-purejs - provides raw LZMA decoder (patched for LZMA2 support)
|
|
23
23
|
// Path accounts for build output in dist/esm/sevenz/codecs/
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const { LZMA } = _require('../../../../assets/lzma-purejs');
|
|
25
|
+
const LzmaDecoder = LZMA.Decoder;
|
|
26
26
|
/**
|
|
27
27
|
* Decode LZMA2 dictionary size from properties byte
|
|
28
28
|
* Properties byte encodes dictionary size as: 2^(dictByte/2 + 12) or similar
|
|
@@ -42,8 +42,8 @@ var LzmaDecoder = LZMA.Decoder;
|
|
|
42
42
|
return 0xffffffff;
|
|
43
43
|
}
|
|
44
44
|
// Dictionary size = 2 | (propByte & 1) << (propByte / 2 + 11)
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
const base = 2 | propByte & 1;
|
|
46
|
+
const shift = Math.floor(propByte / 2) + 11;
|
|
47
47
|
return base << shift;
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
@@ -57,27 +57,27 @@ var LzmaDecoder = LZMA.Decoder;
|
|
|
57
57
|
if (!properties || properties.length < 1) {
|
|
58
58
|
throw new Error('LZMA2 requires properties byte');
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
const dictSize = decodeDictionarySize(properties[0]);
|
|
61
61
|
// Memory optimization: pre-allocate output buffer if size is known
|
|
62
62
|
// This avoids double-memory during Buffer.concat
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
let outputBuffer = null;
|
|
64
|
+
let outputPos = 0;
|
|
65
|
+
const outputChunks = [];
|
|
66
66
|
if (unpackSize && unpackSize > 0) {
|
|
67
67
|
outputBuffer = allocBufferUnsafe(unpackSize);
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
let offset = 0;
|
|
70
70
|
// LZMA decoder instance - reused across chunks
|
|
71
71
|
// The vendored decoder supports setSolid() for LZMA2 state preservation
|
|
72
72
|
// The decoder also has _nowPos64 which tracks cumulative position for rep0 validation
|
|
73
73
|
// and _prevByte which is used for literal decoder context selection
|
|
74
|
-
|
|
74
|
+
const decoder = new LzmaDecoder();
|
|
75
75
|
decoder.setDictionarySize(dictSize);
|
|
76
|
-
|
|
76
|
+
const outWindow = decoder._outWindow;
|
|
77
77
|
// Track current LZMA properties (lc, lp, pb)
|
|
78
|
-
|
|
78
|
+
let propsSet = false;
|
|
79
79
|
while(offset < input.length){
|
|
80
|
-
|
|
80
|
+
const control = input[offset++];
|
|
81
81
|
if (control === 0x00) {
|
|
82
82
|
break;
|
|
83
83
|
}
|
|
@@ -95,13 +95,13 @@ var LzmaDecoder = LZMA.Decoder;
|
|
|
95
95
|
throw new Error('Truncated LZMA2 uncompressed chunk header');
|
|
96
96
|
}
|
|
97
97
|
// Size is big-endian, 16-bit, value + 1
|
|
98
|
-
|
|
98
|
+
const uncompSize = (input[offset] << 8 | input[offset + 1]) + 1;
|
|
99
99
|
offset += 2;
|
|
100
100
|
if (offset + uncompSize > input.length) {
|
|
101
101
|
throw new Error('Truncated LZMA2 uncompressed data');
|
|
102
102
|
}
|
|
103
103
|
// Get the uncompressed data
|
|
104
|
-
|
|
104
|
+
const uncompData = input.slice(offset, offset + uncompSize);
|
|
105
105
|
// Copy uncompressed data to output
|
|
106
106
|
if (outputBuffer) {
|
|
107
107
|
uncompData.copy(outputBuffer, outputPos);
|
|
@@ -113,7 +113,7 @@ var LzmaDecoder = LZMA.Decoder;
|
|
|
113
113
|
// The decoder needs to track this data for LZ77 back-references
|
|
114
114
|
// We write directly to _buffer to avoid flush() which requires _stream to be set
|
|
115
115
|
// We must also update _streamPos to match _pos so that flush() doesn't try to write
|
|
116
|
-
for(
|
|
116
|
+
for(let i = 0; i < uncompData.length; i++){
|
|
117
117
|
outWindow._buffer[outWindow._pos++] = uncompData[i];
|
|
118
118
|
// Handle circular buffer wrap-around
|
|
119
119
|
if (outWindow._pos >= outWindow._windowSize) {
|
|
@@ -139,10 +139,10 @@ var LzmaDecoder = LZMA.Decoder;
|
|
|
139
139
|
// 0xA0-0xBF (01): reset state only
|
|
140
140
|
// 0xC0-0xDF (10): reset state + new properties
|
|
141
141
|
// 0xE0-0xFF (11): reset dictionary + state + new properties
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
const resetState = control >= 0xa0;
|
|
143
|
+
const newProps = control >= 0xc0;
|
|
144
|
+
const dictReset = control >= 0xe0;
|
|
145
|
+
const useSolidMode = !resetState;
|
|
146
146
|
// Handle dictionary reset for control bytes 0xE0-0xFF
|
|
147
147
|
if (dictReset) {
|
|
148
148
|
outWindow._pos = 0;
|
|
@@ -152,24 +152,24 @@ var LzmaDecoder = LZMA.Decoder;
|
|
|
152
152
|
throw new Error('Truncated LZMA2 LZMA chunk header');
|
|
153
153
|
}
|
|
154
154
|
// Uncompressed size: 5 bits from control + 16 bits from next 2 bytes + 1
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
const uncompHigh = control & 0x1f;
|
|
156
|
+
const uncompSize2 = (uncompHigh << 16 | input[offset] << 8 | input[offset + 1]) + 1;
|
|
157
157
|
offset += 2;
|
|
158
158
|
// Compressed size: 16 bits + 1
|
|
159
|
-
|
|
159
|
+
const compSize = (input[offset] << 8 | input[offset + 1]) + 1;
|
|
160
160
|
offset += 2;
|
|
161
161
|
// If new properties, read 1-byte LZMA properties
|
|
162
162
|
if (newProps) {
|
|
163
163
|
if (offset >= input.length) {
|
|
164
164
|
throw new Error('Truncated LZMA2 properties byte');
|
|
165
165
|
}
|
|
166
|
-
|
|
166
|
+
const propsByte = input[offset++];
|
|
167
167
|
// Properties byte: pb * 45 + lp * 9 + lc
|
|
168
168
|
// where pb, lp, lc are LZMA parameters
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
169
|
+
const lc = propsByte % 9;
|
|
170
|
+
const remainder = Math.floor(propsByte / 9);
|
|
171
|
+
const lp = remainder % 5;
|
|
172
|
+
const pb = Math.floor(remainder / 5);
|
|
173
173
|
if (!decoder.setLcLpPb(lc, lp, pb)) {
|
|
174
174
|
throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);
|
|
175
175
|
}
|
|
@@ -182,16 +182,16 @@ var LzmaDecoder = LZMA.Decoder;
|
|
|
182
182
|
throw new Error('Truncated LZMA2 compressed data');
|
|
183
183
|
}
|
|
184
184
|
// Decode LZMA chunk
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
const inStream = createInputStream(input, offset, compSize);
|
|
186
|
+
const outStream = createOutputStream(uncompSize2); // Pre-allocate for memory efficiency
|
|
187
187
|
// Set solid mode based on control byte - this preserves state across code() calls
|
|
188
188
|
decoder.setSolid(useSolidMode);
|
|
189
189
|
// Decode the chunk
|
|
190
|
-
|
|
190
|
+
const success = decoder.code(inStream, outStream, uncompSize2);
|
|
191
191
|
if (!success) {
|
|
192
192
|
throw new Error('LZMA decompression failed');
|
|
193
193
|
}
|
|
194
|
-
|
|
194
|
+
const chunkOutput = outStream.toBuffer();
|
|
195
195
|
if (outputBuffer) {
|
|
196
196
|
chunkOutput.copy(outputBuffer, outputPos);
|
|
197
197
|
outputPos += chunkOutput.length;
|
|
@@ -218,8 +218,8 @@ var LzmaDecoder = LZMA.Decoder;
|
|
|
218
218
|
*/ export function createLzma2Decoder(properties, unpackSize) {
|
|
219
219
|
// Try native decoder first (available on Node.js 8+ with lzma-native installed)
|
|
220
220
|
if (hasNativeLzma && properties && properties.length >= 1) {
|
|
221
|
-
|
|
222
|
-
|
|
221
|
+
const dictSize = decodeDictionarySize(properties[0]);
|
|
222
|
+
const nativeDecoder = createNativeLzma2Decoder(dictSize);
|
|
223
223
|
if (nativeDecoder) {
|
|
224
224
|
return nativeDecoder;
|
|
225
225
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Lzma2.ts"],"sourcesContent":["import Module from 'module';\n\nvar _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/\nvar { LZMA } = _require('../../../../assets/lzma-purejs');\nvar 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 var base = 2 | (propByte & 1);\n var 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 var 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 var outputBuffer: Buffer | null = null;\n var outputPos = 0;\n var outputChunks: Buffer[] = [];\n\n if (unpackSize && unpackSize > 0) {\n outputBuffer = allocBufferUnsafe(unpackSize);\n }\n\n var 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 var decoder = new LzmaDecoder() as InstanceType<typeof LzmaDecoder> & {\n setSolid: (solid: boolean) => 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 var outWindow = (decoder as unknown as { _outWindow: OutWindowType })._outWindow;\n\n // Track current LZMA properties (lc, lp, pb)\n var propsSet = false;\n\n while (offset < input.length) {\n var 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 var 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 var 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 (var 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 var resetState = control >= 0xa0;\n var newProps = control >= 0xc0;\n var dictReset = control >= 0xe0;\n var 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 var uncompHigh = control & 0x1f;\n var uncompSize2 = ((uncompHigh << 16) | (input[offset] << 8) | input[offset + 1]) + 1;\n offset += 2;\n\n // Compressed size: 16 bits + 1\n var 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 var propsByte = input[offset++];\n\n // Properties byte: pb * 45 + lp * 9 + lc\n // where pb, lp, lc are LZMA parameters\n var lc = propsByte % 9;\n var remainder = Math.floor(propsByte / 9);\n var lp = remainder % 5;\n var 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 var inStream = createInputStream(input, offset, compSize);\n var outStream = createOutputStream(uncompSize2); // Pre-allocate for memory efficiency\n\n // Set solid mode based on control byte - this preserves state across code() calls\n decoder.setSolid(useSolidMode);\n\n // Decode the chunk\n var success = decoder.code(inStream, outStream, uncompSize2);\n if (!success) {\n throw new Error('LZMA decompression failed');\n }\n\n var 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 var dictSize = decodeDictionarySize(properties[0]);\n var 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","setSolid","success","code","chunkOutput","toBuffer","toString","Buffer","concat","createLzma2Decoder","nativeDecoder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zE;IACF;IAEA,qDAAqD;IACrD,IAAI1C,cAAc;QAChB,4DAA4D;QAC5D,OAAOC,YAAYD,aAAaF,MAAM,GAAGE,aAAae,KAAK,CAAC,GAAGd,aAAaD;IAC9E;IACA,OAAO2C,OAAOC,MAAM,CAAC1C;AACvB;AAEA;;;;;CAKC,GACD,OAAO,SAAS2C,mBAAmBjD,UAAmB,EAAEC,UAAmB;IACzE,gFAAgF;IAChF,IAAIhB,iBAAiBe,cAAcA,WAAWE,MAAM,IAAI,GAAG;QACzD,IAAIC,WAAWZ,qBAAqBS,UAAU,CAAC,EAAE;QACjD,IAAIkD,gBAAgBlE,yBAAyBmB;QAC7C,IAAI+C,eAAe;YACjB,OAAOA;QACT;IACF;IAEA,6DAA6D;IAC7D,OAAOnE,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 - 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 _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 decoder.setSolid(useSolidMode);\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","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,GACD,OAAO,SAASG,YAAYC,KAAa,EAAEC,UAAmB,EAA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BAChBwC,YAAYxB,IAAI,CAAChB,cAAcC;gBAC/BA,aAAauC,YAAY1C,MAAM;YACjC,OAAO;gBACLI,yBAAAA,mCAAAA,aAAce,IAAI,CAACuB;YACrB;YAEArC,UAAUyB;QACZ,OAAO;YACL,MAAM,IAAIvC,MAAM,CAAC,8BAA8B,EAAEoB,QAAQiC,QAAQ,CAAC,KAAK;QACzE;IACF;IAEA,qDAAqD;IACrD,IAAI1C,cAAc;QAChB,4DAA4D;QAC5D,OAAOC,YAAYD,aAAaF,MAAM,GAAGE,aAAae,KAAK,CAAC,GAAGd,aAAaD;IAC9E;IACA,OAAO2C,OAAOC,MAAM,CAAC1C;AACvB;AAEA;;;;;CAKC,GACD,OAAO,SAAS2C,mBAAmBjD,UAAmB,EAAEC,UAAmB;IACzE,gFAAgF;IAChF,IAAIhB,iBAAiBe,cAAcA,WAAWE,MAAM,IAAI,GAAG;QACzD,MAAMC,WAAWZ,qBAAqBS,UAAU,CAAC,EAAE;QACnD,MAAMkD,gBAAgBlE,yBAAyBmB;QAC/C,IAAI+C,eAAe;YACjB,OAAOA;QACT;IACF;IAEA,6DAA6D;IAC7D,OAAOnE,uBAAuBe,aAAaE,YAAYC;AACzD"}
|
|
@@ -13,7 +13,7 @@ if (major > 0) {
|
|
|
13
13
|
* Create a Transform stream that buffers all input, then decodes in flush
|
|
14
14
|
* This is the common pattern for codecs that can't stream (need full input)
|
|
15
15
|
*/ export default function createBufferingDecoder(decodeFn, properties, unpackSize) {
|
|
16
|
-
|
|
16
|
+
const chunks = [];
|
|
17
17
|
return new Transform({
|
|
18
18
|
transform: (chunk, _encoding, callback)=>{
|
|
19
19
|
chunks.push(chunk);
|
|
@@ -21,8 +21,8 @@ if (major > 0) {
|
|
|
21
21
|
},
|
|
22
22
|
flush: function(callback) {
|
|
23
23
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const input = Buffer.concat(chunks);
|
|
25
|
+
const output = decodeFn(input, properties, unpackSize);
|
|
26
26
|
this.push(output);
|
|
27
27
|
callback();
|
|
28
28
|
} catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/createBufferingDecoder.ts"],"sourcesContent":["// Helper to create a Transform stream that buffers all input before decoding\n// Used by codecs that need the full input before decompression (LZMA, LZMA2, BZip2, etc.)\n\nimport Stream from 'stream';\n\n// Use native streams when available, readable-stream only for Node 0.x\nconst major = +process.versions.node.split('.')[0];\nlet Transform: typeof Stream.Transform;\nif (major > 0) {\n Transform = Stream.Transform;\n} else {\n Transform = require('readable-stream').Transform;\n}\ntype TransformCallback = (error?: Error | null, data?: Buffer) => void;\n\nexport type DecodeFn = (input: Buffer, properties?: Buffer, unpackSize?: number) => Buffer;\n\n/**\n * Create a Transform stream that buffers all input, then decodes in flush\n * This is the common pattern for codecs that can't stream (need full input)\n */\nexport default function createBufferingDecoder(decodeFn: DecodeFn, properties?: Buffer, unpackSize?: number): Stream.Transform {\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/createBufferingDecoder.ts"],"sourcesContent":["// Helper to create a Transform stream that buffers all input before decoding\n// Used by codecs that need the full input before decompression (LZMA, LZMA2, BZip2, etc.)\n\nimport Stream from 'stream';\n\n// Use native streams when available, readable-stream only for Node 0.x\nconst major = +process.versions.node.split('.')[0];\nlet Transform: typeof Stream.Transform;\nif (major > 0) {\n Transform = Stream.Transform;\n} else {\n Transform = require('readable-stream').Transform;\n}\ntype TransformCallback = (error?: Error | null, data?: Buffer) => void;\n\nexport type DecodeFn = (input: Buffer, properties?: Buffer, unpackSize?: number) => Buffer;\n\n/**\n * Create a Transform stream that buffers all input, then decodes in flush\n * This is the common pattern for codecs that can't stream (need full input)\n */\nexport default function createBufferingDecoder(decodeFn: DecodeFn, properties?: Buffer, unpackSize?: number): Stream.Transform {\n const chunks: Buffer[] = [];\n\n return new Transform({\n transform: (chunk: Buffer, _encoding: string, callback: TransformCallback) => {\n chunks.push(chunk);\n callback();\n },\n flush: function (callback: TransformCallback) {\n try {\n const input = Buffer.concat(chunks);\n const output = decodeFn(input, properties, unpackSize);\n this.push(output);\n callback();\n } catch (err) {\n callback(err as Error);\n }\n },\n });\n}\n"],"names":["Stream","major","process","versions","node","split","Transform","require","createBufferingDecoder","decodeFn","properties","unpackSize","chunks","transform","chunk","_encoding","callback","push","flush","input","Buffer","concat","output","err"],"mappings":"AAAA,6EAA6E;AAC7E,0FAA0F;AAE1F,OAAOA,YAAY,SAAS;AAE5B,uEAAuE;AACvE,MAAMC,QAAQ,CAACC,QAAQC,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE;AAClD,IAAIC;AACJ,IAAIL,QAAQ,GAAG;IACbK,YAAYN,OAAOM,SAAS;AAC9B,OAAO;IACLA,YAAYC,QAAQ,mBAAmBD,SAAS;AAClD;AAKA;;;CAGC,GACD,eAAe,SAASE,uBAAuBC,QAAkB,EAAEC,UAAmB,EAAEC,UAAmB;IACzG,MAAMC,SAAmB,EAAE;IAE3B,OAAO,IAAIN,UAAU;QACnBO,WAAW,CAACC,OAAeC,WAAmBC;YAC5CJ,OAAOK,IAAI,CAACH;YACZE;QACF;QACAE,OAAO,SAAUF,QAA2B;YAC1C,IAAI;gBACF,MAAMG,QAAQC,OAAOC,MAAM,CAACT;gBAC5B,MAAMU,SAASb,SAASU,OAAOT,YAAYC;gBAC3C,IAAI,CAACM,IAAI,CAACK;gBACVN;YACF,EAAE,OAAOO,KAAK;gBACZP,SAASO;YACX;QACF;IACF;AACF"}
|
|
@@ -19,12 +19,12 @@ import { createLzma2Decoder, decodeLzma2 } from './Lzma2.js';
|
|
|
19
19
|
// Re-export password functions for API access
|
|
20
20
|
export { getPassword, setPassword };
|
|
21
21
|
// Registry of supported codecs
|
|
22
|
-
|
|
22
|
+
const codecs = {};
|
|
23
23
|
/**
|
|
24
24
|
* Convert codec ID bytes to a string key
|
|
25
25
|
*/ function codecIdToKey(id) {
|
|
26
|
-
|
|
27
|
-
for(
|
|
26
|
+
const parts = [];
|
|
27
|
+
for(let i = 0; i < id.length; i++){
|
|
28
28
|
parts.push(id[i].toString(16).toUpperCase());
|
|
29
29
|
}
|
|
30
30
|
return parts.join('-');
|
|
@@ -33,7 +33,7 @@ var codecs = {};
|
|
|
33
33
|
* Check if two codec IDs match
|
|
34
34
|
*/ function codecIdEquals(a, b) {
|
|
35
35
|
if (a.length !== b.length) return false;
|
|
36
|
-
for(
|
|
36
|
+
for(let i = 0; i < a.length; i++){
|
|
37
37
|
if (a[i] !== b[i]) return false;
|
|
38
38
|
}
|
|
39
39
|
return true;
|
|
@@ -47,8 +47,8 @@ var codecs = {};
|
|
|
47
47
|
* Get a codec by ID
|
|
48
48
|
* @throws Error if codec is not supported
|
|
49
49
|
*/ export function getCodec(id) {
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
const key = codecIdToKey(id);
|
|
51
|
+
const codec = codecs[key];
|
|
52
52
|
if (!codec) {
|
|
53
53
|
throw createCodedError(`Unsupported codec: ${key}`, ErrorCode.UNSUPPORTED_CODEC);
|
|
54
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/index.ts"],"sourcesContent":["// Codec registry for 7z decompression\n// Each codec provides a decode function and optionally a streaming decoder\n\nimport type { Transform } from 'readable-stream';\nimport { CodecId, createCodedError, ErrorCode } from '../constants.ts';\nimport { createAesDecoder, decodeAes, getPassword, setPassword } from './Aes.ts';\nimport { createBcjDecoder, decodeBcj } from './Bcj.ts';\nimport { createBcj2Decoder, decodeBcj2, decodeBcj2Multi } from './Bcj2.ts';\nimport { createBcjArmDecoder, decodeBcjArm } from './BcjArm.ts';\nimport { createBcjArm64Decoder, decodeBcjArm64 } from './BcjArm64.ts';\nimport { createBcjArmtDecoder, decodeBcjArmt } from './BcjArmt.ts';\nimport { createBcjIa64Decoder, decodeBcjIa64 } from './BcjIa64.ts';\nimport { createBcjPpcDecoder, decodeBcjPpc } from './BcjPpc.ts';\nimport { createBcjSparcDecoder, decodeBcjSparc } from './BcjSparc.ts';\nimport { createBzip2Decoder, decodeBzip2 } from './BZip2.ts';\nimport { createCopyDecoder, decodeCopy } from './Copy.ts';\nimport { createDeflateDecoder, decodeDeflate } from './Deflate.ts';\nimport { createDeltaDecoder, decodeDelta } from './Delta.ts';\nimport { createLzmaDecoder, decodeLzma } from './Lzma.ts';\nimport { createLzma2Decoder, decodeLzma2 } from './Lzma2.ts';\n\n// Re-export password functions for API access\nexport { getPassword, setPassword };\n\nexport interface Codec {\n decode: (input: Buffer, properties?: Buffer, unpackSize?: number) => Buffer;\n createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;\n}\n\n// Registry of supported codecs\nvar codecs: { [key: string]: Codec } = {};\n\n/**\n * Convert codec ID bytes to a string key\n */\nfunction codecIdToKey(id: number[]): string {\n var parts: string[] = [];\n for (var i = 0; i < id.length; i++) {\n parts.push(id[i].toString(16).toUpperCase());\n }\n return parts.join('-');\n}\n\n/**\n * Check if two codec IDs match\n */\nfunction codecIdEquals(a: number[], b: number[]): boolean {\n if (a.length !== b.length) return false;\n for (var i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\n/**\n * Register a codec\n */\nexport function registerCodec(id: number[], codec: Codec): void {\n codecs[codecIdToKey(id)] = codec;\n}\n\n/**\n * Get a codec by ID\n * @throws Error if codec is not supported\n */\nexport function getCodec(id: number[]): Codec {\n var key = codecIdToKey(id);\n var codec = codecs[key];\n if (!codec) {\n throw createCodedError(`Unsupported codec: ${key}`, ErrorCode.UNSUPPORTED_CODEC);\n }\n return codec;\n}\n\n/**\n * Check if a codec is supported\n */\nexport function isCodecSupported(id: number[]): boolean {\n return codecs[codecIdToKey(id)] !== undefined;\n}\n\n/**\n * Get human-readable codec name\n */\nexport function getCodecName(id: number[]): string {\n if (codecIdEquals(id, CodecId.COPY)) return 'Copy';\n if (codecIdEquals(id, CodecId.LZMA)) return 'LZMA';\n if (codecIdEquals(id, CodecId.LZMA2)) return 'LZMA2';\n if (codecIdEquals(id, CodecId.BCJ_X86)) return 'BCJ (x86)';\n if (codecIdEquals(id, CodecId.BCJ_ARM)) return 'BCJ (ARM)';\n if (codecIdEquals(id, CodecId.BCJ_ARMT)) return 'BCJ (ARM Thumb)';\n if (codecIdEquals(id, CodecId.BCJ_ARM64)) return 'BCJ (ARM64)';\n if (codecIdEquals(id, CodecId.BCJ_PPC)) return 'BCJ (PowerPC)';\n if (codecIdEquals(id, CodecId.BCJ_IA64)) return 'BCJ (IA64)';\n if (codecIdEquals(id, CodecId.BCJ_SPARC)) return 'BCJ (SPARC)';\n if (codecIdEquals(id, CodecId.BCJ2)) return 'BCJ2';\n if (codecIdEquals(id, CodecId.PPMD)) return 'PPMd';\n if (codecIdEquals(id, CodecId.DELTA)) return 'Delta';\n if (codecIdEquals(id, CodecId.DEFLATE)) return 'Deflate';\n if (codecIdEquals(id, CodecId.BZIP2)) return 'BZip2';\n if (codecIdEquals(id, CodecId.AES)) return 'AES-256';\n return `Unknown (${codecIdToKey(id)})`;\n}\n\n/**\n * Check if a codec ID matches BCJ2\n */\nexport function isBcj2Codec(id: number[]): boolean {\n return codecIdEquals(id, CodecId.BCJ2);\n}\n\n// Re-export BCJ2 multi-stream decoder for special handling\nexport { decodeBcj2Multi };\n\n// Register built-in codecs\n\n// Copy codec (no compression)\nregisterCodec(CodecId.COPY, {\n decode: decodeCopy,\n createDecoder: createCopyDecoder,\n});\n\n// LZMA codec\nregisterCodec(CodecId.LZMA, {\n decode: decodeLzma,\n createDecoder: createLzmaDecoder,\n});\n\n// LZMA2 codec\nregisterCodec(CodecId.LZMA2, {\n decode: decodeLzma2,\n createDecoder: createLzma2Decoder,\n});\n\n// BCJ (x86) filter\nregisterCodec(CodecId.BCJ_X86, {\n decode: decodeBcj,\n createDecoder: createBcjDecoder,\n});\n\n// BCJ (ARM) filter\nregisterCodec(CodecId.BCJ_ARM, {\n decode: decodeBcjArm,\n createDecoder: createBcjArmDecoder,\n});\n\n// BCJ (ARM Thumb) filter\nregisterCodec(CodecId.BCJ_ARMT, {\n decode: decodeBcjArmt,\n createDecoder: createBcjArmtDecoder,\n});\n\n// BCJ (ARM64) filter\nregisterCodec(CodecId.BCJ_ARM64, {\n decode: decodeBcjArm64,\n createDecoder: createBcjArm64Decoder,\n});\n\n// BCJ (PowerPC) filter\nregisterCodec(CodecId.BCJ_PPC, {\n decode: decodeBcjPpc,\n createDecoder: createBcjPpcDecoder,\n});\n\n// BCJ (IA64) filter\nregisterCodec(CodecId.BCJ_IA64, {\n decode: decodeBcjIa64,\n createDecoder: createBcjIa64Decoder,\n});\n\n// BCJ (SPARC) filter\nregisterCodec(CodecId.BCJ_SPARC, {\n decode: decodeBcjSparc,\n createDecoder: createBcjSparcDecoder,\n});\n\n// Delta filter\nregisterCodec(CodecId.DELTA, {\n decode: decodeDelta,\n createDecoder: createDeltaDecoder,\n});\n\n// Deflate codec\nregisterCodec(CodecId.DEFLATE, {\n decode: decodeDeflate,\n createDecoder: createDeflateDecoder,\n});\n\n// BZip2 codec\nregisterCodec(CodecId.BZIP2, {\n decode: decodeBzip2,\n createDecoder: createBzip2Decoder,\n});\n\n// AES-256-CBC codec (encryption)\nregisterCodec(CodecId.AES, {\n decode: decodeAes,\n createDecoder: createAesDecoder,\n});\n\n// BCJ2 (x86-64) filter - multi-stream\n// Note: BCJ2 requires special handling in SevenZipParser due to 4-stream architecture\nregisterCodec(CodecId.BCJ2, {\n decode: decodeBcj2,\n createDecoder: createBcj2Decoder,\n});\n\n// Note: PPMd codec is not implemented. See FUTURE_ENHANCEMENTS.md\n"],"names":["CodecId","createCodedError","ErrorCode","createAesDecoder","decodeAes","getPassword","setPassword","createBcjDecoder","decodeBcj","createBcj2Decoder","decodeBcj2","decodeBcj2Multi","createBcjArmDecoder","decodeBcjArm","createBcjArm64Decoder","decodeBcjArm64","createBcjArmtDecoder","decodeBcjArmt","createBcjIa64Decoder","decodeBcjIa64","createBcjPpcDecoder","decodeBcjPpc","createBcjSparcDecoder","decodeBcjSparc","createBzip2Decoder","decodeBzip2","createCopyDecoder","decodeCopy","createDeflateDecoder","decodeDeflate","createDeltaDecoder","decodeDelta","createLzmaDecoder","decodeLzma","createLzma2Decoder","decodeLzma2","codecs","codecIdToKey","id","parts","i","length","push","toString","toUpperCase","join","codecIdEquals","a","b","registerCodec","codec","getCodec","key","UNSUPPORTED_CODEC","isCodecSupported","undefined","getCodecName","COPY","LZMA","LZMA2","BCJ_X86","BCJ_ARM","BCJ_ARMT","BCJ_ARM64","BCJ_PPC","BCJ_IA64","BCJ_SPARC","BCJ2","PPMD","DELTA","DEFLATE","BZIP2","AES","isBcj2Codec","decode","createDecoder"],"mappings":"AAAA,sCAAsC;AACtC,2EAA2E;AAG3E,SAASA,OAAO,EAAEC,gBAAgB,EAAEC,SAAS,QAAQ,kBAAkB;AACvE,SAASC,gBAAgB,EAAEC,SAAS,EAAEC,WAAW,EAAEC,WAAW,QAAQ,WAAW;AACjF,SAASC,gBAAgB,EAAEC,SAAS,QAAQ,WAAW;AACvD,SAASC,iBAAiB,EAAEC,UAAU,EAAEC,eAAe,QAAQ,YAAY;AAC3E,SAASC,mBAAmB,EAAEC,YAAY,QAAQ,cAAc;AAChE,SAASC,qBAAqB,EAAEC,cAAc,QAAQ,gBAAgB;AACtE,SAASC,oBAAoB,EAAEC,aAAa,QAAQ,eAAe;AACnE,SAASC,oBAAoB,EAAEC,aAAa,QAAQ,eAAe;AACnE,SAASC,mBAAmB,EAAEC,YAAY,QAAQ,cAAc;AAChE,SAASC,qBAAqB,EAAEC,cAAc,QAAQ,gBAAgB;AACtE,SAASC,kBAAkB,EAAEC,WAAW,QAAQ,aAAa;AAC7D,SAASC,iBAAiB,EAAEC,UAAU,QAAQ,YAAY;AAC1D,SAASC,oBAAoB,EAAEC,aAAa,QAAQ,eAAe;AACnE,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IACRiE,eAAelE;AACjB,IAEA,kEAAkE"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/index.ts"],"sourcesContent":["// Codec registry for 7z decompression\n// Each codec provides a decode function and optionally a streaming decoder\n\nimport type { Transform } from 'readable-stream';\nimport { CodecId, createCodedError, ErrorCode } from '../constants.ts';\nimport { createAesDecoder, decodeAes, getPassword, setPassword } from './Aes.ts';\nimport { createBcjDecoder, decodeBcj } from './Bcj.ts';\nimport { createBcj2Decoder, decodeBcj2, decodeBcj2Multi } from './Bcj2.ts';\nimport { createBcjArmDecoder, decodeBcjArm } from './BcjArm.ts';\nimport { createBcjArm64Decoder, decodeBcjArm64 } from './BcjArm64.ts';\nimport { createBcjArmtDecoder, decodeBcjArmt } from './BcjArmt.ts';\nimport { createBcjIa64Decoder, decodeBcjIa64 } from './BcjIa64.ts';\nimport { createBcjPpcDecoder, decodeBcjPpc } from './BcjPpc.ts';\nimport { createBcjSparcDecoder, decodeBcjSparc } from './BcjSparc.ts';\nimport { createBzip2Decoder, decodeBzip2 } from './BZip2.ts';\nimport { createCopyDecoder, decodeCopy } from './Copy.ts';\nimport { createDeflateDecoder, decodeDeflate } from './Deflate.ts';\nimport { createDeltaDecoder, decodeDelta } from './Delta.ts';\nimport { createLzmaDecoder, decodeLzma } from './Lzma.ts';\nimport { createLzma2Decoder, decodeLzma2 } from './Lzma2.ts';\n\n// Re-export password functions for API access\nexport { getPassword, setPassword };\n\nexport interface Codec {\n decode: (input: Buffer, properties?: Buffer, unpackSize?: number) => Buffer;\n createDecoder: (properties?: Buffer, unpackSize?: number) => Transform;\n}\n\n// Registry of supported codecs\nconst codecs: { [key: string]: Codec } = {};\n\n/**\n * Convert codec ID bytes to a string key\n */\nfunction codecIdToKey(id: number[]): string {\n const parts: string[] = [];\n for (let i = 0; i < id.length; i++) {\n parts.push(id[i].toString(16).toUpperCase());\n }\n return parts.join('-');\n}\n\n/**\n * Check if two codec IDs match\n */\nfunction codecIdEquals(a: number[], b: number[]): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n\n/**\n * Register a codec\n */\nexport function registerCodec(id: number[], codec: Codec): void {\n codecs[codecIdToKey(id)] = codec;\n}\n\n/**\n * Get a codec by ID\n * @throws Error if codec is not supported\n */\nexport function getCodec(id: number[]): Codec {\n const key = codecIdToKey(id);\n const codec = codecs[key];\n if (!codec) {\n throw createCodedError(`Unsupported codec: ${key}`, ErrorCode.UNSUPPORTED_CODEC);\n }\n return codec;\n}\n\n/**\n * Check if a codec is supported\n */\nexport function isCodecSupported(id: number[]): boolean {\n return codecs[codecIdToKey(id)] !== undefined;\n}\n\n/**\n * Get human-readable codec name\n */\nexport function getCodecName(id: number[]): string {\n if (codecIdEquals(id, CodecId.COPY)) return 'Copy';\n if (codecIdEquals(id, CodecId.LZMA)) return 'LZMA';\n if (codecIdEquals(id, CodecId.LZMA2)) return 'LZMA2';\n if (codecIdEquals(id, CodecId.BCJ_X86)) return 'BCJ (x86)';\n if (codecIdEquals(id, CodecId.BCJ_ARM)) return 'BCJ (ARM)';\n if (codecIdEquals(id, CodecId.BCJ_ARMT)) return 'BCJ (ARM Thumb)';\n if (codecIdEquals(id, CodecId.BCJ_ARM64)) return 'BCJ (ARM64)';\n if (codecIdEquals(id, CodecId.BCJ_PPC)) return 'BCJ (PowerPC)';\n if (codecIdEquals(id, CodecId.BCJ_IA64)) return 'BCJ (IA64)';\n if (codecIdEquals(id, CodecId.BCJ_SPARC)) return 'BCJ (SPARC)';\n if (codecIdEquals(id, CodecId.BCJ2)) return 'BCJ2';\n if (codecIdEquals(id, CodecId.PPMD)) return 'PPMd';\n if (codecIdEquals(id, CodecId.DELTA)) return 'Delta';\n if (codecIdEquals(id, CodecId.DEFLATE)) return 'Deflate';\n if (codecIdEquals(id, CodecId.BZIP2)) return 'BZip2';\n if (codecIdEquals(id, CodecId.AES)) return 'AES-256';\n return `Unknown (${codecIdToKey(id)})`;\n}\n\n/**\n * Check if a codec ID matches BCJ2\n */\nexport function isBcj2Codec(id: number[]): boolean {\n return codecIdEquals(id, CodecId.BCJ2);\n}\n\n// Re-export BCJ2 multi-stream decoder for special handling\nexport { decodeBcj2Multi };\n\n// Register built-in codecs\n\n// Copy codec (no compression)\nregisterCodec(CodecId.COPY, {\n decode: decodeCopy,\n createDecoder: createCopyDecoder,\n});\n\n// LZMA codec\nregisterCodec(CodecId.LZMA, {\n decode: decodeLzma,\n createDecoder: createLzmaDecoder,\n});\n\n// LZMA2 codec\nregisterCodec(CodecId.LZMA2, {\n decode: decodeLzma2,\n createDecoder: createLzma2Decoder,\n});\n\n// BCJ (x86) filter\nregisterCodec(CodecId.BCJ_X86, {\n decode: decodeBcj,\n createDecoder: createBcjDecoder,\n});\n\n// BCJ (ARM) filter\nregisterCodec(CodecId.BCJ_ARM, {\n decode: decodeBcjArm,\n createDecoder: createBcjArmDecoder,\n});\n\n// BCJ (ARM Thumb) filter\nregisterCodec(CodecId.BCJ_ARMT, {\n decode: decodeBcjArmt,\n createDecoder: createBcjArmtDecoder,\n});\n\n// BCJ (ARM64) filter\nregisterCodec(CodecId.BCJ_ARM64, {\n decode: decodeBcjArm64,\n createDecoder: createBcjArm64Decoder,\n});\n\n// BCJ (PowerPC) filter\nregisterCodec(CodecId.BCJ_PPC, {\n decode: decodeBcjPpc,\n createDecoder: createBcjPpcDecoder,\n});\n\n// BCJ (IA64) filter\nregisterCodec(CodecId.BCJ_IA64, {\n decode: decodeBcjIa64,\n createDecoder: createBcjIa64Decoder,\n});\n\n// BCJ (SPARC) filter\nregisterCodec(CodecId.BCJ_SPARC, {\n decode: decodeBcjSparc,\n createDecoder: createBcjSparcDecoder,\n});\n\n// Delta filter\nregisterCodec(CodecId.DELTA, {\n decode: decodeDelta,\n createDecoder: createDeltaDecoder,\n});\n\n// Deflate codec\nregisterCodec(CodecId.DEFLATE, {\n decode: decodeDeflate,\n createDecoder: createDeflateDecoder,\n});\n\n// BZip2 codec\nregisterCodec(CodecId.BZIP2, {\n decode: decodeBzip2,\n createDecoder: createBzip2Decoder,\n});\n\n// AES-256-CBC codec (encryption)\nregisterCodec(CodecId.AES, {\n decode: decodeAes,\n createDecoder: createAesDecoder,\n});\n\n// BCJ2 (x86-64) filter - multi-stream\n// Note: BCJ2 requires special handling in SevenZipParser due to 4-stream architecture\nregisterCodec(CodecId.BCJ2, {\n decode: decodeBcj2,\n createDecoder: createBcj2Decoder,\n});\n\n// Note: PPMd codec is not implemented. See FUTURE_ENHANCEMENTS.md\n"],"names":["CodecId","createCodedError","ErrorCode","createAesDecoder","decodeAes","getPassword","setPassword","createBcjDecoder","decodeBcj","createBcj2Decoder","decodeBcj2","decodeBcj2Multi","createBcjArmDecoder","decodeBcjArm","createBcjArm64Decoder","decodeBcjArm64","createBcjArmtDecoder","decodeBcjArmt","createBcjIa64Decoder","decodeBcjIa64","createBcjPpcDecoder","decodeBcjPpc","createBcjSparcDecoder","decodeBcjSparc","createBzip2Decoder","decodeBzip2","createCopyDecoder","decodeCopy","createDeflateDecoder","decodeDeflate","createDeltaDecoder","decodeDelta","createLzmaDecoder","decodeLzma","createLzma2Decoder","decodeLzma2","codecs","codecIdToKey","id","parts","i","length","push","toString","toUpperCase","join","codecIdEquals","a","b","registerCodec","codec","getCodec","key","UNSUPPORTED_CODEC","isCodecSupported","undefined","getCodecName","COPY","LZMA","LZMA2","BCJ_X86","BCJ_ARM","BCJ_ARMT","BCJ_ARM64","BCJ_PPC","BCJ_IA64","BCJ_SPARC","BCJ2","PPMD","DELTA","DEFLATE","BZIP2","AES","isBcj2Codec","decode","createDecoder"],"mappings":"AAAA,sCAAsC;AACtC,2EAA2E;AAG3E,SAASA,OAAO,EAAEC,gBAAgB,EAAEC,SAAS,QAAQ,kBAAkB;AACvE,SAASC,gBAAgB,EAAEC,SAAS,EAAEC,WAAW,EAAEC,WAAW,QAAQ,WAAW;AACjF,SAASC,gBAAgB,EAAE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,qBAAqB;AACrB+B,cAAcjD,QAAQkE,SAAS,EAAE;IAC/BQ,QAAQnD;IACRoD,eAAerD;AACjB;AAEA,eAAe;AACf2B,cAAcjD,QAAQqE,KAAK,EAAE;IAC3BK,QAAQ3C;IACR4C,eAAe7C;AACjB;AAEA,gBAAgB;AAChBmB,cAAcjD,QAAQsE,OAAO,EAAE;IAC7BI,QAAQ7C;IACR8C,eAAe/C;AACjB;AAEA,cAAc;AACdqB,cAAcjD,QAAQuE,KAAK,EAAE;IAC3BG,QAAQjD;IACRkD,eAAenD;AACjB;AAEA,iCAAiC;AACjCyB,cAAcjD,QAAQwE,GAAG,EAAE;IACzBE,QAAQtE;IACRuE,eAAexE;AACjB;AAEA,sCAAsC;AACtC,sFAAsF;AACtF8C,cAAcjD,QAAQmE,IAAI,EAAE;IAC1BO,QAAQhE;IACRiE,eAAelE;AACjB,IAEA,kEAAkE"}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* the callback-based async pattern used throughout the iterator libraries.
|
|
10
10
|
*/
|
|
11
11
|
import type { Transform } from 'readable-stream';
|
|
12
|
-
export declare
|
|
12
|
+
export declare const hasNativeLzma: boolean;
|
|
13
13
|
/**
|
|
14
14
|
* Create a native LZMA2 decoder stream
|
|
15
15
|
* Returns a Transform stream that decodes LZMA2 data
|