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,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Synchronous LZMA2 Decoder
|
|
3
|
-
*
|
|
4
|
-
* LZMA2 is a container format that wraps LZMA chunks with framing.
|
|
5
|
-
* Decodes LZMA2 data from a buffer.
|
|
6
|
-
*/ import { allocBufferUnsafe } from 'extract-base-iterator';
|
|
7
|
-
import { parseLzma2ChunkHeader } from '../Lzma2ChunkParser.js';
|
|
8
|
-
import { parseLzma2DictionarySize } from '../types.js';
|
|
9
|
-
import { LzmaDecoder } from './LzmaDecoder.js';
|
|
10
|
-
/**
|
|
11
|
-
* Synchronous LZMA2 decoder
|
|
12
|
-
*/ export class Lzma2Decoder {
|
|
13
|
-
/**
|
|
14
|
-
* Decode LZMA2 data
|
|
15
|
-
* @param input - LZMA2 compressed data
|
|
16
|
-
* @param unpackSize - Expected output size (optional, for pre-allocation)
|
|
17
|
-
* @returns Decompressed data
|
|
18
|
-
*/ decode(input, unpackSize) {
|
|
19
|
-
// Pre-allocate output buffer if size is known
|
|
20
|
-
let outputBuffer = null;
|
|
21
|
-
let outputPos = 0;
|
|
22
|
-
const outputChunks = [];
|
|
23
|
-
if (unpackSize && unpackSize > 0) {
|
|
24
|
-
outputBuffer = allocBufferUnsafe(unpackSize);
|
|
25
|
-
}
|
|
26
|
-
let offset = 0;
|
|
27
|
-
while(offset < input.length){
|
|
28
|
-
const result = parseLzma2ChunkHeader(input, offset);
|
|
29
|
-
if (!result.success) {
|
|
30
|
-
throw new Error('Truncated LZMA2 chunk header');
|
|
31
|
-
}
|
|
32
|
-
const chunk = result.chunk;
|
|
33
|
-
if (chunk.type === 'end') {
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
// Validate we have enough data for the chunk
|
|
37
|
-
const dataSize = chunk.type === 'uncompressed' ? chunk.uncompSize : chunk.compSize;
|
|
38
|
-
if (offset + chunk.headerSize + dataSize > input.length) {
|
|
39
|
-
throw new Error(`Truncated LZMA2 ${chunk.type} data`);
|
|
40
|
-
}
|
|
41
|
-
// Handle dictionary reset
|
|
42
|
-
if (chunk.dictReset) {
|
|
43
|
-
this.lzmaDecoder.resetDictionary();
|
|
44
|
-
}
|
|
45
|
-
const dataOffset = offset + chunk.headerSize;
|
|
46
|
-
if (chunk.type === 'uncompressed') {
|
|
47
|
-
const uncompData = input.slice(dataOffset, dataOffset + chunk.uncompSize);
|
|
48
|
-
// Copy to output
|
|
49
|
-
if (outputBuffer) {
|
|
50
|
-
uncompData.copy(outputBuffer, outputPos);
|
|
51
|
-
outputPos += uncompData.length;
|
|
52
|
-
} else {
|
|
53
|
-
outputChunks.push(uncompData);
|
|
54
|
-
}
|
|
55
|
-
// Feed uncompressed data to dictionary so subsequent LZMA chunks can reference it
|
|
56
|
-
this.lzmaDecoder.feedUncompressed(uncompData);
|
|
57
|
-
offset = dataOffset + chunk.uncompSize;
|
|
58
|
-
} else {
|
|
59
|
-
// LZMA compressed chunk
|
|
60
|
-
// Apply new properties if present
|
|
61
|
-
if (chunk.newProps) {
|
|
62
|
-
const { lc, lp, pb } = chunk.newProps;
|
|
63
|
-
if (!this.lzmaDecoder.setLcLpPb(lc, lp, pb)) {
|
|
64
|
-
throw new Error(`Invalid LZMA properties: lc=${lc} lp=${lp} pb=${pb}`);
|
|
65
|
-
}
|
|
66
|
-
this.propsSet = true;
|
|
67
|
-
}
|
|
68
|
-
if (!this.propsSet) {
|
|
69
|
-
throw new Error('LZMA chunk without properties');
|
|
70
|
-
}
|
|
71
|
-
// Reset probabilities if state reset
|
|
72
|
-
if (chunk.stateReset) {
|
|
73
|
-
this.lzmaDecoder.resetProbabilities();
|
|
74
|
-
}
|
|
75
|
-
// Determine solid mode - preserve dictionary if not resetting state or if only resetting state (not dict)
|
|
76
|
-
const useSolid = !chunk.stateReset || chunk.stateReset && !chunk.dictReset;
|
|
77
|
-
// Decode LZMA chunk
|
|
78
|
-
const chunkData = input.slice(dataOffset, dataOffset + chunk.compSize);
|
|
79
|
-
const decoded = this.lzmaDecoder.decode(chunkData, 0, chunk.uncompSize, useSolid);
|
|
80
|
-
// Copy to output
|
|
81
|
-
if (outputBuffer) {
|
|
82
|
-
decoded.copy(outputBuffer, outputPos);
|
|
83
|
-
outputPos += decoded.length;
|
|
84
|
-
} else {
|
|
85
|
-
outputChunks.push(decoded);
|
|
86
|
-
}
|
|
87
|
-
offset = dataOffset + chunk.compSize;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
// Return pre-allocated buffer or concatenated chunks
|
|
91
|
-
if (outputBuffer) {
|
|
92
|
-
return outputPos < outputBuffer.length ? outputBuffer.slice(0, outputPos) : outputBuffer;
|
|
93
|
-
}
|
|
94
|
-
return Buffer.concat(outputChunks);
|
|
95
|
-
}
|
|
96
|
-
constructor(properties){
|
|
97
|
-
if (!properties || properties.length < 1) {
|
|
98
|
-
throw new Error('LZMA2 requires properties byte');
|
|
99
|
-
}
|
|
100
|
-
this.dictionarySize = parseLzma2DictionarySize(properties[0]);
|
|
101
|
-
this.lzmaDecoder = new LzmaDecoder();
|
|
102
|
-
this.lzmaDecoder.setDictionarySize(this.dictionarySize);
|
|
103
|
-
this.propsSet = false;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Decode LZMA2 data synchronously
|
|
108
|
-
* @param input - LZMA2 compressed data
|
|
109
|
-
* @param properties - 1-byte properties (dictionary size)
|
|
110
|
-
* @param unpackSize - Expected output size (optional)
|
|
111
|
-
* @returns Decompressed data
|
|
112
|
-
*/ export function decodeLzma2(input, properties, unpackSize) {
|
|
113
|
-
const decoder = new Lzma2Decoder(properties);
|
|
114
|
-
return decoder.decode(input, unpackSize);
|
|
115
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/7z-iterator/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 { 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) {\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();\n this.lzmaDecoder.setDictionarySize(this.dictionarySize);\n this.propsSet = false;\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)\n * @returns Decompressed data\n */\nexport function decodeLzma2(input: Buffer, properties: Buffer | Uint8Array, unpackSize?: number): Buffer {\n const decoder = new Lzma2Decoder(properties);\n return decoder.decode(input, unpackSize);\n}\n"],"names":["allocBufferUnsafe","parseLzma2ChunkHeader","parseLzma2DictionarySize","LzmaDecoder","Lzma2Decoder","decode","input","unpackSize","outputBuffer","outputPos","outputChunks","offset","length","result","success","Error","chunk","type","dataSize","uncompSize","compSize","headerSize","dictReset","lzmaDecoder","resetDictionary","dataOffset","uncompData","slice","copy","push","feedUncompressed","newProps","lc","lp","pb","setLcLpPb","propsSet","stateReset","resetProbabilities","useSolid","chunkData","decoded","Buffer","concat","properties","dictionarySize","setDictionarySize","decodeLzma2","decoder"],"mappings":"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"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Synchronous LZMA1 Decoder
|
|
3
|
-
*
|
|
4
|
-
* Decodes LZMA1 compressed data from a buffer.
|
|
5
|
-
* All operations are synchronous.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Synchronous LZMA1 decoder
|
|
9
|
-
*/
|
|
10
|
-
export declare class LzmaDecoder {
|
|
11
|
-
private outWindow;
|
|
12
|
-
private rangeDecoder;
|
|
13
|
-
private isMatchDecoders;
|
|
14
|
-
private isRepDecoders;
|
|
15
|
-
private isRepG0Decoders;
|
|
16
|
-
private isRepG1Decoders;
|
|
17
|
-
private isRepG2Decoders;
|
|
18
|
-
private isRep0LongDecoders;
|
|
19
|
-
private posSlotDecoder;
|
|
20
|
-
private posDecoders;
|
|
21
|
-
private posAlignDecoder;
|
|
22
|
-
private lenDecoder;
|
|
23
|
-
private repLenDecoder;
|
|
24
|
-
private literalDecoder;
|
|
25
|
-
private dictionarySize;
|
|
26
|
-
private dictionarySizeCheck;
|
|
27
|
-
private posStateMask;
|
|
28
|
-
private state;
|
|
29
|
-
private rep0;
|
|
30
|
-
private rep1;
|
|
31
|
-
private rep2;
|
|
32
|
-
private rep3;
|
|
33
|
-
private prevByte;
|
|
34
|
-
private totalPos;
|
|
35
|
-
constructor();
|
|
36
|
-
/**
|
|
37
|
-
* Set dictionary size
|
|
38
|
-
*/
|
|
39
|
-
setDictionarySize(dictionarySize: number): boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Set lc, lp, pb properties
|
|
42
|
-
*/
|
|
43
|
-
setLcLpPb(lc: number, lp: number, pb: number): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Set decoder properties from 5-byte buffer
|
|
46
|
-
*/
|
|
47
|
-
setDecoderProperties(properties: Buffer | Uint8Array): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Initialize probability tables
|
|
50
|
-
*/
|
|
51
|
-
private initProbabilities;
|
|
52
|
-
/**
|
|
53
|
-
* Reset probabilities only (for LZMA2 state reset)
|
|
54
|
-
*/
|
|
55
|
-
resetProbabilities(): void;
|
|
56
|
-
/**
|
|
57
|
-
* Reset dictionary position (for LZMA2 dictionary reset)
|
|
58
|
-
*/
|
|
59
|
-
resetDictionary(): void;
|
|
60
|
-
/**
|
|
61
|
-
* Feed uncompressed data into the dictionary (for LZMA2 uncompressed chunks)
|
|
62
|
-
* This updates the sliding window so subsequent LZMA chunks can reference this data.
|
|
63
|
-
*/
|
|
64
|
-
feedUncompressed(data: Buffer): void;
|
|
65
|
-
/**
|
|
66
|
-
* Decode LZMA data
|
|
67
|
-
* @param input - Compressed input buffer
|
|
68
|
-
* @param inputOffset - Offset into input buffer
|
|
69
|
-
* @param outSize - Expected output size
|
|
70
|
-
* @param solid - If true, preserve state from previous decode
|
|
71
|
-
* @returns Decompressed data
|
|
72
|
-
*/
|
|
73
|
-
decode(input: Buffer, inputOffset: number, outSize: number, solid?: boolean): Buffer;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Decode LZMA1 data synchronously
|
|
77
|
-
* @param input - Compressed data (without 5-byte properties header)
|
|
78
|
-
* @param properties - 5-byte LZMA properties
|
|
79
|
-
* @param outSize - Expected output size
|
|
80
|
-
* @returns Decompressed data
|
|
81
|
-
*/
|
|
82
|
-
export declare function decodeLzma(input: Buffer, properties: Buffer | Uint8Array, outSize: number): Buffer;
|
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Synchronous LZMA1 Decoder
|
|
3
|
-
*
|
|
4
|
-
* Decodes LZMA1 compressed data from a buffer.
|
|
5
|
-
* All operations are synchronous.
|
|
6
|
-
*/ import { allocBufferUnsafe } from 'extract-base-iterator';
|
|
7
|
-
import { getLenToPosState, initBitModels, kEndPosModelIndex, kMatchMinLen, kNumAlignBits, kNumFullDistances, kNumLenToPosStates, kNumLitContextBitsMax, kNumPosSlotBits, kNumPosStatesBitsMax, kNumStates, kStartPosModelIndex, parseProperties, stateIsCharState, stateUpdateChar, stateUpdateMatch, stateUpdateRep, stateUpdateShortRep } from '../types.js';
|
|
8
|
-
import { BitTreeDecoder, RangeDecoder, reverseDecodeFromArray } from './RangeDecoder.js';
|
|
9
|
-
/**
|
|
10
|
-
* Length decoder for match/rep lengths
|
|
11
|
-
*/ let LenDecoder = class LenDecoder {
|
|
12
|
-
create(numPosStates) {
|
|
13
|
-
for(; this.numPosStates < numPosStates; this.numPosStates++){
|
|
14
|
-
this.lowCoder[this.numPosStates] = new BitTreeDecoder(3);
|
|
15
|
-
this.midCoder[this.numPosStates] = new BitTreeDecoder(3);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
init() {
|
|
19
|
-
initBitModels(this.choice);
|
|
20
|
-
for(let i = this.numPosStates - 1; i >= 0; i--){
|
|
21
|
-
this.lowCoder[i].init();
|
|
22
|
-
this.midCoder[i].init();
|
|
23
|
-
}
|
|
24
|
-
this.highCoder.init();
|
|
25
|
-
}
|
|
26
|
-
decode(rangeDecoder, posState) {
|
|
27
|
-
if (rangeDecoder.decodeBit(this.choice, 0) === 0) {
|
|
28
|
-
return this.lowCoder[posState].decode(rangeDecoder);
|
|
29
|
-
}
|
|
30
|
-
if (rangeDecoder.decodeBit(this.choice, 1) === 0) {
|
|
31
|
-
return 8 + this.midCoder[posState].decode(rangeDecoder);
|
|
32
|
-
}
|
|
33
|
-
return 16 + this.highCoder.decode(rangeDecoder);
|
|
34
|
-
}
|
|
35
|
-
constructor(){
|
|
36
|
-
this.choice = initBitModels(null, 2);
|
|
37
|
-
this.lowCoder = [];
|
|
38
|
-
this.midCoder = [];
|
|
39
|
-
this.highCoder = new BitTreeDecoder(8);
|
|
40
|
-
this.numPosStates = 0;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Single literal decoder (decodes one byte)
|
|
45
|
-
*/ let LiteralDecoder2 = class LiteralDecoder2 {
|
|
46
|
-
init() {
|
|
47
|
-
initBitModels(this.decoders);
|
|
48
|
-
}
|
|
49
|
-
decodeNormal(rangeDecoder) {
|
|
50
|
-
let symbol = 1;
|
|
51
|
-
do {
|
|
52
|
-
symbol = symbol << 1 | rangeDecoder.decodeBit(this.decoders, symbol);
|
|
53
|
-
}while (symbol < 0x100)
|
|
54
|
-
return symbol & 0xff;
|
|
55
|
-
}
|
|
56
|
-
decodeWithMatchByte(rangeDecoder, matchByte) {
|
|
57
|
-
let symbol = 1;
|
|
58
|
-
do {
|
|
59
|
-
const matchBit = matchByte >> 7 & 1;
|
|
60
|
-
matchByte <<= 1;
|
|
61
|
-
const bit = rangeDecoder.decodeBit(this.decoders, (1 + matchBit << 8) + symbol);
|
|
62
|
-
symbol = symbol << 1 | bit;
|
|
63
|
-
if (matchBit !== bit) {
|
|
64
|
-
while(symbol < 0x100){
|
|
65
|
-
symbol = symbol << 1 | rangeDecoder.decodeBit(this.decoders, symbol);
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
}while (symbol < 0x100)
|
|
70
|
-
return symbol & 0xff;
|
|
71
|
-
}
|
|
72
|
-
constructor(){
|
|
73
|
-
this.decoders = initBitModels(null, 0x300);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Literal decoder (array of single decoders)
|
|
78
|
-
*/ let LiteralDecoder = class LiteralDecoder {
|
|
79
|
-
create(numPosBits, numPrevBits) {
|
|
80
|
-
if (this.coders.length > 0 && this.numPrevBits === numPrevBits && this.numPosBits === numPosBits) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
this.numPosBits = numPosBits;
|
|
84
|
-
this.posMask = (1 << numPosBits) - 1;
|
|
85
|
-
this.numPrevBits = numPrevBits;
|
|
86
|
-
this.coders = [];
|
|
87
|
-
}
|
|
88
|
-
init() {
|
|
89
|
-
for(let i = 0; i < this.coders.length; i++){
|
|
90
|
-
if (this.coders[i]) {
|
|
91
|
-
var _this_coders_i;
|
|
92
|
-
(_this_coders_i = this.coders[i]) === null || _this_coders_i === void 0 ? void 0 : _this_coders_i.init();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
getDecoder(pos, prevByte) {
|
|
97
|
-
const index = ((pos & this.posMask) << this.numPrevBits) + ((prevByte & 0xff) >>> 8 - this.numPrevBits);
|
|
98
|
-
let decoder = this.coders[index];
|
|
99
|
-
if (!decoder) {
|
|
100
|
-
decoder = new LiteralDecoder2();
|
|
101
|
-
this.coders[index] = decoder;
|
|
102
|
-
}
|
|
103
|
-
return decoder;
|
|
104
|
-
}
|
|
105
|
-
constructor(){
|
|
106
|
-
this.numPosBits = 0;
|
|
107
|
-
this.numPrevBits = 0;
|
|
108
|
-
this.posMask = 0;
|
|
109
|
-
this.coders = [];
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* Output window (sliding dictionary)
|
|
114
|
-
*/ let OutWindow = class OutWindow {
|
|
115
|
-
create(windowSize) {
|
|
116
|
-
if (!this.buffer || this.windowSize !== windowSize) {
|
|
117
|
-
this.buffer = allocBufferUnsafe(windowSize);
|
|
118
|
-
}
|
|
119
|
-
this.windowSize = windowSize;
|
|
120
|
-
this.pos = 0;
|
|
121
|
-
}
|
|
122
|
-
init(solid) {
|
|
123
|
-
if (!solid) {
|
|
124
|
-
this.pos = 0;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
putByte(b) {
|
|
128
|
-
this.buffer[this.pos++] = b;
|
|
129
|
-
if (this.pos >= this.windowSize) {
|
|
130
|
-
this.pos = 0;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
getByte(distance) {
|
|
134
|
-
let pos = this.pos - distance - 1;
|
|
135
|
-
if (pos < 0) {
|
|
136
|
-
pos += this.windowSize;
|
|
137
|
-
}
|
|
138
|
-
return this.buffer[pos];
|
|
139
|
-
}
|
|
140
|
-
copyBlock(distance, len) {
|
|
141
|
-
let pos = this.pos - distance - 1;
|
|
142
|
-
if (pos < 0) {
|
|
143
|
-
pos += this.windowSize;
|
|
144
|
-
}
|
|
145
|
-
for(let i = 0; i < len; i++){
|
|
146
|
-
if (pos >= this.windowSize) {
|
|
147
|
-
pos = 0;
|
|
148
|
-
}
|
|
149
|
-
this.putByte(this.buffer[pos++]);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Copy decoded data to output buffer
|
|
154
|
-
*/ copyTo(output, outputOffset, count) {
|
|
155
|
-
const srcPos = this.pos - count;
|
|
156
|
-
if (srcPos < 0) {
|
|
157
|
-
// Wrap around case - data spans end and beginning of buffer
|
|
158
|
-
const firstPart = -srcPos;
|
|
159
|
-
this.buffer.copy(output, outputOffset, this.windowSize + srcPos, this.windowSize);
|
|
160
|
-
this.buffer.copy(output, outputOffset + firstPart, 0, count - firstPart);
|
|
161
|
-
} else {
|
|
162
|
-
this.buffer.copy(output, outputOffset, srcPos, srcPos + count);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
constructor(){
|
|
166
|
-
this.buffer = allocBufferUnsafe(0); // Replaced by create() before use
|
|
167
|
-
this.windowSize = 0;
|
|
168
|
-
this.pos = 0;
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
/**
|
|
172
|
-
* Synchronous LZMA1 decoder
|
|
173
|
-
*/ export class LzmaDecoder {
|
|
174
|
-
/**
|
|
175
|
-
* Set dictionary size
|
|
176
|
-
*/ setDictionarySize(dictionarySize) {
|
|
177
|
-
if (dictionarySize < 0) return false;
|
|
178
|
-
if (this.dictionarySize !== dictionarySize) {
|
|
179
|
-
this.dictionarySize = dictionarySize;
|
|
180
|
-
this.dictionarySizeCheck = Math.max(dictionarySize, 1);
|
|
181
|
-
this.outWindow.create(Math.max(this.dictionarySizeCheck, 1 << 12));
|
|
182
|
-
}
|
|
183
|
-
return true;
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Set lc, lp, pb properties
|
|
187
|
-
*/ setLcLpPb(lc, lp, pb) {
|
|
188
|
-
if (lc > kNumLitContextBitsMax || lp > 4 || pb > kNumPosStatesBitsMax) {
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
const numPosStates = 1 << pb;
|
|
192
|
-
this.literalDecoder.create(lp, lc);
|
|
193
|
-
this.lenDecoder.create(numPosStates);
|
|
194
|
-
this.repLenDecoder.create(numPosStates);
|
|
195
|
-
this.posStateMask = numPosStates - 1;
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Set decoder properties from 5-byte buffer
|
|
200
|
-
*/ setDecoderProperties(properties) {
|
|
201
|
-
const props = parseProperties(properties);
|
|
202
|
-
if (!this.setLcLpPb(props.lc, props.lp, props.pb)) return false;
|
|
203
|
-
return this.setDictionarySize(props.dictionarySize);
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Initialize probability tables
|
|
207
|
-
*/ initProbabilities() {
|
|
208
|
-
initBitModels(this.isMatchDecoders);
|
|
209
|
-
initBitModels(this.isRepDecoders);
|
|
210
|
-
initBitModels(this.isRepG0Decoders);
|
|
211
|
-
initBitModels(this.isRepG1Decoders);
|
|
212
|
-
initBitModels(this.isRepG2Decoders);
|
|
213
|
-
initBitModels(this.isRep0LongDecoders);
|
|
214
|
-
initBitModels(this.posDecoders);
|
|
215
|
-
this.literalDecoder.init();
|
|
216
|
-
for(let i = kNumLenToPosStates - 1; i >= 0; i--){
|
|
217
|
-
this.posSlotDecoder[i].init();
|
|
218
|
-
}
|
|
219
|
-
this.lenDecoder.init();
|
|
220
|
-
this.repLenDecoder.init();
|
|
221
|
-
this.posAlignDecoder.init();
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Reset probabilities only (for LZMA2 state reset)
|
|
225
|
-
*/ resetProbabilities() {
|
|
226
|
-
this.initProbabilities();
|
|
227
|
-
this.state = 0;
|
|
228
|
-
this.rep0 = 0;
|
|
229
|
-
this.rep1 = 0;
|
|
230
|
-
this.rep2 = 0;
|
|
231
|
-
this.rep3 = 0;
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Reset dictionary position (for LZMA2 dictionary reset)
|
|
235
|
-
*/ resetDictionary() {
|
|
236
|
-
this.outWindow.init(false);
|
|
237
|
-
this.totalPos = 0;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Feed uncompressed data into the dictionary (for LZMA2 uncompressed chunks)
|
|
241
|
-
* This updates the sliding window so subsequent LZMA chunks can reference this data.
|
|
242
|
-
*/ feedUncompressed(data) {
|
|
243
|
-
for(let i = 0; i < data.length; i++){
|
|
244
|
-
this.outWindow.putByte(data[i]);
|
|
245
|
-
}
|
|
246
|
-
this.totalPos += data.length;
|
|
247
|
-
if (data.length > 0) {
|
|
248
|
-
this.prevByte = data[data.length - 1];
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Decode LZMA data
|
|
253
|
-
* @param input - Compressed input buffer
|
|
254
|
-
* @param inputOffset - Offset into input buffer
|
|
255
|
-
* @param outSize - Expected output size
|
|
256
|
-
* @param solid - If true, preserve state from previous decode
|
|
257
|
-
* @returns Decompressed data
|
|
258
|
-
*/ decode(input, inputOffset, outSize, solid = false) {
|
|
259
|
-
this.rangeDecoder.setInput(input, inputOffset);
|
|
260
|
-
if (!solid) {
|
|
261
|
-
this.outWindow.init(false);
|
|
262
|
-
this.initProbabilities();
|
|
263
|
-
this.state = 0;
|
|
264
|
-
this.rep0 = 0;
|
|
265
|
-
this.rep1 = 0;
|
|
266
|
-
this.rep2 = 0;
|
|
267
|
-
this.rep3 = 0;
|
|
268
|
-
this.prevByte = 0;
|
|
269
|
-
this.totalPos = 0;
|
|
270
|
-
} else {
|
|
271
|
-
// Solid mode: preserve dictionary state but reinitialize range decoder
|
|
272
|
-
this.outWindow.init(true);
|
|
273
|
-
}
|
|
274
|
-
const output = allocBufferUnsafe(outSize);
|
|
275
|
-
let outPos = 0;
|
|
276
|
-
let cumPos = this.totalPos;
|
|
277
|
-
while(outPos < outSize){
|
|
278
|
-
const posState = cumPos & this.posStateMask;
|
|
279
|
-
if (this.rangeDecoder.decodeBit(this.isMatchDecoders, (this.state << kNumPosStatesBitsMax) + posState) === 0) {
|
|
280
|
-
// Literal
|
|
281
|
-
const decoder2 = this.literalDecoder.getDecoder(cumPos, this.prevByte);
|
|
282
|
-
if (!stateIsCharState(this.state)) {
|
|
283
|
-
this.prevByte = decoder2.decodeWithMatchByte(this.rangeDecoder, this.outWindow.getByte(this.rep0));
|
|
284
|
-
} else {
|
|
285
|
-
this.prevByte = decoder2.decodeNormal(this.rangeDecoder);
|
|
286
|
-
}
|
|
287
|
-
this.outWindow.putByte(this.prevByte);
|
|
288
|
-
output[outPos++] = this.prevByte;
|
|
289
|
-
this.state = stateUpdateChar(this.state);
|
|
290
|
-
cumPos++;
|
|
291
|
-
} else {
|
|
292
|
-
// Match or rep
|
|
293
|
-
let len;
|
|
294
|
-
if (this.rangeDecoder.decodeBit(this.isRepDecoders, this.state) === 1) {
|
|
295
|
-
// Rep match
|
|
296
|
-
len = 0;
|
|
297
|
-
if (this.rangeDecoder.decodeBit(this.isRepG0Decoders, this.state) === 0) {
|
|
298
|
-
if (this.rangeDecoder.decodeBit(this.isRep0LongDecoders, (this.state << kNumPosStatesBitsMax) + posState) === 0) {
|
|
299
|
-
this.state = stateUpdateShortRep(this.state);
|
|
300
|
-
len = 1;
|
|
301
|
-
}
|
|
302
|
-
} else {
|
|
303
|
-
let distance;
|
|
304
|
-
if (this.rangeDecoder.decodeBit(this.isRepG1Decoders, this.state) === 0) {
|
|
305
|
-
distance = this.rep1;
|
|
306
|
-
} else {
|
|
307
|
-
if (this.rangeDecoder.decodeBit(this.isRepG2Decoders, this.state) === 0) {
|
|
308
|
-
distance = this.rep2;
|
|
309
|
-
} else {
|
|
310
|
-
distance = this.rep3;
|
|
311
|
-
this.rep3 = this.rep2;
|
|
312
|
-
}
|
|
313
|
-
this.rep2 = this.rep1;
|
|
314
|
-
}
|
|
315
|
-
this.rep1 = this.rep0;
|
|
316
|
-
this.rep0 = distance;
|
|
317
|
-
}
|
|
318
|
-
if (len === 0) {
|
|
319
|
-
len = kMatchMinLen + this.repLenDecoder.decode(this.rangeDecoder, posState);
|
|
320
|
-
this.state = stateUpdateRep(this.state);
|
|
321
|
-
}
|
|
322
|
-
} else {
|
|
323
|
-
// Normal match
|
|
324
|
-
this.rep3 = this.rep2;
|
|
325
|
-
this.rep2 = this.rep1;
|
|
326
|
-
this.rep1 = this.rep0;
|
|
327
|
-
len = kMatchMinLen + this.lenDecoder.decode(this.rangeDecoder, posState);
|
|
328
|
-
this.state = stateUpdateMatch(this.state);
|
|
329
|
-
const posSlot = this.posSlotDecoder[getLenToPosState(len)].decode(this.rangeDecoder);
|
|
330
|
-
if (posSlot >= kStartPosModelIndex) {
|
|
331
|
-
const numDirectBits = (posSlot >> 1) - 1;
|
|
332
|
-
this.rep0 = (2 | posSlot & 1) << numDirectBits;
|
|
333
|
-
if (posSlot < kEndPosModelIndex) {
|
|
334
|
-
this.rep0 += reverseDecodeFromArray(this.posDecoders, this.rep0 - posSlot - 1, this.rangeDecoder, numDirectBits);
|
|
335
|
-
} else {
|
|
336
|
-
this.rep0 += this.rangeDecoder.decodeDirectBits(numDirectBits - kNumAlignBits) << kNumAlignBits;
|
|
337
|
-
this.rep0 += this.posAlignDecoder.reverseDecode(this.rangeDecoder);
|
|
338
|
-
if (this.rep0 < 0) {
|
|
339
|
-
if (this.rep0 === -1) break; // End marker
|
|
340
|
-
throw new Error('LZMA: Invalid distance');
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
} else {
|
|
344
|
-
this.rep0 = posSlot;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
if (this.rep0 >= cumPos || this.rep0 >= this.dictionarySizeCheck) {
|
|
348
|
-
throw new Error('LZMA: Invalid distance');
|
|
349
|
-
}
|
|
350
|
-
// Copy match bytes
|
|
351
|
-
for(let i = 0; i < len; i++){
|
|
352
|
-
const b = this.outWindow.getByte(this.rep0);
|
|
353
|
-
this.outWindow.putByte(b);
|
|
354
|
-
output[outPos++] = b;
|
|
355
|
-
}
|
|
356
|
-
cumPos += len;
|
|
357
|
-
this.prevByte = this.outWindow.getByte(0);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
this.totalPos = cumPos;
|
|
361
|
-
return output;
|
|
362
|
-
}
|
|
363
|
-
constructor(){
|
|
364
|
-
this.outWindow = new OutWindow();
|
|
365
|
-
this.rangeDecoder = new RangeDecoder();
|
|
366
|
-
this.isMatchDecoders = initBitModels(null, kNumStates << kNumPosStatesBitsMax);
|
|
367
|
-
this.isRepDecoders = initBitModels(null, kNumStates);
|
|
368
|
-
this.isRepG0Decoders = initBitModels(null, kNumStates);
|
|
369
|
-
this.isRepG1Decoders = initBitModels(null, kNumStates);
|
|
370
|
-
this.isRepG2Decoders = initBitModels(null, kNumStates);
|
|
371
|
-
this.isRep0LongDecoders = initBitModels(null, kNumStates << kNumPosStatesBitsMax);
|
|
372
|
-
this.posSlotDecoder = [];
|
|
373
|
-
this.posDecoders = initBitModels(null, kNumFullDistances - kEndPosModelIndex);
|
|
374
|
-
this.posAlignDecoder = new BitTreeDecoder(kNumAlignBits);
|
|
375
|
-
this.lenDecoder = new LenDecoder();
|
|
376
|
-
this.repLenDecoder = new LenDecoder();
|
|
377
|
-
this.literalDecoder = new LiteralDecoder();
|
|
378
|
-
for(let i = 0; i < kNumLenToPosStates; i++){
|
|
379
|
-
this.posSlotDecoder[i] = new BitTreeDecoder(kNumPosSlotBits);
|
|
380
|
-
}
|
|
381
|
-
this.dictionarySize = -1;
|
|
382
|
-
this.dictionarySizeCheck = -1;
|
|
383
|
-
this.posStateMask = 0;
|
|
384
|
-
this.state = 0;
|
|
385
|
-
this.rep0 = 0;
|
|
386
|
-
this.rep1 = 0;
|
|
387
|
-
this.rep2 = 0;
|
|
388
|
-
this.rep3 = 0;
|
|
389
|
-
this.prevByte = 0;
|
|
390
|
-
this.totalPos = 0;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Decode LZMA1 data synchronously
|
|
395
|
-
* @param input - Compressed data (without 5-byte properties header)
|
|
396
|
-
* @param properties - 5-byte LZMA properties
|
|
397
|
-
* @param outSize - Expected output size
|
|
398
|
-
* @returns Decompressed data
|
|
399
|
-
*/ export function decodeLzma(input, properties, outSize) {
|
|
400
|
-
const decoder = new LzmaDecoder();
|
|
401
|
-
decoder.setDecoderProperties(properties);
|
|
402
|
-
return decoder.decode(input, 0, outSize, false);
|
|
403
|
-
}
|