lzma1 0.0.4 → 0.5.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 -1
- package/dist/lzma.d.ts +1 -0
- package/dist/lzma.js +248 -241
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# lzma1
|
|
2
2
|
|
|
3
|
-
This is a
|
|
3
|
+
This is a [fork][fork-link] of [Nathan Rugg's][fork-author] package that adds
|
|
4
|
+
types and makes the logic more structured and readable.
|
|
4
5
|
|
|
5
6
|
[fork-link]: https://github.com/LZMA-JS/LZMA-JS
|
|
6
7
|
[fork-author]: https://github.com/nmrugg
|
|
@@ -64,8 +65,16 @@ const decompressed = decompress(result);
|
|
|
64
65
|
// data === decompressed
|
|
65
66
|
```
|
|
66
67
|
|
|
68
|
+
## LZMA header
|
|
69
|
+
|
|
70
|
+
More [information][header_link] about the LZMA header.
|
|
71
|
+
|
|
72
|
+

|
|
73
|
+
|
|
67
74
|
## Related
|
|
68
75
|
|
|
69
76
|
- <https://github.com/cscott/lzma-purejs>
|
|
70
77
|
- <https://github.com/glinscott/lzmajs>
|
|
71
78
|
- <https://github.com/mauron85/lzma-purejs/tree/master>
|
|
79
|
+
|
|
80
|
+
[header_link]: https://docs.fileformat.com/compression/lzma/#lzma-header
|
package/dist/lzma.d.ts
CHANGED
package/dist/lzma.js
CHANGED
|
@@ -55,10 +55,16 @@ const CRC32_TABLE = [
|
|
|
55
55
|
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
|
56
56
|
];
|
|
57
57
|
export class LZMA {
|
|
58
|
-
#MAX_UINT32 =
|
|
59
|
-
#
|
|
60
|
-
#
|
|
61
|
-
#
|
|
58
|
+
#MAX_UINT32 = 0x100000000; // 2^32
|
|
59
|
+
#_MAX_UINT32 = 0xFFFFFFFF; // 2^32 - 1
|
|
60
|
+
#MAX_INT32 = 0x7FFFFFFF; // 2^31 - 1
|
|
61
|
+
#MIN_INT32 = -0x80000000; // -2^31
|
|
62
|
+
#MAX_UINT64 = 0x10000000000000000; // 2^64
|
|
63
|
+
#MAX_INT64 = 0x7FFFFFFFFFFFFFFF; // 2^63
|
|
64
|
+
#MIN_INT64 = -0x8000000000000000; // -2^63
|
|
65
|
+
#MAX_COMPRESSION_SIZE = 0x7FFFFFFFFFFFFFFF; // 2^63 - 1
|
|
66
|
+
#kIfinityPrice = 0xFFFFFFF; // 2^28 - 1
|
|
67
|
+
#dictionarySizeThreshold = 0x3FFFFFFF;
|
|
62
68
|
#N1_LONG_LIT;
|
|
63
69
|
#MIN_VALUE;
|
|
64
70
|
#P0_LONG_LIT = [0, 0];
|
|
@@ -80,9 +86,10 @@ export class LZMA {
|
|
|
80
86
|
#gFastPos;
|
|
81
87
|
#compressor;
|
|
82
88
|
#decompressor;
|
|
89
|
+
bitMaskForRange = -16777216;
|
|
83
90
|
constructor() {
|
|
84
|
-
this.#N1_LONG_LIT = [
|
|
85
|
-
this.#MIN_VALUE = [0,
|
|
91
|
+
this.#N1_LONG_LIT = [this.#_MAX_UINT32, -this.#MAX_UINT32];
|
|
92
|
+
this.#MIN_VALUE = [0, this.#MIN_INT64];
|
|
86
93
|
this.#encoder = this.#initEncoder();
|
|
87
94
|
this.#decoder = this.#initDecoder();
|
|
88
95
|
this.#probPrices = this.#createProbPrices();
|
|
@@ -146,8 +153,8 @@ export class LZMA {
|
|
|
146
153
|
m_PosSlotDecoder: this.#initArray(4),
|
|
147
154
|
m_PosDecoders: this.#initArray(114),
|
|
148
155
|
m_PosAlignDecoder: this.#createBitTreeDecoder(4),
|
|
149
|
-
m_LenDecoder: this.#createLenDecoder(
|
|
150
|
-
m_RepLenDecoder: this.#createLenDecoder(
|
|
156
|
+
m_LenDecoder: this.#createLenDecoder(),
|
|
157
|
+
m_RepLenDecoder: this.#createLenDecoder(),
|
|
151
158
|
m_LiteralDecoder: {},
|
|
152
159
|
};
|
|
153
160
|
for (let i = 0; i < 4; ++i) {
|
|
@@ -161,7 +168,7 @@ export class LZMA {
|
|
|
161
168
|
alive: 0,
|
|
162
169
|
encoder: null,
|
|
163
170
|
decoder: null,
|
|
164
|
-
inBytesProcessed: [],
|
|
171
|
+
inBytesProcessed: [0, 0],
|
|
165
172
|
},
|
|
166
173
|
output: {
|
|
167
174
|
buf: this.#initArray(32),
|
|
@@ -175,7 +182,7 @@ export class LZMA {
|
|
|
175
182
|
alive: 0,
|
|
176
183
|
encoder: null,
|
|
177
184
|
decoder: null,
|
|
178
|
-
inBytesProcessed: [],
|
|
185
|
+
inBytesProcessed: [0, 0],
|
|
179
186
|
},
|
|
180
187
|
output: {
|
|
181
188
|
buf: this.#initArray(32),
|
|
@@ -244,8 +251,8 @@ export class LZMA {
|
|
|
244
251
|
}
|
|
245
252
|
#create(valueLow, valueHigh) {
|
|
246
253
|
let diffHigh, diffLow;
|
|
247
|
-
valueHigh %=
|
|
248
|
-
valueLow %=
|
|
254
|
+
valueHigh %= this.#MAX_UINT64;
|
|
255
|
+
valueLow %= this.#MAX_UINT64;
|
|
249
256
|
diffHigh = valueHigh % this.#MAX_UINT32;
|
|
250
257
|
diffLow = Math.floor(valueLow / this.#MAX_UINT32) * this.#MAX_UINT32;
|
|
251
258
|
valueHigh = valueHigh - diffHigh + diffLow;
|
|
@@ -254,16 +261,16 @@ export class LZMA {
|
|
|
254
261
|
valueLow += this.#MAX_UINT32;
|
|
255
262
|
valueHigh -= this.#MAX_UINT32;
|
|
256
263
|
}
|
|
257
|
-
while (valueLow >
|
|
264
|
+
while (valueLow > this.#MAX_UINT32) {
|
|
258
265
|
valueLow -= this.#MAX_UINT32;
|
|
259
266
|
valueHigh += this.#MAX_UINT32;
|
|
260
267
|
}
|
|
261
|
-
valueHigh = valueHigh %
|
|
262
|
-
while (valueHigh >
|
|
263
|
-
valueHigh -=
|
|
268
|
+
valueHigh = valueHigh % this.#MAX_UINT64;
|
|
269
|
+
while (valueHigh > this.#MAX_INT64) {
|
|
270
|
+
valueHigh -= this.#MAX_UINT64;
|
|
264
271
|
}
|
|
265
|
-
while (valueHigh <
|
|
266
|
-
valueHigh +=
|
|
272
|
+
while (valueHigh < this.#MIN_INT64) {
|
|
273
|
+
valueHigh += this.#MAX_UINT64;
|
|
267
274
|
}
|
|
268
275
|
return [valueLow, valueHigh];
|
|
269
276
|
}
|
|
@@ -303,13 +310,13 @@ export class LZMA {
|
|
|
303
310
|
throw new Error("Neg");
|
|
304
311
|
}
|
|
305
312
|
twoToN = this.#pwrAsDouble(n);
|
|
306
|
-
newHigh = a[1] * twoToN %
|
|
313
|
+
newHigh = a[1] * twoToN % this.#MAX_UINT64;
|
|
307
314
|
newLow = a[0] * twoToN;
|
|
308
315
|
diff = newLow - newLow % this.#MAX_UINT32;
|
|
309
316
|
newHigh += diff;
|
|
310
317
|
newLow -= diff;
|
|
311
318
|
if (newHigh >= this.#MAX_COMPRESSION_SIZE) {
|
|
312
|
-
newHigh -=
|
|
319
|
+
newHigh -= this.#MAX_UINT64;
|
|
313
320
|
}
|
|
314
321
|
return [newLow, newHigh];
|
|
315
322
|
}
|
|
@@ -351,12 +358,12 @@ export class LZMA {
|
|
|
351
358
|
data.length = output.count;
|
|
352
359
|
return data;
|
|
353
360
|
}
|
|
354
|
-
#write(
|
|
355
|
-
|
|
361
|
+
#write(buffer, b) {
|
|
362
|
+
buffer.buf[buffer.count++] = b & 0xFF;
|
|
356
363
|
}
|
|
357
|
-
#write_0(
|
|
358
|
-
this.#arraycopy(buf, off,
|
|
359
|
-
|
|
364
|
+
#write_0(buffer, buf, off, len) {
|
|
365
|
+
this.#arraycopy(buf, off, buffer.buf, buffer.count, len);
|
|
366
|
+
buffer.count += len;
|
|
360
367
|
}
|
|
361
368
|
#getChars(inputString, srcBegin, srcEnd, dst, dstBegin) {
|
|
362
369
|
for (let srcIdx = srcBegin; srcIdx < srcEnd; ++srcIdx) {
|
|
@@ -409,9 +416,9 @@ export class LZMA {
|
|
|
409
416
|
this.#FillAlignPrices(this.#encoder);
|
|
410
417
|
// Configure length encoders
|
|
411
418
|
this.#encoder._lenEncoder._tableSize = this.#encoder._numFastBytes + 1 - 2;
|
|
412
|
-
this.#
|
|
419
|
+
this.#LZMA_LenPriceTableEncoder_UpdateTablesUpdateTables(this.#encoder._lenEncoder, 1 << this.#encoder._posStateBits);
|
|
413
420
|
this.#encoder._repMatchLenEncoder._tableSize = this.#encoder._numFastBytes + 1 - 2;
|
|
414
|
-
this.#
|
|
421
|
+
this.#LZMA_LenPriceTableEncoder_UpdateTablesUpdateTables(this.#encoder._repMatchLenEncoder, 1 << this.#encoder._posStateBits);
|
|
415
422
|
// Reset position counter
|
|
416
423
|
this.#encoder.nowPos64 = this.#P0_LONG_LIT;
|
|
417
424
|
// Create new chunker with configured encoder
|
|
@@ -444,7 +451,7 @@ export class LZMA {
|
|
|
444
451
|
if (r == -1) {
|
|
445
452
|
throw new Error("truncated input");
|
|
446
453
|
}
|
|
447
|
-
properties[i] = r
|
|
454
|
+
properties[i] = r & 0xFF;
|
|
448
455
|
}
|
|
449
456
|
if (!this.#SetDecoderProperties(properties)) {
|
|
450
457
|
throw new Error("corrupted input");
|
|
@@ -474,7 +481,7 @@ export class LZMA {
|
|
|
474
481
|
*/
|
|
475
482
|
tmp_length = parseInt(hex_length, 16);
|
|
476
483
|
// If the length is too long to handle, just set it to unknown.
|
|
477
|
-
if (tmp_length >
|
|
484
|
+
if (tmp_length > this.#_MAX_UINT32) {
|
|
478
485
|
this.#compressor.length_0 = this.#N1_LONG_LIT;
|
|
479
486
|
}
|
|
480
487
|
else {
|
|
@@ -513,26 +520,27 @@ export class LZMA {
|
|
|
513
520
|
+ index];
|
|
514
521
|
}
|
|
515
522
|
#GetMatchLen(index, distance, limit) {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
523
|
+
const encoder = this.#compressor.chunker.encoder;
|
|
524
|
+
if (encoder._matchFinder._streamEndWasReached) {
|
|
525
|
+
if (encoder._matchFinder._pos + index + limit
|
|
526
|
+
> encoder._matchFinder._streamPos) {
|
|
527
|
+
limit = encoder._matchFinder._streamPos
|
|
528
|
+
- (encoder._matchFinder._pos + index);
|
|
521
529
|
}
|
|
522
530
|
}
|
|
523
531
|
++distance;
|
|
524
|
-
let i, pby =
|
|
525
|
-
+
|
|
532
|
+
let i, pby = encoder._matchFinder._bufferOffset
|
|
533
|
+
+ encoder._matchFinder._pos
|
|
526
534
|
+ index;
|
|
527
535
|
for (i = 0; i < limit
|
|
528
|
-
&&
|
|
529
|
-
==
|
|
536
|
+
&& encoder._matchFinder._bufferBase[pby + i]
|
|
537
|
+
== encoder._matchFinder._bufferBase[pby + i - distance]; ++i)
|
|
530
538
|
;
|
|
531
539
|
return i;
|
|
532
540
|
}
|
|
533
541
|
#GetNumAvailableBytes() {
|
|
534
|
-
|
|
535
|
-
|
|
542
|
+
const encoder = this.#compressor.chunker.encoder;
|
|
543
|
+
return encoder._matchFinder._streamPos - encoder._matchFinder._pos;
|
|
536
544
|
}
|
|
537
545
|
#MoveBlock() {
|
|
538
546
|
const matchFinder = this.#compressor.chunker.encoder._matchFinder;
|
|
@@ -592,7 +600,7 @@ export class LZMA {
|
|
|
592
600
|
this.#compressor.chunker.encoder._matchFinder._streamPos -= subValue;
|
|
593
601
|
}
|
|
594
602
|
#Create_3(keepAddBufferBefore, keepAddBufferAfter) {
|
|
595
|
-
if (this.#encoder._dictionarySize <
|
|
603
|
+
if (this.#encoder._dictionarySize < this.#dictionarySizeThreshold) {
|
|
596
604
|
this.#encoder._matchFinder._cutValue = 16 + (this.#encoder._numFastBytes >> 1);
|
|
597
605
|
const windowReservSize = ~~((this.#encoder._dictionarySize
|
|
598
606
|
+ keepAddBufferBefore
|
|
@@ -796,7 +804,7 @@ export class LZMA {
|
|
|
796
804
|
}
|
|
797
805
|
#Skip(num) {
|
|
798
806
|
const matchFinder = this.#compressor.chunker.encoder._matchFinder;
|
|
799
|
-
|
|
807
|
+
let count, cur, curMatch, cyclicPos, delta, hash2Value, hash3Value, hashValue, len, len0, len1, lenLimit, matchMinPos, pby1, ptr0, ptr1, temp;
|
|
800
808
|
do {
|
|
801
809
|
if (matchFinder._pos + matchFinder._matchMaxLen <= matchFinder._streamPos) {
|
|
802
810
|
lenLimit = matchFinder._matchMaxLen;
|
|
@@ -886,11 +894,11 @@ export class LZMA {
|
|
|
886
894
|
outputWindow._pos += 1;
|
|
887
895
|
pos += 1;
|
|
888
896
|
if (outputWindow._pos >= outputWindow._windowSize) {
|
|
889
|
-
this.#Flush_0(
|
|
897
|
+
this.#Flush_0();
|
|
890
898
|
}
|
|
891
899
|
}
|
|
892
900
|
}
|
|
893
|
-
#
|
|
901
|
+
#OutWindow_Create(m_OutWindow, windowSize) {
|
|
894
902
|
if (m_OutWindow._buffer == null || m_OutWindow._windowSize != windowSize) {
|
|
895
903
|
m_OutWindow._buffer = this.#initArray(windowSize);
|
|
896
904
|
}
|
|
@@ -898,35 +906,35 @@ export class LZMA {
|
|
|
898
906
|
m_OutWindow._pos = 0;
|
|
899
907
|
m_OutWindow._streamPos = 0;
|
|
900
908
|
}
|
|
901
|
-
#Flush_0(
|
|
902
|
-
|
|
909
|
+
#Flush_0() {
|
|
910
|
+
let size = this.#decoder.m_OutWindow._pos - this.#decoder.m_OutWindow._streamPos;
|
|
903
911
|
if (!size) {
|
|
904
912
|
return;
|
|
905
913
|
}
|
|
906
|
-
this.#write_0(
|
|
907
|
-
if (
|
|
908
|
-
|
|
914
|
+
this.#write_0(this.#decoder.m_OutWindow._stream, this.#decoder.m_OutWindow._buffer, this.#decoder.m_OutWindow._streamPos, size);
|
|
915
|
+
if (this.#decoder.m_OutWindow._pos >= this.#decoder.m_OutWindow._windowSize) {
|
|
916
|
+
this.#decoder.m_OutWindow._pos = 0;
|
|
909
917
|
}
|
|
910
|
-
|
|
918
|
+
this.#decoder.m_OutWindow._streamPos = this.#decoder.m_OutWindow._pos;
|
|
911
919
|
}
|
|
912
920
|
#GetByte(distance) {
|
|
913
921
|
const outputWindow = this.#decompressor.chunker.decoder.m_OutWindow;
|
|
914
|
-
|
|
922
|
+
let pos = outputWindow._pos - distance - 1;
|
|
915
923
|
if (pos < 0) {
|
|
916
924
|
pos += outputWindow._windowSize;
|
|
917
925
|
}
|
|
918
926
|
return outputWindow._buffer[pos];
|
|
919
927
|
}
|
|
920
|
-
#PutByte(
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
if (
|
|
924
|
-
this.#Flush_0(
|
|
928
|
+
#PutByte(b) {
|
|
929
|
+
this.#decoder.m_OutWindow._buffer[this.#decoder.m_OutWindow._pos] = b;
|
|
930
|
+
this.#decoder.m_OutWindow._pos += 1;
|
|
931
|
+
if (this.#decoder.m_OutWindow._pos >= this.#decoder.m_OutWindow._windowSize) {
|
|
932
|
+
this.#Flush_0();
|
|
925
933
|
}
|
|
926
934
|
}
|
|
927
|
-
#
|
|
928
|
-
this.#Flush_0(
|
|
929
|
-
|
|
935
|
+
#OutWindow_ReleaseStream() {
|
|
936
|
+
this.#Flush_0();
|
|
937
|
+
this.#decoder.m_OutWindow._stream = null;
|
|
930
938
|
}
|
|
931
939
|
GetLenToPosState(len) {
|
|
932
940
|
len -= 2;
|
|
@@ -969,8 +977,8 @@ export class LZMA {
|
|
|
969
977
|
if (result
|
|
970
978
|
|| this.#compare(decoder.outSize, this.#P0_LONG_LIT) >= 0
|
|
971
979
|
&& this.#compare(decoder.nowPos64, decoder.outSize) >= 0) {
|
|
972
|
-
this.#Flush_0(
|
|
973
|
-
this.#
|
|
980
|
+
this.#Flush_0();
|
|
981
|
+
this.#OutWindow_ReleaseStream();
|
|
974
982
|
decoder.m_RangeDecoder.Stream = null;
|
|
975
983
|
this.#decompressor.chunker.alive = 0;
|
|
976
984
|
}
|
|
@@ -993,7 +1001,7 @@ export class LZMA {
|
|
|
993
1001
|
}
|
|
994
1002
|
#CodeInChunks(inStream, outSize) {
|
|
995
1003
|
this.#decoder.m_RangeDecoder.Stream = inStream;
|
|
996
|
-
this.#
|
|
1004
|
+
this.#OutWindow_ReleaseStream();
|
|
997
1005
|
this.#decoder.m_OutWindow._stream = this.#decompressor.output;
|
|
998
1006
|
this.#Init_1();
|
|
999
1007
|
this.#decoder.state = 0;
|
|
@@ -1022,7 +1030,7 @@ export class LZMA {
|
|
|
1022
1030
|
else {
|
|
1023
1031
|
decoder.prevByte = this.#DecodeWithMatchByte(decoder2, this.#GetByte(decoder.rep0));
|
|
1024
1032
|
}
|
|
1025
|
-
this.#PutByte(decoder.
|
|
1033
|
+
this.#PutByte(decoder.prevByte);
|
|
1026
1034
|
decoder.state = this.StateUpdateChar(decoder.state);
|
|
1027
1035
|
decoder.nowPos64 = this.#add(decoder.nowPos64, this.#P1_LONG_LIT);
|
|
1028
1036
|
}
|
|
@@ -1065,7 +1073,7 @@ export class LZMA {
|
|
|
1065
1073
|
decoder.rep1 = decoder.rep0;
|
|
1066
1074
|
len = 2 + this.#Decode(decoder.m_LenDecoder, posState);
|
|
1067
1075
|
decoder.state = decoder.state < 7 ? 7 : 10;
|
|
1068
|
-
positionSlot = this.#
|
|
1076
|
+
positionSlot = this.#RangeCoder_BitTreeDecoder_Decoder(decoder.m_PosSlotDecoder[this.GetLenToPosState(len)]);
|
|
1069
1077
|
if (positionSlot >= 4) {
|
|
1070
1078
|
numDirectBits = (positionSlot >> 1) - 1;
|
|
1071
1079
|
decoder.rep0 = (2 | positionSlot & 1) << numDirectBits;
|
|
@@ -1117,7 +1125,7 @@ export class LZMA {
|
|
|
1117
1125
|
this.#Init_8();
|
|
1118
1126
|
}
|
|
1119
1127
|
#SetDecoderProperties(properties) {
|
|
1120
|
-
|
|
1128
|
+
let dictionarySize, i, lc, lp, pb, remainder, val;
|
|
1121
1129
|
if (properties.length < 5) {
|
|
1122
1130
|
return 0;
|
|
1123
1131
|
}
|
|
@@ -1143,7 +1151,7 @@ export class LZMA {
|
|
|
1143
1151
|
if (this.#decoder.m_DictionarySize != dictionarySize) {
|
|
1144
1152
|
this.#decoder.m_DictionarySize = dictionarySize;
|
|
1145
1153
|
this.#decoder.m_DictionarySizeCheck = Math.max(this.#decoder.m_DictionarySize, 1);
|
|
1146
|
-
this.#
|
|
1154
|
+
this.#OutWindow_Create(this.#decoder.m_OutWindow, Math.max(this.#decoder.m_DictionarySizeCheck, 4096));
|
|
1147
1155
|
}
|
|
1148
1156
|
return 1;
|
|
1149
1157
|
}
|
|
@@ -1152,7 +1160,7 @@ export class LZMA {
|
|
|
1152
1160
|
return 0;
|
|
1153
1161
|
}
|
|
1154
1162
|
this.#Create_0(lp, lc);
|
|
1155
|
-
|
|
1163
|
+
let numPosStates = 1 << pb;
|
|
1156
1164
|
this.#Create(this.#decoder.m_LenDecoder, numPosStates);
|
|
1157
1165
|
this.#Create(this.#decoder.m_RepLenDecoder, numPosStates);
|
|
1158
1166
|
this.#decoder.m_PosStateMask = numPosStates - 1;
|
|
@@ -1164,34 +1172,36 @@ export class LZMA {
|
|
|
1164
1172
|
decoder.m_MidCoder[decoder.m_NumPosStates] = this.#createBitTreeDecoder(3);
|
|
1165
1173
|
}
|
|
1166
1174
|
}
|
|
1167
|
-
#Decode(
|
|
1168
|
-
if (!this.#decodeBit(
|
|
1169
|
-
return this.#
|
|
1175
|
+
#Decode(decoder, posState) {
|
|
1176
|
+
if (!this.#decodeBit(decoder.m_Choice, 0)) {
|
|
1177
|
+
return this.#RangeCoder_BitTreeDecoder_Decoder(decoder.m_LowCoder[posState]);
|
|
1170
1178
|
}
|
|
1171
1179
|
let symbol = 8;
|
|
1172
|
-
if (!this.#decodeBit(
|
|
1173
|
-
symbol += this.#
|
|
1180
|
+
if (!this.#decodeBit(decoder.m_Choice, 1)) {
|
|
1181
|
+
symbol += this.#RangeCoder_BitTreeDecoder_Decoder(decoder.m_MidCoder[posState]);
|
|
1174
1182
|
}
|
|
1175
1183
|
else {
|
|
1176
|
-
symbol += 8 + this.#
|
|
1184
|
+
symbol += 8 + this.#RangeCoder_BitTreeDecoder_Decoder(decoder.m_HighCoder);
|
|
1177
1185
|
}
|
|
1178
1186
|
return symbol;
|
|
1179
1187
|
}
|
|
1180
|
-
#createLenDecoder(
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1188
|
+
#createLenDecoder() {
|
|
1189
|
+
const decoder = {
|
|
1190
|
+
m_Choice: this.#initArray(2),
|
|
1191
|
+
m_LowCoder: this.#initArray(16),
|
|
1192
|
+
m_MidCoder: this.#initArray(16),
|
|
1193
|
+
m_HighCoder: this.#createBitTreeDecoder(8),
|
|
1194
|
+
m_NumPosStates: 0,
|
|
1195
|
+
};
|
|
1196
|
+
return decoder;
|
|
1187
1197
|
}
|
|
1188
|
-
#Init(
|
|
1189
|
-
this.InitBitModels(
|
|
1190
|
-
for (let posState = 0; posState <
|
|
1191
|
-
this.InitBitModels(
|
|
1192
|
-
this.InitBitModels(
|
|
1198
|
+
#Init(decoder) {
|
|
1199
|
+
this.InitBitModels(decoder.m_Choice);
|
|
1200
|
+
for (let posState = 0; posState < decoder.m_NumPosStates; ++posState) {
|
|
1201
|
+
this.InitBitModels(decoder.m_LowCoder[posState].Models);
|
|
1202
|
+
this.InitBitModels(decoder.m_MidCoder[posState].Models);
|
|
1193
1203
|
}
|
|
1194
|
-
this.InitBitModels(
|
|
1204
|
+
this.InitBitModels(decoder.m_HighCoder.Models);
|
|
1195
1205
|
}
|
|
1196
1206
|
#Create_0(numPosBits, numPrevBits) {
|
|
1197
1207
|
let i, numStates;
|
|
@@ -1206,7 +1216,7 @@ export class LZMA {
|
|
|
1206
1216
|
numStates = 1 << this.#decoder.m_LiteralDecoder.m_NumPrevBits + this.#decoder.m_LiteralDecoder.m_NumPosBits;
|
|
1207
1217
|
this.#decoder.m_LiteralDecoder.m_Coders = this.#initArray(numStates);
|
|
1208
1218
|
for (i = 0; i < numStates; ++i) {
|
|
1209
|
-
this.#decoder.m_LiteralDecoder.m_Coders[i] = this.#createLiteralDecoderEncoder2(
|
|
1219
|
+
this.#decoder.m_LiteralDecoder.m_Coders[i] = this.#createLiteralDecoderEncoder2();
|
|
1210
1220
|
}
|
|
1211
1221
|
}
|
|
1212
1222
|
#GetDecoder(pos, prevByte) {
|
|
@@ -1218,68 +1228,69 @@ export class LZMA {
|
|
|
1218
1228
|
// Return decoder at calculated index
|
|
1219
1229
|
return literalDecoder.m_Coders[index];
|
|
1220
1230
|
}
|
|
1221
|
-
#Init_0(
|
|
1231
|
+
#Init_0(decoder) {
|
|
1222
1232
|
let i, numStates;
|
|
1223
|
-
numStates = 1 <<
|
|
1233
|
+
numStates = 1 << decoder.m_NumPrevBits + decoder.m_NumPosBits;
|
|
1224
1234
|
for (i = 0; i < numStates; ++i) {
|
|
1225
|
-
this.InitBitModels(
|
|
1235
|
+
this.InitBitModels(decoder.m_Coders[i].m_Decoders);
|
|
1226
1236
|
}
|
|
1227
1237
|
}
|
|
1228
|
-
#DecodeNormal(
|
|
1229
|
-
|
|
1230
|
-
var symbol = 1;
|
|
1238
|
+
#DecodeNormal(decoder) {
|
|
1239
|
+
let symbol = 1;
|
|
1231
1240
|
do {
|
|
1232
|
-
symbol = symbol << 1 | this.#decodeBit(
|
|
1241
|
+
symbol = symbol << 1 | this.#decodeBit(decoder.m_Decoders, symbol);
|
|
1233
1242
|
} while (symbol < 256);
|
|
1234
|
-
return symbol
|
|
1243
|
+
return symbol & 0xFF;
|
|
1235
1244
|
}
|
|
1236
|
-
#DecodeWithMatchByte(
|
|
1245
|
+
#DecodeWithMatchByte(encoder, matchByte) {
|
|
1237
1246
|
let bit, matchBit, symbol = 1;
|
|
1238
1247
|
do {
|
|
1239
1248
|
matchBit = matchByte >> 7 & 1;
|
|
1240
1249
|
matchByte <<= 1;
|
|
1241
|
-
bit = this.#decodeBit(
|
|
1250
|
+
bit = this.#decodeBit(encoder.m_Decoders, (1 + matchBit << 8) + symbol);
|
|
1242
1251
|
symbol = symbol << 1 | bit;
|
|
1243
1252
|
if (matchBit != bit) {
|
|
1244
1253
|
while (symbol < 256) {
|
|
1245
|
-
symbol = symbol << 1 | this.#decodeBit(
|
|
1254
|
+
symbol = symbol << 1 | this.#decodeBit(encoder.m_Decoders, symbol);
|
|
1246
1255
|
}
|
|
1247
1256
|
break;
|
|
1248
1257
|
}
|
|
1249
1258
|
} while (symbol < 256);
|
|
1250
|
-
return symbol
|
|
1259
|
+
return symbol & 0xFF;
|
|
1251
1260
|
}
|
|
1252
|
-
#createLiteralDecoderEncoder2(
|
|
1253
|
-
|
|
1254
|
-
|
|
1261
|
+
#createLiteralDecoderEncoder2() {
|
|
1262
|
+
const literalDecoder = {
|
|
1263
|
+
m_Decoders: this.#initArray(0x300),
|
|
1264
|
+
};
|
|
1265
|
+
return literalDecoder;
|
|
1255
1266
|
}
|
|
1256
1267
|
#Backward(cur) {
|
|
1257
|
-
const
|
|
1268
|
+
const encoder = this.#compressor.chunker.encoder;
|
|
1258
1269
|
let backCur, backMem, posMem, posPrev;
|
|
1259
|
-
|
|
1260
|
-
posMem =
|
|
1261
|
-
backMem =
|
|
1270
|
+
encoder._optimumEndIndex = cur;
|
|
1271
|
+
posMem = encoder._optimum[cur].PosPrev;
|
|
1272
|
+
backMem = encoder._optimum[cur].BackPrev;
|
|
1262
1273
|
do {
|
|
1263
|
-
if (
|
|
1264
|
-
this.#MakeAsChar(
|
|
1265
|
-
|
|
1266
|
-
if (
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1274
|
+
if (encoder._optimum[cur].Prev1IsChar) {
|
|
1275
|
+
this.#MakeAsChar(encoder._optimum[posMem]);
|
|
1276
|
+
encoder._optimum[posMem].PosPrev = posMem - 1;
|
|
1277
|
+
if (encoder._optimum[cur].Prev2) {
|
|
1278
|
+
encoder._optimum[posMem - 1].Prev1IsChar = 0;
|
|
1279
|
+
encoder._optimum[posMem - 1].PosPrev = encoder._optimum[cur].PosPrev2;
|
|
1280
|
+
encoder._optimum[posMem - 1].BackPrev = encoder._optimum[cur].BackPrev2;
|
|
1270
1281
|
}
|
|
1271
1282
|
}
|
|
1272
1283
|
posPrev = posMem;
|
|
1273
1284
|
backCur = backMem;
|
|
1274
|
-
backMem =
|
|
1275
|
-
posMem =
|
|
1276
|
-
|
|
1277
|
-
|
|
1285
|
+
backMem = encoder._optimum[posPrev].BackPrev;
|
|
1286
|
+
posMem = encoder._optimum[posPrev].PosPrev;
|
|
1287
|
+
encoder._optimum[posPrev].BackPrev = backCur;
|
|
1288
|
+
encoder._optimum[posPrev].PosPrev = cur;
|
|
1278
1289
|
cur = posPrev;
|
|
1279
1290
|
} while (cur > 0);
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
return
|
|
1291
|
+
encoder.backRes = encoder._optimum[0].BackPrev;
|
|
1292
|
+
encoder._optimumCurrentIndex = encoder._optimum[0].PosPrev;
|
|
1293
|
+
return encoder._optimumCurrentIndex;
|
|
1283
1294
|
}
|
|
1284
1295
|
#BaseInit() {
|
|
1285
1296
|
this.#encoder._state = 0;
|
|
@@ -1315,7 +1326,7 @@ export class LZMA {
|
|
|
1315
1326
|
this.#Encode_3(this.#compressor.chunker.encoder._isMatch, (this.#compressor.chunker.encoder._state << 4) + posState, 0);
|
|
1316
1327
|
this.#compressor.chunker.encoder._state = this.StateUpdateChar(this.#compressor.chunker.encoder._state);
|
|
1317
1328
|
curByte = this.#GetIndexByte(-this.#compressor.chunker.encoder._additionalOffset);
|
|
1318
|
-
this.#Encode_1(this.#
|
|
1329
|
+
this.#Encode_1(this.#LZMA_Encoder_GetSubCoder(this.#lowBits_0(this.#compressor.chunker.encoder.nowPos64), this.#compressor.chunker.encoder._previousByte), curByte);
|
|
1319
1330
|
this.#compressor.chunker.encoder._previousByte = curByte;
|
|
1320
1331
|
this.#compressor.chunker.encoder._additionalOffset -= 1;
|
|
1321
1332
|
this.#compressor.chunker.encoder.nowPos64 = this.#add(this.#compressor.chunker.encoder.nowPos64, this.#P1_LONG_LIT);
|
|
@@ -1333,7 +1344,7 @@ export class LZMA {
|
|
|
1333
1344
|
if (len == 1 && pos == -1) {
|
|
1334
1345
|
this.#Encode_3(this.#compressor.chunker.encoder._isMatch, complexState, 0);
|
|
1335
1346
|
curByte = this.#GetIndexByte(-this.#compressor.chunker.encoder._additionalOffset);
|
|
1336
|
-
subCoder = this.#
|
|
1347
|
+
subCoder = this.#LZMA_Encoder_GetSubCoder(this.#lowBits_0(this.#compressor.chunker.encoder.nowPos64), this.#compressor.chunker.encoder._previousByte);
|
|
1337
1348
|
if (this.#compressor.chunker.encoder._state < 7) {
|
|
1338
1349
|
this.#Encode_1(subCoder, curByte);
|
|
1339
1350
|
}
|
|
@@ -1456,7 +1467,7 @@ export class LZMA {
|
|
|
1456
1467
|
this.#SetType(binTree, numHashBytes);
|
|
1457
1468
|
this.#encoder._matchFinder = binTree;
|
|
1458
1469
|
}
|
|
1459
|
-
this.#
|
|
1470
|
+
this.#LZMA_Encoder_LiteralEncoder_Create();
|
|
1460
1471
|
if (this.#encoder._dictionarySize == this.#encoder._dictionarySizePrev
|
|
1461
1472
|
&& this.#encoder._numFastBytesPrev == this.#encoder._numFastBytes) {
|
|
1462
1473
|
return;
|
|
@@ -1491,7 +1502,7 @@ export class LZMA {
|
|
|
1491
1502
|
encoder = obj._posSlotEncoder[lenToPosState];
|
|
1492
1503
|
st = lenToPosState << 6;
|
|
1493
1504
|
for (posSlot = 0; posSlot < obj._distTableSize; posSlot += 1) {
|
|
1494
|
-
obj._posSlotPrices[st + posSlot] = this.#
|
|
1505
|
+
obj._posSlotPrices[st + posSlot] = this.#RangeCoder_Encoder_GetPrice_1(encoder, posSlot);
|
|
1495
1506
|
}
|
|
1496
1507
|
for (posSlot = 14; posSlot < obj._distTableSize; posSlot += 1) {
|
|
1497
1508
|
obj._posSlotPrices[st + posSlot] += (posSlot >> 1) - 1 - 4 << 6;
|
|
@@ -1567,7 +1578,7 @@ export class LZMA {
|
|
|
1567
1578
|
}
|
|
1568
1579
|
encoder._optimum[0].State = encoder._state;
|
|
1569
1580
|
posState = position & encoder._posStateMask;
|
|
1570
|
-
encoder._optimum[1].Price = this.#probPrices[encoder._isMatch[(encoder._state << 4) + posState] >>> 2] + this.#
|
|
1581
|
+
encoder._optimum[1].Price = this.#probPrices[encoder._isMatch[(encoder._state << 4) + posState] >>> 2] + this.#RangeCoder_Encoder_GetPrice_0(this.#LZMA_Encoder_GetSubCoder(position, encoder._previousByte), encoder._state >= 7, matchByte, currentByte);
|
|
1571
1582
|
this.#MakeAsChar(encoder._optimum[1]);
|
|
1572
1583
|
matchPrice = this.#probPrices[2_048
|
|
1573
1584
|
- encoder._isMatch[(encoder._state << 4) + posState]
|
|
@@ -1594,7 +1605,7 @@ export class LZMA {
|
|
|
1594
1605
|
encoder._optimum[0].Backs3 = encoder.reps[3];
|
|
1595
1606
|
len = lenEnd;
|
|
1596
1607
|
do {
|
|
1597
|
-
encoder._optimum[len].Price =
|
|
1608
|
+
encoder._optimum[len].Price = this.#kIfinityPrice;
|
|
1598
1609
|
len -= 1;
|
|
1599
1610
|
} while (len >= 2);
|
|
1600
1611
|
for (let i = 0; i < 4; ++i) {
|
|
@@ -1604,7 +1615,7 @@ export class LZMA {
|
|
|
1604
1615
|
}
|
|
1605
1616
|
price_4 = repMatchPrice + this.#GetPureRepPrice(i, encoder._state, posState);
|
|
1606
1617
|
do {
|
|
1607
|
-
curAndLenPrice = price_4 + this.#
|
|
1618
|
+
curAndLenPrice = price_4 + this.#RangeCoder_Encoder_GetPrice(encoder._repMatchLenEncoder, repLen - 2, posState);
|
|
1608
1619
|
optimum = encoder._optimum[repLen];
|
|
1609
1620
|
if (curAndLenPrice < optimum.Price) {
|
|
1610
1621
|
optimum.Price = curAndLenPrice;
|
|
@@ -1624,7 +1635,7 @@ export class LZMA {
|
|
|
1624
1635
|
}
|
|
1625
1636
|
for (;; len += 1) {
|
|
1626
1637
|
distance = encoder._matchDistances[offs + 1];
|
|
1627
|
-
curAndLenPrice = normalMatchPrice + this.#
|
|
1638
|
+
curAndLenPrice = normalMatchPrice + this.#LZMA_Encoder_GetPosLenPrice(distance, len, posState);
|
|
1628
1639
|
optimum = encoder._optimum[len];
|
|
1629
1640
|
if (curAndLenPrice < optimum.Price) {
|
|
1630
1641
|
optimum.Price = curAndLenPrice;
|
|
@@ -1743,7 +1754,7 @@ export class LZMA {
|
|
|
1743
1754
|
posState = position & encoder._posStateMask;
|
|
1744
1755
|
curAnd1Price = curPrice
|
|
1745
1756
|
+ this.#probPrices[encoder._isMatch[(state << 4) + posState] >>> 2]
|
|
1746
|
-
+ this.#
|
|
1757
|
+
+ this.#RangeCoder_Encoder_GetPrice_0(this.#LZMA_Encoder_GetSubCoder(position, this.#GetIndexByte(-2)), state >= 7, matchByte, currentByte);
|
|
1747
1758
|
nextOptimum = encoder._optimum[cur + 1];
|
|
1748
1759
|
nextIsChar = 0;
|
|
1749
1760
|
if (curAnd1Price < nextOptimum.Price) {
|
|
@@ -1786,9 +1797,9 @@ export class LZMA {
|
|
|
1786
1797
|
nextRepMatchPrice = curAnd1Price + this.#probPrices[2_048 - encoder._isMatch[(state2 << 4) + posStateNext] >>> 2] + this.#probPrices[2_048 - encoder._isRep[state2] >>> 2];
|
|
1787
1798
|
offset = cur + 1 + lenTest2;
|
|
1788
1799
|
while (lenEnd < offset) {
|
|
1789
|
-
encoder._optimum[lenEnd += 1].Price =
|
|
1800
|
+
encoder._optimum[lenEnd += 1].Price = this.#kIfinityPrice;
|
|
1790
1801
|
}
|
|
1791
|
-
curAndLenPrice = nextRepMatchPrice + (price = this.#
|
|
1802
|
+
curAndLenPrice = nextRepMatchPrice + (price = this.#RangeCoder_Encoder_GetPrice(encoder._repMatchLenEncoder, lenTest2 - 2, posStateNext),
|
|
1792
1803
|
price + this.#GetPureRepPrice(0, state2, posStateNext));
|
|
1793
1804
|
optimum = encoder._optimum[offset];
|
|
1794
1805
|
if (curAndLenPrice < optimum.Price) {
|
|
@@ -1809,9 +1820,9 @@ export class LZMA {
|
|
|
1809
1820
|
lenTestTemp = lenTest;
|
|
1810
1821
|
do {
|
|
1811
1822
|
while (lenEnd < cur + lenTest) {
|
|
1812
|
-
encoder._optimum[lenEnd += 1].Price =
|
|
1823
|
+
encoder._optimum[lenEnd += 1].Price = this.#kIfinityPrice;
|
|
1813
1824
|
}
|
|
1814
|
-
curAndLenPrice = repMatchPrice + (price_0 = this.#
|
|
1825
|
+
curAndLenPrice = repMatchPrice + (price_0 = this.#RangeCoder_Encoder_GetPrice(encoder._repMatchLenEncoder, lenTest - 2, posState),
|
|
1815
1826
|
price_0 + this.#GetPureRepPrice(repIndex, state, posState));
|
|
1816
1827
|
optimum = encoder._optimum[cur + lenTest];
|
|
1817
1828
|
if (curAndLenPrice < optimum.Price) {
|
|
@@ -1831,18 +1842,18 @@ export class LZMA {
|
|
|
1831
1842
|
if (lenTest2 >= 2) {
|
|
1832
1843
|
state2 = state < 7 ? 8 : 11;
|
|
1833
1844
|
posStateNext = position + lenTest & encoder._posStateMask;
|
|
1834
|
-
curAndLenCharPrice = repMatchPrice + (price_1 = this.#
|
|
1845
|
+
curAndLenCharPrice = repMatchPrice + (price_1 = this.#RangeCoder_Encoder_GetPrice(encoder._repMatchLenEncoder, lenTest - 2, posState),
|
|
1835
1846
|
price_1 + this.#GetPureRepPrice(repIndex, state, posState))
|
|
1836
|
-
+ this.#probPrices[encoder._isMatch[(state2 << 4) + posStateNext] >>> 2] + this.#
|
|
1847
|
+
+ this.#probPrices[encoder._isMatch[(state2 << 4) + posStateNext] >>> 2] + this.#RangeCoder_Encoder_GetPrice_0(this.#LZMA_Encoder_GetSubCoder(position + lenTest, this.#GetIndexByte(lenTest - 1 - 1)), 1, this.#GetIndexByte(lenTest - 1 - (encoder.reps[repIndex] + 1)), this.#GetIndexByte(lenTest - 1));
|
|
1837
1848
|
state2 = this.StateUpdateChar(state2);
|
|
1838
1849
|
posStateNext = position + lenTest + 1 & encoder._posStateMask;
|
|
1839
1850
|
nextMatchPrice = curAndLenCharPrice + this.#probPrices[2_048 - encoder._isMatch[(state2 << 4) + posStateNext] >>> 2];
|
|
1840
1851
|
nextRepMatchPrice = nextMatchPrice + this.#probPrices[2_048 - encoder._isRep[state2] >>> 2];
|
|
1841
1852
|
offset = cur + 1 + lenTest + lenTest2;
|
|
1842
1853
|
while (lenEnd < cur + offset) {
|
|
1843
|
-
encoder._optimum[lenEnd += 1].Price =
|
|
1854
|
+
encoder._optimum[lenEnd += 1].Price = this.#kIfinityPrice;
|
|
1844
1855
|
}
|
|
1845
|
-
curAndLenPrice = nextRepMatchPrice + (price_2 = this.#
|
|
1856
|
+
curAndLenPrice = nextRepMatchPrice + (price_2 = this.#RangeCoder_Encoder_GetPrice(encoder._repMatchLenEncoder, lenTest2 - 2, posStateNext),
|
|
1846
1857
|
price_2 + this.#GetPureRepPrice(0, state2, posStateNext));
|
|
1847
1858
|
optimum = encoder._optimum[cur + offset];
|
|
1848
1859
|
if (curAndLenPrice < optimum.Price) {
|
|
@@ -1866,7 +1877,7 @@ export class LZMA {
|
|
|
1866
1877
|
if (newLen >= startLen) {
|
|
1867
1878
|
normalMatchPrice = matchPrice + this.#probPrices[encoder._isRep[state] >>> 2];
|
|
1868
1879
|
while (lenEnd < cur + newLen) {
|
|
1869
|
-
encoder._optimum[lenEnd += 1].Price =
|
|
1880
|
+
encoder._optimum[lenEnd += 1].Price = this.#kIfinityPrice;
|
|
1870
1881
|
}
|
|
1871
1882
|
offs = 0;
|
|
1872
1883
|
while (startLen > encoder._matchDistances[offs]) {
|
|
@@ -1874,7 +1885,7 @@ export class LZMA {
|
|
|
1874
1885
|
}
|
|
1875
1886
|
for (lenTest = startLen;; lenTest += 1) {
|
|
1876
1887
|
curBack = encoder._matchDistances[offs + 1];
|
|
1877
|
-
curAndLenPrice = normalMatchPrice + this.#
|
|
1888
|
+
curAndLenPrice = normalMatchPrice + this.#LZMA_Encoder_GetPosLenPrice(curBack, lenTest, posState);
|
|
1878
1889
|
optimum = encoder._optimum[cur + lenTest];
|
|
1879
1890
|
if (curAndLenPrice < optimum.Price) {
|
|
1880
1891
|
optimum.Price = curAndLenPrice;
|
|
@@ -1889,7 +1900,7 @@ export class LZMA {
|
|
|
1889
1900
|
if (lenTest2 >= 2) {
|
|
1890
1901
|
state2 = state < 7 ? 7 : 10;
|
|
1891
1902
|
posStateNext = position + lenTest & encoder._posStateMask;
|
|
1892
|
-
curAndLenCharPrice = curAndLenPrice + this.#probPrices[encoder._isMatch[(state2 << 4) + posStateNext] >>> 2] + this.#
|
|
1903
|
+
curAndLenCharPrice = curAndLenPrice + this.#probPrices[encoder._isMatch[(state2 << 4) + posStateNext] >>> 2] + this.#RangeCoder_Encoder_GetPrice_0(this.#LZMA_Encoder_GetSubCoder(position + lenTest, this.#GetIndexByte(lenTest - 1 - 1)), 1, this.#GetIndexByte(lenTest - (curBack + 1) - 1), this.#GetIndexByte(lenTest - 1));
|
|
1893
1904
|
state2 = this.StateUpdateChar(state2);
|
|
1894
1905
|
posStateNext = position + lenTest + 1 & encoder._posStateMask;
|
|
1895
1906
|
nextMatchPrice = curAndLenCharPrice + this.#probPrices[2_048 - encoder._isMatch[(state2 << 4) + posStateNext]
|
|
@@ -1897,9 +1908,9 @@ export class LZMA {
|
|
|
1897
1908
|
nextRepMatchPrice = nextMatchPrice + this.#probPrices[2_048 - encoder._isRep[state2] >>> 2];
|
|
1898
1909
|
offset = lenTest + 1 + lenTest2;
|
|
1899
1910
|
while (lenEnd < cur + offset) {
|
|
1900
|
-
encoder._optimum[lenEnd += 1].Price =
|
|
1911
|
+
encoder._optimum[lenEnd += 1].Price = this.#kIfinityPrice;
|
|
1901
1912
|
}
|
|
1902
|
-
curAndLenPrice = nextRepMatchPrice + (price_3 = this.#
|
|
1913
|
+
curAndLenPrice = nextRepMatchPrice + (price_3 = this.#RangeCoder_Encoder_GetPrice(encoder._repMatchLenEncoder, lenTest2 - 2, posStateNext),
|
|
1903
1914
|
price_3 + this.#GetPureRepPrice(0, state2, posStateNext));
|
|
1904
1915
|
optimum = encoder._optimum[cur + offset];
|
|
1905
1916
|
if (curAndLenPrice < optimum.Price) {
|
|
@@ -1922,19 +1933,20 @@ export class LZMA {
|
|
|
1922
1933
|
}
|
|
1923
1934
|
}
|
|
1924
1935
|
}
|
|
1925
|
-
#
|
|
1936
|
+
#LZMA_Encoder_GetPosLenPrice(pos, len, posState) {
|
|
1937
|
+
const encoder = this.#compressor.chunker.encoder;
|
|
1926
1938
|
let price, lenToPosState = this.GetLenToPosState(len);
|
|
1927
1939
|
if (pos < 128) {
|
|
1928
|
-
price =
|
|
1940
|
+
price = encoder._distancesPrices[lenToPosState * 128 + pos];
|
|
1929
1941
|
}
|
|
1930
1942
|
else {
|
|
1931
|
-
|
|
1932
|
-
|
|
1943
|
+
const position = (lenToPosState << 6) + this.GetPosSlot2(pos);
|
|
1944
|
+
price = encoder._posSlotPrices[position] + encoder._alignPrices[pos & 15];
|
|
1933
1945
|
}
|
|
1934
|
-
return price + this.#
|
|
1946
|
+
return price + this.#RangeCoder_Encoder_GetPrice(encoder._lenEncoder, len - 2, posState);
|
|
1935
1947
|
}
|
|
1936
1948
|
#GetPureRepPrice(repIndex, state, posState) {
|
|
1937
|
-
|
|
1949
|
+
let price;
|
|
1938
1950
|
if (!repIndex) {
|
|
1939
1951
|
price = this.#probPrices[this.#compressor.chunker.encoder._isRepG0[state] >>> 2];
|
|
1940
1952
|
price += this.#probPrices[2_048 - this.#compressor.chunker.encoder._isRep0Long[(state << 4) + posState] >>> 2];
|
|
@@ -1985,23 +1997,16 @@ export class LZMA {
|
|
|
1985
1997
|
}
|
|
1986
1998
|
}
|
|
1987
1999
|
#ReadMatchDistances() {
|
|
1988
|
-
|
|
1989
|
-
this.#compressor.chunker.encoder
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
.encoder
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
.#compressor
|
|
1999
|
-
.chunker
|
|
2000
|
-
.encoder
|
|
2001
|
-
._matchDistances[this.#compressor.chunker.encoder._numDistancePairs - 1], 273 - lenRes);
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
this.#compressor.chunker.encoder._additionalOffset += 1;
|
|
2000
|
+
let lenRes = 0;
|
|
2001
|
+
const encoder = this.#compressor.chunker.encoder;
|
|
2002
|
+
encoder._numDistancePairs = this.#GetMatches();
|
|
2003
|
+
if (encoder._numDistancePairs > 0) {
|
|
2004
|
+
lenRes = encoder._matchDistances[encoder._numDistancePairs - 2];
|
|
2005
|
+
if (lenRes == encoder._numFastBytes) {
|
|
2006
|
+
lenRes += this.#GetMatchLen(lenRes - 1, encoder._matchDistances[encoder._numDistancePairs - 1], 273 - lenRes);
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
encoder._additionalOffset += 1;
|
|
2005
2010
|
return lenRes;
|
|
2006
2011
|
}
|
|
2007
2012
|
#ReleaseMFStream() {
|
|
@@ -2016,7 +2021,8 @@ export class LZMA {
|
|
|
2016
2021
|
}
|
|
2017
2022
|
#SetDictionarySize_0(dictionarySize) {
|
|
2018
2023
|
this.#encoder._dictionarySize = dictionarySize;
|
|
2019
|
-
|
|
2024
|
+
let dicLogSize = 0;
|
|
2025
|
+
for (; dictionarySize > (1 << dicLogSize); ++dicLogSize)
|
|
2020
2026
|
;
|
|
2021
2027
|
this.#encoder._distTableSize = dicLogSize * 2;
|
|
2022
2028
|
}
|
|
@@ -2049,7 +2055,7 @@ export class LZMA {
|
|
|
2049
2055
|
this.#Encode_3(encoder._isRep, encoder._state, 0);
|
|
2050
2056
|
encoder._state = encoder._state < 7 ? 7 : 10;
|
|
2051
2057
|
this.#Encode_0(encoder._lenEncoder, 0, positionState);
|
|
2052
|
-
|
|
2058
|
+
let lenToPosState = this.GetLenToPosState(2);
|
|
2053
2059
|
this.#Encode_2(encoder._posSlotEncoder[lenToPosState], 63);
|
|
2054
2060
|
this.#EncodeDirectBits(67108863, 26);
|
|
2055
2061
|
this.#ReverseEncode(15);
|
|
@@ -2072,21 +2078,21 @@ export class LZMA {
|
|
|
2072
2078
|
}
|
|
2073
2079
|
return this.#gFastPos[pos >> 26] + 52;
|
|
2074
2080
|
}
|
|
2075
|
-
#Encode(
|
|
2081
|
+
#Encode(encoder, symbol, posState) {
|
|
2076
2082
|
if (symbol < 8) {
|
|
2077
|
-
this.#Encode_3(
|
|
2078
|
-
this.#Encode_2(
|
|
2083
|
+
this.#Encode_3(encoder._choice, 0, 0);
|
|
2084
|
+
this.#Encode_2(encoder._lowCoder[posState], symbol);
|
|
2079
2085
|
}
|
|
2080
2086
|
else {
|
|
2081
2087
|
symbol -= 8;
|
|
2082
|
-
this.#Encode_3(
|
|
2088
|
+
this.#Encode_3(encoder._choice, 0, 1);
|
|
2083
2089
|
if (symbol < 8) {
|
|
2084
|
-
this.#Encode_3(
|
|
2085
|
-
this.#Encode_2(
|
|
2090
|
+
this.#Encode_3(encoder._choice, 1, 0);
|
|
2091
|
+
this.#Encode_2(encoder._midCoder[posState], symbol);
|
|
2086
2092
|
}
|
|
2087
2093
|
else {
|
|
2088
|
-
this.#Encode_3(
|
|
2089
|
-
this.#Encode_2(
|
|
2094
|
+
this.#Encode_3(encoder._choice, 1, 1);
|
|
2095
|
+
this.#Encode_2(encoder._highCoder, symbol - 8);
|
|
2090
2096
|
}
|
|
2091
2097
|
}
|
|
2092
2098
|
}
|
|
@@ -2110,34 +2116,34 @@ export class LZMA {
|
|
|
2110
2116
|
}
|
|
2111
2117
|
this.InitBitModels(obj._highCoder.Models);
|
|
2112
2118
|
}
|
|
2113
|
-
#SetPrices(
|
|
2119
|
+
#SetPrices(encoder, posState, numSymbols, prices, st) {
|
|
2114
2120
|
let a0, a1, b0, b1, i;
|
|
2115
|
-
a0 = this.#probPrices[
|
|
2116
|
-
a1 = this.#probPrices[2_048 -
|
|
2117
|
-
b0 = a1 + this.#probPrices[
|
|
2118
|
-
b1 = a1 + this.#probPrices[2_048 -
|
|
2121
|
+
a0 = this.#probPrices[encoder._choice[0] >>> 2];
|
|
2122
|
+
a1 = this.#probPrices[2_048 - encoder._choice[0] >>> 2];
|
|
2123
|
+
b0 = a1 + this.#probPrices[encoder._choice[1] >>> 2];
|
|
2124
|
+
b1 = a1 + this.#probPrices[2_048 - encoder._choice[1] >>> 2];
|
|
2119
2125
|
i = 0;
|
|
2120
2126
|
for (i = 0; i < 8; ++i) {
|
|
2121
2127
|
if (i >= numSymbols) {
|
|
2122
2128
|
return;
|
|
2123
2129
|
}
|
|
2124
|
-
prices[st + i] = a0 + this.#
|
|
2130
|
+
prices[st + i] = a0 + this.#RangeCoder_Encoder_GetPrice_1(encoder._lowCoder[posState], i);
|
|
2125
2131
|
}
|
|
2126
2132
|
for (; i < 16; ++i) {
|
|
2127
2133
|
if (i >= numSymbols) {
|
|
2128
2134
|
return;
|
|
2129
2135
|
}
|
|
2130
|
-
prices[st + i] = b0 + this.#
|
|
2136
|
+
prices[st + i] = b0 + this.#RangeCoder_Encoder_GetPrice_1(encoder._midCoder[posState], i - 8);
|
|
2131
2137
|
}
|
|
2132
2138
|
for (; i < numSymbols; ++i) {
|
|
2133
|
-
prices[st + i] = b1 + this.#
|
|
2139
|
+
prices[st + i] = b1 + this.#RangeCoder_Encoder_GetPrice_1(encoder._highCoder, i - 8 - 8);
|
|
2134
2140
|
}
|
|
2135
2141
|
}
|
|
2136
|
-
#Encode_0(
|
|
2137
|
-
this.#Encode(
|
|
2138
|
-
if ((
|
|
2139
|
-
this.#SetPrices(
|
|
2140
|
-
|
|
2142
|
+
#Encode_0(encoder, symbol, posState) {
|
|
2143
|
+
this.#Encode(encoder, symbol, posState);
|
|
2144
|
+
if ((encoder._counters[posState] -= 1) == 0) {
|
|
2145
|
+
this.#SetPrices(encoder, posState, encoder._tableSize, encoder._prices, posState * 272);
|
|
2146
|
+
encoder._counters[posState] = encoder._tableSize;
|
|
2141
2147
|
}
|
|
2142
2148
|
}
|
|
2143
2149
|
#createLenPriceTableEncoder() {
|
|
@@ -2146,16 +2152,16 @@ export class LZMA {
|
|
|
2146
2152
|
encoder._counters = [];
|
|
2147
2153
|
return encoder;
|
|
2148
2154
|
}
|
|
2149
|
-
#
|
|
2150
|
-
return
|
|
2155
|
+
#RangeCoder_Encoder_GetPrice(encoder, symbol, posState) {
|
|
2156
|
+
return encoder._prices[posState * 272 + symbol];
|
|
2151
2157
|
}
|
|
2152
|
-
#
|
|
2158
|
+
#LZMA_LenPriceTableEncoder_UpdateTablesUpdateTables(encoder, numPosStates) {
|
|
2153
2159
|
for (let posState = 0; posState < numPosStates; ++posState) {
|
|
2154
|
-
this.#SetPrices(
|
|
2155
|
-
|
|
2160
|
+
this.#SetPrices(encoder, posState, encoder._tableSize, encoder._prices, posState * 272);
|
|
2161
|
+
encoder._counters[posState] = encoder._tableSize;
|
|
2156
2162
|
}
|
|
2157
2163
|
}
|
|
2158
|
-
#
|
|
2164
|
+
#LZMA_Encoder_LiteralEncoder_Create() {
|
|
2159
2165
|
let i, numStates;
|
|
2160
2166
|
if (this.#encoder._literalEncoder.m_Coders != null
|
|
2161
2167
|
&& this.#encoder._literalEncoder.m_NumPrevBits == this.#encoder._numLiteralContextBits
|
|
@@ -2168,10 +2174,10 @@ export class LZMA {
|
|
|
2168
2174
|
numStates = 1 << this.#encoder._literalEncoder.m_NumPrevBits + this.#encoder._literalEncoder.m_NumPosBits;
|
|
2169
2175
|
this.#encoder._literalEncoder.m_Coders = this.#initArray(numStates);
|
|
2170
2176
|
for (i = 0; i < numStates; ++i) {
|
|
2171
|
-
this.#encoder._literalEncoder.m_Coders[i] = this.#createLiteralEncoderEncoder2(
|
|
2177
|
+
this.#encoder._literalEncoder.m_Coders[i] = this.#createLiteralEncoderEncoder2();
|
|
2172
2178
|
}
|
|
2173
2179
|
}
|
|
2174
|
-
#
|
|
2180
|
+
#LZMA_Encoder_GetSubCoder(pos, prevByte) {
|
|
2175
2181
|
const literalEncoder = this.#compressor.chunker.encoder._literalEncoder;
|
|
2176
2182
|
// Calculate position mask bits
|
|
2177
2183
|
const posBits = pos & literalEncoder.m_PosMask;
|
|
@@ -2190,15 +2196,15 @@ export class LZMA {
|
|
|
2190
2196
|
this.InitBitModels(this.#encoder._literalEncoder.m_Coders[i].m_Encoders);
|
|
2191
2197
|
}
|
|
2192
2198
|
}
|
|
2193
|
-
#Encode_1(
|
|
2194
|
-
|
|
2199
|
+
#Encode_1(encoder, symbol) {
|
|
2200
|
+
let bit, context = 1;
|
|
2195
2201
|
for (let i = 7; i >= 0; --i) {
|
|
2196
2202
|
bit = symbol >> i & 1;
|
|
2197
|
-
this.#Encode_3(
|
|
2203
|
+
this.#Encode_3(encoder.m_Encoders, context, bit);
|
|
2198
2204
|
context = context << 1 | bit;
|
|
2199
2205
|
}
|
|
2200
2206
|
}
|
|
2201
|
-
#EncodeMatched(
|
|
2207
|
+
#EncodeMatched(encoder, matchByte, symbol) {
|
|
2202
2208
|
let bit, matchBit, state, same = true, context = 1;
|
|
2203
2209
|
for (let i = 7; i >= 0; --i) {
|
|
2204
2210
|
bit = symbol >> i & 1;
|
|
@@ -2208,21 +2214,23 @@ export class LZMA {
|
|
|
2208
2214
|
state += 1 + matchBit << 8;
|
|
2209
2215
|
same = matchBit === bit;
|
|
2210
2216
|
}
|
|
2211
|
-
this.#Encode_3(
|
|
2217
|
+
this.#Encode_3(encoder.m_Encoders, state, bit);
|
|
2212
2218
|
context = context << 1 | bit;
|
|
2213
2219
|
}
|
|
2214
2220
|
}
|
|
2215
|
-
#createLiteralEncoderEncoder2(
|
|
2216
|
-
|
|
2217
|
-
|
|
2221
|
+
#createLiteralEncoderEncoder2() {
|
|
2222
|
+
const encoder = {
|
|
2223
|
+
m_Encoders: this.#initArray(768),
|
|
2224
|
+
};
|
|
2225
|
+
return encoder;
|
|
2218
2226
|
}
|
|
2219
|
-
#
|
|
2227
|
+
#RangeCoder_Encoder_GetPrice_0(encoder, matchMode, matchByte, symbol) {
|
|
2220
2228
|
let bit, context = 1, i = 7, matchBit, price = 0;
|
|
2221
2229
|
if (matchMode) {
|
|
2222
2230
|
for (; i >= 0; --i) {
|
|
2223
2231
|
matchBit = matchByte >> i & 1;
|
|
2224
2232
|
bit = symbol >> i & 1;
|
|
2225
|
-
price += this.GetPrice(
|
|
2233
|
+
price += this.GetPrice(encoder.m_Encoders[(1 + matchBit << 8) + context], bit);
|
|
2226
2234
|
context = context << 1 | bit;
|
|
2227
2235
|
if (matchBit != bit) {
|
|
2228
2236
|
--i;
|
|
@@ -2232,18 +2240,18 @@ export class LZMA {
|
|
|
2232
2240
|
}
|
|
2233
2241
|
for (; i >= 0; --i) {
|
|
2234
2242
|
bit = symbol >> i & 1;
|
|
2235
|
-
price += this.GetPrice(
|
|
2243
|
+
price += this.GetPrice(encoder.m_Encoders[context], bit);
|
|
2236
2244
|
context = context << 1 | bit;
|
|
2237
2245
|
}
|
|
2238
2246
|
return price;
|
|
2239
2247
|
}
|
|
2240
|
-
#MakeAsChar(
|
|
2241
|
-
|
|
2242
|
-
|
|
2248
|
+
#MakeAsChar(optimum) {
|
|
2249
|
+
optimum.BackPrev = -1;
|
|
2250
|
+
optimum.Prev1IsChar = 0;
|
|
2243
2251
|
}
|
|
2244
|
-
#MakeAsShortRep(
|
|
2245
|
-
|
|
2246
|
-
|
|
2252
|
+
#MakeAsShortRep(optimum) {
|
|
2253
|
+
optimum.BackPrev = 0;
|
|
2254
|
+
optimum.Prev1IsChar = 0;
|
|
2247
2255
|
}
|
|
2248
2256
|
#createBitTreeDecoder(numBitLevels) {
|
|
2249
2257
|
return {
|
|
@@ -2251,8 +2259,7 @@ export class LZMA {
|
|
|
2251
2259
|
Models: this.#initArray(1 << numBitLevels),
|
|
2252
2260
|
};
|
|
2253
2261
|
}
|
|
2254
|
-
|
|
2255
|
-
#Decode_0(rangeDecoder) {
|
|
2262
|
+
#RangeCoder_BitTreeDecoder_Decoder(rangeDecoder) {
|
|
2256
2263
|
const _rangeDecoder = this.#decompressor.chunker.decoder.m_RangeDecoder;
|
|
2257
2264
|
let bitIndex, m = 1;
|
|
2258
2265
|
for (bitIndex = rangeDecoder.NumBitLevels; bitIndex != 0; bitIndex -= 1) {
|
|
@@ -2288,28 +2295,28 @@ export class LZMA {
|
|
|
2288
2295
|
Models: this.#initArray(1 << numBitLevels),
|
|
2289
2296
|
};
|
|
2290
2297
|
}
|
|
2291
|
-
#Encode_2(
|
|
2292
|
-
|
|
2293
|
-
for (bitIndex =
|
|
2298
|
+
#Encode_2(encoder, symbol) {
|
|
2299
|
+
let bit, bitIndex, m = 1;
|
|
2300
|
+
for (bitIndex = encoder.NumBitLevels; bitIndex != 0;) {
|
|
2294
2301
|
bitIndex -= 1;
|
|
2295
2302
|
bit = symbol >>> bitIndex & 1;
|
|
2296
|
-
this.#Encode_3(
|
|
2303
|
+
this.#Encode_3(encoder.Models, m, bit);
|
|
2297
2304
|
m = m << 1 | bit;
|
|
2298
2305
|
}
|
|
2299
2306
|
}
|
|
2300
|
-
#
|
|
2301
|
-
|
|
2302
|
-
for (bitIndex =
|
|
2307
|
+
#RangeCoder_Encoder_GetPrice_1(encoder, symbol) {
|
|
2308
|
+
let bit, bitIndex, m = 1, price = 0;
|
|
2309
|
+
for (bitIndex = encoder.NumBitLevels; bitIndex != 0;) {
|
|
2303
2310
|
bitIndex -= 1;
|
|
2304
2311
|
bit = symbol >>> bitIndex & 1;
|
|
2305
|
-
price += this.GetPrice(
|
|
2312
|
+
price += this.GetPrice(encoder.Models[m], bit);
|
|
2306
2313
|
m = (m << 1) + bit;
|
|
2307
2314
|
}
|
|
2308
2315
|
return price;
|
|
2309
2316
|
}
|
|
2310
2317
|
#ReverseEncode(symbol) {
|
|
2311
2318
|
const posAlignEncoder = this.#compressor.chunker.encoder._posAlignEncoder;
|
|
2312
|
-
|
|
2319
|
+
let bit, m = 1;
|
|
2313
2320
|
for (let i = 0; i < posAlignEncoder.NumBitLevels; ++i) {
|
|
2314
2321
|
bit = symbol & 1;
|
|
2315
2322
|
this.#Encode_3(posAlignEncoder.Models, m, bit);
|
|
@@ -2326,18 +2333,18 @@ export class LZMA {
|
|
|
2326
2333
|
symbol >>= 1;
|
|
2327
2334
|
}
|
|
2328
2335
|
}
|
|
2329
|
-
#ReverseGetPrice(
|
|
2336
|
+
#ReverseGetPrice(encoder, symbol) {
|
|
2330
2337
|
let bit, m = 1, price = 0;
|
|
2331
|
-
for (let i =
|
|
2338
|
+
for (let i = encoder.NumBitLevels; i != 0; i -= 1) {
|
|
2332
2339
|
bit = symbol & 1;
|
|
2333
2340
|
symbol >>>= 1;
|
|
2334
|
-
price += this.GetPrice(
|
|
2341
|
+
price += this.GetPrice(encoder.Models[m], bit);
|
|
2335
2342
|
m = m << 1 | bit;
|
|
2336
2343
|
}
|
|
2337
2344
|
return price;
|
|
2338
2345
|
}
|
|
2339
2346
|
ReverseGetPrice(Models, startIndex, NumBitLevels, symbol) {
|
|
2340
|
-
|
|
2347
|
+
let bit, m = 1, price = 0;
|
|
2341
2348
|
for (let i = NumBitLevels; i != 0; i -= 1) {
|
|
2342
2349
|
bit = symbol & 1;
|
|
2343
2350
|
symbol >>>= 1;
|
|
@@ -2353,7 +2360,7 @@ export class LZMA {
|
|
|
2353
2360
|
if ((rangeDecoder.Code ^ this.#MIN_INT32) < (newBound ^ this.#MIN_INT32)) {
|
|
2354
2361
|
rangeDecoder.Range = newBound;
|
|
2355
2362
|
probs[index] = prob + (2_048 - prob >>> 5) << 16 >> 16;
|
|
2356
|
-
if (!(rangeDecoder.Range &
|
|
2363
|
+
if (!(rangeDecoder.Range & this.bitMaskForRange)) {
|
|
2357
2364
|
rangeDecoder.Code = rangeDecoder.Code << 8 | this.#read(rangeDecoder.Stream);
|
|
2358
2365
|
rangeDecoder.Range <<= 8;
|
|
2359
2366
|
}
|
|
@@ -2363,7 +2370,7 @@ export class LZMA {
|
|
|
2363
2370
|
rangeDecoder.Range -= newBound;
|
|
2364
2371
|
rangeDecoder.Code -= newBound;
|
|
2365
2372
|
probs[index] = prob - (prob >>> 5) << 16 >> 16;
|
|
2366
|
-
if (!(rangeDecoder.Range &
|
|
2373
|
+
if (!(rangeDecoder.Range & this.bitMaskForRange)) {
|
|
2367
2374
|
rangeDecoder.Code = rangeDecoder.Code << 8 | this.#read(rangeDecoder.Stream);
|
|
2368
2375
|
rangeDecoder.Range <<= 8;
|
|
2369
2376
|
}
|
|
@@ -2378,7 +2385,7 @@ export class LZMA {
|
|
|
2378
2385
|
let t = rangeDecoder.Code - rangeDecoder.Range >>> 31;
|
|
2379
2386
|
rangeDecoder.Code -= rangeDecoder.Range & t - 1;
|
|
2380
2387
|
result = result << 1 | 1 - t;
|
|
2381
|
-
if (!(rangeDecoder.Range &
|
|
2388
|
+
if (!(rangeDecoder.Range & this.bitMaskForRange)) {
|
|
2382
2389
|
rangeDecoder.Code = rangeDecoder.Code << 8 | this.#read(rangeDecoder.Stream);
|
|
2383
2390
|
rangeDecoder.Range <<= 8;
|
|
2384
2391
|
}
|
|
@@ -2400,18 +2407,18 @@ export class LZMA {
|
|
|
2400
2407
|
}
|
|
2401
2408
|
#Encode_3(probs, index, symbol) {
|
|
2402
2409
|
const rangeEncoder = this.#compressor.chunker.encoder._rangeEncoder;
|
|
2403
|
-
|
|
2410
|
+
let newBound, prob = probs[index];
|
|
2404
2411
|
newBound = (rangeEncoder.Range >>> 11) * prob;
|
|
2405
2412
|
if (!symbol) {
|
|
2406
2413
|
rangeEncoder.Range = newBound;
|
|
2407
2414
|
probs[index] = prob + (2_048 - prob >>> 5) << 16 >> 16;
|
|
2408
2415
|
}
|
|
2409
2416
|
else {
|
|
2410
|
-
rangeEncoder.Low = this.#add(rangeEncoder.Low, this.#and(this.#fromInt(newBound), [
|
|
2417
|
+
rangeEncoder.Low = this.#add(rangeEncoder.Low, this.#and(this.#fromInt(newBound), [this.#_MAX_UINT32, 0]));
|
|
2411
2418
|
rangeEncoder.Range -= newBound;
|
|
2412
2419
|
probs[index] = prob - (prob >>> 5) << 16 >> 16;
|
|
2413
2420
|
}
|
|
2414
|
-
if (!(rangeEncoder.Range &
|
|
2421
|
+
if (!(rangeEncoder.Range & this.bitMaskForRange)) {
|
|
2415
2422
|
rangeEncoder.Range <<= 8;
|
|
2416
2423
|
this.#ShiftLow();
|
|
2417
2424
|
}
|
|
@@ -2423,7 +2430,7 @@ export class LZMA {
|
|
|
2423
2430
|
if ((valueToEncode >>> i & 1) == 1) {
|
|
2424
2431
|
rangeEncoder.Low = this.#add(rangeEncoder.Low, this.#fromInt(rangeEncoder.Range));
|
|
2425
2432
|
}
|
|
2426
|
-
if (!(rangeEncoder.Range &
|
|
2433
|
+
if (!(rangeEncoder.Range & this.bitMaskForRange)) {
|
|
2427
2434
|
rangeEncoder.Range <<= 8;
|
|
2428
2435
|
this.#ShiftLow();
|
|
2429
2436
|
}
|
|
@@ -2547,16 +2554,16 @@ export class LZMA {
|
|
|
2547
2554
|
for (let i = 0; i < l; ++i) {
|
|
2548
2555
|
ch = chars[i];
|
|
2549
2556
|
if (ch >= 1 && ch <= 127) {
|
|
2550
|
-
data[elen++] = ch
|
|
2557
|
+
data[elen++] = ch & 0xFF;
|
|
2551
2558
|
}
|
|
2552
2559
|
else if (!ch || ch >= 128 && ch <= 2047) {
|
|
2553
|
-
data[elen++] = (192 | ch >> 6 & 31)
|
|
2554
|
-
data[elen++] = (128 | ch & 63)
|
|
2560
|
+
data[elen++] = (192 | ch >> 6 & 31) & 0xFF;
|
|
2561
|
+
data[elen++] = (128 | ch & 63) & 0xFF;
|
|
2555
2562
|
}
|
|
2556
2563
|
else {
|
|
2557
|
-
data[elen++] = (224 | ch >> 12 & 15)
|
|
2558
|
-
data[elen++] = (128 | ch >> 6 & 63)
|
|
2559
|
-
data[elen++] = (128 | ch & 63)
|
|
2564
|
+
data[elen++] = (224 | ch >> 12 & 15) & 0xFF;
|
|
2565
|
+
data[elen++] = (128 | ch >> 6 & 63) & 0xFF;
|
|
2566
|
+
data[elen++] = (128 | ch & 63) & 0xFF;
|
|
2560
2567
|
}
|
|
2561
2568
|
}
|
|
2562
2569
|
return data;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lzma1",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"authors": [
|
|
7
7
|
"Filip Seman <filip.seman@pm.me>",
|
|
@@ -27,14 +27,12 @@
|
|
|
27
27
|
"fmt": "dprint fmt",
|
|
28
28
|
"fmt:check": "dprint check",
|
|
29
29
|
"typecheck": "tsc --noEmit",
|
|
30
|
-
"version": "git checkout develop && npm test",
|
|
31
|
-
"postversion": "echo 'Now run npm run build && npm publish'",
|
|
32
30
|
"test": "TS_NODE_TRANSPILE_ONLY=true node --no-warnings --test --test-reporter=spec --loader=ts-node/esm ./*.test.ts",
|
|
33
31
|
"test:watch": "TS_NODE_TRANSPILE_ONLY=true node --no-warnings --test --watch --test-reporter=spec --loader=ts-node/esm ./*.test.ts"
|
|
34
32
|
},
|
|
35
33
|
"dependencies": {},
|
|
36
34
|
"devDependencies": {
|
|
37
|
-
"@types/node": "
|
|
35
|
+
"@types/node": "^22.10.0",
|
|
38
36
|
"dprint": "~0.47.0",
|
|
39
37
|
"ts-node": "~10.9.0",
|
|
40
38
|
"typescript": "^5.7.0"
|