@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
  });
@@ -15,62 +14,52 @@ exports.deflateReset = deflateReset;
15
14
  exports.deflateResetKeep = deflateResetKeep;
16
15
  exports.deflateSetDictionary = deflateSetDictionary;
17
16
  exports.deflateSetHeader = deflateSetHeader;
18
-
19
17
  var utils = _interopRequireWildcard(require("../utils/common.js"));
20
-
21
18
  var trees = _interopRequireWildcard(require("./trees.js"));
22
-
23
19
  var _adler = _interopRequireDefault(require("./adler32.js"));
24
-
25
20
  var _crc = _interopRequireDefault(require("./crc32.js"));
26
-
27
21
  var _messages = _interopRequireDefault(require("./messages.js"));
28
-
29
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
30
-
31
23
  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); }
32
-
33
24
  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; }
34
-
35
25
  /* Public constants ==========================================================*/
36
-
37
26
  /* ===========================================================================*/
38
27
 
39
28
  /* Allowed flush values; see deflate() and inflate() below for details */
40
29
  var Z_NO_FLUSH = 0;
41
30
  exports.Z_NO_FLUSH = Z_NO_FLUSH;
42
- var Z_PARTIAL_FLUSH = 1; //export const Z_SYNC_FLUSH = 2;
43
-
31
+ var Z_PARTIAL_FLUSH = 1;
32
+ //export const Z_SYNC_FLUSH = 2;
44
33
  exports.Z_PARTIAL_FLUSH = Z_PARTIAL_FLUSH;
45
34
  var Z_FULL_FLUSH = 3;
46
35
  exports.Z_FULL_FLUSH = Z_FULL_FLUSH;
47
36
  var Z_FINISH = 4;
48
37
  exports.Z_FINISH = Z_FINISH;
49
- var Z_BLOCK = 5; //export const Z_TREES = 6;
38
+ var Z_BLOCK = 5;
39
+ //export const Z_TREES = 6;
50
40
 
51
41
  /* Return codes for the compression/decompression functions. Negative values
52
42
  * are errors, positive values are used for special but normal events.
53
43
  */
54
-
55
44
  exports.Z_BLOCK = Z_BLOCK;
56
45
  var Z_OK = 0;
57
46
  exports.Z_OK = Z_OK;
58
- var Z_STREAM_END = 1; //export const Z_NEED_DICT = 2;
47
+ var Z_STREAM_END = 1;
48
+ //export const Z_NEED_DICT = 2;
59
49
  //export const Z_ERRNO = -1;
60
-
61
50
  exports.Z_STREAM_END = Z_STREAM_END;
62
51
  var Z_STREAM_ERROR = -2;
63
52
  exports.Z_STREAM_ERROR = Z_STREAM_ERROR;
64
- var Z_DATA_ERROR = -3; //export const Z_MEM_ERROR = -4;
65
-
53
+ var Z_DATA_ERROR = -3;
54
+ //export const Z_MEM_ERROR = -4;
66
55
  exports.Z_DATA_ERROR = Z_DATA_ERROR;
67
- var Z_BUF_ERROR = -5; //export const Z_VERSION_ERROR = -6;
56
+ var Z_BUF_ERROR = -5;
57
+ //export const Z_VERSION_ERROR = -6;
68
58
 
69
59
  /* compression levels */
70
60
  //export const Z_NO_COMPRESSION = 0;
71
61
  //export const Z_BEST_SPEED = 1;
72
62
  //export const Z_BEST_COMPRESSION = 9;
73
-
74
63
  exports.Z_BUF_ERROR = Z_BUF_ERROR;
75
64
  var Z_DEFAULT_COMPRESSION = -1;
76
65
  exports.Z_DEFAULT_COMPRESSION = Z_DEFAULT_COMPRESSION;
@@ -83,45 +72,37 @@ exports.Z_RLE = Z_RLE;
83
72
  var Z_FIXED = 4;
84
73
  exports.Z_FIXED = Z_FIXED;
85
74
  var Z_DEFAULT_STRATEGY = 0;
75
+
86
76
  /* Possible values of the data_type field (though see inflate()) */
87
77
  //export const Z_BINARY = 0;
88
78
  //export const Z_TEXT = 1;
89
79
  //export const Z_ASCII = 1; // = Z_TEXT
90
-
91
80
  exports.Z_DEFAULT_STRATEGY = Z_DEFAULT_STRATEGY;
92
81
  var Z_UNKNOWN = 2;
93
- /* The deflate compression method */
94
82
 
83
+ /* The deflate compression method */
95
84
  exports.Z_UNKNOWN = Z_UNKNOWN;
96
85
  var Z_DEFLATED = 8;
97
- /*============================================================================*/
98
86
 
87
+ /*============================================================================*/
99
88
  exports.Z_DEFLATED = Z_DEFLATED;
100
89
  var MAX_MEM_LEVEL = 9;
101
90
  /* Maximum value for memLevel in deflateInit2 */
102
-
103
91
  var MAX_WBITS = 15;
104
92
  /* 32K LZ77 window */
105
-
106
93
  var DEF_MEM_LEVEL = 8;
107
94
  var LENGTH_CODES = 29;
108
95
  /* number of length codes, not counting the special END_BLOCK code */
109
-
110
96
  var LITERALS = 256;
111
97
  /* number of literal bytes 0..255 */
112
-
113
98
  var L_CODES = LITERALS + 1 + LENGTH_CODES;
114
99
  /* number of Literal or Length codes, including the END_BLOCK code */
115
-
116
100
  var D_CODES = 30;
117
101
  /* number of distance codes */
118
-
119
102
  var BL_CODES = 19;
120
103
  /* number of codes used to transfer the bit lengths */
121
-
122
104
  var HEAP_SIZE = 2 * L_CODES + 1;
123
105
  /* maximum heap size */
124
-
125
106
  var MAX_BITS = 15;
126
107
  /* All codes must not exceed MAX_BITS bits */
127
108
 
@@ -136,17 +117,10 @@ var COMMENT_STATE = 91;
136
117
  var HCRC_STATE = 103;
137
118
  var BUSY_STATE = 113;
138
119
  var FINISH_STATE = 666;
139
- var BS_NEED_MORE = 1;
140
- /* block not completed, need more input or more output */
141
-
142
- var BS_BLOCK_DONE = 2;
143
- /* block flush performed */
144
-
145
- var BS_FINISH_STARTED = 3;
146
- /* finish started, need only more output at next deflate */
147
-
148
- var BS_FINISH_DONE = 4;
149
- /* finish done, accept no more input or output */
120
+ var BS_NEED_MORE = 1; /* block not completed, need more input or more output */
121
+ var BS_BLOCK_DONE = 2; /* block flush performed */
122
+ var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */
123
+ var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */
150
124
 
151
125
  var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.
152
126
 
@@ -154,74 +128,64 @@ function err(strm, errorCode) {
154
128
  strm.msg = _messages["default"][errorCode];
155
129
  return errorCode;
156
130
  }
157
-
158
131
  function rank(f) {
159
132
  return (f << 1) - (f > 4 ? 9 : 0);
160
133
  }
161
-
162
134
  function zero(buf) {
163
135
  var len = buf.length;
164
-
165
136
  while (--len >= 0) {
166
137
  buf[len] = 0;
167
138
  }
168
139
  }
140
+
169
141
  /* =========================================================================
170
142
  * Flush as much pending output as possible. All deflate() output goes
171
143
  * through this function so some applications may wish to modify it
172
144
  * to avoid allocating a large strm->output buffer and copying into it.
173
145
  * (See also read_buf()).
174
146
  */
175
-
176
-
177
147
  function flush_pending(strm) {
178
- var s = strm.state; //_tr_flush_bits(s);
148
+ var s = strm.state;
179
149
 
150
+ //_tr_flush_bits(s);
180
151
  var len = s.pending;
181
-
182
152
  if (len > strm.avail_out) {
183
153
  len = strm.avail_out;
184
154
  }
185
-
186
155
  if (len === 0) {
187
156
  return;
188
157
  }
189
-
190
158
  utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);
191
159
  strm.next_out += len;
192
160
  s.pending_out += len;
193
161
  strm.total_out += len;
194
162
  strm.avail_out -= len;
195
163
  s.pending -= len;
196
-
197
164
  if (s.pending === 0) {
198
165
  s.pending_out = 0;
199
166
  }
200
167
  }
201
-
202
168
  function flush_block_only(s, last) {
203
169
  trees._tr_flush_block(s, s.block_start >= 0 ? s.block_start : -1, s.strstart - s.block_start, last);
204
-
205
170
  s.block_start = s.strstart;
206
171
  flush_pending(s.strm);
207
172
  }
208
-
209
173
  function put_byte(s, b) {
210
174
  s.pending_buf[s.pending++] = b;
211
175
  }
176
+
212
177
  /* =========================================================================
213
178
  * Put a short in the pending buffer. The 16-bit value is put in MSB order.
214
179
  * IN assertion: the stream state is correct and there is enough room in
215
180
  * pending_buf.
216
181
  */
217
-
218
-
219
182
  function putShortMSB(s, b) {
220
183
  // put_byte(s, (Byte)(b >> 8));
221
184
  // put_byte(s, (Byte)(b & 0xff));
222
185
  s.pending_buf[s.pending++] = b >>> 8 & 0xff;
223
186
  s.pending_buf[s.pending++] = b & 0xff;
224
187
  }
188
+
225
189
  /* ===========================================================================
226
190
  * Read a new buffer from the current input stream, update the adler32
227
191
  * and total number of bytes read. All deflate() input goes through
@@ -229,33 +193,28 @@ function putShortMSB(s, b) {
229
193
  * allocating a large strm->input buffer and copying from it.
230
194
  * (See also flush_pending()).
231
195
  */
232
-
233
-
234
196
  function read_buf(strm, buf, start, size) {
235
197
  var len = strm.avail_in;
236
-
237
198
  if (len > size) {
238
199
  len = size;
239
200
  }
240
-
241
201
  if (len === 0) {
242
202
  return 0;
243
203
  }
204
+ strm.avail_in -= len;
244
205
 
245
- strm.avail_in -= len; // zmemcpy(buf, strm->next_in, len);
246
-
206
+ // zmemcpy(buf, strm->next_in, len);
247
207
  utils.arraySet(buf, strm.input, strm.next_in, len, start);
248
-
249
208
  if (strm.state.wrap === 1) {
250
209
  strm.adler = (0, _adler["default"])(strm.adler, buf, len, start);
251
210
  } else if (strm.state.wrap === 2) {
252
211
  strm.adler = (0, _crc["default"])(strm.adler, buf, len, start);
253
212
  }
254
-
255
213
  strm.next_in += len;
256
214
  strm.total_in += len;
257
215
  return len;
258
216
  }
