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