lzma1 0.0.2 → 0.0.3

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