217
+
259
218
  /* ===========================================================================
260
219
  * Set match_start to the longest match starting at the given string and
261
220
  * return its length. Matches shorter or equal to prev_length are discarded,
@@ -265,34 +224,20 @@ function read_buf(strm, buf, start, size) {
265
224
  * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
266
225
  * OUT assertion: the match length is not greater than s->lookahead.
267
226
  */
268
-
269
-
270
227
  function longest_match(s, cur_match) {
271
- var chain_length = s.max_chain_length;
272
- /* max hash chain length */
273
-
274
- var scan = s.strstart;
275
- /* current string */
276
-
277
- var match;
278
- /* matched string */
279
-
280
- var len;
281
- /* length of current match */
282
-
283
- var best_len = s.prev_length;
284
- /* best match length so far */
285
-
286
- var nice_match = s.nice_match;
287
- /* stop if match long enough */
228
+ var chain_length = s.max_chain_length; /* max hash chain length */
229
+ var scan = s.strstart; /* current string */
230
+ var match; /* matched string */
231
+ var len; /* length of current match */
232
+ var best_len = s.prev_length; /* best match length so far */
233
+ var nice_match = s.nice_match; /* stop if match long enough */
234
+ var limit = s.strstart > s.w_size - MIN_LOOKAHEAD ? s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0 /*NIL*/;
288
235
 
289
- var limit = s.strstart > s.w_size - MIN_LOOKAHEAD ? s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0
290
- /*NIL*/
291
- ;
292
236
  var _win = s.window; // shortcut
293
237
 
294
238
  var wmask = s.w_mask;
295
239
  var prev = s.prev;
240
+
296
241
  /* Stop when cur_match becomes <= limit. To simplify the code,
297
242
  * we prevent matches with the string of window index 0.
298
243
  */
@@ -300,29 +245,29 @@ function longest_match(s, cur_match) {
300
245
  var strend = s.strstart + MAX_MATCH;
301
246
  var scan_end1 = _win[scan + best_len - 1];
302
247
  var scan_end = _win[scan + best_len];
248
+
303
249
  /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
304
250
  * It is easy to get rid of this optimization if necessary.
305
251
  */
306
252
  // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
307
253
 
308
254
  /* Do not waste too much time if we already have a good match: */
309
-
310
255
  if (s.prev_length >= s.good_match) {
311
256
  chain_length >>= 2;
312
257
  }
313
258
  /* Do not look for matches beyond the end of the input. This is necessary
314
259
  * to make deflate deterministic.
315
260
  */
316
-
317
-
318
261
  if (nice_match > s.lookahead) {
319
262
  nice_match = s.lookahead;
320
- } // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
263
+ }
321
264
 
265
+ // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
322
266
 
323
267
  do {
324
268
  // Assert(cur_match < s->strstart, "no future");
325
269
  match = cur_match;
270
+
326
271
  /* Skip to next match if the match length cannot increase
327
272
  * or if the match length is less than 2. Note that the checks below
328
273
  * for insufficient lookahead only occur occasionally for performance
@@ -335,47 +280,44 @@ function longest_match(s, cur_match) {
335
280
  if (_win[match + best_len] !== scan_end || _win[match + best_len - 1] !== scan_end1 || _win[match] !== _win[scan] || _win[++match] !== _win[scan + 1]) {
336
281
  continue;
337
282
  }
283
+
338
284
  /* The check at best_len-1 can be removed because it will be made
339
285
  * again later. (This heuristic is not always a win.)
340
286
  * It is not necessary to compare scan[2] and match[2] since they
341
287
  * are always equal when the other bytes match, given that
342
288
  * the hash keys are equal and that HASH_BITS >= 8.
343
289
  */
344
-
345
-
346
290
  scan += 2;
347
- match++; // Assert(*scan == *match, "match[2]?");
291
+ match++;
292
+ // Assert(*scan == *match, "match[2]?");
348
293
 
349
294
  /* We check for insufficient lookahead only every 8th comparison;
350
295
  * the 256th check will be made at strstart+258.
351
296
  */
297
+ do {
298
+ // Do nothing
299
+ } while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && scan < strend);
352
300
 
353
- do {// Do nothing
354
- } while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && scan < strend); // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
355
-
301
+ // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
356
302
 
357
303
  len = MAX_MATCH - (strend - scan);
358
304
  scan = strend - MAX_MATCH;
359
-
360
305
  if (len > best_len) {
361
306
  s.match_start = cur_match;
362
307
  best_len = len;
363
-
364
308
  if (len >= nice_match) {
365
309
  break;
366
310
  }
367
-
368
311
  scan_end1 = _win[scan + best_len - 1];
369
312
  scan_end = _win[scan + best_len];
370
313
  }
371
314
  } while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0);
372
-
373
315
  if (best_len <= s.lookahead) {
374
316
  return best_len;
375
317
  }
376
-
377
318
  return s.lookahead;
378
319
  }
320
+
379
321
  /* ===========================================================================
380
322
  * Fill the window when the lookahead becomes insufficient.
381
323
  * Updates strstart and lookahead.
@@ -386,15 +328,16 @@ function longest_match(s, cur_match) {
386
328
  * performed for at least two bytes (required for the zip translate_eol
387
329
  * option -- not supported here).
388
330
  */
389
-
390
-
391
331
  function fill_window(s) {
392
332
  var _w_size = s.w_size;
393
- var p, n, m, more, str; //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
333
+ var p, n, m, more, str;
334
+
335
+ //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
394
336
 
395
337
  do {
396
- more = s.window_size - s.lookahead - s.strstart; // JS ints have 32 bit, block below not needed
338
+ more = s.window_size - s.lookahead - s.strstart;
397
339
 
340
+ // JS ints have 32 bit, block below not needed
398
341
  /* Deal with !@#$% 64K limit: */
399
342
  //if (sizeof(int) <= 2) {
400
343
  // if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
@@ -411,14 +354,13 @@ function fill_window(s) {
411
354
  /* If the window is almost full and there is insufficient lookahead,
412
355
  * move the upper half to the lower one to make room in the upper half.
413
356
  */
414
-
415
357
  if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {
416
358
  utils.arraySet(s.window, s.window, _w_size, _w_size, 0);
417
359
  s.match_start -= _w_size;
418
360
  s.strstart -= _w_size;
419
361
  /* we now have strstart >= MAX_DIST */
420
-
421
362
  s.block_start -= _w_size;
363
+
422
364
  /* Slide the hash table (could be avoided with 32 bit values
423
365
  at the expense of memory usage). We slide even when level == 0
424
366
  to keep the hash table consistent if we switch back to level > 0
@@ -428,15 +370,12 @@ function fill_window(s) {
428
370
 
429
371
  n = s.hash_size;
430
372
  p = n;
431
-
432
373
  do {
433
374
  m = s.head[--p];
434
375
  s.head[p] = m >= _w_size ? m - _w_size : 0;
435
376
  } while (--n);
436
-
437
377
  n = _w_size;
438
378
  p = n;
439
-
440
379
  do {
441
380
  m = s.prev[--p];
442
381
  s.prev[p] = m >= _w_size ? m - _w_size : 0;
@@ -444,13 +383,12 @@ function fill_window(s) {
444
383
  * its value will never be used.
445
384
  */
446
385
  } while (--n);
447
-
448
386
  more += _w_size;
449
387
  }
450
-
451
388
  if (s.strm.avail_in === 0) {
452
389
  break;
453
390
  }
391
+
454
392
  /* If there was no sliding:
455
393
  * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
456
394
  * more == window_size - lookahead - strstart
@@ -463,21 +401,19 @@ function fill_window(s) {
463
401
  * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
464
402
  */
465
403
  //Assert(more >= 2, "more < 2");
466
-
467
-
468
404
  n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);
469
405
  s.lookahead += n;
470
- /* Initialize the hash value now that we have some input: */
471
406
 
407
+ /* Initialize the hash value now that we have some input: */
472
408
  if (s.lookahead + s.insert >= MIN_MATCH) {
473
409
  str = s.strstart - s.insert;
474
410
  s.ins_h = s.window[str];
475
- /* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */
476
411
 
477
- s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + 1]) & s.hash_mask; //#if MIN_MATCH != 3
412
+ /* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */
413
+ s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + 1]) & s.hash_mask;
414
+ //#if MIN_MATCH != 3
478
415
  // Call update_hash() MIN_MATCH-3 more times
479
416
  //#endif
