lzma1 0.0.1

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/lib/lzma.js ADDED
@@ -0,0 +1,2586 @@
1
+ /** xs */
2
+ /**
3
+ * NOTE: This is the master file that is used to generate lzma-c.js and lzma-d.js.
4
+ * Comments are used to determine which parts are to be removed.
5
+ *
6
+ * cs-ce (compression start-end)
7
+ * ds-de (decompression start-end)
8
+ * xs-xe (only in this file start-end)
9
+ * co (compression only)
10
+ * do (decompression only)
11
+ */
12
+ /** xe */
13
+ const __4294967296 = 4294967296, N1_longLit = [4294967295, -__4294967296],
14
+ /** cs */
15
+ MIN_VALUE = [0, -9223372036854775808],
16
+ /** ce */
17
+ P0_longLit = [0, 0], P1_longLit = [1, 0];
18
+ /**
19
+ * This is MUCH faster than "new Array(len)" in newer versions of v8
20
+ * (starting with Node.js 0.11.15, which uses v8 3.28.73).
21
+ */
22
+ function initDim(len) {
23
+ var array = [];
24
+ array[len - 1] = undefined;
25
+ return array;
26
+ }
27
+ function add(a, b) {
28
+ return create(a[0] + b[0], a[1] + b[1]);
29
+ }
30
+ /** cs */
31
+ function and(a, b) {
32
+ return makeFromBits(~~Math.max(Math.min(a[1] / __4294967296, 2147483647), -2147483648)
33
+ & ~~Math.max(Math.min(b[1] / __4294967296, 2147483647), -2147483648), lowBits_0(a) & lowBits_0(b));
34
+ }
35
+ /** ce */
36
+ function compare(a, b) {
37
+ var nega, negb;
38
+ if (a[0] == b[0] && a[1] == b[1]) {
39
+ return 0;
40
+ }
41
+ nega = a[1] < 0;
42
+ negb = b[1] < 0;
43
+ if (nega && !negb) {
44
+ return -1;
45
+ }
46
+ if (!nega && negb) {
47
+ return 1;
48
+ }
49
+ if (sub(a, b)[1] < 0) {
50
+ return -1;
51
+ }
52
+ return 1;
53
+ }
54
+ function create(valueLow, valueHigh) {
55
+ var diffHigh, diffLow;
56
+ valueHigh %= 1.8446744073709552E19;
57
+ valueLow %= 1.8446744073709552E19;
58
+ diffHigh = valueHigh % __4294967296;
59
+ diffLow = Math.floor(valueLow / __4294967296) * __4294967296;
60
+ valueHigh = valueHigh - diffHigh + diffLow;
61
+ valueLow = valueLow - diffLow + diffHigh;
62
+ while (valueLow < 0) {
63
+ valueLow += __4294967296;
64
+ valueHigh -= __4294967296;
65
+ }
66
+ while (valueLow > 4294967295) {
67
+ valueLow -= __4294967296;
68
+ valueHigh += __4294967296;
69
+ }
70
+ valueHigh = valueHigh % 1.8446744073709552E19;
71
+ while (valueHigh > 9223372032559808512) {
72
+ valueHigh -= 1.8446744073709552E19;
73
+ }
74
+ while (valueHigh < -9223372036854775808) {
75
+ valueHigh += 1.8446744073709552E19;
76
+ }
77
+ return [valueLow, valueHigh];
78
+ }
79
+ /** cs */
80
+ function eq(a, b) {
81
+ return a[0] == b[0] && a[1] == b[1];
82
+ }
83
+ /** ce */
84
+ function fromInt(value) {
85
+ if (value >= 0) {
86
+ return [value, 0];
87
+ }
88
+ else {
89
+ return [value + __4294967296, -__4294967296];
90
+ }
91
+ }
92
+ function lowBits_0(a) {
93
+ if (a[0] >= 2147483648) {
94
+ return ~~Math.max(Math.min(a[0] - __4294967296, 2147483647), -2147483648);
95
+ }
96
+ else {
97
+ return ~~Math.max(Math.min(a[0], 2147483647), -2147483648);
98
+ }
99
+ }
100
+ /** cs */
101
+ function makeFromBits(highBits, lowBits) {
102
+ var high, low;
103
+ high = highBits * __4294967296;
104
+ low = lowBits;
105
+ if (lowBits < 0) {
106
+ low += __4294967296;
107
+ }
108
+ return [low, high];
109
+ }
110
+ function pwrAsDouble(n) {
111
+ if (n <= 30) {
112
+ return 1 << n;
113
+ }
114
+ else {
115
+ return pwrAsDouble(30) * pwrAsDouble(n - 30);
116
+ }
117
+ }
118
+ function shl(a, n) {
119
+ var diff, newHigh, newLow, twoToN;
120
+ n &= 63;
121
+ if (eq(a, MIN_VALUE)) {
122
+ if (!n) {
123
+ return a;
124
+ }
125
+ return P0_longLit;
126
+ }
127
+ if (a[1] < 0) {
128
+ throw new Error("Neg");
129
+ }
130
+ twoToN = pwrAsDouble(n);
131
+ newHigh = a[1] * twoToN % 1.8446744073709552E19;
132
+ newLow = a[0] * twoToN;
133
+ diff = newLow - newLow % __4294967296;
134
+ newHigh += diff;
135
+ newLow -= diff;
136
+ if (newHigh >= 9223372036854775807) {
137
+ newHigh -= 1.8446744073709552E19;
138
+ }
139
+ return [newLow, newHigh];
140
+ }
141
+ function shr(a, n) {
142
+ var shiftFact;
143
+ n &= 63;
144
+ shiftFact = pwrAsDouble(n);
145
+ return create(Math.floor(a[0] / shiftFact), a[1] / shiftFact);
146
+ }
147
+ function shru(a, n) {
148
+ var sr;
149
+ n &= 63;
150
+ sr = shr(a, n);
151
+ if (a[1] < 0) {
152
+ sr = add(sr, shl([2, 0], 63 - n));
153
+ }
154
+ return sr;
155
+ }
156
+ /** ce */
157
+ function sub(a, b) {
158
+ return create(a[0] - b[0], a[1] - b[1]);
159
+ }
160
+ function $ByteArrayInputStream(this$static, buf) {
161
+ this$static.buf = buf;
162
+ this$static.pos = 0;
163
+ this$static.count = buf.length;
164
+ return this$static;
165
+ }
166
+ /** ds */
167
+ function $read(this$static) {
168
+ if (this$static.pos >= this$static.count) {
169
+ return -1;
170
+ }
171
+ return this$static.buf[this$static.pos++] & 255;
172
+ }
173
+ /** de */
174
+ /** cs */
175
+ function $read_0(this$static, buf, off, len) {
176
+ if (this$static.pos >= this$static.count) {
177
+ return -1;
178
+ }
179
+ len = Math.min(len, this$static.count - this$static.pos);
180
+ arraycopy(this$static.buf, this$static.pos, buf, off, len);
181
+ this$static.pos += len;
182
+ return len;
183
+ }
184
+ /** ce */
185
+ function $ByteArrayOutputStream(this$static) {
186
+ this$static.buf = initDim(32);
187
+ this$static.count = 0;
188
+ return this$static;
189
+ }
190
+ function $toByteArray(this$static) {
191
+ var data = this$static.buf;
192
+ data.length = this$static.count;
193
+ return data;
194
+ }
195
+ /** cs */
196
+ function $write(this$static, b) {
197
+ this$static.buf[this$static.count++] = b << 24 >> 24;
198
+ }
199
+ /** ce */
200
+ function $write_0(this$static, buf, off, len) {
201
+ arraycopy(buf, off, this$static.buf, this$static.count, len);
202
+ this$static.count += len;
203
+ }
204
+ /** cs */
205
+ function $getChars(this$static, srcBegin, srcEnd, dst, dstBegin) {
206
+ var srcIdx;
207
+ for (srcIdx = srcBegin; srcIdx < srcEnd; ++srcIdx) {
208
+ dst[dstBegin++] = this$static.charCodeAt(srcIdx);
209
+ }
210
+ }
211
+ /** ce */
212
+ function arraycopy(src, srcOfs, dest, destOfs, len) {
213
+ for (var i = 0; i < len; ++i) {
214
+ dest[destOfs + i] = src[srcOfs + i];
215
+ }
216
+ }
217
+ /** cs */
218
+ function $configure(this$static, encoder) {
219
+ $SetDictionarySize_0(encoder, 1 << this$static.s);
220
+ encoder._numFastBytes = this$static.f;
221
+ $SetMatchFinder(encoder, this$static.m);
222
+ /// lc is always 3
223
+ /// lp is always 0
224
+ /// pb is always 2
225
+ encoder._numLiteralPosStateBits = 0;
226
+ encoder._numLiteralContextBits = 3;
227
+ encoder._posStateBits = 2;
228
+ /// this$static._posStateMask = (1 << pb) - 1;
229
+ encoder._posStateMask = 3;
230
+ }
231
+ function $init(this$static, input, output, length_0, mode) {
232
+ var encoder, i;
233
+ if (compare(length_0, N1_longLit) < 0) {
234
+ throw new Error("invalid length " + length_0);
235
+ }
236
+ this$static.length_0 = length_0;
237
+ encoder = $Encoder({});
238
+ $configure(mode, encoder);
239
+ // encoder._writeEndMark = typeof LZMA.disableEndMark == "undefined";
240
+ $WriteCoderProperties(encoder, output);
241
+ for (i = 0; i < 64; i += 8) {
242
+ $write(output, lowBits_0(shr(length_0, i)) & 255);
243
+ }
244
+ this$static.chunker =
245
+ (encoder._needReleaseMFStream = 0,
246
+ (encoder._inStream = input,
247
+ encoder._finished = 0,
248
+ $Create_2(encoder),
249
+ encoder._rangeEncoder.Stream = output,
250
+ $Init_4(encoder),
251
+ $FillDistancesPrices(encoder),
252
+ $FillAlignPrices(encoder),
253
+ encoder._lenEncoder._tableSize = encoder._numFastBytes + 1 - 2,
254
+ $UpdateTables(encoder._lenEncoder, 1 << encoder._posStateBits),
255
+ encoder._repMatchLenEncoder._tableSize = encoder._numFastBytes
256
+ + 1 - 2,
257
+ $UpdateTables(encoder._repMatchLenEncoder, 1 << encoder._posStateBits),
258
+ encoder.nowPos64 = P0_longLit,
259
+ undefined),
260
+ $Chunker_0({}, encoder));
261
+ }
262
+ function $LZMAByteArrayCompressor(this$static, data, mode) {
263
+ this$static.output = $ByteArrayOutputStream({});
264
+ $init(this$static, $ByteArrayInputStream({}, data), this$static.output, fromInt(data.length), mode);
265
+ return this$static;
266
+ }
267
+ /** ce */
268
+ /** ds */
269
+ function $init_0(this$static, input, output) {
270
+ var decoder, hex_length = "", i, properties = [], r, tmp_length;
271
+ for (i = 0; i < 5; ++i) {
272
+ r = $read(input);
273
+ if (r == -1) {
274
+ throw new Error("truncated input");
275
+ }
276
+ properties[i] = r << 24 >> 24;
277
+ }
278
+ decoder = $Decoder({});
279
+ if (!$SetDecoderProperties(decoder, properties)) {
280
+ throw new Error("corrupted input");
281
+ }
282
+ for (i = 0; i < 64; i += 8) {
283
+ r = $read(input);
284
+ if (r == -1) {
285
+ throw new Error("truncated input");
286
+ }
287
+ r = r.toString(16);
288
+ if (r.length == 1)
289
+ r = "0" + r;
290
+ hex_length = r + "" + hex_length;
291
+ }
292
+ /**
293
+ * Was the length set in the header (if it was compressed from a stream, the
294
+ * length is all f"s).
295
+ */
296
+ if (/^0+$|^f+$/i.test(hex_length)) {
297
+ /// The length is unknown, so set to -1.
298
+ this$static.length_0 = N1_longLit;
299
+ }
300
+ else {
301
+ /**
302
+ * NOTE: If there is a problem with the decoder because of the length,
303
+ * you can always set the length to -1 (N1_longLit) which means unknown.
304
+ */
305
+ tmp_length = parseInt(hex_length, 16);
306
+ /// If the length is too long to handle, just set it to unknown.
307
+ if (tmp_length > 4294967295) {
308
+ this$static.length_0 = N1_longLit;
309
+ }
310
+ else {
311
+ this$static.length_0 = fromInt(tmp_length);
312
+ }
313
+ }
314
+ this$static.chunker = $CodeInChunks(decoder, input, output, this$static.length_0);
315
+ }
316
+ function $LZMAByteArrayDecompressor(this$static, data) {
317
+ this$static.output = $ByteArrayOutputStream({});
318
+ $init_0(this$static, $ByteArrayInputStream({}, data), this$static.output);
319
+ return this$static;
320
+ }
321
+ /** de */
322
+ /** cs */
323
+ function $Create_4(this$static, keepSizeBefore, keepSizeAfter, keepSizeReserv) {
324
+ var blockSize;
325
+ this$static._keepSizeBefore = keepSizeBefore;
326
+ this$static._keepSizeAfter = keepSizeAfter;
327
+ blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;
328
+ if (this$static._bufferBase == null || this$static._blockSize != blockSize) {
329
+ this$static._bufferBase = null;
330
+ this$static._blockSize = blockSize;
331
+ this$static._bufferBase = initDim(this$static._blockSize);
332
+ }
333
+ this$static._pointerToLastSafePosition = this$static._blockSize
334
+ - keepSizeAfter;
335
+ }
336
+ function $GetIndexByte(this$static, index) {
337
+ return this$static
338
+ ._bufferBase[this$static._bufferOffset + this$static._pos + index];
339
+ }
340
+ function $GetMatchLen(this$static, index, distance, limit) {
341
+ var i, pby;
342
+ if (this$static._streamEndWasReached) {
343
+ if (this$static._pos + index + limit > this$static._streamPos) {
344
+ limit = this$static._streamPos - (this$static._pos + index);
345
+ }
346
+ }
347
+ ;
348
+ ++distance;
349
+ pby = this$static._bufferOffset + this$static._pos + index;
350
+ for (i = 0; i < limit
351
+ && this$static._bufferBase[pby + i]
352
+ == this$static._bufferBase[pby + i - distance]; ++i) {
353
+ }
354
+ return i;
355
+ }
356
+ function $GetNumAvailableBytes(this$static) {
357
+ return this$static._streamPos - this$static._pos;
358
+ }
359
+ function $MoveBlock(this$static) {
360
+ var i, numBytes, offset;
361
+ offset = this$static._bufferOffset + this$static._pos
362
+ - this$static._keepSizeBefore;
363
+ if (offset > 0) {
364
+ ;
365
+ --offset;
366
+ }
367
+ numBytes = this$static._bufferOffset + this$static._streamPos - offset;
368
+ for (i = 0; i < numBytes; ++i) {
369
+ this$static._bufferBase[i] = this$static._bufferBase[offset + i];
370
+ }
371
+ this$static._bufferOffset -= offset;
372
+ }
373
+ function $MovePos_1(this$static) {
374
+ var pointerToPostion;
375
+ this$static._pos += 1;
376
+ if (this$static._pos > this$static._posLimit) {
377
+ pointerToPostion = this$static._bufferOffset + this$static._pos;
378
+ if (pointerToPostion > this$static._pointerToLastSafePosition) {
379
+ $MoveBlock(this$static);
380
+ }
381
+ $ReadBlock(this$static);
382
+ }
383
+ }
384
+ function $ReadBlock(this$static) {
385
+ var numReadBytes, pointerToPostion, size;
386
+ if (this$static._streamEndWasReached) {
387
+ return;
388
+ }
389
+ while (1) {
390
+ size = -this$static._bufferOffset + this$static._blockSize
391
+ - this$static._streamPos;
392
+ if (!size) {
393
+ return;
394
+ }
395
+ numReadBytes = $read_0(this$static._stream, this$static._bufferBase, this$static._bufferOffset + this$static._streamPos, size);
396
+ if (numReadBytes == -1) {
397
+ this$static._posLimit = this$static._streamPos;
398
+ pointerToPostion = this$static._bufferOffset + this$static._posLimit;
399
+ if (pointerToPostion > this$static._pointerToLastSafePosition) {
400
+ this$static._posLimit = this$static._pointerToLastSafePosition
401
+ - this$static._bufferOffset;
402
+ }
403
+ this$static._streamEndWasReached = 1;
404
+ return;
405
+ }
406
+ this$static._streamPos += numReadBytes;
407
+ if (this$static._streamPos
408
+ >= this$static._pos + this$static._keepSizeAfter) {
409
+ this$static._posLimit = this$static._streamPos
410
+ - this$static._keepSizeAfter;
411
+ }
412
+ }
413
+ }
414
+ function $ReduceOffsets(this$static, subValue) {
415
+ this$static._bufferOffset += subValue;
416
+ this$static._posLimit -= subValue;
417
+ this$static._pos -= subValue;
418
+ this$static._streamPos -= subValue;
419
+ }
420
+ const CrcTable = function () {
421
+ var i, j, r, CrcTable = [];
422
+ for (i = 0; i < 256; ++i) {
423
+ r = i;
424
+ for (j = 0; j < 8; ++j) {
425
+ if ((r & 1) != 0) {
426
+ r >>>= 1;
427
+ r ^= -306674912;
428
+ }
429
+ else {
430
+ r >>>= 1;
431
+ }
432
+ }
433
+ CrcTable[i] = r;
434
+ }
435
+ return CrcTable;
436
+ }();
437
+ function $Create_3(this$static, historySize, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter) {
438
+ var cyclicBufferSize, hs, windowReservSize;
439
+ if (historySize < 1073741567) {
440
+ this$static._cutValue = 16 + (matchMaxLen >> 1);
441
+ windowReservSize = ~~((historySize + keepAddBufferBefore + matchMaxLen
442
+ + keepAddBufferAfter) / 2) + 256;
443
+ $Create_4(this$static, historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);
444
+ this$static._matchMaxLen = matchMaxLen;
445
+ cyclicBufferSize = historySize + 1;
446
+ if (this$static._cyclicBufferSize != cyclicBufferSize) {
447
+ this$static._son = initDim((this$static._cyclicBufferSize = cyclicBufferSize) * 2);
448
+ }
449
+ hs = 65536;
450
+ if (this$static.HASH_ARRAY) {
451
+ hs = historySize - 1;
452
+ hs |= hs >> 1;
453
+ hs |= hs >> 2;
454
+ hs |= hs >> 4;
455
+ hs |= hs >> 8;
456
+ hs >>= 1;
457
+ hs |= 65535;
458
+ if (hs > 16777216) {
459
+ hs >>= 1;
460
+ }
461
+ this$static._hashMask = hs;
462
+ hs += 1;
463
+ hs += this$static.kFixHashSize;
464
+ }
465
+ if (hs != this$static._hashSizeSum) {
466
+ this$static._hash = initDim(this$static._hashSizeSum = hs);
467
+ }
468
+ }
469
+ }
470
+ function $GetMatches(this$static, distances) {
471
+ var count, cur, curMatch, curMatch2, curMatch3, cyclicPos, delta, hash2Value, hash3Value, hashValue, len, len0, len1, lenLimit, matchMinPos, maxLen, offset, pby1, ptr0, ptr1, temp;
472
+ if (this$static._pos + this$static._matchMaxLen <= this$static._streamPos) {
473
+ lenLimit = this$static._matchMaxLen;
474
+ }
475
+ else {
476
+ lenLimit = this$static._streamPos - this$static._pos;
477
+ if (lenLimit < this$static.kMinMatchCheck) {
478
+ $MovePos_0(this$static);
479
+ return 0;
480
+ }
481
+ }
482
+ offset = 0;
483
+ matchMinPos = this$static._pos > this$static._cyclicBufferSize
484
+ ? this$static._pos - this$static._cyclicBufferSize
485
+ : 0;
486
+ cur = this$static._bufferOffset + this$static._pos;
487
+ maxLen = 1;
488
+ hash2Value = 0;
489
+ hash3Value = 0;
490
+ if (this$static.HASH_ARRAY) {
491
+ temp = CrcTable[this$static._bufferBase[cur] & 255]
492
+ ^ this$static._bufferBase[cur + 1] & 255;
493
+ hash2Value = temp & 1023;
494
+ temp ^= (this$static._bufferBase[cur + 2] & 255) << 8;
495
+ hash3Value = temp & 65535;
496
+ hashValue =
497
+ (temp ^ CrcTable[this$static._bufferBase[cur + 3] & 255] << 5)
498
+ & this$static._hashMask;
499
+ }
500
+ else {
501
+ hashValue = this$static._bufferBase[cur] & 255
502
+ ^ (this$static._bufferBase[cur + 1] & 255) << 8;
503
+ }
504
+ curMatch = this$static._hash[this$static.kFixHashSize + hashValue] || 0;
505
+ if (this$static.HASH_ARRAY) {
506
+ curMatch2 = this$static._hash[hash2Value] || 0;
507
+ curMatch3 = this$static._hash[1024 + hash3Value] || 0;
508
+ this$static._hash[hash2Value] = this$static._pos;
509
+ this$static._hash[1024 + hash3Value] = this$static._pos;
510
+ if (curMatch2 > matchMinPos) {
511
+ if (this$static._bufferBase[this$static._bufferOffset + curMatch2]
512
+ == this$static._bufferBase[cur]) {
513
+ distances[offset++] = maxLen = 2;
514
+ distances[offset++] = this$static._pos - curMatch2 - 1;
515
+ }
516
+ }
517
+ if (curMatch3 > matchMinPos) {
518
+ if (this$static._bufferBase[this$static._bufferOffset + curMatch3]
519
+ == this$static._bufferBase[cur]) {
520
+ if (curMatch3 == curMatch2) {
521
+ offset -= 2;
522
+ }
523
+ distances[offset++] = maxLen = 3;
524
+ distances[offset++] = this$static._pos - curMatch3 - 1;
525
+ curMatch2 = curMatch3;
526
+ }
527
+ }
528
+ if (offset != 0 && curMatch2 == curMatch) {
529
+ offset -= 2;
530
+ maxLen = 1;
531
+ }
532
+ }
533
+ this$static._hash[this$static.kFixHashSize + hashValue] = this$static._pos;
534
+ ptr0 = (this$static._cyclicBufferPos << 1) + 1;
535
+ ptr1 = this$static._cyclicBufferPos << 1;
536
+ len0 = len1 = this$static.kNumHashDirectBytes;
537
+ if (this$static.kNumHashDirectBytes != 0) {
538
+ if (curMatch > matchMinPos) {
539
+ if (this$static
540
+ ._bufferBase[this$static._bufferOffset + curMatch
541
+ + this$static.kNumHashDirectBytes]
542
+ != this$static
543
+ ._bufferBase[cur + this$static.kNumHashDirectBytes]) {
544
+ distances[offset++] = maxLen = this$static.kNumHashDirectBytes;
545
+ distances[offset++] = this$static._pos - curMatch - 1;
546
+ }
547
+ }
548
+ }
549
+ count = this$static._cutValue;
550
+ while (1) {
551
+ if (curMatch <= matchMinPos || count == 0) {
552
+ count -= 1;
553
+ this$static._son[ptr0] = this$static._son[ptr1] = 0;
554
+ break;
555
+ }
556
+ delta = this$static._pos - curMatch;
557
+ cyclicPos = (delta <= this$static._cyclicBufferPos
558
+ ? this$static._cyclicBufferPos - delta
559
+ : this$static._cyclicBufferPos - delta
560
+ + this$static._cyclicBufferSize) << 1;
561
+ pby1 = this$static._bufferOffset + curMatch;
562
+ len = len0 < len1 ? len0 : len1;
563
+ if (this$static._bufferBase[pby1 + len]
564
+ == this$static._bufferBase[cur + len]) {
565
+ while ((len += 1) != lenLimit) {
566
+ if (this$static._bufferBase[pby1 + len]
567
+ != this$static._bufferBase[cur + len]) {
568
+ break;
569
+ }
570
+ }
571
+ if (maxLen < len) {
572
+ distances[offset++] = maxLen = len;
573
+ distances[offset++] = delta - 1;
574
+ if (len == lenLimit) {
575
+ this$static._son[ptr1] = this$static._son[cyclicPos];
576
+ this$static._son[ptr0] = this$static._son[cyclicPos + 1];
577
+ break;
578
+ }
579
+ }
580
+ }
581
+ if ((this$static._bufferBase[pby1 + len] & 255)
582
+ < (this$static._bufferBase[cur + len] & 255)) {
583
+ this$static._son[ptr1] = curMatch;
584
+ ptr1 = cyclicPos + 1;
585
+ curMatch = this$static._son[ptr1];
586
+ len1 = len;
587
+ }
588
+ else {
589
+ this$static._son[ptr0] = curMatch;
590
+ ptr0 = cyclicPos;
591
+ curMatch = this$static._son[ptr0];
592
+ len0 = len;
593
+ }
594
+ }
595
+ $MovePos_0(this$static);
596
+ return offset;
597
+ }
598
+ function $Init_5(this$static) {
599
+ this$static._bufferOffset = 0;
600
+ this$static._pos = 0;
601
+ this$static._streamPos = 0;
602
+ this$static._streamEndWasReached = 0;
603
+ $ReadBlock(this$static);
604
+ this$static._cyclicBufferPos = 0;
605
+ $ReduceOffsets(this$static, -1);
606
+ }
607
+ function $MovePos_0(this$static) {
608
+ var subValue;
609
+ if ((this$static._cyclicBufferPos += 1) >= this$static._cyclicBufferSize) {
610
+ this$static._cyclicBufferPos = 0;
611
+ }
612
+ $MovePos_1(this$static);
613
+ if (this$static._pos == 1073741823) {
614
+ subValue = this$static._pos - this$static._cyclicBufferSize;
615
+ $NormalizeLinks(this$static._son, this$static._cyclicBufferSize * 2, subValue);
616
+ $NormalizeLinks(this$static._hash, this$static._hashSizeSum, subValue);
617
+ $ReduceOffsets(this$static, subValue);
618
+ }
619
+ }
620
+ /**
621
+ * This is only called after reading one whole gigabyte.
622
+ */
623
+ function $NormalizeLinks(items, numItems, subValue) {
624
+ var i, value;
625
+ for (i = 0; i < numItems; ++i) {
626
+ value = items[i] || 0;
627
+ if (value <= subValue) {
628
+ value = 0;
629
+ }
630
+ else {
631
+ value -= subValue;
632
+ }
633
+ items[i] = value;
634
+ }
635
+ }
636
+ function $SetType(this$static, numHashBytes) {
637
+ this$static.HASH_ARRAY = numHashBytes > 2;
638
+ if (this$static.HASH_ARRAY) {
639
+ this$static.kNumHashDirectBytes = 0;
640
+ this$static.kMinMatchCheck = 4;
641
+ this$static.kFixHashSize = 66560;
642
+ }
643
+ else {
644
+ this$static.kNumHashDirectBytes = 2;
645
+ this$static.kMinMatchCheck = 3;
646
+ this$static.kFixHashSize = 0;
647
+ }
648
+ }
649
+ function $Skip(this$static, num) {
650
+ var count, cur, curMatch, cyclicPos, delta, hash2Value, hash3Value, hashValue, len, len0, len1, lenLimit, matchMinPos, pby1, ptr0, ptr1, temp;
651
+ do {
652
+ if (this$static._pos + this$static._matchMaxLen
653
+ <= this$static._streamPos) {
654
+ lenLimit = this$static._matchMaxLen;
655
+ }
656
+ else {
657
+ lenLimit = this$static._streamPos - this$static._pos;
658
+ if (lenLimit < this$static.kMinMatchCheck) {
659
+ $MovePos_0(this$static);
660
+ continue;
661
+ }
662
+ }
663
+ matchMinPos = this$static._pos > this$static._cyclicBufferSize
664
+ ? this$static._pos - this$static._cyclicBufferSize
665
+ : 0;
666
+ cur = this$static._bufferOffset + this$static._pos;
667
+ if (this$static.HASH_ARRAY) {
668
+ temp = CrcTable[this$static._bufferBase[cur] & 255]
669
+ ^ this$static._bufferBase[cur + 1] & 255;
670
+ hash2Value = temp & 1023;
671
+ this$static._hash[hash2Value] = this$static._pos;
672
+ temp ^= (this$static._bufferBase[cur + 2] & 255) << 8;
673
+ hash3Value = temp & 65535;
674
+ this$static._hash[1024 + hash3Value] = this$static._pos;
675
+ hashValue =
676
+ (temp ^ CrcTable[this$static._bufferBase[cur + 3] & 255] << 5)
677
+ & this$static._hashMask;
678
+ }
679
+ else {
680
+ hashValue = this$static._bufferBase[cur] & 255
681
+ ^ (this$static._bufferBase[cur + 1] & 255) << 8;
682
+ }
683
+ curMatch = this$static._hash[this$static.kFixHashSize + hashValue];
684
+ this$static._hash[this$static.kFixHashSize + hashValue] =
685
+ this$static._pos;
686
+ ptr0 = (this$static._cyclicBufferPos << 1) + 1;
687
+ ptr1 = this$static._cyclicBufferPos << 1;
688
+ len0 = len1 = this$static.kNumHashDirectBytes;
689
+ count = this$static._cutValue;
690
+ while (1) {
691
+ if (curMatch <= matchMinPos || count == 0) {
692
+ count -= 1;
693
+ this$static._son[ptr0] = this$static._son[ptr1] = 0;
694
+ break;
695
+ }
696
+ delta = this$static._pos - curMatch;
697
+ cyclicPos = (delta <= this$static._cyclicBufferPos
698
+ ? this$static._cyclicBufferPos - delta
699
+ : this$static._cyclicBufferPos - delta
700
+ + this$static._cyclicBufferSize) << 1;
701
+ pby1 = this$static._bufferOffset + curMatch;
702
+ len = len0 < len1 ? len0 : len1;
703
+ if (this$static._bufferBase[pby1 + len]
704
+ == this$static._bufferBase[cur + len]) {
705
+ while ((len += 1) != lenLimit) {
706
+ if (this$static._bufferBase[pby1 + len]
707
+ != this$static._bufferBase[cur + len]) {
708
+ break;
709
+ }
710
+ }
711
+ if (len == lenLimit) {
712
+ this$static._son[ptr1] = this$static._son[cyclicPos];
713
+ this$static._son[ptr0] = this$static._son[cyclicPos + 1];
714
+ break;
715
+ }
716
+ }
717
+ if ((this$static._bufferBase[pby1 + len] & 255)
718
+ < (this$static._bufferBase[cur + len] & 255)) {
719
+ this$static._son[ptr1] = curMatch;
720
+ ptr1 = cyclicPos + 1;
721
+ curMatch = this$static._son[ptr1];
722
+ len1 = len;
723
+ }
724
+ else {
725
+ this$static._son[ptr0] = curMatch;
726
+ ptr0 = cyclicPos;
727
+ curMatch = this$static._son[ptr0];
728
+ len0 = len;
729
+ }
730
+ }
731
+ $MovePos_0(this$static);
732
+ } while ((num -= 1) != 0);
733
+ }
734
+ /** ce */
735
+ /** ds */
736
+ function $CopyBlock(this$static, distance, len) {
737
+ var pos = this$static._pos - distance - 1;
738
+ if (pos < 0) {
739
+ pos += this$static._windowSize;
740
+ }
741
+ for (; len != 0; len -= 1) {
742
+ if (pos >= this$static._windowSize) {
743
+ pos = 0;
744
+ }
745
+ this$static._buffer[this$static._pos] = this$static._buffer[pos];
746
+ this$static._pos += 1;
747
+ pos += 1;
748
+ if (this$static._pos >= this$static._windowSize) {
749
+ $Flush_0(this$static);
750
+ }
751
+ }
752
+ }
753
+ function $Create_5(this$static, windowSize) {
754
+ if (this$static._buffer == null || this$static._windowSize != windowSize) {
755
+ this$static._buffer = initDim(windowSize);
756
+ }
757
+ this$static._windowSize = windowSize;
758
+ this$static._pos = 0;
759
+ this$static._streamPos = 0;
760
+ }
761
+ function $Flush_0(this$static) {
762
+ var size = this$static._pos - this$static._streamPos;
763
+ if (!size) {
764
+ return;
765
+ }
766
+ $write_0(this$static._stream, this$static._buffer, this$static._streamPos, size);
767
+ if (this$static._pos >= this$static._windowSize) {
768
+ this$static._pos = 0;
769
+ }
770
+ this$static._streamPos = this$static._pos;
771
+ }
772
+ function $GetByte(this$static, distance) {
773
+ var pos = this$static._pos - distance - 1;
774
+ if (pos < 0) {
775
+ pos += this$static._windowSize;
776
+ }
777
+ return this$static._buffer[pos];
778
+ }
779
+ function $PutByte(this$static, b) {
780
+ this$static._buffer[this$static._pos] = b;
781
+ this$static._pos += 1;
782
+ if (this$static._pos >= this$static._windowSize) {
783
+ $Flush_0(this$static);
784
+ }
785
+ }
786
+ function $ReleaseStream(this$static) {
787
+ $Flush_0(this$static);
788
+ this$static._stream = null;
789
+ }
790
+ /** de */
791
+ function GetLenToPosState(len) {
792
+ len -= 2;
793
+ if (len < 4) {
794
+ return len;
795
+ }
796
+ return 3;
797
+ }
798
+ function StateUpdateChar(index) {
799
+ if (index < 4) {
800
+ return 0;
801
+ }
802
+ if (index < 10) {
803
+ return index - 3;
804
+ }
805
+ return index - 6;
806
+ }
807
+ /** cs */
808
+ function $Chunker_0(this$static, encoder) {
809
+ this$static.encoder = encoder;
810
+ this$static.decoder = null;
811
+ this$static.alive = 1;
812
+ return this$static;
813
+ }
814
+ /** ce */
815
+ /** ds */
816
+ function $Chunker(this$static, decoder) {
817
+ this$static.decoder = decoder;
818
+ this$static.encoder = null;
819
+ this$static.alive = 1;
820
+ return this$static;
821
+ }
822
+ /** de */
823
+ /** ds */
824
+ function $processChunkDecode(this$static) {
825
+ if (!this$static.alive) {
826
+ throw new Error("bad state");
827
+ }
828
+ if (this$static.encoder) {
829
+ throw new Error("No encoding");
830
+ }
831
+ else {
832
+ $processDecoderChunk(this$static);
833
+ }
834
+ return this$static.alive;
835
+ }
836
+ function $processDecoderChunk(this$static) {
837
+ var result = $CodeOneChunk(this$static.decoder);
838
+ if (result == -1) {
839
+ throw new Error("corrupted input");
840
+ }
841
+ this$static.inBytesProcessed = N1_longLit;
842
+ this$static.outBytesProcessed = this$static.decoder.nowPos64;
843
+ if (result
844
+ || compare(this$static.decoder.outSize, P0_longLit) >= 0
845
+ && compare(this$static.decoder.nowPos64, this$static.decoder.outSize) >= 0) {
846
+ $Flush_0(this$static.decoder.m_OutWindow);
847
+ $ReleaseStream(this$static.decoder.m_OutWindow);
848
+ this$static.decoder.m_RangeDecoder.Stream = null;
849
+ this$static.alive = 0;
850
+ }
851
+ }
852
+ /** de */
853
+ /** cs */
854
+ function $processChunkEncode(this$static) {
855
+ if (!this$static.alive) {
856
+ throw new Error("bad state");
857
+ }
858
+ if (this$static.encoder) {
859
+ $processEncoderChunk(this$static);
860
+ }
861
+ else {
862
+ throw new Error("No decoding");
863
+ }
864
+ return this$static.alive;
865
+ }
866
+ function $processEncoderChunk(this$static) {
867
+ $CodeOneBlock(this$static.encoder, this$static.encoder.processedInSize, this$static.encoder.processedOutSize, this$static.encoder.finished);
868
+ this$static.inBytesProcessed = this$static.encoder.processedInSize[0];
869
+ if (this$static.encoder.finished[0]) {
870
+ $ReleaseStreams(this$static.encoder);
871
+ this$static.alive = 0;
872
+ }
873
+ }
874
+ /** ce */
875
+ /** ds */
876
+ function $CodeInChunks(this$static, inStream, outStream, outSize) {
877
+ this$static.m_RangeDecoder.Stream = inStream;
878
+ $ReleaseStream(this$static.m_OutWindow);
879
+ this$static.m_OutWindow._stream = outStream;
880
+ $Init_1(this$static);
881
+ this$static.state = 0;
882
+ this$static.rep0 = 0;
883
+ this$static.rep1 = 0;
884
+ this$static.rep2 = 0;
885
+ this$static.rep3 = 0;
886
+ this$static.outSize = outSize;
887
+ this$static.nowPos64 = P0_longLit;
888
+ this$static.prevByte = 0;
889
+ return $Chunker({}, this$static);
890
+ }
891
+ function $CodeOneChunk(this$static) {
892
+ var decoder2, distance, len, numDirectBits, posSlot, posState;
893
+ posState = lowBits_0(this$static.nowPos64) & this$static.m_PosStateMask;
894
+ if (!$DecodeBit(this$static.m_RangeDecoder, this$static.m_IsMatchDecoders, (this$static.state << 4) + posState)) {
895
+ decoder2 = $GetDecoder(this$static.m_LiteralDecoder, lowBits_0(this$static.nowPos64), this$static.prevByte);
896
+ if (this$static.state < 7) {
897
+ this$static.prevByte = $DecodeNormal(decoder2, this$static.m_RangeDecoder);
898
+ }
899
+ else {
900
+ this$static.prevByte = $DecodeWithMatchByte(decoder2, this$static.m_RangeDecoder, $GetByte(this$static.m_OutWindow, this$static.rep0));
901
+ }
902
+ $PutByte(this$static.m_OutWindow, this$static.prevByte);
903
+ this$static.state = StateUpdateChar(this$static.state);
904
+ this$static.nowPos64 = add(this$static.nowPos64, P1_longLit);
905
+ }
906
+ else {
907
+ if ($DecodeBit(this$static.m_RangeDecoder, this$static.m_IsRepDecoders, this$static.state)) {
908
+ len = 0;
909
+ if (!$DecodeBit(this$static.m_RangeDecoder, this$static.m_IsRepG0Decoders, this$static.state)) {
910
+ if (!$DecodeBit(this$static.m_RangeDecoder, this$static.m_IsRep0LongDecoders, (this$static.state << 4) + posState)) {
911
+ this$static.state = this$static.state < 7 ? 9 : 11;
912
+ len = 1;
913
+ }
914
+ }
915
+ else {
916
+ if (!$DecodeBit(this$static.m_RangeDecoder, this$static.m_IsRepG1Decoders, this$static.state)) {
917
+ distance = this$static.rep1;
918
+ }
919
+ else {
920
+ if (!$DecodeBit(this$static.m_RangeDecoder, this$static.m_IsRepG2Decoders, this$static.state)) {
921
+ distance = this$static.rep2;
922
+ }
923
+ else {
924
+ distance = this$static.rep3;
925
+ this$static.rep3 = this$static.rep2;
926
+ }
927
+ this$static.rep2 = this$static.rep1;
928
+ }
929
+ this$static.rep1 = this$static.rep0;
930
+ this$static.rep0 = distance;
931
+ }
932
+ if (!len) {
933
+ len = $Decode(this$static.m_RepLenDecoder, this$static.m_RangeDecoder, posState) + 2;
934
+ this$static.state = this$static.state < 7 ? 8 : 11;
935
+ }
936
+ }
937
+ else {
938
+ this$static.rep3 = this$static.rep2;
939
+ this$static.rep2 = this$static.rep1;
940
+ this$static.rep1 = this$static.rep0;
941
+ len = 2
942
+ + $Decode(this$static.m_LenDecoder, this$static.m_RangeDecoder, posState);
943
+ this$static.state = this$static.state < 7 ? 7 : 10;
944
+ posSlot = $Decode_0(this$static.m_PosSlotDecoder[GetLenToPosState(len)], this$static.m_RangeDecoder);
945
+ if (posSlot >= 4) {
946
+ numDirectBits = (posSlot >> 1) - 1;
947
+ this$static.rep0 = (2 | posSlot & 1) << numDirectBits;
948
+ if (posSlot < 14) {
949
+ this$static.rep0 += ReverseDecode(this$static.m_PosDecoders, this$static.rep0 - posSlot - 1, this$static.m_RangeDecoder, numDirectBits);
950
+ }
951
+ else {
952
+ this$static.rep0 += $DecodeDirectBits(this$static.m_RangeDecoder, numDirectBits - 4) << 4;
953
+ this$static.rep0 += $ReverseDecode(this$static.m_PosAlignDecoder, this$static.m_RangeDecoder);
954
+ if (this$static.rep0 < 0) {
955
+ if (this$static.rep0 == -1) {
956
+ return 1;
957
+ }
958
+ return -1;
959
+ }
960
+ }
961
+ }
962
+ else {
963
+ this$static.rep0 = posSlot;
964
+ }
965
+ }
966
+ if (compare(fromInt(this$static.rep0), this$static.nowPos64) >= 0
967
+ || this$static.rep0 >= this$static.m_DictionarySizeCheck) {
968
+ return -1;
969
+ }
970
+ $CopyBlock(this$static.m_OutWindow, this$static.rep0, len);
971
+ this$static.nowPos64 = add(this$static.nowPos64, fromInt(len));
972
+ this$static.prevByte = $GetByte(this$static.m_OutWindow, 0);
973
+ }
974
+ return 0;
975
+ }
976
+ function $Decoder(this$static) {
977
+ this$static.m_OutWindow = {};
978
+ this$static.m_RangeDecoder = {};
979
+ this$static.m_IsMatchDecoders = initDim(192);
980
+ this$static.m_IsRepDecoders = initDim(12);
981
+ this$static.m_IsRepG0Decoders = initDim(12);
982
+ this$static.m_IsRepG1Decoders = initDim(12);
983
+ this$static.m_IsRepG2Decoders = initDim(12);
984
+ this$static.m_IsRep0LongDecoders = initDim(192);
985
+ this$static.m_PosSlotDecoder = initDim(4);
986
+ this$static.m_PosDecoders = initDim(114);
987
+ this$static.m_PosAlignDecoder = $BitTreeDecoder({}, 4);
988
+ this$static.m_LenDecoder = $Decoder$LenDecoder({});
989
+ this$static.m_RepLenDecoder = $Decoder$LenDecoder({});
990
+ this$static.m_LiteralDecoder = {};
991
+ for (var i = 0; i < 4; ++i) {
992
+ this$static.m_PosSlotDecoder[i] = $BitTreeDecoder({}, 6);
993
+ }
994
+ return this$static;
995
+ }
996
+ function $Init_1(this$static) {
997
+ this$static.m_OutWindow._streamPos = 0;
998
+ this$static.m_OutWindow._pos = 0;
999
+ InitBitModels(this$static.m_IsMatchDecoders);
1000
+ InitBitModels(this$static.m_IsRep0LongDecoders);
1001
+ InitBitModels(this$static.m_IsRepDecoders);
1002
+ InitBitModels(this$static.m_IsRepG0Decoders);
1003
+ InitBitModels(this$static.m_IsRepG1Decoders);
1004
+ InitBitModels(this$static.m_IsRepG2Decoders);
1005
+ InitBitModels(this$static.m_PosDecoders);
1006
+ $Init_0(this$static.m_LiteralDecoder);
1007
+ for (var i = 0; i < 4; ++i) {
1008
+ InitBitModels(this$static.m_PosSlotDecoder[i].Models);
1009
+ }
1010
+ $Init(this$static.m_LenDecoder);
1011
+ $Init(this$static.m_RepLenDecoder);
1012
+ InitBitModels(this$static.m_PosAlignDecoder.Models);
1013
+ $Init_8(this$static.m_RangeDecoder);
1014
+ }
1015
+ function $SetDecoderProperties(this$static, properties) {
1016
+ var dictionarySize, i, lc, lp, pb, remainder, val;
1017
+ if (properties.length < 5) {
1018
+ return 0;
1019
+ }
1020
+ val = properties[0] & 255;
1021
+ lc = val % 9;
1022
+ remainder = ~~(val / 9);
1023
+ lp = remainder % 5;
1024
+ pb = ~~(remainder / 5);
1025
+ dictionarySize = 0;
1026
+ for (i = 0; i < 4; ++i) {
1027
+ dictionarySize += (properties[1 + i] & 255) << i * 8;
1028
+ }
1029
+ /// NOTE: If the input is bad, it might call for an insanely large dictionary size, which would crash the script.
1030
+ if (dictionarySize > 99999999 || !$SetLcLpPb(this$static, lc, lp, pb)) {
1031
+ return 0;
1032
+ }
1033
+ return $SetDictionarySize(this$static, dictionarySize);
1034
+ }
1035
+ function $SetDictionarySize(this$static, dictionarySize) {
1036
+ if (dictionarySize < 0) {
1037
+ return 0;
1038
+ }
1039
+ if (this$static.m_DictionarySize != dictionarySize) {
1040
+ this$static.m_DictionarySize = dictionarySize;
1041
+ this$static.m_DictionarySizeCheck = Math.max(this$static.m_DictionarySize, 1);
1042
+ $Create_5(this$static.m_OutWindow, Math.max(this$static.m_DictionarySizeCheck, 4096));
1043
+ }
1044
+ return 1;
1045
+ }
1046
+ function $SetLcLpPb(this$static, lc, lp, pb) {
1047
+ if (lc > 8 || lp > 4 || pb > 4) {
1048
+ return 0;
1049
+ }
1050
+ $Create_0(this$static.m_LiteralDecoder, lp, lc);
1051
+ var numPosStates = 1 << pb;
1052
+ $Create(this$static.m_LenDecoder, numPosStates);
1053
+ $Create(this$static.m_RepLenDecoder, numPosStates);
1054
+ this$static.m_PosStateMask = numPosStates - 1;
1055
+ return 1;
1056
+ }
1057
+ function $Create(this$static, numPosStates) {
1058
+ for (; this$static.m_NumPosStates < numPosStates; this$static.m_NumPosStates += 1) {
1059
+ this$static.m_LowCoder[this$static.m_NumPosStates] = $BitTreeDecoder({}, 3);
1060
+ this$static.m_MidCoder[this$static.m_NumPosStates] = $BitTreeDecoder({}, 3);
1061
+ }
1062
+ }
1063
+ function $Decode(this$static, rangeDecoder, posState) {
1064
+ if (!$DecodeBit(rangeDecoder, this$static.m_Choice, 0)) {
1065
+ return $Decode_0(this$static.m_LowCoder[posState], rangeDecoder);
1066
+ }
1067
+ var symbol = 8;
1068
+ if (!$DecodeBit(rangeDecoder, this$static.m_Choice, 1)) {
1069
+ symbol += $Decode_0(this$static.m_MidCoder[posState], rangeDecoder);
1070
+ }
1071
+ else {
1072
+ symbol += 8 + $Decode_0(this$static.m_HighCoder, rangeDecoder);
1073
+ }
1074
+ return symbol;
1075
+ }
1076
+ function $Decoder$LenDecoder(this$static) {
1077
+ this$static.m_Choice = initDim(2);
1078
+ this$static.m_LowCoder = initDim(16);
1079
+ this$static.m_MidCoder = initDim(16);
1080
+ this$static.m_HighCoder = $BitTreeDecoder({}, 8);
1081
+ this$static.m_NumPosStates = 0;
1082
+ return this$static;
1083
+ }
1084
+ function $Init(this$static) {
1085
+ InitBitModels(this$static.m_Choice);
1086
+ for (var posState = 0; posState < this$static.m_NumPosStates; ++posState) {
1087
+ InitBitModels(this$static.m_LowCoder[posState].Models);
1088
+ InitBitModels(this$static.m_MidCoder[posState].Models);
1089
+ }
1090
+ InitBitModels(this$static.m_HighCoder.Models);
1091
+ }
1092
+ function $Create_0(this$static, numPosBits, numPrevBits) {
1093
+ var i, numStates;
1094
+ if (this$static.m_Coders != null && this$static.m_NumPrevBits == numPrevBits
1095
+ && this$static.m_NumPosBits == numPosBits) {
1096
+ return;
1097
+ }
1098
+ this$static.m_NumPosBits = numPosBits;
1099
+ this$static.m_PosMask = (1 << numPosBits) - 1;
1100
+ this$static.m_NumPrevBits = numPrevBits;
1101
+ numStates = 1 << this$static.m_NumPrevBits + this$static.m_NumPosBits;
1102
+ this$static.m_Coders = initDim(numStates);
1103
+ for (i = 0; i < numStates; ++i) {
1104
+ this$static.m_Coders[i] = $Decoder$LiteralDecoder$Decoder2({});
1105
+ }
1106
+ }
1107
+ function $GetDecoder(this$static, pos, prevByte) {
1108
+ return this$static
1109
+ .m_Coders[((pos & this$static.m_PosMask) << this$static.m_NumPrevBits)
1110
+ + ((prevByte & 255) >>> 8 - this$static.m_NumPrevBits)];
1111
+ }
1112
+ function $Init_0(this$static) {
1113
+ var i, numStates;
1114
+ numStates = 1 << this$static.m_NumPrevBits + this$static.m_NumPosBits;
1115
+ for (i = 0; i < numStates; ++i) {
1116
+ InitBitModels(this$static.m_Coders[i].m_Decoders);
1117
+ }
1118
+ }
1119
+ function $DecodeNormal(this$static, rangeDecoder) {
1120
+ var symbol = 1;
1121
+ do {
1122
+ symbol = symbol << 1
1123
+ | $DecodeBit(rangeDecoder, this$static.m_Decoders, symbol);
1124
+ } while (symbol < 256);
1125
+ return symbol << 24 >> 24;
1126
+ }
1127
+ function $DecodeWithMatchByte(this$static, rangeDecoder, matchByte) {
1128
+ var bit, matchBit, symbol = 1;
1129
+ do {
1130
+ matchBit = matchByte >> 7 & 1;
1131
+ matchByte <<= 1;
1132
+ bit = $DecodeBit(rangeDecoder, this$static.m_Decoders, (1 + matchBit << 8) + symbol);
1133
+ symbol = symbol << 1 | bit;
1134
+ if (matchBit != bit) {
1135
+ while (symbol < 256) {
1136
+ symbol = symbol << 1
1137
+ | $DecodeBit(rangeDecoder, this$static.m_Decoders, symbol);
1138
+ }
1139
+ break;
1140
+ }
1141
+ } while (symbol < 256);
1142
+ return symbol << 24 >> 24;
1143
+ }
1144
+ function $Decoder$LiteralDecoder$Decoder2(this$static) {
1145
+ this$static.m_Decoders = initDim(768);
1146
+ return this$static;
1147
+ }
1148
+ /** de */
1149
+ /** cs */
1150
+ const g_FastPos = function () {
1151
+ var j, k, slotFast, c = 2, g_FastPos = [0, 1];
1152
+ for (slotFast = 2; slotFast < 22; ++slotFast) {
1153
+ // k = 1 << (slotFast >> 1) - 1;
1154
+ var s = slotFast;
1155
+ s >>= 1;
1156
+ s -= 1;
1157
+ k = 1;
1158
+ k <<= s;
1159
+ for (j = 0; j < k; ++j, ++c) {
1160
+ g_FastPos[c] = slotFast << 24 >> 24;
1161
+ }
1162
+ }
1163
+ return g_FastPos;
1164
+ }();
1165
+ function $Backward(this$static, cur) {
1166
+ var backCur, backMem, posMem, posPrev;
1167
+ this$static._optimumEndIndex = cur;
1168
+ posMem = this$static._optimum[cur].PosPrev;
1169
+ backMem = this$static._optimum[cur].BackPrev;
1170
+ do {
1171
+ if (this$static._optimum[cur].Prev1IsChar) {
1172
+ $MakeAsChar(this$static._optimum[posMem]);
1173
+ this$static._optimum[posMem].PosPrev = posMem - 1;
1174
+ if (this$static._optimum[cur].Prev2) {
1175
+ this$static._optimum[posMem - 1].Prev1IsChar = 0;
1176
+ this$static._optimum[posMem - 1].PosPrev =
1177
+ this$static._optimum[cur].PosPrev2;
1178
+ this$static._optimum[posMem - 1].BackPrev =
1179
+ this$static._optimum[cur].BackPrev2;
1180
+ }
1181
+ }
1182
+ posPrev = posMem;
1183
+ backCur = backMem;
1184
+ backMem = this$static._optimum[posPrev].BackPrev;
1185
+ posMem = this$static._optimum[posPrev].PosPrev;
1186
+ this$static._optimum[posPrev].BackPrev = backCur;
1187
+ this$static._optimum[posPrev].PosPrev = cur;
1188
+ cur = posPrev;
1189
+ } while (cur > 0);
1190
+ this$static.backRes = this$static._optimum[0].BackPrev;
1191
+ this$static._optimumCurrentIndex = this$static._optimum[0].PosPrev;
1192
+ return this$static._optimumCurrentIndex;
1193
+ }
1194
+ function $BaseInit(this$static) {
1195
+ this$static._state = 0;
1196
+ this$static._previousByte = 0;
1197
+ for (var i = 0; i < 4; ++i) {
1198
+ this$static._repDistances[i] = 0;
1199
+ }
1200
+ }
1201
+ function $CodeOneBlock(this$static, inSize, outSize, finished) {
1202
+ var baseVal, complexState, curByte, distance, footerBits, i, len, lenToPosState, matchByte, pos, posReduced, posSlot, posState, progressPosValuePrev, subCoder;
1203
+ inSize[0] = P0_longLit;
1204
+ outSize[0] = P0_longLit;
1205
+ finished[0] = 1;
1206
+ if (this$static._inStream) {
1207
+ this$static._matchFinder._stream = this$static._inStream;
1208
+ $Init_5(this$static._matchFinder);
1209
+ this$static._needReleaseMFStream = 1;
1210
+ this$static._inStream = null;
1211
+ }
1212
+ if (this$static._finished) {
1213
+ return;
1214
+ }
1215
+ this$static._finished = 1;
1216
+ progressPosValuePrev = this$static.nowPos64;
1217
+ if (eq(this$static.nowPos64, P0_longLit)) {
1218
+ if (!$GetNumAvailableBytes(this$static._matchFinder)) {
1219
+ $Flush(this$static, lowBits_0(this$static.nowPos64));
1220
+ return;
1221
+ }
1222
+ $ReadMatchDistances(this$static);
1223
+ posState = lowBits_0(this$static.nowPos64) & this$static._posStateMask;
1224
+ $Encode_3(this$static._rangeEncoder, this$static._isMatch, (this$static._state << 4) + posState, 0);
1225
+ this$static._state = StateUpdateChar(this$static._state);
1226
+ curByte = $GetIndexByte(this$static._matchFinder, -this$static._additionalOffset);
1227
+ $Encode_1($GetSubCoder(this$static._literalEncoder, lowBits_0(this$static.nowPos64), this$static._previousByte), this$static._rangeEncoder, curByte);
1228
+ this$static._previousByte = curByte;
1229
+ this$static._additionalOffset -= 1;
1230
+ this$static.nowPos64 = add(this$static.nowPos64, P1_longLit);
1231
+ }
1232
+ if (!$GetNumAvailableBytes(this$static._matchFinder)) {
1233
+ $Flush(this$static, lowBits_0(this$static.nowPos64));
1234
+ return;
1235
+ }
1236
+ while (1) {
1237
+ len = $GetOptimum(this$static, lowBits_0(this$static.nowPos64));
1238
+ pos = this$static.backRes;
1239
+ posState = lowBits_0(this$static.nowPos64) & this$static._posStateMask;
1240
+ complexState = (this$static._state << 4) + posState;
1241
+ if (len == 1 && pos == -1) {
1242
+ $Encode_3(this$static._rangeEncoder, this$static._isMatch, complexState, 0);
1243
+ curByte = $GetIndexByte(this$static._matchFinder, -this$static._additionalOffset);
1244
+ subCoder = $GetSubCoder(this$static._literalEncoder, lowBits_0(this$static.nowPos64), this$static._previousByte);
1245
+ if (this$static._state < 7) {
1246
+ $Encode_1(subCoder, this$static._rangeEncoder, curByte);
1247
+ }
1248
+ else {
1249
+ matchByte = $GetIndexByte(this$static._matchFinder, -this$static._repDistances[0] - 1
1250
+ - this$static._additionalOffset);
1251
+ $EncodeMatched(subCoder, this$static._rangeEncoder, matchByte, curByte);
1252
+ }
1253
+ this$static._previousByte = curByte;
1254
+ this$static._state = StateUpdateChar(this$static._state);
1255
+ }
1256
+ else {
1257
+ $Encode_3(this$static._rangeEncoder, this$static._isMatch, complexState, 1);
1258
+ if (pos < 4) {
1259
+ $Encode_3(this$static._rangeEncoder, this$static._isRep, this$static._state, 1);
1260
+ if (!pos) {
1261
+ $Encode_3(this$static._rangeEncoder, this$static._isRepG0, this$static._state, 0);
1262
+ if (len == 1) {
1263
+ $Encode_3(this$static._rangeEncoder, this$static._isRep0Long, complexState, 0);
1264
+ }
1265
+ else {
1266
+ $Encode_3(this$static._rangeEncoder, this$static._isRep0Long, complexState, 1);
1267
+ }
1268
+ }
1269
+ else {
1270
+ $Encode_3(this$static._rangeEncoder, this$static._isRepG0, this$static._state, 1);
1271
+ if (pos == 1) {
1272
+ $Encode_3(this$static._rangeEncoder, this$static._isRepG1, this$static._state, 0);
1273
+ }
1274
+ else {
1275
+ $Encode_3(this$static._rangeEncoder, this$static._isRepG1, this$static._state, 1);
1276
+ $Encode_3(this$static._rangeEncoder, this$static._isRepG2, this$static._state, pos - 2);
1277
+ }
1278
+ }
1279
+ if (len == 1) {
1280
+ this$static._state = this$static._state < 7 ? 9 : 11;
1281
+ }
1282
+ else {
1283
+ $Encode_0(this$static._repMatchLenEncoder, this$static._rangeEncoder, len - 2, posState);
1284
+ this$static._state = this$static._state < 7 ? 8 : 11;
1285
+ }
1286
+ distance = this$static._repDistances[pos];
1287
+ if (pos != 0) {
1288
+ for (var i = pos; i >= 1; --i) {
1289
+ this$static._repDistances[i] =
1290
+ this$static._repDistances[i - 1];
1291
+ }
1292
+ this$static._repDistances[0] = distance;
1293
+ }
1294
+ }
1295
+ else {
1296
+ $Encode_3(this$static._rangeEncoder, this$static._isRep, this$static._state, 0);
1297
+ this$static._state = this$static._state < 7 ? 7 : 10;
1298
+ $Encode_0(this$static._lenEncoder, this$static._rangeEncoder, len - 2, posState);
1299
+ pos -= 4;
1300
+ posSlot = GetPosSlot(pos);
1301
+ lenToPosState = GetLenToPosState(len);
1302
+ $Encode_2(this$static._posSlotEncoder[lenToPosState], this$static._rangeEncoder, posSlot);
1303
+ if (posSlot >= 4) {
1304
+ footerBits = (posSlot >> 1) - 1;
1305
+ baseVal = (2 | posSlot & 1) << footerBits;
1306
+ posReduced = pos - baseVal;
1307
+ if (posSlot < 14) {
1308
+ ReverseEncode(this$static._posEncoders, baseVal - posSlot - 1, this$static._rangeEncoder, footerBits, posReduced);
1309
+ }
1310
+ else {
1311
+ $EncodeDirectBits(this$static._rangeEncoder, posReduced >> 4, footerBits - 4);
1312
+ $ReverseEncode(this$static._posAlignEncoder, this$static._rangeEncoder, posReduced & 15);
1313
+ this$static._alignPriceCount += 1;
1314
+ }
1315
+ }
1316
+ distance = pos;
1317
+ for (var i = 3; i >= 1; --i) {
1318
+ this$static._repDistances[i] =
1319
+ this$static._repDistances[i - 1];
1320
+ }
1321
+ this$static._repDistances[0] = distance;
1322
+ this$static._matchPriceCount += 1;
1323
+ }
1324
+ this$static._previousByte = $GetIndexByte(this$static._matchFinder, len - 1 - this$static._additionalOffset);
1325
+ }
1326
+ this$static._additionalOffset -= len;
1327
+ this$static.nowPos64 = add(this$static.nowPos64, fromInt(len));
1328
+ if (!this$static._additionalOffset) {
1329
+ if (this$static._matchPriceCount >= 128) {
1330
+ $FillDistancesPrices(this$static);
1331
+ }
1332
+ if (this$static._alignPriceCount >= 16) {
1333
+ $FillAlignPrices(this$static);
1334
+ }
1335
+ inSize[0] = this$static.nowPos64;
1336
+ outSize[0] = $GetProcessedSizeAdd(this$static._rangeEncoder);
1337
+ if (!$GetNumAvailableBytes(this$static._matchFinder)) {
1338
+ $Flush(this$static, lowBits_0(this$static.nowPos64));
1339
+ return;
1340
+ }
1341
+ if (compare(sub(this$static.nowPos64, progressPosValuePrev), [
1342
+ 4096,
1343
+ 0
1344
+ ]) >= 0) {
1345
+ this$static._finished = 0;
1346
+ finished[0] = 0;
1347
+ return;
1348
+ }
1349
+ }
1350
+ }
1351
+ }
1352
+ function $Create_2(this$static) {
1353
+ var bt, numHashBytes;
1354
+ if (!this$static._matchFinder) {
1355
+ bt = {};
1356
+ numHashBytes = 4;
1357
+ if (!this$static._matchFinderType) {
1358
+ numHashBytes = 2;
1359
+ }
1360
+ $SetType(bt, numHashBytes);
1361
+ this$static._matchFinder = bt;
1362
+ }
1363
+ $Create_1(this$static._literalEncoder, this$static._numLiteralPosStateBits, this$static._numLiteralContextBits);
1364
+ if (this$static._dictionarySize == this$static._dictionarySizePrev
1365
+ && this$static._numFastBytesPrev == this$static._numFastBytes) {
1366
+ return;
1367
+ }
1368
+ $Create_3(this$static._matchFinder, this$static._dictionarySize, 4096, this$static._numFastBytes, 274);
1369
+ this$static._dictionarySizePrev = this$static._dictionarySize;
1370
+ this$static._numFastBytesPrev = this$static._numFastBytes;
1371
+ }
1372
+ function $Encoder(this$static) {
1373
+ var i;
1374
+ this$static._repDistances = initDim(4);
1375
+ this$static._optimum = [];
1376
+ this$static._rangeEncoder = {};
1377
+ this$static._isMatch = initDim(192);
1378
+ this$static._isRep = initDim(12);
1379
+ this$static._isRepG0 = initDim(12);
1380
+ this$static._isRepG1 = initDim(12);
1381
+ this$static._isRepG2 = initDim(12);
1382
+ this$static._isRep0Long = initDim(192);
1383
+ this$static._posSlotEncoder = [];
1384
+ this$static._posEncoders = initDim(114);
1385
+ this$static._posAlignEncoder = $BitTreeEncoder({}, 4);
1386
+ this$static._lenEncoder = $Encoder$LenPriceTableEncoder({});
1387
+ this$static._repMatchLenEncoder = $Encoder$LenPriceTableEncoder({});
1388
+ this$static._literalEncoder = {};
1389
+ this$static._matchDistances = [];
1390
+ this$static._posSlotPrices = [];
1391
+ this$static._distancesPrices = [];
1392
+ this$static._alignPrices = initDim(16);
1393
+ this$static.reps = initDim(4);
1394
+ this$static.repLens = initDim(4);
1395
+ this$static.processedInSize = [P0_longLit];
1396
+ this$static.processedOutSize = [P0_longLit];
1397
+ this$static.finished = [0];
1398
+ this$static.properties = initDim(5);
1399
+ this$static.tempPrices = initDim(128);
1400
+ this$static._longestMatchLength = 0;
1401
+ this$static._matchFinderType = 1;
1402
+ this$static._numDistancePairs = 0;
1403
+ this$static._numFastBytesPrev = -1;
1404
+ this$static.backRes = 0;
1405
+ for (i = 0; i < 4096; ++i) {
1406
+ this$static._optimum[i] = {};
1407
+ }
1408
+ for (i = 0; i < 4; ++i) {
1409
+ this$static._posSlotEncoder[i] = $BitTreeEncoder({}, 6);
1410
+ }
1411
+ return this$static;
1412
+ }
1413
+ function $FillAlignPrices(this$static) {
1414
+ for (var i = 0; i < 16; ++i) {
1415
+ this$static._alignPrices[i] = $ReverseGetPrice(this$static._posAlignEncoder, i);
1416
+ }
1417
+ this$static._alignPriceCount = 0;
1418
+ }
1419
+ function $FillDistancesPrices(this$static) {
1420
+ var baseVal, encoder, footerBits, i, lenToPosState, posSlot, st, st2;
1421
+ for (i = 4; i < 128; ++i) {
1422
+ posSlot = GetPosSlot(i);
1423
+ footerBits = (posSlot >> 1) - 1;
1424
+ baseVal = (2 | posSlot & 1) << footerBits;
1425
+ this$static.tempPrices[i] = ReverseGetPrice(this$static._posEncoders, baseVal - posSlot - 1, footerBits, i - baseVal);
1426
+ }
1427
+ for (lenToPosState = 0; lenToPosState < 4; ++lenToPosState) {
1428
+ encoder = this$static._posSlotEncoder[lenToPosState];
1429
+ st = lenToPosState << 6;
1430
+ for (posSlot = 0; posSlot < this$static._distTableSize; posSlot += 1) {
1431
+ this$static._posSlotPrices[st + posSlot] = $GetPrice_1(encoder, posSlot);
1432
+ }
1433
+ for (posSlot = 14; posSlot < this$static._distTableSize; posSlot += 1) {
1434
+ this$static._posSlotPrices[st + posSlot] += (posSlot >> 1) - 1 - 4
1435
+ << 6;
1436
+ }
1437
+ st2 = lenToPosState * 128;
1438
+ for (i = 0; i < 4; ++i) {
1439
+ this$static._distancesPrices[st2 + i] =
1440
+ this$static._posSlotPrices[st + i];
1441
+ }
1442
+ for (; i < 128; ++i) {
1443
+ this$static._distancesPrices[st2 + i] =
1444
+ this$static._posSlotPrices[st + GetPosSlot(i)]
1445
+ + this$static.tempPrices[i];
1446
+ }
1447
+ }
1448
+ this$static._matchPriceCount = 0;
1449
+ }
1450
+ function $Flush(this$static, nowPos) {
1451
+ $ReleaseMFStream(this$static);
1452
+ $WriteEndMarker(this$static, nowPos & this$static._posStateMask);
1453
+ for (var i = 0; i < 5; ++i) {
1454
+ $ShiftLow(this$static._rangeEncoder);
1455
+ }
1456
+ }
1457
+ function $GetOptimum(this$static, position) {
1458
+ var cur, curAnd1Price, curAndLenCharPrice, curAndLenPrice, curBack, curPrice, currentByte, distance, i, len, lenEnd, lenMain, lenRes, lenTest, lenTest2, lenTestTemp, matchByte, matchPrice, newLen, nextIsChar, nextMatchPrice, nextOptimum, nextRepMatchPrice, normalMatchPrice, numAvailableBytes, numAvailableBytesFull, numDistancePairs, offs, offset, opt, optimum, pos, posPrev, posState, posStateNext, price_4, repIndex, repLen, repMatchPrice, repMaxIndex, shortRepPrice, startLen, state, state2, t, price, price_0, price_1, price_2, price_3;
1459
+ if (this$static._optimumEndIndex != this$static._optimumCurrentIndex) {
1460
+ lenRes = this$static._optimum[this$static._optimumCurrentIndex].PosPrev
1461
+ - this$static._optimumCurrentIndex;
1462
+ this$static.backRes =
1463
+ this$static._optimum[this$static._optimumCurrentIndex].BackPrev;
1464
+ this$static._optimumCurrentIndex =
1465
+ this$static._optimum[this$static._optimumCurrentIndex].PosPrev;
1466
+ return lenRes;
1467
+ }
1468
+ this$static._optimumCurrentIndex = this$static._optimumEndIndex = 0;
1469
+ if (this$static._longestMatchWasFound) {
1470
+ lenMain = this$static._longestMatchLength;
1471
+ this$static._longestMatchWasFound = 0;
1472
+ }
1473
+ else {
1474
+ lenMain = $ReadMatchDistances(this$static);
1475
+ }
1476
+ numDistancePairs = this$static._numDistancePairs;
1477
+ numAvailableBytes = $GetNumAvailableBytes(this$static._matchFinder) + 1;
1478
+ if (numAvailableBytes < 2) {
1479
+ this$static.backRes = -1;
1480
+ return 1;
1481
+ }
1482
+ if (numAvailableBytes > 273) {
1483
+ numAvailableBytes = 273;
1484
+ }
1485
+ repMaxIndex = 0;
1486
+ for (i = 0; i < 4; ++i) {
1487
+ this$static.reps[i] = this$static._repDistances[i];
1488
+ this$static.repLens[i] = $GetMatchLen(this$static._matchFinder, -1, this$static.reps[i], 273);
1489
+ if (this$static.repLens[i] > this$static.repLens[repMaxIndex]) {
1490
+ repMaxIndex = i;
1491
+ }
1492
+ }
1493
+ if (this$static.repLens[repMaxIndex] >= this$static._numFastBytes) {
1494
+ this$static.backRes = repMaxIndex;
1495
+ lenRes = this$static.repLens[repMaxIndex];
1496
+ $MovePos(this$static, lenRes - 1);
1497
+ return lenRes;
1498
+ }
1499
+ if (lenMain >= this$static._numFastBytes) {
1500
+ this$static.backRes = this$static._matchDistances[numDistancePairs - 1]
1501
+ + 4;
1502
+ $MovePos(this$static, lenMain - 1);
1503
+ return lenMain;
1504
+ }
1505
+ currentByte = $GetIndexByte(this$static._matchFinder, -1);
1506
+ matchByte = $GetIndexByte(this$static._matchFinder, -this$static._repDistances[0] - 1 - 1);
1507
+ if (lenMain < 2 && currentByte != matchByte
1508
+ && this$static.repLens[repMaxIndex] < 2) {
1509
+ this$static.backRes = -1;
1510
+ return 1;
1511
+ }
1512
+ this$static._optimum[0].State = this$static._state;
1513
+ posState = position & this$static._posStateMask;
1514
+ this$static._optimum[1].Price = ProbPrices[this$static._isMatch[(this$static._state << 4) + posState] >>> 2]
1515
+ + $GetPrice_0($GetSubCoder(this$static._literalEncoder, position, this$static._previousByte), this$static._state >= 7, matchByte, currentByte);
1516
+ $MakeAsChar(this$static._optimum[1]);
1517
+ matchPrice = ProbPrices[2048 - this$static._isMatch[(this$static._state << 4) + posState]
1518
+ >>> 2];
1519
+ repMatchPrice = matchPrice
1520
+ + ProbPrices[2048 - this$static._isRep[this$static._state] >>> 2];
1521
+ if (matchByte == currentByte) {
1522
+ shortRepPrice = repMatchPrice
1523
+ + $GetRepLen1Price(this$static, this$static._state, posState);
1524
+ if (shortRepPrice < this$static._optimum[1].Price) {
1525
+ this$static._optimum[1].Price = shortRepPrice;
1526
+ $MakeAsShortRep(this$static._optimum[1]);
1527
+ }
1528
+ }
1529
+ lenEnd = lenMain >= this$static.repLens[repMaxIndex]
1530
+ ? lenMain
1531
+ : this$static.repLens[repMaxIndex];
1532
+ if (lenEnd < 2) {
1533
+ this$static.backRes = this$static._optimum[1].BackPrev;
1534
+ return 1;
1535
+ }
1536
+ this$static._optimum[1].PosPrev = 0;
1537
+ this$static._optimum[0].Backs0 = this$static.reps[0];
1538
+ this$static._optimum[0].Backs1 = this$static.reps[1];
1539
+ this$static._optimum[0].Backs2 = this$static.reps[2];
1540
+ this$static._optimum[0].Backs3 = this$static.reps[3];
1541
+ len = lenEnd;
1542
+ do {
1543
+ this$static._optimum[len].Price = 268435455;
1544
+ len -= 1;
1545
+ } while (len >= 2);
1546
+ for (i = 0; i < 4; ++i) {
1547
+ repLen = this$static.repLens[i];
1548
+ if (repLen < 2) {
1549
+ continue;
1550
+ }
1551
+ price_4 = repMatchPrice
1552
+ + $GetPureRepPrice(this$static, i, this$static._state, posState);
1553
+ do {
1554
+ curAndLenPrice = price_4
1555
+ + $GetPrice(this$static._repMatchLenEncoder, repLen - 2, posState);
1556
+ optimum = this$static._optimum[repLen];
1557
+ if (curAndLenPrice < optimum.Price) {
1558
+ optimum.Price = curAndLenPrice;
1559
+ optimum.PosPrev = 0;
1560
+ optimum.BackPrev = i;
1561
+ optimum.Prev1IsChar = 0;
1562
+ }
1563
+ } while ((repLen -= 1) >= 2);
1564
+ }
1565
+ normalMatchPrice = matchPrice
1566
+ + ProbPrices[this$static._isRep[this$static._state] >>> 2];
1567
+ len = this$static.repLens[0] >= 2 ? this$static.repLens[0] + 1 : 2;
1568
+ if (len <= lenMain) {
1569
+ offs = 0;
1570
+ while (len > this$static._matchDistances[offs]) {
1571
+ offs += 2;
1572
+ }
1573
+ for (;; len += 1) {
1574
+ distance = this$static._matchDistances[offs + 1];
1575
+ curAndLenPrice = normalMatchPrice
1576
+ + $GetPosLenPrice(this$static, distance, len, posState);
1577
+ optimum = this$static._optimum[len];
1578
+ if (curAndLenPrice < optimum.Price) {
1579
+ optimum.Price = curAndLenPrice;
1580
+ optimum.PosPrev = 0;
1581
+ optimum.BackPrev = distance + 4;
1582
+ optimum.Prev1IsChar = 0;
1583
+ }
1584
+ if (len == this$static._matchDistances[offs]) {
1585
+ offs += 2;
1586
+ if (offs == numDistancePairs) {
1587
+ break;
1588
+ }
1589
+ }
1590
+ }
1591
+ }
1592
+ cur = 0;
1593
+ while (1) {
1594
+ ;
1595
+ ++cur;
1596
+ if (cur == lenEnd) {
1597
+ return $Backward(this$static, cur);
1598
+ }
1599
+ newLen = $ReadMatchDistances(this$static);
1600
+ numDistancePairs = this$static._numDistancePairs;
1601
+ if (newLen >= this$static._numFastBytes) {
1602
+ this$static._longestMatchLength = newLen;
1603
+ this$static._longestMatchWasFound = 1;
1604
+ return $Backward(this$static, cur);
1605
+ }
1606
+ position += 1;
1607
+ posPrev = this$static._optimum[cur].PosPrev;
1608
+ if (this$static._optimum[cur].Prev1IsChar) {
1609
+ posPrev -= 1;
1610
+ if (this$static._optimum[cur].Prev2) {
1611
+ state = this$static._optimum[this$static._optimum[cur].PosPrev2]
1612
+ .State;
1613
+ if (this$static._optimum[cur].BackPrev2 < 4) {
1614
+ state = (state < 7) ? 8 : 11;
1615
+ }
1616
+ else {
1617
+ state = (state < 7) ? 7 : 10;
1618
+ }
1619
+ }
1620
+ else {
1621
+ state = this$static._optimum[posPrev].State;
1622
+ }
1623
+ state = StateUpdateChar(state);
1624
+ }
1625
+ else {
1626
+ state = this$static._optimum[posPrev].State;
1627
+ }
1628
+ if (posPrev == cur - 1) {
1629
+ if (!this$static._optimum[cur].BackPrev) {
1630
+ state = state < 7 ? 9 : 11;
1631
+ }
1632
+ else {
1633
+ state = StateUpdateChar(state);
1634
+ }
1635
+ }
1636
+ else {
1637
+ if (this$static._optimum[cur].Prev1IsChar
1638
+ && this$static._optimum[cur].Prev2) {
1639
+ posPrev = this$static._optimum[cur].PosPrev2;
1640
+ pos = this$static._optimum[cur].BackPrev2;
1641
+ state = state < 7 ? 8 : 11;
1642
+ }
1643
+ else {
1644
+ pos = this$static._optimum[cur].BackPrev;
1645
+ if (pos < 4) {
1646
+ state = state < 7 ? 8 : 11;
1647
+ }
1648
+ else {
1649
+ state = state < 7 ? 7 : 10;
1650
+ }
1651
+ }
1652
+ opt = this$static._optimum[posPrev];
1653
+ if (pos < 4) {
1654
+ if (!pos) {
1655
+ this$static.reps[0] = opt.Backs0;
1656
+ this$static.reps[1] = opt.Backs1;
1657
+ this$static.reps[2] = opt.Backs2;
1658
+ this$static.reps[3] = opt.Backs3;
1659
+ }
1660
+ else if (pos == 1) {
1661
+ this$static.reps[0] = opt.Backs1;
1662
+ this$static.reps[1] = opt.Backs0;
1663
+ this$static.reps[2] = opt.Backs2;
1664
+ this$static.reps[3] = opt.Backs3;
1665
+ }
1666
+ else if (pos == 2) {
1667
+ this$static.reps[0] = opt.Backs2;
1668
+ this$static.reps[1] = opt.Backs0;
1669
+ this$static.reps[2] = opt.Backs1;
1670
+ this$static.reps[3] = opt.Backs3;
1671
+ }
1672
+ else {
1673
+ this$static.reps[0] = opt.Backs3;
1674
+ this$static.reps[1] = opt.Backs0;
1675
+ this$static.reps[2] = opt.Backs1;
1676
+ this$static.reps[3] = opt.Backs2;
1677
+ }
1678
+ }
1679
+ else {
1680
+ this$static.reps[0] = pos - 4;
1681
+ this$static.reps[1] = opt.Backs0;
1682
+ this$static.reps[2] = opt.Backs1;
1683
+ this$static.reps[3] = opt.Backs2;
1684
+ }
1685
+ }
1686
+ this$static._optimum[cur].State = state;
1687
+ this$static._optimum[cur].Backs0 = this$static.reps[0];
1688
+ this$static._optimum[cur].Backs1 = this$static.reps[1];
1689
+ this$static._optimum[cur].Backs2 = this$static.reps[2];
1690
+ this$static._optimum[cur].Backs3 = this$static.reps[3];
1691
+ curPrice = this$static._optimum[cur].Price;
1692
+ currentByte = $GetIndexByte(this$static._matchFinder, -1);
1693
+ matchByte = $GetIndexByte(this$static._matchFinder, -this$static.reps[0] - 1 - 1);
1694
+ posState = position & this$static._posStateMask;
1695
+ curAnd1Price = curPrice
1696
+ + ProbPrices[this$static._isMatch[(state << 4) + posState] >>> 2]
1697
+ + $GetPrice_0($GetSubCoder(this$static._literalEncoder, position, $GetIndexByte(this$static._matchFinder, -2)), state >= 7, matchByte, currentByte);
1698
+ nextOptimum = this$static._optimum[cur + 1];
1699
+ nextIsChar = 0;
1700
+ if (curAnd1Price < nextOptimum.Price) {
1701
+ nextOptimum.Price = curAnd1Price;
1702
+ nextOptimum.PosPrev = cur;
1703
+ nextOptimum.BackPrev = -1;
1704
+ nextOptimum.Prev1IsChar = 0;
1705
+ nextIsChar = 1;
1706
+ }
1707
+ matchPrice = curPrice
1708
+ + ProbPrices[2048 - this$static._isMatch[(state << 4) + posState] >>> 2];
1709
+ repMatchPrice = matchPrice
1710
+ + ProbPrices[2048 - this$static._isRep[state] >>> 2];
1711
+ if (matchByte == currentByte
1712
+ && !(nextOptimum.PosPrev < cur && !nextOptimum.BackPrev)) {
1713
+ shortRepPrice = repMatchPrice
1714
+ + (ProbPrices[this$static._isRepG0[state] >>> 2]
1715
+ + ProbPrices[this$static._isRep0Long[(state << 4) + posState] >>> 2]);
1716
+ if (shortRepPrice <= nextOptimum.Price) {
1717
+ nextOptimum.Price = shortRepPrice;
1718
+ nextOptimum.PosPrev = cur;
1719
+ nextOptimum.BackPrev = 0;
1720
+ nextOptimum.Prev1IsChar = 0;
1721
+ nextIsChar = 1;
1722
+ }
1723
+ }
1724
+ numAvailableBytesFull = $GetNumAvailableBytes(this$static._matchFinder)
1725
+ + 1;
1726
+ numAvailableBytesFull = 4095 - cur < numAvailableBytesFull
1727
+ ? 4095 - cur
1728
+ : numAvailableBytesFull;
1729
+ numAvailableBytes = numAvailableBytesFull;
1730
+ if (numAvailableBytes < 2) {
1731
+ continue;
1732
+ }
1733
+ if (numAvailableBytes > this$static._numFastBytes) {
1734
+ numAvailableBytes = this$static._numFastBytes;
1735
+ }
1736
+ if (!nextIsChar && matchByte != currentByte) {
1737
+ t = Math.min(numAvailableBytesFull - 1, this$static._numFastBytes);
1738
+ lenTest2 = $GetMatchLen(this$static._matchFinder, 0, this$static.reps[0], t);
1739
+ if (lenTest2 >= 2) {
1740
+ state2 = StateUpdateChar(state);
1741
+ posStateNext = position + 1 & this$static._posStateMask;
1742
+ nextRepMatchPrice = curAnd1Price
1743
+ + ProbPrices[2048
1744
+ - this$static._isMatch[(state2 << 4) + posStateNext]
1745
+ >>> 2] + ProbPrices[2048 - this$static._isRep[state2] >>> 2];
1746
+ offset = cur + 1 + lenTest2;
1747
+ while (lenEnd < offset) {
1748
+ this$static._optimum[lenEnd += 1].Price = 268435455;
1749
+ }
1750
+ curAndLenPrice = nextRepMatchPrice
1751
+ + (price = $GetPrice(this$static._repMatchLenEncoder, lenTest2 - 2, posStateNext),
1752
+ price
1753
+ + $GetPureRepPrice(this$static, 0, state2, posStateNext));
1754
+ optimum = this$static._optimum[offset];
1755
+ if (curAndLenPrice < optimum.Price) {
1756
+ optimum.Price = curAndLenPrice;
1757
+ optimum.PosPrev = cur + 1;
1758
+ optimum.BackPrev = 0;
1759
+ optimum.Prev1IsChar = 1;
1760
+ optimum.Prev2 = 0;
1761
+ }
1762
+ }
1763
+ }
1764
+ startLen = 2;
1765
+ for (repIndex = 0; repIndex < 4; ++repIndex) {
1766
+ lenTest = $GetMatchLen(this$static._matchFinder, -1, this$static.reps[repIndex], numAvailableBytes);
1767
+ if (lenTest < 2) {
1768
+ continue;
1769
+ }
1770
+ lenTestTemp = lenTest;
1771
+ do {
1772
+ while (lenEnd < cur + lenTest) {
1773
+ this$static._optimum[lenEnd += 1].Price = 268435455;
1774
+ }
1775
+ curAndLenPrice = repMatchPrice
1776
+ + (price_0 = $GetPrice(this$static._repMatchLenEncoder, lenTest - 2, posState),
1777
+ price_0
1778
+ + $GetPureRepPrice(this$static, repIndex, state, posState));
1779
+ optimum = this$static._optimum[cur + lenTest];
1780
+ if (curAndLenPrice < optimum.Price) {
1781
+ optimum.Price = curAndLenPrice;
1782
+ optimum.PosPrev = cur;
1783
+ optimum.BackPrev = repIndex;
1784
+ optimum.Prev1IsChar = 0;
1785
+ }
1786
+ } while ((lenTest -= 1) >= 2);
1787
+ lenTest = lenTestTemp;
1788
+ if (!repIndex) {
1789
+ startLen = lenTest + 1;
1790
+ }
1791
+ if (lenTest < numAvailableBytesFull) {
1792
+ t = Math.min(numAvailableBytesFull - 1 - lenTest, this$static._numFastBytes);
1793
+ lenTest2 = $GetMatchLen(this$static._matchFinder, lenTest, this$static.reps[repIndex], t);
1794
+ if (lenTest2 >= 2) {
1795
+ state2 = state < 7 ? 8 : 11;
1796
+ posStateNext = position + lenTest
1797
+ & this$static._posStateMask;
1798
+ curAndLenCharPrice = repMatchPrice
1799
+ + (price_1 = $GetPrice(this$static._repMatchLenEncoder, lenTest - 2, posState),
1800
+ price_1
1801
+ + $GetPureRepPrice(this$static, repIndex, state, posState))
1802
+ + ProbPrices[this$static._isMatch[(state2 << 4) + posStateNext]
1803
+ >>> 2]
1804
+ + $GetPrice_0($GetSubCoder(this$static._literalEncoder, position + lenTest, $GetIndexByte(this$static._matchFinder, lenTest - 1 - 1)), 1, $GetIndexByte(this$static._matchFinder, lenTest - 1 - (this$static.reps[repIndex] + 1)), $GetIndexByte(this$static._matchFinder, lenTest - 1));
1805
+ state2 = StateUpdateChar(state2);
1806
+ posStateNext = position + lenTest + 1
1807
+ & this$static._posStateMask;
1808
+ nextMatchPrice = curAndLenCharPrice
1809
+ + ProbPrices[2048
1810
+ - this$static
1811
+ ._isMatch[(state2 << 4) + posStateNext]
1812
+ >>> 2];
1813
+ nextRepMatchPrice = nextMatchPrice
1814
+ + ProbPrices[2048 - this$static._isRep[state2] >>> 2];
1815
+ offset = lenTest + 1 + lenTest2;
1816
+ while (lenEnd < cur + offset) {
1817
+ this$static._optimum[lenEnd += 1].Price = 268435455;
1818
+ }
1819
+ curAndLenPrice = nextRepMatchPrice
1820
+ + (price_2 = $GetPrice(this$static._repMatchLenEncoder, lenTest2 - 2, posStateNext),
1821
+ price_2
1822
+ + $GetPureRepPrice(this$static, 0, state2, posStateNext));
1823
+ optimum = this$static._optimum[cur + offset];
1824
+ if (curAndLenPrice < optimum.Price) {
1825
+ optimum.Price = curAndLenPrice;
1826
+ optimum.PosPrev = cur + lenTest + 1;
1827
+ optimum.BackPrev = 0;
1828
+ optimum.Prev1IsChar = 1;
1829
+ optimum.Prev2 = 1;
1830
+ optimum.PosPrev2 = cur;
1831
+ optimum.BackPrev2 = repIndex;
1832
+ }
1833
+ }
1834
+ }
1835
+ }
1836
+ if (newLen > numAvailableBytes) {
1837
+ newLen = numAvailableBytes;
1838
+ for (numDistancePairs = 0; newLen > this$static._matchDistances[numDistancePairs]; numDistancePairs += 2) { }
1839
+ this$static._matchDistances[numDistancePairs] = newLen;
1840
+ numDistancePairs += 2;
1841
+ }
1842
+ if (newLen >= startLen) {
1843
+ normalMatchPrice = matchPrice
1844
+ + ProbPrices[this$static._isRep[state] >>> 2];
1845
+ while (lenEnd < cur + newLen) {
1846
+ this$static._optimum[lenEnd += 1].Price = 268435455;
1847
+ }
1848
+ offs = 0;
1849
+ while (startLen > this$static._matchDistances[offs]) {
1850
+ offs += 2;
1851
+ }
1852
+ for (lenTest = startLen;; lenTest += 1) {
1853
+ curBack = this$static._matchDistances[offs + 1];
1854
+ curAndLenPrice = normalMatchPrice
1855
+ + $GetPosLenPrice(this$static, curBack, lenTest, posState);
1856
+ optimum = this$static._optimum[cur + lenTest];
1857
+ if (curAndLenPrice < optimum.Price) {
1858
+ optimum.Price = curAndLenPrice;
1859
+ optimum.PosPrev = cur;
1860
+ optimum.BackPrev = curBack + 4;
1861
+ optimum.Prev1IsChar = 0;
1862
+ }
1863
+ if (lenTest == this$static._matchDistances[offs]) {
1864
+ if (lenTest < numAvailableBytesFull) {
1865
+ t = Math.min(numAvailableBytesFull - 1 - lenTest, this$static._numFastBytes);
1866
+ lenTest2 = $GetMatchLen(this$static._matchFinder, lenTest, curBack, t);
1867
+ if (lenTest2 >= 2) {
1868
+ state2 = state < 7 ? 7 : 10;
1869
+ posStateNext = position + lenTest
1870
+ & this$static._posStateMask;
1871
+ curAndLenCharPrice = curAndLenPrice
1872
+ + ProbPrices[this$static
1873
+ ._isMatch[(state2 << 4) + posStateNext]
1874
+ >>> 2]
1875
+ + $GetPrice_0($GetSubCoder(this$static._literalEncoder, position + lenTest, $GetIndexByte(this$static._matchFinder, lenTest - 1 - 1)), 1, $GetIndexByte(this$static._matchFinder, lenTest - (curBack + 1) - 1), $GetIndexByte(this$static._matchFinder, lenTest - 1));
1876
+ state2 = StateUpdateChar(state2);
1877
+ posStateNext = position + lenTest + 1
1878
+ & this$static._posStateMask;
1879
+ nextMatchPrice = curAndLenCharPrice
1880
+ + ProbPrices[2048
1881
+ - this$static
1882
+ ._isMatch[(state2 << 4) + posStateNext] >>> 2];
1883
+ nextRepMatchPrice = nextMatchPrice
1884
+ + ProbPrices[2048 - this$static._isRep[state2] >>> 2];
1885
+ offset = lenTest + 1 + lenTest2;
1886
+ while (lenEnd < cur + offset) {
1887
+ this$static._optimum[lenEnd += 1].Price =
1888
+ 268435455;
1889
+ }
1890
+ curAndLenPrice = nextRepMatchPrice
1891
+ + (price_3 = $GetPrice(this$static._repMatchLenEncoder, lenTest2 - 2, posStateNext),
1892
+ price_3
1893
+ + $GetPureRepPrice(this$static, 0, state2, posStateNext));
1894
+ optimum = this$static._optimum[cur + offset];
1895
+ if (curAndLenPrice < optimum.Price) {
1896
+ optimum.Price = curAndLenPrice;
1897
+ optimum.PosPrev = cur + lenTest + 1;
1898
+ optimum.BackPrev = 0;
1899
+ optimum.Prev1IsChar = 1;
1900
+ optimum.Prev2 = 1;
1901
+ optimum.PosPrev2 = cur;
1902
+ optimum.BackPrev2 = curBack + 4;
1903
+ }
1904
+ }
1905
+ }
1906
+ offs += 2;
1907
+ if (offs == numDistancePairs) {
1908
+ break;
1909
+ }
1910
+ }
1911
+ }
1912
+ }
1913
+ }
1914
+ }
1915
+ function $GetPosLenPrice(this$static, pos, len, posState) {
1916
+ var price, lenToPosState = GetLenToPosState(len);
1917
+ if (pos < 128) {
1918
+ price = this$static._distancesPrices[lenToPosState * 128 + pos];
1919
+ }
1920
+ else {
1921
+ price =
1922
+ this$static._posSlotPrices[(lenToPosState << 6) + GetPosSlot2(pos)]
1923
+ + this$static._alignPrices[pos & 15];
1924
+ }
1925
+ return price + $GetPrice(this$static._lenEncoder, len - 2, posState);
1926
+ }
1927
+ function $GetPureRepPrice(this$static, repIndex, state, posState) {
1928
+ var price;
1929
+ if (!repIndex) {
1930
+ price = ProbPrices[this$static._isRepG0[state] >>> 2];
1931
+ price += ProbPrices[2048 - this$static._isRep0Long[(state << 4) + posState] >>> 2];
1932
+ }
1933
+ else {
1934
+ price = ProbPrices[2048 - this$static._isRepG0[state] >>> 2];
1935
+ if (repIndex == 1) {
1936
+ price += ProbPrices[this$static._isRepG1[state] >>> 2];
1937
+ }
1938
+ else {
1939
+ price += ProbPrices[2048 - this$static._isRepG1[state] >>> 2];
1940
+ price += GetPrice(this$static._isRepG2[state], repIndex - 2);
1941
+ }
1942
+ }
1943
+ return price;
1944
+ }
1945
+ function $GetRepLen1Price(this$static, state, posState) {
1946
+ return ProbPrices[this$static._isRepG0[state] >>> 2]
1947
+ + ProbPrices[this$static._isRep0Long[(state << 4) + posState] >>> 2];
1948
+ }
1949
+ function $Init_4(this$static) {
1950
+ $BaseInit(this$static);
1951
+ $Init_9(this$static._rangeEncoder);
1952
+ InitBitModels(this$static._isMatch);
1953
+ InitBitModels(this$static._isRep0Long);
1954
+ InitBitModels(this$static._isRep);
1955
+ InitBitModels(this$static._isRepG0);
1956
+ InitBitModels(this$static._isRepG1);
1957
+ InitBitModels(this$static._isRepG2);
1958
+ InitBitModels(this$static._posEncoders);
1959
+ $Init_3(this$static._literalEncoder);
1960
+ for (var i = 0; i < 4; ++i) {
1961
+ InitBitModels(this$static._posSlotEncoder[i].Models);
1962
+ }
1963
+ $Init_2(this$static._lenEncoder, 1 << this$static._posStateBits);
1964
+ $Init_2(this$static._repMatchLenEncoder, 1 << this$static._posStateBits);
1965
+ InitBitModels(this$static._posAlignEncoder.Models);
1966
+ this$static._longestMatchWasFound = 0;
1967
+ this$static._optimumEndIndex = 0;
1968
+ this$static._optimumCurrentIndex = 0;
1969
+ this$static._additionalOffset = 0;
1970
+ }
1971
+ function $MovePos(this$static, num) {
1972
+ if (num > 0) {
1973
+ $Skip(this$static._matchFinder, num);
1974
+ this$static._additionalOffset += num;
1975
+ }
1976
+ }
1977
+ function $ReadMatchDistances(this$static) {
1978
+ var lenRes = 0;
1979
+ this$static._numDistancePairs = $GetMatches(this$static._matchFinder, this$static._matchDistances);
1980
+ if (this$static._numDistancePairs > 0) {
1981
+ lenRes = this$static._matchDistances[this$static._numDistancePairs - 2];
1982
+ if (lenRes == this$static._numFastBytes) {
1983
+ lenRes += $GetMatchLen(this$static._matchFinder, lenRes - 1, this$static._matchDistances[this$static._numDistancePairs - 1], 273 - lenRes);
1984
+ }
1985
+ }
1986
+ this$static._additionalOffset += 1;
1987
+ return lenRes;
1988
+ }
1989
+ function $ReleaseMFStream(this$static) {
1990
+ if (this$static._matchFinder && this$static._needReleaseMFStream) {
1991
+ this$static._matchFinder._stream = null;
1992
+ this$static._needReleaseMFStream = 0;
1993
+ }
1994
+ }
1995
+ function $ReleaseStreams(this$static) {
1996
+ $ReleaseMFStream(this$static);
1997
+ this$static._rangeEncoder.Stream = null;
1998
+ }
1999
+ function $SetDictionarySize_0(this$static, dictionarySize) {
2000
+ this$static._dictionarySize = dictionarySize;
2001
+ for (var dicLogSize = 0; dictionarySize > 1 << dicLogSize; ++dicLogSize) { }
2002
+ this$static._distTableSize = dicLogSize * 2;
2003
+ }
2004
+ function $SetMatchFinder(this$static, matchFinderIndex) {
2005
+ var matchFinderIndexPrev = this$static._matchFinderType;
2006
+ this$static._matchFinderType = matchFinderIndex;
2007
+ if (this$static._matchFinder
2008
+ && matchFinderIndexPrev != this$static._matchFinderType) {
2009
+ this$static._dictionarySizePrev = -1;
2010
+ this$static._matchFinder = null;
2011
+ }
2012
+ }
2013
+ function $WriteCoderProperties(this$static, outStream) {
2014
+ this$static.properties[0] =
2015
+ (this$static._posStateBits * 5 + this$static._numLiteralPosStateBits)
2016
+ * 9 + this$static._numLiteralContextBits << 24 >> 24;
2017
+ for (var i = 0; i < 4; ++i) {
2018
+ this$static.properties[1 + i] =
2019
+ this$static._dictionarySize >> 8 * i << 24 >> 24;
2020
+ }
2021
+ $write_0(outStream, this$static.properties, 0, 5);
2022
+ }
2023
+ function $WriteEndMarker(this$static, posState) {
2024
+ // if (!this$static._writeEndMark) {
2025
+ // return;
2026
+ // }
2027
+ $Encode_3(this$static._rangeEncoder, this$static._isMatch, (this$static._state << 4) + posState, 1);
2028
+ $Encode_3(this$static._rangeEncoder, this$static._isRep, this$static._state, 0);
2029
+ this$static._state = this$static._state < 7 ? 7 : 10;
2030
+ $Encode_0(this$static._lenEncoder, this$static._rangeEncoder, 0, posState);
2031
+ var lenToPosState = GetLenToPosState(2);
2032
+ $Encode_2(this$static._posSlotEncoder[lenToPosState], this$static._rangeEncoder, 63);
2033
+ $EncodeDirectBits(this$static._rangeEncoder, 67108863, 26);
2034
+ $ReverseEncode(this$static._posAlignEncoder, this$static._rangeEncoder, 15);
2035
+ }
2036
+ function GetPosSlot(pos) {
2037
+ if (pos < 2048) {
2038
+ return g_FastPos[pos];
2039
+ }
2040
+ if (pos < 2097152) {
2041
+ return g_FastPos[pos >> 10] + 20;
2042
+ }
2043
+ return g_FastPos[pos >> 20] + 40;
2044
+ }
2045
+ function GetPosSlot2(pos) {
2046
+ if (pos < 131072) {
2047
+ return g_FastPos[pos >> 6] + 12;
2048
+ }
2049
+ if (pos < 134217728) {
2050
+ return g_FastPos[pos >> 16] + 32;
2051
+ }
2052
+ return g_FastPos[pos >> 26] + 52;
2053
+ }
2054
+ function $Encode(this$static, rangeEncoder, symbol, posState) {
2055
+ if (symbol < 8) {
2056
+ $Encode_3(rangeEncoder, this$static._choice, 0, 0);
2057
+ $Encode_2(this$static._lowCoder[posState], rangeEncoder, symbol);
2058
+ }
2059
+ else {
2060
+ symbol -= 8;
2061
+ $Encode_3(rangeEncoder, this$static._choice, 0, 1);
2062
+ if (symbol < 8) {
2063
+ $Encode_3(rangeEncoder, this$static._choice, 1, 0);
2064
+ $Encode_2(this$static._midCoder[posState], rangeEncoder, symbol);
2065
+ }
2066
+ else {
2067
+ $Encode_3(rangeEncoder, this$static._choice, 1, 1);
2068
+ $Encode_2(this$static._highCoder, rangeEncoder, symbol - 8);
2069
+ }
2070
+ }
2071
+ }
2072
+ function $Encoder$LenEncoder(this$static) {
2073
+ this$static._choice = initDim(2);
2074
+ this$static._lowCoder = initDim(16);
2075
+ this$static._midCoder = initDim(16);
2076
+ this$static._highCoder = $BitTreeEncoder({}, 8);
2077
+ for (var posState = 0; posState < 16; ++posState) {
2078
+ this$static._lowCoder[posState] = $BitTreeEncoder({}, 3);
2079
+ this$static._midCoder[posState] = $BitTreeEncoder({}, 3);
2080
+ }
2081
+ return this$static;
2082
+ }
2083
+ function $Init_2(this$static, numPosStates) {
2084
+ InitBitModels(this$static._choice);
2085
+ for (var posState = 0; posState < numPosStates; ++posState) {
2086
+ InitBitModels(this$static._lowCoder[posState].Models);
2087
+ InitBitModels(this$static._midCoder[posState].Models);
2088
+ }
2089
+ InitBitModels(this$static._highCoder.Models);
2090
+ }
2091
+ function $SetPrices(this$static, posState, numSymbols, prices, st) {
2092
+ var a0, a1, b0, b1, i;
2093
+ a0 = ProbPrices[this$static._choice[0] >>> 2];
2094
+ a1 = ProbPrices[2048 - this$static._choice[0] >>> 2];
2095
+ b0 = a1 + ProbPrices[this$static._choice[1] >>> 2];
2096
+ b1 = a1 + ProbPrices[2048 - this$static._choice[1] >>> 2];
2097
+ i = 0;
2098
+ for (i = 0; i < 8; ++i) {
2099
+ if (i >= numSymbols) {
2100
+ return;
2101
+ }
2102
+ prices[st + i] = a0 + $GetPrice_1(this$static._lowCoder[posState], i);
2103
+ }
2104
+ for (; i < 16; ++i) {
2105
+ if (i >= numSymbols) {
2106
+ return;
2107
+ }
2108
+ prices[st + i] = b0
2109
+ + $GetPrice_1(this$static._midCoder[posState], i - 8);
2110
+ }
2111
+ for (; i < numSymbols; ++i) {
2112
+ prices[st + i] = b1 + $GetPrice_1(this$static._highCoder, i - 8 - 8);
2113
+ }
2114
+ }
2115
+ function $Encode_0(this$static, rangeEncoder, symbol, posState) {
2116
+ $Encode(this$static, rangeEncoder, symbol, posState);
2117
+ if ((this$static._counters[posState] -= 1) == 0) {
2118
+ $SetPrices(this$static, posState, this$static._tableSize, this$static._prices, posState * 272);
2119
+ this$static._counters[posState] = this$static._tableSize;
2120
+ }
2121
+ }
2122
+ function $Encoder$LenPriceTableEncoder(this$static) {
2123
+ $Encoder$LenEncoder(this$static);
2124
+ this$static._prices = [];
2125
+ this$static._counters = [];
2126
+ return this$static;
2127
+ }
2128
+ function $GetPrice(this$static, symbol, posState) {
2129
+ return this$static._prices[posState * 272 + symbol];
2130
+ }
2131
+ function $UpdateTables(this$static, numPosStates) {
2132
+ for (var posState = 0; posState < numPosStates; ++posState) {
2133
+ $SetPrices(this$static, posState, this$static._tableSize, this$static._prices, posState * 272);
2134
+ this$static._counters[posState] = this$static._tableSize;
2135
+ }
2136
+ }
2137
+ function $Create_1(this$static, numPosBits, numPrevBits) {
2138
+ var i, numStates;
2139
+ if (this$static.m_Coders != null && this$static.m_NumPrevBits == numPrevBits
2140
+ && this$static.m_NumPosBits == numPosBits) {
2141
+ return;
2142
+ }
2143
+ this$static.m_NumPosBits = numPosBits;
2144
+ this$static.m_PosMask = (1 << numPosBits) - 1;
2145
+ this$static.m_NumPrevBits = numPrevBits;
2146
+ numStates = 1 << this$static.m_NumPrevBits + this$static.m_NumPosBits;
2147
+ this$static.m_Coders = initDim(numStates);
2148
+ for (i = 0; i < numStates; ++i) {
2149
+ this$static.m_Coders[i] = $Encoder$LiteralEncoder$Encoder2({});
2150
+ }
2151
+ }
2152
+ function $GetSubCoder(this$static, pos, prevByte) {
2153
+ return this$static
2154
+ .m_Coders[((pos & this$static.m_PosMask) << this$static.m_NumPrevBits)
2155
+ + ((prevByte & 255) >>> 8 - this$static.m_NumPrevBits)];
2156
+ }
2157
+ function $Init_3(this$static) {
2158
+ var i, numStates = 1 << this$static.m_NumPrevBits + this$static.m_NumPosBits;
2159
+ for (i = 0; i < numStates; ++i) {
2160
+ InitBitModels(this$static.m_Coders[i].m_Encoders);
2161
+ }
2162
+ }
2163
+ function $Encode_1(this$static, rangeEncoder, symbol) {
2164
+ var bit, i, context = 1;
2165
+ for (i = 7; i >= 0; --i) {
2166
+ bit = symbol >> i & 1;
2167
+ $Encode_3(rangeEncoder, this$static.m_Encoders, context, bit);
2168
+ context = context << 1 | bit;
2169
+ }
2170
+ }
2171
+ function $EncodeMatched(this$static, rangeEncoder, matchByte, symbol) {
2172
+ var bit, i, matchBit, state, same = 1, context = 1;
2173
+ for (i = 7; i >= 0; --i) {
2174
+ bit = symbol >> i & 1;
2175
+ state = context;
2176
+ if (same) {
2177
+ matchBit = matchByte >> i & 1;
2178
+ state += 1 + matchBit << 8;
2179
+ same = matchBit == bit;
2180
+ }
2181
+ $Encode_3(rangeEncoder, this$static.m_Encoders, state, bit);
2182
+ context = context << 1 | bit;
2183
+ }
2184
+ }
2185
+ function $Encoder$LiteralEncoder$Encoder2(this$static) {
2186
+ this$static.m_Encoders = initDim(768);
2187
+ return this$static;
2188
+ }
2189
+ function $GetPrice_0(this$static, matchMode, matchByte, symbol) {
2190
+ var bit, context = 1, i = 7, matchBit, price = 0;
2191
+ if (matchMode) {
2192
+ for (; i >= 0; --i) {
2193
+ matchBit = matchByte >> i & 1;
2194
+ bit = symbol >> i & 1;
2195
+ price += GetPrice(this$static.m_Encoders[(1 + matchBit << 8) + context], bit);
2196
+ context = context << 1 | bit;
2197
+ if (matchBit != bit) {
2198
+ ;
2199
+ --i;
2200
+ break;
2201
+ }
2202
+ }
2203
+ }
2204
+ for (; i >= 0; --i) {
2205
+ bit = symbol >> i & 1;
2206
+ price += GetPrice(this$static.m_Encoders[context], bit);
2207
+ context = context << 1 | bit;
2208
+ }
2209
+ return price;
2210
+ }
2211
+ function $MakeAsChar(this$static) {
2212
+ this$static.BackPrev = -1;
2213
+ this$static.Prev1IsChar = 0;
2214
+ }
2215
+ function $MakeAsShortRep(this$static) {
2216
+ this$static.BackPrev = 0;
2217
+ this$static.Prev1IsChar = 0;
2218
+ }
2219
+ /** ce */
2220
+ /** ds */
2221
+ function $BitTreeDecoder(this$static, numBitLevels) {
2222
+ this$static.NumBitLevels = numBitLevels;
2223
+ this$static.Models = initDim(1 << numBitLevels);
2224
+ return this$static;
2225
+ }
2226
+ function $Decode_0(this$static, rangeDecoder) {
2227
+ var bitIndex, m = 1;
2228
+ for (bitIndex = this$static.NumBitLevels; bitIndex != 0; bitIndex -= 1) {
2229
+ m = (m << 1) + $DecodeBit(rangeDecoder, this$static.Models, m);
2230
+ }
2231
+ return m - (1 << this$static.NumBitLevels);
2232
+ }
2233
+ function $ReverseDecode(this$static, rangeDecoder) {
2234
+ var bit, bitIndex, m = 1, symbol = 0;
2235
+ for (bitIndex = 0; bitIndex < this$static.NumBitLevels; ++bitIndex) {
2236
+ bit = $DecodeBit(rangeDecoder, this$static.Models, m);
2237
+ m <<= 1;
2238
+ m += bit;
2239
+ symbol |= bit << bitIndex;
2240
+ }
2241
+ return symbol;
2242
+ }
2243
+ function ReverseDecode(Models, startIndex, rangeDecoder, NumBitLevels) {
2244
+ var bit, bitIndex, m = 1, symbol = 0;
2245
+ for (bitIndex = 0; bitIndex < NumBitLevels; ++bitIndex) {
2246
+ bit = $DecodeBit(rangeDecoder, Models, startIndex + m);
2247
+ m <<= 1;
2248
+ m += bit;
2249
+ symbol |= bit << bitIndex;
2250
+ }
2251
+ return symbol;
2252
+ }
2253
+ /** de */
2254
+ /** cs */
2255
+ function $BitTreeEncoder(this$static, numBitLevels) {
2256
+ this$static.NumBitLevels = numBitLevels;
2257
+ this$static.Models = initDim(1 << numBitLevels);
2258
+ return this$static;
2259
+ }
2260
+ function $Encode_2(this$static, rangeEncoder, symbol) {
2261
+ var bit, bitIndex, m = 1;
2262
+ for (bitIndex = this$static.NumBitLevels; bitIndex != 0;) {
2263
+ bitIndex -= 1;
2264
+ bit = symbol >>> bitIndex & 1;
2265
+ $Encode_3(rangeEncoder, this$static.Models, m, bit);
2266
+ m = m << 1 | bit;
2267
+ }
2268
+ }
2269
+ function $GetPrice_1(this$static, symbol) {
2270
+ var bit, bitIndex, m = 1, price = 0;
2271
+ for (bitIndex = this$static.NumBitLevels; bitIndex != 0;) {
2272
+ bitIndex -= 1;
2273
+ bit = symbol >>> bitIndex & 1;
2274
+ price += GetPrice(this$static.Models[m], bit);
2275
+ m = (m << 1) + bit;
2276
+ }
2277
+ return price;
2278
+ }
2279
+ function $ReverseEncode(this$static, rangeEncoder, symbol) {
2280
+ var bit, i, m = 1;
2281
+ for (i = 0; i < this$static.NumBitLevels; ++i) {
2282
+ bit = symbol & 1;
2283
+ $Encode_3(rangeEncoder, this$static.Models, m, bit);
2284
+ m = m << 1 | bit;
2285
+ symbol >>= 1;
2286
+ }
2287
+ }
2288
+ function $ReverseGetPrice(this$static, symbol) {
2289
+ var bit, i, m = 1, price = 0;
2290
+ for (i = this$static.NumBitLevels; i != 0; i -= 1) {
2291
+ bit = symbol & 1;
2292
+ symbol >>>= 1;
2293
+ price += GetPrice(this$static.Models[m], bit);
2294
+ m = m << 1 | bit;
2295
+ }
2296
+ return price;
2297
+ }
2298
+ function ReverseEncode(Models, startIndex, rangeEncoder, NumBitLevels, symbol) {
2299
+ var bit, i, m = 1;
2300
+ for (i = 0; i < NumBitLevels; ++i) {
2301
+ bit = symbol & 1;
2302
+ $Encode_3(rangeEncoder, Models, startIndex + m, bit);
2303
+ m = m << 1 | bit;
2304
+ symbol >>= 1;
2305
+ }
2306
+ }
2307
+ function ReverseGetPrice(Models, startIndex, NumBitLevels, symbol) {
2308
+ var bit, i, m = 1, price = 0;
2309
+ for (i = NumBitLevels; i != 0; i -= 1) {
2310
+ bit = symbol & 1;
2311
+ symbol >>>= 1;
2312
+ price +=
2313
+ ProbPrices[((Models[startIndex + m] - bit ^ -bit) & 2047) >>> 2];
2314
+ m = m << 1 | bit;
2315
+ }
2316
+ return price;
2317
+ }
2318
+ /** ce */
2319
+ /** ds */
2320
+ function $DecodeBit(this$static, probs, index) {
2321
+ var newBound, prob = probs[index];
2322
+ newBound = (this$static.Range >>> 11) * prob;
2323
+ if ((this$static.Code ^ -2147483648) < (newBound ^ -2147483648)) {
2324
+ this$static.Range = newBound;
2325
+ probs[index] = prob + (2048 - prob >>> 5) << 16 >> 16;
2326
+ if (!(this$static.Range & -16777216)) {
2327
+ this$static.Code = this$static.Code << 8 | $read(this$static.Stream);
2328
+ this$static.Range <<= 8;
2329
+ }
2330
+ return 0;
2331
+ }
2332
+ else {
2333
+ this$static.Range -= newBound;
2334
+ this$static.Code -= newBound;
2335
+ probs[index] = prob - (prob >>> 5) << 16 >> 16;
2336
+ if (!(this$static.Range & -16777216)) {
2337
+ this$static.Code = this$static.Code << 8 | $read(this$static.Stream);
2338
+ this$static.Range <<= 8;
2339
+ }
2340
+ return 1;
2341
+ }
2342
+ }
2343
+ function $DecodeDirectBits(this$static, numTotalBits) {
2344
+ var i, t, result = 0;
2345
+ for (i = numTotalBits; i != 0; i -= 1) {
2346
+ this$static.Range >>>= 1;
2347
+ t = this$static.Code - this$static.Range >>> 31;
2348
+ this$static.Code -= this$static.Range & t - 1;
2349
+ result = result << 1 | 1 - t;
2350
+ if (!(this$static.Range & -16777216)) {
2351
+ this$static.Code = this$static.Code << 8 | $read(this$static.Stream);
2352
+ this$static.Range <<= 8;
2353
+ }
2354
+ }
2355
+ return result;
2356
+ }
2357
+ function $Init_8(this$static) {
2358
+ this$static.Code = 0;
2359
+ this$static.Range = -1;
2360
+ for (var i = 0; i < 5; ++i) {
2361
+ this$static.Code = this$static.Code << 8 | $read(this$static.Stream);
2362
+ }
2363
+ }
2364
+ /** de */
2365
+ function InitBitModels(probs) {
2366
+ for (var i = probs.length - 1; i >= 0; --i) {
2367
+ probs[i] = 1024;
2368
+ }
2369
+ }
2370
+ /** cs */
2371
+ const ProbPrices = function () {
2372
+ var end, i, j, start, ProbPrices = [];
2373
+ for (i = 8; i >= 0; --i) {
2374
+ start = 1;
2375
+ start <<= 9 - i - 1;
2376
+ end = 1;
2377
+ end <<= 9 - i;
2378
+ for (j = start; j < end; ++j) {
2379
+ ProbPrices[j] = (i << 6) + (end - j << 6 >>> 9 - i - 1);
2380
+ }
2381
+ }
2382
+ return ProbPrices;
2383
+ }();
2384
+ function $Encode_3(this$static, probs, index, symbol) {
2385
+ var newBound, prob = probs[index];
2386
+ newBound = (this$static.Range >>> 11) * prob;
2387
+ if (!symbol) {
2388
+ this$static.Range = newBound;
2389
+ probs[index] = prob + (2048 - prob >>> 5) << 16 >> 16;
2390
+ }
2391
+ else {
2392
+ this$static.Low = add(this$static.Low, and(fromInt(newBound), [4294967295, 0]));
2393
+ this$static.Range -= newBound;
2394
+ probs[index] = prob - (prob >>> 5) << 16 >> 16;
2395
+ }
2396
+ if (!(this$static.Range & -16777216)) {
2397
+ this$static.Range <<= 8;
2398
+ $ShiftLow(this$static);
2399
+ }
2400
+ }
2401
+ function $EncodeDirectBits(this$static, v, numTotalBits) {
2402
+ for (var i = numTotalBits - 1; i >= 0; i -= 1) {
2403
+ this$static.Range >>>= 1;
2404
+ if ((v >>> i & 1) == 1) {
2405
+ this$static.Low = add(this$static.Low, fromInt(this$static.Range));
2406
+ }
2407
+ if (!(this$static.Range & -16777216)) {
2408
+ this$static.Range <<= 8;
2409
+ $ShiftLow(this$static);
2410
+ }
2411
+ }
2412
+ }
2413
+ function $GetProcessedSizeAdd(this$static) {
2414
+ return add(add(fromInt(this$static._cacheSize), this$static._position), [
2415
+ 4,
2416
+ 0
2417
+ ]);
2418
+ }
2419
+ function $Init_9(this$static) {
2420
+ this$static._position = P0_longLit;
2421
+ this$static.Low = P0_longLit;
2422
+ this$static.Range = -1;
2423
+ this$static._cacheSize = 1;
2424
+ this$static._cache = 0;
2425
+ }
2426
+ function $ShiftLow(this$static) {
2427
+ var temp, LowHi = lowBits_0(shru(this$static.Low, 32));
2428
+ if (LowHi != 0 || compare(this$static.Low, [4278190080, 0]) < 0) {
2429
+ this$static._position = add(this$static._position, fromInt(this$static._cacheSize));
2430
+ temp = this$static._cache;
2431
+ do {
2432
+ $write(this$static.Stream, temp + LowHi);
2433
+ temp = 255;
2434
+ } while ((this$static._cacheSize -= 1) != 0);
2435
+ this$static._cache = lowBits_0(this$static.Low) >>> 24;
2436
+ }
2437
+ this$static._cacheSize += 1;
2438
+ this$static.Low = shl(and(this$static.Low, [16777215, 0]), 8);
2439
+ }
2440
+ function GetPrice(Prob, symbol) {
2441
+ return ProbPrices[((Prob - symbol ^ -symbol) & 2047) >>> 2];
2442
+ }
2443
+ /** ce */
2444
+ /** ds */
2445
+ function decode(utf) {
2446
+ var i = 0, j = 0, x, y, z, l = utf.length, buf = [], charCodes = [];
2447
+ for (; i < l; ++i, ++j) {
2448
+ x = utf[i] & 255;
2449
+ if (!(x & 128)) {
2450
+ if (!x) {
2451
+ /// It appears that this is binary data, so it cannot be converted to a string, so just send it back.
2452
+ return utf;
2453
+ }
2454
+ charCodes[j] = x;
2455
+ }
2456
+ else if ((x & 224) == 192) {
2457
+ if (i + 1 >= l) {
2458
+ /// It appears that this is binary data, so it cannot be converted to a string, so just send it back.
2459
+ return utf;
2460
+ }
2461
+ y = utf[++i] & 255;
2462
+ if ((y & 192) != 128) {
2463
+ /// It appears that this is binary data, so it cannot be converted to a string, so just send it back.
2464
+ return utf;
2465
+ }
2466
+ charCodes[j] = ((x & 31) << 6) | (y & 63);
2467
+ }
2468
+ else if ((x & 240) == 224) {
2469
+ if (i + 2 >= l) {
2470
+ /// It appears that this is binary data, so it cannot be converted to a string, so just send it back.
2471
+ return utf;
2472
+ }
2473
+ y = utf[++i] & 255;
2474
+ if ((y & 192) != 128) {
2475
+ /// It appears that this is binary data, so it cannot be converted to a string, so just send it back.
2476
+ return utf;
2477
+ }
2478
+ z = utf[++i] & 255;
2479
+ if ((z & 192) != 128) {
2480
+ /// It appears that this is binary data, so it cannot be converted to a string, so just send it back.
2481
+ return utf;
2482
+ }
2483
+ charCodes[j] = ((x & 15) << 12) | ((y & 63) << 6) | (z & 63);
2484
+ }
2485
+ else {
2486
+ /// It appears that this is binary data, so it cannot be converted to a string, so just send it back.
2487
+ return utf;
2488
+ }
2489
+ if (j == 16383) {
2490
+ buf.push(String.fromCharCode.apply(String, charCodes));
2491
+ j = -1;
2492
+ }
2493
+ }
2494
+ if (j > 0) {
2495
+ charCodes.length = j;
2496
+ buf.push(String.fromCharCode.apply(String, charCodes));
2497
+ }
2498
+ return buf.join("");
2499
+ }
2500
+ /** de */
2501
+ /** cs */
2502
+ function encode(s) {
2503
+ var ch, chars = [], data, elen = 0, i, l = s.length;
2504
+ /// Be able to handle binary arrays and buffers.
2505
+ if (typeof s == "object") {
2506
+ return s;
2507
+ }
2508
+ else {
2509
+ $getChars(s, 0, l, chars, 0);
2510
+ }
2511
+ /// Add extra spaces in the array to break up the unicode symbols.
2512
+ for (i = 0; i < l; ++i) {
2513
+ ch = chars[i];
2514
+ if (ch >= 1 && ch <= 127) {
2515
+ ;
2516
+ ++elen;
2517
+ }
2518
+ else if (!ch || ch >= 128 && ch <= 2047) {
2519
+ elen += 2;
2520
+ }
2521
+ else {
2522
+ elen += 3;
2523
+ }
2524
+ }
2525
+ data = [];
2526
+ elen = 0;
2527
+ for (i = 0; i < l; ++i) {
2528
+ ch = chars[i];
2529
+ if (ch >= 1 && ch <= 127) {
2530
+ data[elen++] = ch << 24 >> 24;
2531
+ }
2532
+ else if (!ch || ch >= 128 && ch <= 2047) {
2533
+ data[elen++] = (192 | ch >> 6 & 31) << 24 >> 24;
2534
+ data[elen++] = (128 | ch & 63) << 24 >> 24;
2535
+ }
2536
+ else {
2537
+ data[elen++] = (224 | ch >> 12 & 15) << 24 >> 24;
2538
+ data[elen++] = (128 | ch >> 6 & 63) << 24 >> 24;
2539
+ data[elen++] = (128 | ch & 63) << 24 >> 24;
2540
+ }
2541
+ }
2542
+ return data;
2543
+ }
2544
+ /** cs */
2545
+ export function compress(data, mode = 5) {
2546
+ const this$static = {};
2547
+ this$static.c = $LZMAByteArrayCompressor({}, encode(data), get_mode_obj(mode));
2548
+ while ($processChunkEncode(this$static.c.chunker))
2549
+ ;
2550
+ return new Int8Array($toByteArray(this$static.c.output));
2551
+ }
2552
+ /** ce */
2553
+ /** ds */
2554
+ export function decompress(bytearray) {
2555
+ const this$static = {};
2556
+ this$static.d = $LZMAByteArrayDecompressor({}, bytearray);
2557
+ while ($processChunkDecode(this$static.d.chunker))
2558
+ ;
2559
+ return new Int8Array(decode($toByteArray(this$static.d.output)));
2560
+ }
2561
+ /** de */
2562
+ /** cs */
2563
+ const get_mode_obj = function () {
2564
+ /// s is dictionarySize
2565
+ /// f is fb
2566
+ /// m is matchFinder
2567
+ /// NOTE: Because some values are always the same, they have been removed.
2568
+ /// lc is always 3
2569
+ /// lp is always 0
2570
+ /// pb is always 2
2571
+ const modes = [
2572
+ { s: 16, f: 64, m: 0 },
2573
+ { s: 20, f: 64, m: 0 },
2574
+ { s: 19, f: 64, m: 1 },
2575
+ { s: 20, f: 64, m: 1 },
2576
+ { s: 21, f: 128, m: 1 },
2577
+ { s: 22, f: 128, m: 1 },
2578
+ { s: 23, f: 128, m: 1 },
2579
+ { s: 24, f: 255, m: 1 },
2580
+ { s: 25, f: 255, m: 1 }
2581
+ ];
2582
+ return function (mode) {
2583
+ return modes[mode - 1];
2584
+ };
2585
+ }();
2586
+ /** ce */