@novnc/novnc 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/core/base64.js +104 -0
  2. package/core/crypto/aes.js +178 -0
  3. package/core/crypto/bigint.js +34 -0
  4. package/core/crypto/crypto.js +90 -0
  5. package/core/crypto/des.js +330 -0
  6. package/core/crypto/dh.js +55 -0
  7. package/core/crypto/md5.js +82 -0
  8. package/core/crypto/rsa.js +132 -0
  9. package/core/decoders/copyrect.js +27 -0
  10. package/core/decoders/h264.js +321 -0
  11. package/core/decoders/hextile.js +181 -0
  12. package/core/decoders/jpeg.js +161 -0
  13. package/core/decoders/raw.js +59 -0
  14. package/core/decoders/rre.js +44 -0
  15. package/core/decoders/tight.js +393 -0
  16. package/core/decoders/tightpng.js +27 -0
  17. package/core/decoders/zlib.js +51 -0
  18. package/core/decoders/zrle.js +185 -0
  19. package/core/deflator.js +84 -0
  20. package/core/display.js +578 -0
  21. package/core/encodings.js +54 -0
  22. package/core/inflator.js +65 -0
  23. package/core/input/domkeytable.js +311 -0
  24. package/core/input/fixedkeys.js +129 -0
  25. package/core/input/gesturehandler.js +567 -0
  26. package/core/input/keyboard.js +294 -0
  27. package/core/input/keysym.js +616 -0
  28. package/core/input/keysymdef.js +688 -0
  29. package/core/input/util.js +191 -0
  30. package/core/input/vkeys.js +116 -0
  31. package/core/input/xtscancodes.js +173 -0
  32. package/core/ra2.js +312 -0
  33. package/core/rfb.js +3411 -0
  34. package/core/util/browser.js +233 -0
  35. package/core/util/cursor.js +249 -0
  36. package/core/util/element.js +32 -0
  37. package/core/util/events.js +138 -0
  38. package/core/util/eventtarget.js +35 -0
  39. package/core/util/int.js +15 -0
  40. package/core/util/logging.js +56 -0
  41. package/core/util/strings.js +28 -0
  42. package/core/websock.js +369 -0
  43. package/docs/API.md +0 -5
  44. package/package.json +6 -10
  45. package/vendor/pako/LICENSE +21 -0
  46. package/vendor/pako/README.md +6 -0
  47. package/{lib/vendor → vendor}/pako/lib/utils/common.js +13 -23
  48. package/{lib/vendor → vendor}/pako/lib/zlib/adler32.js +12 -14
  49. package/vendor/pako/lib/zlib/constants.js +47 -0
  50. package/{lib/vendor → vendor}/pako/lib/zlib/crc32.js +15 -14
  51. package/{lib/vendor → vendor}/pako/lib/zlib/deflate.js +459 -334
  52. package/{lib/vendor → vendor}/pako/lib/zlib/gzheader.js +13 -19
  53. package/{lib/vendor → vendor}/pako/lib/zlib/inffast.js +116 -119
  54. package/vendor/pako/lib/zlib/inflate.js +1527 -0
  55. package/{lib/vendor → vendor}/pako/lib/zlib/inftrees.js +103 -91
  56. package/vendor/pako/lib/zlib/messages.js +11 -0
  57. package/{lib/vendor → vendor}/pako/lib/zlib/trees.js +313 -268
  58. package/{lib/vendor → vendor}/pako/lib/zlib/zstream.js +4 -10
  59. package/lib/base64.js +0 -100
  60. package/lib/crypto/aes.js +0 -481
  61. package/lib/crypto/bigint.js +0 -41
  62. package/lib/crypto/crypto.js +0 -109
  63. package/lib/crypto/des.js +0 -374
  64. package/lib/crypto/dh.js +0 -81
  65. package/lib/crypto/md5.js +0 -97
  66. package/lib/crypto/rsa.js +0 -312
  67. package/lib/decoders/copyrect.js +0 -40
  68. package/lib/decoders/h264.js +0 -349
  69. package/lib/decoders/hextile.js +0 -195
  70. package/lib/decoders/jpeg.js +0 -175
  71. package/lib/decoders/raw.js +0 -66
  72. package/lib/decoders/rre.js +0 -52
  73. package/lib/decoders/tight.js +0 -363
  74. package/lib/decoders/tightpng.js +0 -51
  75. package/lib/decoders/zlib.js +0 -57
  76. package/lib/decoders/zrle.js +0 -192
  77. package/lib/deflator.js +0 -88
  78. package/lib/display.js +0 -588
  79. package/lib/encodings.js +0 -70
  80. package/lib/inflator.js +0 -77
  81. package/lib/input/domkeytable.js +0 -313
  82. package/lib/input/fixedkeys.js +0 -127
  83. package/lib/input/gesturehandler.js +0 -573
  84. package/lib/input/keyboard.js +0 -293
  85. package/lib/input/keysym.js +0 -878
  86. package/lib/input/keysymdef.js +0 -1351
  87. package/lib/input/util.js +0 -217
  88. package/lib/input/vkeys.js +0 -121
  89. package/lib/input/xtscancodes.js +0 -343
  90. package/lib/ra2.js +0 -535
  91. package/lib/rfb.js +0 -3398
  92. package/lib/util/browser.js +0 -239
  93. package/lib/util/cursor.js +0 -269
  94. package/lib/util/element.js +0 -41
  95. package/lib/util/events.js +0 -133
  96. package/lib/util/eventtarget.js +0 -53
  97. package/lib/util/int.js +0 -21
  98. package/lib/util/logging.js +0 -56
  99. package/lib/util/strings.js +0 -36
  100. package/lib/vendor/pako/lib/zlib/constants.js +0 -47
  101. package/lib/vendor/pako/lib/zlib/inflate.js +0 -1602
  102. package/lib/vendor/pako/lib/zlib/messages.js +0 -25
  103. package/lib/websock.js +0 -395
@@ -1,50 +1,35 @@
1
- "use strict";
2
-
3
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports._tr_align = _tr_align;
8
- exports._tr_flush_block = _tr_flush_block;
9
- exports._tr_init = _tr_init;
10
- exports._tr_stored_block = _tr_stored_block;
11
- exports._tr_tally = _tr_tally;
12
- var utils = _interopRequireWildcard(require("../utils/common.js"));
13
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
14
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
1
+ import * as utils from "../utils/common.js";
2
+
15
3
  /* Public constants ==========================================================*/
16
4
  /* ===========================================================================*/
17
5
 
6
+
18
7
  //var Z_FILTERED = 1;
19
8
  //var Z_HUFFMAN_ONLY = 2;
20
9
  //var Z_RLE = 3;
21
- var Z_FIXED = 4;
10
+ var Z_FIXED = 4;
22
11
  //var Z_DEFAULT_STRATEGY = 0;
23
12
 
24
13
  /* Possible values of the data_type field (though see inflate()) */
25
- var Z_BINARY = 0;
26
- var Z_TEXT = 1;
14
+ var Z_BINARY = 0;
15
+ var Z_TEXT = 1;
27
16
  //var Z_ASCII = 1; // = Z_TEXT
28
- var Z_UNKNOWN = 2;
17
+ var Z_UNKNOWN = 2;
29
18
 
30
19
  /*============================================================================*/
31
20
 
32
- function zero(buf) {
33
- var len = buf.length;
34
- while (--len >= 0) {
35
- buf[len] = 0;
36
- }
37
- }
21
+
22
+ function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
38
23
 
39
24
  // From zutil.h
40
25
 
41
26
  var STORED_BLOCK = 0;
42
27
  var STATIC_TREES = 1;
43
- var DYN_TREES = 2;
28
+ var DYN_TREES = 2;
44
29
  /* The three kinds of block type */
45
30
 
46
- var MIN_MATCH = 3;
47
- var MAX_MATCH = 258;
31
+ var MIN_MATCH = 3;
32
+ var MAX_MATCH = 258;
48
33
  /* The minimum and maximum match lengths */
49
34
 
50
35
  // From deflate.h
