@novnc/novnc 1.3.0 → 1.4.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/AUTHORS +2 -2
  2. package/LICENSE.txt +1 -1
  3. package/README.md +23 -7
  4. package/core/decoders/jpeg.js +141 -0
  5. package/core/decoders/raw.js +1 -1
  6. package/core/decoders/zrle.js +185 -0
  7. package/core/des.js +1 -1
  8. package/core/display.js +12 -0
  9. package/core/encodings.js +4 -0
  10. package/core/input/keyboard.js +10 -0
  11. package/core/ra2.js +567 -0
  12. package/core/rfb.js +469 -84
  13. package/core/util/browser.js +56 -7
  14. package/core/util/cursor.js +4 -0
  15. package/core/util/md5.js +79 -0
  16. package/docs/API.md +318 -157
  17. package/lib/base64.js +20 -34
  18. package/lib/decoders/copyrect.js +5 -12
  19. package/lib/decoders/hextile.js +17 -47
  20. package/lib/decoders/jpeg.js +149 -0
  21. package/lib/decoders/raw.js +10 -23
  22. package/lib/decoders/rre.js +5 -16
  23. package/lib/decoders/tight.js +13 -79
  24. package/lib/decoders/tightpng.js +8 -28
  25. package/lib/decoders/zrle.js +188 -0
  26. package/lib/deflator.js +9 -23
  27. package/lib/des.js +24 -37
  28. package/lib/display.js +62 -108
  29. package/lib/encodings.js +7 -8
  30. package/lib/inflator.js +6 -19
  31. package/lib/input/domkeytable.js +77 -48
  32. package/lib/input/fixedkeys.js +8 -3
  33. package/lib/input/gesturehandler.js +86 -153
  34. package/lib/input/keyboard.js +62 -91
  35. package/lib/input/keysym.js +14 -270
  36. package/lib/input/keysymdef.js +5 -7
  37. package/lib/input/util.js +43 -85
  38. package/lib/input/vkeys.js +0 -3
  39. package/lib/input/xtscancodes.js +1 -168
  40. package/lib/ra2.js +1005 -0
  41. package/lib/rfb.js +795 -923
  42. package/lib/util/browser.js +66 -29
  43. package/lib/util/cursor.js +29 -66
  44. package/lib/util/element.js +3 -5
  45. package/lib/util/events.js +23 -30
  46. package/lib/util/eventtarget.js +5 -14
  47. package/lib/util/int.js +1 -2
  48. package/lib/util/logging.js +1 -19
  49. package/lib/util/md5.js +77 -0
  50. package/lib/util/strings.js +3 -5
  51. package/lib/vendor/pako/lib/utils/common.js +8 -17
  52. package/lib/vendor/pako/lib/zlib/adler32.js +3 -7
  53. package/lib/vendor/pako/lib/zlib/constants.js +2 -5
  54. package/lib/vendor/pako/lib/zlib/crc32.js +5 -12
  55. package/lib/vendor/pako/lib/zlib/deflate.js +213 -618
  56. package/lib/vendor/pako/lib/zlib/gzheader.js +1 -13
  57. package/lib/vendor/pako/lib/zlib/inffast.js +60 -176
  58. package/lib/vendor/pako/lib/zlib/inflate.js +398 -888
  59. package/lib/vendor/pako/lib/zlib/inftrees.js +63 -169
  60. package/lib/vendor/pako/lib/zlib/messages.js +1 -11
  61. package/lib/vendor/pako/lib/zlib/trees.js +246 -588
  62. package/lib/vendor/pako/lib/zlib/zstream.js +2 -18
  63. package/lib/websock.js +37 -88
  64. package/package.json +32 -35
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
-
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
@@ -10,37 +9,34 @@ exports._tr_flush_block = _tr_flush_block;
10
9
  exports._tr_init = _tr_init;
11
10
  exports._tr_stored_block = _tr_stored_block;
12
11
  exports._tr_tally = _tr_tally;
13
-
14
12
  var utils = _interopRequireWildcard(require("../utils/common.js"));
15
-
16
13
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
14
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
15
  /* Public constants ==========================================================*/
21
-
22
16
  /* ===========================================================================*/
17
+
23
18
  //var Z_FILTERED = 1;
24
19
  //var Z_HUFFMAN_ONLY = 2;
25
20
  //var Z_RLE = 3;
26
- var Z_FIXED = 4; //var Z_DEFAULT_STRATEGY = 0;
21
+ var Z_FIXED = 4;
22
+ //var Z_DEFAULT_STRATEGY = 0;
27
23
 
28
24
  /* Possible values of the data_type field (though see inflate()) */
29
-
30
25
  var Z_BINARY = 0;
31
- var Z_TEXT = 1; //var Z_ASCII = 1; // = Z_TEXT
32
-
26
+ var Z_TEXT = 1;
27
+ //var Z_ASCII = 1; // = Z_TEXT
33
28
  var Z_UNKNOWN = 2;
29
+
34
30
  /*============================================================================*/
35
31
 
36
32
  function zero(buf) {
37
33
  var len = buf.length;
38
-
39
34
  while (--len >= 0) {
40
35
  buf[len] = 0;
41
36
  }
42
- } // From zutil.h
37
+ }
43
38
 
39
+ // From zutil.h
44
40
 
45
41
  var STORED_BLOCK = 0;
46
42
  var STATIC_TREES = 1;
@@ -50,8 +46,8 @@ var DYN_TREES = 2;
50
46
  var MIN_MATCH = 3;
51
47
  var MAX_MATCH = 258;
52
48
  /* The minimum and maximum match lengths */
53
- // From deflate.h
54
49
 
50
+ // From deflate.h
55
51
  /* ===========================================================================
56
52
  * Internal compression state.
57
53
  */
@@ -100,15 +96,11 @@ var REPZ_11_138 = 18;
100
96
  /* repeat a zero length 11-138 times (7 bits of repeat count) */
101
97
 
102
98
  /* eslint-disable comma-spacing,array-bracket-spacing */
103
-
104
- var extra_lbits =
105
- /* extra bits for each length code */
99
+ var extra_lbits = /* extra bits for each length code */
106
100
  [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0];
107
- var extra_dbits =
108
- /* extra bits for each distance code */
101
+ var extra_dbits = /* extra bits for each distance code */
109
102
  [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13];
110
- var extra_blbits =
111
- /* extra bits for each bit length code */
103
+ var extra_blbits = /* extra bits for each bit length code */
112
104
  [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7];
113
105
  var bl_order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
114
106
  /* eslint-enable comma-spacing,array-bracket-spacing */
@@ -120,12 +112,12 @@ var bl_order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
120
112
  /* ===========================================================================
121
113
  * Local data. These are initialized only once.
122
114
  */
115
+
123
116
  // We pre-fill arrays with 0 to avoid uninitialized gaps
124
117
 
125
- var DIST_CODE_LEN = 512;
126
- /* see definition of array dist_code below */
127
- // !!!! Use flat array insdead of structure, Freq = i*2, Len = i*2+1
118
+ var DIST_CODE_LEN = 512; /* see definition of array dist_code below */
128
119
 
120
+ // !!!! Use flat array insdead of structure, Freq = i*2, Len = i*2+1
129
121
  var static_ltree = new Array((L_CODES + 2) * 2);
130
122
  zero(static_ltree);
131
123
  /* The static literal tree. Since the bit lengths are imposed, there is no
@@ -141,7 +133,6 @@ zero(static_dtree);
141
133
  */
142
134
 
143
135
  var _dist_code = new Array(DIST_CODE_LEN);
144
-
145
136
  zero(_dist_code);
146
137
  /* Distance codes. The first 256 values correspond to the distances
147
138
  * 3 .. 258, the last 256 values correspond to the top 8 bits of
@@ -149,7 +140,6 @@ zero(_dist_code);
149
140
  */
150
141
 
151
142
  var _length_code = new Array(MAX_MATCH - MIN_MATCH + 1);
152
-
153
143
  zero(_length_code);
154
144
  /* length code for each normalized match length (0 == MIN_MATCH) */
155
145
 
@@ -162,61 +152,43 @@ zero(base_dist);
162
152
  /* First normalized distance for each code (0 = distance of 1) */
163
153
 
