lzma1 0.0.4 → 0.4.0-next.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/lzma.js +204 -203
- package/package.json +1 -3
package/dist/lzma.js
CHANGED
|
@@ -63,6 +63,7 @@ export class LZMA {
|
|
|
63
63
|
#MIN_VALUE;
|
|
64
64
|
#P0_LONG_LIT = [0, 0];
|
|
65
65
|
#P1_LONG_LIT = [1, 0];
|
|
66
|
+
#kIfinityPrice = 268435455;
|
|
66
67
|
CompressionModes = {
|
|
67
68
|
1: { searchDepth: 16, filterStrength: 64, modeIndex: 0 },
|
|
68
69
|
2: { searchDepth: 20, filterStrength: 64, modeIndex: 0 },
|
|
@@ -146,8 +147,8 @@ export class LZMA {
|
|
|
146
147
|
m_PosSlotDecoder: this.#initArray(4),
|
|
147
148
|
m_PosDecoders: this.#initArray(114),
|
|
148
149
|
m_PosAlignDecoder: this.#createBitTreeDecoder(4),
|
|
149
|
-
m_LenDecoder: this.#createLenDecoder(
|
|
150
|
-
m_RepLenDecoder: this.#createLenDecoder(
|
|
150
|
+
m_LenDecoder: this.#createLenDecoder(),
|
|
151
|
+
m_RepLenDecoder: this.#createLenDecoder(),
|
|
151
152
|
m_LiteralDecoder: {},
|
|
152
153
|
};
|
|
153
154
|
for (let i = 0; i < 4; ++i) {
|
|
@@ -161,7 +162,7 @@ export class LZMA {
|
|
|
161
162
|
alive: 0,
|
|
162
163
|
encoder: null,
|
|
163
164
|
decoder: null,
|
|
164
|
-
inBytesProcessed: [],
|
|
165
|
+
inBytesProcessed: [0, 0],
|
|
165
166
|
},
|
|
166
167
|
output: {
|
|
167
168
|
buf: this.#initArray(32),
|
|
@@ -175,7 +176,7 @@ export class LZMA {
|
|
|
175
176
|
alive: 0,
|
|
176
177
|
encoder: null,
|
|
177
178
|
decoder: null,
|
|
178
|
-
inBytesProcessed: [],
|
|
179
|
+
inBytesProcessed: [0, 0],
|
|
179
180
|
},
|
|
180
181
|
output: {
|
|
181
182
|
buf: this.#initArray(32),
|
|
@@ -409,9 +410,9 @@ export class LZMA {
|
|
|
409
410
|
this.#FillAlignPrices(this.#encoder);
|
|
410
411
|
// Configure length encoders
|
|
411
412
|
this.#encoder._lenEncoder._tableSize = this.#encoder._numFastBytes + 1 - 2;
|
|
412
|
-
this.#
|
|
413
|
+
this.#LZMA_LenPriceTableEncoder_UpdateTablesUpdateTables(this.#encoder._lenEncoder, 1 << this.#encoder._posStateBits);
|
|
413
414
|
this.#encoder._repMatchLenEncoder._tableSize = this.#encoder._numFastBytes + 1 - 2;
|
|
414
|
-
this.#
|
|
415
|
+
this.#LZMA_LenPriceTableEncoder_UpdateTablesUpdateTables(this.#encoder._repMatchLenEncoder, 1 << this.#encoder._posStateBits);
|
|
415
416
|
// Reset position counter
|
|
416
417
|
this.#encoder.nowPos64 = this.#P0_LONG_LIT;
|
|
417
418
|
// Create new chunker with configured encoder
|
|
@@ -513,26 +514,27 @@ export class LZMA {
|
|
|
513
514
|
+ index];
|
|
514
515
|
}
|
|
515
516
|
#GetMatchLen(index, distance, limit) {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
517
|
+
const encoder = this.#compressor.chunker.encoder;
|
|
518
|
+
if (encoder._matchFinder._streamEndWasReached) {
|
|
519
|
+
if (encoder._matchFinder._pos + index + limit
|
|
520
|
+
> encoder._matchFinder._streamPos) {
|
|
521
|
+
limit = encoder._matchFinder._streamPos
|
|
522
|
+
- (encoder._matchFinder._pos + index);
|
|
521
523
|
}
|
|
522
524
|
}
|
|
523
525
|
++distance;
|
|
524
|
-
let i, pby =
|
|
525
|
-
+
|
|
526
|
+
let i, pby = encoder._matchFinder._bufferOffset
|
|
527
|
+
+ encoder._matchFinder._pos
|
|
526
528
|
+ index;
|
|
527
529
|
for (i = 0; i < limit
|
|
528
|
-
&&
|
|
529
|
-
==
|
|
530
|
+
&& encoder._matchFinder._bufferBase[pby + i]
|
|
531
|
+
== encoder._matchFinder._bufferBase[pby + i - distance]; ++i)
|
|
530
532
|
;
|
|
531
533
|
return i;
|
|
532
534
|
}
|
|
533
535
|
#GetNumAvailableBytes() {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
+
const encoder = this.#compressor.chunker.encoder;
|
|
537
|
+
return encoder._matchFinder._streamPos - encoder._matchFinder._pos;
|
|
536
538
|
}
|
|
537
539
|
#MoveBlock() {
|
|
538
540
|
const matchFinder = this.#compressor.chunker.encoder._matchFinder;
|
|
@@ -796,7 +798,7 @@ export class LZMA {
|
|
|
796
798
|
}
|
|
797
799
|
#Skip(num) {
|
|
798
800
|
const matchFinder = this.#compressor.chunker.encoder._matchFinder;
|
|
799
|
-
|
|
801
|
+
let count, cur, curMatch, cyclicPos, delta, hash2Value, hash3Value, hashValue, len, len0, len1, lenLimit, matchMinPos, pby1, ptr0, ptr1, temp;
|
|
800
802
|
do {
|
|
801
803
|
if (matchFinder._pos + matchFinder._matchMaxLen <= matchFinder._streamPos) {
|
|
802
804
|
lenLimit = matchFinder._matchMaxLen;
|
|
@@ -886,11 +888,11 @@ export class LZMA {
|
|
|
886
888
|
outputWindow._pos += 1;
|
|
887
889
|
pos += 1;
|
|
888
890
|
if (outputWindow._pos >= outputWindow._windowSize) {
|
|
889
|
-
this.#Flush_0(
|
|
891
|
+
this.#Flush_0();
|
|
890
892
|
}
|
|
891
893
|
}
|
|
892
894
|
}
|
|
893
|
-
#
|
|
895
|
+
#OutWindow_Create(m_OutWindow, windowSize) {
|
|
894
896
|
if (m_OutWindow._buffer == null || m_OutWindow._windowSize != windowSize) {
|
|
895
897
|
m_OutWindow._buffer = this.#initArray(windowSize);
|
|
896
898
|
}
|
|
@@ -898,35 +900,35 @@ export class LZMA {
|
|
|
898
900
|
m_OutWindow._pos = 0;
|
|
899
901
|
m_OutWindow._streamPos = 0;
|
|
900
902
|
}
|
|
901
|
-
#Flush_0(
|
|
902
|
-
|
|
903
|
+
#Flush_0() {
|
|
904
|
+
let size = this.#decoder.m_OutWindow._pos - this.#decoder.m_OutWindow._streamPos;
|
|
903
905
|
if (!size) {
|
|
904
906
|
return;
|
|
905
907
|
}
|
|
906
|
-
this.#write_0(
|
|
907
|
-
if (
|
|
908
|
-
|
|
908
|
+
this.#write_0(this.#decoder.m_OutWindow._stream, this.#decoder.m_OutWindow._buffer, this.#decoder.m_OutWindow._streamPos, size);
|
|
909
|
+
if (this.#decoder.m_OutWindow._pos >= this.#decoder.m_OutWindow._windowSize) {
|
|
910
|
+
this.#decoder.m_OutWindow._pos = 0;
|
|
909
911
|
}
|
|
910
|
-
|
|
912
|
+
this.#decoder.m_OutWindow._streamPos = this.#decoder.m_OutWindow._pos;
|
|
911
913
|
}
|
|
912
914
|
#GetByte(distance) {
|
|
913
915
|
const outputWindow = this.#decompressor.chunker.decoder.m_OutWindow;
|
|
914
|
-
|
|
916
|
+
let pos = outputWindow._pos - distance - 1;
|
|
915
917
|
if (pos < 0) {
|
|
916
918
|
pos += outputWindow._windowSize;
|
|
917
919
|
}
|
|
918
920
|
return outputWindow._buffer[pos];
|
|
919
921
|
}
|
|
920
|
-
#PutByte(
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
if (
|
|
924
|
-
this.#Flush_0(
|
|
922
|
+
#PutByte(b) {
|
|
923
|
+
this.#decoder.m_OutWindow._buffer[this.#decoder.m_OutWindow._pos] = b;
|
|
924
|
+
this.#decoder.m_OutWindow._pos += 1;
|
|
925
|
+
if (this.#decoder.m_OutWindow._pos >= this.#decoder.m_OutWindow._windowSize) {
|
|
926
|
+
this.#Flush_0();
|
|
925
927
|
}
|
|
926
928
|
}
|
|
927
|
-
#
|
|
928
|
-
this.#Flush_0(
|
|
929
|
-
|
|
929
|
+
#OutWindow_ReleaseStream() {
|
|
930
|
+
this.#Flush_0();
|
|
931
|
+
this.#decoder.m_OutWindow._stream = null;
|
|
930
932
|
}
|
|
931
933
|
GetLenToPosState(len) {
|
|
932
934
|
len -= 2;
|
|
@@ -969,8 +971,8 @@ export class LZMA {
|
|
|
969
971
|
if (result
|
|
970
972
|
|| this.#compare(decoder.outSize, this.#P0_LONG_LIT) >= 0
|
|
971
973
|
&& this.#compare(decoder.nowPos64, decoder.outSize) >= 0) {
|
|
972
|
-
this.#Flush_0(
|
|
973
|
-
this.#
|
|
974
|
+
this.#Flush_0();
|
|
975
|
+
this.#OutWindow_ReleaseStream();
|
|
974
976
|
decoder.m_RangeDecoder.Stream = null;
|
|
975
977
|
this.#decompressor.chunker.alive = 0;
|
|
976
978
|
}
|
|
@@ -993,7 +995,7 @@ export class LZMA {
|
|
|
993
995
|
}
|
|
994
996
|
#CodeInChunks(inStream, outSize) {
|
|
995
997
|
this.#decoder.m_RangeDecoder.Stream = inStream;
|
|
996
|
-
this.#
|
|
998
|
+
this.#OutWindow_ReleaseStream();
|
|
997
999
|
this.#decoder.m_OutWindow._stream = this.#decompressor.output;
|
|
998
1000
|
this.#Init_1();
|
|
999
1001
|
this.#decoder.state = 0;
|
|
@@ -1022,7 +1024,7 @@ export class LZMA {
|
|
|
1022
1024
|
else {
|
|
1023
1025
|
decoder.prevByte = this.#DecodeWithMatchByte(decoder2, this.#GetByte(decoder.rep0));
|
|
1024
1026
|
}
|
|
1025
|
-
this.#PutByte(decoder.
|
|
1027
|
+
this.#PutByte(decoder.prevByte);
|
|
1026
1028
|
decoder.state = this.StateUpdateChar(decoder.state);
|
|
1027
1029
|
decoder.nowPos64 = this.#add(decoder.nowPos64, this.#P1_LONG_LIT);
|
|
1028
1030
|
}
|
|
@@ -1065,7 +1067,7 @@ export class LZMA {
|
|
|
1065
1067
|
decoder.rep1 = decoder.rep0;
|
|
1066
1068
|
len = 2 + this.#Decode(decoder.m_LenDecoder, posState);
|
|
1067
1069
|
decoder.state = decoder.state < 7 ? 7 : 10;
|
|
1068
|
-
positionSlot = this.#
|
|
1070
|
+
positionSlot = this.#RangeCoder_BitTreeDecoder_Decoder(decoder.m_PosSlotDecoder[this.GetLenToPosState(len)]);
|
|
1069
1071
|
if (positionSlot >= 4) {
|
|
1070
1072
|
numDirectBits = (positionSlot >> 1) - 1;
|
|
1071
1073
|
decoder.rep0 = (2 | positionSlot & 1) << numDirectBits;
|
|
@@ -1117,7 +1119,7 @@ export class LZMA {
|
|
|
1117
1119
|
this.#Init_8();
|
|
1118
1120
|
}
|
|
1119
1121
|
#SetDecoderProperties(properties) {
|
|
1120
|
-
|
|
1122
|
+
let dictionarySize, i, lc, lp, pb, remainder, val;
|
|
1121
1123
|
if (properties.length < 5) {
|
|
1122
1124
|
return 0;
|
|
1123
1125
|
}
|
|
@@ -1143,7 +1145,7 @@ export class LZMA {
|
|
|
1143
1145
|
if (this.#decoder.m_DictionarySize != dictionarySize) {
|
|
1144
1146
|
this.#decoder.m_DictionarySize = dictionarySize;
|
|
1145
1147
|
this.#decoder.m_DictionarySizeCheck = Math.max(this.#decoder.m_DictionarySize, 1);
|
|
1146
|
-
this.#
|
|
1148
|
+
this.#OutWindow_Create(this.#decoder.m_OutWindow, Math.max(this.#decoder.m_DictionarySizeCheck, 4096));
|
|
1147
1149
|
}
|
|
1148
1150
|
return 1;
|
|
1149
1151
|
}
|
|
@@ -1152,7 +1154,7 @@ export class LZMA {
|
|
|
1152
1154
|
return 0;
|
|
1153
1155
|
}
|
|
1154
1156
|
this.#Create_0(lp, lc);
|
|
1155
|
-
|
|
1157
|
+
let numPosStates = 1 << pb;
|
|
1156
1158
|
this.#Create(this.#decoder.m_LenDecoder, numPosStates);
|
|
1157
1159
|
this.#Create(this.#decoder.m_RepLenDecoder, numPosStates);
|
|
1158
1160
|
this.#decoder.m_PosStateMask = numPosStates - 1;
|
|
@@ -1164,34 +1166,36 @@ export class LZMA {
|
|
|
1164
1166
|
decoder.m_MidCoder[decoder.m_NumPosStates] = this.#createBitTreeDecoder(3);
|
|
1165
1167
|
}
|
|
1166
1168
|
}
|
|
1167
|
-
#Decode(
|
|
1168
|
-
if (!this.#decodeBit(
|
|
1169
|
-
return this.#
|
|
1169
|
+
#Decode(decoder, posState) {
|
|
1170
|
+
if (!this.#decodeBit(decoder.m_Choice, 0)) {
|
|
1171
|
+
return this.#RangeCoder_BitTreeDecoder_Decoder(decoder.m_LowCoder[posState]);
|
|
1170
1172
|
}
|
|
1171
1173
|
let symbol = 8;
|
|
1172
|
-
if (!this.#decodeBit(
|
|
1173
|
-
symbol += this.#
|
|
1174
|
+
if (!this.#decodeBit(decoder.m_Choice, 1)) {
|
|
1175
|
+
symbol += this.#RangeCoder_BitTreeDecoder_Decoder(decoder.m_MidCoder[posState]);
|
|
1174
1176
|
}
|
|
1175
1177
|
else {
|
|
1176
|
-
symbol += 8 + this.#
|
|
1178
|
+
symbol += 8 + this.#RangeCoder_BitTreeDecoder_Decoder(decoder.m_HighCoder);
|
|
1177
1179
|
}
|
|
1178
1180
|
return symbol;
|
|
1179
1181
|
}
|
|
1180
|
-
#createLenDecoder(
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1182
|
+
#createLenDecoder() {
|
|
1183
|
+
const decoder = {
|
|
1184
|
+
m_Choice: this.#initArray(2),
|
|
1185
|
+
m_LowCoder: this.#initArray(16),
|
|
1186
|
+
m_MidCoder: this.#initArray(16),
|
|
1187
|
+
m_HighCoder: this.#createBitTreeDecoder(8),
|
|
1188
|
+
m_NumPosStates: 0,
|
|
1189
|
+
};
|
|
1190
|
+
return decoder;
|
|
1187
1191
|
}
|
|
1188
|
-
#Init(
|
|
1189
|
-
this.InitBitModels(
|
|
1190
|
-
for (let posState = 0; posState <
|
|
1191
|
-
this.InitBitModels(
|
|
1192
|
-
this.InitBitModels(
|
|
1192
|
+
#Init(decoder) {
|
|
1193
|
+
this.InitBitModels(decoder.m_Choice);
|
|
1194
|
+
for (let posState = 0; posState < decoder.m_NumPosStates; ++posState) {
|
|
1195
|
+
this.InitBitModels(decoder.m_LowCoder[posState].Models);
|
|
1196
|
+
this.InitBitModels(decoder.m_MidCoder[posState].Models);
|
|
1193
1197
|
}
|
|
1194
|
-
this.InitBitModels(
|
|
1198
|
+
this.InitBitModels(decoder.m_HighCoder.Models);
|
|
1195
1199
|
}
|
|
1196
1200
|
#Create_0(numPosBits, numPrevBits) {
|
|
1197
1201
|
let i, numStates;
|
|
@@ -1206,7 +1210,7 @@ export class LZMA {
|
|
|
1206
1210
|
numStates = 1 << this.#decoder.m_LiteralDecoder.m_NumPrevBits + this.#decoder.m_LiteralDecoder.m_NumPosBits;
|
|
1207
1211
|
this.#decoder.m_LiteralDecoder.m_Coders = this.#initArray(numStates);
|
|
1208
1212
|
for (i = 0; i < numStates; ++i) {
|
|
1209
|
-
this.#decoder.m_LiteralDecoder.m_Coders[i] = this.#createLiteralDecoderEncoder2(
|
|
1213
|
+
this.#decoder.m_LiteralDecoder.m_Coders[i] = this.#createLiteralDecoderEncoder2();
|
|
1210
1214
|
}
|
|
1211
1215
|
}
|
|
1212
1216
|
#GetDecoder(pos, prevByte) {
|
|
@@ -1218,68 +1222,69 @@ export class LZMA {
|
|
|
1218
1222
|
// Return decoder at calculated index
|
|
1219
1223
|
return literalDecoder.m_Coders[index];
|
|
1220
1224
|
}
|
|
1221
|
-
#Init_0(
|
|
1225
|
+
#Init_0(decoder) {
|
|
1222
1226
|
let i, numStates;
|
|
1223
|
-
numStates = 1 <<
|
|
1227
|
+
numStates = 1 << decoder.m_NumPrevBits + decoder.m_NumPosBits;
|
|
1224
1228
|
for (i = 0; i < numStates; ++i) {
|
|
1225
|
-
this.InitBitModels(
|
|
1229
|
+
this.InitBitModels(decoder.m_Coders[i].m_Decoders);
|
|
1226
1230
|
}
|
|
1227
1231
|
}
|
|
1228
|
-
#DecodeNormal(
|
|
1229
|
-
|
|
1230
|
-
var symbol = 1;
|
|
1232
|
+
#DecodeNormal(decoder) {
|
|
1233
|
+
let symbol = 1;
|
|
1231
1234
|
do {
|
|
1232
|
-
symbol = symbol << 1 | this.#decodeBit(
|
|
1235
|
+
symbol = symbol << 1 | this.#decodeBit(decoder.m_Decoders, symbol);
|
|
1233
1236
|
} while (symbol < 256);
|
|
1234
1237
|
return symbol << 24 >> 24;
|
|
1235
1238
|
}
|
|
1236
|
-
#DecodeWithMatchByte(
|
|
1239
|
+
#DecodeWithMatchByte(encoder, matchByte) {
|
|
1237
1240
|
let bit, matchBit, symbol = 1;
|
|
1238
1241
|
do {
|
|
1239
1242
|
matchBit = matchByte >> 7 & 1;
|
|
1240
1243
|
matchByte <<= 1;
|
|
1241
|
-
bit = this.#decodeBit(
|
|
1244
|
+
bit = this.#decodeBit(encoder.m_Decoders, (1 + matchBit << 8) + symbol);
|
|
1242
1245
|
symbol = symbol << 1 | bit;
|
|
1243
1246
|
if (matchBit != bit) {
|
|
1244
1247
|
while (symbol < 256) {
|
|
1245
|
-
symbol = symbol << 1 | this.#decodeBit(
|
|
1248
|
+
symbol = symbol << 1 | this.#decodeBit(encoder.m_Decoders, symbol);
|
|
1246
1249
|
}
|
|
1247
1250
|
break;
|
|
1248
1251
|
}
|
|
1249
1252
|
} while (symbol < 256);
|
|
1250
1253
|
return symbol << 24 >> 24;
|
|
1251
1254
|
}
|
|
1252
|
-
#createLiteralDecoderEncoder2(
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
+
#createLiteralDecoderEncoder2() {
|
|
1256
|
+
const literalDecoder = {
|
|
1257
|
+
m_Decoders: this.#initArray(0x300),
|
|
1258
|
+
};
|
|
1259
|
+
return literalDecoder;
|
|
1255
1260
|
}
|
|
1256
1261
|
#Backward(cur) {
|
|
1257
|
-
const
|
|
1262
|
+
const encoder = this.#compressor.chunker.encoder;
|
|
1258
1263
|
let backCur, backMem, posMem, posPrev;
|
|
1259
|
-
|
|
1260
|
-
posMem =
|
|
1261
|
-
backMem =
|
|
1264
|
+
encoder._optimumEndIndex = cur;
|
|
1265
|
+
posMem = encoder._optimum[cur].PosPrev;
|
|
1266
|
+
backMem = encoder._optimum[cur].BackPrev;
|
|
1262
1267
|
do {
|
|
1263
|
-
if (
|
|
1264
|
-
this.#MakeAsChar(
|
|
1265
|
-
|
|
1266
|
-
if (
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1268
|
+
if (encoder._optimum[cur].Prev1IsChar) {
|
|
1269
|
+
this.#MakeAsChar(encoder._optimum[posMem]);
|
|
1270
|
+
encoder._optimum[posMem].PosPrev = posMem - 1;
|
|
1271
|
+
if (encoder._optimum[cur].Prev2) {
|
|
1272
|
+
encoder._optimum[posMem - 1].Prev1IsChar = 0;
|
|
1273
|
+
encoder._optimum[posMem - 1].PosPrev = encoder._optimum[cur].PosPrev2;
|
|
1274
|
+
encoder._optimum[posMem - 1].BackPrev = encoder._optimum[cur].BackPrev2;
|
|
1270
1275
|
}
|
|
1271
1276
|
}
|
|
1272
1277
|
posPrev = posMem;
|
|
1273
1278
|
backCur = backMem;
|
|
1274
|
-
backMem =
|
|
1275
|
-
posMem =
|
|
1276
|
-
|
|
1277
|
-
|
|
1279
|
+
backMem = encoder._optimum[posPrev].BackPrev;
|
|
1280
|
+
posMem = encoder._optimum[posPrev].PosPrev;
|
|
1281
|
+
encoder._optimum[posPrev].BackPrev = backCur;
|
|
1282
|
+
encoder._optimum[posPrev].PosPrev = cur;
|
|
1278
1283
|
cur = posPrev;
|
|
1279
1284
|
} while (cur > 0);
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
return
|
|
1285
|
+
encoder.backRes = encoder._optimum[0].BackPrev;
|
|
1286
|
+
encoder._optimumCurrentIndex = encoder._optimum[0].PosPrev;
|
|
1287
|
+
return encoder._optimumCurrentIndex;
|
|
1283
1288
|
}
|
|
1284
1289
|
#BaseInit() {
|
|
1285
1290
|
this.#encoder._state = 0;
|
|
@@ -1315,7 +1320,7 @@ export class LZMA {
|
|
|
1315
1320
|
this.#Encode_3(this.#compressor.chunker.encoder._isMatch, (this.#compressor.chunker.encoder._state << 4) + posState, 0);
|
|
1316
1321
|
this.#compressor.chunker.encoder._state = this.StateUpdateChar(this.#compressor.chunker.encoder._state);
|
|
1317
1322
|
curByte = this.#GetIndexByte(-this.#compressor.chunker.encoder._additionalOffset);
|
|
1318
|
-
this.#Encode_1(this.#
|
|
1323
|
+
this.#Encode_1(this.#LZMA_Encoder_GetSubCoder(this.#lowBits_0(this.#compressor.chunker.encoder.nowPos64), this.#compressor.chunker.encoder._previousByte), curByte);
|
|
1319
1324
|
this.#compressor.chunker.encoder._previousByte = curByte;
|
|
1320
1325
|
this.#compressor.chunker.encoder._additionalOffset -= 1;
|
|
1321
1326
|
this.#compressor.chunker.encoder.nowPos64 = this.#add(this.#compressor.chunker.encoder.nowPos64, this.#P1_LONG_LIT);
|
|
@@ -1333,7 +1338,7 @@ export class LZMA {
|
|
|
1333
1338
|
if (len == 1 && pos == -1) {
|
|
1334
1339
|
this.#Encode_3(this.#compressor.chunker.encoder._isMatch, complexState, 0);
|
|
1335
1340
|
curByte = this.#GetIndexByte(-this.#compressor.chunker.encoder._additionalOffset);
|
|
1336
|
-
subCoder = this.#
|
|
1341
|
+
subCoder = this.#LZMA_Encoder_GetSubCoder(this.#lowBits_0(this.#compressor.chunker.encoder.nowPos64), this.#compressor.chunker.encoder._previousByte);
|
|
1337
1342
|
if (this.#compressor.chunker.encoder._state < 7) {
|
|
1338
1343
|
this.#Encode_1(subCoder, curByte);
|
|
1339
1344
|
}
|
|
@@ -1456,7 +1461,7 @@ export class LZMA {
|
|
|
1456
1461
|
this.#SetType(binTree, numHashBytes);
|
|
1457
1462
|
this.#encoder._matchFinder = binTree;
|
|
1458
1463
|
}
|
|
1459
|
-
this.#
|
|
1464
|
+
this.#LZMA_Encoder_LiteralEncoder_Create();
|
|
1460
1465
|
if (this.#encoder._dictionarySize == this.#encoder._dictionarySizePrev
|
|
1461
1466
|
&& this.#encoder._numFastBytesPrev == this.#encoder._numFastBytes) {
|
|
1462
1467
|
return;
|
|
@@ -1491,7 +1496,7 @@ export class LZMA {
|
|
|
1491
1496
|
encoder = obj._posSlotEncoder[lenToPosState];
|
|
1492
1497
|
st = lenToPosState << 6;
|
|
1493
1498
|
for (posSlot = 0; posSlot < obj._distTableSize; posSlot += 1) {
|
|
1494
|
-
obj._posSlotPrices[st + posSlot] = this.#
|
|
1499
|
+
obj._posSlotPrices[st + posSlot] = this.#RangeCoder_Encoder_GetPrice_1(encoder, posSlot);
|
|
1495
1500
|
}
|
|
1496
1501
|
for (posSlot = 14; posSlot < obj._distTableSize; posSlot += 1) {
|
|
1497
1502
|
obj._posSlotPrices[st + posSlot] += (posSlot >> 1) - 1 - 4 << 6;
|
|
@@ -1567,7 +1572,7 @@ export class LZMA {
|
|
|
1567
1572
|
}
|
|
1568
1573
|
encoder._optimum[0].State = encoder._state;
|
|
1569
1574
|
posState = position & encoder._posStateMask;
|
|
1570
|
-
encoder._optimum[1].Price = this.#probPrices[encoder._isMatch[(encoder._state << 4) + posState] >>> 2] + this.#
|
|
1575
|
+
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
1576
|
this.#MakeAsChar(encoder._optimum[1]);
|
|
1572
1577
|
matchPrice = this.#probPrices[2_048
|
|
1573
1578
|
- encoder._isMatch[(encoder._state << 4) + posState]
|
|
@@ -1594,7 +1599,7 @@ export class LZMA {
|
|
|
1594
1599
|
encoder._optimum[0].Backs3 = encoder.reps[3];
|
|
1595
1600
|
len = lenEnd;
|
|
1596
1601
|
do {
|
|
1597
|
-
encoder._optimum[len].Price =
|
|
1602
|
+
encoder._optimum[len].Price = this.#kIfinityPrice;
|
|
1598
1603
|
len -= 1;
|
|
1599
1604
|
} while (len >= 2);
|
|
1600
1605
|
for (let i = 0; i < 4; ++i) {
|
|
@@ -1604,7 +1609,7 @@ export class LZMA {
|
|
|
1604
1609
|
}
|
|
1605
1610
|
price_4 = repMatchPrice + this.#GetPureRepPrice(i, encoder._state, posState);
|
|
1606
1611
|
do {
|
|
1607
|
-
curAndLenPrice = price_4 + this.#
|
|
1612
|
+
curAndLenPrice = price_4 + this.#RangeCoder_Encoder_GetPrice(encoder._repMatchLenEncoder, repLen - 2, posState);
|
|
1608
1613
|
optimum = encoder._optimum[repLen];
|
|
1609
1614
|
if (curAndLenPrice < optimum.Price) {
|
|
1610
1615
|
optimum.Price = curAndLenPrice;
|
|
@@ -1624,7 +1629,7 @@ export class LZMA {
|
|
|
1624
1629
|
}
|
|
1625
1630
|
for (;; len += 1) {
|
|
1626
1631
|
distance = encoder._matchDistances[offs + 1];
|
|
1627
|
-
curAndLenPrice = normalMatchPrice + this.#
|
|
1632
|
+
curAndLenPrice = normalMatchPrice + this.#LZMA_Encoder_GetPosLenPrice(distance, len, posState);
|
|
1628
1633
|
optimum = encoder._optimum[len];
|
|
1629
1634
|
if (curAndLenPrice < optimum.Price) {
|
|
1630
1635
|
optimum.Price = curAndLenPrice;
|
|
@@ -1743,7 +1748,7 @@ export class LZMA {
|
|
|
1743
1748
|
posState = position & encoder._posStateMask;
|
|
1744
1749
|
curAnd1Price = curPrice
|
|
1745
1750
|
+ this.#probPrices[encoder._isMatch[(state << 4) + posState] >>> 2]
|
|
1746
|
-
+ this.#
|
|
1751
|
+
+ this.#RangeCoder_Encoder_GetPrice_0(this.#LZMA_Encoder_GetSubCoder(position, this.#GetIndexByte(-2)), state >= 7, matchByte, currentByte);
|
|
1747
1752
|
nextOptimum = encoder._optimum[cur + 1];
|
|
1748
1753
|
nextIsChar = 0;
|
|
1749
1754
|
if (curAnd1Price < nextOptimum.Price) {
|
|
@@ -1786,9 +1791,9 @@ export class LZMA {
|
|
|
1786
1791
|
nextRepMatchPrice = curAnd1Price + this.#probPrices[2_048 - encoder._isMatch[(state2 << 4) + posStateNext] >>> 2] + this.#probPrices[2_048 - encoder._isRep[state2] >>> 2];
|
|
1787
1792
|
offset = cur + 1 + lenTest2;
|
|
1788
1793
|
while (lenEnd < offset) {
|
|
1789
|
-
encoder._optimum[lenEnd += 1].Price =
|
|
1794
|
+
encoder._optimum[lenEnd += 1].Price = this.#kIfinityPrice;
|
|
1790
1795
|
}
|
|
1791
|
-
curAndLenPrice = nextRepMatchPrice + (price = this.#
|
|
1796
|
+
curAndLenPrice = nextRepMatchPrice + (price = this.#RangeCoder_Encoder_GetPrice(encoder._repMatchLenEncoder, lenTest2 - 2, posStateNext),
|
|
1792
1797
|
price + this.#GetPureRepPrice(0, state2, posStateNext));
|
|
1793
1798
|
optimum = encoder._optimum[offset];
|
|
1794
1799
|
if (curAndLenPrice < optimum.Price) {
|
|
@@ -1809,9 +1814,9 @@ export class LZMA {
|
|
|
1809
1814
|
lenTestTemp = lenTest;
|
|
1810
1815
|
do {
|
|
1811
1816
|
while (lenEnd < cur + lenTest) {
|
|
1812
|
-
encoder._optimum[lenEnd += 1].Price =
|
|
1817
|
+
encoder._optimum[lenEnd += 1].Price = this.#kIfinityPrice;
|
|
1813
1818
|
}
|
|
1814
|
-
curAndLenPrice = repMatchPrice + (price_0 = this.#
|
|
1819
|
+
curAndLenPrice = repMatchPrice + (price_0 = this.#RangeCoder_Encoder_GetPrice(encoder._repMatchLenEncoder, lenTest - 2, posState),
|
|
1815
1820
|
price_0 + this.#GetPureRepPrice(repIndex, state, posState));
|
|
1816
1821
|
optimum = encoder._optimum[cur + lenTest];
|
|
1817
1822
|
if (curAndLenPrice < optimum.Price) {
|
|
@@ -1831,18 +1836,18 @@ export class LZMA {
|
|
|
1831
1836
|
if (lenTest2 >= 2) {
|
|
1832
1837
|
state2 = state < 7 ? 8 : 11;
|
|
1833
1838
|
posStateNext = position + lenTest & encoder._posStateMask;
|
|
1834
|
-
curAndLenCharPrice = repMatchPrice + (price_1 = this.#
|
|
1839
|
+
curAndLenCharPrice = repMatchPrice + (price_1 = this.#RangeCoder_Encoder_GetPrice(encoder._repMatchLenEncoder, lenTest - 2, posState),
|
|
1835
1840
|
price_1 + this.#GetPureRepPrice(repIndex, state, posState))
|
|
1836
|
-
+ this.#probPrices[encoder._isMatch[(state2 << 4) + posStateNext] >>> 2] + this.#
|
|
1841
|
+
+ 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
1842
|
state2 = this.StateUpdateChar(state2);
|
|
1838
1843
|
posStateNext = position + lenTest + 1 & encoder._posStateMask;
|
|
1839
1844
|
nextMatchPrice = curAndLenCharPrice + this.#probPrices[2_048 - encoder._isMatch[(state2 << 4) + posStateNext] >>> 2];
|
|
1840
1845
|
nextRepMatchPrice = nextMatchPrice + this.#probPrices[2_048 - encoder._isRep[state2] >>> 2];
|
|
1841
1846
|
offset = cur + 1 + lenTest + lenTest2;
|
|
1842
1847
|
while (lenEnd < cur + offset) {
|
|
1843
|
-
encoder._optimum[lenEnd += 1].Price =
|
|
1848
|
+
encoder._optimum[lenEnd += 1].Price = this.#kIfinityPrice;
|
|
1844
1849
|
}
|
|
1845
|
-
curAndLenPrice = nextRepMatchPrice + (price_2 = this.#
|
|
1850
|
+
curAndLenPrice = nextRepMatchPrice + (price_2 = this.#RangeCoder_Encoder_GetPrice(encoder._repMatchLenEncoder, lenTest2 - 2, posStateNext),
|
|
1846
1851
|
price_2 + this.#GetPureRepPrice(0, state2, posStateNext));
|
|
1847
1852
|
optimum = encoder._optimum[cur + offset];
|
|
1848
1853
|
if (curAndLenPrice < optimum.Price) {
|
|
@@ -1866,7 +1871,7 @@ export class LZMA {
|
|
|
1866
1871
|
if (newLen >= startLen) {
|
|
1867
1872
|
normalMatchPrice = matchPrice + this.#probPrices[encoder._isRep[state] >>> 2];
|
|
1868
1873
|
while (lenEnd < cur + newLen) {
|
|
1869
|
-
encoder._optimum[lenEnd += 1].Price =
|
|
1874
|
+
encoder._optimum[lenEnd += 1].Price = this.#kIfinityPrice;
|
|
1870
1875
|
}
|
|
1871
1876
|
offs = 0;
|
|
1872
1877
|
while (startLen > encoder._matchDistances[offs]) {
|
|
@@ -1874,7 +1879,7 @@ export class LZMA {
|
|
|
1874
1879
|
}
|
|
1875
1880
|
for (lenTest = startLen;; lenTest += 1) {
|
|
1876
1881
|
curBack = encoder._matchDistances[offs + 1];
|
|
1877
|
-
curAndLenPrice = normalMatchPrice + this.#
|
|
1882
|
+
curAndLenPrice = normalMatchPrice + this.#LZMA_Encoder_GetPosLenPrice(curBack, lenTest, posState);
|
|
1878
1883
|
optimum = encoder._optimum[cur + lenTest];
|
|
1879
1884
|
if (curAndLenPrice < optimum.Price) {
|
|
1880
1885
|
optimum.Price = curAndLenPrice;
|
|
@@ -1889,7 +1894,7 @@ export class LZMA {
|
|
|
1889
1894
|
if (lenTest2 >= 2) {
|
|
1890
1895
|
state2 = state < 7 ? 7 : 10;
|
|
1891
1896
|
posStateNext = position + lenTest & encoder._posStateMask;
|
|
1892
|
-
curAndLenCharPrice = curAndLenPrice + this.#probPrices[encoder._isMatch[(state2 << 4) + posStateNext] >>> 2] + this.#
|
|
1897
|
+
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
1898
|
state2 = this.StateUpdateChar(state2);
|
|
1894
1899
|
posStateNext = position + lenTest + 1 & encoder._posStateMask;
|
|
1895
1900
|
nextMatchPrice = curAndLenCharPrice + this.#probPrices[2_048 - encoder._isMatch[(state2 << 4) + posStateNext]
|
|
@@ -1897,9 +1902,9 @@ export class LZMA {
|
|
|
1897
1902
|
nextRepMatchPrice = nextMatchPrice + this.#probPrices[2_048 - encoder._isRep[state2] >>> 2];
|
|
1898
1903
|
offset = lenTest + 1 + lenTest2;
|
|
1899
1904
|
while (lenEnd < cur + offset) {
|
|
1900
|
-
encoder._optimum[lenEnd += 1].Price =
|
|
1905
|
+
encoder._optimum[lenEnd += 1].Price = this.#kIfinityPrice;
|
|
1901
1906
|
}
|
|
1902
|
-
curAndLenPrice = nextRepMatchPrice + (price_3 = this.#
|
|
1907
|
+
curAndLenPrice = nextRepMatchPrice + (price_3 = this.#RangeCoder_Encoder_GetPrice(encoder._repMatchLenEncoder, lenTest2 - 2, posStateNext),
|
|
1903
1908
|
price_3 + this.#GetPureRepPrice(0, state2, posStateNext));
|
|
1904
1909
|
optimum = encoder._optimum[cur + offset];
|
|
1905
1910
|
if (curAndLenPrice < optimum.Price) {
|
|
@@ -1922,19 +1927,20 @@ export class LZMA {
|
|
|
1922
1927
|
}
|
|
1923
1928
|
}
|
|
1924
1929
|
}
|
|
1925
|
-
#
|
|
1930
|
+
#LZMA_Encoder_GetPosLenPrice(pos, len, posState) {
|
|
1931
|
+
const encoder = this.#compressor.chunker.encoder;
|
|
1926
1932
|
let price, lenToPosState = this.GetLenToPosState(len);
|
|
1927
1933
|
if (pos < 128) {
|
|
1928
|
-
price =
|
|
1934
|
+
price = encoder._distancesPrices[lenToPosState * 128 + pos];
|
|
1929
1935
|
}
|
|
1930
1936
|
else {
|
|
1931
|
-
|
|
1932
|
-
|
|
1937
|
+
const position = (lenToPosState << 6) + this.GetPosSlot2(pos);
|
|
1938
|
+
price = encoder._posSlotPrices[position] + encoder._alignPrices[pos & 15];
|
|
1933
1939
|
}
|
|
1934
|
-
return price + this.#
|
|
1940
|
+
return price + this.#RangeCoder_Encoder_GetPrice(encoder._lenEncoder, len - 2, posState);
|
|
1935
1941
|
}
|
|
1936
1942
|
#GetPureRepPrice(repIndex, state, posState) {
|
|
1937
|
-
|
|
1943
|
+
let price;
|
|
1938
1944
|
if (!repIndex) {
|
|
1939
1945
|
price = this.#probPrices[this.#compressor.chunker.encoder._isRepG0[state] >>> 2];
|
|
1940
1946
|
price += this.#probPrices[2_048 - this.#compressor.chunker.encoder._isRep0Long[(state << 4) + posState] >>> 2];
|
|
@@ -1985,23 +1991,16 @@ export class LZMA {
|
|
|
1985
1991
|
}
|
|
1986
1992
|
}
|
|
1987
1993
|
#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;
|
|
1994
|
+
let lenRes = 0;
|
|
1995
|
+
const encoder = this.#compressor.chunker.encoder;
|
|
1996
|
+
encoder._numDistancePairs = this.#GetMatches();
|
|
1997
|
+
if (encoder._numDistancePairs > 0) {
|
|
1998
|
+
lenRes = encoder._matchDistances[encoder._numDistancePairs - 2];
|
|
1999
|
+
if (lenRes == encoder._numFastBytes) {
|
|
2000
|
+
lenRes += this.#GetMatchLen(lenRes - 1, encoder._matchDistances[encoder._numDistancePairs - 1], 273 - lenRes);
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
encoder._additionalOffset += 1;
|
|
2005
2004
|
return lenRes;
|
|
2006
2005
|
}
|
|
2007
2006
|
#ReleaseMFStream() {
|
|
@@ -2016,7 +2015,8 @@ export class LZMA {
|
|
|
2016
2015
|
}
|
|
2017
2016
|
#SetDictionarySize_0(dictionarySize) {
|
|
2018
2017
|
this.#encoder._dictionarySize = dictionarySize;
|
|
2019
|
-
|
|
2018
|
+
let dicLogSize = 0;
|
|
2019
|
+
for (; dictionarySize > (1 << dicLogSize); ++dicLogSize)
|
|
2020
2020
|
;
|
|
2021
2021
|
this.#encoder._distTableSize = dicLogSize * 2;
|
|
2022
2022
|
}
|
|
@@ -2049,7 +2049,7 @@ export class LZMA {
|
|
|
2049
2049
|
this.#Encode_3(encoder._isRep, encoder._state, 0);
|
|
2050
2050
|
encoder._state = encoder._state < 7 ? 7 : 10;
|
|
2051
2051
|
this.#Encode_0(encoder._lenEncoder, 0, positionState);
|
|
2052
|
-
|
|
2052
|
+
let lenToPosState = this.GetLenToPosState(2);
|
|
2053
2053
|
this.#Encode_2(encoder._posSlotEncoder[lenToPosState], 63);
|
|
2054
2054
|
this.#EncodeDirectBits(67108863, 26);
|
|
2055
2055
|
this.#ReverseEncode(15);
|
|
@@ -2072,21 +2072,21 @@ export class LZMA {
|
|
|
2072
2072
|
}
|
|
2073
2073
|
return this.#gFastPos[pos >> 26] + 52;
|
|
2074
2074
|
}
|
|
2075
|
-
#Encode(
|
|
2075
|
+
#Encode(encoder, symbol, posState) {
|
|
2076
2076
|
if (symbol < 8) {
|
|
2077
|
-
this.#Encode_3(
|
|
2078
|
-
this.#Encode_2(
|
|
2077
|
+
this.#Encode_3(encoder._choice, 0, 0);
|
|
2078
|
+
this.#Encode_2(encoder._lowCoder[posState], symbol);
|
|
2079
2079
|
}
|
|
2080
2080
|
else {
|
|
2081
2081
|
symbol -= 8;
|
|
2082
|
-
this.#Encode_3(
|
|
2082
|
+
this.#Encode_3(encoder._choice, 0, 1);
|
|
2083
2083
|
if (symbol < 8) {
|
|
2084
|
-
this.#Encode_3(
|
|
2085
|
-
this.#Encode_2(
|
|
2084
|
+
this.#Encode_3(encoder._choice, 1, 0);
|
|
2085
|
+
this.#Encode_2(encoder._midCoder[posState], symbol);
|
|
2086
2086
|
}
|
|
2087
2087
|
else {
|
|
2088
|
-
this.#Encode_3(
|
|
2089
|
-
this.#Encode_2(
|
|
2088
|
+
this.#Encode_3(encoder._choice, 1, 1);
|
|
2089
|
+
this.#Encode_2(encoder._highCoder, symbol - 8);
|
|
2090
2090
|
}
|
|
2091
2091
|
}
|
|
2092
2092
|
}
|
|
@@ -2110,34 +2110,34 @@ export class LZMA {
|
|
|
2110
2110
|
}
|
|
2111
2111
|
this.InitBitModels(obj._highCoder.Models);
|
|
2112
2112
|
}
|
|
2113
|
-
#SetPrices(
|
|
2113
|
+
#SetPrices(encoder, posState, numSymbols, prices, st) {
|
|
2114
2114
|
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 -
|
|
2115
|
+
a0 = this.#probPrices[encoder._choice[0] >>> 2];
|
|
2116
|
+
a1 = this.#probPrices[2_048 - encoder._choice[0] >>> 2];
|
|
2117
|
+
b0 = a1 + this.#probPrices[encoder._choice[1] >>> 2];
|
|
2118
|
+
b1 = a1 + this.#probPrices[2_048 - encoder._choice[1] >>> 2];
|
|
2119
2119
|
i = 0;
|
|
2120
2120
|
for (i = 0; i < 8; ++i) {
|
|
2121
2121
|
if (i >= numSymbols) {
|
|
2122
2122
|
return;
|
|
2123
2123
|
}
|
|
2124
|
-
prices[st + i] = a0 + this.#
|
|
2124
|
+
prices[st + i] = a0 + this.#RangeCoder_Encoder_GetPrice_1(encoder._lowCoder[posState], i);
|
|
2125
2125
|
}
|
|
2126
2126
|
for (; i < 16; ++i) {
|
|
2127
2127
|
if (i >= numSymbols) {
|
|
2128
2128
|
return;
|
|
2129
2129
|
}
|
|
2130
|
-
prices[st + i] = b0 + this.#
|
|
2130
|
+
prices[st + i] = b0 + this.#RangeCoder_Encoder_GetPrice_1(encoder._midCoder[posState], i - 8);
|
|
2131
2131
|
}
|
|
2132
2132
|
for (; i < numSymbols; ++i) {
|
|
2133
|
-
prices[st + i] = b1 + this.#
|
|
2133
|
+
prices[st + i] = b1 + this.#RangeCoder_Encoder_GetPrice_1(encoder._highCoder, i - 8 - 8);
|
|
2134
2134
|
}
|
|
2135
2135
|
}
|
|
2136
|
-
#Encode_0(
|
|
2137
|
-
this.#Encode(
|
|
2138
|
-
if ((
|
|
2139
|
-
this.#SetPrices(
|
|
2140
|
-
|
|
2136
|
+
#Encode_0(encoder, symbol, posState) {
|
|
2137
|
+
this.#Encode(encoder, symbol, posState);
|
|
2138
|
+
if ((encoder._counters[posState] -= 1) == 0) {
|
|
2139
|
+
this.#SetPrices(encoder, posState, encoder._tableSize, encoder._prices, posState * 272);
|
|
2140
|
+
encoder._counters[posState] = encoder._tableSize;
|
|
2141
2141
|
}
|
|
2142
2142
|
}
|
|
2143
2143
|
#createLenPriceTableEncoder() {
|
|
@@ -2146,16 +2146,16 @@ export class LZMA {
|
|
|
2146
2146
|
encoder._counters = [];
|
|
2147
2147
|
return encoder;
|
|
2148
2148
|
}
|
|
2149
|
-
#
|
|
2150
|
-
return
|
|
2149
|
+
#RangeCoder_Encoder_GetPrice(encoder, symbol, posState) {
|
|
2150
|
+
return encoder._prices[posState * 272 + symbol];
|
|
2151
2151
|
}
|
|
2152
|
-
#
|
|
2152
|
+
#LZMA_LenPriceTableEncoder_UpdateTablesUpdateTables(encoder, numPosStates) {
|
|
2153
2153
|
for (let posState = 0; posState < numPosStates; ++posState) {
|
|
2154
|
-
this.#SetPrices(
|
|
2155
|
-
|
|
2154
|
+
this.#SetPrices(encoder, posState, encoder._tableSize, encoder._prices, posState * 272);
|
|
2155
|
+
encoder._counters[posState] = encoder._tableSize;
|
|
2156
2156
|
}
|
|
2157
2157
|
}
|
|
2158
|
-
#
|
|
2158
|
+
#LZMA_Encoder_LiteralEncoder_Create() {
|
|
2159
2159
|
let i, numStates;
|
|
2160
2160
|
if (this.#encoder._literalEncoder.m_Coders != null
|
|
2161
2161
|
&& this.#encoder._literalEncoder.m_NumPrevBits == this.#encoder._numLiteralContextBits
|
|
@@ -2168,10 +2168,10 @@ export class LZMA {
|
|
|
2168
2168
|
numStates = 1 << this.#encoder._literalEncoder.m_NumPrevBits + this.#encoder._literalEncoder.m_NumPosBits;
|
|
2169
2169
|
this.#encoder._literalEncoder.m_Coders = this.#initArray(numStates);
|
|
2170
2170
|
for (i = 0; i < numStates; ++i) {
|
|
2171
|
-
this.#encoder._literalEncoder.m_Coders[i] = this.#createLiteralEncoderEncoder2(
|
|
2171
|
+
this.#encoder._literalEncoder.m_Coders[i] = this.#createLiteralEncoderEncoder2();
|
|
2172
2172
|
}
|
|
2173
2173
|
}
|
|
2174
|
-
#
|
|
2174
|
+
#LZMA_Encoder_GetSubCoder(pos, prevByte) {
|
|
2175
2175
|
const literalEncoder = this.#compressor.chunker.encoder._literalEncoder;
|
|
2176
2176
|
// Calculate position mask bits
|
|
2177
2177
|
const posBits = pos & literalEncoder.m_PosMask;
|
|
@@ -2190,15 +2190,15 @@ export class LZMA {
|
|
|
2190
2190
|
this.InitBitModels(this.#encoder._literalEncoder.m_Coders[i].m_Encoders);
|
|
2191
2191
|
}
|
|
2192
2192
|
}
|
|
2193
|
-
#Encode_1(
|
|
2194
|
-
|
|
2193
|
+
#Encode_1(encoder, symbol) {
|
|
2194
|
+
let bit, context = 1;
|
|
2195
2195
|
for (let i = 7; i >= 0; --i) {
|
|
2196
2196
|
bit = symbol >> i & 1;
|
|
2197
|
-
this.#Encode_3(
|
|
2197
|
+
this.#Encode_3(encoder.m_Encoders, context, bit);
|
|
2198
2198
|
context = context << 1 | bit;
|
|
2199
2199
|
}
|
|
2200
2200
|
}
|
|
2201
|
-
#EncodeMatched(
|
|
2201
|
+
#EncodeMatched(encoder, matchByte, symbol) {
|
|
2202
2202
|
let bit, matchBit, state, same = true, context = 1;
|
|
2203
2203
|
for (let i = 7; i >= 0; --i) {
|
|
2204
2204
|
bit = symbol >> i & 1;
|
|
@@ -2208,21 +2208,23 @@ export class LZMA {
|
|
|
2208
2208
|
state += 1 + matchBit << 8;
|
|
2209
2209
|
same = matchBit === bit;
|
|
2210
2210
|
}
|
|
2211
|
-
this.#Encode_3(
|
|
2211
|
+
this.#Encode_3(encoder.m_Encoders, state, bit);
|
|
2212
2212
|
context = context << 1 | bit;
|
|
2213
2213
|
}
|
|
2214
2214
|
}
|
|
2215
|
-
#createLiteralEncoderEncoder2(
|
|
2216
|
-
|
|
2217
|
-
|
|
2215
|
+
#createLiteralEncoderEncoder2() {
|
|
2216
|
+
const encoder = {
|
|
2217
|
+
m_Encoders: this.#initArray(768),
|
|
2218
|
+
};
|
|
2219
|
+
return encoder;
|
|
2218
2220
|
}
|
|
2219
|
-
#
|
|
2221
|
+
#RangeCoder_Encoder_GetPrice_0(encoder, matchMode, matchByte, symbol) {
|
|
2220
2222
|
let bit, context = 1, i = 7, matchBit, price = 0;
|
|
2221
2223
|
if (matchMode) {
|
|
2222
2224
|
for (; i >= 0; --i) {
|
|
2223
2225
|
matchBit = matchByte >> i & 1;
|
|
2224
2226
|
bit = symbol >> i & 1;
|
|
2225
|
-
price += this.GetPrice(
|
|
2227
|
+
price += this.GetPrice(encoder.m_Encoders[(1 + matchBit << 8) + context], bit);
|
|
2226
2228
|
context = context << 1 | bit;
|
|
2227
2229
|
if (matchBit != bit) {
|
|
2228
2230
|
--i;
|
|
@@ -2232,18 +2234,18 @@ export class LZMA {
|
|
|
2232
2234
|
}
|
|
2233
2235
|
for (; i >= 0; --i) {
|
|
2234
2236
|
bit = symbol >> i & 1;
|
|
2235
|
-
price += this.GetPrice(
|
|
2237
|
+
price += this.GetPrice(encoder.m_Encoders[context], bit);
|
|
2236
2238
|
context = context << 1 | bit;
|
|
2237
2239
|
}
|
|
2238
2240
|
return price;
|
|
2239
2241
|
}
|
|
2240
|
-
#MakeAsChar(
|
|
2241
|
-
|
|
2242
|
-
|
|
2242
|
+
#MakeAsChar(optimum) {
|
|
2243
|
+
optimum.BackPrev = -1;
|
|
2244
|
+
optimum.Prev1IsChar = 0;
|
|
2243
2245
|
}
|
|
2244
|
-
#MakeAsShortRep(
|
|
2245
|
-
|
|
2246
|
-
|
|
2246
|
+
#MakeAsShortRep(optimum) {
|
|
2247
|
+
optimum.BackPrev = 0;
|
|
2248
|
+
optimum.Prev1IsChar = 0;
|
|
2247
2249
|
}
|
|
2248
2250
|
#createBitTreeDecoder(numBitLevels) {
|
|
2249
2251
|
return {
|
|
@@ -2251,8 +2253,7 @@ export class LZMA {
|
|
|
2251
2253
|
Models: this.#initArray(1 << numBitLevels),
|
|
2252
2254
|
};
|
|
2253
2255
|
}
|
|
2254
|
-
|
|
2255
|
-
#Decode_0(rangeDecoder) {
|
|
2256
|
+
#RangeCoder_BitTreeDecoder_Decoder(rangeDecoder) {
|
|
2256
2257
|
const _rangeDecoder = this.#decompressor.chunker.decoder.m_RangeDecoder;
|
|
2257
2258
|
let bitIndex, m = 1;
|
|
2258
2259
|
for (bitIndex = rangeDecoder.NumBitLevels; bitIndex != 0; bitIndex -= 1) {
|
|
@@ -2288,28 +2289,28 @@ export class LZMA {
|
|
|
2288
2289
|
Models: this.#initArray(1 << numBitLevels),
|
|
2289
2290
|
};
|
|
2290
2291
|
}
|
|
2291
|
-
#Encode_2(
|
|
2292
|
-
|
|
2293
|
-
for (bitIndex =
|
|
2292
|
+
#Encode_2(encoder, symbol) {
|
|
2293
|
+
let bit, bitIndex, m = 1;
|
|
2294
|
+
for (bitIndex = encoder.NumBitLevels; bitIndex != 0;) {
|
|
2294
2295
|
bitIndex -= 1;
|
|
2295
2296
|
bit = symbol >>> bitIndex & 1;
|
|
2296
|
-
this.#Encode_3(
|
|
2297
|
+
this.#Encode_3(encoder.Models, m, bit);
|
|
2297
2298
|
m = m << 1 | bit;
|
|
2298
2299
|
}
|
|
2299
2300
|
}
|
|
2300
|
-
#
|
|
2301
|
-
|
|
2302
|
-
for (bitIndex =
|
|
2301
|
+
#RangeCoder_Encoder_GetPrice_1(encoder, symbol) {
|
|
2302
|
+
let bit, bitIndex, m = 1, price = 0;
|
|
2303
|
+
for (bitIndex = encoder.NumBitLevels; bitIndex != 0;) {
|
|
2303
2304
|
bitIndex -= 1;
|
|
2304
2305
|
bit = symbol >>> bitIndex & 1;
|
|
2305
|
-
price += this.GetPrice(
|
|
2306
|
+
price += this.GetPrice(encoder.Models[m], bit);
|
|
2306
2307
|
m = (m << 1) + bit;
|
|
2307
2308
|
}
|
|
2308
2309
|
return price;
|
|
2309
2310
|
}
|
|
2310
2311
|
#ReverseEncode(symbol) {
|
|
2311
2312
|
const posAlignEncoder = this.#compressor.chunker.encoder._posAlignEncoder;
|
|
2312
|
-
|
|
2313
|
+
let bit, m = 1;
|
|
2313
2314
|
for (let i = 0; i < posAlignEncoder.NumBitLevels; ++i) {
|
|
2314
2315
|
bit = symbol & 1;
|
|
2315
2316
|
this.#Encode_3(posAlignEncoder.Models, m, bit);
|
|
@@ -2326,18 +2327,18 @@ export class LZMA {
|
|
|
2326
2327
|
symbol >>= 1;
|
|
2327
2328
|
}
|
|
2328
2329
|
}
|
|
2329
|
-
#ReverseGetPrice(
|
|
2330
|
+
#ReverseGetPrice(encoder, symbol) {
|
|
2330
2331
|
let bit, m = 1, price = 0;
|
|
2331
|
-
for (let i =
|
|
2332
|
+
for (let i = encoder.NumBitLevels; i != 0; i -= 1) {
|
|
2332
2333
|
bit = symbol & 1;
|
|
2333
2334
|
symbol >>>= 1;
|
|
2334
|
-
price += this.GetPrice(
|
|
2335
|
+
price += this.GetPrice(encoder.Models[m], bit);
|
|
2335
2336
|
m = m << 1 | bit;
|
|
2336
2337
|
}
|
|
2337
2338
|
return price;
|
|
2338
2339
|
}
|
|
2339
2340
|
ReverseGetPrice(Models, startIndex, NumBitLevels, symbol) {
|
|
2340
|
-
|
|
2341
|
+
let bit, m = 1, price = 0;
|
|
2341
2342
|
for (let i = NumBitLevels; i != 0; i -= 1) {
|
|
2342
2343
|
bit = symbol & 1;
|
|
2343
2344
|
symbol >>>= 1;
|
|
@@ -2400,7 +2401,7 @@ export class LZMA {
|
|
|
2400
2401
|
}
|
|
2401
2402
|
#Encode_3(probs, index, symbol) {
|
|
2402
2403
|
const rangeEncoder = this.#compressor.chunker.encoder._rangeEncoder;
|
|
2403
|
-
|
|
2404
|
+
let newBound, prob = probs[index];
|
|
2404
2405
|
newBound = (rangeEncoder.Range >>> 11) * prob;
|
|
2405
2406
|
if (!symbol) {
|
|
2406
2407
|
rangeEncoder.Range = newBound;
|
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.4.0-next.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"authors": [
|
|
7
7
|
"Filip Seman <filip.seman@pm.me>",
|
|
@@ -27,8 +27,6 @@
|
|
|
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
|
},
|