@@ -52,30 +37,31 @@ var MAX_MATCH = 258;
52
37
  * Internal compression state.
53
38
  */
54
39
 
55
- var LENGTH_CODES = 29;
40
+ var LENGTH_CODES = 29;
56
41
  /* number of length codes, not counting the special END_BLOCK code */
57
42
 
58
- var LITERALS = 256;
43
+ var LITERALS = 256;
59
44
  /* number of literal bytes 0..255 */
60
45
 
61
- var L_CODES = LITERALS + 1 + LENGTH_CODES;
46
+ var L_CODES = LITERALS + 1 + LENGTH_CODES;
62
47
  /* number of Literal or Length codes, including the END_BLOCK code */
63
48
 
64
- var D_CODES = 30;
49
+ var D_CODES = 30;
65
50
  /* number of distance codes */
66
51
 
67
- var BL_CODES = 19;
52
+ var BL_CODES = 19;
68
53
  /* number of codes used to transfer the bit lengths */
69
54
 
70
- var HEAP_SIZE = 2 * L_CODES + 1;
55
+ var HEAP_SIZE = 2 * L_CODES + 1;
71
56
  /* maximum heap size */
72
57
 
73
- var MAX_BITS = 15;
58
+ var MAX_BITS = 15;
74
59
  /* All codes must not exceed MAX_BITS bits */
75
60
 
76
- var Buf_size = 16;
61
+ var Buf_size = 16;
77
62
  /* size of bit buffer in bi_buf */
78
63
 
64
+
79
65
  /* ===========================================================================
80
66
  * Constants
81
67
  */
@@ -83,26 +69,30 @@ var Buf_size = 16;
83
69
  var MAX_BL_BITS = 7;
84
70
  /* Bit length codes must not exceed MAX_BL_BITS bits */
85
71
 
86
- var END_BLOCK = 256;
72
+ var END_BLOCK = 256;
87
73
  /* end of block literal code */
88
74
 
89
- var REP_3_6 = 16;
75
+ var REP_3_6 = 16;
90
76
  /* repeat previous bit length 3-6 times (2 bits of repeat count) */
91
77
 
92
- var REPZ_3_10 = 17;
78
+ var REPZ_3_10 = 17;
93
79
  /* repeat a zero length 3-10 times (3 bits of repeat count) */
94
80
 
95
81
  var REPZ_11_138 = 18;
96
82
  /* repeat a zero length 11-138 times (7 bits of repeat count) */
97
83
 
98
84
  /* eslint-disable comma-spacing,array-bracket-spacing */
99
- var extra_lbits = /* extra bits for each length code */
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];
101
- var extra_dbits = /* extra bits for each distance code */
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];
103
- var extra_blbits = /* extra bits for each bit length code */
104
- [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7];
105
- var bl_order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
85
+ var extra_lbits = /* extra bits for each length code */
86
+ [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];
87
+
88
+ var extra_dbits = /* extra bits for each distance code */
89
+ [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];
90
+
91
+ var extra_blbits = /* extra bits for each bit length code */
92
+ [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7];
93
+
94
+ var bl_order =
95
+ [16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];
106
96
  /* eslint-enable comma-spacing,array-bracket-spacing */
107
97
 
108
98
  /* The lengths of the bit length codes are sent in order of decreasing
@@ -118,7 +108,7 @@ var bl_order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
118
108
  var DIST_CODE_LEN = 512; /* see definition of array dist_code below */
119
109
 
120
110
  // !!!! Use flat array insdead of structure, Freq = i*2, Len = i*2+1
121
- var static_ltree = new Array((L_CODES + 2) * 2);
111
+ var static_ltree = new Array((L_CODES + 2) * 2);
122
112
  zero(static_ltree);
123
113
  /* The static literal tree. Since the bit lengths are imposed, there is no
124
114
  * need for the L_CODES extra codes used during heap construction. However
@@ -126,83 +116,97 @@ zero(static_ltree);
126
116
  * below).
127
117
  */
128
118
 
129
- var static_dtree = new Array(D_CODES * 2);
119
+ var static_dtree = new Array(D_CODES * 2);
130
120
  zero(static_dtree);
131
121
  /* The static distance tree. (Actually a trivial tree since all codes use
132
122
  * 5 bits.)
133
123
  */
134
124
 
135
- var _dist_code = new Array(DIST_CODE_LEN);
125
+ var _dist_code = new Array(DIST_CODE_LEN);
136
126
  zero(_dist_code);
137
127
  /* Distance codes. The first 256 values correspond to the distances
138
128
  * 3 .. 258, the last 256 values correspond to the top 8 bits of
139
129
  * the 15 bit distances.
140
130
  */
141
131
 
142
- var _length_code = new Array(MAX_MATCH - MIN_MATCH + 1);
132
+ var _length_code = new Array(MAX_MATCH - MIN_MATCH + 1);
143
133
  zero(_length_code);
144
134
  /* length code for each normalized match length (0 == MIN_MATCH) */
145
135
 
146
- var base_length = new Array(LENGTH_CODES);
136
+ var base_length = new Array(LENGTH_CODES);
147
137
  zero(base_length);
148
138
  /* First normalized length for each code (0 = MIN_MATCH) */
149
139
 
150
- var base_dist = new Array(D_CODES);
140
+ var base_dist = new Array(D_CODES);
151
141
  zero(base_dist);
152
142
  /* First normalized distance for each code (0 = distance of 1) */
153
143
 
144
+
154
145
  function StaticTreeDesc(static_tree, extra_bits, extra_base, elems, max_length) {
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 */
146
+
147
+ this.static_tree = static_tree; /* static tree or NULL */
148
+ this.extra_bits = extra_bits; /* extra bits for each code or NULL */
149
+ this.extra_base = extra_base; /* base index for extra_bits */
150
+ this.elems = elems; /* max number of elements in the tree */
151
+ this.max_length = max_length; /* max bit length for the codes */
160
152
 
161
153
  // show if `static_tree` has data or dummy - needed for monomorphic objects
162
- this.has_stree = static_tree && static_tree.length;
154
+ this.has_stree = static_tree && static_tree.length;
163
155
  }
156
+
157
+
164
158
  var static_l_desc;
165
159
  var static_d_desc;
166
160
  var static_bl_desc;
161
+
162
+
167
163
  function TreeDesc(dyn_tree, stat_desc) {
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 */
164
+ this.dyn_tree = dyn_tree; /* the dynamic tree */
165
+ this.max_code = 0; /* largest code with non zero frequency */
166
+ this.stat_desc = stat_desc; /* the corresponding static tree */
171
167
  }
168
+
169
+
170
+
172
171
  function d_code(dist) {
173
172
  return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];
174
173
  }
175
174
 
175
+
176
176
  /* ===========================================================================
177
177
  * Output a short LSB first on the stream.
178
178
  * IN assertion: there is enough room in pendingBuf.
179
179
  */
180
180
  function put_short(s, w) {
181
- // put_byte(s, (uch)((w) & 0xff));
182
- // put_byte(s, (uch)((ush)(w) >> 8));
183
- s.pending_buf[s.pending++] = w & 0xff;
184
- s.pending_buf[s.pending++] = w >>> 8 & 0xff;
181
+ // put_byte(s, (uch)((w) & 0xff));
182
+ // put_byte(s, (uch)((ush)(w) >> 8));
183
+ s.pending_buf[s.pending++] = (w) & 0xff;
184
+ s.pending_buf[s.pending++] = (w >>> 8) & 0xff;
185
185
  }
186
186
 
187
+
187
188
  /* ===========================================================================
188
189
  * Send a value on a given number of bits.
189
190
  * IN assertion: length <= 16 and value fits in length bits.
190
191
  */