164
154
  function StaticTreeDesc(static_tree, extra_bits, extra_base, elems, max_length) {
165
- this.static_tree = static_tree;
166
- /* static tree or NULL */
155
+ this.static_tree = static_tree; /* static tree or NULL */
156
+ this.extra_bits = extra_bits; /* extra bits for each code or NULL */
157
+ this.extra_base = extra_base; /* base index for extra_bits */
158
+ this.elems = elems; /* max number of elements in the tree */
159
+ this.max_length = max_length; /* max bit length for the codes */
167
160
 
168
- this.extra_bits = extra_bits;
169
- /* extra bits for each code or NULL */
170
-
171
- this.extra_base = extra_base;
172
- /* base index for extra_bits */
173
-
174
- this.elems = elems;
175
- /* max number of elements in the tree */
176
-
177
- this.max_length = max_length;
178
- /* max bit length for the codes */
179
161
  // show if `static_tree` has data or dummy - needed for monomorphic objects
180
-
181
162
  this.has_stree = static_tree && static_tree.length;
182
163
  }
183
-
184
164
  var static_l_desc;
185
165
  var static_d_desc;
186
166
  var static_bl_desc;
187
-
188
167
  function TreeDesc(dyn_tree, stat_desc) {
189
- this.dyn_tree = dyn_tree;
190
- /* the dynamic tree */
191
-
192
- this.max_code = 0;
193
- /* largest code with non zero frequency */
194
-
195
- this.stat_desc = stat_desc;
196
- /* the corresponding static tree */
168
+ this.dyn_tree = dyn_tree; /* the dynamic tree */
169
+ this.max_code = 0; /* largest code with non zero frequency */
170
+ this.stat_desc = stat_desc; /* the corresponding static tree */
197
171
  }
198
172
 
199
173
  function d_code(dist) {
200
174
  return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];
201
175
  }
176
+
202
177
  /* ===========================================================================
203
178
  * Output a short LSB first on the stream.
204
179
  * IN assertion: there is enough room in pendingBuf.
205
180
  */
206
-
207
-
208
181
  function put_short(s, w) {
209
182
  // put_byte(s, (uch)((w) & 0xff));
210
183
  // put_byte(s, (uch)((ush)(w) >> 8));
211
184
  s.pending_buf[s.pending++] = w & 0xff;
212
185
  s.pending_buf[s.pending++] = w >>> 8 & 0xff;
213
186
  }
187
+
214
188
  /* ===========================================================================
215
189
  * Send a value on a given number of bits.
216
190
  * IN assertion: length <= 16 and value fits in length bits.
217
191
  */
