xz-compat 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +42 -0
- package/README.md +248 -0
- package/dist/cjs/compat.d.cts +1 -0
- package/dist/cjs/compat.d.ts +1 -0
- package/dist/cjs/compat.js +23 -0
- package/dist/cjs/compat.js.map +1 -0
- package/dist/cjs/filters/bcj/Bcj.d.cts +16 -0
- package/dist/cjs/filters/bcj/Bcj.d.ts +16 -0
- package/dist/cjs/filters/bcj/Bcj.js +192 -0
- package/dist/cjs/filters/bcj/Bcj.js.map +1 -0
- package/dist/cjs/filters/bcj/BcjArm.d.cts +16 -0
- package/dist/cjs/filters/bcj/BcjArm.d.ts +16 -0
- package/dist/cjs/filters/bcj/BcjArm.js +122 -0
- package/dist/cjs/filters/bcj/BcjArm.js.map +1 -0
- package/dist/cjs/filters/bcj/BcjArm64.d.cts +21 -0
- package/dist/cjs/filters/bcj/BcjArm64.d.ts +21 -0
- package/dist/cjs/filters/bcj/BcjArm64.js +65 -0
- package/dist/cjs/filters/bcj/BcjArm64.js.map +1 -0
- package/dist/cjs/filters/bcj/BcjArmt.d.cts +19 -0
- package/dist/cjs/filters/bcj/BcjArmt.d.ts +19 -0
- package/dist/cjs/filters/bcj/BcjArmt.js +76 -0
- package/dist/cjs/filters/bcj/BcjArmt.js.map +1 -0
- package/dist/cjs/filters/bcj/BcjIa64.d.cts +15 -0
- package/dist/cjs/filters/bcj/BcjIa64.d.ts +15 -0
- package/dist/cjs/filters/bcj/BcjIa64.js +141 -0
- package/dist/cjs/filters/bcj/BcjIa64.js.map +1 -0
- package/dist/cjs/filters/bcj/BcjPpc.d.cts +20 -0
- package/dist/cjs/filters/bcj/BcjPpc.d.ts +20 -0
- package/dist/cjs/filters/bcj/BcjPpc.js +64 -0
- package/dist/cjs/filters/bcj/BcjPpc.js.map +1 -0
- package/dist/cjs/filters/bcj/BcjSparc.d.cts +19 -0
- package/dist/cjs/filters/bcj/BcjSparc.d.ts +19 -0
- package/dist/cjs/filters/bcj/BcjSparc.js +69 -0
- package/dist/cjs/filters/bcj/BcjSparc.js.map +1 -0
- package/dist/cjs/filters/delta/Delta.d.cts +16 -0
- package/dist/cjs/filters/delta/Delta.d.ts +16 -0
- package/dist/cjs/filters/delta/Delta.js +74 -0
- package/dist/cjs/filters/delta/Delta.js.map +1 -0
- package/dist/cjs/filters/index.d.cts +8 -0
- package/dist/cjs/filters/index.d.ts +8 -0
- package/dist/cjs/filters/index.js +27 -0
- package/dist/cjs/filters/index.js.map +1 -0
- package/dist/cjs/index.d.cts +4 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +58 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lzma/Lzma2ChunkParser.d.cts +73 -0
- package/dist/cjs/lzma/Lzma2ChunkParser.d.ts +73 -0
- package/dist/cjs/lzma/Lzma2ChunkParser.js +148 -0
- package/dist/cjs/lzma/Lzma2ChunkParser.js.map +1 -0
- package/dist/cjs/lzma/index.d.cts +31 -0
- package/dist/cjs/lzma/index.d.ts +31 -0
- package/dist/cjs/lzma/index.js +83 -0
- package/dist/cjs/lzma/index.js.map +1 -0
- package/dist/cjs/lzma/stream/transforms.d.cts +46 -0
- package/dist/cjs/lzma/stream/transforms.d.ts +46 -0
- package/dist/cjs/lzma/stream/transforms.js +193 -0
- package/dist/cjs/lzma/stream/transforms.js.map +1 -0
- package/dist/cjs/lzma/sync/Lzma2Decoder.d.cts +63 -0
- package/dist/cjs/lzma/sync/Lzma2Decoder.d.ts +63 -0
- package/dist/cjs/lzma/sync/Lzma2Decoder.js +231 -0
- package/dist/cjs/lzma/sync/Lzma2Decoder.js.map +1 -0
- package/dist/cjs/lzma/sync/LzmaDecoder.d.cts +97 -0
- package/dist/cjs/lzma/sync/LzmaDecoder.d.ts +97 -0
- package/dist/cjs/lzma/sync/LzmaDecoder.js +582 -0
- package/dist/cjs/lzma/sync/LzmaDecoder.js.map +1 -0
- package/dist/cjs/lzma/sync/RangeDecoder.d.cts +69 -0
- package/dist/cjs/lzma/sync/RangeDecoder.d.ts +69 -0
- package/dist/cjs/lzma/sync/RangeDecoder.js +162 -0
- package/dist/cjs/lzma/sync/RangeDecoder.js.map +1 -0
- package/dist/cjs/lzma/types.d.cts +117 -0
- package/dist/cjs/lzma/types.d.ts +117 -0
- package/dist/cjs/lzma/types.js +264 -0
- package/dist/cjs/lzma/types.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/utils/createBufferingDecoder.d.cts +10 -0
- package/dist/cjs/utils/createBufferingDecoder.d.ts +10 -0
- package/dist/cjs/utils/createBufferingDecoder.js +41 -0
- package/dist/cjs/utils/createBufferingDecoder.js.map +1 -0
- package/dist/cjs/xz/Decoder.d.cts +21 -0
- package/dist/cjs/xz/Decoder.d.ts +21 -0
- package/dist/cjs/xz/Decoder.js +325 -0
- package/dist/cjs/xz/Decoder.js.map +1 -0
- package/dist/esm/compat.d.ts +1 -0
- package/dist/esm/compat.js +7 -0
- package/dist/esm/compat.js.map +1 -0
- package/dist/esm/filters/bcj/Bcj.d.ts +16 -0
- package/dist/esm/filters/bcj/Bcj.js +184 -0
- package/dist/esm/filters/bcj/Bcj.js.map +1 -0
- package/dist/esm/filters/bcj/BcjArm.d.ts +16 -0
- package/dist/esm/filters/bcj/BcjArm.js +114 -0
- package/dist/esm/filters/bcj/BcjArm.js.map +1 -0
- package/dist/esm/filters/bcj/BcjArm64.d.ts +21 -0
- package/dist/esm/filters/bcj/BcjArm64.js +57 -0
- package/dist/esm/filters/bcj/BcjArm64.js.map +1 -0
- package/dist/esm/filters/bcj/BcjArmt.d.ts +19 -0
- package/dist/esm/filters/bcj/BcjArmt.js +66 -0
- package/dist/esm/filters/bcj/BcjArmt.js.map +1 -0
- package/dist/esm/filters/bcj/BcjIa64.d.ts +15 -0
- package/dist/esm/filters/bcj/BcjIa64.js +127 -0
- package/dist/esm/filters/bcj/BcjIa64.js.map +1 -0
- package/dist/esm/filters/bcj/BcjPpc.d.ts +20 -0
- package/dist/esm/filters/bcj/BcjPpc.js +55 -0
- package/dist/esm/filters/bcj/BcjPpc.js.map +1 -0
- package/dist/esm/filters/bcj/BcjSparc.d.ts +19 -0
- package/dist/esm/filters/bcj/BcjSparc.js +59 -0
- package/dist/esm/filters/bcj/BcjSparc.js.map +1 -0
- package/dist/esm/filters/delta/Delta.d.ts +16 -0
- package/dist/esm/filters/delta/Delta.js +66 -0
- package/dist/esm/filters/delta/Delta.js.map +1 -0
- package/dist/esm/filters/index.d.ts +8 -0
- package/dist/esm/filters/index.js +9 -0
- package/dist/esm/filters/index.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lzma/Lzma2ChunkParser.d.ts +73 -0
- package/dist/esm/lzma/Lzma2ChunkParser.js +137 -0
- package/dist/esm/lzma/Lzma2ChunkParser.js.map +1 -0
- package/dist/esm/lzma/index.d.ts +31 -0
- package/dist/esm/lzma/index.js +44 -0
- package/dist/esm/lzma/index.js.map +1 -0
- package/dist/esm/lzma/stream/transforms.d.ts +46 -0
- package/dist/esm/lzma/stream/transforms.js +190 -0
- package/dist/esm/lzma/stream/transforms.js.map +1 -0
- package/dist/esm/lzma/sync/Lzma2Decoder.d.ts +63 -0
- package/dist/esm/lzma/sync/Lzma2Decoder.js +211 -0
- package/dist/esm/lzma/sync/Lzma2Decoder.js.map +1 -0
- package/dist/esm/lzma/sync/LzmaDecoder.d.ts +97 -0
- package/dist/esm/lzma/sync/LzmaDecoder.js +545 -0
- package/dist/esm/lzma/sync/LzmaDecoder.js.map +1 -0
- package/dist/esm/lzma/sync/RangeDecoder.d.ts +69 -0
- package/dist/esm/lzma/sync/RangeDecoder.js +132 -0
- package/dist/esm/lzma/sync/RangeDecoder.js.map +1 -0
- package/dist/esm/lzma/types.d.ts +117 -0
- package/dist/esm/lzma/types.js +154 -0
- package/dist/esm/lzma/types.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/utils/createBufferingDecoder.d.ts +10 -0
- package/dist/esm/utils/createBufferingDecoder.js +30 -0
- package/dist/esm/utils/createBufferingDecoder.js.map +1 -0
- package/dist/esm/xz/Decoder.d.ts +21 -0
- package/dist/esm/xz/Decoder.js +313 -0
- package/dist/esm/xz/Decoder.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
import { type OutputSink } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Synchronous LZMA2 decoder
|
|
10
|
+
*/
|
|
11
|
+
export declare class Lzma2Decoder {
|
|
12
|
+
private lzmaDecoder;
|
|
13
|
+
private dictionarySize;
|
|
14
|
+
private propsSet;
|
|
15
|
+
constructor(properties: Buffer | Uint8Array, outputSink?: OutputSink);
|
|
16
|
+
/**
|
|
17
|
+
* Reset the dictionary (for stream boundaries)
|
|
18
|
+
*/
|
|
19
|
+
resetDictionary(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Reset all probability models (for stream boundaries)
|
|
22
|
+
*/
|
|
23
|
+
resetProbabilities(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Set LZMA properties
|
|
26
|
+
*/
|
|
27
|
+
setLcLpPb(lc: number, lp: number, pb: number): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Feed uncompressed data to the dictionary (for subsequent LZMA chunks)
|
|
30
|
+
*/
|
|
31
|
+
feedUncompressed(data: Buffer): void;
|
|
32
|
+
/**
|
|
33
|
+
* Decode raw LZMA data (used internally for LZMA2 chunks)
|
|
34
|
+
* @param input - LZMA compressed data
|
|
35
|
+
* @param offset - Input offset
|
|
36
|
+
* @param outSize - Expected output size
|
|
37
|
+
* @param solid - Use solid mode
|
|
38
|
+
* @returns Decompressed data
|
|
39
|
+
*/
|
|
40
|
+
decodeLzmaData(input: Buffer, offset: number, outSize: number, solid?: boolean): Buffer;
|
|
41
|
+
/**
|
|
42
|
+
* Decode LZMA2 data with streaming output
|
|
43
|
+
* @param input - LZMA2 compressed data
|
|
44
|
+
* @returns Total number of bytes written to sink
|
|
45
|
+
*/
|
|
46
|
+
decodeWithSink(input: Buffer): number;
|
|
47
|
+
/**
|
|
48
|
+
* Decode LZMA2 data
|
|
49
|
+
* @param input - LZMA2 compressed data
|
|
50
|
+
* @param unpackSize - Expected output size (optional, for pre-allocation)
|
|
51
|
+
* @returns Decompressed data
|
|
52
|
+
*/
|
|
53
|
+
decode(input: Buffer, unpackSize?: number): Buffer;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Decode LZMA2 data synchronously
|
|
57
|
+
* @param input - LZMA2 compressed data
|
|
58
|
+
* @param properties - 1-byte properties (dictionary size)
|
|
59
|
+
* @param unpackSize - Expected output size (optional, autodetects if not provided)
|
|
60
|
+
* @param outputSink - Optional output sink for zero-copy decoding (returns bytes written)
|
|
61
|
+
* @returns Decompressed data (or bytes written if outputSink provided)
|
|
62
|
+
*/
|
|
63
|
+
export declare function decodeLzma2(input: Buffer, properties: Buffer | Uint8Array, unpackSize?: number, outputSink?: OutputSink): Buffer | number;
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
import { type OutputSink } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Synchronous LZMA2 decoder
|
|
10
|
+
*/
|
|
11
|
+
export declare class Lzma2Decoder {
|
|
12
|
+
private lzmaDecoder;
|
|
13
|
+
private dictionarySize;
|
|
14
|
+
private propsSet;
|
|
15
|
+
constructor(properties: Buffer | Uint8Array, outputSink?: OutputSink);
|
|
16
|
+
/**
|
|
17
|
+
* Reset the dictionary (for stream boundaries)
|
|
18
|
+
*/
|
|
19
|
+
resetDictionary(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Reset all probability models (for stream boundaries)
|
|
22
|
+
*/
|
|
23
|
+
resetProbabilities(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Set LZMA properties
|
|
26
|
+
*/
|
|
27
|
+
setLcLpPb(lc: number, lp: number, pb: number): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Feed uncompressed data to the dictionary (for subsequent LZMA chunks)
|
|
30
|
+
*/
|
|
31
|
+
feedUncompressed(data: Buffer): void;
|
|
32
|
+
/**
|
|
33
|
+
* Decode raw LZMA data (used internally for LZMA2 chunks)
|
|
34
|
+
* @param input - LZMA compressed data
|
|
35
|
+
* @param offset - Input offset
|
|
36
|
+
* @param outSize - Expected output size
|
|
37
|
+
* @param solid - Use solid mode
|
|
38
|
+
* @returns Decompressed data
|
|
39
|
+
*/
|
|
40
|
+
decodeLzmaData(input: Buffer, offset: number, outSize: number, solid?: boolean): Buffer;
|
|
41
|
+
/**
|
|
42
|
+
* Decode LZMA2 data with streaming output
|
|
43
|
+
* @param input - LZMA2 compressed data
|
|
44
|
+
* @returns Total number of bytes written to sink
|
|
45
|
+
*/
|
|
46
|
+
decodeWithSink(input: Buffer): number;
|
|
47
|
+
/**
|
|
48
|
+
* Decode LZMA2 data
|
|
49
|
+
* @param input - LZMA2 compressed data
|
|
50
|
+
* @param unpackSize - Expected output size (optional, for pre-allocation)
|
|
51
|
+
* @returns Decompressed data
|
|
52
|
+
*/
|
|
53
|
+
decode(input: Buffer, unpackSize?: number): Buffer;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Decode LZMA2 data synchronously
|
|
57
|
+
* @param input - LZMA2 compressed data
|
|
58
|
+
* @param properties - 1-byte properties (dictionary size)
|
|
59
|
+
* @param unpackSize - Expected output size (optional, autodetects if not provided)
|
|
60
|
+
* @param outputSink - Optional output sink for zero-copy decoding (returns bytes written)
|
|
61
|
+
* @returns Decompressed data (or bytes written if outputSink provided)
|
|
62
|
+
*/
|
|
63
|
+
export declare function decodeLzma2(input: Buffer, properties: Buffer | Uint8Array, unpackSize?: number, outputSink?: OutputSink): Buffer | number;
|
|
@@ -0,0 +1,231 @@
|
|
|
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
|
+
*/ "use strict";
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
function _export(target, all) {
|
|
11
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
_export(exports, {
|
|
17
|
+
get Lzma2Decoder () {
|
|
18
|
+
return Lzma2Decoder;
|
|
19
|
+
},
|
|
20
|
+
get decodeLzma2 () {
|
|
21
|
+
return decodeLzma2;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var _extractbaseiterator = require("extract-base-iterator");
|
|
25
|
+
var _Lzma2ChunkParserts = require("../Lzma2ChunkParser.js");
|
|
26
|
+
var _typests = require("../types.js");
|
|
27
|
+
var _LzmaDecoderts = require("./LzmaDecoder.js");
|
|
28
|
+
function _class_call_check(instance, Constructor) {
|
|
29
|
+
if (!(instance instanceof Constructor)) {
|
|
30
|
+
throw new TypeError("Cannot call a class as a function");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
var Lzma2Decoder = /*#__PURE__*/ function() {
|
|
34
|
+
"use strict";
|
|
35
|
+
function Lzma2Decoder(properties, outputSink) {
|
|
36
|
+
_class_call_check(this, Lzma2Decoder);
|
|
37
|
+
if (!properties || properties.length < 1) {
|
|
38
|
+
throw new Error('LZMA2 requires properties byte');
|
|
39
|
+
}
|
|
40
|
+
this.dictionarySize = (0, _typests.parseLzma2DictionarySize)(properties[0]);
|
|
41
|
+
this.lzmaDecoder = new _LzmaDecoderts.LzmaDecoder(outputSink);
|
|
42
|
+
this.lzmaDecoder.setDictionarySize(this.dictionarySize);
|
|
43
|
+
this.propsSet = false;
|
|
44
|
+
}
|
|
45
|
+
var _proto = Lzma2Decoder.prototype;
|
|
46
|
+
/**
|
|
47
|
+
* Reset the dictionary (for stream boundaries)
|
|
48
|
+
*/ _proto.resetDictionary = function resetDictionary() {
|
|
49
|
+
this.lzmaDecoder.resetDictionary();
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Reset all probability models (for stream boundaries)
|
|
53
|
+
*/ _proto.resetProbabilities = function resetProbabilities() {
|
|
54
|
+
this.lzmaDecoder.resetProbabilities();
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Set LZMA properties
|
|
58
|
+
*/ _proto.setLcLpPb = function setLcLpPb(lc, lp, pb) {
|
|
59
|
+
return this.lzmaDecoder.setLcLpPb(lc, lp, pb);
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Feed uncompressed data to the dictionary (for subsequent LZMA chunks)
|
|
63
|
+
*/ _proto.feedUncompressed = function feedUncompressed(data) {
|
|
64
|
+
this.lzmaDecoder.feedUncompressed(data);
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Decode raw LZMA data (used internally for LZMA2 chunks)
|
|
68
|
+
* @param input - LZMA compressed data
|
|
69
|
+
* @param offset - Input offset
|
|
70
|
+
* @param outSize - Expected output size
|
|
71
|
+
* @param solid - Use solid mode
|
|
72
|
+
* @returns Decompressed data
|
|
73
|
+
*/ _proto.decodeLzmaData = function decodeLzmaData(input, offset, outSize) {
|
|
74
|
+
var solid = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
|
|
75
|
+
return this.lzmaDecoder.decode(input, offset, outSize, solid);
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Decode LZMA2 data with streaming output
|
|
79
|
+
* @param input - LZMA2 compressed data
|
|
80
|
+
* @returns Total number of bytes written to sink
|
|
81
|
+
*/ _proto.decodeWithSink = function decodeWithSink(input) {
|
|
82
|
+
var totalBytes = 0;
|
|
83
|
+
var offset = 0;
|
|
84
|
+
while(offset < input.length){
|
|
85
|
+
var result = (0, _Lzma2ChunkParserts.parseLzma2ChunkHeader)(input, offset);
|
|
86
|
+
if (!result.success) {
|
|
87
|
+
throw new Error('Truncated LZMA2 chunk header');
|
|
88
|
+
}
|
|
89
|
+
var chunk = result.chunk;
|
|
90
|
+
if (chunk.type === 'end') {
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
// Validate we have enough data for the chunk
|
|
94
|
+
var dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;
|
|
95
|
+
if (offset + chunk.headerSize + dataSize > input.length) {
|
|
96
|
+
throw new Error("Truncated LZMA2 ".concat(chunk.type, " data"));
|
|
97
|
+
}
|
|
98
|
+
// Handle dictionary reset
|
|
99
|
+
if (chunk.dictReset) {
|
|
100
|
+
this.lzmaDecoder.resetDictionary();
|
|
101
|
+
}
|
|
102
|
+
var dataOffset = offset + chunk.headerSize;
|
|
103
|
+
if (chunk.type === 'uncompressed') {
|
|
104
|
+
var uncompData = input.slice(dataOffset, dataOffset + chunk.uncompSize);
|
|
105
|
+
// Feed uncompressed data to dictionary so subsequent LZMA chunks can reference it
|
|
106
|
+
this.lzmaDecoder.feedUncompressed(uncompData);
|
|
107
|
+
totalBytes += uncompData.length;
|
|
108
|
+
offset = dataOffset + chunk.uncompSize;
|
|
109
|
+
} else {
|
|
110
|
+
// LZMA compressed chunk
|
|
111
|
+
// Apply new properties if present
|
|
112
|
+
if (chunk.newProps) {
|
|
113
|
+
var _chunk_newProps = chunk.newProps, lc = _chunk_newProps.lc, lp = _chunk_newProps.lp, pb = _chunk_newProps.pb;
|
|
114
|
+
if (!this.lzmaDecoder.setLcLpPb(lc, lp, pb)) {
|
|
115
|
+
throw new Error("Invalid LZMA properties: lc=".concat(lc, " lp=").concat(lp, " pb=").concat(pb));
|
|
116
|
+
}
|
|
117
|
+
this.propsSet = true;
|
|
118
|
+
}
|
|
119
|
+
if (!this.propsSet) {
|
|
120
|
+
throw new Error('LZMA chunk without properties');
|
|
121
|
+
}
|
|
122
|
+
// Reset probabilities if state reset
|
|
123
|
+
if (chunk.stateReset) {
|
|
124
|
+
this.lzmaDecoder.resetProbabilities();
|
|
125
|
+
}
|
|
126
|
+
// Determine solid mode
|
|
127
|
+
var useSolid = !chunk.stateReset || chunk.stateReset && !chunk.dictReset;
|
|
128
|
+
// Decode LZMA chunk directly to sink
|
|
129
|
+
totalBytes += this.lzmaDecoder.decodeWithSink(input, dataOffset, chunk.uncompSize, useSolid);
|
|
130
|
+
offset = dataOffset + chunk.compSize;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Flush any remaining data in the OutWindow
|
|
134
|
+
this.lzmaDecoder.flushOutWindow();
|
|
135
|
+
return totalBytes;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Decode LZMA2 data
|
|
139
|
+
* @param input - LZMA2 compressed data
|
|
140
|
+
* @param unpackSize - Expected output size (optional, for pre-allocation)
|
|
141
|
+
* @returns Decompressed data
|
|
142
|
+
*/ _proto.decode = function decode(input, unpackSize) {
|
|
143
|
+
// Pre-allocate output buffer if size is known
|
|
144
|
+
var outputBuffer = null;
|
|
145
|
+
var outputPos = 0;
|
|
146
|
+
var outputChunks = [];
|
|
147
|
+
if (unpackSize && unpackSize > 0) {
|
|
148
|
+
outputBuffer = (0, _extractbaseiterator.allocBufferUnsafe)(unpackSize);
|
|
149
|
+
}
|
|
150
|
+
var offset = 0;
|
|
151
|
+
while(offset < input.length){
|
|
152
|
+
var result = (0, _Lzma2ChunkParserts.parseLzma2ChunkHeader)(input, offset);
|
|
153
|
+
if (!result.success) {
|
|
154
|
+
throw new Error('Truncated LZMA2 chunk header');
|
|
155
|
+
}
|
|
156
|
+
var chunk = result.chunk;
|
|
157
|
+
if (chunk.type === 'end') {
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
// Validate we have enough data for the chunk
|
|
161
|
+
var dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;
|
|
162
|
+
if (offset + chunk.headerSize + dataSize > input.length) {
|
|
163
|
+
throw new Error("Truncated LZMA2 ".concat(chunk.type, " data"));
|
|
164
|
+
}
|
|
165
|
+
// Handle dictionary reset
|
|
166
|
+
if (chunk.dictReset) {
|
|
167
|
+
this.lzmaDecoder.resetDictionary();
|
|
168
|
+
}
|
|
169
|
+
var dataOffset = offset + chunk.headerSize;
|
|
170
|
+
if (chunk.type === 'uncompressed') {
|
|
171
|
+
var uncompData = input.slice(dataOffset, dataOffset + chunk.uncompSize);
|
|
172
|
+
// Copy to output
|
|
173
|
+
if (outputBuffer) {
|
|
174
|
+
uncompData.copy(outputBuffer, outputPos);
|
|
175
|
+
outputPos += uncompData.length;
|
|
176
|
+
} else {
|
|
177
|
+
outputChunks.push(uncompData);
|
|
178
|
+
}
|
|
179
|
+
// Feed uncompressed data to dictionary so subsequent LZMA chunks can reference it
|
|
180
|
+
this.lzmaDecoder.feedUncompressed(uncompData);
|
|
181
|
+
offset = dataOffset + chunk.uncompSize;
|
|
182
|
+
} else {
|
|
183
|
+
// LZMA compressed chunk
|
|
184
|
+
// Apply new properties if present
|
|
185
|
+
if (chunk.newProps) {
|
|
186
|
+
var _chunk_newProps = chunk.newProps, lc = _chunk_newProps.lc, lp = _chunk_newProps.lp, pb = _chunk_newProps.pb;
|
|
187
|
+
if (!this.lzmaDecoder.setLcLpPb(lc, lp, pb)) {
|
|
188
|
+
throw new Error("Invalid LZMA properties: lc=".concat(lc, " lp=").concat(lp, " pb=").concat(pb));
|
|
189
|
+
}
|
|
190
|
+
this.propsSet = true;
|
|
191
|
+
}
|
|
192
|
+
if (!this.propsSet) {
|
|
193
|
+
throw new Error('LZMA chunk without properties');
|
|
194
|
+
}
|
|
195
|
+
// Reset probabilities if state reset
|
|
196
|
+
if (chunk.stateReset) {
|
|
197
|
+
this.lzmaDecoder.resetProbabilities();
|
|
198
|
+
}
|
|
199
|
+
// Determine solid mode - preserve dictionary if not resetting state or if only resetting state (not dict)
|
|
200
|
+
var useSolid = !chunk.stateReset || chunk.stateReset && !chunk.dictReset;
|
|
201
|
+
// Decode LZMA chunk
|
|
202
|
+
var chunkData = input.slice(dataOffset, dataOffset + chunk.compSize);
|
|
203
|
+
var decoded = this.lzmaDecoder.decode(chunkData, 0, chunk.uncompSize, useSolid);
|
|
204
|
+
// Copy to output
|
|
205
|
+
if (outputBuffer) {
|
|
206
|
+
decoded.copy(outputBuffer, outputPos);
|
|
207
|
+
outputPos += decoded.length;
|
|
208
|
+
} else {
|
|
209
|
+
outputChunks.push(decoded);
|
|
210
|
+
}
|
|
211
|
+
offset = dataOffset + chunk.compSize;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// Return pre-allocated buffer or concatenated chunks
|
|
215
|
+
if (outputBuffer) {
|
|
216
|
+
return outputPos < outputBuffer.length ? outputBuffer.slice(0, outputPos) : outputBuffer;
|
|
217
|
+
}
|
|
218
|
+
return Buffer.concat(outputChunks);
|
|
219
|
+
};
|
|
220
|
+
return Lzma2Decoder;
|
|
221
|
+
}();
|
|
222
|
+
function decodeLzma2(input, properties, unpackSize, outputSink) {
|
|
223
|
+
var decoder = new Lzma2Decoder(properties, outputSink);
|
|
224
|
+
if (outputSink) {
|
|
225
|
+
// Zero-copy mode: write to sink during decode
|
|
226
|
+
return decoder.decodeWithSink(input);
|
|
227
|
+
}
|
|
228
|
+
// Buffering mode: returns Buffer (zero-copy)
|
|
229
|
+
return decoder.decode(input, unpackSize);
|
|
230
|
+
}
|
|
231
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/lzma/sync/Lzma2Decoder.ts"],"sourcesContent":["/**\n * Synchronous LZMA2 Decoder\n *\n * LZMA2 is a container format that wraps LZMA chunks with framing.\n * Decodes LZMA2 data from a buffer.\n */\n\nimport { allocBufferUnsafe } from 'extract-base-iterator';\nimport { parseLzma2ChunkHeader } from '../Lzma2ChunkParser.ts';\nimport { type OutputSink, parseLzma2DictionarySize } from '../types.ts';\nimport { LzmaDecoder } from './LzmaDecoder.ts';\n\n/**\n * Synchronous LZMA2 decoder\n */\nexport class Lzma2Decoder {\n private lzmaDecoder: LzmaDecoder;\n private dictionarySize: number;\n private propsSet: boolean;\n\n constructor(properties: Buffer | Uint8Array, outputSink?: OutputSink) {\n if (!properties || properties.length < 1) {\n throw new Error('LZMA2 requires properties byte');\n }\n\n this.dictionarySize = parseLzma2DictionarySize(properties[0]);\n this.lzmaDecoder = new LzmaDecoder(outputSink);\n this.lzmaDecoder.setDictionarySize(this.dictionarySize);\n this.propsSet = false;\n }\n\n /**\n * Reset the dictionary (for stream boundaries)\n */\n resetDictionary(): void {\n this.lzmaDecoder.resetDictionary();\n }\n\n /**\n * Reset all probability models (for stream boundaries)\n */\n resetProbabilities(): void {\n this.lzmaDecoder.resetProbabilities();\n }\n\n /**\n * Set LZMA properties\n */\n setLcLpPb(lc: number, lp: number, pb: number): boolean {\n return this.lzmaDecoder.setLcLpPb(lc, lp, pb);\n }\n\n /**\n * Feed uncompressed data to the dictionary (for subsequent LZMA chunks)\n */\n feedUncompressed(data: Buffer): void {\n this.lzmaDecoder.feedUncompressed(data);\n }\n\n /**\n * Decode raw LZMA data (used internally for LZMA2 chunks)\n * @param input - LZMA compressed data\n * @param offset - Input offset\n * @param outSize - Expected output size\n * @param solid - Use solid mode\n * @returns Decompressed data\n */\n decodeLzmaData(input: Buffer, offset: number, outSize: number, solid = false): Buffer {\n return this.lzmaDecoder.decode(input, offset, outSize, solid);\n }\n\n /**\n * Decode LZMA2 data with streaming output\n * @param input - LZMA2 compressed data\n * @returns Total number of bytes written to sink\n */\n decodeWithSink(input: Buffer): number {\n let totalBytes = 0;\n let offset = 0;\n\n while (offset < input.length) {\n const result = parseLzma2ChunkHeader(input, offset);\n\n if (!result.success) {\n throw new Error('Truncated LZMA2 chunk header');\n }\n\n const chunk = result.chunk;\n\n if (chunk.type === 'end') {\n break;\n }\n\n // Validate we have enough data for the chunk\n const dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;\n if (offset + chunk.headerSize + dataSize > input.length) {\n throw new Error(`Truncated LZMA2 ${chunk.type} data`);\n }\n\n // Handle dictionary reset\n if (chunk.dictReset) {\n this.lzmaDecoder.resetDictionary();\n }\n\n const dataOffset = offset + chunk.headerSize;\n\n if (chunk.type === 'uncompressed') {\n const uncompData = input.slice(dataOffset, dataOffset + chunk.uncompSize);\n\n // Feed uncompressed data to dictionary so subsequent LZMA chunks can reference it\n this.lzmaDecoder.feedUncompressed(uncompData);\n\n totalBytes += uncompData.length;\n offset = dataOffset + chunk.uncompSize;\n } else {\n // LZMA compressed chunk\n\n // Apply new properties if present\n if (chunk.newProps) {\n const { lc, lp, pb } = chunk.newProps;\n if (!this.lzmaDecoder.setLcLpPb(lc, lp, pb)) {\n throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);\n }\n this.propsSet = true;\n }\n\n if (!this.propsSet) {\n throw new Error('LZMA chunk without properties');\n }\n\n // Reset probabilities if state reset\n if (chunk.stateReset) {\n this.lzmaDecoder.resetProbabilities();\n }\n\n // Determine solid mode\n const useSolid = !chunk.stateReset || (chunk.stateReset && !chunk.dictReset);\n\n // Decode LZMA chunk directly to sink\n totalBytes += this.lzmaDecoder.decodeWithSink(input, dataOffset, chunk.uncompSize, useSolid);\n\n offset = dataOffset + chunk.compSize;\n }\n }\n\n // Flush any remaining data in the OutWindow\n this.lzmaDecoder.flushOutWindow();\n\n return totalBytes;\n }\n\n /**\n * Decode LZMA2 data\n * @param input - LZMA2 compressed data\n * @param unpackSize - Expected output size (optional, for pre-allocation)\n * @returns Decompressed data\n */\n decode(input: Buffer, unpackSize?: number): Buffer {\n // Pre-allocate output buffer if size is known\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 while (offset < input.length) {\n const result = parseLzma2ChunkHeader(input, offset);\n\n if (!result.success) {\n throw new Error('Truncated LZMA2 chunk header');\n }\n\n const chunk = result.chunk;\n\n if (chunk.type === 'end') {\n break;\n }\n\n // Validate we have enough data for the chunk\n const dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;\n if (offset + chunk.headerSize + dataSize > input.length) {\n throw new Error(`Truncated LZMA2 ${chunk.type} data`);\n }\n\n // Handle dictionary reset\n if (chunk.dictReset) {\n this.lzmaDecoder.resetDictionary();\n }\n\n const dataOffset = offset + chunk.headerSize;\n\n if (chunk.type === 'uncompressed') {\n const uncompData = input.slice(dataOffset, dataOffset + chunk.uncompSize);\n\n // Copy to output\n if (outputBuffer) {\n uncompData.copy(outputBuffer, outputPos);\n outputPos += uncompData.length;\n } else {\n outputChunks.push(uncompData);\n }\n\n // Feed uncompressed data to dictionary so subsequent LZMA chunks can reference it\n this.lzmaDecoder.feedUncompressed(uncompData);\n\n offset = dataOffset + chunk.uncompSize;\n } else {\n // LZMA compressed chunk\n\n // Apply new properties if present\n if (chunk.newProps) {\n const { lc, lp, pb } = chunk.newProps;\n if (!this.lzmaDecoder.setLcLpPb(lc, lp, pb)) {\n throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);\n }\n this.propsSet = true;\n }\n\n if (!this.propsSet) {\n throw new Error('LZMA chunk without properties');\n }\n\n // Reset probabilities if state reset\n if (chunk.stateReset) {\n this.lzmaDecoder.resetProbabilities();\n }\n\n // Determine solid mode - preserve dictionary if not resetting state or if only resetting state (not dict)\n const useSolid = !chunk.stateReset || (chunk.stateReset && !chunk.dictReset);\n\n // Decode LZMA chunk\n const chunkData = input.slice(dataOffset, dataOffset + chunk.compSize);\n const decoded = this.lzmaDecoder.decode(chunkData, 0, chunk.uncompSize, useSolid);\n\n // Copy to output\n if (outputBuffer) {\n decoded.copy(outputBuffer, outputPos);\n outputPos += decoded.length;\n } else {\n outputChunks.push(decoded);\n }\n\n offset = dataOffset + chunk.compSize;\n }\n }\n\n // Return pre-allocated buffer or concatenated chunks\n if (outputBuffer) {\n return outputPos < outputBuffer.length ? outputBuffer.slice(0, outputPos) : outputBuffer;\n }\n return Buffer.concat(outputChunks);\n }\n}\n\n/**\n * Decode LZMA2 data synchronously\n * @param input - LZMA2 compressed data\n * @param properties - 1-byte properties (dictionary size)\n * @param unpackSize - Expected output size (optional, autodetects if not provided)\n * @param outputSink - Optional output sink for zero-copy decoding (returns bytes written)\n * @returns Decompressed data (or bytes written if outputSink provided)\n */\nexport function decodeLzma2(input: Buffer, properties: Buffer | Uint8Array, unpackSize?: number, outputSink?: OutputSink): Buffer | number {\n const decoder = new Lzma2Decoder(properties, outputSink);\n if (outputSink) {\n // Zero-copy mode: write to sink during decode\n return decoder.decodeWithSink(input);\n }\n // Buffering mode: returns Buffer (zero-copy)\n return decoder.decode(input, unpackSize);\n}\n"],"names":["Lzma2Decoder","decodeLzma2","properties","outputSink","length","Error","dictionarySize","parseLzma2DictionarySize","lzmaDecoder","LzmaDecoder","setDictionarySize","propsSet","resetDictionary","resetProbabilities","setLcLpPb","lc","lp","pb","feedUncompressed","data","decodeLzmaData","input","offset","outSize","solid","decode","decodeWithSink","totalBytes","result","parseLzma2ChunkHeader","success","chunk","type","dataSize","uncompSize","compSize","headerSize","dictReset","dataOffset","uncompData","slice","newProps","stateReset","useSolid","flushOutWindow","unpackSize","outputBuffer","outputPos","outputChunks","allocBufferUnsafe","copy","push","chunkData","decoded","Buffer","concat","decoder"],"mappings":"AAAA;;;;;CAKC;;;;;;;;;;;QAUYA;eAAAA;;QA2PGC;eAAAA;;;mCAnQkB;kCACI;uBACoB;6BAC9B;;;;;;AAKrB,IAAA,AAAMD,6BAAN;;aAAMA,aAKCE,UAA+B,EAAEC,UAAuB;gCALzDH;QAMT,IAAI,CAACE,cAAcA,WAAWE,MAAM,GAAG,GAAG;YACxC,MAAM,IAAIC,MAAM;QAClB;QAEA,IAAI,CAACC,cAAc,GAAGC,IAAAA,iCAAwB,EAACL,UAAU,CAAC,EAAE;QAC5D,IAAI,CAACM,WAAW,GAAG,IAAIC,0BAAW,CAACN;QACnC,IAAI,CAACK,WAAW,CAACE,iBAAiB,CAAC,IAAI,CAACJ,cAAc;QACtD,IAAI,CAACK,QAAQ,GAAG;;iBAbPX;IAgBX;;GAEC,GACDY,OAAAA,eAEC,GAFDA,SAAAA;QACE,IAAI,CAACJ,WAAW,CAACI,eAAe;IAClC;IAEA;;GAEC,GACDC,OAAAA,kBAEC,GAFDA,SAAAA;QACE,IAAI,CAACL,WAAW,CAACK,kBAAkB;IACrC;IAEA;;GAEC,GACDC,OAAAA,SAEC,GAFDA,SAAAA,UAAUC,EAAU,EAAEC,EAAU,EAAEC,EAAU;QAC1C,OAAO,IAAI,CAACT,WAAW,CAACM,SAAS,CAACC,IAAIC,IAAIC;IAC5C;IAEA;;GAEC,GACDC,OAAAA,gBAEC,GAFDA,SAAAA,iBAAiBC,IAAY;QAC3B,IAAI,CAACX,WAAW,CAACU,gBAAgB,CAACC;IACpC;IAEA;;;;;;;GAOC,GACDC,OAAAA,cAEC,GAFDA,SAAAA,eAAeC,KAAa,EAAEC,MAAc,EAAEC,OAAe;YAAEC,QAAAA,iEAAQ;QACrE,OAAO,IAAI,CAAChB,WAAW,CAACiB,MAAM,CAACJ,OAAOC,QAAQC,SAASC;I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AW,CAACK,kBAAkB;gBACrC;gBAEA,0GAA0G;gBAC1G,IAAM8B,WAAW,CAACZ,MAAMW,UAAU,IAAKX,MAAMW,UAAU,IAAI,CAACX,MAAMM,SAAS;gBAE3E,oBAAoB;gBACpB,IAAMe,YAAY/B,MAAMmB,KAAK,CAACF,YAAYA,aAAaP,MAAMI,QAAQ;gBACrE,IAAMkB,UAAU,IAAI,CAAC7C,WAAW,CAACiB,MAAM,CAAC2B,WAAW,GAAGrB,MAAMG,UAAU,EAAES;gBAExE,iBAAiB;gBACjB,IAAIG,cAAc;oBAChBO,QAAQH,IAAI,CAACJ,cAAcC;oBAC3BA,aAAaM,QAAQjD,MAAM;gBAC7B,OAAO;oBACL4C,aAAaG,IAAI,CAACE;gBACpB;gBAEA/B,SAASgB,aAAaP,MAAMI,QAAQ;YACtC;QACF;QAEA,qDAAqD;QACrD,IAAIW,cAAc;YAChB,OAAOC,YAAYD,aAAa1C,MAAM,GAAG0C,aAAaN,KAAK,CAAC,GAAGO,aAAaD;QAC9E;QACA,OAAOQ,OAAOC,MAAM,CAACP;IACvB;WAhPWhD;;AA2PN,SAASC,YAAYoB,KAAa,EAAEnB,UAA+B,EAAE2C,UAAmB,EAAE1C,UAAuB;IACtH,IAAMqD,UAAU,IAAIxD,aAAaE,YAAYC;IAC7C,IAAIA,YAAY;QACd,8CAA8C;QAC9C,OAAOqD,QAAQ9B,cAAc,CAACL;IAChC;IACA,6CAA6C;IAC7C,OAAOmC,QAAQ/B,MAAM,CAACJ,OAAOwB;AAC/B"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synchronous LZMA1 Decoder
|
|
3
|
+
*
|
|
4
|
+
* Decodes LZMA1 compressed data from a buffer.
|
|
5
|
+
* All operations are synchronous.
|
|
6
|
+
*/
|
|
7
|
+
import { type OutputSink } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Synchronous LZMA1 decoder
|
|
10
|
+
*/
|
|
11
|
+
export declare class LzmaDecoder {
|
|
12
|
+
private outWindow;
|
|
13
|
+
private rangeDecoder;
|
|
14
|
+
private isMatchDecoders;
|
|
15
|
+
private isRepDecoders;
|
|
16
|
+
private isRepG0Decoders;
|
|
17
|
+
private isRepG1Decoders;
|
|
18
|
+
private isRepG2Decoders;
|
|
19
|
+
private isRep0LongDecoders;
|
|
20
|
+
private posSlotDecoder;
|
|
21
|
+
private posDecoders;
|
|
22
|
+
private posAlignDecoder;
|
|
23
|
+
private lenDecoder;
|
|
24
|
+
private repLenDecoder;
|
|
25
|
+
private literalDecoder;
|
|
26
|
+
private dictionarySize;
|
|
27
|
+
private dictionarySizeCheck;
|
|
28
|
+
private posStateMask;
|
|
29
|
+
private state;
|
|
30
|
+
private rep0;
|
|
31
|
+
private rep1;
|
|
32
|
+
private rep2;
|
|
33
|
+
private rep3;
|
|
34
|
+
private prevByte;
|
|
35
|
+
private totalPos;
|
|
36
|
+
constructor(outputSink?: OutputSink);
|
|
37
|
+
/**
|
|
38
|
+
* Set dictionary size
|
|
39
|
+
*/
|
|
40
|
+
setDictionarySize(dictionarySize: number): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Set lc, lp, pb properties
|
|
43
|
+
*/
|
|
44
|
+
setLcLpPb(lc: number, lp: number, pb: number): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Set decoder properties from 5-byte buffer
|
|
47
|
+
*/
|
|
48
|
+
setDecoderProperties(properties: Buffer | Uint8Array): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Initialize probability tables
|
|
51
|
+
*/
|
|
52
|
+
private initProbabilities;
|
|
53
|
+
/**
|
|
54
|
+
* Reset probabilities only (for LZMA2 state reset)
|
|
55
|
+
*/
|
|
56
|
+
resetProbabilities(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Reset dictionary position (for LZMA2 dictionary reset)
|
|
59
|
+
*/
|
|
60
|
+
resetDictionary(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Feed uncompressed data into the dictionary (for LZMA2 uncompressed chunks)
|
|
63
|
+
* This updates the sliding window so subsequent LZMA chunks can reference this data.
|
|
64
|
+
*/
|
|
65
|
+
feedUncompressed(data: Buffer): void;
|
|
66
|
+
/**
|
|
67
|
+
* Flush any remaining data in the OutWindow to the sink
|
|
68
|
+
*/
|
|
69
|
+
flushOutWindow(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Decode LZMA data with streaming output (no buffer accumulation)
|
|
72
|
+
* @param input - Compressed input buffer
|
|
73
|
+
* @param inputOffset - Offset into input buffer
|
|
74
|
+
* @param outSize - Expected output size
|
|
75
|
+
* @param solid - If true, preserve state from previous decode
|
|
76
|
+
* @returns Number of bytes written to sink
|
|
77
|
+
*/
|
|
78
|
+
decodeWithSink(input: Buffer, inputOffset: number, outSize: number, solid?: boolean): number;
|
|
79
|
+
/**
|
|
80
|
+
* Decode LZMA data
|
|
81
|
+
* @param input - Compressed input buffer
|
|
82
|
+
* @param inputOffset - Offset into input buffer
|
|
83
|
+
* @param outSize - Expected output size
|
|
84
|
+
* @param solid - If true, preserve state from previous decode
|
|
85
|
+
* @returns Decompressed data
|
|
86
|
+
*/
|
|
87
|
+
decode(input: Buffer, inputOffset: number, outSize: number, solid?: boolean): Buffer;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Decode LZMA1 data synchronously
|
|
91
|
+
* @param input - Compressed data (without 5-byte properties header)
|
|
92
|
+
* @param properties - 5-byte LZMA properties
|
|
93
|
+
* @param outSize - Expected output size
|
|
94
|
+
* @param outputSink - Optional output sink for zero-copy decoding (returns bytes written)
|
|
95
|
+
* @returns Decompressed data (or bytes written if outputSink provided)
|
|
96
|
+
*/
|
|
97
|
+
export declare function decodeLzma(input: Buffer, properties: Buffer | Uint8Array, outSize: number, outputSink?: OutputSink): Buffer | number;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synchronous LZMA1 Decoder
|
|
3
|
+
*
|
|
4
|
+
* Decodes LZMA1 compressed data from a buffer.
|
|
5
|
+
* All operations are synchronous.
|
|
6
|
+
*/
|
|
7
|
+
import { type OutputSink } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Synchronous LZMA1 decoder
|
|
10
|
+
*/
|
|
11
|
+
export declare class LzmaDecoder {
|
|
12
|
+
private outWindow;
|
|
13
|
+
private rangeDecoder;
|
|
14
|
+
private isMatchDecoders;
|
|
15
|
+
private isRepDecoders;
|
|
16
|
+
private isRepG0Decoders;
|
|
17
|
+
private isRepG1Decoders;
|
|
18
|
+
private isRepG2Decoders;
|
|
19
|
+
private isRep0LongDecoders;
|
|
20
|
+
private posSlotDecoder;
|
|
21
|
+
private posDecoders;
|
|
22
|
+
private posAlignDecoder;
|
|
23
|
+
private lenDecoder;
|
|
24
|
+
private repLenDecoder;
|
|
25
|
+
private literalDecoder;
|
|
26
|
+
private dictionarySize;
|
|
27
|
+
private dictionarySizeCheck;
|
|
28
|
+
private posStateMask;
|
|
29
|
+
private state;
|
|
30
|
+
private rep0;
|
|
31
|
+
private rep1;
|
|
32
|
+
private rep2;
|
|
33
|
+
private rep3;
|
|
34
|
+
private prevByte;
|
|
35
|
+
private totalPos;
|
|
36
|
+
constructor(outputSink?: OutputSink);
|
|
37
|
+
/**
|
|
38
|
+
* Set dictionary size
|
|
39
|
+
*/
|
|
40
|
+
setDictionarySize(dictionarySize: number): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Set lc, lp, pb properties
|
|
43
|
+
*/
|
|
44
|
+
setLcLpPb(lc: number, lp: number, pb: number): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Set decoder properties from 5-byte buffer
|
|
47
|
+
*/
|
|
48
|
+
setDecoderProperties(properties: Buffer | Uint8Array): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Initialize probability tables
|
|
51
|
+
*/
|
|
52
|
+
private initProbabilities;
|
|
53
|
+
/**
|
|
54
|
+
* Reset probabilities only (for LZMA2 state reset)
|
|
55
|
+
*/
|
|
56
|
+
resetProbabilities(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Reset dictionary position (for LZMA2 dictionary reset)
|
|
59
|
+
*/
|
|
60
|
+
resetDictionary(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Feed uncompressed data into the dictionary (for LZMA2 uncompressed chunks)
|
|
63
|
+
* This updates the sliding window so subsequent LZMA chunks can reference this data.
|
|
64
|
+
*/
|
|
65
|
+
feedUncompressed(data: Buffer): void;
|
|
66
|
+
/**
|
|
67
|
+
* Flush any remaining data in the OutWindow to the sink
|
|
68
|
+
*/
|
|
69
|
+
flushOutWindow(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Decode LZMA data with streaming output (no buffer accumulation)
|
|
72
|
+
* @param input - Compressed input buffer
|
|
73
|
+
* @param inputOffset - Offset into input buffer
|
|
74
|
+
* @param outSize - Expected output size
|
|
75
|
+
* @param solid - If true, preserve state from previous decode
|
|
76
|
+
* @returns Number of bytes written to sink
|
|
77
|
+
*/
|
|
78
|
+
decodeWithSink(input: Buffer, inputOffset: number, outSize: number, solid?: boolean): number;
|
|
79
|
+
/**
|
|
80
|
+
* Decode LZMA data
|
|
81
|
+
* @param input - Compressed input buffer
|
|
82
|
+
* @param inputOffset - Offset into input buffer
|
|
83
|
+
* @param outSize - Expected output size
|
|
84
|
+
* @param solid - If true, preserve state from previous decode
|
|
85
|
+
* @returns Decompressed data
|
|
86
|
+
*/
|
|
87
|
+
decode(input: Buffer, inputOffset: number, outSize: number, solid?: boolean): Buffer;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Decode LZMA1 data synchronously
|
|
91
|
+
* @param input - Compressed data (without 5-byte properties header)
|
|
92
|
+
* @param properties - 5-byte LZMA properties
|
|
93
|
+
* @param outSize - Expected output size
|
|
94
|
+
* @param outputSink - Optional output sink for zero-copy decoding (returns bytes written)
|
|
95
|
+
* @returns Decompressed data (or bytes written if outputSink provided)
|
|
96
|
+
*/
|
|
97
|
+
export declare function decodeLzma(input: Buffer, properties: Buffer | Uint8Array, outSize: number, outputSink?: OutputSink): Buffer | number;
|