480
-
481
417
  while (s.insert) {
482
418
  /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
483
419
  s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
@@ -485,7 +421,6 @@ function fill_window(s) {
485
421
  s.head[s.ins_h] = str;
486
422
  str++;
487
423
  s.insert--;
488
-
489
424
  if (s.lookahead + s.insert < MIN_MATCH) {
490
425
  break;
491
426
  }
@@ -494,8 +429,8 @@ function fill_window(s) {
494
429
  /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
495
430
  * but this is not important since only literal bytes will be emitted.
496
431
  */
497
-
498
432
  } while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0);
433
+
499
434
  /* If the WIN_INIT bytes after the end of the current data have never been
500
435
  * written, then zero those bytes in order to avoid memory check reports of
501
436
  * the use of uninitialized (or uninitialised as Julian writes) bytes by
@@ -532,8 +467,8 @@ function fill_window(s) {
532
467
  //
533
468
  // Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
534
469
  // "not enough room for search");
535
-
536
470
  }
471
+
537
472
  /* ===========================================================================
538
473
  * Copy without compression as much as possible from the input stream, return
539
474
  * the current block state.
@@ -543,20 +478,16 @@ function fill_window(s) {
543
478
  * NOTE: this function should be optimized to avoid extra copying from
544
479
  * window to pending_buf.
545
480
  */
546
-
547
-
548
481
  function deflate_stored(s, flush) {
549
482
  /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
550
483
  * to pending_buf_size, and each stored block has a 5 byte header:
551
484
  */
552
485
  var max_block_size = 0xffff;
553
-
554
486
  if (max_block_size > s.pending_buf_size - 5) {
555
487
  max_block_size = s.pending_buf_size - 5;
556
488
  }
557
- /* Copy as much as possible from input to output: */
558
-
559
489
 
490
+ /* Copy as much as possible from input to output: */
560
491
  for (;;) {
561
492
  /* Fill the window as much as possible: */
562
493
  if (s.lookahead <= 1) {
@@ -566,86 +497,70 @@ function deflate_stored(s, flush) {
566
497
  // s.block_start >= s.w_size)) {
567
498
  // throw new Error("slide too late");
568
499
  // }
569
- fill_window(s);
570
500
 
501
+ fill_window(s);
571
502
  if (s.lookahead === 0 && flush === Z_NO_FLUSH) {
572
503
  return BS_NEED_MORE;
573
504
  }
574
-
575
505
  if (s.lookahead === 0) {
576
506
  break;
577
507
  }
578
508
  /* flush the current block */
579
-
580
- } //Assert(s->block_start >= 0L, "block gone");
509
+ }
510
+ //Assert(s->block_start >= 0L, "block gone");
581
511
  // if (s.block_start < 0) throw new Error("block gone");
582
512
 
583
-
584
513
  s.strstart += s.lookahead;
585
514
  s.lookahead = 0;
586
- /* Emit a stored block if pending_buf will be full: */
587
515
 
516
+ /* Emit a stored block if pending_buf will be full: */
588
517
  var max_start = s.block_start + max_block_size;
589
-
590
518
  if (s.strstart === 0 || s.strstart >= max_start) {
591
519
  /* strstart == 0 is possible when wraparound on 16-bit machine */
592
520
  s.lookahead = s.strstart - max_start;
593
521
  s.strstart = max_start;
594
522
  /*** FLUSH_BLOCK(s, 0); ***/
595
-
596
523
  flush_block_only(s, false);
597
-
598
524
  if (s.strm.avail_out === 0) {
599
525
  return BS_NEED_MORE;
600
526
  }
601
527
  /***/
602
-
603
528
  }
604
529
  /* Flush if we may have to slide, otherwise block_start may become
605
530
  * negative and the data will be gone:
606
531
  */
607
-
608
-
609
532
  if (s.strstart - s.block_start >= s.w_size - MIN_LOOKAHEAD) {
610
533
  /*** FLUSH_BLOCK(s, 0); ***/
611
534
  flush_block_only(s, false);
612
-
613
535
  if (s.strm.avail_out === 0) {
614
536
  return BS_NEED_MORE;
615
537
  }
616
538
  /***/
617
-
618
539
  }
619
540
  }
620
541
 
621
542
  s.insert = 0;
622
-
623
543
  if (flush === Z_FINISH) {
624
544
  /*** FLUSH_BLOCK(s, 1); ***/
625
545
  flush_block_only(s, true);
626
-
627
546
  if (s.strm.avail_out === 0) {
628
547
  return BS_FINISH_STARTED;
629
548
  }
630
549
  /***/
631
-
632
-
633
550
  return BS_FINISH_DONE;
634
551
  }
635
-
636
552
  if (s.strstart > s.block_start) {
637
553
  /*** FLUSH_BLOCK(s, 0); ***/
638
554
  flush_block_only(s, false);
639
-
640
555
  if (s.strm.avail_out === 0) {
641
556
  return BS_NEED_MORE;
642
557
  }
643
558
  /***/
644
-
645
559
  }
646
560
 
647
561
  return BS_NEED_MORE;
648
562
  }
563
+
649
564
  /* ===========================================================================
650
565
  * Compress as much as possible from the input stream, return the current
651
566
  * block state.
@@ -653,14 +568,9 @@ function deflate_stored(s, flush) {
653
568
  * new strings in the dictionary only for unmatched strings or for short
654
569
  * matches. It is used only for the fast compression options.
655
570
  */
656
-
657
-
658
571
  function deflate_fast(s, flush) {
659
- var hash_head;
660
- /* head of the hash chain */
661
-
662
- var bflush;
663
- /* set if current block must be flushed */
572
+ var hash_head; /* head of the hash chain */
573
+ var bflush; /* set if current block must be flushed */
664
574
 
665
575
  for (;;) {
666
576
  /* Make sure that we always have enough lookahead, except
@@ -670,25 +580,18 @@ function deflate_fast(s, flush) {
670
580
  */
671
581
  if (s.lookahead < MIN_LOOKAHEAD) {
672
582
  fill_window(s);
673
-
674
583
  if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
675
584
  return BS_NEED_MORE;
676
585
  }
677
-
678
586
  if (s.lookahead === 0) {
679
- break;
680
- /* flush the current block */
587
+ break; /* flush the current block */
681
588
  }
682
589
  }
590
+
683
591
  /* Insert the string window[strstart .. strstart+2] in the
684
592
  * dictionary, and set hash_head to the head of the hash chain:
685
593
  */
686
-
687
-
688
- hash_head = 0
689
- /*NIL*/
690
- ;
691
-
594
+ hash_head = 0 /*NIL*/;
692
595
  if (s.lookahead >= MIN_MATCH) {
693
596
  /*** INSERT_STRING(s, s.strstart, hash_head); ***/
694
597
  s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
@@ -696,14 +599,11 @@ function deflate_fast(s, flush) {
696
599
  s.head[s.ins_h] = s.strstart;
697
600
  /***/
698
601
  }
602
+
699
603
  /* Find the longest match, discarding those <= prev_length.
700
604
  * At this point we have always match_length < MIN_MATCH
701
605
  */
702
-
703
-
704
- if (hash_head !== 0
705
- /*NIL*/
706
- && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD) {
606
+ if (hash_head !== 0 /*NIL*/ && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD) {
707
607
  /* To simplify the code, we prevent matches with the string
708
608
  * of window index 0 (in particular we have to avoid a match
709
609
  * of the string with itself at the start of the input file).
@@ -719,41 +619,34 @@ function deflate_fast(s, flush) {
719
619
  s.match_length - MIN_MATCH, bflush); ***/
720
620
  bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);
721
621
  s.lookahead -= s.match_length;
622
+
722
623
  /* Insert new strings in the hash table only if the match length
723
624
  * is not too large. This saves time but degrades compression.
724
625
  */
725
-
726
- if (s.match_length <= s.max_lazy_match
727
- /*max_insert_length*/
728
- && s.lookahead >= MIN_MATCH) {
729
- s.match_length--;
730
- /* string at strstart already in table */
731
-
626
+ if (s.match_length <= s.max_lazy_match /*max_insert_length*/ && s.lookahead >= MIN_MATCH) {
627
+ s.match_length--; /* string at strstart already in table */
732
628
  do {
733
629
  s.strstart++;
734
630
  /*** INSERT_STRING(s, s.strstart, hash_head); ***/
735
-
736
631
  s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
737
632
  hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
738
633
  s.head[s.ins_h] = s.strstart;
739
634
  /***/
740
-
741
635
  /* strstart never exceeds WSIZE-MAX_MATCH, so there are
742
636
  * always MIN_MATCH bytes ahead.
743
637
  */
744
638
  } while (--s.match_length !== 0);
745
-
746
639
  s.strstart++;
747
640
  } else {
748
641
  s.strstart += s.match_length;
749
642
  s.match_length = 0;
750
643
  s.ins_h = s.window[s.strstart];
751
644
  /* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */
645
+ s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + 1]) & s.hash_mask;
752
646
 
753
- s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + 1]) & s.hash_mask; //#if MIN_MATCH != 3
647
+ //#if MIN_MATCH != 3
754
648
  // Call UPDATE_HASH() MIN_MATCH-3 more times
755
649
  //#endif
756
-
757
650
  /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
758
651
  * matter since it will be recomputed at next deflate call.
759
652
  */
@@ -761,70 +654,55 @@ function deflate_fast(s, flush) {
761
654
  } else {
762
655
  /* No match, output a literal byte */
763
656
  //Tracevv((stderr,"%c", s.window[s.strstart]));
764
-
765
657
  /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
766
658
  bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
767
659
  s.lookahead--;
768
660
  s.strstart++;
769
661
  }
770
-
771
662
  if (bflush) {
772
663
  /*** FLUSH_BLOCK(s, 0); ***/
773
664
  flush_block_only(s, false);
774
-
775
665
  if (s.strm.avail_out === 0) {
776
666
  return BS_NEED_MORE;
777
667
  }
778
668
  /***/
779
-
780
669
  }
781
670
  }
782
671
 
783
672
  s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;
784
-
785
673
  if (flush === Z_FINISH) {
786
674
  /*** FLUSH_BLOCK(s, 1); ***/
787
675
  flush_block_only(s, true);
788
-
789
676
  if (s.strm.avail_out === 0) {
790
677
  return BS_FINISH_STARTED;
791
678
  }
792
679
  /***/
793
-
794
-
795
680
  return BS_FINISH_DONE;
796
681
  }
797
-
798
682
  if (s.last_lit) {
799
683
  /*** FLUSH_BLOCK(s, 0); ***/
800
684
  flush_block_only(s, false);
801
-
802
685
  if (s.strm.avail_out === 0) {
803
686
  return BS_NEED_MORE;
804
687
  }
805
688
  /***/
806
-
807
689
  }
808
690
 
809
691
  return BS_BLOCK_DONE;
810
692
  }
693
+
811
694
  /* ===========================================================================
812
695
  * Same as above, but achieves better compression. We use a lazy
813
696
  * evaluation for matches: a match is finally adopted only if there is
814
697
  * no better match at the next window position.
815
698
  */
816
-
817
-
818
699
  function deflate_slow(s, flush) {
819
- var hash_head;
820
- /* head of hash chain */
821
-
822
- var bflush;
823
- /* set if current block must be flushed */
700
+ var hash_head; /* head of hash chain */
701
+ var bflush; /* set if current block must be flushed */
824
702
 
825
703
  var max_insert;
826
- /* Process the input block. */
827
704
 
705
+ /* Process the input block. */
828
706
  for (;;) {
829
707
  /* Make sure that we always have enough lookahead, except
830
708
  * at the end of the input file. We need MAX_MATCH bytes
@@ -833,26 +711,18 @@ function deflate_slow(s, flush) {
833
711
  */
834
712
  if (s.lookahead < MIN_LOOKAHEAD) {
835
713
  fill_window(s);
836
-
837
714
  if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
838
715
  return BS_NEED_MORE;
839
716
  }
840
-
841
717
  if (s.lookahead === 0) {
842
718
  break;
843
- }
844
- /* flush the current block */
845
-
719
+ } /* flush the current block */
846
720
  }
721
+
847
722
  /* Insert the string window[strstart .. strstart+2] in the
848
723
  * dictionary, and set hash_head to the head of the hash chain:
849
724
  */