218
-
219
-
220
192
  function send_bits(s, value, length) {
221
193
  if (s.bi_valid > Buf_size - length) {
222
194
  s.bi_buf |= value << s.bi_valid & 0xffff;
@@ -228,37 +200,28 @@ function send_bits(s, value, length) {
228
200
  s.bi_valid += length;
229
201
  }
230
202
  }
231
-
232
203
  function send_code(s, c, tree) {
233
- send_bits(s, tree[c * 2]
234
- /*.Code*/
235
- , tree[c * 2 + 1]
236
- /*.Len*/
237
- );
204
+ send_bits(s, tree[c * 2] /*.Code*/, tree[c * 2 + 1] /*.Len*/);
238
205
  }
206
+
239
207
  /* ===========================================================================
240
208
  * Reverse the first len bits of a code, using straightforward code (a faster
241
209
  * method would use a table)
242
210
  * IN assertion: 1 <= len <= 15
243
211
  */
244
-
245
-
246
212
  function bi_reverse(code, len) {
247
213
  var res = 0;
248
-
249
214
  do {
250
215
  res |= code & 1;
251
216
  code >>>= 1;
252
217
  res <<= 1;
253
218
  } while (--len > 0);
254
-
255
219
  return res >>> 1;
256
220
  }
221
+
257
222
  /* ===========================================================================
258
223
  * Flush the bit buffer, keeping at most 7 bits in it.
259
224
  */
260
-
261
-
262
225
  function bi_flush(s) {
263
226
  if (s.bi_valid === 16) {
264
227
  put_short(s, s.bi_buf);
@@ -270,6 +233,7 @@ function bi_flush(s) {
270
233
  s.bi_valid -= 8;
271
234
  }
272
235
  }
236
+
273
237
  /* ===========================================================================
274
238
  * Compute the optimal bit lengths for a tree and update the total bit length
275
239
  * for the current block.
@@ -280,9 +244,8 @@ function bi_flush(s) {
280
244
  * The length opt_len is updated; static_len is also updated if stree is
281
245
  * not null.
282
246
  */
283
-
284
-
285
- function gen_bitlen(s, desc) // deflate_state *s;
247
+ function gen_bitlen(s, desc)
248
+ // deflate_state *s;
286
249
  // tree_desc *desc; /* the tree descriptor */
287
250
  {
288
251
  var tree = desc.dyn_tree;
@@ -292,144 +255,91 @@ function gen_bitlen(s, desc) // deflate_state *s;
292
255
  var extra = desc.stat_desc.extra_bits;
293
256
  var base = desc.stat_desc.extra_base;
294
257
  var max_length = desc.stat_desc.max_length;
295
- var h;
296
- /* heap index */
297
-
298
- var n, m;
299
- /* iterate over the tree elements */
300
-
301
- var bits;
302
- /* bit length */
303
-
304
- var xbits;
305
- /* extra bits */
306
-
307
- var f;
308
- /* frequency */
309
-
310
- var overflow = 0;
311
- /* number of elements with bit length too large */
258
+ var h; /* heap index */
259
+ var n, m; /* iterate over the tree elements */
260
+ var bits; /* bit length */
261
+ var xbits; /* extra bits */
262
+ var f; /* frequency */
263
+ var overflow = 0; /* number of elements with bit length too large */
312
264
 
313
265
  for (bits = 0; bits <= MAX_BITS; bits++) {
314
266
  s.bl_count[bits] = 0;
315
267
  }
268
+
316
269
  /* In a first pass, compute the optimal bit lengths (which may
317
270
  * overflow in the case of the bit length tree).
318
271
  */
319
-
320
-
321
- tree[s.heap[s.heap_max] * 2 + 1]
322
- /*.Len*/
323
- = 0;
324
- /* root of the heap */
272
+ tree[s.heap[s.heap_max] * 2 + 1] /*.Len*/ = 0; /* root of the heap */
325
273
 
326
274
  for (h = s.heap_max + 1; h < HEAP_SIZE; h++) {
327
275
  n = s.heap[h];
328
- bits = tree[tree[n * 2 + 1]
329
- /*.Dad*/
330
- * 2 + 1]
331
- /*.Len*/
332
- + 1;
333
-
276
+ bits = tree[tree[n * 2 + 1] /*.Dad*/ * 2 + 1] /*.Len*/ + 1;
334
277
  if (bits > max_length) {
335
278
  bits = max_length;
336
279
  overflow++;
337
280
  }
338
-
339
- tree[n * 2 + 1]
340
- /*.Len*/
341
- = bits;
281
+ tree[n * 2 + 1] /*.Len*/ = bits;
342
282
  /* We overwrite tree[n].Dad which is no longer needed */
343
283
 
344
284
  if (n > max_code) {
345
285
  continue;
346
- }
347
- /* not a leaf node */
348
-
286
+ } /* not a leaf node */
349
287
 
350
288
  s.bl_count[bits]++;
351
289
  xbits = 0;
352
-
353
290
  if (n >= base) {
354
291
  xbits = extra[n - base];
355
292
  }
356
-
357
- f = tree[n * 2]
358
- /*.Freq*/
359
- ;
293
+ f = tree[n * 2] /*.Freq*/;
360
294
  s.opt_len += f * (bits + xbits);
361
-
362
295
  if (has_stree) {
363
- s.static_len += f * (stree[n * 2 + 1]
364
- /*.Len*/
365
- + xbits);
296
+ s.static_len += f * (stree[n * 2 + 1] /*.Len*/ + xbits);
366
297
  }
367
298
  }
368
-
369
299
  if (overflow === 0) {
370
300
  return;
371
- } // Trace((stderr,"\nbit length overflow\n"));
301
+ }
372
302
 
303
+ // Trace((stderr,"\nbit length overflow\n"));
373
304
  /* This happens for example on obj2 and pic of the Calgary corpus */
374
305
 
375
306
  /* Find the first bit length which could increase: */
376
-
377
-
378
307
  do {
379
308
  bits = max_length - 1;
380
-
381
309
  while (s.bl_count[bits] === 0) {
382
310
  bits--;
383
311
  }
384
-
385
- s.bl_count[bits]--;
386
- /* move one leaf down the tree */
387
-
388
- s.bl_count[bits + 1] += 2;
389
- /* move one overflow item as its brother */
390
-
312
+ s.bl_count[bits]--; /* move one leaf down the tree */
313
+ s.bl_count[bits + 1] += 2; /* move one overflow item as its brother */
391
314
  s.bl_count[max_length]--;
392
315
  /* The brother of the overflow item also moves one step up,
393
316
  * but this does not affect bl_count[max_length]
394
317
  */
395
-
396
318
  overflow -= 2;
397
319
  } while (overflow > 0);
320
+
398
321
  /* Now recompute all bit lengths, scanning in increasing frequency.
399
322
  * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
400
323
  * lengths instead of fixing only the wrong ones. This idea is taken
401
324
  * from 'ar' written by Haruhiko Okumura.)
402
325
  */
403
-
404
-
405
326
  for (bits = max_length; bits !== 0; bits--) {
406
327
  n = s.bl_count[bits];
407
-
408
328
  while (n !== 0) {
409
329
  m = s.heap[--h];
410
-
411
330
  if (m > max_code) {
412
331
  continue;
413
332
  }
414
-
415
- if (tree[m * 2 + 1]
416
- /*.Len*/
417
- !== bits) {
333
+ if (tree[m * 2 + 1] /*.Len*/ !== bits) {
418
334
  // Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
419
- s.opt_len += (bits - tree[m * 2 + 1]
420
- /*.Len*/
421
- ) * tree[m * 2]
422
- /*.Freq*/
423
- ;
424
- tree[m * 2 + 1]
425
- /*.Len*/
426
- = bits;
335
+ s.opt_len += (bits - tree[m * 2 + 1] /*.Len*/) * tree[m * 2] /*.Freq*/;
336
+ tree[m * 2 + 1] /*.Len*/ = bits;
427
337
  }
428
-
429
338
  n--;
430
339
  }
431
340
  }
432
341
  }
342
+
433
343
  /* ===========================================================================
434
344
  * Generate the codes for a given tree and bit counts (which need not be
435
345
  * optimal).
@@ -438,28 +348,19 @@ function gen_bitlen(s, desc) // deflate_state *s;
438
348
  * OUT assertion: the field code is set for all tree elements of non
439
349
  * zero code length.
440
350
  */
441
-
442
-
443
- function gen_codes(tree, max_code, bl_count) // ct_data *tree; /* the tree to decorate */
351
+ function gen_codes(tree, max_code, bl_count)
352
+ // ct_data *tree; /* the tree to decorate */
444
353
  // int max_code; /* largest code with non zero frequency */
445
354
  // ushf *bl_count; /* number of codes at each bit length */
446
355
  {
447
- var next_code = new Array(MAX_BITS + 1);
448
- /* next code value for each bit length */
449
-
450
- var code = 0;
451
- /* running code value */
452
-
453
- var bits;
454
- /* bit index */
455
-
456
- var n;
457
- /* code index */
356
+ var next_code = new Array(MAX_BITS + 1); /* next code value for each bit length */
357
+ var code = 0; /* running code value */
358
+ var bits; /* bit index */
359
+ var n; /* code index */
458
360
 
459
361
  /* The distribution counts are first used to generate the code values
460
362
  * without bit reversal.
461
363
  */
462
-
463
364
  for (bits = 1; bits <= MAX_BITS; bits++) {
464
365
  next_code[bits] = code = code + bl_count[bits - 1] << 1;
465
366
  }
@@ -470,52 +371,35 @@ function gen_codes(tree, max_code, bl_count) // ct_data *tree; /*
470
371
  // "inconsistent bit counts");
471
372
  //Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
472
373
 
473
-
474
374
  for (n = 0; n <= max_code; n++) {
475
- var len = tree[n * 2 + 1]
476
- /*.Len*/
477
- ;
478
-
375
+ var len = tree[n * 2 + 1] /*.Len*/;
479
376
  if (len === 0) {
480
377
  continue;
481
378
  }
482
379
  /* Now reverse the bits */
380
+ tree[n * 2] /*.Code*/ = bi_reverse(next_code[len]++, len);
483
381
 
484
-
485
- tree[n * 2]
486
- /*.Code*/
487
- = bi_reverse(next_code[len]++, len); //Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
382
+ //Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
488
383
  // n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
489
384
  }
490
385
  }
386
+
491
387
  /* ===========================================================================
492
388
  * Initialize the various 'constant' tables.
493
389
  */
494
-
495
-
496
390
  function tr_static_init() {
497
- var n;
498
- /* iterates over tree elements */
499
-
500
- var bits;
501
- /* bit counter */
502
-
503
- var length;
504
- /* length value */
505
-
506
- var code;
507
- /* code value */
508
-
509
- var dist;
510
- /* distance index */
511
-
391
+ var n; /* iterates over tree elements */
392
+ var bits; /* bit counter */
393
+ var length; /* length value */
394
+ var code; /* code value */
395
+ var dist; /* distance index */
512
396
  var bl_count = new Array(MAX_BITS + 1);
513
397
  /* number of codes at each bit length for an optimal tree */
398
+
514
399
  // do check in _tr_init()
515
400
  //if (static_init_done) return;
516
401
 
517
402
  /* For some embedded targets, global variables are not initialized: */
518
-
519
403
  /*#ifdef NO_INIT_GLOBAL_POINTERS
520
404
  static_l_desc.static_tree = static_ltree;
521
405
  static_l_desc.extra_bits = extra_lbits;
@@ -525,85 +409,60 @@ function tr_static_init() {
525
409
  #endif*/
526
410
 
527
411
  /* Initialize the mapping length (0..255) -> length code (0..28) */
528
-
529
412
  length = 0;
530
-
531
413
  for (code = 0; code < LENGTH_CODES - 1; code++) {
532
414
  base_length[code] = length;
533
-
534
415
  for (n = 0; n < 1 << extra_lbits[code]; n++) {
535
416
  _length_code[length++] = code;
536
417
  }
537
- } //Assert (length == 256, "tr_static_init: length != 256");
538
-
418
+ }
419
+ //Assert (length == 256, "tr_static_init: length != 256");
539
420
  /* Note that the length 255 (match length 258) can be represented
540
421
  * in two different ways: code 284 + 5 bits or code 285, so we
541
422
  * overwrite length_code[255] to use the best encoding:
542
423
  */
543
-
544
-
545
424
  _length_code[length - 1] = code;
546
- /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
547
425
 
426
+ /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
548
427
  dist = 0;
549
-
550
428
  for (code = 0; code < 16; code++) {
551
429
  base_dist[code] = dist;
552
-
553
430
  for (n = 0; n < 1 << extra_dbits[code]; n++) {
554
431
  _dist_code[dist++] = code;
555
432
  }
556
- } //Assert (dist == 256, "tr_static_init: dist != 256");
557
-
558
-
559
- dist >>= 7;
560
- /* from now on, all distances are divided by 128 */
561
-
433
+ }
434
+ //Assert (dist == 256, "tr_static_init: dist != 256");
435
+ dist >>= 7; /* from now on, all distances are divided by 128 */
562
436
  for (; code < D_CODES; code++) {
563
437
  base_dist[code] = dist << 7;
564
-
565
438
  for (n = 0; n < 1 << extra_dbits[code] - 7; n++) {
566
439
  _dist_code[256 + dist++] = code;
567
440
  }
568
- } //Assert (dist == 256, "tr_static_init: 256+dist != 512");
441
+ }
442
+ //Assert (dist == 256, "tr_static_init: 256+dist != 512");
569
443
 
570
444
  /* Construct the codes of the static literal tree */
571
-
572
-
573
445
  for (bits = 0; bits <= MAX_BITS; bits++) {
574
446
  bl_count[bits] = 0;
575
447
  }
