7z-iterator 1.3.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.d.cts +3 -1
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +7 -28
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/nextEntry.js +1 -2
- package/dist/cjs/nextEntry.js.map +1 -1
- package/dist/cjs/sevenz/codecs/index.js +52 -30
- package/dist/cjs/sevenz/codecs/index.js.map +1 -1
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +4 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/nextEntry.js +1 -2
- package/dist/esm/nextEntry.js.map +1 -1
- package/dist/esm/sevenz/codecs/index.js +32 -10
- package/dist/esm/sevenz/codecs/index.js.map +1 -1
- package/package.json +10 -4
- package/dist/cjs/lzma/Lzma2ChunkParser.d.cts +0 -73
- package/dist/cjs/lzma/Lzma2ChunkParser.d.ts +0 -73
- package/dist/cjs/lzma/Lzma2ChunkParser.js +0 -148
- package/dist/cjs/lzma/Lzma2ChunkParser.js.map +0 -1
- package/dist/cjs/lzma/index.d.cts +0 -13
- package/dist/cjs/lzma/index.d.ts +0 -13
- package/dist/cjs/lzma/index.js +0 -63
- package/dist/cjs/lzma/index.js.map +0 -1
- package/dist/cjs/lzma/stream/transforms.d.cts +0 -38
- package/dist/cjs/lzma/stream/transforms.d.ts +0 -38
- package/dist/cjs/lzma/stream/transforms.js +0 -149
- package/dist/cjs/lzma/stream/transforms.js.map +0 -1
- package/dist/cjs/lzma/sync/Lzma2Decoder.d.cts +0 -30
- package/dist/cjs/lzma/sync/Lzma2Decoder.d.ts +0 -30
- package/dist/cjs/lzma/sync/Lzma2Decoder.js +0 -135
- package/dist/cjs/lzma/sync/Lzma2Decoder.js.map +0 -1
- package/dist/cjs/lzma/sync/LzmaDecoder.d.cts +0 -82
- package/dist/cjs/lzma/sync/LzmaDecoder.d.ts +0 -82
- package/dist/cjs/lzma/sync/LzmaDecoder.js +0 -440
- package/dist/cjs/lzma/sync/LzmaDecoder.js.map +0 -1
- package/dist/cjs/lzma/sync/RangeDecoder.d.cts +0 -69
- package/dist/cjs/lzma/sync/RangeDecoder.d.ts +0 -69
- package/dist/cjs/lzma/sync/RangeDecoder.js +0 -162
- package/dist/cjs/lzma/sync/RangeDecoder.js.map +0 -1
- package/dist/cjs/lzma/types.d.cts +0 -110
- package/dist/cjs/lzma/types.d.ts +0 -110
- package/dist/cjs/lzma/types.js +0 -264
- package/dist/cjs/lzma/types.js.map +0 -1
- package/dist/cjs/sevenz/codecs/Bcj.d.cts +0 -16
- package/dist/cjs/sevenz/codecs/Bcj.d.ts +0 -16
- package/dist/cjs/sevenz/codecs/Bcj.js +0 -183
- package/dist/cjs/sevenz/codecs/Bcj.js.map +0 -1
- package/dist/cjs/sevenz/codecs/BcjArm.d.cts +0 -21
- package/dist/cjs/sevenz/codecs/BcjArm.d.ts +0 -21
- package/dist/cjs/sevenz/codecs/BcjArm.js +0 -104
- package/dist/cjs/sevenz/codecs/BcjArm.js.map +0 -1
- package/dist/cjs/sevenz/codecs/BcjArm64.d.cts +0 -21
- package/dist/cjs/sevenz/codecs/BcjArm64.d.ts +0 -21
- package/dist/cjs/sevenz/codecs/BcjArm64.js +0 -65
- package/dist/cjs/sevenz/codecs/BcjArm64.js.map +0 -1
- package/dist/cjs/sevenz/codecs/BcjArmt.d.cts +0 -19
- package/dist/cjs/sevenz/codecs/BcjArmt.d.ts +0 -19
- package/dist/cjs/sevenz/codecs/BcjArmt.js +0 -76
- package/dist/cjs/sevenz/codecs/BcjArmt.js.map +0 -1
- package/dist/cjs/sevenz/codecs/BcjIa64.d.cts +0 -15
- package/dist/cjs/sevenz/codecs/BcjIa64.d.ts +0 -15
- package/dist/cjs/sevenz/codecs/BcjIa64.js +0 -141
- package/dist/cjs/sevenz/codecs/BcjIa64.js.map +0 -1
- package/dist/cjs/sevenz/codecs/BcjPpc.d.cts +0 -20
- package/dist/cjs/sevenz/codecs/BcjPpc.d.ts +0 -20
- package/dist/cjs/sevenz/codecs/BcjPpc.js +0 -64
- package/dist/cjs/sevenz/codecs/BcjPpc.js.map +0 -1
- package/dist/cjs/sevenz/codecs/BcjSparc.d.cts +0 -19
- package/dist/cjs/sevenz/codecs/BcjSparc.d.ts +0 -19
- package/dist/cjs/sevenz/codecs/BcjSparc.js +0 -69
- package/dist/cjs/sevenz/codecs/BcjSparc.js.map +0 -1
- package/dist/cjs/sevenz/codecs/Delta.d.cts +0 -16
- package/dist/cjs/sevenz/codecs/Delta.d.ts +0 -16
- package/dist/cjs/sevenz/codecs/Delta.js +0 -74
- package/dist/cjs/sevenz/codecs/Delta.js.map +0 -1
- package/dist/cjs/sevenz/codecs/Lzma.d.cts +0 -17
- package/dist/cjs/sevenz/codecs/Lzma.d.ts +0 -17
- package/dist/cjs/sevenz/codecs/Lzma.js +0 -40
- package/dist/cjs/sevenz/codecs/Lzma.js.map +0 -1
- package/dist/cjs/sevenz/codecs/Lzma2.d.cts +0 -20
- package/dist/cjs/sevenz/codecs/Lzma2.d.ts +0 -20
- package/dist/cjs/sevenz/codecs/Lzma2.js +0 -42
- package/dist/cjs/sevenz/codecs/Lzma2.js.map +0 -1
- package/dist/esm/lzma/Lzma2ChunkParser.d.ts +0 -73
- package/dist/esm/lzma/Lzma2ChunkParser.js +0 -137
- package/dist/esm/lzma/Lzma2ChunkParser.js.map +0 -1
- package/dist/esm/lzma/index.d.ts +0 -13
- package/dist/esm/lzma/index.js +0 -15
- package/dist/esm/lzma/index.js.map +0 -1
- package/dist/esm/lzma/stream/transforms.d.ts +0 -38
- package/dist/esm/lzma/stream/transforms.js +0 -150
- package/dist/esm/lzma/stream/transforms.js.map +0 -1
- package/dist/esm/lzma/sync/Lzma2Decoder.d.ts +0 -30
- package/dist/esm/lzma/sync/Lzma2Decoder.js +0 -115
- package/dist/esm/lzma/sync/Lzma2Decoder.js.map +0 -1
- package/dist/esm/lzma/sync/LzmaDecoder.d.ts +0 -82
- package/dist/esm/lzma/sync/LzmaDecoder.js +0 -403
- package/dist/esm/lzma/sync/LzmaDecoder.js.map +0 -1
- package/dist/esm/lzma/sync/RangeDecoder.d.ts +0 -69
- package/dist/esm/lzma/sync/RangeDecoder.js +0 -132
- package/dist/esm/lzma/sync/RangeDecoder.js.map +0 -1
- package/dist/esm/lzma/types.d.ts +0 -110
- package/dist/esm/lzma/types.js +0 -154
- package/dist/esm/lzma/types.js.map +0 -1
- package/dist/esm/sevenz/codecs/Bcj.d.ts +0 -16
- package/dist/esm/sevenz/codecs/Bcj.js +0 -175
- package/dist/esm/sevenz/codecs/Bcj.js.map +0 -1
- package/dist/esm/sevenz/codecs/BcjArm.d.ts +0 -21
- package/dist/esm/sevenz/codecs/BcjArm.js +0 -101
- package/dist/esm/sevenz/codecs/BcjArm.js.map +0 -1
- package/dist/esm/sevenz/codecs/BcjArm64.d.ts +0 -21
- package/dist/esm/sevenz/codecs/BcjArm64.js +0 -57
- package/dist/esm/sevenz/codecs/BcjArm64.js.map +0 -1
- package/dist/esm/sevenz/codecs/BcjArmt.d.ts +0 -19
- package/dist/esm/sevenz/codecs/BcjArmt.js +0 -66
- package/dist/esm/sevenz/codecs/BcjArmt.js.map +0 -1
- package/dist/esm/sevenz/codecs/BcjIa64.d.ts +0 -15
- package/dist/esm/sevenz/codecs/BcjIa64.js +0 -127
- package/dist/esm/sevenz/codecs/BcjIa64.js.map +0 -1
- package/dist/esm/sevenz/codecs/BcjPpc.d.ts +0 -20
- package/dist/esm/sevenz/codecs/BcjPpc.js +0 -55
- package/dist/esm/sevenz/codecs/BcjPpc.js.map +0 -1
- package/dist/esm/sevenz/codecs/BcjSparc.d.ts +0 -19
- package/dist/esm/sevenz/codecs/BcjSparc.js +0 -59
- package/dist/esm/sevenz/codecs/BcjSparc.js.map +0 -1
- package/dist/esm/sevenz/codecs/Delta.d.ts +0 -16
- package/dist/esm/sevenz/codecs/Delta.js +0 -66
- package/dist/esm/sevenz/codecs/Delta.js.map +0 -1
- package/dist/esm/sevenz/codecs/Lzma.d.ts +0 -17
- package/dist/esm/sevenz/codecs/Lzma.js +0 -33
- package/dist/esm/sevenz/codecs/Lzma.js.map +0 -1
- package/dist/esm/sevenz/codecs/Lzma2.d.ts +0 -20
- package/dist/esm/sevenz/codecs/Lzma2.js +0 -38
- package/dist/esm/sevenz/codecs/Lzma2.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/sevenz/codecs/Lzma.ts"],"sourcesContent":["// LZMA codec using TypeScript LZMA decoder\n// LZMA properties in 7z are 5 bytes: 1 byte lc/lp/pb + 4 bytes dictionary size (little-endian)\n\nimport type { Transform } from 'stream';\nimport { createLzmaDecoder as createLzmaTransform, decodeLzma as lzmaDecode } from '../../lzma/index.ts';\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\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 if (typeof unpackSize !== 'number' || unpackSize < 0) {\n throw new Error('LZMA requires known unpack size');\n }\n\n return lzmaDecode(input, properties, unpackSize);\n}\n\n/**\n * Create an LZMA decoder Transform stream\n *\n * Note: LZMA1 has no chunk boundaries, so this buffers all input\n * and decompresses when the stream ends.\n */\nexport function createLzmaDecoder(properties?: Buffer, unpackSize?: number): Transform {\n if (!properties || properties.length < 5) {\n throw new Error('LZMA requires 5-byte properties');\n }\n\n if (typeof unpackSize !== 'number' || unpackSize < 0) {\n throw new Error('LZMA requires known unpack size');\n }\n\n return createLzmaTransform(properties, unpackSize) as Transform;\n}\n"],"names":["createLzmaDecoder","decodeLzma","input","properties","unpackSize","length","Error","lzmaDecode","createLzmaTransform"],"mappings":"AAAA,2CAA2C;AAC3C,+FAA+F;;;;;;;;;;;;QA+B/EA;eAAAA;;QAlBAC;eAAAA;;;uBAVmE;AAU5E,SAASA,WAAWC,KAAa,EAAEC,UAAmB,EAAEC,UAAmB;IAChF,IAAI,CAACD,cAAcA,WAAWE,MAAM,GAAG,GAAG;QACxC,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAI,OAAOF,eAAe,YAAYA,aAAa,GAAG;QACpD,MAAM,IAAIE,MAAM;IAClB;IAEA,OAAOC,IAAAA,mBAAU,EAACL,OAAOC,YAAYC;AACvC;AAQO,SAASJ,kBAAkBG,UAAmB,EAAEC,UAAmB;IACxE,IAAI,CAACD,cAAcA,WAAWE,MAAM,GAAG,GAAG;QACxC,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAI,OAAOF,eAAe,YAAYA,aAAa,GAAG;QACpD,MAAM,IAAIE,MAAM;IAClB;IAEA,OAAOE,IAAAA,0BAAmB,EAACL,YAAYC;AACzC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Transform } from 'stream';
|
|
2
|
-
/**
|
|
3
|
-
* Decode LZMA2 compressed data to buffer
|
|
4
|
-
*
|
|
5
|
-
* @param input - LZMA2 compressed data
|
|
6
|
-
* @param properties - Properties buffer (1 byte: dictionary size)
|
|
7
|
-
* @param unpackSize - Expected output size (optional, for pre-allocation)
|
|
8
|
-
* @returns Decompressed data
|
|
9
|
-
*/
|
|
10
|
-
export declare function decodeLzma2(input: Buffer, properties?: Buffer, unpackSize?: number): Buffer;
|
|
11
|
-
/**
|
|
12
|
-
* Create an LZMA2 decoder Transform stream
|
|
13
|
-
*
|
|
14
|
-
* This is a true streaming decoder that processes LZMA2 chunks incrementally.
|
|
15
|
-
* Memory usage is O(dictionary_size + max_chunk_size) instead of O(folder_size).
|
|
16
|
-
*
|
|
17
|
-
* LZMA2 chunks are up to ~2MB uncompressed, so memory is bounded regardless of
|
|
18
|
-
* total archive size.
|
|
19
|
-
*/
|
|
20
|
-
export declare function createLzma2Decoder(properties?: Buffer, _unpackSize?: number): Transform;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Transform } from 'stream';
|
|
2
|
-
/**
|
|
3
|
-
* Decode LZMA2 compressed data to buffer
|
|
4
|
-
*
|
|
5
|
-
* @param input - LZMA2 compressed data
|
|
6
|
-
* @param properties - Properties buffer (1 byte: dictionary size)
|
|
7
|
-
* @param unpackSize - Expected output size (optional, for pre-allocation)
|
|
8
|
-
* @returns Decompressed data
|
|
9
|
-
*/
|
|
10
|
-
export declare function decodeLzma2(input: Buffer, properties?: Buffer, unpackSize?: number): Buffer;
|
|
11
|
-
/**
|
|
12
|
-
* Create an LZMA2 decoder Transform stream
|
|
13
|
-
*
|
|
14
|
-
* This is a true streaming decoder that processes LZMA2 chunks incrementally.
|
|
15
|
-
* Memory usage is O(dictionary_size + max_chunk_size) instead of O(folder_size).
|
|
16
|
-
*
|
|
17
|
-
* LZMA2 chunks are up to ~2MB uncompressed, so memory is bounded regardless of
|
|
18
|
-
* total archive size.
|
|
19
|
-
*/
|
|
20
|
-
export declare function createLzma2Decoder(properties?: Buffer, _unpackSize?: number): Transform;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// LZMA2 codec using TypeScript LZMA decoder
|
|
2
|
-
//
|
|
3
|
-
// LZMA2 format specification:
|
|
4
|
-
// https://github.com/ulikunitz/xz/blob/master/doc/LZMA2.md
|
|
5
|
-
//
|
|
6
|
-
// Control byte values:
|
|
7
|
-
// 0x00 = End of stream
|
|
8
|
-
// 0x01 = Uncompressed chunk, dictionary reset
|
|
9
|
-
// 0x02 = Uncompressed chunk, no dictionary reset
|
|
10
|
-
// 0x80-0xFF = LZMA compressed chunk (bits encode reset flags and size)
|
|
11
|
-
"use strict";
|
|
12
|
-
Object.defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
14
|
-
});
|
|
15
|
-
function _export(target, all) {
|
|
16
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
_export(exports, {
|
|
22
|
-
get createLzma2Decoder () {
|
|
23
|
-
return createLzma2Decoder;
|
|
24
|
-
},
|
|
25
|
-
get decodeLzma2 () {
|
|
26
|
-
return decodeLzma2;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
var _indexts = require("../../lzma/index.js");
|
|
30
|
-
function decodeLzma2(input, properties, unpackSize) {
|
|
31
|
-
if (!properties || properties.length < 1) {
|
|
32
|
-
throw new Error('LZMA2 requires properties byte');
|
|
33
|
-
}
|
|
34
|
-
return (0, _indexts.decodeLzma2)(input, properties, unpackSize);
|
|
35
|
-
}
|
|
36
|
-
function createLzma2Decoder(properties, _unpackSize) {
|
|
37
|
-
if (!properties || properties.length < 1) {
|
|
38
|
-
throw new Error('LZMA2 requires properties byte');
|
|
39
|
-
}
|
|
40
|
-
return (0, _indexts.createLzma2Decoder)(properties);
|
|
41
|
-
}
|
|
42
|
-
/* 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/Lzma2.ts"],"sourcesContent":["// LZMA2 codec using TypeScript LZMA decoder\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 type { Transform } from 'stream';\nimport { createLzma2Decoder as createLzma2Transform, decodeLzma2 as lzma2Decode } from '../../lzma/index.ts';\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 (optional, for pre-allocation)\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 return lzma2Decode(input, properties, unpackSize);\n}\n\n/**\n * Create an LZMA2 decoder Transform stream\n *\n * This is a true streaming decoder that processes LZMA2 chunks incrementally.\n * Memory usage is O(dictionary_size + max_chunk_size) instead of O(folder_size).\n *\n * LZMA2 chunks are up to ~2MB uncompressed, so memory is bounded regardless of\n * total archive size.\n */\nexport function createLzma2Decoder(properties?: Buffer, _unpackSize?: number): Transform {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n\n return createLzma2Transform(properties) as Transform;\n}\n"],"names":["createLzma2Decoder","decodeLzma2","input","properties","unpackSize","length","Error","lzma2Decode","_unpackSize","createLzma2Transform"],"mappings":"AAAA,4CAA4C;AAC5C,EAAE;AACF,8BAA8B;AAC9B,2DAA2D;AAC3D,EAAE;AACF,uBAAuB;AACvB,+BAA+B;AAC/B,sDAAsD;AACtD,yDAAyD;AACzD,0EAA0E;;;;;;;;;;;;QA8B1DA;eAAAA;;QAjBAC;eAAAA;;;uBAVuE;AAUhF,SAASA,YAAYC,KAAa,EAAEC,UAAmB,EAAEC,UAAmB;IACjF,IAAI,CAACD,cAAcA,WAAWE,MAAM,GAAG,GAAG;QACxC,MAAM,IAAIC,MAAM;IAClB;IAEA,OAAOC,IAAAA,oBAAW,EAACL,OAAOC,YAAYC;AACxC;AAWO,SAASJ,mBAAmBG,UAAmB,EAAEK,WAAoB;IAC1E,IAAI,CAACL,cAAcA,WAAWE,MAAM,GAAG,GAAG;QACxC,MAAM,IAAIC,MAAM;IAClB;IAEA,OAAOG,IAAAA,2BAAoB,EAACN;AAC9B"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LZMA2 Chunk Parser
|
|
3
|
-
*
|
|
4
|
-
* Shared parsing logic for LZMA2 chunk headers.
|
|
5
|
-
* Used by both synchronous and streaming decoders.
|
|
6
|
-
*
|
|
7
|
-
* LZMA2 control byte ranges:
|
|
8
|
-
* 0x00 = End of stream
|
|
9
|
-
* 0x01 = Uncompressed chunk, dictionary reset
|
|
10
|
-
* 0x02 = Uncompressed chunk, no dictionary reset
|
|
11
|
-
* 0x80-0x9F = LZMA chunk, no reset (solid mode)
|
|
12
|
-
* 0xA0-0xBF = LZMA chunk, reset state (probabilities)
|
|
13
|
-
* 0xC0-0xDF = LZMA chunk, reset state + new properties
|
|
14
|
-
* 0xE0-0xFF = LZMA chunk, reset dictionary + state + new properties
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* LZMA properties extracted from chunk header
|
|
18
|
-
*/
|
|
19
|
-
export interface LzmaChunkProps {
|
|
20
|
-
lc: number;
|
|
21
|
-
lp: number;
|
|
22
|
-
pb: number;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Parsed LZMA2 chunk information
|
|
26
|
-
*/
|
|
27
|
-
export interface Lzma2Chunk {
|
|
28
|
-
/** Chunk type */
|
|
29
|
-
type: 'end' | 'uncompressed' | 'lzma';
|
|
30
|
-
/** Total bytes consumed by header (including control byte) */
|
|
31
|
-
headerSize: number;
|
|
32
|
-
/** Whether to reset dictionary */
|
|
33
|
-
dictReset: boolean;
|
|
34
|
-
/** Whether to reset state/probabilities */
|
|
35
|
-
stateReset: boolean;
|
|
36
|
-
/** New LZMA properties (only for control >= 0xC0) */
|
|
37
|
-
newProps: LzmaChunkProps | null;
|
|
38
|
-
/** Uncompressed data size */
|
|
39
|
-
uncompSize: number;
|
|
40
|
-
/** Compressed data size (0 for uncompressed chunks) */
|
|
41
|
-
compSize: number;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Result of parsing attempt
|
|
45
|
-
*/
|
|
46
|
-
export type ParseResult = {
|
|
47
|
-
success: true;
|
|
48
|
-
chunk: Lzma2Chunk;
|
|
49
|
-
} | {
|
|
50
|
-
success: false;
|
|
51
|
-
needBytes: number;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Parse an LZMA2 chunk header
|
|
55
|
-
*
|
|
56
|
-
* @param input - Input buffer
|
|
57
|
-
* @param offset - Offset to start parsing
|
|
58
|
-
* @returns Parsed chunk info or number of bytes needed
|
|
59
|
-
*/
|
|
60
|
-
export declare function parseLzma2ChunkHeader(input: Buffer, offset: number): ParseResult;
|
|
61
|
-
/** Result type for hasCompleteChunk with totalSize included on success */
|
|
62
|
-
export type CompleteChunkResult = {
|
|
63
|
-
success: true;
|
|
64
|
-
chunk: Lzma2Chunk;
|
|
65
|
-
totalSize: number;
|
|
66
|
-
} | {
|
|
67
|
-
success: false;
|
|
68
|
-
needBytes: number;
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Check if we have enough data for the complete chunk (header + data)
|
|
72
|
-
*/
|
|
73
|
-
export declare function hasCompleteChunk(input: Buffer, offset: number): CompleteChunkResult;
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LZMA2 Chunk Parser
|
|
3
|
-
*
|
|
4
|
-
* Shared parsing logic for LZMA2 chunk headers.
|
|
5
|
-
* Used by both synchronous and streaming decoders.
|
|
6
|
-
*
|
|
7
|
-
* LZMA2 control byte ranges:
|
|
8
|
-
* 0x00 = End of stream
|
|
9
|
-
* 0x01 = Uncompressed chunk, dictionary reset
|
|
10
|
-
* 0x02 = Uncompressed chunk, no dictionary reset
|
|
11
|
-
* 0x80-0x9F = LZMA chunk, no reset (solid mode)
|
|
12
|
-
* 0xA0-0xBF = LZMA chunk, reset state (probabilities)
|
|
13
|
-
* 0xC0-0xDF = LZMA chunk, reset state + new properties
|
|
14
|
-
* 0xE0-0xFF = LZMA chunk, reset dictionary + state + new properties
|
|
15
|
-
*/ /**
|
|
16
|
-
* LZMA properties extracted from chunk header
|
|
17
|
-
*/ /**
|
|
18
|
-
* Parse an LZMA2 chunk header
|
|
19
|
-
*
|
|
20
|
-
* @param input - Input buffer
|
|
21
|
-
* @param offset - Offset to start parsing
|
|
22
|
-
* @returns Parsed chunk info or number of bytes needed
|
|
23
|
-
*/ export function parseLzma2ChunkHeader(input, offset) {
|
|
24
|
-
if (offset >= input.length) {
|
|
25
|
-
return {
|
|
26
|
-
success: false,
|
|
27
|
-
needBytes: 1
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const control = input[offset];
|
|
31
|
-
// End of stream
|
|
32
|
-
if (control === 0x00) {
|
|
33
|
-
return {
|
|
34
|
-
success: true,
|
|
35
|
-
chunk: {
|
|
36
|
-
type: 'end',
|
|
37
|
-
headerSize: 1,
|
|
38
|
-
dictReset: false,
|
|
39
|
-
stateReset: false,
|
|
40
|
-
newProps: null,
|
|
41
|
-
uncompSize: 0,
|
|
42
|
-
compSize: 0
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
// Uncompressed chunk
|
|
47
|
-
if (control === 0x01 || control === 0x02) {
|
|
48
|
-
// Need 3 bytes: control + 2 size bytes
|
|
49
|
-
if (offset + 3 > input.length) {
|
|
50
|
-
return {
|
|
51
|
-
success: false,
|
|
52
|
-
needBytes: 3 - (input.length - offset)
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
const uncompSize = (input[offset + 1] << 8 | input[offset + 2]) + 1;
|
|
56
|
-
return {
|
|
57
|
-
success: true,
|
|
58
|
-
chunk: {
|
|
59
|
-
type: 'uncompressed',
|
|
60
|
-
headerSize: 3,
|
|
61
|
-
dictReset: control === 0x01,
|
|
62
|
-
stateReset: false,
|
|
63
|
-
newProps: null,
|
|
64
|
-
uncompSize,
|
|
65
|
-
compSize: 0
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
// LZMA compressed chunk
|
|
70
|
-
if (control >= 0x80) {
|
|
71
|
-
const hasNewProps = control >= 0xc0;
|
|
72
|
-
const minHeaderSize = hasNewProps ? 6 : 5; // control + 2 uncomp + 2 comp + (1 props)
|
|
73
|
-
if (offset + minHeaderSize > input.length) {
|
|
74
|
-
return {
|
|
75
|
-
success: false,
|
|
76
|
-
needBytes: minHeaderSize - (input.length - offset)
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
// Parse sizes
|
|
80
|
-
const uncompHigh = control & 0x1f;
|
|
81
|
-
const uncompSize = (uncompHigh << 16 | input[offset + 1] << 8 | input[offset + 2]) + 1;
|
|
82
|
-
const compSize = (input[offset + 3] << 8 | input[offset + 4]) + 1;
|
|
83
|
-
// Parse properties if present
|
|
84
|
-
let newProps = null;
|
|
85
|
-
if (hasNewProps) {
|
|
86
|
-
const propsByte = input[offset + 5];
|
|
87
|
-
const lc = propsByte % 9;
|
|
88
|
-
const remainder = ~~(propsByte / 9);
|
|
89
|
-
const lp = remainder % 5;
|
|
90
|
-
const pb = ~~(remainder / 5);
|
|
91
|
-
newProps = {
|
|
92
|
-
lc,
|
|
93
|
-
lp,
|
|
94
|
-
pb
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
success: true,
|
|
99
|
-
chunk: {
|
|
100
|
-
type: 'lzma',
|
|
101
|
-
headerSize: minHeaderSize,
|
|
102
|
-
dictReset: control >= 0xe0,
|
|
103
|
-
stateReset: control >= 0xa0,
|
|
104
|
-
newProps,
|
|
105
|
-
uncompSize,
|
|
106
|
-
compSize
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
// Invalid control byte
|
|
111
|
-
throw new Error(`Invalid LZMA2 control byte: 0x${control.toString(16)}`);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Check if we have enough data for the complete chunk (header + data)
|
|
115
|
-
*/ export function hasCompleteChunk(input, offset) {
|
|
116
|
-
const result = parseLzma2ChunkHeader(input, offset);
|
|
117
|
-
if (result.success === false) {
|
|
118
|
-
return {
|
|
119
|
-
success: false,
|
|
120
|
-
needBytes: result.needBytes
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
const { chunk } = result;
|
|
124
|
-
const dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;
|
|
125
|
-
const totalSize = chunk.headerSize + dataSize;
|
|
126
|
-
if (offset + totalSize > input.length) {
|
|
127
|
-
return {
|
|
128
|
-
success: false,
|
|
129
|
-
needBytes: totalSize - (input.length - offset)
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
success: true,
|
|
134
|
-
chunk,
|
|
135
|
-
totalSize
|
|
136
|
-
};
|
|
137
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/lzma/Lzma2ChunkParser.ts"],"sourcesContent":["/**\n * LZMA2 Chunk Parser\n *\n * Shared parsing logic for LZMA2 chunk headers.\n * Used by both synchronous and streaming decoders.\n *\n * LZMA2 control byte ranges:\n * 0x00 = End of stream\n * 0x01 = Uncompressed chunk, dictionary reset\n * 0x02 = Uncompressed chunk, no dictionary reset\n * 0x80-0x9F = LZMA chunk, no reset (solid mode)\n * 0xA0-0xBF = LZMA chunk, reset state (probabilities)\n * 0xC0-0xDF = LZMA chunk, reset state + new properties\n * 0xE0-0xFF = LZMA chunk, reset dictionary + state + new properties\n */\n\n/**\n * LZMA properties extracted from chunk header\n */\nexport interface LzmaChunkProps {\n lc: number;\n lp: number;\n pb: number;\n}\n\n/**\n * Parsed LZMA2 chunk information\n */\nexport interface Lzma2Chunk {\n /** Chunk type */\n type: 'end' | 'uncompressed' | 'lzma';\n /** Total bytes consumed by header (including control byte) */\n headerSize: number;\n /** Whether to reset dictionary */\n dictReset: boolean;\n /** Whether to reset state/probabilities */\n stateReset: boolean;\n /** New LZMA properties (only for control >= 0xC0) */\n newProps: LzmaChunkProps | null;\n /** Uncompressed data size */\n uncompSize: number;\n /** Compressed data size (0 for uncompressed chunks) */\n compSize: number;\n}\n\n/**\n * Result of parsing attempt\n */\nexport type ParseResult = { success: true; chunk: Lzma2Chunk } | { success: false; needBytes: number };\n\n/**\n * Parse an LZMA2 chunk header\n *\n * @param input - Input buffer\n * @param offset - Offset to start parsing\n * @returns Parsed chunk info or number of bytes needed\n */\nexport function parseLzma2ChunkHeader(input: Buffer, offset: number): ParseResult {\n if (offset >= input.length) {\n return { success: false, needBytes: 1 };\n }\n\n const control = input[offset];\n\n // End of stream\n if (control === 0x00) {\n return {\n success: true,\n chunk: {\n type: 'end',\n headerSize: 1,\n dictReset: false,\n stateReset: false,\n newProps: null,\n uncompSize: 0,\n compSize: 0,\n },\n };\n }\n\n // Uncompressed chunk\n if (control === 0x01 || control === 0x02) {\n // Need 3 bytes: control + 2 size bytes\n if (offset + 3 > input.length) {\n return { success: false, needBytes: 3 - (input.length - offset) };\n }\n\n const uncompSize = ((input[offset + 1] << 8) | input[offset + 2]) + 1;\n\n return {\n success: true,\n chunk: {\n type: 'uncompressed',\n headerSize: 3,\n dictReset: control === 0x01,\n stateReset: false,\n newProps: null,\n uncompSize,\n compSize: 0,\n },\n };\n }\n\n // LZMA compressed chunk\n if (control >= 0x80) {\n const hasNewProps = control >= 0xc0;\n const minHeaderSize = hasNewProps ? 6 : 5; // control + 2 uncomp + 2 comp + (1 props)\n\n if (offset + minHeaderSize > input.length) {\n return { success: false, needBytes: minHeaderSize - (input.length - offset) };\n }\n\n // Parse sizes\n const uncompHigh = control & 0x1f;\n const uncompSize = ((uncompHigh << 16) | (input[offset + 1] << 8) | input[offset + 2]) + 1;\n const compSize = ((input[offset + 3] << 8) | input[offset + 4]) + 1;\n\n // Parse properties if present\n let newProps: LzmaChunkProps | null = null;\n if (hasNewProps) {\n const propsByte = input[offset + 5];\n const lc = propsByte % 9;\n const remainder = ~~(propsByte / 9);\n const lp = remainder % 5;\n const pb = ~~(remainder / 5);\n newProps = { lc, lp, pb };\n }\n\n return {\n success: true,\n chunk: {\n type: 'lzma',\n headerSize: minHeaderSize,\n dictReset: control >= 0xe0,\n stateReset: control >= 0xa0,\n newProps,\n uncompSize,\n compSize,\n },\n };\n }\n\n // Invalid control byte\n throw new Error(`Invalid LZMA2 control byte: 0x${control.toString(16)}`);\n}\n\n/** Result type for hasCompleteChunk with totalSize included on success */\nexport type CompleteChunkResult = { success: true; chunk: Lzma2Chunk; totalSize: number } | { success: false; needBytes: number };\n\n/**\n * Check if we have enough data for the complete chunk (header + data)\n */\nexport function hasCompleteChunk(input: Buffer, offset: number): CompleteChunkResult {\n const result = parseLzma2ChunkHeader(input, offset);\n\n if (result.success === false) {\n return { success: false, needBytes: result.needBytes };\n }\n\n const { chunk } = result;\n const dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;\n const totalSize = chunk.headerSize + dataSize;\n\n if (offset + totalSize > input.length) {\n return { success: false, needBytes: totalSize - (input.length - offset) };\n }\n\n return { success: true, chunk, totalSize };\n}\n"],"names":["parseLzma2ChunkHeader","input","offset","length","success","needBytes","control","chunk","type","headerSize","dictReset","stateReset","newProps","uncompSize","compSize","hasNewProps","minHeaderSize","uncompHigh","propsByte","lc","remainder","lp","pb","Error","toString","hasCompleteChunk","result","dataSize","totalSize"],"mappings":"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"}
|
package/dist/esm/lzma/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LZMA Decoder Module
|
|
3
|
-
*
|
|
4
|
-
* Provides both synchronous and streaming LZMA1/LZMA2 decoders.
|
|
5
|
-
*
|
|
6
|
-
* Synchronous API: Use when input is a complete Buffer
|
|
7
|
-
* Streaming API: Use with Transform streams for memory-efficient decompression
|
|
8
|
-
*/
|
|
9
|
-
export { createLzma2Decoder, createLzmaDecoder } from './stream/transforms.js';
|
|
10
|
-
export { decodeLzma2, Lzma2Decoder } from './sync/Lzma2Decoder.js';
|
|
11
|
-
export { decodeLzma, LzmaDecoder } from './sync/LzmaDecoder.js';
|
|
12
|
-
export { BitTreeDecoder, RangeDecoder } from './sync/RangeDecoder.js';
|
|
13
|
-
export * from './types.js';
|
package/dist/esm/lzma/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LZMA Decoder Module
|
|
3
|
-
*
|
|
4
|
-
* Provides both synchronous and streaming LZMA1/LZMA2 decoders.
|
|
5
|
-
*
|
|
6
|
-
* Synchronous API: Use when input is a complete Buffer
|
|
7
|
-
* Streaming API: Use with Transform streams for memory-efficient decompression
|
|
8
|
-
*/ // Streaming decoders (Transform streams)
|
|
9
|
-
export { createLzma2Decoder, createLzmaDecoder } from './stream/transforms.js';
|
|
10
|
-
export { decodeLzma2, Lzma2Decoder } from './sync/Lzma2Decoder.js';
|
|
11
|
-
// Synchronous decoders (for Buffer input)
|
|
12
|
-
export { decodeLzma, LzmaDecoder } from './sync/LzmaDecoder.js';
|
|
13
|
-
export { BitTreeDecoder, RangeDecoder } from './sync/RangeDecoder.js';
|
|
14
|
-
// Type exports
|
|
15
|
-
export * from './types.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/lzma/index.ts"],"sourcesContent":["/**\n * LZMA Decoder Module\n *\n * Provides both synchronous and streaming LZMA1/LZMA2 decoders.\n *\n * Synchronous API: Use when input is a complete Buffer\n * Streaming API: Use with Transform streams for memory-efficient decompression\n */\n\n// Streaming decoders (Transform streams)\nexport { createLzma2Decoder, createLzmaDecoder } from './stream/transforms.ts';\nexport { decodeLzma2, Lzma2Decoder } from './sync/Lzma2Decoder.ts';\n// Synchronous decoders (for Buffer input)\nexport { decodeLzma, LzmaDecoder } from './sync/LzmaDecoder.ts';\nexport { BitTreeDecoder, RangeDecoder } from './sync/RangeDecoder.ts';\n// Type exports\nexport * from './types.ts';\n"],"names":["createLzma2Decoder","createLzmaDecoder","decodeLzma2","Lzma2Decoder","decodeLzma","LzmaDecoder","BitTreeDecoder","RangeDecoder"],"mappings":"AAAA;;;;;;;CAOC,GAED,yCAAyC;AACzC,SAASA,kBAAkB,EAAEC,iBAAiB,QAAQ,yBAAyB;AAC/E,SAASC,WAAW,EAAEC,YAAY,QAAQ,yBAAyB;AACnE,0CAA0C;AAC1C,SAASC,UAAU,EAAEC,WAAW,QAAQ,wBAAwB;AAChE,SAASC,cAAc,EAAEC,YAAY,QAAQ,yBAAyB;AACtE,eAAe;AACf,cAAc,aAAa"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LZMA Transform Stream Wrappers
|
|
3
|
-
*
|
|
4
|
-
* Provides Transform streams for LZMA1 and LZMA2 decompression.
|
|
5
|
-
*
|
|
6
|
-
* LZMA2 streaming works by buffering until a complete chunk is available,
|
|
7
|
-
* then decoding synchronously. LZMA2 chunks are bounded in size (~2MB max
|
|
8
|
-
* uncompressed), so memory usage is predictable and bounded.
|
|
9
|
-
*
|
|
10
|
-
* True byte-by-byte async LZMA streaming would require rewriting the entire
|
|
11
|
-
* decoder with continuation-passing style, which is complex and not worth
|
|
12
|
-
* the effort given LZMA2's chunked format.
|
|
13
|
-
*/
|
|
14
|
-
import { Transform } from 'extract-base-iterator';
|
|
15
|
-
/**
|
|
16
|
-
* Create an LZMA2 decoder Transform stream
|
|
17
|
-
*
|
|
18
|
-
* This is a streaming decoder that processes LZMA2 chunks incrementally.
|
|
19
|
-
* Memory usage is O(dictionary_size + max_chunk_size) instead of O(folder_size).
|
|
20
|
-
*
|
|
21
|
-
* @param properties - 1-byte LZMA2 properties (dictionary size)
|
|
22
|
-
* @returns Transform stream that decompresses LZMA2 data
|
|
23
|
-
*/
|
|
24
|
-
export declare function createLzma2Decoder(properties: Buffer | Uint8Array): InstanceType<typeof Transform>;
|
|
25
|
-
/**
|
|
26
|
-
* Create an LZMA1 decoder Transform stream
|
|
27
|
-
*
|
|
28
|
-
* Note: LZMA1 has no chunk boundaries, so this requires knowing the
|
|
29
|
-
* uncompressed size upfront. The stream buffers all input, then
|
|
30
|
-
* decompresses when complete.
|
|
31
|
-
*
|
|
32
|
-
* For true streaming, use LZMA2 which has built-in chunking.
|
|
33
|
-
*
|
|
34
|
-
* @param properties - 5-byte LZMA properties
|
|
35
|
-
* @param unpackSize - Expected uncompressed size
|
|
36
|
-
* @returns Transform stream that decompresses LZMA1 data
|
|
37
|
-
*/
|
|
38
|
-
export declare function createLzmaDecoder(properties: Buffer | Uint8Array, unpackSize: number): InstanceType<typeof Transform>;
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LZMA Transform Stream Wrappers
|
|
3
|
-
*
|
|
4
|
-
* Provides Transform streams for LZMA1 and LZMA2 decompression.
|
|
5
|
-
*
|
|
6
|
-
* LZMA2 streaming works by buffering until a complete chunk is available,
|
|
7
|
-
* then decoding synchronously. LZMA2 chunks are bounded in size (~2MB max
|
|
8
|
-
* uncompressed), so memory usage is predictable and bounded.
|
|
9
|
-
*
|
|
10
|
-
* True byte-by-byte async LZMA streaming would require rewriting the entire
|
|
11
|
-
* decoder with continuation-passing style, which is complex and not worth
|
|
12
|
-
* the effort given LZMA2's chunked format.
|
|
13
|
-
*/ import { Transform } from 'extract-base-iterator';
|
|
14
|
-
import { hasCompleteChunk } from '../Lzma2ChunkParser.js';
|
|
15
|
-
import { LzmaDecoder } from '../sync/LzmaDecoder.js';
|
|
16
|
-
import { parseLzma2DictionarySize } from '../types.js';
|
|
17
|
-
/**
|
|
18
|
-
* Create an LZMA2 decoder Transform stream
|
|
19
|
-
*
|
|
20
|
-
* This is a streaming decoder that processes LZMA2 chunks incrementally.
|
|
21
|
-
* Memory usage is O(dictionary_size + max_chunk_size) instead of O(folder_size).
|
|
22
|
-
*
|
|
23
|
-
* @param properties - 1-byte LZMA2 properties (dictionary size)
|
|
24
|
-
* @returns Transform stream that decompresses LZMA2 data
|
|
25
|
-
*/ export function createLzma2Decoder(properties) {
|
|
26
|
-
if (!properties || properties.length < 1) {
|
|
27
|
-
throw new Error('LZMA2 requires properties byte');
|
|
28
|
-
}
|
|
29
|
-
const dictSize = parseLzma2DictionarySize(properties[0]);
|
|
30
|
-
// LZMA decoder instance - reused across chunks for solid mode
|
|
31
|
-
const decoder = new LzmaDecoder();
|
|
32
|
-
decoder.setDictionarySize(dictSize);
|
|
33
|
-
// Track current LZMA properties
|
|
34
|
-
let propsSet = false;
|
|
35
|
-
// Buffer for incomplete chunk data
|
|
36
|
-
let pending = null;
|
|
37
|
-
let finished = false;
|
|
38
|
-
return new Transform({
|
|
39
|
-
transform: function(chunk, _encoding, callback) {
|
|
40
|
-
if (finished) {
|
|
41
|
-
callback(null);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
// Combine with pending data
|
|
45
|
-
let input;
|
|
46
|
-
if (pending && pending.length > 0) {
|
|
47
|
-
input = Buffer.concat([
|
|
48
|
-
pending,
|
|
49
|
-
chunk
|
|
50
|
-
]);
|
|
51
|
-
pending = null;
|
|
52
|
-
} else {
|
|
53
|
-
input = chunk;
|
|
54
|
-
}
|
|
55
|
-
let offset = 0;
|
|
56
|
-
try {
|
|
57
|
-
while(offset < input.length && !finished){
|
|
58
|
-
const result = hasCompleteChunk(input, offset);
|
|
59
|
-
if (!result.success) {
|
|
60
|
-
// Need more data
|
|
61
|
-
pending = input.slice(offset);
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
const { chunk: chunkInfo, totalSize } = result;
|
|
65
|
-
if (chunkInfo.type === 'end') {
|
|
66
|
-
finished = true;
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
// Handle dictionary reset
|
|
70
|
-
if (chunkInfo.dictReset) {
|
|
71
|
-
decoder.resetDictionary();
|
|
72
|
-
}
|
|
73
|
-
const dataOffset = offset + chunkInfo.headerSize;
|
|
74
|
-
if (chunkInfo.type === 'uncompressed') {
|
|
75
|
-
const uncompData = input.slice(dataOffset, dataOffset + chunkInfo.uncompSize);
|
|
76
|
-
this.push(uncompData);
|
|
77
|
-
// Feed uncompressed data to dictionary for subsequent LZMA chunks
|
|
78
|
-
decoder.feedUncompressed(uncompData);
|
|
79
|
-
} else {
|
|
80
|
-
// LZMA compressed chunk
|
|
81
|
-
// Apply new properties if present
|
|
82
|
-
if (chunkInfo.newProps) {
|
|
83
|
-
const { lc, lp, pb } = chunkInfo.newProps;
|
|
84
|
-
if (!decoder.setLcLpPb(lc, lp, pb)) {
|
|
85
|
-
throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);
|
|
86
|
-
}
|
|
87
|
-
propsSet = true;
|
|
88
|
-
}
|
|
89
|
-
if (!propsSet) {
|
|
90
|
-
throw new Error('LZMA chunk without properties');
|
|
91
|
-
}
|
|
92
|
-
// Reset probabilities if state reset
|
|
93
|
-
if (chunkInfo.stateReset) {
|
|
94
|
-
decoder.resetProbabilities();
|
|
95
|
-
}
|
|
96
|
-
// Determine solid mode - preserve dictionary if not resetting state or if only resetting state (not dict)
|
|
97
|
-
const useSolid = !chunkInfo.stateReset || chunkInfo.stateReset && !chunkInfo.dictReset;
|
|
98
|
-
const compData = input.slice(dataOffset, dataOffset + chunkInfo.compSize);
|
|
99
|
-
const decoded = decoder.decode(compData, 0, chunkInfo.uncompSize, useSolid);
|
|
100
|
-
this.push(decoded);
|
|
101
|
-
}
|
|
102
|
-
offset += totalSize;
|
|
103
|
-
}
|
|
104
|
-
callback(null);
|
|
105
|
-
} catch (err) {
|
|
106
|
-
callback(err);
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
flush: function(callback) {
|
|
110
|
-
if (pending && pending.length > 0 && !finished) {
|
|
111
|
-
callback(new Error('Truncated LZMA2 stream'));
|
|
112
|
-
} else {
|
|
113
|
-
callback(null);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Create an LZMA1 decoder Transform stream
|
|
120
|
-
*
|
|
121
|
-
* Note: LZMA1 has no chunk boundaries, so this requires knowing the
|
|
122
|
-
* uncompressed size upfront. The stream buffers all input, then
|
|
123
|
-
* decompresses when complete.
|
|
124
|
-
*
|
|
125
|
-
* For true streaming, use LZMA2 which has built-in chunking.
|
|
126
|
-
*
|
|
127
|
-
* @param properties - 5-byte LZMA properties
|
|
128
|
-
* @param unpackSize - Expected uncompressed size
|
|
129
|
-
* @returns Transform stream that decompresses LZMA1 data
|
|
130
|
-
*/ export function createLzmaDecoder(properties, unpackSize) {
|
|
131
|
-
const decoder = new LzmaDecoder();
|
|
132
|
-
decoder.setDecoderProperties(properties);
|
|
133
|
-
const chunks = [];
|
|
134
|
-
return new Transform({
|
|
135
|
-
transform: function(chunk, _encoding, callback) {
|
|
136
|
-
chunks.push(chunk);
|
|
137
|
-
callback(null);
|
|
138
|
-
},
|
|
139
|
-
flush: function(callback) {
|
|
140
|
-
try {
|
|
141
|
-
const input = Buffer.concat(chunks);
|
|
142
|
-
const output = decoder.decode(input, 0, unpackSize, false);
|
|
143
|
-
this.push(output);
|
|
144
|
-
callback(null);
|
|
145
|
-
} catch (err) {
|
|
146
|
-
callback(err);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/src/lzma/stream/transforms.ts"],"sourcesContent":["/**\n * LZMA Transform Stream Wrappers\n *\n * Provides Transform streams for LZMA1 and LZMA2 decompression.\n *\n * LZMA2 streaming works by buffering until a complete chunk is available,\n * then decoding synchronously. LZMA2 chunks are bounded in size (~2MB max\n * uncompressed), so memory usage is predictable and bounded.\n *\n * True byte-by-byte async LZMA streaming would require rewriting the entire\n * decoder with continuation-passing style, which is complex and not worth\n * the effort given LZMA2's chunked format.\n */\n\nimport { Transform } from 'extract-base-iterator';\nimport { hasCompleteChunk } from '../Lzma2ChunkParser.ts';\nimport { LzmaDecoder } from '../sync/LzmaDecoder.ts';\nimport { parseLzma2DictionarySize } from '../types.ts';\n\n/**\n * Create an LZMA2 decoder Transform stream\n *\n * This is a streaming decoder that processes LZMA2 chunks incrementally.\n * Memory usage is O(dictionary_size + max_chunk_size) instead of O(folder_size).\n *\n * @param properties - 1-byte LZMA2 properties (dictionary size)\n * @returns Transform stream that decompresses LZMA2 data\n */\nexport function createLzma2Decoder(properties: Buffer | Uint8Array): InstanceType<typeof Transform> {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n\n const dictSize = parseLzma2DictionarySize(properties[0]);\n\n // LZMA decoder instance - reused across chunks for solid mode\n const decoder = new LzmaDecoder();\n decoder.setDictionarySize(dictSize);\n\n // Track current LZMA properties\n let propsSet = false;\n\n // Buffer for incomplete chunk data\n let pending: Buffer | null = null;\n let finished = false;\n\n return new Transform({\n transform: function (this: InstanceType<typeof Transform>, chunk: Buffer, _encoding: string, callback: (err?: Error | null) => void) {\n if (finished) {\n callback(null);\n return;\n }\n\n // Combine with pending data\n let input: Buffer;\n if (pending && pending.length > 0) {\n input = Buffer.concat([pending, chunk]);\n pending = null;\n } else {\n input = chunk;\n }\n\n let offset = 0;\n\n try {\n while (offset < input.length && !finished) {\n const result = hasCompleteChunk(input, offset);\n\n if (!result.success) {\n // Need more data\n pending = input.slice(offset);\n break;\n }\n\n const { chunk: chunkInfo, totalSize } = result;\n\n if (chunkInfo.type === 'end') {\n finished = true;\n break;\n }\n\n // Handle dictionary reset\n if (chunkInfo.dictReset) {\n decoder.resetDictionary();\n }\n\n const dataOffset = offset + chunkInfo.headerSize;\n\n if (chunkInfo.type === 'uncompressed') {\n const uncompData = input.slice(dataOffset, dataOffset + chunkInfo.uncompSize);\n this.push(uncompData);\n\n // Feed uncompressed data to dictionary for subsequent LZMA chunks\n decoder.feedUncompressed(uncompData);\n } else {\n // LZMA compressed chunk\n\n // Apply new properties if present\n if (chunkInfo.newProps) {\n const { lc, lp, pb } = chunkInfo.newProps;\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 // Reset probabilities if state reset\n if (chunkInfo.stateReset) {\n decoder.resetProbabilities();\n }\n\n // Determine solid mode - preserve dictionary if not resetting state or if only resetting state (not dict)\n const useSolid = !chunkInfo.stateReset || (chunkInfo.stateReset && !chunkInfo.dictReset);\n\n const compData = input.slice(dataOffset, dataOffset + chunkInfo.compSize);\n const decoded = decoder.decode(compData, 0, chunkInfo.uncompSize, useSolid);\n this.push(decoded);\n }\n\n offset += totalSize;\n }\n\n callback(null);\n } catch (err) {\n callback(err as Error);\n }\n },\n\n flush: function (this: InstanceType<typeof Transform>, callback: (err?: Error | null) => void) {\n if (pending && pending.length > 0 && !finished) {\n callback(new Error('Truncated LZMA2 stream'));\n } else {\n callback(null);\n }\n },\n });\n}\n\n/**\n * Create an LZMA1 decoder Transform stream\n *\n * Note: LZMA1 has no chunk boundaries, so this requires knowing the\n * uncompressed size upfront. The stream buffers all input, then\n * decompresses when complete.\n *\n * For true streaming, use LZMA2 which has built-in chunking.\n *\n * @param properties - 5-byte LZMA properties\n * @param unpackSize - Expected uncompressed size\n * @returns Transform stream that decompresses LZMA1 data\n */\nexport function createLzmaDecoder(properties: Buffer | Uint8Array, unpackSize: number): InstanceType<typeof Transform> {\n const decoder = new LzmaDecoder();\n decoder.setDecoderProperties(properties);\n\n const chunks: Buffer[] = [];\n\n return new Transform({\n transform: function (this: InstanceType<typeof Transform>, chunk: Buffer, _encoding: string, callback: (err?: Error | null) => void) {\n chunks.push(chunk);\n callback(null);\n },\n\n flush: function (this: InstanceType<typeof Transform>, callback: (err?: Error | null) => void) {\n try {\n const input = Buffer.concat(chunks);\n const output = decoder.decode(input, 0, unpackSize, false);\n this.push(output);\n callback(null);\n } catch (err) {\n callback(err as Error);\n }\n },\n });\n}\n"],"names":["Transform","hasCompleteChunk","LzmaDecoder","parseLzma2DictionarySize","createLzma2Decoder","properties","length","Error","dictSize","decoder","setDictionarySize","propsSet","pending","finished","transform","chunk","_encoding","callback","input","Buffer","concat","offset","result","success","slice","chunkInfo","totalSize","type","dictReset","resetDictionary","dataOffset","headerSize","uncompData","uncompSize","push","feedUncompressed","newProps","lc","lp","pb","setLcLpPb","stateReset","resetProbabilities","useSolid","compData","compSize","decoded","decode","err","flush","createLzmaDecoder","unpackSize","setDecoderProperties","chunks","output"],"mappings":"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"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Synchronous LZMA2 Decoder
|
|
3
|
-
*
|
|
4
|
-
* LZMA2 is a container format that wraps LZMA chunks with framing.
|
|
5
|
-
* Decodes LZMA2 data from a buffer.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Synchronous LZMA2 decoder
|
|
9
|
-
*/
|
|
10
|
-
export declare class Lzma2Decoder {
|
|
11
|
-
private lzmaDecoder;
|
|
12
|
-
private dictionarySize;
|
|
13
|
-
private propsSet;
|
|
14
|
-
constructor(properties: Buffer | Uint8Array);
|
|
15
|
-
/**
|
|
16
|
-
* Decode LZMA2 data
|
|
17
|
-
* @param input - LZMA2 compressed data
|
|
18
|
-
* @param unpackSize - Expected output size (optional, for pre-allocation)
|
|
19
|
-
* @returns Decompressed data
|
|
20
|
-
*/
|
|
21
|
-
decode(input: Buffer, unpackSize?: number): Buffer;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Decode LZMA2 data synchronously
|
|
25
|
-
* @param input - LZMA2 compressed data
|
|
26
|
-
* @param properties - 1-byte properties (dictionary size)
|
|
27
|
-
* @param unpackSize - Expected output size (optional)
|
|
28
|
-
* @returns Decompressed data
|
|
29
|
-
*/
|
|
30
|
-
export declare function decodeLzma2(input: Buffer, properties: Buffer | Uint8Array, unpackSize?: number): Buffer;
|