850
-
851
-
852
- hash_head = 0
853
- /*NIL*/
854
- ;
855
-
725
+ hash_head = 0 /*NIL*/;
856
726
  if (s.lookahead >= MIN_MATCH) {
857
727
  /*** INSERT_STRING(s, s.strstart, hash_head); ***/
858
728
  s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
@@ -860,19 +730,13 @@ function deflate_slow(s, flush) {
860
730
  s.head[s.ins_h] = s.strstart;
861
731
  /***/
862
732
  }
733
+
863
734
  /* Find the longest match, discarding those <= prev_length.
864
735
  */
865
-
866
-
867
736
  s.prev_length = s.match_length;
868
737
  s.prev_match = s.match_start;
869
738
  s.match_length = MIN_MATCH - 1;
870
-
871
- if (hash_head !== 0
872
- /*NIL*/
873
- && s.prev_length < s.max_lazy_match && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD
874
- /*MAX_DIST(s)*/
875
- ) {
739
+ if (hash_head !== 0 /*NIL*/ && s.prev_length < s.max_lazy_match && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD /*MAX_DIST(s)*/) {
876
740
  /* To simplify the code, we prevent matches with the string
877
741
  * of window index 0 (in particular we have to avoid a match
878
742
  * of the string with itself at the start of the input file).
@@ -880,9 +744,7 @@ function deflate_slow(s, flush) {
880
744
  s.match_length = longest_match(s, hash_head);
881
745
  /* longest_match() sets match_start */
882
746
 
883
- if (s.match_length <= 5 && (s.strategy === Z_FILTERED || s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096
884
- /*TOO_FAR*/
885
- )) {
747
+ if (s.match_length <= 5 && (s.strategy === Z_FILTERED || s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096 /*TOO_FAR*/)) {
886
748
  /* If prev_match is also MIN_MATCH, match_start is garbage
887
749
  * but we will ignore the current match anyway.
888
750
  */
@@ -892,26 +754,22 @@ function deflate_slow(s, flush) {
892
754
  /* If there was a match at the previous step and the current
893
755
  * match is not better, output the previous match:
894
756
  */
895
-
896
-
897
757
  if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) {
898
758
  max_insert = s.strstart + s.lookahead - MIN_MATCH;
899
759
  /* Do not insert strings in hash table beyond this. */
760
+
900
761
  //check_match(s, s.strstart-1, s.prev_match, s.prev_length);
901
762
 
902
763
  /***_tr_tally_dist(s, s.strstart - 1 - s.prev_match,
903
764
  s.prev_length - MIN_MATCH, bflush);***/
904
-
905
765
  bflush = trees._tr_tally(s, s.strstart - 1 - s.prev_match, s.prev_length - MIN_MATCH);
906
766
  /* Insert in hash table all strings up to the end of the match.
907
767
  * strstart-1 and strstart are already inserted. If there is not
908
768
  * enough lookahead, the last two strings are not inserted in
909
769
  * the hash table.
910
770
  */
911
-
912
771
  s.lookahead -= s.prev_length - 1;
913
772
  s.prev_length -= 2;
914
-
915
773
  do {
916
774
  if (++s.strstart <= max_insert) {
917
775
  /*** INSERT_STRING(s, s.strstart, hash_head); ***/
@@ -921,20 +779,16 @@ function deflate_slow(s, flush) {
921
779
  /***/
922
780
  }
923
781
  } while (--s.prev_length !== 0);
924
-
925
782
  s.match_available = 0;
926
783
  s.match_length = MIN_MATCH - 1;
927
784
  s.strstart++;
928
-
929
785
  if (bflush) {
930
786
  /*** FLUSH_BLOCK(s, 0); ***/
931
787
  flush_block_only(s, false);
932
-
933
788
  if (s.strm.avail_out === 0) {
934
789
  return BS_NEED_MORE;
935
790
  }
936
791
  /***/
937
-
938
792
  }
939
793
  } else if (s.match_available) {
940
794
  /* If there was no match at the previous position, output a
@@ -942,10 +796,8 @@ function deflate_slow(s, flush) {
942
796
  * is longer, truncate the previous match to a single literal.
943
797
  */
944
798
  //Tracevv((stderr,"%c", s->window[s->strstart-1]));
945
-
946
799
  /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
947
800
  bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
948
-
949
801
  if (bflush) {
950
802
  /*** FLUSH_BLOCK_ONLY(s, 0) ***/
951
803
  flush_block_only(s, false);
@@ -954,7 +806,6 @@ function deflate_slow(s, flush) {
954
806
 
955
807
  s.strstart++;
956
808
  s.lookahead--;
957
-
958
809
  if (s.strm.avail_out === 0) {
959
810
  return BS_NEED_MORE;
960
811
  }
@@ -966,64 +817,47 @@ function deflate_slow(s, flush) {
966
817
  s.strstart++;
967
818
  s.lookahead--;
968
819
  }
969
- } //Assert (flush != Z_NO_FLUSH, "no flush?");
970
-
971
-
820
+ }
821
+ //Assert (flush != Z_NO_FLUSH, "no flush?");
972
822
  if (s.match_available) {
973
823
  //Tracevv((stderr,"%c", s->window[s->strstart-1]));
974
-
975
824
  /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
976
825
  bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
977
826
  s.match_available = 0;
978
827
  }
979
-
980
828
  s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;
981
-
982
829
  if (flush === Z_FINISH) {
983
830
  /*** FLUSH_BLOCK(s, 1); ***/
984
831
  flush_block_only(s, true);
985
-
986
832
  if (s.strm.avail_out === 0) {
987
833
  return BS_FINISH_STARTED;
988
834
  }
989
835
  /***/
990
-
991
-
992
836
  return BS_FINISH_DONE;
993
837
  }
994
-
995
838
  if (s.last_lit) {
996
839
  /*** FLUSH_BLOCK(s, 0); ***/
997
840
  flush_block_only(s, false);
998
-
999
841
  if (s.strm.avail_out === 0) {
1000
842
  return BS_NEED_MORE;
1001
843
  }
1002
844
  /***/
1003
-
1004
845
  }
1005
846
 
1006
847
  return BS_BLOCK_DONE;
1007
848
  }
849
+
1008
850
  /* ===========================================================================
1009
851
  * For Z_RLE, simply look for runs of bytes, generate matches only of distance
1010
852
  * one. Do not maintain a hash table. (It will be regenerated if this run of
1011
853
  * deflate switches away from Z_RLE.)
1012
854
  */
1013
-
1014
-
1015
855
  function deflate_rle(s, flush) {
1016
- var bflush;
1017
- /* set if current block must be flushed */
1018
-
1019
- var prev;
1020
- /* byte at distance one to match */
1021
-
1022
- var scan, strend;
1023
- /* scan goes up to strend for length of run */
856
+ var bflush; /* set if current block must be flushed */
857
+ var prev; /* byte at distance one to match */
858
+ var scan, strend; /* scan goes up to strend for length of run */
1024
859
 
1025
860
  var _win = s.window;
1026
-
1027
861
  for (;;) {
1028
862
  /* Make sure that we always have enough lookahead, except
1029
863
  * at the end of the input file. We need MAX_MATCH bytes
@@ -1031,43 +865,33 @@ function deflate_rle(s, flush) {
1031
865
  */
1032
866
  if (s.lookahead <= MAX_MATCH) {
1033
867
  fill_window(s);
1034
-
1035
868
  if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) {
1036
869
  return BS_NEED_MORE;
1037
870
  }
1038
-
1039
871
  if (s.lookahead === 0) {
1040
872
  break;
1041
- }
1042
- /* flush the current block */
1043
-
873
+ } /* flush the current block */
1044
874
  }
1045
- /* See how many times the previous byte repeats */
1046
-
1047
875
 
876
+ /* See how many times the previous byte repeats */
1048
877
  s.match_length = 0;
1049
-
1050
878
  if (s.lookahead >= MIN_MATCH && s.strstart > 0) {
1051
879
  scan = s.strstart - 1;
1052
880
  prev = _win[scan];
1053
-
1054
881
  if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) {
1055
882
  strend = s.strstart + MAX_MATCH;
1056
-
1057
- do {// Do nothing
883
+ do {
884
+ // Do nothing
1058
885
  } while (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && scan < strend);
1059
-
1060
886
  s.match_length = MAX_MATCH - (strend - scan);
1061
-
1062
887
  if (s.match_length > s.lookahead) {
1063
888
  s.match_length = s.lookahead;
1064
889
  }
1065
- } //Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
1066
-
890
+ }
891
+ //Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
1067
892
  }
1068
- /* Emit match if have run of MIN_MATCH or longer, else emit literal */
1069
-
1070
893
 
894
+ /* Emit match if have run of MIN_MATCH or longer, else emit literal */
1071
895
  if (s.match_length >= MIN_MATCH) {
1072
896
  //check_match(s, s.strstart, s.strstart - 1, s.match_length);
1073
897
 
@@ -1079,135 +903,106 @@ function deflate_rle(s, flush) {
1079
903
  } else {
1080
904
  /* No match, output a literal byte */
1081
905
  //Tracevv((stderr,"%c", s->window[s->strstart]));
1082
-
1083
906
  /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
1084
907
  bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
1085
908
  s.lookahead--;
1086
909
  s.strstart++;
1087
910
  }
1088
-
1089
911
  if (bflush) {
1090
912
  /*** FLUSH_BLOCK(s, 0); ***/
1091
913
  flush_block_only(s, false);
1092
-
1093
914
  if (s.strm.avail_out === 0) {
1094
915
  return BS_NEED_MORE;
1095
916
  }
1096
917
  /***/
1097
-
1098
918
  }
1099
919
  }
1100
920
 
1101
921
  s.insert = 0;
1102
-
1103
922
  if (flush === Z_FINISH) {
1104
923
  /*** FLUSH_BLOCK(s, 1); ***/
1105
924
  flush_block_only(s, true);
1106
-
1107
925
  if (s.strm.avail_out === 0) {
1108
926
  return BS_FINISH_STARTED;
1109
927
  }
1110
928
  /***/
1111
-
1112
-
1113
929
  return BS_FINISH_DONE;
1114
930
  }
1115
-
1116
931
  if (s.last_lit) {
1117
932
  /*** FLUSH_BLOCK(s, 0); ***/
1118
933
  flush_block_only(s, false);
1119
-
1120
934
  if (s.strm.avail_out === 0) {
1121
935
  return BS_NEED_MORE;
1122
936
  }
1123
937
  /***/
1124
-
1125
938
  }
1126
939
 
1127
940
  return BS_BLOCK_DONE;
1128
941
  }
942
+
1129
943
  /* ===========================================================================
1130
944
  * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
1131
945
  * (It will be regenerated if this run of deflate switches away from Huffman.)
1132
946
  */
1133
-
1134
-
1135
947
  function deflate_huff(s, flush) {
1136
- var bflush;
1137
- /* set if current block must be flushed */
948
+ var bflush; /* set if current block must be flushed */
1138
949
 
1139
950
  for (;;) {
1140
951
  /* Make sure that we have a literal to write. */
1141
952
  if (s.lookahead === 0) {
1142
953
  fill_window(s);
1143
-
1144
954
  if (s.lookahead === 0) {
1145
955
  if (flush === Z_NO_FLUSH) {
1146
956
  return BS_NEED_MORE;
1147
957
  }
1148
-
1149
- break;
1150
- /* flush the current block */
958
+ break; /* flush the current block */
1151
959
  }
1152
960
  }
1153
- /* Output a literal byte */
1154
-
1155
-
1156
- s.match_length = 0; //Tracevv((stderr,"%c", s->window[s->strstart]));
1157
961
 
962
+ /* Output a literal byte */
963
+ s.match_length = 0;
964
+ //Tracevv((stderr,"%c", s->window[s->strstart]));
1158
965
  /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
1159
-
1160
966
  bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
1161
967
  s.lookahead--;
1162
968
  s.strstart++;
1163
-
1164
969
  if (bflush) {
1165
970
  /*** FLUSH_BLOCK(s, 0); ***/
1166
971
  flush_block_only(s, false);
1167
-
1168
972
  if (s.strm.avail_out === 0) {
1169
973
  return BS_NEED_MORE;
1170
974
  }
1171
975
  /***/
1172
-
1173
976
  }
1174
977
  }
1175
978
 
1176
979
  s.insert = 0;
1177
-
1178
980
  if (flush === Z_FINISH) {
1179
981
  /*** FLUSH_BLOCK(s, 1); ***/
1180
982
  flush_block_only(s, true);
1181
-
1182
983
  if (s.strm.avail_out === 0) {
1183
984
  return BS_FINISH_STARTED;
1184
985
  }
1185
986
  /***/
1186
-
1187
-
1188
987
  return BS_FINISH_DONE;
1189
988
  }
1190
-
1191
989
  if (s.last_lit) {
1192
990
  /*** FLUSH_BLOCK(s, 0); ***/
1193
991
  flush_block_only(s, false);
1194
-
1195
992
  if (s.strm.avail_out === 0) {
1196
993
  return BS_NEED_MORE;
1197
994
  }
1198
995
  /***/
1199
-
1200
996
  }
1201
997
 
1202
998
  return BS_BLOCK_DONE;
1203
999
  }
1000
+
1204
1001
  /* Values for max_lazy_match, good_match and max_chain_length, depending on
1205
1002
  * the desired pack level (0..9). The values given below have been tuned to
1206
1003
  * exclude worst case performance for pathological files. Better values may be
1207
1004
  * found for specific files.
1208
1005
  */
1209
-
1210
-
1211
1006
  function Config(good_length, max_lazy, nice_length, max_chain, func) {
1212
1007
  this.good_length = good_length;
1213
1008
  this.max_lazy = max_lazy;
@@ -1215,44 +1010,31 @@ function Config(good_length, max_lazy, nice_length, max_chain, func) {
1215
1010
  this.max_chain = max_chain;
1216
1011
  this.func = func;
1217
1012
  }
1218
-
1219
1013
  var configuration_table;
1220
- configuration_table = [
1221
- /* good lazy nice chain */
1222
- new Config(0, 0, 0, 0, deflate_stored),
1223
- /* 0 store only */
1224
- new Config(4, 4, 8, 4, deflate_fast),
1225
- /* 1 max speed, no lazy matches */
1226
- new Config(4, 5, 16, 8, deflate_fast),
1227
- /* 2 */
1228
- new Config(4, 6, 32, 32, deflate_fast),
1229
- /* 3 */
1230
- new Config(4, 4, 16, 16, deflate_slow),
1231
- /* 4 lazy matches */
1232
- new Config(8, 16, 32, 32, deflate_slow),
1233
- /* 5 */
1234
- new Config(8, 16, 128, 128, deflate_slow),
1235
- /* 6 */
1236
- new Config(8, 32, 128, 256, deflate_slow),
1237
- /* 7 */
1238
- new Config(32, 128, 258, 1024, deflate_slow),
1239
- /* 8 */
1240
- new Config(32, 258, 258, 4096, deflate_slow)
1241
- /* 9 max compression */
1242
- ];
1014
+ configuration_table = [/* good lazy nice chain */
1015
+ new Config(0, 0, 0, 0, deflate_stored), /* 0 store only */
1016
+ new Config(4, 4, 8, 4, deflate_fast), /* 1 max speed, no lazy matches */
1017
+ new Config(4, 5, 16, 8, deflate_fast), /* 2 */
1018
+ new Config(4, 6, 32, 32, deflate_fast), /* 3 */
1019
+
1020
+ new Config(4, 4, 16, 16, deflate_slow), /* 4 lazy matches */
1021
+ new Config(8, 16, 32, 32, deflate_slow), /* 5 */
1022
+ new Config(8, 16, 128, 128, deflate_slow), /* 6 */
1023
+ new Config(8, 32, 128, 256, deflate_slow), /* 7 */
1024
+ new Config(32, 128, 258, 1024, deflate_slow), /* 8 */
1025
+ new Config(32, 258, 258, 4096, deflate_slow) /* 9 max compression */];
1026
+
1243
1027
  /* ===========================================================================
1244
1028
  * Initialize the "longest match" routines for a new zlib stream
1245
1029
  */
1246
-
1247
1030
  function lm_init(s) {
1248
1031
  s.window_size = 2 * s.w_size;
1249
- /*** CLEAR_HASH(s); ***/
1250
1032
 
1033
+ /*** CLEAR_HASH(s); ***/
1251
1034
  zero(s.head); // Fill with NIL (= 0);
1252
1035
 
1253
1036
  /* Set the default configuration parameters:
1254
1037
  */
1255
-
1256
1038
  s.max_lazy_match = configuration_table[s.level].max_lazy;
1257
1039
  s.good_match = configuration_table[s.level].good_length;
1258
1040
  s.nice_match = configuration_table[s.level].nice_length;
@@ -1265,49 +1047,22 @@ function lm_init(s) {
1265
1047
  s.match_available = 0;
1266
1048
  s.ins_h = 0;
1267
1049
  }
1268
-
1269
1050
  function DeflateState() {
1270
- this.strm = null;
1271
- /* pointer back to this zlib stream */
1272
-
1273
- this.status = 0;
1274
- /* as the name implies */
1275
-
1276
- this.pending_buf = null;
1277
- /* output still pending */
1278
-
1279
- this.pending_buf_size = 0;
1280
- /* size of pending_buf */
1281
-
1282
- this.pending_out = 0;
1283
- /* next pending byte to output to the stream */
1284
-
1285
- this.pending = 0;
1286
- /* nb of bytes in the pending buffer */
1287
-
1288
- this.wrap = 0;
1289
- /* bit 0 true for zlib, bit 1 true for gzip */
1290
-
1291
- this.gzhead = null;
1292
- /* gzip header information to write */
1293
-
1294
- this.gzindex = 0;
1295
- /* where in extra, name, or comment */
1296
-
1297
- this.method = Z_DEFLATED;
1298
- /* can only be DEFLATED */
1299
-
1300
- this.last_flush = -1;
1301
- /* value of flush param for previous deflate call */
1302
-
1303
- this.w_size = 0;
1304
- /* LZ77 window size (32K by default) */
1305
-
1306
- this.w_bits = 0;
1307
- /* log2(w_size) (8..16) */
1308
-
1309
- this.w_mask = 0;
1310
- /* w_size - 1 */
1051
+ this.strm = null; /* pointer back to this zlib stream */
1052
+ this.status = 0; /* as the name implies */
1053
+ this.pending_buf = null; /* output still pending */
1054
+ this.pending_buf_size = 0; /* size of pending_buf */
1055
+ this.pending_out = 0; /* next pending byte to output to the stream */
1056
+ this.pending = 0; /* nb of bytes in the pending buffer */
1057
+ this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */
1058
+ this.gzhead = null; /* gzip header information to write */
1059
+ this.gzindex = 0; /* where in extra, name, or comment */
1060
+ this.method = Z_DEFLATED; /* can only be DEFLATED */
1061
+ this.last_flush = -1; /* value of flush param for previous deflate call */
1062
+
1063
+ this.w_size = 0; /* LZ77 window size (32K by default) */
1064
+ this.w_bits = 0; /* log2(w_size) (8..16) */
1065
+ this.w_mask = 0; /* w_size - 1 */
1311
1066
 
1312
1067
  this.window = null;
1313
1068
  /* Sliding window. Input bytes are read into the second half of the window,
@@ -1328,20 +1083,12 @@ function DeflateState() {
1328
1083
  * An index in this array is thus a window index modulo 32K.
1329
1084
  */
1330
1085
 
1331
- this.head = null;
1332
- /* Heads of the hash chains or NIL. */
1333
-
1334
- this.ins_h = 0;
1335
- /* hash index of string to be inserted */
1336
-
1337
- this.hash_size = 0;
1338
- /* number of elements in hash table */
1086
+ this.head = null; /* Heads of the hash chains or NIL. */
1339
1087
 
1340
- this.hash_bits = 0;
1341
- /* log2(hash_size) */
1342
-
1343
- this.hash_mask = 0;
1344
- /* hash_size-1 */
1088
+ this.ins_h = 0; /* hash index of string to be inserted */
1089
+ this.hash_size = 0; /* number of elements in hash table */
1090
+ this.hash_bits = 0; /* log2(hash_size) */
1091
+ this.hash_mask = 0; /* hash_size-1 */
1345
1092
 
1346
1093
  this.hash_shift = 0;
1347
1094
  /* Number of bits by which ins_h must be shifted at each input
@@ -1355,23 +1102,12 @@ function DeflateState() {
1355
1102
  * negative when the window is moved backwards.
1356
1103
  */
1357
1104
 
1358
- this.match_length = 0;
1359
- /* length of best match */
1360
-
1361
- this.prev_match = 0;
1362
- /* previous match */
1363
-
1364
- this.match_available = 0;
1365
- /* set if previous match exists */
1366
-
1367
- this.strstart = 0;
1368
- /* start of string to insert */
1369
-
1370
- this.match_start = 0;
1371
- /* start of matching string */
1372
-
1373
- this.lookahead = 0;
1374
- /* number of valid bytes ahead in window */
1105
+ this.match_length = 0; /* length of best match */
1106
+ this.prev_match = 0; /* previous match */
1107
+ this.match_available = 0; /* set if previous match exists */
1108
+ this.strstart = 0; /* start of string to insert */
1109
+ this.match_start = 0; /* start of matching string */
1110
+ this.lookahead = 0; /* number of valid bytes ahead in window */
1375
1111
 
1376
1112
  this.prev_length = 0;
1377
1113
  /* Length of the best match at previous step. Matches not greater than this
@@ -1391,75 +1127,58 @@ function DeflateState() {
1391
1127
  */
1392
1128
  // That's alias to max_lazy_match, don't use directly
1393
1129
  //this.max_insert_length = 0;
1394
-
1395
1130
  /* Insert new strings in the hash table only if the match length is not
1396
1131
  * greater than this length. This saves time but degrades compression.
1397
1132
  * max_insert_length is used only for compression levels <= 3.
1398
1133
  */
1399
1134
 
1400
- this.level = 0;
1401
- /* compression level (1..9) */
1402
-
1403
- this.strategy = 0;
1404
- /* favor or force Huffman coding*/
1135
+ this.level = 0; /* compression level (1..9) */
1136
+ this.strategy = 0; /* favor or force Huffman coding*/
1405
1137
 
1406
1138
  this.good_match = 0;
1407
1139
  /* Use a faster search when the previous match is longer than this */
1408
1140
 
1409
- this.nice_match = 0;
1410
- /* Stop searching when current match exceeds this */
1141
+ this.nice_match = 0; /* Stop searching when current match exceeds this */
1411
1142
 
1412
1143
  /* used by trees.c: */
1413
1144
 
1414
1145
  /* Didn't use ct_data typedef below to suppress compiler warning */
1146
+
1415
1147
  // struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
1416
1148
  // struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
1417
1149
  // struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
1150
+
1418
1151
  // Use flat array of DOUBLE size, with interleaved fata,
1419
1152
  // because JS does not support effective
1420
-
1421
1153
  this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2);
1422
1154
  this.dyn_dtree = new utils.Buf16((2 * D_CODES + 1) * 2);
1423
1155
  this.bl_tree = new utils.Buf16((2 * BL_CODES + 1) * 2);
1424
1156
  zero(this.dyn_ltree);
1425
1157
  zero(this.dyn_dtree);
1426
1158
  zero(this.bl_tree);
1427
- this.l_desc = null;
1428
- /* desc. for literal tree */
1429
-
1430
- this.d_desc = null;
1431
- /* desc. for distance tree */
1159
+ this.l_desc = null; /* desc. for literal tree */
1160
+ this.d_desc = null; /* desc. for distance tree */
1161
+ this.bl_desc = null; /* desc. for bit length tree */
1432
1162
 
1433
- this.bl_desc = null;
1434
- /* desc. for bit length tree */
1435
1163
  //ush bl_count[MAX_BITS+1];
1436
-
1437
1164
  this.bl_count = new utils.Buf16(MAX_BITS + 1);
1438
1165
  /* number of codes at each bit length for an optimal tree */
1439
- //int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
1440
-
1441
- this.heap = new utils.Buf16(2 * L_CODES + 1);
1442
- /* heap used to build the Huffman trees */
1443
1166
 
1167
+ //int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
1168
+ this.heap = new utils.Buf16(2 * L_CODES + 1); /* heap used to build the Huffman trees */
1444
1169
  zero(this.heap);
1445
- this.heap_len = 0;
1446
- /* number of elements in the heap */
1447
-
1448
- this.heap_max = 0;
1449
- /* element of largest frequency */
1450
-
1170
+ this.heap_len = 0; /* number of elements in the heap */
1171
+ this.heap_max = 0; /* element of largest frequency */
1451
1172
  /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
1452
1173
  * The same heap array is used to build all trees.
1453
1174
  */
1454
1175
 
1455
1176
  this.depth = new utils.Buf16(2 * L_CODES + 1); //uch depth[2*L_CODES+1];
1456
-
1457
1177
  zero(this.depth);
1458
1178
  /* Depth of each subtree used as tie breaker for trees of equal frequency
1459
1179
  */
1460
1180
 
1461
- this.l_buf = 0;
1462
- /* buffer index for literals or lengths */
1181
+ this.l_buf = 0; /* buffer index for literals or lengths */
1463
1182
 
1464
1183
  this.lit_bufsize = 0;
1465
1184
  /* Size of match buffer for literals/lengths. There are 4 reasons for
@@ -1481,8 +1200,7 @@ function DeflateState() {
1481
1200
  * - I can't count above 4
1482
1201
  */
1483
1202
 
1484
- this.last_lit = 0;
1485
- /* running index in l_buf */
1203
+ this.last_lit = 0; /* running index in l_buf */
1486
1204
 
1487
1205
  this.d_buf = 0;
1488
1206
  /* Buffer index for distances. To simplify the code, d_buf and l_buf have
@@ -1490,31 +1208,23 @@ function DeflateState() {
1490
1208
  * array would be necessary.
1491
1209
  */
1492
1210
 
1493
- this.opt_len = 0;
1494
- /* bit length of current block with optimal trees */
1495
-
1496
- this.static_len = 0;
1497
- /* bit length of current block with static trees */
1498
-
1499
- this.matches = 0;
1500
- /* number of string matches in current block */
1501
-
1502
- this.insert = 0;
1503
- /* bytes at end of window left to insert */
1211
+ this.opt_len = 0; /* bit length of current block with optimal trees */
1212
+ this.static_len = 0; /* bit length of current block with static trees */
1213
+ this.matches = 0; /* number of string matches in current block */
1214
+ this.insert = 0; /* bytes at end of window left to insert */
1504
1215
 
1505
1216
  this.bi_buf = 0;
1506
1217
  /* Output buffer. bits are inserted starting at the bottom (least
1507
1218
  * significant bits).
1508
1219
  */
1509
-
1510
1220
  this.bi_valid = 0;
1511
1221
  /* Number of valid bits in bi_buf. All bits above the last valid bit
1512
1222
  * are always zero.
1513
1223
  */
1224
+
1514
1225
  // Used for window memory init. We safely ignore it for JS. That makes
1515
1226
  // sense only for pointers and memory check tools.
1516
1227
  //this.high_water = 0;
1517
-
1518
1228
  /* High water mark offset in window for initialized bytes -- bytes above
1519
1229
  * this are set to zero in order to avoid memory check warnings when
1520
1230
  * longest match routines access bytes past the input. This is then
@@ -1524,17 +1234,14 @@ function DeflateState() {
1524
1234
 
1525
1235
  function deflateResetKeep(strm) {
1526
1236
  var s;
1527
-
1528
1237
  if (!strm || !strm.state) {
1529
1238
  return err(strm, Z_STREAM_ERROR);
1530
1239
  }
1531
-
1532
1240
  strm.total_in = strm.total_out = 0;
1533
1241
  strm.data_type = Z_UNKNOWN;
1534
1242
  s = strm.state;
1535
1243
  s.pending = 0;
1536
1244
  s.pending_out = 0;
1537
-
1538
1245
  if (s.wrap < 0) {
1539
1246
  s.wrap = -s.wrap;
1540
1247
  /* was made negative by deflate(..., Z_FINISH); */
@@ -1543,70 +1250,52 @@ function deflateResetKeep(strm) {
1543
1250
  s.status = s.wrap ? INIT_STATE : BUSY_STATE;
1544
1251
  strm.adler = s.wrap === 2 ? 0 // crc32(0, Z_NULL, 0)
1545
1252
  : 1; // adler32(0, Z_NULL, 0)
1546
-
1547
1253
  s.last_flush = Z_NO_FLUSH;
1548
-
1549
1254
  trees._tr_init(s);
1550
-
1551
1255
  return Z_OK;
1552
1256
  }
1553
-
1554
1257
  function deflateReset(strm) {
1555
1258
  var ret = deflateResetKeep(strm);
1556
-
1557
1259
  if (ret === Z_OK) {
1558
1260
  lm_init(strm.state);
1559
1261
  }
1560
-
1561
1262
  return ret;
1562
1263
  }
1563
-
1564
1264
  function deflateSetHeader(strm, head) {
1565
1265
  if (!strm || !strm.state) {
1566
1266
  return Z_STREAM_ERROR;
1567
1267
  }
1568
-
1569
1268
  if (strm.state.wrap !== 2) {
1570
1269
  return Z_STREAM_ERROR;
1571
1270
  }
1572
-
1573
1271
  strm.state.gzhead = head;
1574
1272
  return Z_OK;
1575
1273
  }
1576
-
1577
1274
  function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
1578
1275
  if (!strm) {
1579
1276
  // === Z_NULL
1580
1277
  return Z_STREAM_ERROR;
1581
1278
  }
1582
-
1583
1279
  var wrap = 1;
1584
-
1585
1280
  if (level === Z_DEFAULT_COMPRESSION) {
1586
1281
  level = 6;
1587
1282
  }
1588
-
1589
1283
  if (windowBits < 0) {
1590
1284
  /* suppress zlib wrapper */
1591
1285
  wrap = 0;
1592
1286
  windowBits = -windowBits;
1593
1287
  } else if (windowBits > 15) {
1594
- wrap = 2;
1595
- /* write gzip wrapper instead */
1596
-
1288
+ wrap = 2; /* write gzip wrapper instead */
1597
1289
  windowBits -= 16;
1598
1290
  }
1599
-
1600
1291
  if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED || windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
1601
1292
  return err(strm, Z_STREAM_ERROR);
1602
1293
  }
1603
-
1604
1294
  if (windowBits === 8) {
1605
1295
  windowBits = 9;
1606
1296
  }
1607
1297
  /* until 256-byte window bug fixed */
1608
1298
 
1609
-
1610
1299
  var s = new DeflateState();
1611
1300
  strm.state = s;
1612
1301
  s.strm = strm;
@@ -1621,31 +1310,33 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
1621
1310
  s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH);
1622
1311
  s.window = new utils.Buf8(s.w_size * 2);
1623
1312
  s.head = new utils.Buf16(s.hash_size);
1624
- s.prev = new utils.Buf16(s.w_size); // Don't need mem init magic for JS.
1313
+ s.prev = new utils.Buf16(s.w_size);
1314
+
1315
+ // Don't need mem init magic for JS.
1625
1316
  //s.high_water = 0; /* nothing written to s->window yet */
1626
1317
 
1627
- s.lit_bufsize = 1 << memLevel + 6;
1628
- /* 16K elements by default */
1318
+ s.lit_bufsize = 1 << memLevel + 6; /* 16K elements by default */
1319
+
1320
+ s.pending_buf_size = s.lit_bufsize * 4;
1629
1321
 
1630
- s.pending_buf_size = s.lit_bufsize * 4; //overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
1322
+ //overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
1631
1323
  //s->pending_buf = (uchf *) overlay;
1324
+ s.pending_buf = new utils.Buf8(s.pending_buf_size);
1632
1325
 
1633
- s.pending_buf = new utils.Buf8(s.pending_buf_size); // It is offset from `s.pending_buf` (size is `s.lit_bufsize * 2`)
1326
+ // It is offset from `s.pending_buf` (size is `s.lit_bufsize * 2`)
1634
1327
  //s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
1328
+ s.d_buf = 1 * s.lit_bufsize;
1635
1329
 
1636
- s.d_buf = 1 * s.lit_bufsize; //s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
1637
-
1330
+ //s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
1638
1331
  s.l_buf = (1 + 2) * s.lit_bufsize;
1639
1332
  s.level = level;
1640
1333
  s.strategy = strategy;
1641
1334
  s.method = method;
1642
1335
  return deflateReset(strm);
1643
1336
  }
1644
-
1645
1337
  function deflateInit(strm, level) {
1646
1338
  return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
1647
1339
  }
1648
-
1649
1340
  function deflate(strm, flush) {
1650
1341
  var old_flush, s;
1651
1342
  var beg, val; // for gzip header write only
@@ -1653,29 +1344,22 @@ function deflate(strm, flush) {
1653
1344
  if (!strm || !strm.state || flush > Z_BLOCK || flush < 0) {
1654
1345
  return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR;
1655
1346
  }
1656
-
1657
1347
  s = strm.state;
1658
-
1659
1348
  if (!strm.output || !strm.input && strm.avail_in !== 0 || s.status === FINISH_STATE && flush !== Z_FINISH) {
1660
1349
  return err(strm, strm.avail_out === 0 ? Z_BUF_ERROR : Z_STREAM_ERROR);
1661
1350
  }
1662
-
1663
- s.strm = strm;
1664
- /* just in case */
1665
-
1351
+ s.strm = strm; /* just in case */
1666
1352
  old_flush = s.last_flush;
1667
1353
  s.last_flush = flush;
1668
- /* Write the header */
1669
1354
 
1355
+ /* Write the header */
1670
1356
  if (s.status === INIT_STATE) {
1671
1357
  if (s.wrap === 2) {
1672
1358
  // GZIP header
1673
1359
  strm.adler = 0; //crc32(0L, Z_NULL, 0);
1674
-
1675
1360
  put_byte(s, 31);
1676
1361
  put_byte(s, 139);
1677
1362
  put_byte(s, 8);
1678
-
1679
1363
  if (!s.gzhead) {
1680
1364
  // s->gzhead == Z_NULL
1681
1365
  put_byte(s, 0);
@@ -1694,24 +1378,21 @@ function deflate(strm, flush) {
1694
1378
  put_byte(s, s.gzhead.time >> 24 & 0xff);
1695
1379
  put_byte(s, s.level === 9 ? 2 : s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? 4 : 0);
1696
1380
  put_byte(s, s.gzhead.os & 0xff);
1697
-
1698
1381
  if (s.gzhead.extra && s.gzhead.extra.length) {
1699
1382
  put_byte(s, s.gzhead.extra.length & 0xff);
1700
1383
  put_byte(s, s.gzhead.extra.length >> 8 & 0xff);
1701
1384
  }
1702
-
1703
1385
  if (s.gzhead.hcrc) {
1704
1386
  strm.adler = (0, _crc["default"])(strm.adler, s.pending_buf, s.pending, 0);
1705
1387
  }
1706
-
1707
1388
  s.gzindex = 0;
1708
1389
  s.status = EXTRA_STATE;
1709
1390
  }
1710
- } else // DEFLATE header
1391
+ } else
1392
+ // DEFLATE header
1711
1393
  {
1712
1394
  var header = Z_DEFLATED + (s.w_bits - 8 << 4) << 8;
1713
1395
  var level_flags = -1;
1714
-
1715
1396
  if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {
1716
1397
  level_flags = 0;
1717
1398
  } else if (s.level < 6) {
@@ -1721,57 +1402,45 @@ function deflate(strm, flush) {
1721
1402
  } else {
1722
1403
  level_flags = 3;
1723
1404
  }
1724
-
1725
1405
  header |= level_flags << 6;
1726
-
1727
1406
  if (s.strstart !== 0) {
1728
1407
  header |= PRESET_DICT;
1729
1408
  }
1730
-
1731
1409
  header += 31 - header % 31;
1732
1410
  s.status = BUSY_STATE;
1733
1411
  putShortMSB(s, header);
1734
- /* Save the adler32 of the preset dictionary: */
1735
1412
 
1413
+ /* Save the adler32 of the preset dictionary: */
1736
1414
  if (s.strstart !== 0) {
1737
1415
  putShortMSB(s, strm.adler >>> 16);
1738
1416
  putShortMSB(s, strm.adler & 0xffff);
1739
1417
  }
1740
-
1741
1418
  strm.adler = 1; // adler32(0L, Z_NULL, 0);
1742
1419
  }
1743
- } //#ifdef GZIP
1744
-
1420
+ }
1745
1421
 
1422
+ //#ifdef GZIP
1746
1423
  if (s.status === EXTRA_STATE) {
1747
- if (s.gzhead.extra
1748
- /* != Z_NULL*/
1749
- ) {
1750
- beg = s.pending;
1751
- /* start of bytes to update crc */
1424
+ if (s.gzhead.extra /* != Z_NULL*/) {
1425
+ beg = s.pending; /* start of bytes to update crc */
1752
1426
 
1753
1427
  while (s.gzindex < (s.gzhead.extra.length & 0xffff)) {
1754
1428
  if (s.pending === s.pending_buf_size) {
1755
1429
  if (s.gzhead.hcrc && s.pending > beg) {
1756
1430
  strm.adler = (0, _crc["default"])(strm.adler, s.pending_buf, s.pending - beg, beg);
1757
1431
  }
1758
-
1759
1432
  flush_pending(strm);
1760
1433
  beg = s.pending;
1761
-
1762
1434
  if (s.pending === s.pending_buf_size) {
1763
1435
  break;
1764
1436
  }
1765
1437
  }
1766
-
1767
1438
  put_byte(s, s.gzhead.extra[s.gzindex] & 0xff);
1768
1439
  s.gzindex++;
1769
1440
  }
1770
-
1771
1441
  if (s.gzhead.hcrc && s.pending > beg) {
1772
1442
  strm.adler = (0, _crc["default"])(strm.adler, s.pending_buf, s.pending - beg, beg);
1773
1443
  }
1774
-
1775
1444
  if (s.gzindex === s.gzhead.extra.length) {
1776
1445
  s.gzindex = 0;
1777
1446
  s.status = NAME_STATE;
@@ -1780,13 +1449,9 @@ function deflate(strm, flush) {
1780
1449
  s.status = NAME_STATE;
1781
1450
  }
1782
1451
  }
1783
-
1784
1452
  if (s.status === NAME_STATE) {
1785
- if (s.gzhead.name
1786
- /* != Z_NULL*/
1787
- ) {
1788
- beg = s.pending;
1789
- /* start of bytes to update crc */
1453
+ if (s.gzhead.name /* != Z_NULL*/) {
1454
+ beg = s.pending; /* start of bytes to update crc */
1790
1455
  //int val;
1791
1456
 
1792
1457
  do {
@@ -1794,30 +1459,24 @@ function deflate(strm, flush) {
1794
1459
  if (s.gzhead.hcrc && s.pending > beg) {
1795
1460
  strm.adler = (0, _crc["default"])(strm.adler, s.pending_buf, s.pending - beg, beg);
1796
1461
  }
1797
-
1798
1462
  flush_pending(strm);
1799
1463
  beg = s.pending;
1800
-
1801
1464
  if (s.pending === s.pending_buf_size) {
1802
1465
  val = 1;
1803
1466
  break;
1804
1467
  }
1805
- } // JS specific: little magic to add zero terminator to end of string
1806
-
1807
-
1468
+ }
1469
+ // JS specific: little magic to add zero terminator to end of string
1808
1470
  if (s.gzindex < s.gzhead.name.length) {
1809
1471
  val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff;
1810
1472
  } else {
1811
1473
  val = 0;
1812
1474
  }
1813
-
1814
1475
  put_byte(s, val);
1815
1476
  } while (val !== 0);
1816
-
1817
1477
  if (s.gzhead.hcrc && s.pending > beg) {
1818
1478
  strm.adler = (0, _crc["default"])(strm.adler, s.pending_buf, s.pending - beg, beg);
1819
1479
  }
1820
-
1821
1480
  if (val === 0) {
1822
1481
  s.gzindex = 0;
1823
1482
  s.status = COMMENT_STATE;
@@ -1826,13 +1485,9 @@ function deflate(strm, flush) {
1826
1485
  s.status = COMMENT_STATE;
1827
1486
  }
1828
1487
  }
1829
-
1830
1488
  if (s.status === COMMENT_STATE) {
1831
- if (s.gzhead.comment
1832
- /* != Z_NULL*/
1833
- ) {
1834
- beg = s.pending;
1835
- /* start of bytes to update crc */
1489
+ if (s.gzhead.comment /* != Z_NULL*/) {
1490
+ beg = s.pending; /* start of bytes to update crc */
1836
1491
  //int val;
1837
1492
 
1838
1493
  do {
@@ -1840,30 +1495,24 @@ function deflate(strm, flush) {
1840
1495
  if (s.gzhead.hcrc && s.pending > beg) {
1841
1496
  strm.adler = (0, _crc["default"])(strm.adler, s.pending_buf, s.pending - beg, beg);
1842
1497
  }
1843
-
1844
1498
  flush_pending(strm);
1845
1499
  beg = s.pending;
1846
-
1847
1500
  if (s.pending === s.pending_buf_size) {
1848
1501
  val = 1;
1849
1502
  break;
1850
1503
  }
1851
- } // JS specific: little magic to add zero terminator to end of string
1852
-
1853
-
1504
+ }
1505
+ // JS specific: little magic to add zero terminator to end of string
1854
1506
  if (s.gzindex < s.gzhead.comment.length) {
1855
1507
  val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff;
1856
1508
  } else {
1857
1509
  val = 0;
1858
1510
  }
1859
-
1860
1511
  put_byte(s, val);
1861
1512
  } while (val !== 0);
1862
-
1863
1513
  if (s.gzhead.hcrc && s.pending > beg) {
1864
1514
  strm.adler = (0, _crc["default"])(strm.adler, s.pending_buf, s.pending - beg, beg);
1865
1515
  }
1866
-
1867
1516
  if (val === 0) {
1868
1517
  s.status = HCRC_STATE;
1869
1518
  }
@@ -1871,31 +1520,26 @@ function deflate(strm, flush) {
1871
1520
  s.status = HCRC_STATE;
1872
1521
  }
1873
1522
  }
1874
-
1875
1523
  if (s.status === HCRC_STATE) {
1876
1524
  if (s.gzhead.hcrc) {
1877
1525
  if (s.pending + 2 > s.pending_buf_size) {
1878
1526
  flush_pending(strm);
1879
1527
  }
1880
-
1881
1528
  if (s.pending + 2 <= s.pending_buf_size) {
1882
1529
  put_byte(s, strm.adler & 0xff);
1883
1530
  put_byte(s, strm.adler >> 8 & 0xff);
1884
1531
  strm.adler = 0; //crc32(0L, Z_NULL, 0);
1885
-
1886
1532
  s.status = BUSY_STATE;
1887
1533
  }
1888
1534
  } else {
1889
1535
  s.status = BUSY_STATE;
1890
1536
  }
1891
- } //#endif
1537
+ }
1538
+ //#endif
1892
1539
 
1893
1540
  /* Flush as much pending output as possible */
1894
-
1895
-
1896
1541
  if (s.pending !== 0) {
1897
1542
  flush_pending(strm);
1898
-
1899
1543
  if (strm.avail_out === 0) {
1900
1544
  /* Since avail_out is 0, deflate will be called again with
1901
1545
  * more output space, but possibly with both pending and
@@ -1906,31 +1550,27 @@ function deflate(strm, flush) {
1906
1550
  s.last_flush = -1;
1907
1551
  return Z_OK;
1908
1552
  }
1553
+
1909
1554
  /* Make sure there is something to do and avoid duplicate consecutive
1910
1555
  * flushes. For repeated and useless calls with Z_FINISH, we keep
1911
1556
  * returning Z_STREAM_END instead of Z_BUF_ERROR.
1912
1557
  */
1913
-
1914
1558
  } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) && flush !== Z_FINISH) {
1915
1559
  return err(strm, Z_BUF_ERROR);
1916
1560
  }
1917
- /* User must not provide more input after the first FINISH: */
1918
-
1919
1561
 
1562
+ /* User must not provide more input after the first FINISH: */
1920
1563
  if (s.status === FINISH_STATE && strm.avail_in !== 0) {
1921
1564
  return err(strm, Z_BUF_ERROR);
1922
1565
  }
1566
+
1923
1567
  /* Start a new block or continue the current one.
1924
1568
  */
1925
-
1926
-
1927
1569
  if (strm.avail_in !== 0 || s.lookahead !== 0 || flush !== Z_NO_FLUSH && s.status !== FINISH_STATE) {
1928
1570
  var bstate = s.strategy === Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : s.strategy === Z_RLE ? deflate_rle(s, flush) : configuration_table[s.level].func(s, flush);
1929
-
1930
1571
  if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) {
1931
1572
  s.status = FINISH_STATE;
1932
1573
  }
1933
-
1934
1574
  if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) {
1935
1575
  if (strm.avail_out === 0) {
1936
1576
  s.last_flush = -1;
@@ -1952,16 +1592,13 @@ function deflate(strm, flush) {
1952
1592
  trees._tr_align(s);
1953
1593
  } else if (flush !== Z_BLOCK) {
1954
1594
  /* FULL_FLUSH or SYNC_FLUSH */
1595
+
1955
1596
  trees._tr_stored_block(s, 0, 0, false);
1956
1597
  /* For a full flush, this empty block will be recognized
1957
1598
  * as a special marker by inflate_sync().
1958
1599
  */
1959
-
1960
-
1961
1600
  if (flush === Z_FULL_FLUSH) {
1962
- /*** CLEAR_HASH(s); ***/
1963
-
1964
- /* forget history */
1601
+ /*** CLEAR_HASH(s); ***/ /* forget history */
1965
1602
  zero(s.head); // Fill with NIL (= 0);
1966
1603
 
1967
1604
  if (s.lookahead === 0) {
@@ -1971,30 +1608,24 @@ function deflate(strm, flush) {
1971
1608
  }
1972
1609
  }
1973
1610
  }
1974
-
1975
1611
  flush_pending(strm);
1976
-
1977
1612
  if (strm.avail_out === 0) {
1978
- s.last_flush = -1;
1979
- /* avoid BUF_ERROR at next call, see above */
1980
-
1613
+ s.last_flush = -1; /* avoid BUF_ERROR at next call, see above */
1981
1614
  return Z_OK;
1982
1615
  }
1983
1616
  }
1984
- } //Assert(strm->avail_out > 0, "bug2");
1617
+ }
1618
+ //Assert(strm->avail_out > 0, "bug2");
1985
1619
  //if (strm.avail_out <= 0) { throw new Error("bug2");}
1986
1620
 
1987
-
1988
1621
  if (flush !== Z_FINISH) {
1989
1622
  return Z_OK;
1990
1623
  }
1991
-
1992
1624
  if (s.wrap <= 0) {
1993
1625
  return Z_STREAM_END;
1994
1626
  }
1995
- /* Write the trailer */
1996
-
1997
1627
 
1628
+ /* Write the trailer */
1998
1629
  if (s.wrap === 2) {
1999
1630
  put_byte(s, strm.adler & 0xff);
2000
1631
  put_byte(s, strm.adler >> 8 & 0xff);
@@ -2008,47 +1639,33 @@ function deflate(strm, flush) {
2008
1639
  putShortMSB(s, strm.adler >>> 16);
2009
1640
  putShortMSB(s, strm.adler & 0xffff);
2010
1641
  }
2011
-
2012
1642
  flush_pending(strm);
2013
1643
  /* If avail_out is zero, the application will call deflate again
2014
1644
  * to flush the rest.
2015
1645
  */
2016
-
2017
1646
  if (s.wrap > 0) {
2018
1647
  s.wrap = -s.wrap;
2019
1648
  }
2020
1649
  /* write the trailer only once! */
2021
-
2022
-
2023
1650
  return s.pending !== 0 ? Z_OK : Z_STREAM_END;
2024
1651
  }
2025
-
2026
1652
  function deflateEnd(strm) {
2027
1653
  var status;
2028
-
2029
- if (!strm
2030
- /*== Z_NULL*/
2031
- || !strm.state
2032
- /*== Z_NULL*/
2033
- ) {
1654
+ if (!strm /*== Z_NULL*/ || !strm.state /*== Z_NULL*/) {
2034
1655
  return Z_STREAM_ERROR;
2035
1656
  }
2036
-
2037
1657
  status = strm.state.status;
2038
-
2039
1658
  if (status !== INIT_STATE && status !== EXTRA_STATE && status !== NAME_STATE && status !== COMMENT_STATE && status !== HCRC_STATE && status !== BUSY_STATE && status !== FINISH_STATE) {
2040
1659
  return err(strm, Z_STREAM_ERROR);
2041
1660
  }
2042
-
2043
1661
  strm.state = null;
2044
1662
  return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;
2045
1663
  }
1664
+
2046
1665
  /* =========================================================================
2047
1666
  * Initializes the compression dictionary from the given byte
2048
1667
  * sequence without producing any compressed output.
2049
1668
  */
2050
-
2051
-
2052
1669
  function deflateSetDictionary(strm, dictionary) {
2053
1670
  var dictLength = dictionary.length;
2054
1671
  var s;
@@ -2058,57 +1675,40 @@ function deflateSetDictionary(strm, dictionary) {
2058
1675
  var next;
2059
1676
  var input;
2060
1677
  var tmpDict;
2061
-
2062
- if (!strm
2063
- /*== Z_NULL*/
2064
- || !strm.state
2065
- /*== Z_NULL*/
2066
- ) {
1678
+ if (!strm /*== Z_NULL*/ || !strm.state /*== Z_NULL*/) {
2067
1679
  return Z_STREAM_ERROR;
2068
1680
  }
2069
-
2070
1681
  s = strm.state;
2071
1682
  wrap = s.wrap;
2072
-
2073
1683
  if (wrap === 2 || wrap === 1 && s.status !== INIT_STATE || s.lookahead) {
2074
1684
  return Z_STREAM_ERROR;
2075
1685
  }
2076
- /* when using zlib wrappers, compute Adler-32 for provided dictionary */
2077
-
2078
1686
 
1687
+ /* when using zlib wrappers, compute Adler-32 for provided dictionary */
2079
1688
  if (wrap === 1) {
2080
1689
  /* adler32(strm->adler, dictionary, dictLength); */
2081
1690
  strm.adler = (0, _adler["default"])(strm.adler, dictionary, dictLength, 0);
2082
1691
  }
2083
-
2084
- s.wrap = 0;
2085
- /* avoid computing Adler-32 in read_buf */
1692
+ s.wrap = 0; /* avoid computing Adler-32 in read_buf */
2086
1693
 
2087
1694
  /* if dictionary would fill window, just replace the history */
2088
-
2089
1695
  if (dictLength >= s.w_size) {
2090
1696
  if (wrap === 0) {
2091
1697
  /* already empty otherwise */
2092
-
2093
1698
  /*** CLEAR_HASH(s); ***/
2094
1699
  zero(s.head); // Fill with NIL (= 0);
2095
-
2096
1700
  s.strstart = 0;
2097
1701
  s.block_start = 0;
2098
1702
  s.insert = 0;
2099
1703
  }
2100
1704
  /* use the tail */
2101
1705
  // dictionary = dictionary.slice(dictLength - s.w_size);
2102
-
2103
-
2104
1706
  tmpDict = new utils.Buf8(s.w_size);
2105
1707
  utils.arraySet(tmpDict, dictionary, dictLength - s.w_size, s.w_size, 0);
2106
1708
  dictionary = tmpDict;
2107
1709
  dictLength = s.w_size;
2108
1710
  }
2109
1711
  /* insert dictionary into window and hash */
2110
-
2111
-
2112
1712
  avail = strm.avail_in;
2113
1713
  next = strm.next_in;
2114
1714
  input = strm.input;
@@ -2116,11 +1716,9 @@ function deflateSetDictionary(strm, dictionary) {
2116
1716
  strm.next_in = 0;
2117
1717
  strm.input = dictionary;
2118
1718
  fill_window(s);
2119
-
2120
1719
  while (s.lookahead >= MIN_MATCH) {
2121
1720
  str = s.strstart;
2122
1721
  n = s.lookahead - (MIN_MATCH - 1);
2123
-
2124
1722
  do {
2125
1723
  /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
2126
1724
  s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
@@ -2128,12 +1726,10 @@ function deflateSetDictionary(strm, dictionary) {
2128
1726
  s.head[s.ins_h] = str;
2129
1727
  str++;
2130
1728
  } while (--n);
2131
-
2132
1729
  s.strstart = str;
2133
1730
  s.lookahead = MIN_MATCH - 1;
2134
1731
  fill_window(s);
2135
1732
  }
2136
-
2137
1733
  s.strstart += s.lookahead;
2138
1734
  s.block_start = s.strstart;
2139
1735
  s.insert = s.lookahead;
@@ -2146,8 +1742,8 @@ function deflateSetDictionary(strm, dictionary) {
2146
1742
  s.wrap = wrap;
2147
1743
  return Z_OK;
2148
1744
  }
2149
-
2150
1745
  var deflateInfo = 'pako deflate (from Nodeca project)';
1746
+
2151
1747
  /* Not implemented
2152
1748
  exports.deflateBound = deflateBound;
2153
1749
  exports.deflateCopy = deflateCopy;
@@ -2156,5 +1752,4 @@ exports.deflatePending = deflatePending;
2156
1752
  exports.deflatePrime = deflatePrime;
2157
1753
  exports.deflateTune = deflateTune;
2158
1754
  */
2159
-
2160
1755
  exports.deflateInfo = deflateInfo;