lzma1 0.2.0 → 0.3.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/README.md +10 -3
- package/lib/decoder.js +84 -85
- package/lib/encoder.js +794 -143
- package/lib/index.js +0 -1
- package/lib/lz-window.js +3 -4
- package/lib/lzma.js +50 -1383
- package/lib/match-finder.js +402 -0
- package/lib/range-decoder.js +3 -16
- package/lib/range-encoder.js +14 -24
- package/lib/streams.js +64 -1
- package/lib/utils.js +4 -102
- package/package.json +24 -13
- package/src/decoder.ts +604 -0
- package/src/encoder.ts +2108 -0
- package/src/index.ts +71 -0
- package/src/len-coder.ts +217 -0
- package/src/lit-coder.ts +196 -0
- package/src/lz-window.ts +99 -0
- package/src/lzma.ts +142 -0
- package/src/match-finder.ts +548 -0
- package/src/range-bit-tree-coder.ts +109 -0
- package/src/range-decoder.ts +98 -0
- package/src/range-encoder.ts +136 -0
- package/src/streams.ts +73 -0
- package/src/utils.ts +263 -0
- package/lib/chunker.d.ts +0 -46
- package/lib/chunker.js +0 -68
- package/lib/decoder.d.ts +0 -80
- package/lib/encoder.d.ts +0 -266
- package/lib/index.d.ts +0 -38
- package/lib/len-coder.d.ts +0 -70
- package/lib/lit-coder.d.ts +0 -63
- package/lib/lz-in-window.d.ts +0 -43
- package/lib/lz-in-window.js +0 -132
- package/lib/lz-window.d.ts +0 -35
- package/lib/lzma.d.ts +0 -107
- package/lib/match-finder-config.d.ts +0 -34
- package/lib/match-finder-config.js +0 -63
- package/lib/range-bit-tree-coder.d.ts +0 -34
- package/lib/range-decoder.d.ts +0 -34
- package/lib/range-encoder.d.ts +0 -46
- package/lib/streams.d.ts +0 -32
- package/lib/utils.d.ts +0 -127
package/lib/decoder.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { LzOutWindow } from "./lz-window.js";
|
|
2
|
-
import { RangeDecoder } from "./range-decoder.js";
|
|
3
|
-
import type { BaseStream, BufferWithCount } from "./streams.js";
|
|
4
|
-
import { type BitTree } from "./utils.js";
|
|
5
|
-
interface LenDecoder {
|
|
6
|
-
choice: number[];
|
|
7
|
-
lowCoder: BitTree[];
|
|
8
|
-
midCoder: BitTree[];
|
|
9
|
-
highCoder: BitTree;
|
|
10
|
-
numPosStates: number;
|
|
11
|
-
}
|
|
12
|
-
interface LiteralCoder {
|
|
13
|
-
coders: any[];
|
|
14
|
-
numPrevBits: number;
|
|
15
|
-
numPosBits: number;
|
|
16
|
-
posMask: number;
|
|
17
|
-
init?(): void;
|
|
18
|
-
}
|
|
19
|
-
export declare class Decoder {
|
|
20
|
-
rangeDecoder: RangeDecoder;
|
|
21
|
-
outWindow: LzOutWindow;
|
|
22
|
-
state: number;
|
|
23
|
-
rep0: number;
|
|
24
|
-
rep1: number;
|
|
25
|
-
rep2: number;
|
|
26
|
-
rep3: number;
|
|
27
|
-
prevByte: number;
|
|
28
|
-
nowPos64: [number, number];
|
|
29
|
-
outSize: [number, number];
|
|
30
|
-
posStateMask: number;
|
|
31
|
-
dictSizeCheck: number;
|
|
32
|
-
matchDecoders: number[];
|
|
33
|
-
rep0LongDecoders: number[];
|
|
34
|
-
repDecoders: number[];
|
|
35
|
-
repG0Decoders: number[];
|
|
36
|
-
repG1Decoders: number[];
|
|
37
|
-
repG2Decoders: number[];
|
|
38
|
-
posDecoders: number[];
|
|
39
|
-
literalDecoder: LiteralCoder;
|
|
40
|
-
posSlotDecoders: BitTree[];
|
|
41
|
-
lenDecoder: LenDecoder;
|
|
42
|
-
repLenDecoder: LenDecoder;
|
|
43
|
-
posAlignDecoder: BitTree;
|
|
44
|
-
get literalCoder(): LiteralCoder;
|
|
45
|
-
decoder: Decoder;
|
|
46
|
-
encoder: null;
|
|
47
|
-
alive: number;
|
|
48
|
-
inBytesProcessed: [number, number];
|
|
49
|
-
constructor();
|
|
50
|
-
createLenDecoder(): LenDecoder;
|
|
51
|
-
setDecoderProperties(properties: number[]): boolean;
|
|
52
|
-
copyBlock(len: number): void;
|
|
53
|
-
putByte(b: number): void;
|
|
54
|
-
getByte(distance: number): number;
|
|
55
|
-
getDecoder(pos: number, prevByte: number): any;
|
|
56
|
-
initLiteralDecoder(): void;
|
|
57
|
-
init(): void;
|
|
58
|
-
initLenDecoder(decoder: LenDecoder): void;
|
|
59
|
-
outWindowReleaseStream(): void;
|
|
60
|
-
decodeBit(probs: number[], index: number): 0 | 1;
|
|
61
|
-
decodeDirectBits(numTotalBits: number): number;
|
|
62
|
-
initRangeDecoder(): void;
|
|
63
|
-
rangeBitTreeDecoder(bitTree: BitTree): number;
|
|
64
|
-
reverseDecode(models: number[], startIndex: number, numBitLevels: number): number;
|
|
65
|
-
reverseDecodeAlignDecoder(): number;
|
|
66
|
-
decodeNormalWithRangeDecoder(decoder: any): number;
|
|
67
|
-
decodeWithMatchByteWithRangeDecoder(encoder: any, matchByte: number): number;
|
|
68
|
-
decodeLenWithRangeDecoder(decoder: LenDecoder, posState: number): number;
|
|
69
|
-
codeOneChunk(): 0 | 1 | -1;
|
|
70
|
-
setupForDecoding(inStream: BaseStream, outSize: [number, number], outputBuffer: BufferWithCount): void;
|
|
71
|
-
processChunk(): number;
|
|
72
|
-
writeToOutput(buffer: BufferWithCount, data: number[], offset: number, length: number): void;
|
|
73
|
-
private isBufferWithCount;
|
|
74
|
-
flush(): void;
|
|
75
|
-
/**
|
|
76
|
-
* Cleanup decoder resources
|
|
77
|
-
*/
|
|
78
|
-
cleanup(): void;
|
|
79
|
-
}
|
|
80
|
-
export {};
|
package/lib/encoder.d.ts
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import { LenEncoder, type RangeEncoder as LenRangeEncoder } from "./len-coder.js";
|
|
2
|
-
import { LitCoder } from "./lit-coder.js";
|
|
3
|
-
import type { BaseStream } from "./streams.js";
|
|
4
|
-
import type { LiteralDecoderEncoder2 } from "./utils.js";
|
|
5
|
-
import { type BitTree } from "./utils.js";
|
|
6
|
-
export interface MatchFinder {
|
|
7
|
-
_posLimit: number;
|
|
8
|
-
_bufferBase: number[];
|
|
9
|
-
_pos: number;
|
|
10
|
-
_streamPos: number;
|
|
11
|
-
_streamEndWasReached: number;
|
|
12
|
-
_bufferOffset: number;
|
|
13
|
-
_blockSize: number;
|
|
14
|
-
_keepSizeBefore: number;
|
|
15
|
-
_keepSizeAfter: number;
|
|
16
|
-
_pointerToLastSafePosition: number;
|
|
17
|
-
_stream: BaseStream | null;
|
|
18
|
-
HASH_ARRAY: boolean;
|
|
19
|
-
kNumHashDirectBytes: number;
|
|
20
|
-
kMinMatchCheck: number;
|
|
21
|
-
kFixHashSize: number;
|
|
22
|
-
_hashMask: number;
|
|
23
|
-
_hashSizeSum: number;
|
|
24
|
-
_hash: number[];
|
|
25
|
-
_cyclicBufferSize: number;
|
|
26
|
-
_cyclicBufferPos: number;
|
|
27
|
-
_son: number[];
|
|
28
|
-
_matchMaxLen: number;
|
|
29
|
-
_cutValue: number;
|
|
30
|
-
}
|
|
31
|
-
export interface Optimum {
|
|
32
|
-
state?: number;
|
|
33
|
-
price?: number;
|
|
34
|
-
posPrev?: number;
|
|
35
|
-
backPrev?: number;
|
|
36
|
-
prev1IsChar?: number;
|
|
37
|
-
prev2?: number;
|
|
38
|
-
posPrev2?: number;
|
|
39
|
-
backPrev2?: number;
|
|
40
|
-
backs0?: number;
|
|
41
|
-
backs1?: number;
|
|
42
|
-
backs2?: number;
|
|
43
|
-
backs3?: number;
|
|
44
|
-
}
|
|
45
|
-
interface RangeEncoder {
|
|
46
|
-
stream: {
|
|
47
|
-
buf: number[];
|
|
48
|
-
count: number;
|
|
49
|
-
} | null;
|
|
50
|
-
rrange: number;
|
|
51
|
-
cache: number;
|
|
52
|
-
low: [number, number];
|
|
53
|
-
cacheSize: number;
|
|
54
|
-
position: [number, number];
|
|
55
|
-
encodeBit(probs: number[], index: number, bit: number): void;
|
|
56
|
-
encodeBitTree(tree: BitTree, symbol: number): void;
|
|
57
|
-
encodeDirectBits(value: number, bits: number): void;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* LZMA Encoder class that handles compression operations
|
|
61
|
-
*/
|
|
62
|
-
export declare class Encoder implements LenRangeEncoder {
|
|
63
|
-
private encoderState;
|
|
64
|
-
private positionEncoder;
|
|
65
|
-
_state: number;
|
|
66
|
-
_previousByte: number;
|
|
67
|
-
_distTableSize: number;
|
|
68
|
-
_longestMatchWasFound: number;
|
|
69
|
-
_optimumEndIndex: number;
|
|
70
|
-
_optimumCurrentIndex: number;
|
|
71
|
-
_additionalOffset: number;
|
|
72
|
-
_dictionarySize: number;
|
|
73
|
-
_matchFinder: MatchFinder | null;
|
|
74
|
-
_dictionarySizePrev: number;
|
|
75
|
-
_numFastBytes: number;
|
|
76
|
-
_numLiteralContextBits: number;
|
|
77
|
-
_numLiteralPosStateBits: number;
|
|
78
|
-
_posStateBits: number;
|
|
79
|
-
_posStateMask: number;
|
|
80
|
-
_needReleaseMFStream: number;
|
|
81
|
-
_inStream: BaseStream | null;
|
|
82
|
-
_finished: number;
|
|
83
|
-
nowPos64: [number, number];
|
|
84
|
-
_repDistances: number[];
|
|
85
|
-
_optimum: Optimum[];
|
|
86
|
-
_rangeEncoder: RangeEncoder;
|
|
87
|
-
_isMatch: number[];
|
|
88
|
-
_isRep: number[];
|
|
89
|
-
_isRepG0: number[];
|
|
90
|
-
_isRepG1: number[];
|
|
91
|
-
_isRepG2: number[];
|
|
92
|
-
_isRep0Long: number[];
|
|
93
|
-
_posSlotEncoder: BitTree[];
|
|
94
|
-
_posEncoders: number[];
|
|
95
|
-
_posAlignEncoder: BitTree | null;
|
|
96
|
-
_lenEncoder: LenEncoder | null;
|
|
97
|
-
_repMatchLenEncoder: LenEncoder | null;
|
|
98
|
-
_literalEncoder: LitCoder | null;
|
|
99
|
-
_matchDistances: number[];
|
|
100
|
-
_posSlotPrices: number[];
|
|
101
|
-
_distancesPrices: number[];
|
|
102
|
-
_alignPrices: number[];
|
|
103
|
-
_matchPriceCount: number;
|
|
104
|
-
_alignPriceCount: number;
|
|
105
|
-
reps: number[];
|
|
106
|
-
repLens: number[];
|
|
107
|
-
processedInSize: [number, number][];
|
|
108
|
-
processedOutSize: [number, number][];
|
|
109
|
-
finished: number[];
|
|
110
|
-
properties: number[];
|
|
111
|
-
tempPrices: number[];
|
|
112
|
-
_longestMatchLength: number;
|
|
113
|
-
_matchFinderType: number;
|
|
114
|
-
_numDistancePairs: number;
|
|
115
|
-
_numFastBytesPrev: number;
|
|
116
|
-
backRes: number;
|
|
117
|
-
constructor();
|
|
118
|
-
/**
|
|
119
|
-
* Initialize basic encoder state
|
|
120
|
-
*/
|
|
121
|
-
baseInit(): void;
|
|
122
|
-
/**
|
|
123
|
-
* Get optimum array
|
|
124
|
-
*/
|
|
125
|
-
getOptimum(): Optimum[];
|
|
126
|
-
/**
|
|
127
|
-
* Get back result
|
|
128
|
-
*/
|
|
129
|
-
getBackRes(): number;
|
|
130
|
-
setBackRes(backRes: number): void;
|
|
131
|
-
init(): void;
|
|
132
|
-
/**
|
|
133
|
-
* Initialize encoder range coder
|
|
134
|
-
*/
|
|
135
|
-
initEncoderState(): void;
|
|
136
|
-
/**
|
|
137
|
-
* Initialize literal encoder
|
|
138
|
-
*/
|
|
139
|
-
initLiteralEncoder(): void;
|
|
140
|
-
/**
|
|
141
|
-
* Create optimum structures
|
|
142
|
-
*/
|
|
143
|
-
createOptimumStructures(): void;
|
|
144
|
-
/**
|
|
145
|
-
* Create length price table encoder
|
|
146
|
-
*/
|
|
147
|
-
createLenPriceTableEncoder(): LenEncoder;
|
|
148
|
-
/**
|
|
149
|
-
* Create literal encoder encoder2
|
|
150
|
-
*/
|
|
151
|
-
createLiteralEncoderEncoder2(): LiteralDecoderEncoder2;
|
|
152
|
-
/**
|
|
153
|
-
* Create literal encoder
|
|
154
|
-
*/
|
|
155
|
-
createLiteralEncoder(): void;
|
|
156
|
-
/**
|
|
157
|
-
* Initialize completely with proper encoder state
|
|
158
|
-
*/
|
|
159
|
-
initialize(): void;
|
|
160
|
-
/**
|
|
161
|
-
* Configure encoder settings
|
|
162
|
-
*/
|
|
163
|
-
configure(mode: {
|
|
164
|
-
searchDepth: number;
|
|
165
|
-
filterStrength: number;
|
|
166
|
-
modeIndex: number;
|
|
167
|
-
}): void;
|
|
168
|
-
/**
|
|
169
|
-
* Set dictionary size
|
|
170
|
-
*/
|
|
171
|
-
setDictionarySize(dictionarySize: number): void;
|
|
172
|
-
/**
|
|
173
|
-
* Encode a bit using range coder
|
|
174
|
-
*/
|
|
175
|
-
encodeBit(probs: number[], index: number, symbol: number): void;
|
|
176
|
-
/**
|
|
177
|
-
* Encode bit tree
|
|
178
|
-
*/
|
|
179
|
-
encodeBitTree(encoder: BitTree, symbol: number): void;
|
|
180
|
-
/**
|
|
181
|
-
* Encode literal
|
|
182
|
-
*/
|
|
183
|
-
encodeLiteral(encoder: LiteralDecoderEncoder2, symbol: number): void;
|
|
184
|
-
/**
|
|
185
|
-
* Encode matched literal
|
|
186
|
-
*/
|
|
187
|
-
encodeMatched(encoder: LiteralDecoderEncoder2, matchByte: number, symbol: number): void;
|
|
188
|
-
/**
|
|
189
|
-
* Encode length using direct method calls
|
|
190
|
-
*/
|
|
191
|
-
encodeLength(encoder: LenEncoder, symbol: number, posState: number): void;
|
|
192
|
-
/**
|
|
193
|
-
* Encode direct bits
|
|
194
|
-
*/
|
|
195
|
-
encodeDirectBits(valueToEncode: number, numTotalBits: number): void;
|
|
196
|
-
/**
|
|
197
|
-
* Reverse encode
|
|
198
|
-
*/
|
|
199
|
-
reverseEncode(symbol: number): void;
|
|
200
|
-
/**
|
|
201
|
-
* Reverse encode range
|
|
202
|
-
*/
|
|
203
|
-
reverseEncodeRange(startIndex: number, numBitLevels: number, symbol: number): void;
|
|
204
|
-
/**
|
|
205
|
-
* Write end marker
|
|
206
|
-
*/
|
|
207
|
-
writeEndMarker(positionState: number): void;
|
|
208
|
-
/**
|
|
209
|
-
* Encode length with price table update
|
|
210
|
-
*/
|
|
211
|
-
encodeLengthWithPriceUpdate(encoder: LenEncoder, symbol: number, posState: number): void;
|
|
212
|
-
private and64;
|
|
213
|
-
private shru64;
|
|
214
|
-
private shl64;
|
|
215
|
-
private pwrAsDouble;
|
|
216
|
-
/**
|
|
217
|
-
* Shift low helper (proper implementation) - public method for external access
|
|
218
|
-
*/
|
|
219
|
-
shiftLow(): void;
|
|
220
|
-
/**
|
|
221
|
-
* Write byte to stream
|
|
222
|
-
*/
|
|
223
|
-
private writeToStream;
|
|
224
|
-
initRangeEncoder(): void;
|
|
225
|
-
/**
|
|
226
|
-
* Fill alignment prices for position alignment encoder
|
|
227
|
-
*/
|
|
228
|
-
fillAlignPrices(): void;
|
|
229
|
-
/**
|
|
230
|
-
* Fill distance prices for position encoders
|
|
231
|
-
*/
|
|
232
|
-
fillDistancesPrices(): void;
|
|
233
|
-
/**
|
|
234
|
-
* Get position slot for a distance value
|
|
235
|
-
*/
|
|
236
|
-
getPosSlot(pos: number): number;
|
|
237
|
-
/**
|
|
238
|
-
* Get reverse price for bit tree encoder
|
|
239
|
-
*/
|
|
240
|
-
reverseGetPrice(encoder: BitTree, symbol: number): number;
|
|
241
|
-
/**
|
|
242
|
-
* Get reverse price for array of models
|
|
243
|
-
*/
|
|
244
|
-
reverseGetPriceArray(Models: number[], startIndex: number, NumBitLevels: number, symbol: number): number;
|
|
245
|
-
/**
|
|
246
|
-
* Get price for probability model (optimized)
|
|
247
|
-
*/
|
|
248
|
-
getPrice(Prob: number, symbol: number): number;
|
|
249
|
-
/**
|
|
250
|
-
* Get price for bit tree encoder (optimized)
|
|
251
|
-
*/
|
|
252
|
-
rangeCoder_Encoder_GetPrice_1(encoder: BitTree, symbol: number): number;
|
|
253
|
-
/**
|
|
254
|
-
* Create encoder optimization structures (optimized)
|
|
255
|
-
*/
|
|
256
|
-
createEncoderStructures(): void;
|
|
257
|
-
/**
|
|
258
|
-
* Create match finder and encoder structures (replaces #Create_2)
|
|
259
|
-
*/
|
|
260
|
-
createMatchFinderAndStructures(): void;
|
|
261
|
-
/**
|
|
262
|
-
* Get literal encoder subcoder (utility method)
|
|
263
|
-
*/
|
|
264
|
-
getSubCoderUtility(pos: number, prevByte: number): LiteralDecoderEncoder2;
|
|
265
|
-
}
|
|
266
|
-
export {};
|
package/lib/index.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Filip Seman
|
|
4
|
-
* SPDX-License-Identifier: MIT
|
|
5
|
-
*/
|
|
6
|
-
import { type CompressionMode } from "./lzma.js";
|
|
7
|
-
export { LZMA } from "./lzma.js";
|
|
8
|
-
export { CRC32_TABLE } from "./utils.js";
|
|
9
|
-
/**
|
|
10
|
-
* Compresses data using LZMA algorithm
|
|
11
|
-
*
|
|
12
|
-
* @param data Data to compress - can be Uint8Array or ArrayBuffer
|
|
13
|
-
* @param mode Compression mode (1-9), defaults to 5
|
|
14
|
-
* @returns Compressed data as a byte array
|
|
15
|
-
*/
|
|
16
|
-
export declare function compress(data: Uint8Array | ArrayBuffer, mode?: CompressionMode): Uint8Array;
|
|
17
|
-
/**
|
|
18
|
-
* Compresses data using LZMA algorithm
|
|
19
|
-
*
|
|
20
|
-
* @param data String to compress
|
|
21
|
-
* @param mode Compression mode (1-9), defaults to 5
|
|
22
|
-
* @returns Compressed data as byte array
|
|
23
|
-
*/
|
|
24
|
-
export declare function compressString(data: string, mode?: CompressionMode): Uint8Array;
|
|
25
|
-
/**
|
|
26
|
-
* Decompresses LZMA compressed data
|
|
27
|
-
*
|
|
28
|
-
* @param data Compressed data as Uint8Array or ArrayBuffer
|
|
29
|
-
* @returns Decompressed data
|
|
30
|
-
*/
|
|
31
|
-
export declare function decompress(data: Uint8Array | ArrayBuffer): Uint8Array;
|
|
32
|
-
/**
|
|
33
|
-
* Decompresses LZMA compressed data
|
|
34
|
-
*
|
|
35
|
-
* @param data Compressed data as Uint8Array or ArrayBuffer
|
|
36
|
-
* @returns Decompressed data as string
|
|
37
|
-
*/
|
|
38
|
-
export declare function decompressString(data: Uint8Array | ArrayBuffer): string;
|
package/lib/len-coder.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { type BitTree } from "./utils.js";
|
|
2
|
-
/**
|
|
3
|
-
* Range encoder interface for LenEncoder to communicate with
|
|
4
|
-
*/
|
|
5
|
-
export interface RangeEncoder {
|
|
6
|
-
encodeBit(probs: number[], index: number, symbol: number): void;
|
|
7
|
-
encodeBitTree(encoder: BitTree, symbol: number): void;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Length encoder class for LZMA compression
|
|
11
|
-
* Handles encoding of match lengths with price optimization
|
|
12
|
-
*/
|
|
13
|
-
export declare class LenEncoder {
|
|
14
|
-
private choice;
|
|
15
|
-
private lowCoder;
|
|
16
|
-
private midCoder;
|
|
17
|
-
private highCoder;
|
|
18
|
-
private tableSize;
|
|
19
|
-
private prices;
|
|
20
|
-
private counters;
|
|
21
|
-
constructor();
|
|
22
|
-
/**
|
|
23
|
-
* Initialize the encoder with specified number of position states
|
|
24
|
-
*/
|
|
25
|
-
init(numPosStates: number): void;
|
|
26
|
-
/**
|
|
27
|
-
* Encode a length value using the provided range encoder
|
|
28
|
-
*/
|
|
29
|
-
encode(symbol: number, posState: number, rangeEncoder: RangeEncoder): void;
|
|
30
|
-
/**
|
|
31
|
-
* Encode with price table update
|
|
32
|
-
*/
|
|
33
|
-
encodeWithUpdate(symbol: number, posState: number, rangeEncoder: RangeEncoder): void;
|
|
34
|
-
/**
|
|
35
|
-
* Get price for encoding a symbol at the given position state
|
|
36
|
-
*/
|
|
37
|
-
getPrice(symbol: number, posState: number): number;
|
|
38
|
-
/**
|
|
39
|
-
* Initialize as a price table encoder
|
|
40
|
-
*/
|
|
41
|
-
initPriceTable(): void;
|
|
42
|
-
/**
|
|
43
|
-
* Set table size for price optimization
|
|
44
|
-
*/
|
|
45
|
-
setTableSize(size: number): void;
|
|
46
|
-
/**
|
|
47
|
-
* Set table size and update internal counters
|
|
48
|
-
*/
|
|
49
|
-
setTableSizeAndInitCounters(size: number, numPosStates: number): void;
|
|
50
|
-
/**
|
|
51
|
-
* Get table size
|
|
52
|
-
*/
|
|
53
|
-
getTableSize(): number;
|
|
54
|
-
/**
|
|
55
|
-
* Update price tables for all position states
|
|
56
|
-
*/
|
|
57
|
-
updateTables(numPosStates: number): void;
|
|
58
|
-
/**
|
|
59
|
-
* Calculate price for bit tree encoder
|
|
60
|
-
*/
|
|
61
|
-
private getBitTreePrice;
|
|
62
|
-
/**
|
|
63
|
-
* Get price for a single bit
|
|
64
|
-
*/
|
|
65
|
-
private getBitPrice;
|
|
66
|
-
/**
|
|
67
|
-
* Set prices for all symbols in a position state range
|
|
68
|
-
*/
|
|
69
|
-
private setPrices;
|
|
70
|
-
}
|
package/lib/lit-coder.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { type BasicRangeDecoder, type BasicRangeEncoder } from "./utils.js";
|
|
2
|
-
export declare class LitSubCoder {
|
|
3
|
-
private coders;
|
|
4
|
-
constructor();
|
|
5
|
-
/**
|
|
6
|
-
* Decode normal literal symbol
|
|
7
|
-
*/
|
|
8
|
-
decodeNormal(rd: BasicRangeDecoder): number;
|
|
9
|
-
/**
|
|
10
|
-
* Decode literal symbol with match byte context
|
|
11
|
-
*/
|
|
12
|
-
decodeWithMatchByte(rd: BasicRangeDecoder, matchByte: number): number;
|
|
13
|
-
/**
|
|
14
|
-
* Encode literal symbol
|
|
15
|
-
*/
|
|
16
|
-
encode(re: BasicRangeEncoder, symbol: number): void;
|
|
17
|
-
/**
|
|
18
|
-
* Encode literal symbol with match byte context
|
|
19
|
-
*/
|
|
20
|
-
encodeMatched(re: BasicRangeEncoder, matchByte: number, symbol: number): void;
|
|
21
|
-
/**
|
|
22
|
-
* Get price for encoding literal symbol
|
|
23
|
-
*/
|
|
24
|
-
getPrice(matchMode: boolean, matchByte: number, symbol: number): number;
|
|
25
|
-
/**
|
|
26
|
-
* Reset coder to initial state
|
|
27
|
-
*/
|
|
28
|
-
reset(): void;
|
|
29
|
-
/**
|
|
30
|
-
* Get decoders array (for compatibility with LiteralDecoderEncoder2)
|
|
31
|
-
*/
|
|
32
|
-
get decoders(): number[];
|
|
33
|
-
}
|
|
34
|
-
export declare class LitCoder {
|
|
35
|
-
private _coders;
|
|
36
|
-
private _numPrevBits;
|
|
37
|
-
private _posMask;
|
|
38
|
-
constructor(numPosBits: number, numPrevBits: number);
|
|
39
|
-
/**
|
|
40
|
-
* Get sub-coder for position and previous byte
|
|
41
|
-
*/
|
|
42
|
-
getSubCoder(pos: number, prevByte: number): LitSubCoder;
|
|
43
|
-
/**
|
|
44
|
-
* Reset all sub-coders
|
|
45
|
-
*/
|
|
46
|
-
reset(): void;
|
|
47
|
-
/**
|
|
48
|
-
* Get number of previous bits (for compatibility)
|
|
49
|
-
*/
|
|
50
|
-
get numPrevBits(): number;
|
|
51
|
-
/**
|
|
52
|
-
* Get number of position bits (for compatibility)
|
|
53
|
-
*/
|
|
54
|
-
get numPosBits(): number;
|
|
55
|
-
/**
|
|
56
|
-
* Get position mask (for compatibility)
|
|
57
|
-
*/
|
|
58
|
-
get posMask(): number;
|
|
59
|
-
/**
|
|
60
|
-
* Get coders array (for compatibility)
|
|
61
|
-
*/
|
|
62
|
-
get coders(): LitSubCoder[];
|
|
63
|
-
}
|
package/lib/lz-in-window.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { MatchFinder } from "./encoder.js";
|
|
2
|
-
/**
|
|
3
|
-
* LzInWindow - Input Window helper for LZMA encoding
|
|
4
|
-
*
|
|
5
|
-
* This class manages the input window operations for LZMA encoding,
|
|
6
|
-
* including buffer management, position tracking, and input stream reading.
|
|
7
|
-
*/
|
|
8
|
-
export declare class LzInWindow {
|
|
9
|
-
private matchFinder;
|
|
10
|
-
constructor(matchFinder: MatchFinder);
|
|
11
|
-
/**
|
|
12
|
-
* Get a byte at the specified index relative to current position
|
|
13
|
-
*/
|
|
14
|
-
getIndexByte(index: number): number;
|
|
15
|
-
/**
|
|
16
|
-
* Calculate match length between current position and a previous position
|
|
17
|
-
*/
|
|
18
|
-
getMatchLen(index: number, distance: number, limit: number): number;
|
|
19
|
-
/**
|
|
20
|
-
* Get number of available bytes in the input window
|
|
21
|
-
*/
|
|
22
|
-
getNumAvailableBytes(): number;
|
|
23
|
-
/**
|
|
24
|
-
* Move buffer block when reaching buffer boundaries
|
|
25
|
-
*/
|
|
26
|
-
moveBlock(): void;
|
|
27
|
-
/**
|
|
28
|
-
* Move position by one and handle buffer management
|
|
29
|
-
*/
|
|
30
|
-
movePos(): void;
|
|
31
|
-
/**
|
|
32
|
-
* Read a block of data from the input stream
|
|
33
|
-
*/
|
|
34
|
-
readBlock(): void;
|
|
35
|
-
/**
|
|
36
|
-
* Reduce all position offsets by the specified value
|
|
37
|
-
*/
|
|
38
|
-
reduceOffsets(subValue: number): void;
|
|
39
|
-
/**
|
|
40
|
-
* Read data from the input stream into the buffer
|
|
41
|
-
*/
|
|
42
|
-
private readFromStream;
|
|
43
|
-
}
|
package/lib/lz-in-window.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { arraycopy } from "./utils.js";
|
|
2
|
-
/**
|
|
3
|
-
* LzInWindow - Input Window helper for LZMA encoding
|
|
4
|
-
*
|
|
5
|
-
* This class manages the input window operations for LZMA encoding,
|
|
6
|
-
* including buffer management, position tracking, and input stream reading.
|
|
7
|
-
*/
|
|
8
|
-
export class LzInWindow {
|
|
9
|
-
matchFinder;
|
|
10
|
-
constructor(matchFinder) {
|
|
11
|
-
this.matchFinder = matchFinder;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Get a byte at the specified index relative to current position
|
|
15
|
-
*/
|
|
16
|
-
getIndexByte(index) {
|
|
17
|
-
const byte = this.matchFinder._bufferBase[this.matchFinder._bufferOffset + this.matchFinder._pos + index];
|
|
18
|
-
return byte;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Calculate match length between current position and a previous position
|
|
22
|
-
*/
|
|
23
|
-
getMatchLen(index, distance, limit) {
|
|
24
|
-
if (this.matchFinder._streamEndWasReached) {
|
|
25
|
-
if (this.matchFinder._pos + index + limit > this.matchFinder._streamPos) {
|
|
26
|
-
limit = this.matchFinder._streamPos - (this.matchFinder._pos + index);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
++distance;
|
|
30
|
-
let i;
|
|
31
|
-
const pby = this.matchFinder._bufferOffset + this.matchFinder._pos + index;
|
|
32
|
-
for (i = 0; i < limit
|
|
33
|
-
&& this.matchFinder._bufferBase[pby + i]
|
|
34
|
-
== this.matchFinder._bufferBase[pby + i - distance]; ++i)
|
|
35
|
-
;
|
|
36
|
-
return i;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Get number of available bytes in the input window
|
|
40
|
-
*/
|
|
41
|
-
getNumAvailableBytes() {
|
|
42
|
-
return this.matchFinder._streamPos - this.matchFinder._pos;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Move buffer block when reaching buffer boundaries
|
|
46
|
-
*/
|
|
47
|
-
moveBlock() {
|
|
48
|
-
let offset = this.matchFinder._bufferOffset + this.matchFinder._pos - this.matchFinder._keepSizeBefore;
|
|
49
|
-
if (offset > 0) {
|
|
50
|
-
--offset;
|
|
51
|
-
}
|
|
52
|
-
const numBytes = this.matchFinder._bufferOffset + this.matchFinder._streamPos - offset;
|
|
53
|
-
for (let i = 0; i < numBytes; ++i) {
|
|
54
|
-
this.matchFinder._bufferBase[i] = this.matchFinder._bufferBase[offset + i];
|
|
55
|
-
}
|
|
56
|
-
this.matchFinder._bufferOffset -= offset;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Move position by one and handle buffer management
|
|
60
|
-
*/
|
|
61
|
-
movePos() {
|
|
62
|
-
this.matchFinder._pos += 1;
|
|
63
|
-
if (this.matchFinder._pos > this.matchFinder._posLimit) {
|
|
64
|
-
const pointerToPosition = this.matchFinder._bufferOffset + this.matchFinder._pos;
|
|
65
|
-
if (pointerToPosition > this.matchFinder._pointerToLastSafePosition) {
|
|
66
|
-
this.moveBlock();
|
|
67
|
-
}
|
|
68
|
-
this.readBlock();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Read a block of data from the input stream
|
|
73
|
-
*/
|
|
74
|
-
readBlock() {
|
|
75
|
-
if (this.matchFinder._streamEndWasReached) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
while (true) {
|
|
79
|
-
const size = -this.matchFinder._bufferOffset + this.matchFinder._blockSize - this.matchFinder._streamPos;
|
|
80
|
-
if (!size) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const bytesRead = this.readFromStream(this.matchFinder._bufferOffset + this.matchFinder._streamPos, size);
|
|
84
|
-
if (bytesRead == -1) {
|
|
85
|
-
this.matchFinder._posLimit = this.matchFinder._streamPos;
|
|
86
|
-
const pointerToPosition = this.matchFinder._bufferOffset + this.matchFinder._posLimit;
|
|
87
|
-
if (pointerToPosition > this.matchFinder._pointerToLastSafePosition) {
|
|
88
|
-
this.matchFinder._posLimit = this.matchFinder._pointerToLastSafePosition - this.matchFinder._bufferOffset;
|
|
89
|
-
}
|
|
90
|
-
this.matchFinder._streamEndWasReached = 1;
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
this.matchFinder._streamPos += bytesRead;
|
|
94
|
-
if (this.matchFinder._streamPos >= this.matchFinder._pos + this.matchFinder._keepSizeAfter) {
|
|
95
|
-
this.matchFinder._posLimit = this.matchFinder._streamPos - this.matchFinder._keepSizeAfter;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Reduce all position offsets by the specified value
|
|
101
|
-
*/
|
|
102
|
-
reduceOffsets(subValue) {
|
|
103
|
-
this.matchFinder._bufferOffset += subValue;
|
|
104
|
-
this.matchFinder._posLimit -= subValue;
|
|
105
|
-
this.matchFinder._pos -= subValue;
|
|
106
|
-
this.matchFinder._streamPos -= subValue;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Read data from the input stream into the buffer
|
|
110
|
-
*/
|
|
111
|
-
readFromStream(off, len) {
|
|
112
|
-
const stream = this.matchFinder._stream;
|
|
113
|
-
const buffer = this.matchFinder._bufferBase;
|
|
114
|
-
if (stream.pos >= stream.count) {
|
|
115
|
-
return -1;
|
|
116
|
-
}
|
|
117
|
-
let srcBuf;
|
|
118
|
-
if (stream.buf instanceof Uint8Array) {
|
|
119
|
-
srcBuf = Array.from(stream.buf);
|
|
120
|
-
}
|
|
121
|
-
else if (stream.buf instanceof ArrayBuffer) {
|
|
122
|
-
srcBuf = Array.from(new Uint8Array(stream.buf));
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
srcBuf = stream.buf;
|
|
126
|
-
}
|
|
127
|
-
len = Math.min(len, stream.count - stream.pos);
|
|
128
|
-
arraycopy(srcBuf, stream.pos, buffer, off, len);
|
|
129
|
-
stream.pos += len;
|
|
130
|
-
return len;
|
|
131
|
-
}
|
|
132
|
-
}
|