576
-
577
448
  n = 0;
578
-
579
449
  while (n <= 143) {
580
- static_ltree[n * 2 + 1]
581
- /*.Len*/
582
- = 8;
450
+ static_ltree[n * 2 + 1] /*.Len*/ = 8;
583
451
  n++;
584
452
  bl_count[8]++;
585
453
  }
586
-
587
454
  while (n <= 255) {
588
- static_ltree[n * 2 + 1]
589
- /*.Len*/
590
- = 9;
455
+ static_ltree[n * 2 + 1] /*.Len*/ = 9;
591
456
  n++;
592
457
  bl_count[9]++;
593
458
  }
594
-
595
459
  while (n <= 279) {
596
- static_ltree[n * 2 + 1]
597
- /*.Len*/
598
- = 7;
460
+ static_ltree[n * 2 + 1] /*.Len*/ = 7;
599
461
  n++;
600
462
  bl_count[7]++;
601
463
  }
602
-
603
464
  while (n <= 287) {
604
- static_ltree[n * 2 + 1]
605
- /*.Len*/
606
- = 8;
465
+ static_ltree[n * 2 + 1] /*.Len*/ = 8;
607
466
  n++;
608
467
  bl_count[8]++;
609
468
  }
@@ -611,65 +470,46 @@ function tr_static_init() {
611
470
  * tree construction to get a canonical Huffman tree (longest code
612
471
  * all ones)
613
472
  */
614
-
615
-
616
473
  gen_codes(static_ltree, L_CODES + 1, bl_count);
617
- /* The static distance tree is trivial: */
618
474
 
475
+ /* The static distance tree is trivial: */
619
476
  for (n = 0; n < D_CODES; n++) {
620
- static_dtree[n * 2 + 1]
621
- /*.Len*/
622
- = 5;
623
- static_dtree[n * 2]
624
- /*.Code*/
625
- = bi_reverse(n, 5);
626
- } // Now data ready and we can init static trees
627
-
477
+ static_dtree[n * 2 + 1] /*.Len*/ = 5;
478
+ static_dtree[n * 2] /*.Code*/ = bi_reverse(n, 5);
479
+ }
628
480
 
481
+ // Now data ready and we can init static trees
629
482
  static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS + 1, L_CODES, MAX_BITS);
630
483
  static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS);
631
- static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS); //static_init_done = true;
484
+ static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS);
485
+
486
+ //static_init_done = true;
632
487
  }
488
+
633
489
  /* ===========================================================================
634
490
  * Initialize a new block.
635
491
  */
636
-
637
-
638
492
  function init_block(s) {
639
- var n;
640
- /* iterates over tree elements */
493
+ var n; /* iterates over tree elements */
641
494
 
642
495
  /* Initialize the trees. */
643
-
644
496
  for (n = 0; n < L_CODES; n++) {
645
- s.dyn_ltree[n * 2]
646
- /*.Freq*/
647
- = 0;
497
+ s.dyn_ltree[n * 2] /*.Freq*/ = 0;
648
498
  }
649
-
650
499
  for (n = 0; n < D_CODES; n++) {
651
- s.dyn_dtree[n * 2]
652
- /*.Freq*/
653
- = 0;
500
+ s.dyn_dtree[n * 2] /*.Freq*/ = 0;
654
501
  }
655
-
656
502
  for (n = 0; n < BL_CODES; n++) {
657
- s.bl_tree[n * 2]
658
- /*.Freq*/
659
- = 0;
503
+ s.bl_tree[n * 2] /*.Freq*/ = 0;
660
504
  }
661
-
662
- s.dyn_ltree[END_BLOCK * 2]
663
- /*.Freq*/
664
- = 1;
505
+ s.dyn_ltree[END_BLOCK * 2] /*.Freq*/ = 1;
665
506
  s.opt_len = s.static_len = 0;
666
507
  s.last_lit = s.matches = 0;
667
508
  }
509
+
668
510
  /* ===========================================================================
669
511
  * Flush the bit buffer and align the output on a byte boundary
670
512
  */
671
-
672
-
673
513
  function bi_windup(s) {
674
514
  if (s.bi_valid > 8) {
675
515
  put_short(s, s.bi_buf);
@@ -677,172 +517,131 @@ function bi_windup(s) {
677
517
  //put_byte(s, (Byte)s->bi_buf);
678
518
  s.pending_buf[s.pending++] = s.bi_buf;
679
519
  }
680
-
681
520
  s.bi_buf = 0;
682
521
  s.bi_valid = 0;
683
522
  }
523
+
684
524
  /* ===========================================================================
685
525
  * Copy a stored block, storing first the length and its
686
526
  * one's complement if requested.
687
527
  */
688
-
689
-
690
- function copy_block(s, buf, len, header) //DeflateState *s;
528
+ function copy_block(s, buf, len, header)
529
+ //DeflateState *s;
691
530
  //charf *buf; /* the input data */
692
531
  //unsigned len; /* its length */
693
532
  //int header; /* true if block header must be written */
694
533
  {
695
- bi_windup(s);
696
- /* align on byte boundary */
534
+ bi_windup(s); /* align on byte boundary */
697
535
 
698
536
  if (header) {
699
537
  put_short(s, len);
700
538
  put_short(s, ~len);
701
- } // while (len--) {
539
+ }
540
+ // while (len--) {
702
541
  // put_byte(s, *buf++);
703
542
  // }
704
-
705
-
706
543
  utils.arraySet(s.pending_buf, s.window, buf, len, s.pending);
707
544
  s.pending += len;
708
545
  }
546
+
709
547
  /* ===========================================================================
710
548
  * Compares to subtrees, using the tree depth as tie breaker when
711
549
  * the subtrees have equal frequency. This minimizes the worst case length.
712
550
  */
713
-
714
-
715
551
  function smaller(tree, n, m, depth) {
716
552
  var _n2 = n * 2;
717
-
718
553
  var _m2 = m * 2;
719
-
720
- return tree[_n2]
721
- /*.Freq*/
722
- < tree[_m2]
723
- /*.Freq*/
724
- || tree[_n2]
725
- /*.Freq*/
726
- === tree[_m2]
727
- /*.Freq*/
728
- && depth[n] <= depth[m];
554
+ return tree[_n2] /*.Freq*/ < tree[_m2] /*.Freq*/ || tree[_n2] /*.Freq*/ === tree[_m2] /*.Freq*/ && depth[n] <= depth[m];
729
555
  }
556
+
730
557
  /* ===========================================================================
731
558
  * Restore the heap property by moving down the tree starting at node k,
732
559
  * exchanging a node with the smallest of its two sons if necessary, stopping
733
560
  * when the heap property is re-established (each father smaller than its
734
561
  * two sons).
735
562
  */
736
-
737
-
738
- function pqdownheap(s, tree, k) // deflate_state *s;
563
+ function pqdownheap(s, tree, k)
564
+ // deflate_state *s;
739
565
  // ct_data *tree; /* the tree to restore */
740
566
  // int k; /* node to move down */
741
567
  {
742
568
  var v = s.heap[k];
743
- var j = k << 1;
744
- /* left son of k */
745
-
569
+ var j = k << 1; /* left son of k */
746
570
  while (j <= s.heap_len) {
747
571
  /* Set j to the smallest of the two sons: */
748
572
  if (j < s.heap_len && smaller(tree, s.heap[j + 1], s.heap[j], s.depth)) {
749
573
  j++;
750
574
  }
751
575
  /* Exit if v is smaller than both sons */
752
-
753
-
754
576
  if (smaller(tree, v, s.heap[j], s.depth)) {
755
577
  break;
756
578
  }
757
- /* Exchange v with the smallest son */
758
-
759
579
 
580
+ /* Exchange v with the smallest son */
760
581
  s.heap[k] = s.heap[j];
761
582
  k = j;
762
- /* And continue down the tree, setting j to the left son of k */
763
583
 
584
+ /* And continue down the tree, setting j to the left son of k */
764
585
  j <<= 1;
765
586
  }
766
-
767
587
  s.heap[k] = v;
768
- } // inlined manually
588
+ }
589
+
590
+ // inlined manually
769
591
  // var SMALLEST = 1;
