xz-compat 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -7
- package/dist/cjs/index.d.cts +13 -3
- package/dist/cjs/index.d.ts +13 -3
- package/dist/cjs/index.js +24 -12
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lzma/index.d.cts +2 -18
- package/dist/cjs/lzma/index.d.ts +2 -18
- package/dist/cjs/lzma/index.js +0 -43
- package/dist/cjs/lzma/index.js.map +1 -1
- package/dist/cjs/lzma/sync/Lzma2Decoder.d.cts +4 -2
- package/dist/cjs/lzma/sync/Lzma2Decoder.d.ts +4 -2
- package/dist/cjs/lzma/sync/Lzma2Decoder.js +7 -6
- package/dist/cjs/lzma/sync/Lzma2Decoder.js.map +1 -1
- package/dist/cjs/lzma/sync/LzmaDecoder.d.cts +20 -2
- package/dist/cjs/lzma/sync/LzmaDecoder.d.ts +20 -2
- package/dist/cjs/lzma/sync/LzmaDecoder.js +22 -7
- package/dist/cjs/lzma/sync/LzmaDecoder.js.map +1 -1
- package/dist/cjs/native.d.cts +31 -0
- package/dist/cjs/native.d.ts +31 -0
- package/dist/cjs/native.js +65 -0
- package/dist/cjs/native.js.map +1 -0
- package/dist/cjs/sevenz.d.cts +47 -0
- package/dist/cjs/sevenz.d.ts +47 -0
- package/dist/cjs/sevenz.js +86 -0
- package/dist/cjs/sevenz.js.map +1 -0
- package/dist/cjs/xz/Decoder.d.cts +13 -0
- package/dist/cjs/xz/Decoder.d.ts +13 -0
- package/dist/cjs/xz/Decoder.js +42 -32
- package/dist/cjs/xz/Decoder.js.map +1 -1
- package/dist/esm/index.d.ts +13 -3
- package/dist/esm/index.js +26 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lzma/index.d.ts +2 -18
- package/dist/esm/lzma/index.js +2 -30
- package/dist/esm/lzma/index.js.map +1 -1
- package/dist/esm/lzma/sync/Lzma2Decoder.d.ts +4 -2
- package/dist/esm/lzma/sync/Lzma2Decoder.js +8 -7
- package/dist/esm/lzma/sync/Lzma2Decoder.js.map +1 -1
- package/dist/esm/lzma/sync/LzmaDecoder.d.ts +20 -2
- package/dist/esm/lzma/sync/LzmaDecoder.js +26 -7
- package/dist/esm/lzma/sync/LzmaDecoder.js.map +1 -1
- package/dist/esm/native.d.ts +31 -0
- package/dist/esm/native.js +51 -0
- package/dist/esm/native.js.map +1 -0
- package/dist/esm/sevenz.d.ts +47 -0
- package/dist/esm/sevenz.js +81 -0
- package/dist/esm/sevenz.js.map +1 -0
- package/dist/esm/xz/Decoder.d.ts +13 -0
- package/dist/esm/xz/Decoder.js +21 -9
- package/dist/esm/xz/Decoder.js.map +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ xz-compat is a complete pure JavaScript implementation of XZ decompression with
|
|
|
8
8
|
|
|
9
9
|
- ✅ **XZ Format Support**: Full XZ container format decoding
|
|
10
10
|
- ✅ **LZMA2 Decoder**: Complete LZMA2 decompression implementation
|
|
11
|
+
- ✅ **High-Level 7z API**: Streamlined decoding for 7z files with automatic native acceleration
|
|
11
12
|
- ✅ **BCJ Filters**: Branch conversion for improved compression on executables
|
|
12
13
|
- x86 (32-bit)
|
|
13
14
|
- ARM (32-bit)
|
|
@@ -19,7 +20,7 @@ xz-compat is a complete pure JavaScript implementation of XZ decompression with
|
|
|
19
20
|
- ✅ **Delta Filter**: Byte-level delta encoding
|
|
20
21
|
- ✅ **Streaming & Sync**: Both streaming transforms and synchronous decoding
|
|
21
22
|
- ✅ **Node 0.8+**: Works on legacy Node.js versions
|
|
22
|
-
- ✅ **
|
|
23
|
+
- ✅ **Native Acceleration**: Optional @napi-rs/lzma on Node.js 14+ for 3-5x performance boost
|
|
23
24
|
|
|
24
25
|
## Installation
|
|
25
26
|
|
|
@@ -27,9 +28,19 @@ xz-compat is a complete pure JavaScript implementation of XZ decompression with
|
|
|
27
28
|
npm install xz-compat
|
|
28
29
|
```
|
|
29
30
|
|
|
31
|
+
### Optional Native Acceleration
|
|
32
|
+
|
|
33
|
+
For Node.js 14+, install `@napi-rs/lzma` for automatic performance boost:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @napi-rs/lzma
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
This provides 3-5x faster decompression. The library automatically detects and uses native bindings when available, falling back to pure JavaScript on older Node versions or when not installed.
|
|
40
|
+
|
|
30
41
|
## Quick Start
|
|
31
42
|
|
|
32
|
-
###
|
|
43
|
+
### XZ Decompression (Self-describing format)
|
|
33
44
|
|
|
34
45
|
```javascript
|
|
35
46
|
import { readFileSync } from 'fs';
|
|
@@ -55,7 +66,18 @@ decoder.on('data', (chunk) => {
|
|
|
55
66
|
});
|
|
56
67
|
```
|
|
57
68
|
|
|
58
|
-
### LZMA2 Decompression
|
|
69
|
+
### 7z LZMA/LZMA2 Decompression (High-level API)
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
import { decode7zLzma2, decode7zLzma } from 'xz-compat';
|
|
73
|
+
|
|
74
|
+
// Decompress LZMA2 from a 7z file (properties extracted separately)
|
|
75
|
+
const lzma2Data = readFileSync('data.7z');
|
|
76
|
+
const lzma2Properties = /* from 7z folder structure */;
|
|
77
|
+
const decompressed = decode7zLzma2(lzma2Data, lzma2Properties);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### LZMA/LZMA2 (Low-level API)
|
|
59
81
|
|
|
60
82
|
```javascript
|
|
61
83
|
import { decodeLzma2 } from 'xz-compat';
|
|
@@ -90,20 +112,46 @@ const unfilteredArm = decodeBcjArm(armData);
|
|
|
90
112
|
|
|
91
113
|
## API Reference
|
|
92
114
|
|
|
93
|
-
###
|
|
115
|
+
### High-Level APIs (Recommended)
|
|
94
116
|
|
|
117
|
+
#### XZ Decompression
|
|
95
118
|
#### `decodeXZ(buffer: Buffer): Buffer`
|
|
96
119
|
Synchronously decompresses XZ format data.
|
|
120
|
+
- **Automatic native acceleration**: Uses @napi-rs/lzma when available on Node 14+
|
|
121
|
+
- **Self-describing**: Properties embedded in XZ format
|
|
97
122
|
|
|
98
123
|
#### `createXZDecoder(): Transform`
|
|
99
124
|
Creates a streaming Transform for XZ decompression.
|
|
125
|
+
- Automatically uses native acceleration when available
|
|
126
|
+
|
|
127
|
+
#### 7z LZMA/LZMA2 Decompression
|
|
128
|
+
#### `decode7zLzma2(data: Buffer, properties: Buffer, unpackSize?: number): Buffer`
|
|
129
|
+
Decompresses LZMA2 data from a 7z file.
|
|
130
|
+
- Accepts properties separately (matching 7z format)
|
|
131
|
+
- Tries native acceleration via @napi-rs/lzma automatically
|
|
132
|
+
- Falls back to pure JavaScript if native unavailable
|
|
133
|
+
|
|
134
|
+
#### `decode7zLzma(data: Buffer, properties: Buffer, unpackSize: number): Buffer`
|
|
135
|
+
Decompresses LZMA1 data from a 7z file.
|
|
136
|
+
- Accepts 5-byte properties separately
|
|
137
|
+
- Tries native acceleration automatically
|
|
138
|
+
|
|
139
|
+
### Low-Level APIs (Specialized Use)
|
|
140
|
+
|
|
141
|
+
#### LZMA Decompression
|
|
142
|
+
#### `decodeLzma(buffer: Buffer, properties: Buffer, outSize: number, sink?: OutputSink): Buffer`
|
|
143
|
+
Synchronously decodes LZMA1 compressed data.
|
|
144
|
+
- Low-level API for raw LZMA data
|
|
145
|
+
- Requires separate properties and output size
|
|
100
146
|
|
|
101
|
-
|
|
147
|
+
#### `createLzmaDecoder(properties: Buffer, outSize: number): Transform`
|
|
148
|
+
Creates a streaming Transform for LZMA1 decompression.
|
|
102
149
|
|
|
103
|
-
####
|
|
150
|
+
#### LZMA2 Decompression
|
|
151
|
+
#### `decodeLzma2(buffer: Buffer, properties: Buffer, unpackSize: number, sink?: OutputSink): Buffer`
|
|
104
152
|
Synchronously decodes LZMA2 compressed data.
|
|
105
153
|
|
|
106
|
-
#### `createLzma2Decoder(properties: Buffer, unpackSize
|
|
154
|
+
#### `createLzma2Decoder(properties: Buffer, unpackSize?: number): Transform`
|
|
107
155
|
Creates a streaming Transform for LZMA2 decompression.
|
|
108
156
|
|
|
109
157
|
### BCJ Filters
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* XZ-Compat: XZ/LZMA Decompression Library
|
|
3
|
+
*
|
|
4
|
+
* Pure JavaScript implementation with optional native acceleration
|
|
5
|
+
* via @napi-rs/lzma on Node.js 14+.
|
|
6
|
+
*
|
|
7
|
+
* Works on Node.js 0.8+ with automatic performance optimization
|
|
8
|
+
* when native bindings are available.
|
|
9
|
+
*/
|
|
10
|
+
export { decode7zLzma, decode7zLzma2 } from './sevenz.js';
|
|
4
11
|
export { createXZDecoder, decodeXZ } from './xz/Decoder.js';
|
|
12
|
+
export { createLzma2Decoder, createLzmaDecoder, decodeLzma, decodeLzma2 } from './lzma/index.js';
|
|
13
|
+
export * from './filters/index.js';
|
|
14
|
+
export { isNativeAvailable } from './native.js';
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* XZ-Compat: XZ/LZMA Decompression Library
|
|
3
|
+
*
|
|
4
|
+
* Pure JavaScript implementation with optional native acceleration
|
|
5
|
+
* via @napi-rs/lzma on Node.js 14+.
|
|
6
|
+
*
|
|
7
|
+
* Works on Node.js 0.8+ with automatic performance optimization
|
|
8
|
+
* when native bindings are available.
|
|
9
|
+
*/
|
|
10
|
+
export { decode7zLzma, decode7zLzma2 } from './sevenz.js';
|
|
4
11
|
export { createXZDecoder, decodeXZ } from './xz/Decoder.js';
|
|
12
|
+
export { createLzma2Decoder, createLzmaDecoder, decodeLzma, decodeLzma2 } from './lzma/index.js';
|
|
13
|
+
export * from './filters/index.js';
|
|
14
|
+
export { isNativeAvailable } from './native.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* XZ-Compat: XZ/LZMA Decompression Library
|
|
3
|
+
*
|
|
4
|
+
* Pure JavaScript implementation with optional native acceleration
|
|
5
|
+
* via @napi-rs/lzma on Node.js 14+.
|
|
6
|
+
*
|
|
7
|
+
* Works on Node.js 0.8+ with automatic performance optimization
|
|
8
|
+
* when native bindings are available.
|
|
9
|
+
*/ // ============================================================================
|
|
10
|
+
// High-Level APIs (Recommended)
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// 7z-specific decoders - accept properties separately, try native automatically
|
|
3
13
|
"use strict";
|
|
4
14
|
Object.defineProperty(exports, "__esModule", {
|
|
5
15
|
value: true
|
|
@@ -11,12 +21,6 @@ function _export(target, all) {
|
|
|
11
21
|
});
|
|
12
22
|
}
|
|
13
23
|
_export(exports, {
|
|
14
|
-
get Lzma2Decoder () {
|
|
15
|
-
return _indexts.Lzma2Decoder;
|
|
16
|
-
},
|
|
17
|
-
get LzmaDecoder () {
|
|
18
|
-
return _indexts.LzmaDecoder;
|
|
19
|
-
},
|
|
20
24
|
get createLzma2Decoder () {
|
|
21
25
|
return _indexts.createLzma2Decoder;
|
|
22
26
|
},
|
|
@@ -26,6 +30,12 @@ _export(exports, {
|
|
|
26
30
|
get createXZDecoder () {
|
|
27
31
|
return _Decoderts.createXZDecoder;
|
|
28
32
|
},
|
|
33
|
+
get decode7zLzma () {
|
|
34
|
+
return _sevenzts.decode7zLzma;
|
|
35
|
+
},
|
|
36
|
+
get decode7zLzma2 () {
|
|
37
|
+
return _sevenzts.decode7zLzma2;
|
|
38
|
+
},
|
|
29
39
|
get decodeLzma () {
|
|
30
40
|
return _indexts.decodeLzma;
|
|
31
41
|
},
|
|
@@ -35,13 +45,15 @@ _export(exports, {
|
|
|
35
45
|
get decodeXZ () {
|
|
36
46
|
return _Decoderts.decodeXZ;
|
|
37
47
|
},
|
|
38
|
-
get
|
|
39
|
-
return
|
|
48
|
+
get isNativeAvailable () {
|
|
49
|
+
return _nativets.isNativeAvailable;
|
|
40
50
|
}
|
|
41
51
|
});
|
|
42
|
-
|
|
43
|
-
var _indexts = require("./lzma/index.js");
|
|
52
|
+
var _sevenzts = require("./sevenz.js");
|
|
44
53
|
var _Decoderts = require("./xz/Decoder.js");
|
|
54
|
+
var _indexts = require("./lzma/index.js");
|
|
55
|
+
_export_star(require("./filters/index.js"), exports);
|
|
56
|
+
var _nativets = require("./native.js");
|
|
45
57
|
function _export_star(from, to) {
|
|
46
58
|
Object.keys(from).forEach(function(k) {
|
|
47
59
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/src/index.ts"],"sourcesContent":["/**\n * XZ-Compat: XZ/LZMA Decompression Library\n *\n * Pure JavaScript implementation with optional native acceleration\n * via @napi-rs/lzma on Node.js 14+.\n *\n * Works on Node.js 0.8+ with automatic performance optimization\n * when native bindings are available.\n */\n\n// ============================================================================\n// High-Level APIs (Recommended)\n// ============================================================================\n\n// 7z-specific decoders - accept properties separately, try native automatically\nexport { decode7zLzma, decode7zLzma2 } from './sevenz.ts';\n// XZ container format - self-describing, works great with native acceleration\nexport { createXZDecoder, decodeXZ } from './xz/Decoder.ts';\n\n// ============================================================================\n// Low-Level APIs (Backward Compatibility)\n// ============================================================================\n\n// Raw LZMA decoders (for specialized use cases)\nexport { createLzma2Decoder, createLzmaDecoder, decodeLzma, decodeLzma2 } from './lzma/index.ts';\n\n// ============================================================================\n// Supporting APIs\n// ============================================================================\n\n// Preprocessing filters (BCJ/Delta - used by 7z-iterator)\nexport * from './filters/index.ts';\n\n// Native acceleration utilities\nexport { isNativeAvailable } from './native.ts';\n"],"names":["createLzma2Decoder","createLzmaDecoder","createXZDecoder","decode7zLzma","decode7zLzma2","decodeLzma","decodeLzma2","decodeXZ","isNativeAvailable"],"mappings":"AAAA;;;;;;;;CAQC,GAED,+EAA+E;AAC/E,gCAAgC;AAChC,+EAA+E;AAE/E,gFAAgF;;;;;;;;;;;;QAUvEA;eAAAA,2BAAkB;;QAAEC;eAAAA,0BAAiB;;QAPrCC;eAAAA,0BAAe;;QAFfC;eAAAA,sBAAY;;QAAEC;eAAAA,uBAAa;;QASYC;eAAAA,mBAAU;;QAAEC;eAAAA,oBAAW;;QAP7CC;eAAAA,mBAAQ;;QAiBzBC;eAAAA,2BAAiB;;;wBAnBkB;yBAEF;uBAOqC;qBAOjE;wBAGoB"}
|
|
@@ -11,21 +11,5 @@
|
|
|
11
11
|
* - LZMA1 has no chunk boundaries and requires buffering all input for streaming
|
|
12
12
|
*/
|
|
13
13
|
export { createLzma2Decoder, createLzmaDecoder } from './stream/transforms.js';
|
|
14
|
-
export { decodeLzma2
|
|
15
|
-
export { decodeLzma
|
|
16
|
-
export { BitTreeDecoder, RangeDecoder } from './sync/RangeDecoder.js';
|
|
17
|
-
export * from './types.js';
|
|
18
|
-
/**
|
|
19
|
-
* Detect LZMA format from compressed data
|
|
20
|
-
*
|
|
21
|
-
* LZMA2 uses chunk-based framing with control bytes:
|
|
22
|
-
* - 0x00: End of stream
|
|
23
|
-
* - 0x01-0x02: Uncompressed chunks
|
|
24
|
-
* - 0x80-0xFF: LZMA compressed chunks
|
|
25
|
-
*
|
|
26
|
-
* LZMA1 is raw LZMA-compressed data (no framing)
|
|
27
|
-
*
|
|
28
|
-
* @param data - Compressed data to analyze
|
|
29
|
-
* @returns 'lzma1' for LZMA1, 'lzma2' for LZMA2
|
|
30
|
-
*/
|
|
31
|
-
export declare function detectLzmaFormat(data: Buffer): 'lzma1' | 'lzma2';
|
|
14
|
+
export { decodeLzma2 } from './sync/Lzma2Decoder.js';
|
|
15
|
+
export { decodeLzma } from './sync/LzmaDecoder.js';
|
package/dist/cjs/lzma/index.d.ts
CHANGED
|
@@ -11,21 +11,5 @@
|
|
|
11
11
|
* - LZMA1 has no chunk boundaries and requires buffering all input for streaming
|
|
12
12
|
*/
|
|
13
13
|
export { createLzma2Decoder, createLzmaDecoder } from './stream/transforms.js';
|
|
14
|
-
export { decodeLzma2
|
|
15
|
-
export { decodeLzma
|
|
16
|
-
export { BitTreeDecoder, RangeDecoder } from './sync/RangeDecoder.js';
|
|
17
|
-
export * from './types.js';
|
|
18
|
-
/**
|
|
19
|
-
* Detect LZMA format from compressed data
|
|
20
|
-
*
|
|
21
|
-
* LZMA2 uses chunk-based framing with control bytes:
|
|
22
|
-
* - 0x00: End of stream
|
|
23
|
-
* - 0x01-0x02: Uncompressed chunks
|
|
24
|
-
* - 0x80-0xFF: LZMA compressed chunks
|
|
25
|
-
*
|
|
26
|
-
* LZMA1 is raw LZMA-compressed data (no framing)
|
|
27
|
-
*
|
|
28
|
-
* @param data - Compressed data to analyze
|
|
29
|
-
* @returns 'lzma1' for LZMA1, 'lzma2' for LZMA2
|
|
30
|
-
*/
|
|
31
|
-
export declare function detectLzmaFormat(data: Buffer): 'lzma1' | 'lzma2';
|
|
14
|
+
export { decodeLzma2 } from './sync/Lzma2Decoder.js';
|
|
15
|
+
export { decodeLzma } from './sync/LzmaDecoder.js';
|
package/dist/cjs/lzma/index.js
CHANGED
|
@@ -21,18 +21,6 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
-
get BitTreeDecoder () {
|
|
25
|
-
return _RangeDecoderts.BitTreeDecoder;
|
|
26
|
-
},
|
|
27
|
-
get Lzma2Decoder () {
|
|
28
|
-
return _Lzma2Decoderts.Lzma2Decoder;
|
|
29
|
-
},
|
|
30
|
-
get LzmaDecoder () {
|
|
31
|
-
return _LzmaDecoderts.LzmaDecoder;
|
|
32
|
-
},
|
|
33
|
-
get RangeDecoder () {
|
|
34
|
-
return _RangeDecoderts.RangeDecoder;
|
|
35
|
-
},
|
|
36
24
|
get createLzma2Decoder () {
|
|
37
25
|
return _transformsts.createLzma2Decoder;
|
|
38
26
|
},
|
|
@@ -44,40 +32,9 @@ _export(exports, {
|
|
|
44
32
|
},
|
|
45
33
|
get decodeLzma2 () {
|
|
46
34
|
return _Lzma2Decoderts.decodeLzma2;
|
|
47
|
-
},
|
|
48
|
-
get detectLzmaFormat () {
|
|
49
|
-
return detectLzmaFormat;
|
|
50
35
|
}
|
|
51
36
|
});
|
|
52
37
|
var _transformsts = require("./stream/transforms.js");
|
|
53
38
|
var _Lzma2Decoderts = require("./sync/Lzma2Decoder.js");
|
|
54
39
|
var _LzmaDecoderts = require("./sync/LzmaDecoder.js");
|
|
55
|
-
var _RangeDecoderts = require("./sync/RangeDecoder.js");
|
|
56
|
-
_export_star(require("./types.js"), exports);
|
|
57
|
-
function _export_star(from, to) {
|
|
58
|
-
Object.keys(from).forEach(function(k) {
|
|
59
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
60
|
-
Object.defineProperty(to, k, {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
get: function() {
|
|
63
|
-
return from[k];
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
return from;
|
|
69
|
-
}
|
|
70
|
-
function detectLzmaFormat(data) {
|
|
71
|
-
if (data.length === 0) {
|
|
72
|
-
// Default to LZMA2 for empty data (matches LZMA2 decoder behavior)
|
|
73
|
-
return 'lzma2';
|
|
74
|
-
}
|
|
75
|
-
var firstByte = data[0];
|
|
76
|
-
// LZMA2 control bytes: 0x00, 0x01, 0x02, or 0x80-0xFF
|
|
77
|
-
if (firstByte === 0x00 || firstByte === 0x01 || firstByte === 0x02 || firstByte >= 0x80 && firstByte <= 0xff) {
|
|
78
|
-
return 'lzma2';
|
|
79
|
-
}
|
|
80
|
-
// All other values indicate LZMA1 (raw LZMA data)
|
|
81
|
-
return 'lzma1';
|
|
82
|
-
}
|
|
83
40
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/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 * LZMA1 vs LZMA2:\n * - LZMA2 is chunked and supports true streaming with bounded memory\n * - LZMA1 has no chunk boundaries and requires buffering all input for streaming\n */\n\n// Streaming decoders (Transform streams)\nexport { createLzma2Decoder, createLzmaDecoder } from './stream/transforms.ts';\nexport { decodeLzma2
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/xz-compat/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 * LZMA1 vs LZMA2:\n * - LZMA2 is chunked and supports true streaming with bounded memory\n * - LZMA1 has no chunk boundaries and requires buffering all input for streaming\n */\n\n// Streaming decoders (Transform streams)\nexport { createLzma2Decoder, createLzmaDecoder } from './stream/transforms.ts';\nexport { decodeLzma2 } from './sync/Lzma2Decoder.ts';\n// Synchronous decoders (for Buffer input)\nexport { decodeLzma } from './sync/LzmaDecoder.ts';\n"],"names":["createLzma2Decoder","createLzmaDecoder","decodeLzma","decodeLzma2"],"mappings":"AAAA;;;;;;;;;;;CAWC,GAED,yCAAyC;;;;;;;;;;;;QAChCA;eAAAA,gCAAkB;;QAAEC;eAAAA,+BAAiB;;QAGrCC;eAAAA,yBAAU;;QAFVC;eAAAA,2BAAW;;;4BADkC;8BAC1B;6BAED"}
|
|
@@ -57,7 +57,9 @@ export declare class Lzma2Decoder {
|
|
|
57
57
|
* @param input - LZMA2 compressed data
|
|
58
58
|
* @param properties - 1-byte properties (dictionary size)
|
|
59
59
|
* @param unpackSize - Expected output size (optional, autodetects if not provided)
|
|
60
|
-
* @param outputSink - Optional output sink for
|
|
60
|
+
* @param outputSink - Optional output sink with write callback for streaming (returns bytes written)
|
|
61
61
|
* @returns Decompressed data (or bytes written if outputSink provided)
|
|
62
62
|
*/
|
|
63
|
-
export declare function decodeLzma2(input: Buffer, properties: Buffer | Uint8Array, unpackSize?: number, outputSink?:
|
|
63
|
+
export declare function decodeLzma2(input: Buffer, properties: Buffer | Uint8Array, unpackSize?: number, outputSink?: {
|
|
64
|
+
write(buffer: Buffer): void;
|
|
65
|
+
}): Buffer | number;
|
|
@@ -57,7 +57,9 @@ export declare class Lzma2Decoder {
|
|
|
57
57
|
* @param input - LZMA2 compressed data
|
|
58
58
|
* @param properties - 1-byte properties (dictionary size)
|
|
59
59
|
* @param unpackSize - Expected output size (optional, autodetects if not provided)
|
|
60
|
-
* @param outputSink - Optional output sink for
|
|
60
|
+
* @param outputSink - Optional output sink with write callback for streaming (returns bytes written)
|
|
61
61
|
* @returns Decompressed data (or bytes written if outputSink provided)
|
|
62
62
|
*/
|
|
63
|
-
export declare function decodeLzma2(input: Buffer, properties: Buffer | Uint8Array, unpackSize?: number, outputSink?:
|
|
63
|
+
export declare function decodeLzma2(input: Buffer, properties: Buffer | Uint8Array, unpackSize?: number, outputSink?: {
|
|
64
|
+
write(buffer: Buffer): void;
|
|
65
|
+
}): Buffer | number;
|
|
@@ -198,14 +198,15 @@ var Lzma2Decoder = /*#__PURE__*/ function() {
|
|
|
198
198
|
}
|
|
199
199
|
// Determine solid mode - preserve dictionary if not resetting state or if only resetting state (not dict)
|
|
200
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
|
|
201
|
+
// Decode LZMA chunk - use zero-copy when we have pre-allocated buffer
|
|
205
202
|
if (outputBuffer) {
|
|
206
|
-
|
|
207
|
-
|
|
203
|
+
// Zero-copy: decode directly into caller's buffer
|
|
204
|
+
var bytesWritten = this.lzmaDecoder.decodeToBuffer(input, dataOffset, chunk.uncompSize, outputBuffer, outputPos, useSolid);
|
|
205
|
+
outputPos += bytesWritten;
|
|
208
206
|
} else {
|
|
207
|
+
// No pre-allocation: decode to new buffer and collect chunks
|
|
208
|
+
var chunkData = input.slice(dataOffset, dataOffset + chunk.compSize);
|
|
209
|
+
var decoded = this.lzmaDecoder.decode(chunkData, 0, chunk.uncompSize, useSolid);
|
|
209
210
|
outputChunks.push(decoded);
|
|
210
211
|
}
|
|
211
212
|
offset = dataOffset + chunk.compSize;
|
|
@@ -1 +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,kBAE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Aa,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"}
|
|
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 - use zero-copy when we have pre-allocated buffer\n if (outputBuffer) {\n // Zero-copy: decode directly into caller's buffer\n const bytesWritten = this.lzmaDecoder.decodeToBuffer(input, dataOffset, chunk.uncompSize, outputBuffer, outputPos, useSolid);\n outputPos += bytesWritten;\n } else {\n // No pre-allocation: decode to new buffer and collect chunks\n const chunkData = input.slice(dataOffset, dataOffset + chunk.compSize);\n const decoded = this.lzmaDecoder.decode(chunkData, 0, chunk.uncompSize, useSolid);\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 with write callback for streaming (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?: { write(buffer: Buffer): void }): Buffer | number {\n const decoder = new Lzma2Decoder(properties, outputSink as 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","bytesWritten","decodeToBuffer","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,O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IAChC;IACA,6CAA6C;IAC7C,OAAOqC,QAAQjC,MAAM,CAACJ,OAAOwB;AAC/B"}
|
|
@@ -76,6 +76,17 @@ export declare class LzmaDecoder {
|
|
|
76
76
|
* @returns Number of bytes written to sink
|
|
77
77
|
*/
|
|
78
78
|
decodeWithSink(input: Buffer, inputOffset: number, outSize: number, solid?: boolean): number;
|
|
79
|
+
/**
|
|
80
|
+
* Decode LZMA data directly into caller's buffer (zero-copy)
|
|
81
|
+
* @param input - Compressed input buffer
|
|
82
|
+
* @param inputOffset - Offset into input buffer
|
|
83
|
+
* @param outSize - Expected output size
|
|
84
|
+
* @param output - Pre-allocated output buffer to write to
|
|
85
|
+
* @param outputOffset - Offset in output buffer to start writing
|
|
86
|
+
* @param solid - If true, preserve state from previous decode
|
|
87
|
+
* @returns Number of bytes written
|
|
88
|
+
*/
|
|
89
|
+
decodeToBuffer(input: Buffer, inputOffset: number, outSize: number, output: Buffer, outputOffset: number, solid?: boolean): number;
|
|
79
90
|
/**
|
|
80
91
|
* Decode LZMA data
|
|
81
92
|
* @param input - Compressed input buffer
|
|
@@ -88,10 +99,17 @@ export declare class LzmaDecoder {
|
|
|
88
99
|
}
|
|
89
100
|
/**
|
|
90
101
|
* Decode LZMA1 data synchronously
|
|
102
|
+
*
|
|
103
|
+
* Note: LZMA1 is a low-level format. @napi-rs/lzma expects self-describing
|
|
104
|
+
* data (like XZ), but here we accept raw LZMA with properties specified separately.
|
|
105
|
+
* Pure JS implementation is used for LZMA1.
|
|
106
|
+
*
|
|
91
107
|
* @param input - Compressed data (without 5-byte properties header)
|
|
92
108
|
* @param properties - 5-byte LZMA properties
|
|
93
109
|
* @param outSize - Expected output size
|
|
94
|
-
* @param outputSink - Optional output sink for
|
|
110
|
+
* @param outputSink - Optional output sink with write callback for streaming (returns bytes written)
|
|
95
111
|
* @returns Decompressed data (or bytes written if outputSink provided)
|
|
96
112
|
*/
|
|
97
|
-
export declare function decodeLzma(input: Buffer, properties: Buffer | Uint8Array, outSize: number, outputSink?:
|
|
113
|
+
export declare function decodeLzma(input: Buffer, properties: Buffer | Uint8Array, outSize: number, outputSink?: {
|
|
114
|
+
write(buffer: Buffer): void;
|
|
115
|
+
}): Buffer | number;
|
|
@@ -76,6 +76,17 @@ export declare class LzmaDecoder {
|
|
|
76
76
|
* @returns Number of bytes written to sink
|
|
77
77
|
*/
|
|
78
78
|
decodeWithSink(input: Buffer, inputOffset: number, outSize: number, solid?: boolean): number;
|
|
79
|
+
/**
|
|
80
|
+
* Decode LZMA data directly into caller's buffer (zero-copy)
|
|
81
|
+
* @param input - Compressed input buffer
|
|
82
|
+
* @param inputOffset - Offset into input buffer
|
|
83
|
+
* @param outSize - Expected output size
|
|
84
|
+
* @param output - Pre-allocated output buffer to write to
|
|
85
|
+
* @param outputOffset - Offset in output buffer to start writing
|
|
86
|
+
* @param solid - If true, preserve state from previous decode
|
|
87
|
+
* @returns Number of bytes written
|
|
88
|
+
*/
|
|
89
|
+
decodeToBuffer(input: Buffer, inputOffset: number, outSize: number, output: Buffer, outputOffset: number, solid?: boolean): number;
|
|
79
90
|
/**
|
|
80
91
|
* Decode LZMA data
|
|
81
92
|
* @param input - Compressed input buffer
|
|
@@ -88,10 +99,17 @@ export declare class LzmaDecoder {
|
|
|
88
99
|
}
|
|
89
100
|
/**
|
|
90
101
|
* Decode LZMA1 data synchronously
|
|
102
|
+
*
|
|
103
|
+
* Note: LZMA1 is a low-level format. @napi-rs/lzma expects self-describing
|
|
104
|
+
* data (like XZ), but here we accept raw LZMA with properties specified separately.
|
|
105
|
+
* Pure JS implementation is used for LZMA1.
|
|
106
|
+
*
|
|
91
107
|
* @param input - Compressed data (without 5-byte properties header)
|
|
92
108
|
* @param properties - 5-byte LZMA properties
|
|
93
109
|
* @param outSize - Expected output size
|
|
94
|
-
* @param outputSink - Optional output sink for
|
|
110
|
+
* @param outputSink - Optional output sink with write callback for streaming (returns bytes written)
|
|
95
111
|
* @returns Decompressed data (or bytes written if outputSink provided)
|
|
96
112
|
*/
|
|
97
|
-
export declare function decodeLzma(input: Buffer, properties: Buffer | Uint8Array, outSize: number, outputSink?:
|
|
113
|
+
export declare function decodeLzma(input: Buffer, properties: Buffer | Uint8Array, outSize: number, outputSink?: {
|
|
114
|
+
write(buffer: Buffer): void;
|
|
115
|
+
}): Buffer | number;
|
|
@@ -453,14 +453,16 @@ var LzmaDecoder = /*#__PURE__*/ function() {
|
|
|
453
453
|
return outPos;
|
|
454
454
|
};
|
|
455
455
|
/**
|
|
456
|
-
* Decode LZMA data
|
|
456
|
+
* Decode LZMA data directly into caller's buffer (zero-copy)
|
|
457
457
|
* @param input - Compressed input buffer
|
|
458
458
|
* @param inputOffset - Offset into input buffer
|
|
459
459
|
* @param outSize - Expected output size
|
|
460
|
+
* @param output - Pre-allocated output buffer to write to
|
|
461
|
+
* @param outputOffset - Offset in output buffer to start writing
|
|
460
462
|
* @param solid - If true, preserve state from previous decode
|
|
461
|
-
* @returns
|
|
462
|
-
*/ _proto.
|
|
463
|
-
var solid = arguments.length >
|
|
463
|
+
* @returns Number of bytes written
|
|
464
|
+
*/ _proto.decodeToBuffer = function decodeToBuffer(input, inputOffset, outSize, output, outputOffset) {
|
|
465
|
+
var solid = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : false;
|
|
464
466
|
this.rangeDecoder.setInput(input, inputOffset);
|
|
465
467
|
if (!solid) {
|
|
466
468
|
this.outWindow.init(false);
|
|
@@ -476,10 +478,10 @@ var LzmaDecoder = /*#__PURE__*/ function() {
|
|
|
476
478
|
// Solid mode: preserve dictionary state but reinitialize range decoder
|
|
477
479
|
this.outWindow.init(true);
|
|
478
480
|
}
|
|
479
|
-
var
|
|
480
|
-
var
|
|
481
|
+
var outPos = outputOffset;
|
|
482
|
+
var outEnd = outputOffset + outSize;
|
|
481
483
|
var cumPos = this.totalPos;
|
|
482
|
-
while(outPos <
|
|
484
|
+
while(outPos < outEnd){
|
|
483
485
|
var posState = cumPos & this.posStateMask;
|
|
484
486
|
if (this.rangeDecoder.decodeBit(this.isMatchDecoders, (this.state << _typests.kNumPosStatesBitsMax) + posState) === 0) {
|
|
485
487
|
// Literal
|
|
@@ -563,6 +565,19 @@ var LzmaDecoder = /*#__PURE__*/ function() {
|
|
|
563
565
|
}
|
|
564
566
|
}
|
|
565
567
|
this.totalPos = cumPos;
|
|
568
|
+
return outPos - outputOffset;
|
|
569
|
+
};
|
|
570
|
+
/**
|
|
571
|
+
* Decode LZMA data
|
|
572
|
+
* @param input - Compressed input buffer
|
|
573
|
+
* @param inputOffset - Offset into input buffer
|
|
574
|
+
* @param outSize - Expected output size
|
|
575
|
+
* @param solid - If true, preserve state from previous decode
|
|
576
|
+
* @returns Decompressed data
|
|
577
|
+
*/ _proto.decode = function decode(input, inputOffset, outSize) {
|
|
578
|
+
var solid = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
|
|
579
|
+
var output = (0, _extractbaseiterator.allocBufferUnsafe)(outSize);
|
|
580
|
+
this.decodeToBuffer(input, inputOffset, outSize, output, 0, solid);
|
|
566
581
|
return output;
|
|
567
582
|
};
|
|
568
583
|
return LzmaDecoder;
|