191
192
  function send_bits(s, value, length) {
192
- if (s.bi_valid > Buf_size - length) {
193
- s.bi_buf |= value << s.bi_valid & 0xffff;
193
+ if (s.bi_valid > (Buf_size - length)) {
194
+ s.bi_buf |= (value << s.bi_valid) & 0xffff;
194
195
  put_short(s, s.bi_buf);
195
- s.bi_buf = value >> Buf_size - s.bi_valid;
196
+ s.bi_buf = value >> (Buf_size - s.bi_valid);
196
197
  s.bi_valid += length - Buf_size;
197
198
  } else {
198
- s.bi_buf |= value << s.bi_valid & 0xffff;
199
+ s.bi_buf |= (value << s.bi_valid) & 0xffff;
199
200
  s.bi_valid += length;
200
201
  }
201
202
  }
203
+
204
+
202
205
  function send_code(s, c, tree) {
203
- send_bits(s, tree[c * 2] /*.Code*/, tree[c * 2 + 1] /*.Len*/);
206
+ send_bits(s, tree[c * 2]/*.Code*/, tree[c * 2 + 1]/*.Len*/);
204
207
  }
205
208
 
209
+
206
210
  /* ===========================================================================
207
211
  * Reverse the first len bits of a code, using straightforward code (a faster
208
212
  * method would use a table)
@@ -218,6 +222,7 @@ function bi_reverse(code, len) {
218
222
  return res >>> 1;
219
223
  }
220
224
 
225
+
221
226
  /* ===========================================================================
222
227
  * Flush the bit buffer, keeping at most 7 bits in it.
223
228
  */
@@ -226,6 +231,7 @@ function bi_flush(s) {
226
231
  put_short(s, s.bi_buf);
227
232
  s.bi_buf = 0;
228
233
  s.bi_valid = 0;
234
+
229
235
  } else if (s.bi_valid >= 8) {
230
236
  s.pending_buf[s.pending++] = s.bi_buf & 0xff;
231
237
  s.bi_buf >>= 8;
@@ -233,6 +239,7 @@ function bi_flush(s) {
233
239
  }
234
240
  }
235
241
 
242
+
236
243
  /* ===========================================================================
237
244
  * Compute the optimal bit lengths for a tree and update the total bit length
238
245
  * for the current block.
@@ -247,19 +254,19 @@ function gen_bitlen(s, desc)
247
254
  // deflate_state *s;
248
255
  // tree_desc *desc; /* the tree descriptor */
249
256
  {
250
- var tree = desc.dyn_tree;
251
- var max_code = desc.max_code;
252
- var stree = desc.stat_desc.static_tree;
253
- var has_stree = desc.stat_desc.has_stree;
254
- var extra = desc.stat_desc.extra_bits;
255
- var base = desc.stat_desc.extra_base;
256
- var max_length = desc.stat_desc.max_length;
257
- var h; /* heap index */
258
- var n, m; /* iterate over the tree elements */
259
- var bits; /* bit length */
260
- var xbits; /* extra bits */
261
- var f; /* frequency */
262
- var overflow = 0; /* number of elements with bit length too large */
257
+ var tree = desc.dyn_tree;
258
+ var max_code = desc.max_code;
259
+ var stree = desc.stat_desc.static_tree;
260
+ var has_stree = desc.stat_desc.has_stree;
261
+ var extra = desc.stat_desc.extra_bits;
262
+ var base = desc.stat_desc.extra_base;
263
+ var max_length = desc.stat_desc.max_length;
264
+ var h; /* heap index */
265
+ var n, m; /* iterate over the tree elements */
266
+ var bits; /* bit length */
267
+ var xbits; /* extra bits */
268
+ var f; /* frequency */
269
+ var overflow = 0; /* number of elements with bit length too large */
263
270
 
264
271
  for (bits = 0; bits <= MAX_BITS; bits++) {
265
272
  s.bl_count[bits] = 0;
@@ -268,36 +275,32 @@ function gen_bitlen(s, desc)
268
275
  /* In a first pass, compute the optimal bit lengths (which may
269
276
  * overflow in the case of the bit length tree).
270
277
  */
271
- tree[s.heap[s.heap_max] * 2 + 1] /*.Len*/ = 0; /* root of the heap */
278
+ tree[s.heap[s.heap_max] * 2 + 1]/*.Len*/ = 0; /* root of the heap */
272
279
 
273
280
  for (h = s.heap_max + 1; h < HEAP_SIZE; h++) {
274
281
  n = s.heap[h];
275
- bits = tree[tree[n * 2 + 1] /*.Dad*/ * 2 + 1] /*.Len*/ + 1;
282
+ bits = tree[tree[n * 2 + 1]/*.Dad*/ * 2 + 1]/*.Len*/ + 1;
276
283
  if (bits > max_length) {
277
284
  bits = max_length;
278
285
  overflow++;
279
286
  }
280
- tree[n * 2 + 1] /*.Len*/ = bits;
287
+ tree[n * 2 + 1]/*.Len*/ = bits;
281
288
  /* We overwrite tree[n].Dad which is no longer needed */
282
289
 
283
- if (n > max_code) {
284
- continue;
285
- } /* not a leaf node */
290
+ if (n > max_code) { continue; } /* not a leaf node */
286
291
 
287
292
  s.bl_count[bits]++;
288
293
  xbits = 0;
289
294
  if (n >= base) {
290
295
  xbits = extra[n - base];
291
296
  }
292
- f = tree[n * 2] /*.Freq*/;
297
+ f = tree[n * 2]/*.Freq*/;
293
298
  s.opt_len += f * (bits + xbits);
294
299
  if (has_stree) {
295
- s.static_len += f * (stree[n * 2 + 1] /*.Len*/ + xbits);
300
+ s.static_len += f * (stree[n * 2 + 1]/*.Len*/ + xbits);
296
301
  }
297
302
  }
298
- if (overflow === 0) {
299
- return;
300
- }
303
+ if (overflow === 0) { return; }
301
304
 
302
305
  // Trace((stderr,"\nbit length overflow\n"));
303
306
  /* This happens for example on obj2 and pic of the Calgary corpus */
@@ -305,10 +308,8 @@ function gen_bitlen(s, desc)
305
308
  /* Find the first bit length which could increase: */
306
309
  do {
307
310
  bits = max_length - 1;
308
- while (s.bl_count[bits] === 0) {
309
- bits--;
310
- }
311
- s.bl_count[bits]--; /* move one leaf down the tree */
311
+ while (s.bl_count[bits] === 0) { bits--; }
312
+ s.bl_count[bits]--; /* move one leaf down the tree */
312
313
  s.bl_count[bits + 1] += 2; /* move one overflow item as its brother */
313
314
  s.bl_count[max_length]--;
314
315
  /* The brother of the overflow item also moves one step up,
@@ -326,19 +327,18 @@ function gen_bitlen(s, desc)
326
327
  n = s.bl_count[bits];
327
328
  while (n !== 0) {
328
329
  m = s.heap[--h];
329
- if (m > max_code) {
330
- continue;
331
- }
332
- if (tree[m * 2 + 1] /*.Len*/ !== bits) {
330
+ if (m > max_code) { continue; }
331
+ if (tree[m * 2 + 1]/*.Len*/ !== bits) {
333
332
  // Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
334
- s.opt_len += (bits - tree[m * 2 + 1] /*.Len*/) * tree[m * 2] /*.Freq*/;
335
- tree[m * 2 + 1] /*.Len*/ = bits;
333
+ s.opt_len += (bits - tree[m * 2 + 1]/*.Len*/) * tree[m * 2]/*.Freq*/;
334
+ tree[m * 2 + 1]/*.Len*/ = bits;
336
335
  }
337
336
  n--;
338
337
  }
339
338
  }
340
339
  }
341
340
 
341
+
342
342
  /* ===========================================================================
343
343
  * Generate the codes for a given tree and bit counts (which need not be
344
344
  * optimal).
@@ -353,15 +353,15 @@ function gen_codes(tree, max_code, bl_count)
353
353
  // ushf *bl_count; /* number of codes at each bit length */
354
354
  {
355
355
  var next_code = new Array(MAX_BITS + 1); /* next code value for each bit length */
356
- var code = 0; /* running code value */
357
- var bits; /* bit index */
358
- var n; /* code index */
356
+ var code = 0; /* running code value */
357
+ var bits; /* bit index */
358
+ var n; /* code index */
359
359
 
360
360
  /* The distribution counts are first used to generate the code values
361
361
  * without bit reversal.
362
362
  */
363
363
  for (bits = 1; bits <= MAX_BITS; bits++) {
364
- next_code[bits] = code = code + bl_count[bits - 1] << 1;
364
+ next_code[bits] = code = (code + bl_count[bits - 1]) << 1;
365
365
  }
366
366
  /* Check that the bit counts in bl_count are consistent. The last code
367
367
  * must be all ones.
@@ -370,28 +370,27 @@ function gen_codes(tree, max_code, bl_count)
370
370
  // "inconsistent bit counts");
371
371
  //Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
372
372
 
373
- for (n = 0; n <= max_code; n++) {
374
- var len = tree[n * 2 + 1] /*.Len*/;
375
- if (len === 0) {
376
- continue;
377
- }
373
+ for (n = 0; n <= max_code; n++) {
374
+ var len = tree[n * 2 + 1]/*.Len*/;
375
+ if (len === 0) { continue; }
378
376
  /* Now reverse the bits */
379
- tree[n * 2] /*.Code*/ = bi_reverse(next_code[len]++, len);
377
+ tree[n * 2]/*.Code*/ = bi_reverse(next_code[len]++, len);
380
378
 
381
379
  //Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
382
380
  // n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
383
381
  }
384
382
  }
385
383
 
384
+
386
385
  /* ===========================================================================
387
386
  * Initialize the various 'constant' tables.
388
387
  */
389
388
  function tr_static_init() {
390
- var n; /* iterates over tree elements */
391
- var bits; /* bit counter */
392
- var length; /* length value */
393
- var code; /* code value */
394
- var dist; /* distance index */
389
+ var n; /* iterates over tree elements */
390
+ var bits; /* bit counter */
391
+ var length; /* length value */
392
+ var code; /* code value */
393
+ var dist; /* distance index */
395
394
  var bl_count = new Array(MAX_BITS + 1);
396
395
  /* number of codes at each bit length for an optimal tree */
397
396
 
@@ -399,19 +398,19 @@ function tr_static_init() {
399
398
  //if (static_init_done) return;
400
399
 
401
400
  /* For some embedded targets, global variables are not initialized: */
402
- /*#ifdef NO_INIT_GLOBAL_POINTERS
403
- static_l_desc.static_tree = static_ltree;
404
- static_l_desc.extra_bits = extra_lbits;
405
- static_d_desc.static_tree = static_dtree;
406
- static_d_desc.extra_bits = extra_dbits;
407
- static_bl_desc.extra_bits = extra_blbits;
408
- #endif*/
401
+ /*#ifdef NO_INIT_GLOBAL_POINTERS
402
+ static_l_desc.static_tree = static_ltree;
403
+ static_l_desc.extra_bits = extra_lbits;
404
+ static_d_desc.static_tree = static_dtree;
405
+ static_d_desc.extra_bits = extra_dbits;
406
+ static_bl_desc.extra_bits = extra_blbits;
407
+ #endif*/
409
408
 
410
409
  /* Initialize the mapping length (0..255) -> length code (0..28) */
411
410
  length = 0;
412
411
  for (code = 0; code < LENGTH_CODES - 1; code++) {
413
412
  base_length[code] = length;
414
- for (n = 0; n < 1 << extra_lbits[code]; n++) {
413
+ for (n = 0; n < (1 << extra_lbits[code]); n++) {
415
414
  _length_code[length++] = code;
416
415
  }
417
416
  }
@@ -426,7 +425,7 @@ function tr_static_init() {
426
425
  dist = 0;
427
426
  for (code = 0; code < 16; code++) {
428
427
  base_dist[code] = dist;
429
- for (n = 0; n < 1 << extra_dbits[code]; n++) {
428
+ for (n = 0; n < (1 << extra_dbits[code]); n++) {
430
429
  _dist_code[dist++] = code;
431
430
  }
432
431
  }
@@ -434,7 +433,7 @@ function tr_static_init() {
434
433
  dist >>= 7; /* from now on, all distances are divided by 128 */
435
434
  for (; code < D_CODES; code++) {
436
435
  base_dist[code] = dist << 7;
437
- for (n = 0; n < 1 << extra_dbits[code] - 7; n++) {
436
+ for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) {
438
437
  _dist_code[256 + dist++] = code;
439
438
  }
440
439
  }
@@ -444,24 +443,25 @@ function tr_static_init() {
444
443
  for (bits = 0; bits <= MAX_BITS; bits++) {
445
444
  bl_count[bits] = 0;
446
445
  }
446
+
447
447
  n = 0;
448
448
  while (n <= 143) {
449
- static_ltree[n * 2 + 1] /*.Len*/ = 8;
449
+ static_ltree[n * 2 + 1]/*.Len*/ = 8;
450
450
  n++;
451
451
  bl_count[8]++;
452
452
  }
453
453
  while (n <= 255) {
454
- static_ltree[n * 2 + 1] /*.Len*/ = 9;
454
+ static_ltree[n * 2 + 1]/*.Len*/ = 9;
455
455
  n++;
456
456
  bl_count[9]++;
457
457
  }
458
458
  while (n <= 279) {
459
- static_ltree[n * 2 + 1] /*.Len*/ = 7;
459
+ static_ltree[n * 2 + 1]/*.Len*/ = 7;
460
460
  n++;
461
461
  bl_count[7]++;
462
462
  }
463
463
  while (n <= 287) {
464
- static_ltree[n * 2 + 1] /*.Len*/ = 8;
464
+ static_ltree[n * 2 + 1]/*.Len*/ = 8;
465
465
  n++;
466
466
  bl_count[8]++;
467
467
  }
@@ -473,18 +473,19 @@ function tr_static_init() {
473
473
 
474
474
  /* The static distance tree is trivial: */
475
475
  for (n = 0; n < D_CODES; n++) {
476
- static_dtree[n * 2 + 1] /*.Len*/ = 5;
477
- static_dtree[n * 2] /*.Code*/ = bi_reverse(n, 5);
476
+ static_dtree[n * 2 + 1]/*.Len*/ = 5;
477
+ static_dtree[n * 2]/*.Code*/ = bi_reverse(n, 5);
478
478
  }
479
479
 
480
480
  // Now data ready and we can init static trees
481
481
  static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS + 1, L_CODES, MAX_BITS);
482
- static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS);
483
- static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS);
482
+ static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS);
483
+ static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS);
484
484
 
485
485
  //static_init_done = true;
486
486
  }
487
487
 
488
+
488
489
  /* ===========================================================================
489
490
  * Initialize a new block.
490
491
  */
@@ -492,24 +493,21 @@ function init_block(s) {
492
493
  var n; /* iterates over tree elements */
493
494
 
494
495
  /* Initialize the trees. */
495
- for (n = 0; n < L_CODES; n++) {
496
- s.dyn_ltree[n * 2] /*.Freq*/ = 0;
497
- }
498
- for (n = 0; n < D_CODES; n++) {
499
- s.dyn_dtree[n * 2] /*.Freq*/ = 0;
500
- }
501
- for (n = 0; n < BL_CODES; n++) {
502
- s.bl_tree[n * 2] /*.Freq*/ = 0;
503
- }
504
- s.dyn_ltree[END_BLOCK * 2] /*.Freq*/ = 1;
496
+ for (n = 0; n < L_CODES; n++) { s.dyn_ltree[n * 2]/*.Freq*/ = 0; }
497
+ for (n = 0; n < D_CODES; n++) { s.dyn_dtree[n * 2]/*.Freq*/ = 0; }
498
+ for (n = 0; n < BL_CODES; n++) { s.bl_tree[n * 2]/*.Freq*/ = 0; }
499
+
500
+ s.dyn_ltree[END_BLOCK * 2]/*.Freq*/ = 1;
505
501
  s.opt_len = s.static_len = 0;
506
502
  s.last_lit = s.matches = 0;
507
503
  }
508
504
 
505
+
509
506
  /* ===========================================================================
510
507
  * Flush the bit buffer and align the output on a byte boundary
511
508
  */
512
- function bi_windup(s) {
509
+ function bi_windup(s)
510
+ {
513
511
  if (s.bi_valid > 8) {
514
512
  put_short(s, s.bi_buf);
515
513
  } else if (s.bi_valid > 0) {
@@ -530,15 +528,15 @@ function copy_block(s, buf, len, header)
530
528
  //unsigned len; /* its length */
531
529
  //int header; /* true if block header must be written */
532
530
  {
533
- bi_windup(s); /* align on byte boundary */
531
+ bi_windup(s); /* align on byte boundary */
534
532
 
535
533
  if (header) {
536
534
  put_short(s, len);
537
535
  put_short(s, ~len);
538
536
  }
539
- // while (len--) {
540
- // put_byte(s, *buf++);
541
- // }
537
+ // while (len--) {
538
+ // put_byte(s, *buf++);
539
+ // }
542
540
  utils.arraySet(s.pending_buf, s.window, buf, len, s.pending);
543
541
  s.pending += len;
544
542
  }
@@ -550,7 +548,8 @@ function copy_block(s, buf, len, header)
550
548
  function smaller(tree, n, m, depth) {
551
549
  var _n2 = n * 2;
552
550
  var _m2 = m * 2;
553
- return tree[_n2] /*.Freq*/ < tree[_m2] /*.Freq*/ || tree[_n2] /*.Freq*/ === tree[_m2] /*.Freq*/ && depth[n] <= depth[m];
551
+ return (tree[_n2]/*.Freq*/ < tree[_m2]/*.Freq*/ ||
552
+ (tree[_n2]/*.Freq*/ === tree[_m2]/*.Freq*/ && depth[n] <= depth[m]));
554
553
  }
555
554
 
556
555
  /* ===========================================================================
@@ -565,16 +564,15 @@ function pqdownheap(s, tree, k)
565
564
  // int k; /* node to move down */
566
565
  {
567
566
  var v = s.heap[k];
568
- var j = k << 1; /* left son of k */
567
+ var j = k << 1; /* left son of k */
569
568
  while (j <= s.heap_len) {
570
569
  /* Set j to the smallest of the two sons: */
571
- if (j < s.heap_len && smaller(tree, s.heap[j + 1], s.heap[j], s.depth)) {
570
+ if (j < s.heap_len &&
571
+ smaller(tree, s.heap[j + 1], s.heap[j], s.depth)) {
572
572
  j++;
573
573
  }
574
574
  /* Exit if v is smaller than both sons */
575
- if (smaller(tree, v, s.heap[j], s.depth)) {
576
- break;
577
- }
575
+ if (smaller(tree, v, s.heap[j], s.depth)) { break; }
578
576
 
579
577
  /* Exchange v with the smallest son */
580
578
  s.heap[k] = s.heap[j];
@@ -586,6 +584,7 @@ function pqdownheap(s, tree, k)
586
584
  s.heap[k] = v;
587
585
  }
588
586
 
587
+
589
588
  // inlined manually
590
589
  // var SMALLEST = 1;
591
590
 
@@ -597,17 +596,18 @@ function compress_block(s, ltree, dtree)
597
596
  // const ct_data *ltree; /* literal tree */
598
597
  // const ct_data *dtree; /* distance tree */
599
598
  {
600
- var dist; /* distance of matched string */
601
- var lc; /* match length or unmatched char (if dist == 0) */
602
- var lx = 0; /* running index in l_buf */
603
- var code; /* the code to send */
604
- var extra; /* number of extra bits to send */
599
+ var dist; /* distance of matched string */
600
+ var lc; /* match length or unmatched char (if dist == 0) */
601
+ var lx = 0; /* running index in l_buf */
602
+ var code; /* the code to send */
603
+ var extra; /* number of extra bits to send */
605
604
 
606
605
  if (s.last_lit !== 0) {
607
606
  do {
608
- dist = s.pending_buf[s.d_buf + lx * 2] << 8 | s.pending_buf[s.d_buf + lx * 2 + 1];
607
+ dist = (s.pending_buf[s.d_buf + lx * 2] << 8) | (s.pending_buf[s.d_buf + lx * 2 + 1]);
609
608
  lc = s.pending_buf[s.l_buf + lx];
610
609
  lx++;
610
+
611
611
  if (dist === 0) {
612
612
  send_code(s, lc, ltree); /* send a literal byte */
613
613
  //Tracecv(isgraph(lc), (stderr," '%c' ", lc));
@@ -618,28 +618,31 @@ function compress_block(s, ltree, dtree)
618
618
  extra = extra_lbits[code];
619
619
  if (extra !== 0) {
620
620
  lc -= base_length[code];
621
- send_bits(s, lc, extra); /* send the extra length bits */
621
+ send_bits(s, lc, extra); /* send the extra length bits */
622
622
  }
623
623
  dist--; /* dist is now the match distance - 1 */
624
624
  code = d_code(dist);
625
625
  //Assert (code < D_CODES, "bad d_code");
626
626
 
627
- send_code(s, code, dtree); /* send the distance code */
627
+ send_code(s, code, dtree); /* send the distance code */
628
628
  extra = extra_dbits[code];
629
629
  if (extra !== 0) {
630
630
  dist -= base_dist[code];
631
- send_bits(s, dist, extra); /* send the extra distance bits */
631
+ send_bits(s, dist, extra); /* send the extra distance bits */
632
632
  }
633
633
  } /* literal or match pair ? */
634
634
 
635
635
  /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
636
636
  //Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
637
637
  // "pendingBuf overflow");
638
+
638
639
  } while (lx < s.last_lit);
639
640
  }
641
+
640
642
  send_code(s, END_BLOCK, ltree);
641
643
  }
642
644
 
645
+
643
646
  /* ===========================================================================
644
647
  * Construct one Huffman tree and assigns the code bit strings and lengths.
645
648
  * Update the total bit length for the current block.
@@ -652,13 +655,13 @@ function build_tree(s, desc)
652
655
  // deflate_state *s;
653
656
  // tree_desc *desc; /* the tree descriptor */
654
657
  {
655
- var tree = desc.dyn_tree;
656
- var stree = desc.stat_desc.static_tree;
658
+ var tree = desc.dyn_tree;
659
+ var stree = desc.stat_desc.static_tree;
657
660
  var has_stree = desc.stat_desc.has_stree;
658
- var elems = desc.stat_desc.elems;
659
- var n, m; /* iterate over heap elements */
661
+ var elems = desc.stat_desc.elems;
662
+ var n, m; /* iterate over heap elements */
660
663
  var max_code = -1; /* largest code with non zero frequency */
661
- var node; /* new node being created */
664
+ var node; /* new node being created */
662
665
 
663
666
  /* Construct the initial heap, with least frequent element in
664
667
  * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
@@ -666,12 +669,14 @@ function build_tree(s, desc)
666
669
  */
667
670
  s.heap_len = 0;
668
671
  s.heap_max = HEAP_SIZE;
672
+
669
673
  for (n = 0; n < elems; n++) {
670
- if (tree[n * 2] /*.Freq*/ !== 0) {
674
+ if (tree[n * 2]/*.Freq*/ !== 0) {
671
675
  s.heap[++s.heap_len] = max_code = n;
672
676
  s.depth[n] = 0;
677
+
673
678
  } else {
674
- tree[n * 2 + 1] /*.Len*/ = 0;
679
+ tree[n * 2 + 1]/*.Len*/ = 0;
675
680
  }
676
681
  }
677
682
 
@@ -681,12 +686,13 @@ function build_tree(s, desc)
681
686
  * two codes of non zero frequency.
682
687
  */
683
688
  while (s.heap_len < 2) {
684
- node = s.heap[++s.heap_len] = max_code < 2 ? ++max_code : 0;
685
- tree[node * 2] /*.Freq*/ = 1;
689
+ node = s.heap[++s.heap_len] = (max_code < 2 ? ++max_code : 0);
690
+ tree[node * 2]/*.Freq*/ = 1;
686
691
  s.depth[node] = 0;
687
692
  s.opt_len--;
693
+
688
694
  if (has_stree) {
689
- s.static_len -= stree[node * 2 + 1] /*.Len*/;
695
+ s.static_len -= stree[node * 2 + 1]/*.Len*/;
690
696
  }
691
697
  /* node is 0 or 1 so it does not have extra bits */
692
698
  }
@@ -695,37 +701,37 @@ function build_tree(s, desc)
695
701
  /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
696
702
  * establish sub-heaps of increasing lengths:
697
703
  */
698
- for (n = s.heap_len >> 1 /*int /2*/; n >= 1; n--) {
699
- pqdownheap(s, tree, n);
700
- }
704
+ for (n = (s.heap_len >> 1/*int /2*/); n >= 1; n--) { pqdownheap(s, tree, n); }
701
705
 
702
706
  /* Construct the Huffman tree by repeatedly combining the least two
703
707
  * frequent nodes.
704
708
  */
705
- node = elems; /* next internal node of the tree */
709
+ node = elems; /* next internal node of the tree */
706
710
  do {
707
711
  //pqremove(s, tree, n); /* n = node of least frequency */
708
712
  /*** pqremove ***/
709
- n = s.heap[1 /*SMALLEST*/];
710
- s.heap[1 /*SMALLEST*/] = s.heap[s.heap_len--];
711
- pqdownheap(s, tree, 1 /*SMALLEST*/);
713
+ n = s.heap[1/*SMALLEST*/];
714
+ s.heap[1/*SMALLEST*/] = s.heap[s.heap_len--];
715
+ pqdownheap(s, tree, 1/*SMALLEST*/);
712
716
  /***/
713
717
 
714
- m = s.heap[1 /*SMALLEST*/]; /* m = node of next least frequency */
718
+ m = s.heap[1/*SMALLEST*/]; /* m = node of next least frequency */
715
719
 
716
720
  s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */
717
721
  s.heap[--s.heap_max] = m;
718
722
 
719
723
  /* Create a new node father of n and m */
720
- tree[node * 2] /*.Freq*/ = tree[n * 2] /*.Freq*/ + tree[m * 2] /*.Freq*/;
724
+ tree[node * 2]/*.Freq*/ = tree[n * 2]/*.Freq*/ + tree[m * 2]/*.Freq*/;
721
725
  s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;
722
- tree[n * 2 + 1] /*.Dad*/ = tree[m * 2 + 1] /*.Dad*/ = node;
726
+ tree[n * 2 + 1]/*.Dad*/ = tree[m * 2 + 1]/*.Dad*/ = node;
723
727
 
724
728
  /* and insert the new node in the heap */
725
- s.heap[1 /*SMALLEST*/] = node++;
726
- pqdownheap(s, tree, 1 /*SMALLEST*/);
729
+ s.heap[1/*SMALLEST*/] = node++;
730
+ pqdownheap(s, tree, 1/*SMALLEST*/);
731
+
727
732
  } while (s.heap_len >= 2);
728
- s.heap[--s.heap_max] = s.heap[1 /*SMALLEST*/];
733
+
734
+ s.heap[--s.heap_max] = s.heap[1/*SMALLEST*/];
729
735
 
730
736
  /* At this point, the fields freq and dad are set. We can now
731
737
  * generate the bit lengths.
@@ -736,6 +742,7 @@ function build_tree(s, desc)
736
742
  gen_codes(tree, max_code, s.bl_count);
737
743
  }
738
744
 
745
+
739
746
  /* ===========================================================================
740
747
  * Scan a literal or distance tree to determine the frequencies of the codes
741
748
  * in the bit length tree.
@@ -745,47 +752,55 @@ function scan_tree(s, tree, max_code)
745
752
  // ct_data *tree; /* the tree to be scanned */
746
753
  // int max_code; /* and its largest code of non zero frequency */
747
754
  {
748
- var n; /* iterates over all tree elements */
749
- var prevlen = -1; /* last emitted length */
750
- var curlen; /* length of current code */
755
+ var n; /* iterates over all tree elements */
756
+ var prevlen = -1; /* last emitted length */
757
+ var curlen; /* length of current code */
751
758
 
752
- var nextlen = tree[0 * 2 + 1] /*.Len*/; /* length of next code */
759
+ var nextlen = tree[0 * 2 + 1]/*.Len*/; /* length of next code */
753
760
 
754
- var count = 0; /* repeat count of the current code */
755
- var max_count = 7; /* max repeat count */
756
- var min_count = 4; /* min repeat count */
761
+ var count = 0; /* repeat count of the current code */
762
+ var max_count = 7; /* max repeat count */
763
+ var min_count = 4; /* min repeat count */
757
764
 
758
765
  if (nextlen === 0) {
759
766
  max_count = 138;
760
767
  min_count = 3;
761
768
  }
762
- tree[(max_code + 1) * 2 + 1] /*.Len*/ = 0xffff; /* guard */
769
+ tree[(max_code + 1) * 2 + 1]/*.Len*/ = 0xffff; /* guard */
763
770
 
764
771
  for (n = 0; n <= max_code; n++) {
765
772
  curlen = nextlen;
766
- nextlen = tree[(n + 1) * 2 + 1] /*.Len*/;
773
+ nextlen = tree[(n + 1) * 2 + 1]/*.Len*/;
774
+
767
775
  if (++count < max_count && curlen === nextlen) {
768
776
  continue;
777
+
769
778
  } else if (count < min_count) {
770
- s.bl_tree[curlen * 2] /*.Freq*/ += count;
779
+ s.bl_tree[curlen * 2]/*.Freq*/ += count;
780
+
771
781
  } else if (curlen !== 0) {
772
- if (curlen !== prevlen) {
773
- s.bl_tree[curlen * 2] /*.Freq*/++;
774
- }
775
- s.bl_tree[REP_3_6 * 2] /*.Freq*/++;
782
+
783
+ if (curlen !== prevlen) { s.bl_tree[curlen * 2]/*.Freq*/++; }
784
+ s.bl_tree[REP_3_6 * 2]/*.Freq*/++;
785
+
776
786
  } else if (count <= 10) {
777
- s.bl_tree[REPZ_3_10 * 2] /*.Freq*/++;
787
+ s.bl_tree[REPZ_3_10 * 2]/*.Freq*/++;
788
+
778
789
  } else {
779
- s.bl_tree[REPZ_11_138 * 2] /*.Freq*/++;
790
+ s.bl_tree[REPZ_11_138 * 2]/*.Freq*/++;
780
791
  }
792
+
781
793
  count = 0;
782
794
  prevlen = curlen;
795
+
783
796
  if (nextlen === 0) {
784
797
  max_count = 138;
785
798
  min_count = 3;
799
+
786
800
  } else if (curlen === nextlen) {
787
801
  max_count = 6;
788
802
  min_count = 3;
803
+
789
804
  } else {
790
805
  max_count = 7;
791
806
  min_count = 4;
@@ -793,6 +808,7 @@ function scan_tree(s, tree, max_code)
793
808
  }
794
809
  }
795
810
 
811
+
796
812
  /* ===========================================================================
797
813
  * Send a literal or distance tree in compressed form, using the codes in
798
814
  * bl_tree.
@@ -802,30 +818,32 @@ function send_tree(s, tree, max_code)
802
818
  // ct_data *tree; /* the tree to be scanned */
803
819
  // int max_code; /* and its largest code of non zero frequency */
804
820
  {
805
- var n; /* iterates over all tree elements */
806
- var prevlen = -1; /* last emitted length */
807
- var curlen; /* length of current code */
821
+ var n; /* iterates over all tree elements */
822
+ var prevlen = -1; /* last emitted length */
823
+ var curlen; /* length of current code */
808
824
 
809
- var nextlen = tree[0 * 2 + 1] /*.Len*/; /* length of next code */
825
+ var nextlen = tree[0 * 2 + 1]/*.Len*/; /* length of next code */
810
826
 
811
- var count = 0; /* repeat count of the current code */
812
- var max_count = 7; /* max repeat count */
813
- var min_count = 4; /* min repeat count */
827
+ var count = 0; /* repeat count of the current code */
828
+ var max_count = 7; /* max repeat count */
829
+ var min_count = 4; /* min repeat count */
814
830
 
815
- /* tree[max_code+1].Len = -1; */ /* guard already set */
831
+ /* tree[max_code+1].Len = -1; */ /* guard already set */
816
832
  if (nextlen === 0) {
817
833
  max_count = 138;
818
834
  min_count = 3;
819
835
  }
836
+
820
837
  for (n = 0; n <= max_code; n++) {
821
838
  curlen = nextlen;
822
- nextlen = tree[(n + 1) * 2 + 1] /*.Len*/;
839
+ nextlen = tree[(n + 1) * 2 + 1]/*.Len*/;
840
+
823
841
  if (++count < max_count && curlen === nextlen) {
824
842
  continue;
843
+
825
844
  } else if (count < min_count) {
826
- do {
827
- send_code(s, curlen, s.bl_tree);
828
- } while (--count !== 0);
845
+ do { send_code(s, curlen, s.bl_tree); } while (--count !== 0);
846
+
829
847
  } else if (curlen !== 0) {
830
848
  if (curlen !== prevlen) {
831
849
  send_code(s, curlen, s.bl_tree);
@@ -834,21 +852,26 @@ function send_tree(s, tree, max_code)
834
852
  //Assert(count >= 3 && count <= 6, " 3_6?");
835
853
  send_code(s, REP_3_6, s.bl_tree);
836
854
  send_bits(s, count - 3, 2);
855
+
837
856
  } else if (count <= 10) {
838
857
  send_code(s, REPZ_3_10, s.bl_tree);
839
858
  send_bits(s, count - 3, 3);
859
+
840
860
  } else {
841
861
  send_code(s, REPZ_11_138, s.bl_tree);
842
862
  send_bits(s, count - 11, 7);
843
863
  }
864
+
844
865
  count = 0;
845
866
  prevlen = curlen;
846
867
  if (nextlen === 0) {
847
868
  max_count = 138;
848
869
  min_count = 3;
870
+
849
871
  } else if (curlen === nextlen) {
850
872
  max_count = 6;
851
873
  min_count = 3;
874
+
852
875
  } else {
853
876
  max_count = 7;
854
877
  min_count = 4;
@@ -856,12 +879,13 @@ function send_tree(s, tree, max_code)
856
879
  }
857
880
  }
858
881
 
882
+
859
883
  /* ===========================================================================
860
884
  * Construct the Huffman tree for the bit lengths and return the index in
861
885
  * bl_order of the last bit length code to send.
862
886
  */
863
887
  function build_bl_tree(s) {
864
- var max_blindex; /* index of last bit length code of non zero freq */
888
+ var max_blindex; /* index of last bit length code of non zero freq */
865
889
 
866
890
  /* Determine the bit length frequencies for literal and distance trees */
867
891
  scan_tree(s, s.dyn_ltree, s.l_desc.max_code);
@@ -878,7 +902,7 @@ function build_bl_tree(s) {
878
902
  * 3 but the actual value used is 4.)
879
903
  */
880
904
  for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {
881
- if (s.bl_tree[bl_order[max_blindex] * 2 + 1] /*.Len*/ !== 0) {
905
+ if (s.bl_tree[bl_order[max_blindex] * 2 + 1]/*.Len*/ !== 0) {
882
906
  break;
883
907
  }
884
908
  }
@@ -890,6 +914,7 @@ function build_bl_tree(s) {
890
914
  return max_blindex;
891
915
  }
892
916
 
917
+
893
918
  /* ===========================================================================
894
919
  * Send the header for a block using dynamic Huffman trees: the counts, the
895
920
  * lengths of the bit length codes, the literal tree and the distance tree.
@@ -899,18 +924,18 @@ function send_all_trees(s, lcodes, dcodes, blcodes)
899
924
  // deflate_state *s;
900
925
  // int lcodes, dcodes, blcodes; /* number of codes for each tree */
901
926
  {
902
- var rank; /* index in bl_order */
927
+ var rank; /* index in bl_order */
903
928
 
904
929
  //Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
905
930
  //Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
906
931
  // "too many codes");
907
932
  //Tracev((stderr, "\nbl counts: "));
908
933
  send_bits(s, lcodes - 257, 5); /* not +255 as stated in appnote.txt */
909
- send_bits(s, dcodes - 1, 5);
910
- send_bits(s, blcodes - 4, 4); /* not -3 as stated in appnote.txt */
934
+ send_bits(s, dcodes - 1, 5);
935
+ send_bits(s, blcodes - 4, 4); /* not -3 as stated in appnote.txt */
911
936
  for (rank = 0; rank < blcodes; rank++) {
912
937
  //Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
913
- send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1] /*.Len*/, 3);
938
+ send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1]/*.Len*/, 3);
914
939
  }
915
940
  //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
916
941
 
@@ -921,6 +946,7 @@ function send_all_trees(s, lcodes, dcodes, blcodes)
921
946
  //Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
922
947
  }
923
948
 
949
+
924
950
  /* ===========================================================================
925
951
  * Check if the data type is TEXT or BINARY, using the following algorithm:
926
952
  * - TEXT if the two conditions below are satisfied:
@@ -944,17 +970,18 @@ function detect_data_type(s) {
944
970
 
945
971
  /* Check for non-textual ("black-listed") bytes. */
946
972
  for (n = 0; n <= 31; n++, black_mask >>>= 1) {
947
- if (black_mask & 1 && s.dyn_ltree[n * 2] /*.Freq*/ !== 0) {
973
+ if ((black_mask & 1) && (s.dyn_ltree[n * 2]/*.Freq*/ !== 0)) {
948
974
  return Z_BINARY;
949
975
  }
950
976
  }
951
977
 
952
978
  /* Check for textual ("white-listed") bytes. */
953
- if (s.dyn_ltree[9 * 2] /*.Freq*/ !== 0 || s.dyn_ltree[10 * 2] /*.Freq*/ !== 0 || s.dyn_ltree[13 * 2] /*.Freq*/ !== 0) {
979
+ if (s.dyn_ltree[9 * 2]/*.Freq*/ !== 0 || s.dyn_ltree[10 * 2]/*.Freq*/ !== 0 ||
980
+ s.dyn_ltree[13 * 2]/*.Freq*/ !== 0) {
954
981
  return Z_TEXT;
955
982
  }
956
983
  for (n = 32; n < LITERALS; n++) {
957
- if (s.dyn_ltree[n * 2] /*.Freq*/ !== 0) {
984
+ if (s.dyn_ltree[n * 2]/*.Freq*/ !== 0) {
958
985
  return Z_TEXT;
959
986
  }
960
987
  }
@@ -964,19 +991,25 @@ function detect_data_type(s) {
964
991
  */
965
992
  return Z_BINARY;
966
993
  }
994
+
995
+
967
996
  var static_init_done = false;
968
997
 
969
998
  /* ===========================================================================
970
999
  * Initialize the tree data structures for a new zlib stream.
971
1000
  */
972
- function _tr_init(s) {
1001
+ function _tr_init(s)
1002
+ {
1003
+
973
1004
  if (!static_init_done) {
974
1005
  tr_static_init();
975
1006
  static_init_done = true;
976
1007
  }
977
- s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc);
978
- s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc);
1008
+
1009
+ s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc);
1010
+ s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc);
979
1011
  s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc);
1012
+
980
1013
  s.bi_buf = 0;
981
1014
  s.bi_valid = 0;
982
1015
 
@@ -984,6 +1017,7 @@ function _tr_init(s) {
984
1017
  init_block(s);
985
1018
  }
986
1019
 
1020
+
987
1021
  /* ===========================================================================
988
1022
  * Send a stored block
989
1023
  */
@@ -993,10 +1027,11 @@ function _tr_stored_block(s, buf, stored_len, last)
993
1027
  //ulg stored_len; /* length of input block */
994
1028
  //int last; /* one if this is the last block for a file */
995
1029
  {
996
- send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3); /* send block type */
1030
+ send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3); /* send block type */
997
1031
  copy_block(s, buf, stored_len, true); /* with header */
998
1032
  }
999
1033
 
1034
+
1000
1035
  /* ===========================================================================
1001
1036
  * Send one empty static block to give enough lookahead for inflate.
1002
1037
  * This takes 10 bits, of which 7 may remain in the bit buffer.
@@ -1007,6 +1042,7 @@ function _tr_align(s) {
1007
1042
  bi_flush(s);
1008
1043
  }
1009
1044
 
1045
+
1010
1046
  /* ===========================================================================
1011
1047
  * Determine the best encoding for the current block: dynamic trees, static
1012
1048
  * trees or store, and output the encoded block to the zip file.
@@ -1017,11 +1053,12 @@ function _tr_flush_block(s, buf, stored_len, last)
1017
1053
  //ulg stored_len; /* length of input block */
1018
1054
  //int last; /* one if this is the last block for a file */
1019
1055
  {
1020
- var opt_lenb, static_lenb; /* opt_len and static_len in bytes */
1021
- var max_blindex = 0; /* index of last bit length code of non zero freq */
1056
+ var opt_lenb, static_lenb; /* opt_len and static_len in bytes */
1057
+ var max_blindex = 0; /* index of last bit length code of non zero freq */
1022
1058
 
1023
1059
  /* Build the Huffman trees unless a stored block is forced */
1024
1060
  if (s.level > 0) {
1061
+
1025
1062
  /* Check if the file is binary or text */
1026
1063
  if (s.strm.data_type === Z_UNKNOWN) {
1027
1064
  s.strm.data_type = detect_data_type(s);
@@ -1045,21 +1082,21 @@ function _tr_flush_block(s, buf, stored_len, last)
1045
1082
  max_blindex = build_bl_tree(s);
1046
1083
 
1047
1084
  /* Determine the best encoding. Compute the block lengths in bytes. */
1048
- opt_lenb = s.opt_len + 3 + 7 >>> 3;
1049
- static_lenb = s.static_len + 3 + 7 >>> 3;
1085
+ opt_lenb = (s.opt_len + 3 + 7) >>> 3;
1086
+ static_lenb = (s.static_len + 3 + 7) >>> 3;
1050
1087
 
1051
1088
  // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
1052
1089
  // opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
1053
1090
  // s->last_lit));
1054
1091
 
1055
- if (static_lenb <= opt_lenb) {
1056
- opt_lenb = static_lenb;
1057
- }
1092
+ if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }
1093
+
1058
1094
  } else {
1059
1095
  // Assert(buf != (char*)0, "lost buf");
1060
1096
  opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
1061
1097
  }
1062
- if (stored_len + 4 <= opt_lenb && buf !== -1) {
1098
+
1099
+ if ((stored_len + 4 <= opt_lenb) && (buf !== -1)) {
1063
1100
  /* 4: two words for the lengths */
1064
1101
 
1065
1102
  /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
@@ -1069,9 +1106,12 @@ function _tr_flush_block(s, buf, stored_len, last)
1069
1106
  * transform a block into a stored block.
1070
1107
  */
1071
1108
  _tr_stored_block(s, buf, stored_len, last);
1109
+
1072
1110
  } else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) {
1111
+
1073
1112
  send_bits(s, (STATIC_TREES << 1) + (last ? 1 : 0), 3);
1074
1113
  compress_block(s, static_ltree, static_dtree);
1114
+
1075
1115
  } else {
1076
1116
  send_bits(s, (DYN_TREES << 1) + (last ? 1 : 0), 3);
1077
1117
  send_all_trees(s, s.l_desc.max_code + 1, s.d_desc.max_code + 1, max_blindex + 1);
@@ -1082,6 +1122,7 @@ function _tr_flush_block(s, buf, stored_len, last)
1082
1122
  * and uLong implemented on 32 bits.
1083
1123
  */
1084
1124
  init_block(s);
1125
+
1085
1126
  if (last) {
1086
1127
  bi_windup(s);
1087
1128
  }
@@ -1100,51 +1141,55 @@ function _tr_tally(s, dist, lc)
1100
1141
  {
1101
1142
  //var out_length, in_length, dcode;
1102
1143
 
1103
- s.pending_buf[s.d_buf + s.last_lit * 2] = dist >>> 8 & 0xff;
1144
+ s.pending_buf[s.d_buf + s.last_lit * 2] = (dist >>> 8) & 0xff;
1104
1145
  s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff;
1146
+
1105
1147
  s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff;
1106
1148
  s.last_lit++;
1149
+
1107
1150
  if (dist === 0) {
1108
1151
  /* lc is the unmatched char */
1109
- s.dyn_ltree[lc * 2] /*.Freq*/++;
1152
+ s.dyn_ltree[lc * 2]/*.Freq*/++;
1110
1153
  } else {
1111
1154
  s.matches++;
1112
1155
  /* Here, lc is the match length - MIN_MATCH */
1113
- dist--; /* dist = match distance - 1 */
1156
+ dist--; /* dist = match distance - 1 */
1114
1157
  //Assert((ush)dist < (ush)MAX_DIST(s) &&
1115
1158
  // (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
1116
1159
  // (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
1117
1160
 
1118
- s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2] /*.Freq*/++;
1119
- s.dyn_dtree[d_code(dist) * 2] /*.Freq*/++;
1161
+ s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2]/*.Freq*/++;
1162
+ s.dyn_dtree[d_code(dist) * 2]/*.Freq*/++;
1120
1163
  }
1121
1164
 
1122
- // (!) This block is disabled in zlib defailts,
1123
- // don't enable it for binary compatibility
1124
-
1125
- //#ifdef TRUNCATE_BLOCK
1126
- // /* Try to guess if it is profitable to stop the current block here */
1127
- // if ((s.last_lit & 0x1fff) === 0 && s.level > 2) {
1128
- // /* Compute an upper bound for the compressed length */
1129
- // out_length = s.last_lit*8;
1130
- // in_length = s.strstart - s.block_start;
1131
- //
1132
- // for (dcode = 0; dcode < D_CODES; dcode++) {
1133
- // out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]);
1134
- // }
1135
- // out_length >>>= 3;
1136
- // //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
1137
- // // s->last_lit, in_length, out_length,
1138
- // // 100L - out_length*100L/in_length));
1139
- // if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) {
1140
- // return true;
1141
- // }
1142
- // }
1143
- //#endif
1144
-
1145
- return s.last_lit === s.lit_bufsize - 1;
1165
+ // (!) This block is disabled in zlib defailts,
1166
+ // don't enable it for binary compatibility
1167
+
1168
+ //#ifdef TRUNCATE_BLOCK
1169
+ // /* Try to guess if it is profitable to stop the current block here */
1170
+ // if ((s.last_lit & 0x1fff) === 0 && s.level > 2) {
1171
+ // /* Compute an upper bound for the compressed length */
1172
+ // out_length = s.last_lit*8;
1173
+ // in_length = s.strstart - s.block_start;
1174
+ //
1175
+ // for (dcode = 0; dcode < D_CODES; dcode++) {
1176
+ // out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]);
1177
+ // }
1178
+ // out_length >>>= 3;
1179
+ // //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
1180
+ // // s->last_lit, in_length, out_length,
1181
+ // // 100L - out_length*100L/in_length));
1182
+ // if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) {
1183
+ // return true;
1184
+ // }
1185
+ // }
1186
+ //#endif
1187
+
1188
+ return (s.last_lit === s.lit_bufsize - 1);
1146
1189
  /* We avoid equality with lit_bufsize because of wraparound at 64K
1147
1190
  * on 16 bit machines and because stored blocks are restricted to
1148
1191
  * 64K-1 bytes.
1149
1192
  */
1150
- }
1193
+ }
1194
+
1195
+ export { _tr_init, _tr_stored_block, _tr_flush_block, _tr_tally, _tr_align };