@novnc/novnc 1.2.0 → 1.3.0-g0ef7582

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