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,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,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,148 +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
|
-
*/ "use strict";
|
|
18
|
-
Object.defineProperty(exports, "__esModule", {
|
|
19
|
-
value: true
|
|
20
|
-
});
|
|
21
|
-
function _export(target, all) {
|
|
22
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
_export(exports, {
|
|
28
|
-
get hasCompleteChunk () {
|
|
29
|
-
return hasCompleteChunk;
|
|
30
|
-
},
|
|
31
|
-
get parseLzma2ChunkHeader () {
|
|
32
|
-
return parseLzma2ChunkHeader;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
function parseLzma2ChunkHeader(input, offset) {
|
|
36
|
-
if (offset >= input.length) {
|
|
37
|
-
return {
|
|
38
|
-
success: false,
|
|
39
|
-
needBytes: 1
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
var control = input[offset];
|
|
43
|
-
// End of stream
|
|
44
|
-
if (control === 0x00) {
|
|
45
|
-
return {
|
|
46
|
-
success: true,
|
|
47
|
-
chunk: {
|
|
48
|
-
type: 'end',
|
|
49
|
-
headerSize: 1,
|
|
50
|
-
dictReset: false,
|
|
51
|
-
stateReset: false,
|
|
52
|
-
newProps: null,
|
|
53
|
-
uncompSize: 0,
|
|
54
|
-
compSize: 0
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
// Uncompressed chunk
|
|
59
|
-
if (control === 0x01 || control === 0x02) {
|
|
60
|
-
// Need 3 bytes: control + 2 size bytes
|
|
61
|
-
if (offset + 3 > input.length) {
|
|
62
|
-
return {
|
|
63
|
-
success: false,
|
|
64
|
-
needBytes: 3 - (input.length - offset)
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
var uncompSize = (input[offset + 1] << 8 | input[offset + 2]) + 1;
|
|
68
|
-
return {
|
|
69
|
-
success: true,
|
|
70
|
-
chunk: {
|
|
71
|
-
type: 'uncompressed',
|
|
72
|
-
headerSize: 3,
|
|
73
|
-
dictReset: control === 0x01,
|
|
74
|
-
stateReset: false,
|
|
75
|
-
newProps: null,
|
|
76
|
-
uncompSize: uncompSize,
|
|
77
|
-
compSize: 0
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
// LZMA compressed chunk
|
|
82
|
-
if (control >= 0x80) {
|
|
83
|
-
var hasNewProps = control >= 0xc0;
|
|
84
|
-
var minHeaderSize = hasNewProps ? 6 : 5; // control + 2 uncomp + 2 comp + (1 props)
|
|
85
|
-
if (offset + minHeaderSize > input.length) {
|
|
86
|
-
return {
|
|
87
|
-
success: false,
|
|
88
|
-
needBytes: minHeaderSize - (input.length - offset)
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
// Parse sizes
|
|
92
|
-
var uncompHigh = control & 0x1f;
|
|
93
|
-
var uncompSize1 = (uncompHigh << 16 | input[offset + 1] << 8 | input[offset + 2]) + 1;
|
|
94
|
-
var compSize = (input[offset + 3] << 8 | input[offset + 4]) + 1;
|
|
95
|
-
// Parse properties if present
|
|
96
|
-
var newProps = null;
|
|
97
|
-
if (hasNewProps) {
|
|
98
|
-
var propsByte = input[offset + 5];
|
|
99
|
-
var lc = propsByte % 9;
|
|
100
|
-
var remainder = ~~(propsByte / 9);
|
|
101
|
-
var lp = remainder % 5;
|
|
102
|
-
var pb = ~~(remainder / 5);
|
|
103
|
-
newProps = {
|
|
104
|
-
lc: lc,
|
|
105
|
-
lp: lp,
|
|
106
|
-
pb: pb
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
success: true,
|
|
111
|
-
chunk: {
|
|
112
|
-
type: 'lzma',
|
|
113
|
-
headerSize: minHeaderSize,
|
|
114
|
-
dictReset: control >= 0xe0,
|
|
115
|
-
stateReset: control >= 0xa0,
|
|
116
|
-
newProps: newProps,
|
|
117
|
-
uncompSize: uncompSize1,
|
|
118
|
-
compSize: compSize
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
// Invalid control byte
|
|
123
|
-
throw new Error("Invalid LZMA2 control byte: 0x".concat(control.toString(16)));
|
|
124
|
-
}
|
|
125
|
-
function hasCompleteChunk(input, offset) {
|
|
126
|
-
var result = parseLzma2ChunkHeader(input, offset);
|
|
127
|
-
if (result.success === false) {
|
|
128
|
-
return {
|
|
129
|
-
success: false,
|
|
130
|
-
needBytes: result.needBytes
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
var chunk = result.chunk;
|
|
134
|
-
var dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;
|
|
135
|
-
var totalSize = chunk.headerSize + dataSize;
|
|
136
|
-
if (offset + totalSize > input.length) {
|
|
137
|
-
return {
|
|
138
|
-
success: false,
|
|
139
|
-
needBytes: totalSize - (input.length - offset)
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
return {
|
|
143
|
-
success: true,
|
|
144
|
-
chunk: chunk,
|
|
145
|
-
totalSize: totalSize
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
/* 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/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":["hasCompleteChunk","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","result","dataSize","totalSize"],"mappings":"AAAA;;;;;;;;;;;;;;CAcC,GAED;;CAEC;;;;;;;;;;;QAsIeA;eAAAA;;QA/FAC;eAAAA;;;AAAT,SAASA,sBAAsBC,KAAa,EAAEC,MAAc;IACjE,IAAIA,UAAUD,MAAME,MAAM,EAAE;QAC1B,OAAO;YAAEC,SAAS;YAAOC,WAAW;QAAE;IACxC;IAEA,IAAMC,UAAUL,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
* 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/cjs/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/cjs/lzma/index.js
DELETED
|
@@ -1,63 +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
|
-
"use strict";
|
|
10
|
-
Object.defineProperty(exports, "__esModule", {
|
|
11
|
-
value: true
|
|
12
|
-
});
|
|
13
|
-
function _export(target, all) {
|
|
14
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
_export(exports, {
|
|
20
|
-
get BitTreeDecoder () {
|
|
21
|
-
return _RangeDecoderts.BitTreeDecoder;
|
|
22
|
-
},
|
|
23
|
-
get Lzma2Decoder () {
|
|
24
|
-
return _Lzma2Decoderts.Lzma2Decoder;
|
|
25
|
-
},
|
|
26
|
-
get LzmaDecoder () {
|
|
27
|
-
return _LzmaDecoderts.LzmaDecoder;
|
|
28
|
-
},
|
|
29
|
-
get RangeDecoder () {
|
|
30
|
-
return _RangeDecoderts.RangeDecoder;
|
|
31
|
-
},
|
|
32
|
-
get createLzma2Decoder () {
|
|
33
|
-
return _transformsts.createLzma2Decoder;
|
|
34
|
-
},
|
|
35
|
-
get createLzmaDecoder () {
|
|
36
|
-
return _transformsts.createLzmaDecoder;
|
|
37
|
-
},
|
|
38
|
-
get decodeLzma () {
|
|
39
|
-
return _LzmaDecoderts.decodeLzma;
|
|
40
|
-
},
|
|
41
|
-
get decodeLzma2 () {
|
|
42
|
-
return _Lzma2Decoderts.decodeLzma2;
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
var _transformsts = require("./stream/transforms.js");
|
|
46
|
-
var _Lzma2Decoderts = require("./sync/Lzma2Decoder.js");
|
|
47
|
-
var _LzmaDecoderts = require("./sync/LzmaDecoder.js");
|
|
48
|
-
var _RangeDecoderts = require("./sync/RangeDecoder.js");
|
|
49
|
-
_export_star(require("./types.js"), exports);
|
|
50
|
-
function _export_star(from, to) {
|
|
51
|
-
Object.keys(from).forEach(function(k) {
|
|
52
|
-
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
53
|
-
Object.defineProperty(to, k, {
|
|
54
|
-
enumerable: true,
|
|
55
|
-
get: function() {
|
|
56
|
-
return from[k];
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
return from;
|
|
62
|
-
}
|
|
63
|
-
/* 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/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":["BitTreeDecoder","Lzma2Decoder","LzmaDecoder","RangeDecoder","createLzma2Decoder","createLzmaDecoder","decodeLzma","decodeLzma2"],"mappings":"AAAA;;;;;;;CAOC,GAED,yCAAyC;;;;;;;;;;;;QAKhCA;eAAAA,8BAAc;;QAHDC;eAAAA,4BAAY;;QAEbC;eAAAA,0BAAW;;QACPC;eAAAA,4BAAY;;QAJ5BC;eAAAA,gCAAkB;;QAAEC;eAAAA,+BAAiB;;QAGrCC;eAAAA,yBAAU;;QAFVC;eAAAA,2BAAW;;;4BADkC;8BACZ;6BAEF;8BACK;qBAE/B"}
|
|
@@ -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,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,149 +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
|
-
*/ "use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
function _export(target, all) {
|
|
18
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
_export(exports, {
|
|
24
|
-
get createLzma2Decoder () {
|
|
25
|
-
return createLzma2Decoder;
|
|
26
|
-
},
|
|
27
|
-
get createLzmaDecoder () {
|
|
28
|
-
return createLzmaDecoder;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
var _extractbaseiterator = require("extract-base-iterator");
|
|
32
|
-
var _Lzma2ChunkParserts = require("../Lzma2ChunkParser.js");
|
|
33
|
-
var _LzmaDecoderts = require("../sync/LzmaDecoder.js");
|
|
34
|
-
var _typests = require("../types.js");
|
|
35
|
-
function createLzma2Decoder(properties) {
|
|
36
|
-
if (!properties || properties.length < 1) {
|
|
37
|
-
throw new Error('LZMA2 requires properties byte');
|
|
38
|
-
}
|
|
39
|
-
var dictSize = (0, _typests.parseLzma2DictionarySize)(properties[0]);
|
|
40
|
-
// LZMA decoder instance - reused across chunks for solid mode
|
|
41
|
-
var decoder = new _LzmaDecoderts.LzmaDecoder();
|
|
42
|
-
decoder.setDictionarySize(dictSize);
|
|
43
|
-
// Track current LZMA properties
|
|
44
|
-
var propsSet = false;
|
|
45
|
-
// Buffer for incomplete chunk data
|
|
46
|
-
var pending = null;
|
|
47
|
-
var finished = false;
|
|
48
|
-
return new _extractbaseiterator.Transform({
|
|
49
|
-
transform: function transform(chunk, _encoding, callback) {
|
|
50
|
-
if (finished) {
|
|
51
|
-
callback(null);
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
// Combine with pending data
|
|
55
|
-
var input;
|
|
56
|
-
if (pending && pending.length > 0) {
|
|
57
|
-
input = Buffer.concat([
|
|
58
|
-
pending,
|
|
59
|
-
chunk
|
|
60
|
-
]);
|
|
61
|
-
pending = null;
|
|
62
|
-
} else {
|
|
63
|
-
input = chunk;
|
|
64
|
-
}
|
|
65
|
-
var offset = 0;
|
|
66
|
-
try {
|
|
67
|
-
while(offset < input.length && !finished){
|
|
68
|
-
var result = (0, _Lzma2ChunkParserts.hasCompleteChunk)(input, offset);
|
|
69
|
-
if (!result.success) {
|
|
70
|
-
// Need more data
|
|
71
|
-
pending = input.slice(offset);
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
var chunkInfo = result.chunk, totalSize = result.totalSize;
|
|
75
|
-
if (chunkInfo.type === 'end') {
|
|
76
|
-
finished = true;
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
// Handle dictionary reset
|
|
80
|
-
if (chunkInfo.dictReset) {
|
|
81
|
-
decoder.resetDictionary();
|
|
82
|
-
}
|
|
83
|
-
var dataOffset = offset + chunkInfo.headerSize;
|
|
84
|
-
if (chunkInfo.type === 'uncompressed') {
|
|
85
|
-
var uncompData = input.slice(dataOffset, dataOffset + chunkInfo.uncompSize);
|
|
86
|
-
this.push(uncompData);
|
|
87
|
-
// Feed uncompressed data to dictionary for subsequent LZMA chunks
|
|
88
|
-
decoder.feedUncompressed(uncompData);
|
|
89
|
-
} else {
|
|
90
|
-
// LZMA compressed chunk
|
|
91
|
-
// Apply new properties if present
|
|
92
|
-
if (chunkInfo.newProps) {
|
|
93
|
-
var _chunkInfo_newProps = chunkInfo.newProps, lc = _chunkInfo_newProps.lc, lp = _chunkInfo_newProps.lp, pb = _chunkInfo_newProps.pb;
|
|
94
|
-
if (!decoder.setLcLpPb(lc, lp, pb)) {
|
|
95
|
-
throw new Error("Invalid LZMA properties: lc=".concat(lc, " lp=").concat(lp, " pb=").concat(pb));
|
|
96
|
-
}
|
|
97
|
-
propsSet = true;
|
|
98
|
-
}
|
|
99
|
-
if (!propsSet) {
|
|
100
|
-
throw new Error('LZMA chunk without properties');
|
|
101
|
-
}
|
|
102
|
-
// Reset probabilities if state reset
|
|
103
|
-
if (chunkInfo.stateReset) {
|
|
104
|
-
decoder.resetProbabilities();
|
|
105
|
-
}
|
|
106
|
-
// Determine solid mode - preserve dictionary if not resetting state or if only resetting state (not dict)
|
|
107
|
-
var useSolid = !chunkInfo.stateReset || chunkInfo.stateReset && !chunkInfo.dictReset;
|
|
108
|
-
var compData = input.slice(dataOffset, dataOffset + chunkInfo.compSize);
|
|
109
|
-
var decoded = decoder.decode(compData, 0, chunkInfo.uncompSize, useSolid);
|
|
110
|
-
this.push(decoded);
|
|
111
|
-
}
|
|
112
|
-
offset += totalSize;
|
|
113
|
-
}
|
|
114
|
-
callback(null);
|
|
115
|
-
} catch (err) {
|
|
116
|
-
callback(err);
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
flush: function flush(callback) {
|
|
120
|
-
if (pending && pending.length > 0 && !finished) {
|
|
121
|
-
callback(new Error('Truncated LZMA2 stream'));
|
|
122
|
-
} else {
|
|
123
|
-
callback(null);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
function createLzmaDecoder(properties, unpackSize) {
|
|
129
|
-
var decoder = new _LzmaDecoderts.LzmaDecoder();
|
|
130
|
-
decoder.setDecoderProperties(properties);
|
|
131
|
-
var chunks = [];
|
|
132
|
-
return new _extractbaseiterator.Transform({
|
|
133
|
-
transform: function transform(chunk, _encoding, callback) {
|
|
134
|
-
chunks.push(chunk);
|
|
135
|
-
callback(null);
|
|
136
|
-
},
|
|
137
|
-
flush: function flush(callback) {
|
|
138
|
-
try {
|
|
139
|
-
var input = Buffer.concat(chunks);
|
|
140
|
-
var output = decoder.decode(input, 0, unpackSize, false);
|
|
141
|
-
this.push(output);
|
|
142
|
-
callback(null);
|
|
143
|
-
} catch (err) {
|
|
144
|
-
callback(err);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
/* 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/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":["createLzma2Decoder","createLzmaDecoder","properties","length","Error","dictSize","parseLzma2DictionarySize","decoder","LzmaDecoder","setDictionarySize","propsSet","pending","finished","Transform","transform","chunk","_encoding","callback","input","Buffer","concat","offset","result","hasCompleteChunk","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","unpackSize","setDecoderProperties","chunks","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