770
592
 
771
593
  /* ===========================================================================
772
594
  * Send the block data compressed using the given Huffman trees
773
595
  */
774
-
775
-
776
- function compress_block(s, ltree, dtree) // deflate_state *s;
596
+ function compress_block(s, ltree, dtree)
597
+ // deflate_state *s;
777
598
  // const ct_data *ltree; /* literal tree */
778
599
  // const ct_data *dtree; /* distance tree */
779
600
  {
780
- var dist;
781
- /* distance of matched string */
782
-
783
- var lc;
784
- /* match length or unmatched char (if dist == 0) */
785
-
786
- var lx = 0;
787
- /* running index in l_buf */
788
-
789
- var code;
790
- /* the code to send */
791
-
792
- var extra;
793
- /* number of extra bits to send */
601
+ var dist; /* distance of matched string */
602
+ var lc; /* match length or unmatched char (if dist == 0) */
603
+ var lx = 0; /* running index in l_buf */
604
+ var code; /* the code to send */
605
+ var extra; /* number of extra bits to send */
794
606
 
795
607
  if (s.last_lit !== 0) {
796
608
  do {
797
609
  dist = s.pending_buf[s.d_buf + lx * 2] << 8 | s.pending_buf[s.d_buf + lx * 2 + 1];
798
610
  lc = s.pending_buf[s.l_buf + lx];
799
611
  lx++;
800
-
801
612
  if (dist === 0) {
802
- send_code(s, lc, ltree);
803
- /* send a literal byte */
613
+ send_code(s, lc, ltree); /* send a literal byte */
804
614
  //Tracecv(isgraph(lc), (stderr," '%c' ", lc));
805
615
  } else {
806
616
  /* Here, lc is the match length - MIN_MATCH */
807
617
  code = _length_code[lc];
808
- send_code(s, code + LITERALS + 1, ltree);
809
- /* send the length code */
810
-
618
+ send_code(s, code + LITERALS + 1, ltree); /* send the length code */
811
619
  extra = extra_lbits[code];
812
-
813
620
  if (extra !== 0) {
814
621
  lc -= base_length[code];
815
- send_bits(s, lc, extra);
816
- /* send the extra length bits */
622
+ send_bits(s, lc, extra); /* send the extra length bits */
817
623
  }
818
624
 
819
- dist--;
820
- /* dist is now the match distance - 1 */
821
-
822
- code = d_code(dist); //Assert (code < D_CODES, "bad d_code");
823
-
824
- send_code(s, code, dtree);
825
- /* send the distance code */
625
+ dist--; /* dist is now the match distance - 1 */
626
+ code = d_code(dist);
627
+ //Assert (code < D_CODES, "bad d_code");
826
628
 
629
+ send_code(s, code, dtree); /* send the distance code */
827
630
  extra = extra_dbits[code];
828
-
829
631
  if (extra !== 0) {
830
632
  dist -= base_dist[code];
831
- send_bits(s, dist, extra);
832
- /* send the extra distance bits */
633
+ send_bits(s, dist, extra); /* send the extra distance bits */
833
634
  }
834
- }
835
- /* literal or match pair ? */
635
+ } /* literal or match pair ? */
836
636
 
837
637
  /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
838
638
  //Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
839
639
  // "pendingBuf overflow");
840
-
841
640
  } while (lx < s.last_lit);
842
641
  }
843
-
844
642
  send_code(s, END_BLOCK, ltree);
845
643
  }
644
+
846
645
  /* ===========================================================================
847
646
  * Construct one Huffman tree and assigns the code bit strings and lengths.
848
647
  * Update the total bit length for the current block.
@@ -851,207 +650,132 @@ function compress_block(s, ltree, dtree) // deflate_state *s;
851
650
  * and corresponding code. The length opt_len is updated; static_len is
852
651
  * also updated if stree is not null. The field max_code is set.
853
652
  */
854
-
855
-
856
- function build_tree(s, desc) // deflate_state *s;
653
+ function build_tree(s, desc)
654
+ // deflate_state *s;
857
655
  // tree_desc *desc; /* the tree descriptor */
858
656
  {
859
657
  var tree = desc.dyn_tree;
860
658
  var stree = desc.stat_desc.static_tree;
861
659
  var has_stree = desc.stat_desc.has_stree;
862
660
  var elems = desc.stat_desc.elems;
863
- var n, m;
864
- /* iterate over heap elements */
865
-
866
- var max_code = -1;
867
- /* largest code with non zero frequency */
868
-
869
- var node;
870
- /* new node being created */
661
+ var n, m; /* iterate over heap elements */
662
+ var max_code = -1; /* largest code with non zero frequency */
663
+ var node; /* new node being created */
871
664
 
872
665
  /* Construct the initial heap, with least frequent element in
873
666
  * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
874
667
  * heap[0] is not used.
875
668
  */
876
-
877
669
  s.heap_len = 0;
878
670
  s.heap_max = HEAP_SIZE;
879
-
880
671
  for (n = 0; n < elems; n++) {
881
- if (tree[n * 2]
882
- /*.Freq*/
883
- !== 0) {
672
+ if (tree[n * 2] /*.Freq*/ !== 0) {
884
673
  s.heap[++s.heap_len] = max_code = n;
885
674
  s.depth[n] = 0;
886
675
  } else {
887
- tree[n * 2 + 1]
888
- /*.Len*/
889
- = 0;
676
+ tree[n * 2 + 1] /*.Len*/ = 0;
890
677
  }
891
678
  }
679
+
892
680
  /* The pkzip format requires that at least one distance code exists,
893
681
  * and that at least one bit should be sent even if there is only one
894
682
  * possible code. So to avoid special checks later on we force at least
895
683
  * two codes of non zero frequency.
896
684
  */
897
-
898
-
899
685
  while (s.heap_len < 2) {
900
686
  node = s.heap[++s.heap_len] = max_code < 2 ? ++max_code : 0;
901
- tree[node * 2]
902
- /*.Freq*/
903
- = 1;
687
+ tree[node * 2] /*.Freq*/ = 1;
904
688
  s.depth[node] = 0;
905
689
  s.opt_len--;
906
-
907
690
  if (has_stree) {
908
- s.static_len -= stree[node * 2 + 1]
909
- /*.Len*/
910
- ;
691
+ s.static_len -= stree[node * 2 + 1] /*.Len*/;
911
692
  }
912
693
  /* node is 0 or 1 so it does not have extra bits */
913
-
914
694
  }
915
695
 
916
696
  desc.max_code = max_code;
697
+
917
698
  /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
918
699
  * establish sub-heaps of increasing lengths:
919
700
  */
920
-
921
- for (n = s.heap_len >> 1
922
- /*int /2*/
923
- ; n >= 1; n--) {
701
+ for (n = s.heap_len >> 1 /*int /2*/; n >= 1; n--) {
924
702
  pqdownheap(s, tree, n);
925
703
  }
704
+
926
705
  /* Construct the Huffman tree by repeatedly combining the least two
927
706
  * frequent nodes.
928
707
  */
929
-
930
-
931
- node = elems;
932
- /* next internal node of the tree */
933
-
708
+ node = elems; /* next internal node of the tree */
934
709
  do {
935
710
  //pqremove(s, tree, n); /* n = node of least frequency */
936
-
937
711
  /*** pqremove ***/
938
- n = s.heap[1
939
- /*SMALLEST*/
940
- ];
941
- s.heap[1
942
- /*SMALLEST*/
943
- ] = s.heap[s.heap_len--];
944
- pqdownheap(s, tree, 1
945
- /*SMALLEST*/
946
- );
712
+ n = s.heap[1 /*SMALLEST*/];
713
+ s.heap[1 /*SMALLEST*/] = s.heap[s.heap_len--];
714
+ pqdownheap(s, tree, 1 /*SMALLEST*/);
947
715
  /***/
948
716
 
949
- m = s.heap[1
950
- /*SMALLEST*/
951
- ];
952
- /* m = node of next least frequency */
953
-
954
- s.heap[--s.heap_max] = n;
955
- /* keep the nodes sorted by frequency */
717
+ m = s.heap[1 /*SMALLEST*/]; /* m = node of next least frequency */
956
718
 
719
+ s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */
957
720
  s.heap[--s.heap_max] = m;
958
- /* Create a new node father of n and m */
959
721
 
960
- tree[node * 2]
961
- /*.Freq*/
962
- = tree[n * 2]
963
- /*.Freq*/
964
- + tree[m * 2]
965
- /*.Freq*/
966
- ;
722
+ /* Create a new node father of n and m */
723
+ tree[node * 2] /*.Freq*/ = tree[n * 2] /*.Freq*/ + tree[m * 2] /*.Freq*/;
967
724
  s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;
968
- tree[n * 2 + 1]
969
- /*.Dad*/
970
- = tree[m * 2 + 1]
971
- /*.Dad*/
972
- = node;
973
- /* and insert the new node in the heap */
725
+ tree[n * 2 + 1] /*.Dad*/ = tree[m * 2 + 1] /*.Dad*/ = node;
974
726
 
975
- s.heap[1
976
- /*SMALLEST*/
977
- ] = node++;
978
- pqdownheap(s, tree, 1
979
- /*SMALLEST*/
980
- );
727
+ /* and insert the new node in the heap */
728
+ s.heap[1 /*SMALLEST*/] = node++;
729
+ pqdownheap(s, tree, 1 /*SMALLEST*/);
981
730
  } while (s.heap_len >= 2);
731
+ s.heap[--s.heap_max] = s.heap[1 /*SMALLEST*/];
982
732
 
983
- s.heap[--s.heap_max] = s.heap[1
984
- /*SMALLEST*/
985
- ];
986
733
  /* At this point, the fields freq and dad are set. We can now
987
734
  * generate the bit lengths.
988
735
  */
989
-
990
736
  gen_bitlen(s, desc);
991
- /* The field len is now set, we can generate the bit codes */
992
737
 
738
+ /* The field len is now set, we can generate the bit codes */
993
739
  gen_codes(tree, max_code, s.bl_count);
994
740
  }
741
+
995
742
  /* ===========================================================================
996
743
  * Scan a literal or distance tree to determine the frequencies of the codes
997
744
  * in the bit length tree.
998
745
  */
999
-
1000
-
1001
- function scan_tree(s, tree, max_code) // deflate_state *s;
746
+ function scan_tree(s, tree, max_code)
747
+ // deflate_state *s;
1002
748
  // ct_data *tree; /* the tree to be scanned */
1003
749
  // int max_code; /* and its largest code of non zero frequency */
1004
750
  {
1005
- var n;
1006
- /* iterates over all tree elements */
751
+ var n; /* iterates over all tree elements */
752
+ var prevlen = -1; /* last emitted length */
753
+ var curlen; /* length of current code */
1007
754
 
1008
- var prevlen = -1;
1009
- /* last emitted length */
755
+ var nextlen = tree[0 * 2 + 1] /*.Len*/; /* length of next code */
1010
756
 
1011
- var curlen;
1012
- /* length of current code */
1013
-
1014
- var nextlen = tree[0 * 2 + 1]
1015
- /*.Len*/
1016
- ;
1017
- /* length of next code */
1018
-
1019
- var count = 0;
1020
- /* repeat count of the current code */
1021
-
1022
- var max_count = 7;
1023
- /* max repeat count */
1024
-
1025
- var min_count = 4;
1026
- /* min repeat count */
757
+ var count = 0; /* repeat count of the current code */
758
+ var max_count = 7; /* max repeat count */
759
+ var min_count = 4; /* min repeat count */
1027
760
 
1028
761
  if (nextlen === 0) {
1029
762
  max_count = 138;
1030
763
  min_count = 3;
1031
764
  }
1032
-
1033
- tree[(max_code + 1) * 2 + 1]
1034
- /*.Len*/
1035
- = 0xffff;
1036
- /* guard */
765
+ tree[(max_code + 1) * 2 + 1] /*.Len*/ = 0xffff; /* guard */
1037
766
 
1038
767
  for (n = 0; n <= max_code; n++) {
1039
768
  curlen = nextlen;
1040
- nextlen = tree[(n + 1) * 2 + 1]
1041
- /*.Len*/
1042
- ;
769
+ nextlen = tree[(n + 1) * 2 + 1] /*.Len*/;
1043
770
 
1044
771
  if (++count < max_count && curlen === nextlen) {
1045
772
  continue;
1046
773
  } else if (count < min_count) {
1047
- s.bl_tree[curlen * 2]
1048
- /*.Freq*/
1049
- += count;
774
+ s.bl_tree[curlen * 2] /*.Freq*/ += count;
1050
775
  } else if (curlen !== 0) {
1051
776
  if (curlen !== prevlen) {
1052
777
  s.bl_tree[curlen * 2] /*.Freq*/++;
1053
778
  }
1054
-
1055
779
  s.bl_tree[REP_3_6 * 2] /*.Freq*/++;
1056
780
  } else if (count <= 10) {
1057
781
  s.bl_tree[REPZ_3_10 * 2] /*.Freq*/++;
@@ -1061,7 +785,6 @@ function scan_tree(s, tree, max_code) // deflate_state *s;
1061
785
 
1062
786
  count = 0;
1063
787
  prevlen = curlen;
1064
-
1065
788
  if (nextlen === 0) {
1066
789
  max_count = 138;
1067
790
  min_count = 3;
@@ -1074,53 +797,34 @@ function scan_tree(s, tree, max_code) // deflate_state *s;
1074
797
  }
1075
798
  }
1076
799
  }
800
+
1077
801
  /* ===========================================================================
1078
802
  * Send a literal or distance tree in compressed form, using the codes in
1079
803
  * bl_tree.
1080
804
  */
1081
-
1082
-
1083
- function send_tree(s, tree, max_code) // deflate_state *s;
805
+ function send_tree(s, tree, max_code)
806
+ // deflate_state *s;
1084
807
  // ct_data *tree; /* the tree to be scanned */
1085
808
  // int max_code; /* and its largest code of non zero frequency */
1086
809
  {
1087
- var n;
1088
- /* iterates over all tree elements */
1089
-
1090
- var prevlen = -1;
1091
- /* last emitted length */
1092
-
1093
- var curlen;
1094
- /* length of current code */
1095
-
1096
- var nextlen = tree[0 * 2 + 1]
1097
- /*.Len*/
1098
- ;
1099
- /* length of next code */
1100
-
1101
- var count = 0;
1102
- /* repeat count of the current code */
810
+ var n; /* iterates over all tree elements */
811
+ var prevlen = -1; /* last emitted length */
812
+ var curlen; /* length of current code */
1103
813
 
1104
- var max_count = 7;
1105
- /* max repeat count */
814
+ var nextlen = tree[0 * 2 + 1] /*.Len*/; /* length of next code */
1106
815
 
1107
- var min_count = 4;
1108
- /* min repeat count */
1109
-
1110
- /* tree[max_code+1].Len = -1; */
1111
-
1112
- /* guard already set */
816
+ var count = 0; /* repeat count of the current code */
817
+ var max_count = 7; /* max repeat count */
818
+ var min_count = 4; /* min repeat count */
1113
819
 
820
+ /* tree[max_code+1].Len = -1; */ /* guard already set */
1114
821
  if (nextlen === 0) {
1115
822
  max_count = 138;
1116
823
  min_count = 3;
1117
824
  }
1118
-
1119
825
  for (n = 0; n <= max_code; n++) {
1120
826
  curlen = nextlen;
1121
- nextlen = tree[(n + 1) * 2 + 1]
1122
- /*.Len*/
1123
- ;
827
+ nextlen = tree[(n + 1) * 2 + 1] /*.Len*/;
1124
828
 
1125
829
  if (++count < max_count && curlen === nextlen) {
1126
830
  continue;
@@ -1132,9 +836,8 @@ function send_tree(s, tree, max_code) // deflate_state *s;
1132
836
  if (curlen !== prevlen) {
1133
837
  send_code(s, curlen, s.bl_tree);
1134
838
  count--;
1135
- } //Assert(count >= 3 && count <= 6, " 3_6?");
1136
-
1137
-
839
+ }
840
+ //Assert(count >= 3 && count <= 6, " 3_6?");
1138
841
  send_code(s, REP_3_6, s.bl_tree);
1139
842
  send_bits(s, count - 3, 2);
1140
843
  } else if (count <= 10) {
@@ -1144,10 +847,8 @@ function send_tree(s, tree, max_code) // deflate_state *s;
1144
847
  send_code(s, REPZ_11_138, s.bl_tree);
1145
848
  send_bits(s, count - 11, 7);
1146
849
  }
1147
-
1148
850
  count = 0;
1149
851
  prevlen = curlen;
1150
-
1151
852
  if (nextlen === 0) {
1152
853
  max_count = 138;
1153
854
  min_count = 3;
@@ -1160,22 +861,19 @@ function send_tree(s, tree, max_code) // deflate_state *s;
1160
861
  }
1161
862
  }
1162
863
  }
864
+
1163
865
  /* ===========================================================================
1164
866
  * Construct the Huffman tree for the bit lengths and return the index in
1165
867
  * bl_order of the last bit length code to send.
1166
868
  */
1167
-
1168
-
1169
869
  function build_bl_tree(s) {
1170
- var max_blindex;
1171
- /* index of last bit length code of non zero freq */
870
+ var max_blindex; /* index of last bit length code of non zero freq */
1172
871
 
1173
872
  /* Determine the bit length frequencies for literal and distance trees */
1174
-
1175
873
  scan_tree(s, s.dyn_ltree, s.l_desc.max_code);
1176
874
  scan_tree(s, s.dyn_dtree, s.d_desc.max_code);
1177
- /* Build the bit length tree: */
1178
875
 
876
+ /* Build the bit length tree: */
1179
877
  build_tree(s, s.bl_desc);
1180
878
  /* opt_len now includes the length of the tree representations, except
1181
879
  * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
@@ -1185,62 +883,50 @@ function build_bl_tree(s) {
1185
883
  * requires that at least 4 bit length codes be sent. (appnote.txt says
1186
884
  * 3 but the actual value used is 4.)
1187
885
  */
1188
-
1189
886
  for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {
1190
- if (s.bl_tree[bl_order[max_blindex] * 2 + 1]
1191
- /*.Len*/
1192
- !== 0) {
887
+ if (s.bl_tree[bl_order[max_blindex] * 2 + 1] /*.Len*/ !== 0) {
1193
888
  break;
1194
889
  }
1195
890
  }
1196
891
  /* Update opt_len to include the bit length tree and counts */
1197
-
1198
-
1199
- s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4; //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
892
+ s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
893
+ //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
1200
894
  // s->opt_len, s->static_len));
1201
895
 
1202
896
  return max_blindex;
1203
897
  }
898
+
1204
899
  /* ===========================================================================
1205
900
  * Send the header for a block using dynamic Huffman trees: the counts, the
1206
901
  * lengths of the bit length codes, the literal tree and the distance tree.
1207
902
  * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
1208
903
  */
1209
-
1210
-
1211
- function send_all_trees(s, lcodes, dcodes, blcodes) // deflate_state *s;
904
+ function send_all_trees(s, lcodes, dcodes, blcodes)
905
+ // deflate_state *s;
1212
906
  // int lcodes, dcodes, blcodes; /* number of codes for each tree */
1213
907
  {
1214
- var rank;
1215
- /* index in bl_order */
908
+ var rank; /* index in bl_order */
909
+
1216
910
  //Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
1217
911
  //Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
1218
912
  // "too many codes");
1219
913
  //Tracev((stderr, "\nbl counts: "));
1220
-
1221
- send_bits(s, lcodes - 257, 5);
1222
- /* not +255 as stated in appnote.txt */
1223
-
914
+ send_bits(s, lcodes - 257, 5); /* not +255 as stated in appnote.txt */
1224
915
  send_bits(s, dcodes - 1, 5);
1225
- send_bits(s, blcodes - 4, 4);
1226
- /* not -3 as stated in appnote.txt */
1227
-
916
+ send_bits(s, blcodes - 4, 4); /* not -3 as stated in appnote.txt */
1228
917
  for (rank = 0; rank < blcodes; rank++) {
1229
918
  //Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
1230
- send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1]
1231
- /*.Len*/
1232
- , 3);
1233
- } //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
1234
-
919
+ send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1] /*.Len*/, 3);
920
+ }
921
+ //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
1235
922
 
1236
- send_tree(s, s.dyn_ltree, lcodes - 1);
1237
- /* literal tree */
923
+ send_tree(s, s.dyn_ltree, lcodes - 1); /* literal tree */
1238
924
  //Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
1239
925
 
1240
- send_tree(s, s.dyn_dtree, dcodes - 1);
1241
- /* distance tree */
926
+ send_tree(s, s.dyn_dtree, dcodes - 1); /* distance tree */
1242
927
  //Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
1243
928
  }
929
+
1244
930
  /* ===========================================================================
1245
931
  * Check if the data type is TEXT or BINARY, using the following algorithm:
1246
932
  * - TEXT if the two conditions below are satisfied:
@@ -1254,8 +940,6 @@ function send_all_trees(s, lcodes, dcodes, blcodes) // deflate_state *s;
1254
940
  * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
1255
941
  * IN assertion: the fields Freq of dyn_ltree are set.
1256
942
  */
1257
-
1258
-
1259
943
  function detect_data_type(s) {
1260
944
  /* black_mask is the bit mask of black-listed bytes
1261
945
  * set bits 0..6, 14..25, and 28..31
@@ -1263,123 +947,100 @@ function detect_data_type(s) {
1263
947
  */
1264
948
  var black_mask = 0xf3ffc07f;
1265
949
  var n;
1266
- /* Check for non-textual ("black-listed") bytes. */
1267
950
 
951
+ /* Check for non-textual ("black-listed") bytes. */
1268
952
  for (n = 0; n <= 31; n++, black_mask >>>= 1) {
1269
- if (black_mask & 1 && s.dyn_ltree[n * 2]
1270
- /*.Freq*/
1271
- !== 0) {
953
+ if (black_mask & 1 && s.dyn_ltree[n * 2] /*.Freq*/ !== 0) {
1272
954
  return Z_BINARY;
1273
955
  }
1274
956
  }
1275
- /* Check for textual ("white-listed") bytes. */
1276
957
 
1277
-
1278
- if (s.dyn_ltree[9 * 2]
1279
- /*.Freq*/
1280
- !== 0 || s.dyn_ltree[10 * 2]
1281
- /*.Freq*/
1282
- !== 0 || s.dyn_ltree[13 * 2]
1283
- /*.Freq*/
1284
- !== 0) {
958
+ /* Check for textual ("white-listed") bytes. */
959
+ if (s.dyn_ltree[9 * 2] /*.Freq*/ !== 0 || s.dyn_ltree[10 * 2] /*.Freq*/ !== 0 || s.dyn_ltree[13 * 2] /*.Freq*/ !== 0) {
1285
960
  return Z_TEXT;
1286
961
  }
1287
-
1288
962
  for (n = 32; n < LITERALS; n++) {
1289
- if (s.dyn_ltree[n * 2]
1290
- /*.Freq*/
1291
- !== 0) {
963
+ if (s.dyn_ltree[n * 2] /*.Freq*/ !== 0) {
1292
964
  return Z_TEXT;
1293
965
  }
1294
966
  }
967
+
1295
968
  /* There are no "black-listed" or "white-listed" bytes:
1296
969
  * this stream either is empty or has tolerated ("gray-listed") bytes only.
1297
970
  */
1298
-
1299
-
1300
971
  return Z_BINARY;
1301
972
  }
1302
-
1303
973
  var static_init_done = false;
974
+
1304
975
  /* ===========================================================================
1305
976
  * Initialize the tree data structures for a new zlib stream.
1306
977
  */
1307
-
1308
978
  function _tr_init(s) {
1309
979
  if (!static_init_done) {
1310
980
  tr_static_init();
1311
981
  static_init_done = true;
1312
982
  }
1313
-
1314
983
  s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc);
1315
984
  s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc);
1316
985
  s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc);
1317
986
  s.bi_buf = 0;
1318
987
  s.bi_valid = 0;
1319
- /* Initialize the first block of the first file: */
1320
988
 
989
+ /* Initialize the first block of the first file: */
1321
990
  init_block(s);
1322
991
  }
992
+
1323
993
  /* ===========================================================================
1324
994
  * Send a stored block
1325
995
  */
1326
-
1327
-
1328
- function _tr_stored_block(s, buf, stored_len, last) //DeflateState *s;
996
+ function _tr_stored_block(s, buf, stored_len, last)
997
+ //DeflateState *s;
1329
998
  //charf *buf; /* input block */
1330
999
  //ulg stored_len; /* length of input block */
1331
1000
  //int last; /* one if this is the last block for a file */
1332
1001
  {
1333
- send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3);
1334
- /* send block type */
1335
-
1336
- copy_block(s, buf, stored_len, true);
1337
- /* with header */
1002
+ send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3); /* send block type */
1003
+ copy_block(s, buf, stored_len, true); /* with header */
1338
1004
  }
1005
+
1339
1006
  /* ===========================================================================
1340
1007
  * Send one empty static block to give enough lookahead for inflate.
1341
1008
  * This takes 10 bits, of which 7 may remain in the bit buffer.
1342
1009
  */
1343
-
1344
-
1345
1010
  function _tr_align(s) {
1346
1011
  send_bits(s, STATIC_TREES << 1, 3);
1347
1012
  send_code(s, END_BLOCK, static_ltree);
1348
1013
  bi_flush(s);
1349
1014
  }
1015
+
1350
1016
  /* ===========================================================================
1351
1017
  * Determine the best encoding for the current block: dynamic trees, static
1352
1018
  * trees or store, and output the encoded block to the zip file.
1353
1019
  */
1354
-
1355
-
1356
- function _tr_flush_block(s, buf, stored_len, last) //DeflateState *s;
1020
+ function _tr_flush_block(s, buf, stored_len, last)
1021
+ //DeflateState *s;
1357
1022
  //charf *buf; /* input block, or NULL if too old */
1358
1023
  //ulg stored_len; /* length of input block */
1359
1024
  //int last; /* one if this is the last block for a file */
1360
1025
  {
1361
- var opt_lenb, static_lenb;
1362
- /* opt_len and static_len in bytes */
1363
-
1364
- var max_blindex = 0;
1365
- /* index of last bit length code of non zero freq */
1026
+ var opt_lenb, static_lenb; /* opt_len and static_len in bytes */
1027
+ var max_blindex = 0; /* index of last bit length code of non zero freq */
1366
1028
 
1367
1029
  /* Build the Huffman trees unless a stored block is forced */
1368
-
1369
1030
  if (s.level > 0) {
1370
1031
  /* Check if the file is binary or text */
1371
1032
  if (s.strm.data_type === Z_UNKNOWN) {
1372
1033
  s.strm.data_type = detect_data_type(s);
1373
1034
  }
1374
- /* Construct the literal and distance trees */
1375
-
1376
1035
 
1377
- build_tree(s, s.l_desc); // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
1036
+ /* Construct the literal and distance trees */
1037
+ build_tree(s, s.l_desc);
1038
+ // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
1378
1039
  // s->static_len));
1379
1040
 
1380
- build_tree(s, s.d_desc); // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
1041
+ build_tree(s, s.d_desc);
1042
+ // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
1381
1043
  // s->static_len));
1382
-
1383
1044
  /* At this point, opt_len and static_len are the total bit lengths of
1384
1045
  * the compressed block data, excluding the tree representations.
1385
1046
  */
@@ -1387,12 +1048,13 @@ function _tr_flush_block(s, buf, stored_len, last) //DeflateState *s;
1387
1048
  /* Build the bit length tree for the above two trees, and get the index
1388
1049
  * in bl_order of the last bit length code to send.
1389
1050
  */
1390
-
1391
1051
  max_blindex = build_bl_tree(s);
1392
- /* Determine the best encoding. Compute the block lengths in bytes. */
1393
1052
 
1053
+ /* Determine the best encoding. Compute the block lengths in bytes. */
1394
1054
  opt_lenb = s.opt_len + 3 + 7 >>> 3;
1395
- static_lenb = s.static_len + 3 + 7 >>> 3; // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
1055
+ static_lenb = s.static_len + 3 + 7 >>> 3;
1056
+
1057
+ // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
1396
1058
  // opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
1397
1059
  // s->last_lit));
1398
1060
 
@@ -1401,8 +1063,7 @@ function _tr_flush_block(s, buf, stored_len, last) //DeflateState *s;
1401
1063
  }
1402
1064
  } else {
1403
1065
  // Assert(buf != (char*)0, "lost buf");
1404
- opt_lenb = static_lenb = stored_len + 5;
1405
- /* force a stored block */
1066
+ opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
1406
1067
  }
1407
1068
 
1408
1069
  if (stored_len + 4 <= opt_lenb && buf !== -1) {
@@ -1422,54 +1083,52 @@ function _tr_flush_block(s, buf, stored_len, last) //DeflateState *s;
1422
1083
  send_bits(s, (DYN_TREES << 1) + (last ? 1 : 0), 3);
1423
1084
  send_all_trees(s, s.l_desc.max_code + 1, s.d_desc.max_code + 1, max_blindex + 1);
1424
1085
  compress_block(s, s.dyn_ltree, s.dyn_dtree);
1425
- } // Assert (s->compressed_len == s->bits_sent, "bad compressed size");
1426
-
1086
+ }
1087
+ // Assert (s->compressed_len == s->bits_sent, "bad compressed size");
1427
1088
  /* The above check is made mod 2^32, for files larger than 512 MB
1428
1089
  * and uLong implemented on 32 bits.
1429
1090
  */
1430
-
1431
-
1432
1091
  init_block(s);
1433
-
1434
1092
  if (last) {
1435
1093
  bi_windup(s);
1436
- } // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
1094
+ }
1095
+ // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
1437
1096
  // s->compressed_len-7*last));
1438
-
1439
1097
  }
1098
+
1440
1099
  /* ===========================================================================
1441
1100
  * Save the match info and tally the frequency counts. Return true if
1442
1101
  * the current block must be flushed.
1443
1102
  */
1444
-
1445
-
1446
- function _tr_tally(s, dist, lc) // deflate_state *s;
1103
+ function _tr_tally(s, dist, lc)
1104
+ // deflate_state *s;
1447
1105
  // unsigned dist; /* distance of matched string */
1448
1106
  // unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
1449
1107
  {
1450
1108
  //var out_length, in_length, dcode;
1109
+
1451
1110
  s.pending_buf[s.d_buf + s.last_lit * 2] = dist >>> 8 & 0xff;
1452
1111
  s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff;
1453
1112
  s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff;
1454
1113
  s.last_lit++;
1455
-
1456
1114
  if (dist === 0) {
1457
1115
  /* lc is the unmatched char */
1458
1116
  s.dyn_ltree[lc * 2] /*.Freq*/++;
1459
1117
  } else {
1460
1118
  s.matches++;
1461
1119
  /* Here, lc is the match length - MIN_MATCH */
1462
-
1463
- dist--;
1464
- /* dist = match distance - 1 */
1120
+ dist--; /* dist = match distance - 1 */
1465
1121
  //Assert((ush)dist < (ush)MAX_DIST(s) &&
1466
1122
  // (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
1467
1123
  // (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
1468
1124
 
1469
1125
  s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2] /*.Freq*/++;
1470
1126
  s.dyn_dtree[d_code(dist) * 2] /*.Freq*/++;
1471
- } // (!) This block is disabled in zlib defailts,
1127
+ }
1128
+
1129
+ // (!) This block is disabled in zlib defailts,
1472
1130
  // don't enable it for binary compatibility
1131
+
1473
1132
  //#ifdef TRUNCATE_BLOCK
1474
1133
  // /* Try to guess if it is profitable to stop the current block here */
1475
1134
  // if ((s.last_lit & 0x1fff) === 0 && s.level > 2) {
@@ -1490,7 +1149,6 @@ function _tr_tally(s, dist, lc) // deflate_state *s;
1490
1149
  // }
1491
1150
  //#endif
1492
1151
 
1493
-
1494
1152
  return s.last_lit === s.lit_bufsize - 1;
1495
1153
  /* We avoid equality with lit_bufsize because of wraparound at 64K
1496
1154
  * on 16 bit machines and because stored blocks are restricted to