@novnc/novnc 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/base64.js +104 -0
- package/core/crypto/aes.js +178 -0
- package/core/crypto/bigint.js +34 -0
- package/core/crypto/crypto.js +90 -0
- package/core/crypto/des.js +330 -0
- package/core/crypto/dh.js +55 -0
- package/core/crypto/md5.js +82 -0
- package/core/crypto/rsa.js +132 -0
- package/core/decoders/copyrect.js +27 -0
- package/core/decoders/h264.js +321 -0
- package/core/decoders/hextile.js +181 -0
- package/core/decoders/jpeg.js +161 -0
- package/core/decoders/raw.js +59 -0
- package/core/decoders/rre.js +44 -0
- package/core/decoders/tight.js +393 -0
- package/core/decoders/tightpng.js +27 -0
- package/core/decoders/zlib.js +51 -0
- package/core/decoders/zrle.js +185 -0
- package/core/deflator.js +84 -0
- package/core/display.js +578 -0
- package/core/encodings.js +54 -0
- package/core/inflator.js +65 -0
- package/core/input/domkeytable.js +311 -0
- package/core/input/fixedkeys.js +129 -0
- package/core/input/gesturehandler.js +567 -0
- package/core/input/keyboard.js +294 -0
- package/core/input/keysym.js +616 -0
- package/core/input/keysymdef.js +688 -0
- package/core/input/util.js +191 -0
- package/core/input/vkeys.js +116 -0
- package/core/input/xtscancodes.js +173 -0
- package/core/ra2.js +312 -0
- package/core/rfb.js +3411 -0
- package/core/util/browser.js +233 -0
- package/core/util/cursor.js +249 -0
- package/core/util/element.js +32 -0
- package/core/util/events.js +138 -0
- package/core/util/eventtarget.js +35 -0
- package/core/util/int.js +15 -0
- package/core/util/logging.js +56 -0
- package/core/util/strings.js +28 -0
- package/core/websock.js +369 -0
- package/docs/API.md +0 -5
- package/package.json +6 -10
- package/vendor/pako/LICENSE +21 -0
- package/vendor/pako/README.md +6 -0
- package/{lib/vendor → vendor}/pako/lib/utils/common.js +13 -23
- package/{lib/vendor → vendor}/pako/lib/zlib/adler32.js +12 -14
- package/vendor/pako/lib/zlib/constants.js +47 -0
- package/{lib/vendor → vendor}/pako/lib/zlib/crc32.js +15 -14
- package/{lib/vendor → vendor}/pako/lib/zlib/deflate.js +459 -334
- package/{lib/vendor → vendor}/pako/lib/zlib/gzheader.js +13 -19
- package/{lib/vendor → vendor}/pako/lib/zlib/inffast.js +116 -119
- package/vendor/pako/lib/zlib/inflate.js +1527 -0
- package/{lib/vendor → vendor}/pako/lib/zlib/inftrees.js +103 -91
- package/vendor/pako/lib/zlib/messages.js +11 -0
- package/{lib/vendor → vendor}/pako/lib/zlib/trees.js +313 -268
- package/{lib/vendor → vendor}/pako/lib/zlib/zstream.js +4 -10
- package/lib/base64.js +0 -100
- package/lib/crypto/aes.js +0 -481
- package/lib/crypto/bigint.js +0 -41
- package/lib/crypto/crypto.js +0 -109
- package/lib/crypto/des.js +0 -374
- package/lib/crypto/dh.js +0 -81
- package/lib/crypto/md5.js +0 -97
- package/lib/crypto/rsa.js +0 -312
- package/lib/decoders/copyrect.js +0 -40
- package/lib/decoders/h264.js +0 -349
- package/lib/decoders/hextile.js +0 -195
- package/lib/decoders/jpeg.js +0 -175
- package/lib/decoders/raw.js +0 -66
- package/lib/decoders/rre.js +0 -52
- package/lib/decoders/tight.js +0 -363
- package/lib/decoders/tightpng.js +0 -51
- package/lib/decoders/zlib.js +0 -57
- package/lib/decoders/zrle.js +0 -192
- package/lib/deflator.js +0 -88
- package/lib/display.js +0 -588
- package/lib/encodings.js +0 -70
- package/lib/inflator.js +0 -77
- package/lib/input/domkeytable.js +0 -313
- package/lib/input/fixedkeys.js +0 -127
- package/lib/input/gesturehandler.js +0 -573
- package/lib/input/keyboard.js +0 -293
- package/lib/input/keysym.js +0 -878
- package/lib/input/keysymdef.js +0 -1351
- package/lib/input/util.js +0 -217
- package/lib/input/vkeys.js +0 -121
- package/lib/input/xtscancodes.js +0 -343
- package/lib/ra2.js +0 -535
- package/lib/rfb.js +0 -3398
- package/lib/util/browser.js +0 -239
- package/lib/util/cursor.js +0 -269
- package/lib/util/element.js +0 -41
- package/lib/util/events.js +0 -133
- package/lib/util/eventtarget.js +0 -53
- package/lib/util/int.js +0 -21
- package/lib/util/logging.js +0 -56
- package/lib/util/strings.js +0 -36
- package/lib/vendor/pako/lib/zlib/constants.js +0 -47
- package/lib/vendor/pako/lib/zlib/inflate.js +0 -1602
- package/lib/vendor/pako/lib/zlib/messages.js +0 -25
- package/lib/websock.js +0 -395
|
@@ -1,98 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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;
|
|
11
|
-
exports.deflateInit = deflateInit;
|
|
12
|
-
exports.deflateInit2 = deflateInit2;
|
|
13
|
-
exports.deflateReset = deflateReset;
|
|
14
|
-
exports.deflateResetKeep = deflateResetKeep;
|
|
15
|
-
exports.deflateSetDictionary = deflateSetDictionary;
|
|
16
|
-
exports.deflateSetHeader = deflateSetHeader;
|
|
17
|
-
var utils = _interopRequireWildcard(require("../utils/common.js"));
|
|
18
|
-
var trees = _interopRequireWildcard(require("./trees.js"));
|
|
19
|
-
var _adler = _interopRequireDefault(require("./adler32.js"));
|
|
20
|
-
var _crc = _interopRequireDefault(require("./crc32.js"));
|
|
21
|
-
var _messages = _interopRequireDefault(require("./messages.js"));
|
|
22
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
23
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
24
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
1
|
+
import * as utils from "../utils/common.js";
|
|
2
|
+
import * as trees from "./trees.js";
|
|
3
|
+
import adler32 from "./adler32.js";
|
|
4
|
+
import crc32 from "./crc32.js";
|
|
5
|
+
import msg from "./messages.js";
|
|
6
|
+
|
|
25
7
|
/* Public constants ==========================================================*/
|
|
26
8
|
/* ===========================================================================*/
|
|
27
9
|
|
|
10
|
+
|
|
28
11
|
/* Allowed flush values; see deflate() and inflate() below for details */
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
export const Z_NO_FLUSH = 0;
|
|
13
|
+
export const Z_PARTIAL_FLUSH = 1;
|
|
31
14
|
//export const Z_SYNC_FLUSH = 2;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
export const Z_FULL_FLUSH = 3;
|
|
16
|
+
export const Z_FINISH = 4;
|
|
17
|
+
export const Z_BLOCK = 5;
|
|
35
18
|
//export const Z_TREES = 6;
|
|
36
19
|
|
|
20
|
+
|
|
37
21
|
/* Return codes for the compression/decompression functions. Negative values
|
|
38
22
|
* are errors, positive values are used for special but normal events.
|
|
39
23
|
*/
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
export const Z_OK = 0;
|
|
25
|
+
export const Z_STREAM_END = 1;
|
|
42
26
|
//export const Z_NEED_DICT = 2;
|
|
43
27
|
//export const Z_ERRNO = -1;
|
|
44
|
-
|
|
45
|
-
|
|
28
|
+
export const Z_STREAM_ERROR = -2;
|
|
29
|
+
export const Z_DATA_ERROR = -3;
|
|
46
30
|
//export const Z_MEM_ERROR = -4;
|
|
47
|
-
|
|
31
|
+
export const Z_BUF_ERROR = -5;
|
|
48
32
|
//export const Z_VERSION_ERROR = -6;
|
|
49
33
|
|
|
34
|
+
|
|
50
35
|
/* compression levels */
|
|
51
36
|
//export const Z_NO_COMPRESSION = 0;
|
|
52
37
|
//export const Z_BEST_SPEED = 1;
|
|
53
38
|
//export const Z_BEST_COMPRESSION = 9;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
39
|
+
export const Z_DEFAULT_COMPRESSION = -1;
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
export const Z_FILTERED = 1;
|
|
43
|
+
export const Z_HUFFMAN_ONLY = 2;
|
|
44
|
+
export const Z_RLE = 3;
|
|
45
|
+
export const Z_FIXED = 4;
|
|
46
|
+
export const Z_DEFAULT_STRATEGY = 0;
|
|
60
47
|
|
|
61
48
|
/* Possible values of the data_type field (though see inflate()) */
|
|
62
49
|
//export const Z_BINARY = 0;
|
|
63
50
|
//export const Z_TEXT = 1;
|
|
64
51
|
//export const Z_ASCII = 1; // = Z_TEXT
|
|
65
|
-
|
|
52
|
+
export const Z_UNKNOWN = 2;
|
|
53
|
+
|
|
66
54
|
|
|
67
55
|
/* The deflate compression method */
|
|
68
|
-
|
|
56
|
+
export const Z_DEFLATED = 8;
|
|
69
57
|
|
|
70
58
|
/*============================================================================*/
|
|
71
59
|
|
|
60
|
+
|
|
72
61
|
var MAX_MEM_LEVEL = 9;
|
|
73
62
|
/* Maximum value for memLevel in deflateInit2 */
|
|
74
63
|
var MAX_WBITS = 15;
|
|
75
64
|
/* 32K LZ77 window */
|
|
76
65
|
var DEF_MEM_LEVEL = 8;
|
|
77
|
-
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
var LENGTH_CODES = 29;
|
|
78
69
|
/* number of length codes, not counting the special END_BLOCK code */
|
|
79
|
-
var LITERALS
|
|
70
|
+
var LITERALS = 256;
|
|
80
71
|
/* number of literal bytes 0..255 */
|
|
81
|
-
var L_CODES
|
|
72
|
+
var L_CODES = LITERALS + 1 + LENGTH_CODES;
|
|
82
73
|
/* number of Literal or Length codes, including the END_BLOCK code */
|
|
83
|
-
var D_CODES
|
|
74
|
+
var D_CODES = 30;
|
|
84
75
|
/* number of distance codes */
|
|
85
|
-
var BL_CODES
|
|
76
|
+
var BL_CODES = 19;
|
|
86
77
|
/* number of codes used to transfer the bit lengths */
|
|
87
|
-
var HEAP_SIZE
|
|
78
|
+
var HEAP_SIZE = 2 * L_CODES + 1;
|
|
88
79
|
/* maximum heap size */
|
|
89
|
-
var MAX_BITS
|
|
80
|
+
var MAX_BITS = 15;
|
|
90
81
|
/* All codes must not exceed MAX_BITS bits */
|
|
91
82
|
|
|
92
83
|
var MIN_MATCH = 3;
|
|
93
84
|
var MAX_MATCH = 258;
|
|
94
|
-
var MIN_LOOKAHEAD = MAX_MATCH + MIN_MATCH + 1;
|
|
85
|
+
var MIN_LOOKAHEAD = (MAX_MATCH + MIN_MATCH + 1);
|
|
86
|
+
|
|
95
87
|
var PRESET_DICT = 0x20;
|
|
88
|
+
|
|
96
89
|
var INIT_STATE = 42;
|
|
97
90
|
var EXTRA_STATE = 69;
|
|
98
91
|
var NAME_STATE = 73;
|
|
@@ -100,27 +93,26 @@ var COMMENT_STATE = 91;
|
|
|
100
93
|
var HCRC_STATE = 103;
|
|
101
94
|
var BUSY_STATE = 113;
|
|
102
95
|
var FINISH_STATE = 666;
|
|
103
|
-
|
|
104
|
-
var
|
|
96
|
+
|
|
97
|
+
var BS_NEED_MORE = 1; /* block not completed, need more input or more output */
|
|
98
|
+
var BS_BLOCK_DONE = 2; /* block flush performed */
|
|
105
99
|
var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */
|
|
106
|
-
var BS_FINISH_DONE
|
|
100
|
+
var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */
|
|
107
101
|
|
|
108
102
|
var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.
|
|
109
103
|
|
|
110
104
|
function err(strm, errorCode) {
|
|
111
|
-
strm.msg =
|
|
105
|
+
strm.msg = msg[errorCode];
|
|
112
106
|
return errorCode;
|
|
113
107
|
}
|
|
108
|
+
|
|
114
109
|
function rank(f) {
|
|
115
|
-
return (f << 1) - (f > 4 ? 9 : 0);
|
|
116
|
-
}
|
|
117
|
-
function zero(buf) {
|
|
118
|
-
var len = buf.length;
|
|
119
|
-
while (--len >= 0) {
|
|
120
|
-
buf[len] = 0;
|
|
121
|
-
}
|
|
110
|
+
return ((f) << 1) - ((f) > 4 ? 9 : 0);
|
|
122
111
|
}
|
|
123
112
|
|
|
113
|
+
function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
|
|
114
|
+
|
|
115
|
+
|
|
124
116
|
/* =========================================================================
|
|
125
117
|
* Flush as much pending output as possible. All deflate() output goes
|
|
126
118
|
* through this function so some applications may wish to modify it
|
|
@@ -135,9 +127,8 @@ function flush_pending(strm) {
|
|
|
135
127
|
if (len > strm.avail_out) {
|
|
136
128
|
len = strm.avail_out;
|
|
137
129
|
}
|
|
138
|
-
if (len === 0) {
|
|
139
|
-
|
|
140
|
-
}
|
|
130
|
+
if (len === 0) { return; }
|
|
131
|
+
|
|
141
132
|
utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);
|
|
142
133
|
strm.next_out += len;
|
|
143
134
|
s.pending_out += len;
|
|
@@ -148,27 +139,33 @@ function flush_pending(strm) {
|
|
|
148
139
|
s.pending_out = 0;
|
|
149
140
|
}
|
|
150
141
|
}
|
|
142
|
+
|
|
143
|
+
|
|
151
144
|
function flush_block_only(s, last) {
|
|
152
|
-
trees._tr_flush_block(s, s.block_start >= 0 ? s.block_start : -1, s.strstart - s.block_start, last);
|
|
145
|
+
trees._tr_flush_block(s, (s.block_start >= 0 ? s.block_start : -1), s.strstart - s.block_start, last);
|
|
153
146
|
s.block_start = s.strstart;
|
|
154
147
|
flush_pending(s.strm);
|
|
155
148
|
}
|
|
149
|
+
|
|
150
|
+
|
|
156
151
|
function put_byte(s, b) {
|
|
157
152
|
s.pending_buf[s.pending++] = b;
|
|
158
153
|
}
|
|
159
154
|
|
|
155
|
+
|
|
160
156
|
/* =========================================================================
|
|
161
157
|
* Put a short in the pending buffer. The 16-bit value is put in MSB order.
|
|
162
158
|
* IN assertion: the stream state is correct and there is enough room in
|
|
163
159
|
* pending_buf.
|
|
164
160
|
*/
|
|
165
161
|
function putShortMSB(s, b) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
s.pending_buf[s.pending++] = b >>> 8 & 0xff;
|
|
162
|
+
// put_byte(s, (Byte)(b >> 8));
|
|
163
|
+
// put_byte(s, (Byte)(b & 0xff));
|
|
164
|
+
s.pending_buf[s.pending++] = (b >>> 8) & 0xff;
|
|
169
165
|
s.pending_buf[s.pending++] = b & 0xff;
|
|
170
166
|
}
|
|
171
167
|
|
|
168
|
+
|
|
172
169
|
/* ===========================================================================
|
|
173
170
|
* Read a new buffer from the current input stream, update the adler32
|
|
174
171
|
* and total number of bytes read. All deflate() input goes through
|
|
@@ -178,26 +175,29 @@ function putShortMSB(s, b) {
|
|
|
178
175
|
*/
|
|
179
176
|
function read_buf(strm, buf, start, size) {
|
|
180
177
|
var len = strm.avail_in;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return 0;
|
|
186
|
-
}
|
|
178
|
+
|
|
179
|
+
if (len > size) { len = size; }
|
|
180
|
+
if (len === 0) { return 0; }
|
|
181
|
+
|
|
187
182
|
strm.avail_in -= len;
|
|
188
183
|
|
|
189
184
|
// zmemcpy(buf, strm->next_in, len);
|
|
190
185
|
utils.arraySet(buf, strm.input, strm.next_in, len, start);
|
|
191
186
|
if (strm.state.wrap === 1) {
|
|
192
|
-
strm.adler = (
|
|
193
|
-
} else if (strm.state.wrap === 2) {
|
|
194
|
-
strm.adler = (0, _crc["default"])(strm.adler, buf, len, start);
|
|
187
|
+
strm.adler = adler32(strm.adler, buf, len, start);
|
|
195
188
|
}
|
|
189
|
+
|
|
190
|
+
else if (strm.state.wrap === 2) {
|
|
191
|
+
strm.adler = crc32(strm.adler, buf, len, start);
|
|
192
|
+
}
|
|
193
|
+
|
|
196
194
|
strm.next_in += len;
|
|
197
195
|
strm.total_in += len;
|
|
196
|
+
|
|
198
197
|
return len;
|
|
199
198
|
}
|
|
200
199
|
|
|
200
|
+
|
|
201
201
|
/* ===========================================================================
|
|
202
202
|
* Set match_start to the longest match starting at the given string and
|
|
203
203
|
* return its length. Matches shorter or equal to prev_length are discarded,
|
|
@@ -208,25 +208,27 @@ function read_buf(strm, buf, start, size) {
|
|
|
208
208
|
* OUT assertion: the match length is not greater than s->lookahead.
|
|
209
209
|
*/
|
|
210
210
|
function longest_match(s, cur_match) {
|
|
211
|
-
var chain_length = s.max_chain_length;
|
|
211
|
+
var chain_length = s.max_chain_length; /* max hash chain length */
|
|
212
212
|
var scan = s.strstart; /* current string */
|
|
213
|
-
var match;
|
|
214
|
-
var len;
|
|
215
|
-
var best_len = s.prev_length;
|
|
216
|
-
var nice_match = s.nice_match;
|
|
217
|
-
var limit = s.strstart >
|
|
213
|
+
var match; /* matched string */
|
|
214
|
+
var len; /* length of current match */
|
|
215
|
+
var best_len = s.prev_length; /* best match length so far */
|
|
216
|
+
var nice_match = s.nice_match; /* stop if match long enough */
|
|
217
|
+
var limit = (s.strstart > (s.w_size - MIN_LOOKAHEAD)) ?
|
|
218
|
+
s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0/*NIL*/;
|
|
219
|
+
|
|
218
220
|
var _win = s.window; // shortcut
|
|
219
221
|
|
|
220
222
|
var wmask = s.w_mask;
|
|
221
|
-
var prev
|
|
223
|
+
var prev = s.prev;
|
|
222
224
|
|
|
223
225
|
/* Stop when cur_match becomes <= limit. To simplify the code,
|
|
224
226
|
* we prevent matches with the string of window index 0.
|
|
225
227
|
*/
|
|
226
228
|
|
|
227
229
|
var strend = s.strstart + MAX_MATCH;
|
|
228
|
-
var scan_end1
|
|
229
|
-
var scan_end
|
|
230
|
+
var scan_end1 = _win[scan + best_len - 1];
|
|
231
|
+
var scan_end = _win[scan + best_len];
|
|
230
232
|
|
|
231
233
|
/* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
|
|
232
234
|
* It is easy to get rid of this optimization if necessary.
|
|
@@ -240,9 +242,7 @@ function longest_match(s, cur_match) {
|
|
|
240
242
|
/* Do not look for matches beyond the end of the input. This is necessary
|
|
241
243
|
* to make deflate deterministic.
|
|
242
244
|
*/
|
|
243
|
-
if (nice_match > s.lookahead) {
|
|
244
|
-
nice_match = s.lookahead;
|
|
245
|
-
}
|
|
245
|
+
if (nice_match > s.lookahead) { nice_match = s.lookahead; }
|
|
246
246
|
|
|
247
247
|
// Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
|
|
248
248
|
|
|
@@ -259,7 +259,10 @@ function longest_match(s, cur_match) {
|
|
|
259
259
|
* the output of deflate is not affected by the uninitialized values.
|
|
260
260
|
*/
|
|
261
261
|
|
|
262
|
-
if (_win[match + best_len]
|
|
262
|
+
if (_win[match + best_len] !== scan_end ||
|
|
263
|
+
_win[match + best_len - 1] !== scan_end1 ||
|
|
264
|
+
_win[match] !== _win[scan] ||
|
|
265
|
+
_win[++match] !== _win[scan + 1]) {
|
|
263
266
|
continue;
|
|
264
267
|
}
|
|
265
268
|
|
|
@@ -278,28 +281,35 @@ function longest_match(s, cur_match) {
|
|
|
278
281
|
*/
|
|
279
282
|
do {
|
|
280
283
|
// Do nothing
|
|
281
|
-
} while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
|
|
284
|
+
} while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
|
|
285
|
+
_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
|
|
286
|
+
_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
|
|
287
|
+
_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
|
|
288
|
+
scan < strend);
|
|
282
289
|
|
|
283
290
|
// Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
|
|
284
291
|
|
|
285
292
|
len = MAX_MATCH - (strend - scan);
|
|
286
293
|
scan = strend - MAX_MATCH;
|
|
294
|
+
|
|
287
295
|
if (len > best_len) {
|
|
288
296
|
s.match_start = cur_match;
|
|
289
297
|
best_len = len;
|
|
290
298
|
if (len >= nice_match) {
|
|
291
299
|
break;
|
|
292
300
|
}
|
|
293
|
-
scan_end1
|
|
294
|
-
scan_end
|
|
301
|
+
scan_end1 = _win[scan + best_len - 1];
|
|
302
|
+
scan_end = _win[scan + best_len];
|
|
295
303
|
}
|
|
296
304
|
} while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0);
|
|
305
|
+
|
|
297
306
|
if (best_len <= s.lookahead) {
|
|
298
307
|
return best_len;
|
|
299
308
|
}
|
|
300
309
|
return s.lookahead;
|
|
301
310
|
}
|
|
302
311
|
|
|
312
|
+
|
|
303
313
|
/* ===========================================================================
|
|
304
314
|
* Fill the window when the lookahead becomes insufficient.
|
|
305
315
|
* Updates strstart and lookahead.
|
|
@@ -333,10 +343,12 @@ function fill_window(s) {
|
|
|
333
343
|
// }
|
|
334
344
|
//}
|
|
335
345
|
|
|
346
|
+
|
|
336
347
|
/* If the window is almost full and there is insufficient lookahead,
|
|
337
348
|
* move the upper half to the lower one to make room in the upper half.
|
|
338
349
|
*/
|
|
339
350
|
if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {
|
|
351
|
+
|
|
340
352
|
utils.arraySet(s.window, s.window, _w_size, _w_size, 0);
|
|
341
353
|
s.match_start -= _w_size;
|
|
342
354
|
s.strstart -= _w_size;
|
|
@@ -354,17 +366,19 @@ function fill_window(s) {
|
|
|
354
366
|
p = n;
|
|
355
367
|
do {
|
|
356
368
|
m = s.head[--p];
|
|
357
|
-
s.head[p] = m >= _w_size ? m - _w_size : 0;
|
|
369
|
+
s.head[p] = (m >= _w_size ? m - _w_size : 0);
|
|
358
370
|
} while (--n);
|
|
371
|
+
|
|
359
372
|
n = _w_size;
|
|
360
373
|
p = n;
|
|
361
374
|
do {
|
|
362
375
|
m = s.prev[--p];
|
|
363
|
-
s.prev[p] = m >= _w_size ? m - _w_size : 0;
|
|
376
|
+
s.prev[p] = (m >= _w_size ? m - _w_size : 0);
|
|
364
377
|
/* If n is not on any hash chain, prev[n] is garbage but
|
|
365
378
|
* its value will never be used.
|
|
366
379
|
*/
|
|
367
380
|
} while (--n);
|
|
381
|
+
|
|
368
382
|
more += _w_size;
|
|
369
383
|
}
|
|
370
384
|
if (s.strm.avail_in === 0) {
|
|
@@ -392,13 +406,14 @@ function fill_window(s) {
|
|
|
392
406
|
s.ins_h = s.window[str];
|
|
393
407
|
|
|
394
408
|
/* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */
|
|
395
|
-
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + 1]) & s.hash_mask;
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
409
|
+
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + 1]) & s.hash_mask;
|
|
410
|
+
//#if MIN_MATCH != 3
|
|
411
|
+
// Call update_hash() MIN_MATCH-3 more times
|
|
412
|
+
//#endif
|
|
399
413
|
while (s.insert) {
|
|
400
414
|
/* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
|
|
401
|
-
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
|
|
415
|
+
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
|
|
416
|
+
|
|
402
417
|
s.prev[str & s.w_mask] = s.head[s.ins_h];
|
|
403
418
|
s.head[s.ins_h] = str;
|
|
404
419
|
str++;
|
|
@@ -411,6 +426,7 @@ function fill_window(s) {
|
|
|
411
426
|
/* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
|
|
412
427
|
* but this is not important since only literal bytes will be emitted.
|
|
413
428
|
*/
|
|
429
|
+
|
|
414
430
|
} while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0);
|
|
415
431
|
|
|
416
432
|
/* If the WIN_INIT bytes after the end of the current data have never been
|
|
@@ -420,35 +436,35 @@ function fill_window(s) {
|
|
|
420
436
|
* time through here. WIN_INIT is set to MAX_MATCH since the longest match
|
|
421
437
|
* routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
|
|
422
438
|
*/
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
439
|
+
// if (s.high_water < s.window_size) {
|
|
440
|
+
// var curr = s.strstart + s.lookahead;
|
|
441
|
+
// var init = 0;
|
|
442
|
+
//
|
|
443
|
+
// if (s.high_water < curr) {
|
|
444
|
+
// /* Previous high water mark below current data -- zero WIN_INIT
|
|
445
|
+
// * bytes or up to end of window, whichever is less.
|
|
446
|
+
// */
|
|
447
|
+
// init = s.window_size - curr;
|
|
448
|
+
// if (init > WIN_INIT)
|
|
449
|
+
// init = WIN_INIT;
|
|
450
|
+
// zmemzero(s->window + curr, (unsigned)init);
|
|
451
|
+
// s->high_water = curr + init;
|
|
452
|
+
// }
|
|
453
|
+
// else if (s->high_water < (ulg)curr + WIN_INIT) {
|
|
454
|
+
// /* High water mark at or above current data, but below current data
|
|
455
|
+
// * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
|
|
456
|
+
// * to end of window, whichever is less.
|
|
457
|
+
// */
|
|
458
|
+
// init = (ulg)curr + WIN_INIT - s->high_water;
|
|
459
|
+
// if (init > s->window_size - s->high_water)
|
|
460
|
+
// init = s->window_size - s->high_water;
|
|
461
|
+
// zmemzero(s->window + s->high_water, (unsigned)init);
|
|
462
|
+
// s->high_water += init;
|
|
463
|
+
// }
|
|
464
|
+
// }
|
|
465
|
+
//
|
|
466
|
+
// Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
|
|
467
|
+
// "not enough room for search");
|
|
452
468
|
}
|
|
453
469
|
|
|
454
470
|
/* ===========================================================================
|
|
@@ -465,6 +481,7 @@ function deflate_stored(s, flush) {
|
|
|
465
481
|
* to pending_buf_size, and each stored block has a 5 byte header:
|
|
466
482
|
*/
|
|
467
483
|
var max_block_size = 0xffff;
|
|
484
|
+
|
|
468
485
|
if (max_block_size > s.pending_buf_size - 5) {
|
|
469
486
|
max_block_size = s.pending_buf_size - 5;
|
|
470
487
|
}
|
|
@@ -473,30 +490,33 @@ function deflate_stored(s, flush) {
|
|
|
473
490
|
for (;;) {
|
|
474
491
|
/* Fill the window as much as possible: */
|
|
475
492
|
if (s.lookahead <= 1) {
|
|
493
|
+
|
|
476
494
|
//Assert(s->strstart < s->w_size+MAX_DIST(s) ||
|
|
477
495
|
// s->block_start >= (long)s->w_size, "slide too late");
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
496
|
+
// if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) ||
|
|
497
|
+
// s.block_start >= s.w_size)) {
|
|
498
|
+
// throw new Error("slide too late");
|
|
499
|
+
// }
|
|
482
500
|
|
|
483
501
|
fill_window(s);
|
|
484
502
|
if (s.lookahead === 0 && flush === Z_NO_FLUSH) {
|
|
485
503
|
return BS_NEED_MORE;
|
|
486
504
|
}
|
|
505
|
+
|
|
487
506
|
if (s.lookahead === 0) {
|
|
488
507
|
break;
|
|
489
508
|
}
|
|
490
509
|
/* flush the current block */
|
|
491
510
|
}
|
|
492
511
|
//Assert(s->block_start >= 0L, "block gone");
|
|
493
|
-
|
|
512
|
+
// if (s.block_start < 0) throw new Error("block gone");
|
|
494
513
|
|
|
495
514
|
s.strstart += s.lookahead;
|
|
496
515
|
s.lookahead = 0;
|
|
497
516
|
|
|
498
517
|
/* Emit a stored block if pending_buf will be full: */
|
|
499
518
|
var max_start = s.block_start + max_block_size;
|
|
519
|
+
|
|
500
520
|
if (s.strstart === 0 || s.strstart >= max_start) {
|
|
501
521
|
/* strstart == 0 is possible when wraparound on 16-bit machine */
|
|
502
522
|
s.lookahead = s.strstart - max_start;
|
|
@@ -507,11 +527,13 @@ function deflate_stored(s, flush) {
|
|
|
507
527
|
return BS_NEED_MORE;
|
|
508
528
|
}
|
|
509
529
|
/***/
|
|
530
|
+
|
|
531
|
+
|
|
510
532
|
}
|
|
511
533
|
/* Flush if we may have to slide, otherwise block_start may become
|
|
512
534
|
* negative and the data will be gone:
|
|
513
535
|
*/
|
|
514
|
-
if (s.strstart - s.block_start >= s.w_size - MIN_LOOKAHEAD) {
|
|
536
|
+
if (s.strstart - s.block_start >= (s.w_size - MIN_LOOKAHEAD)) {
|
|
515
537
|
/*** FLUSH_BLOCK(s, 0); ***/
|
|
516
538
|
flush_block_only(s, false);
|
|
517
539
|
if (s.strm.avail_out === 0) {
|
|
@@ -520,7 +542,9 @@ function deflate_stored(s, flush) {
|
|
|
520
542
|
/***/
|
|
521
543
|
}
|
|
522
544
|
}
|
|
545
|
+
|
|
523
546
|
s.insert = 0;
|
|
547
|
+
|
|
524
548
|
if (flush === Z_FINISH) {
|
|
525
549
|
/*** FLUSH_BLOCK(s, 1); ***/
|
|
526
550
|
flush_block_only(s, true);
|
|
@@ -530,6 +554,7 @@ function deflate_stored(s, flush) {
|
|
|
530
554
|
/***/
|
|
531
555
|
return BS_FINISH_DONE;
|
|
532
556
|
}
|
|
557
|
+
|
|
533
558
|
if (s.strstart > s.block_start) {
|
|
534
559
|
/*** FLUSH_BLOCK(s, 0); ***/
|
|
535
560
|
flush_block_only(s, false);
|
|
@@ -538,6 +563,7 @@ function deflate_stored(s, flush) {
|
|
|
538
563
|
}
|
|
539
564
|
/***/
|
|
540
565
|
}
|
|
566
|
+
|
|
541
567
|
return BS_NEED_MORE;
|
|
542
568
|
}
|
|
543
569
|
|
|
@@ -549,8 +575,8 @@ function deflate_stored(s, flush) {
|
|
|
549
575
|
* matches. It is used only for the fast compression options.
|
|
550
576
|
*/
|
|
551
577
|
function deflate_fast(s, flush) {
|
|
552
|
-
var hash_head;
|
|
553
|
-
var bflush;
|
|
578
|
+
var hash_head; /* head of the hash chain */
|
|
579
|
+
var bflush; /* set if current block must be flushed */
|
|
554
580
|
|
|
555
581
|
for (;;) {
|
|
556
582
|
/* Make sure that we always have enough lookahead, except
|
|
@@ -571,10 +597,10 @@ function deflate_fast(s, flush) {
|
|
|
571
597
|
/* Insert the string window[strstart .. strstart+2] in the
|
|
572
598
|
* dictionary, and set hash_head to the head of the hash chain:
|
|
573
599
|
*/
|
|
574
|
-
hash_head = 0
|
|
600
|
+
hash_head = 0/*NIL*/;
|
|
575
601
|
if (s.lookahead >= MIN_MATCH) {
|
|
576
602
|
/*** INSERT_STRING(s, s.strstart, hash_head); ***/
|
|
577
|
-
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
|
|
603
|
+
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
|
|
578
604
|
hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
|
|
579
605
|
s.head[s.ins_h] = s.strstart;
|
|
580
606
|
/***/
|
|
@@ -583,7 +609,7 @@ function deflate_fast(s, flush) {
|
|
|
583
609
|
/* Find the longest match, discarding those <= prev_length.
|
|
584
610
|
* At this point we have always match_length < MIN_MATCH
|
|
585
611
|
*/
|
|
586
|
-
if (hash_head !== 0
|
|
612
|
+
if (hash_head !== 0/*NIL*/ && ((s.strstart - hash_head) <= (s.w_size - MIN_LOOKAHEAD))) {
|
|
587
613
|
/* To simplify the code, we prevent matches with the string
|
|
588
614
|
* of window index 0 (in particular we have to avoid a match
|
|
589
615
|
* of the string with itself at the start of the input file).
|
|
@@ -597,17 +623,18 @@ function deflate_fast(s, flush) {
|
|
|
597
623
|
/*** _tr_tally_dist(s, s.strstart - s.match_start,
|
|
598
624
|
s.match_length - MIN_MATCH, bflush); ***/
|
|
599
625
|
bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);
|
|
626
|
+
|
|
600
627
|
s.lookahead -= s.match_length;
|
|
601
628
|
|
|
602
629
|
/* Insert new strings in the hash table only if the match length
|
|
603
630
|
* is not too large. This saves time but degrades compression.
|
|
604
631
|
*/
|
|
605
|
-
if (s.match_length <= s.max_lazy_match
|
|
632
|
+
if (s.match_length <= s.max_lazy_match/*max_insert_length*/ && s.lookahead >= MIN_MATCH) {
|
|
606
633
|
s.match_length--; /* string at strstart already in table */
|
|
607
634
|
do {
|
|
608
635
|
s.strstart++;
|
|
609
636
|
/*** INSERT_STRING(s, s.strstart, hash_head); ***/
|
|
610
|
-
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
|
|
637
|
+
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
|
|
611
638
|
hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
|
|
612
639
|
s.head[s.ins_h] = s.strstart;
|
|
613
640
|
/***/
|
|
@@ -616,16 +643,17 @@ function deflate_fast(s, flush) {
|
|
|
616
643
|
*/
|
|
617
644
|
} while (--s.match_length !== 0);
|
|
618
645
|
s.strstart++;
|
|
619
|
-
} else
|
|
646
|
+
} else
|
|
647
|
+
{
|
|
620
648
|
s.strstart += s.match_length;
|
|
621
649
|
s.match_length = 0;
|
|
622
650
|
s.ins_h = s.window[s.strstart];
|
|
623
651
|
/* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */
|
|
624
|
-
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + 1]) & s.hash_mask;
|
|
652
|
+
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + 1]) & s.hash_mask;
|
|
625
653
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
654
|
+
//#if MIN_MATCH != 3
|
|
655
|
+
// Call UPDATE_HASH() MIN_MATCH-3 more times
|
|
656
|
+
//#endif
|
|
629
657
|
/* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
|
|
630
658
|
* matter since it will be recomputed at next deflate call.
|
|
631
659
|
*/
|
|
@@ -635,6 +663,7 @@ function deflate_fast(s, flush) {
|
|
|
635
663
|
//Tracevv((stderr,"%c", s.window[s.strstart]));
|
|
636
664
|
/*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
|
|
637
665
|
bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
|
|
666
|
+
|
|
638
667
|
s.lookahead--;
|
|
639
668
|
s.strstart++;
|
|
640
669
|
}
|
|
@@ -647,7 +676,7 @@ function deflate_fast(s, flush) {
|
|
|
647
676
|
/***/
|
|
648
677
|
}
|
|
649
678
|
}
|
|
650
|
-
s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;
|
|
679
|
+
s.insert = ((s.strstart < (MIN_MATCH - 1)) ? s.strstart : MIN_MATCH - 1);
|
|
651
680
|
if (flush === Z_FINISH) {
|
|
652
681
|
/*** FLUSH_BLOCK(s, 1); ***/
|
|
653
682
|
flush_block_only(s, true);
|
|
@@ -674,8 +703,8 @@ function deflate_fast(s, flush) {
|
|
|
674
703
|
* no better match at the next window position.
|
|
675
704
|
*/
|
|
676
705
|
function deflate_slow(s, flush) {
|
|
677
|
-
var hash_head;
|
|
678
|
-
var bflush;
|
|
706
|
+
var hash_head; /* head of hash chain */
|
|
707
|
+
var bflush; /* set if current block must be flushed */
|
|
679
708
|
|
|
680
709
|
var max_insert;
|
|
681
710
|
|
|
@@ -691,18 +720,16 @@ function deflate_slow(s, flush) {
|
|
|
691
720
|
if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
|
|
692
721
|
return BS_NEED_MORE;
|
|
693
722
|
}
|
|
694
|
-
if (s.lookahead === 0) {
|
|
695
|
-
break;
|
|
696
|
-
} /* flush the current block */
|
|
723
|
+
if (s.lookahead === 0) { break; } /* flush the current block */
|
|
697
724
|
}
|
|
698
725
|
|
|
699
726
|
/* Insert the string window[strstart .. strstart+2] in the
|
|
700
727
|
* dictionary, and set hash_head to the head of the hash chain:
|
|
701
728
|
*/
|
|
702
|
-
hash_head = 0
|
|
729
|
+
hash_head = 0/*NIL*/;
|
|
703
730
|
if (s.lookahead >= MIN_MATCH) {
|
|
704
731
|
/*** INSERT_STRING(s, s.strstart, hash_head); ***/
|
|
705
|
-
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
|
|
732
|
+
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
|
|
706
733
|
hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
|
|
707
734
|
s.head[s.ins_h] = s.strstart;
|
|
708
735
|
/***/
|
|
@@ -713,7 +740,9 @@ function deflate_slow(s, flush) {
|
|
|
713
740
|
s.prev_length = s.match_length;
|
|
714
741
|
s.prev_match = s.match_start;
|
|
715
742
|
s.match_length = MIN_MATCH - 1;
|
|
716
|
-
|
|
743
|
+
|
|
744
|
+
if (hash_head !== 0/*NIL*/ && s.prev_length < s.max_lazy_match &&
|
|
745
|
+
s.strstart - hash_head <= (s.w_size - MIN_LOOKAHEAD)/*MAX_DIST(s)*/) {
|
|
717
746
|
/* To simplify the code, we prevent matches with the string
|
|
718
747
|
* of window index 0 (in particular we have to avoid a match
|
|
719
748
|
* of the string with itself at the start of the input file).
|
|
@@ -721,7 +750,9 @@ function deflate_slow(s, flush) {
|
|
|
721
750
|
s.match_length = longest_match(s, hash_head);
|
|
722
751
|
/* longest_match() sets match_start */
|
|
723
752
|
|
|
724
|
-
if (s.match_length <= 5 &&
|
|
753
|
+
if (s.match_length <= 5 &&
|
|
754
|
+
(s.strategy === Z_FILTERED || (s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096/*TOO_FAR*/))) {
|
|
755
|
+
|
|
725
756
|
/* If prev_match is also MIN_MATCH, match_start is garbage
|
|
726
757
|
* but we will ignore the current match anyway.
|
|
727
758
|
*/
|
|
@@ -750,7 +781,7 @@ function deflate_slow(s, flush) {
|
|
|
750
781
|
do {
|
|
751
782
|
if (++s.strstart <= max_insert) {
|
|
752
783
|
/*** INSERT_STRING(s, s.strstart, hash_head); ***/
|
|
753
|
-
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
|
|
784
|
+
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
|
|
754
785
|
hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
|
|
755
786
|
s.head[s.ins_h] = s.strstart;
|
|
756
787
|
/***/
|
|
@@ -759,6 +790,7 @@ function deflate_slow(s, flush) {
|
|
|
759
790
|
s.match_available = 0;
|
|
760
791
|
s.match_length = MIN_MATCH - 1;
|
|
761
792
|
s.strstart++;
|
|
793
|
+
|
|
762
794
|
if (bflush) {
|
|
763
795
|
/*** FLUSH_BLOCK(s, 0); ***/
|
|
764
796
|
flush_block_only(s, false);
|
|
@@ -767,6 +799,7 @@ function deflate_slow(s, flush) {
|
|
|
767
799
|
}
|
|
768
800
|
/***/
|
|
769
801
|
}
|
|
802
|
+
|
|
770
803
|
} else if (s.match_available) {
|
|
771
804
|
/* If there was no match at the previous position, output a
|
|
772
805
|
* single literal. If there was a match but the current match
|
|
@@ -775,6 +808,7 @@ function deflate_slow(s, flush) {
|
|
|
775
808
|
//Tracevv((stderr,"%c", s->window[s->strstart-1]));
|
|
776
809
|
/*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
|
|
777
810
|
bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
|
|
811
|
+
|
|
778
812
|
if (bflush) {
|
|
779
813
|
/*** FLUSH_BLOCK_ONLY(s, 0) ***/
|
|
780
814
|
flush_block_only(s, false);
|
|
@@ -799,6 +833,7 @@ function deflate_slow(s, flush) {
|
|
|
799
833
|
//Tracevv((stderr,"%c", s->window[s->strstart-1]));
|
|
800
834
|
/*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
|
|
801
835
|
bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
|
|
836
|
+
|
|
802
837
|
s.match_available = 0;
|
|
803
838
|
}
|
|
804
839
|
s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;
|
|
@@ -819,20 +854,23 @@ function deflate_slow(s, flush) {
|
|
|
819
854
|
}
|
|
820
855
|
/***/
|
|
821
856
|
}
|
|
857
|
+
|
|
822
858
|
return BS_BLOCK_DONE;
|
|
823
859
|
}
|
|
824
860
|
|
|
861
|
+
|
|
825
862
|
/* ===========================================================================
|
|
826
863
|
* For Z_RLE, simply look for runs of bytes, generate matches only of distance
|
|
827
864
|
* one. Do not maintain a hash table. (It will be regenerated if this run of
|
|
828
865
|
* deflate switches away from Z_RLE.)
|
|
829
866
|
*/
|
|
830
867
|
function deflate_rle(s, flush) {
|
|
831
|
-
var bflush;
|
|
832
|
-
var prev;
|
|
833
|
-
var scan, strend;
|
|
868
|
+
var bflush; /* set if current block must be flushed */
|
|
869
|
+
var prev; /* byte at distance one to match */
|
|
870
|
+
var scan, strend; /* scan goes up to strend for length of run */
|
|
834
871
|
|
|
835
872
|
var _win = s.window;
|
|
873
|
+
|
|
836
874
|
for (;;) {
|
|
837
875
|
/* Make sure that we always have enough lookahead, except
|
|
838
876
|
* at the end of the input file. We need MAX_MATCH bytes
|
|
@@ -843,9 +881,7 @@ function deflate_rle(s, flush) {
|
|
|
843
881
|
if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) {
|
|
844
882
|
return BS_NEED_MORE;
|
|
845
883
|
}
|
|
846
|
-
if (s.lookahead === 0) {
|
|
847
|
-
break;
|
|
848
|
-
} /* flush the current block */
|
|
884
|
+
if (s.lookahead === 0) { break; } /* flush the current block */
|
|
849
885
|
}
|
|
850
886
|
|
|
851
887
|
/* See how many times the previous byte repeats */
|
|
@@ -857,7 +893,11 @@ function deflate_rle(s, flush) {
|
|
|
857
893
|
strend = s.strstart + MAX_MATCH;
|
|
858
894
|
do {
|
|
859
895
|
// Do nothing
|
|
860
|
-
} while (prev === _win[++scan] && prev === _win[++scan] &&
|
|
896
|
+
} while (prev === _win[++scan] && prev === _win[++scan] &&
|
|
897
|
+
prev === _win[++scan] && prev === _win[++scan] &&
|
|
898
|
+
prev === _win[++scan] && prev === _win[++scan] &&
|
|
899
|
+
prev === _win[++scan] && prev === _win[++scan] &&
|
|
900
|
+
scan < strend);
|
|
861
901
|
s.match_length = MAX_MATCH - (strend - scan);
|
|
862
902
|
if (s.match_length > s.lookahead) {
|
|
863
903
|
s.match_length = s.lookahead;
|
|
@@ -872,6 +912,7 @@ function deflate_rle(s, flush) {
|
|
|
872
912
|
|
|
873
913
|
/*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/
|
|
874
914
|
bflush = trees._tr_tally(s, 1, s.match_length - MIN_MATCH);
|
|
915
|
+
|
|
875
916
|
s.lookahead -= s.match_length;
|
|
876
917
|
s.strstart += s.match_length;
|
|
877
918
|
s.match_length = 0;
|
|
@@ -880,6 +921,7 @@ function deflate_rle(s, flush) {
|
|
|
880
921
|
//Tracevv((stderr,"%c", s->window[s->strstart]));
|
|
881
922
|
/*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
|
|
882
923
|
bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
|
|
924
|
+
|
|
883
925
|
s.lookahead--;
|
|
884
926
|
s.strstart++;
|
|
885
927
|
}
|
|
@@ -918,7 +960,7 @@ function deflate_rle(s, flush) {
|
|
|
918
960
|
* (It will be regenerated if this run of deflate switches away from Huffman.)
|
|
919
961
|
*/
|
|
920
962
|
function deflate_huff(s, flush) {
|
|
921
|
-
var bflush;
|
|
963
|
+
var bflush; /* set if current block must be flushed */
|
|
922
964
|
|
|
923
965
|
for (;;) {
|
|
924
966
|
/* Make sure that we have a literal to write. */
|
|
@@ -928,7 +970,7 @@ function deflate_huff(s, flush) {
|
|
|
928
970
|
if (flush === Z_NO_FLUSH) {
|
|
929
971
|
return BS_NEED_MORE;
|
|
930
972
|
}
|
|
931
|
-
break;
|
|
973
|
+
break; /* flush the current block */
|
|
932
974
|
}
|
|
933
975
|
}
|
|
934
976
|
|
|
@@ -981,19 +1023,24 @@ function Config(good_length, max_lazy, nice_length, max_chain, func) {
|
|
|
981
1023
|
this.max_chain = max_chain;
|
|
982
1024
|
this.func = func;
|
|
983
1025
|
}
|
|
1026
|
+
|
|
984
1027
|
var configuration_table;
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
new Config(
|
|
989
|
-
new Config(4,
|
|
990
|
-
|
|
991
|
-
new Config(4,
|
|
992
|
-
|
|
993
|
-
new Config(
|
|
994
|
-
new Config(8,
|
|
995
|
-
new Config(
|
|
996
|
-
new Config(
|
|
1028
|
+
|
|
1029
|
+
configuration_table = [
|
|
1030
|
+
/* good lazy nice chain */
|
|
1031
|
+
new Config(0, 0, 0, 0, deflate_stored), /* 0 store only */
|
|
1032
|
+
new Config(4, 4, 8, 4, deflate_fast), /* 1 max speed, no lazy matches */
|
|
1033
|
+
new Config(4, 5, 16, 8, deflate_fast), /* 2 */
|
|
1034
|
+
new Config(4, 6, 32, 32, deflate_fast), /* 3 */
|
|
1035
|
+
|
|
1036
|
+
new Config(4, 4, 16, 16, deflate_slow), /* 4 lazy matches */
|
|
1037
|
+
new Config(8, 16, 32, 32, deflate_slow), /* 5 */
|
|
1038
|
+
new Config(8, 16, 128, 128, deflate_slow), /* 6 */
|
|
1039
|
+
new Config(8, 32, 128, 256, deflate_slow), /* 7 */
|
|
1040
|
+
new Config(32, 128, 258, 1024, deflate_slow), /* 8 */
|
|
1041
|
+
new Config(32, 258, 258, 4096, deflate_slow) /* 9 max compression */
|
|
1042
|
+
];
|
|
1043
|
+
|
|
997
1044
|
|
|
998
1045
|
/* ===========================================================================
|
|
999
1046
|
* Initialize the "longest match" routines for a new zlib stream
|
|
@@ -1010,6 +1057,7 @@ function lm_init(s) {
|
|
|
1010
1057
|
s.good_match = configuration_table[s.level].good_length;
|
|
1011
1058
|
s.nice_match = configuration_table[s.level].nice_length;
|
|
1012
1059
|
s.max_chain_length = configuration_table[s.level].max_chain;
|
|
1060
|
+
|
|
1013
1061
|
s.strstart = 0;
|
|
1014
1062
|
s.block_start = 0;
|
|
1015
1063
|
s.lookahead = 0;
|
|
@@ -1018,22 +1066,24 @@ function lm_init(s) {
|
|
|
1018
1066
|
s.match_available = 0;
|
|
1019
1067
|
s.ins_h = 0;
|
|
1020
1068
|
}
|
|
1069
|
+
|
|
1070
|
+
|
|
1021
1071
|
function DeflateState() {
|
|
1022
|
-
this.strm = null;
|
|
1023
|
-
this.status = 0;
|
|
1024
|
-
this.pending_buf = null;
|
|
1025
|
-
this.pending_buf_size = 0;
|
|
1026
|
-
this.pending_out = 0;
|
|
1027
|
-
this.pending = 0;
|
|
1028
|
-
this.wrap = 0;
|
|
1029
|
-
this.gzhead = null;
|
|
1030
|
-
this.gzindex = 0;
|
|
1072
|
+
this.strm = null; /* pointer back to this zlib stream */
|
|
1073
|
+
this.status = 0; /* as the name implies */
|
|
1074
|
+
this.pending_buf = null; /* output still pending */
|
|
1075
|
+
this.pending_buf_size = 0; /* size of pending_buf */
|
|
1076
|
+
this.pending_out = 0; /* next pending byte to output to the stream */
|
|
1077
|
+
this.pending = 0; /* nb of bytes in the pending buffer */
|
|
1078
|
+
this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */
|
|
1079
|
+
this.gzhead = null; /* gzip header information to write */
|
|
1080
|
+
this.gzindex = 0; /* where in extra, name, or comment */
|
|
1031
1081
|
this.method = Z_DEFLATED; /* can only be DEFLATED */
|
|
1032
|
-
this.last_flush = -1;
|
|
1082
|
+
this.last_flush = -1; /* value of flush param for previous deflate call */
|
|
1033
1083
|
|
|
1034
|
-
this.w_size = 0;
|
|
1035
|
-
this.w_bits = 0;
|
|
1036
|
-
this.w_mask = 0;
|
|
1084
|
+
this.w_size = 0; /* LZ77 window size (32K by default) */
|
|
1085
|
+
this.w_bits = 0; /* log2(w_size) (8..16) */
|
|
1086
|
+
this.w_mask = 0; /* w_size - 1 */
|
|
1037
1087
|
|
|
1038
1088
|
this.window = null;
|
|
1039
1089
|
/* Sliding window. Input bytes are read into the second half of the window,
|
|
@@ -1054,12 +1104,12 @@ function DeflateState() {
|
|
|
1054
1104
|
* An index in this array is thus a window index modulo 32K.
|
|
1055
1105
|
*/
|
|
1056
1106
|
|
|
1057
|
-
this.head = null;
|
|
1107
|
+
this.head = null; /* Heads of the hash chains or NIL. */
|
|
1058
1108
|
|
|
1059
|
-
this.ins_h = 0;
|
|
1060
|
-
this.hash_size = 0;
|
|
1061
|
-
this.hash_bits = 0;
|
|
1062
|
-
this.hash_mask = 0;
|
|
1109
|
+
this.ins_h = 0; /* hash index of string to be inserted */
|
|
1110
|
+
this.hash_size = 0; /* number of elements in hash table */
|
|
1111
|
+
this.hash_bits = 0; /* log2(hash_size) */
|
|
1112
|
+
this.hash_mask = 0; /* hash_size-1 */
|
|
1063
1113
|
|
|
1064
1114
|
this.hash_shift = 0;
|
|
1065
1115
|
/* Number of bits by which ins_h must be shifted at each input
|
|
@@ -1073,12 +1123,12 @@ function DeflateState() {
|
|
|
1073
1123
|
* negative when the window is moved backwards.
|
|
1074
1124
|
*/
|
|
1075
1125
|
|
|
1076
|
-
this.match_length = 0;
|
|
1077
|
-
this.prev_match = 0;
|
|
1078
|
-
this.match_available = 0;
|
|
1079
|
-
this.strstart = 0;
|
|
1080
|
-
this.match_start = 0;
|
|
1081
|
-
this.lookahead = 0;
|
|
1126
|
+
this.match_length = 0; /* length of best match */
|
|
1127
|
+
this.prev_match = 0; /* previous match */
|
|
1128
|
+
this.match_available = 0; /* set if previous match exists */
|
|
1129
|
+
this.strstart = 0; /* start of string to insert */
|
|
1130
|
+
this.match_start = 0; /* start of matching string */
|
|
1131
|
+
this.lookahead = 0; /* number of valid bytes ahead in window */
|
|
1082
1132
|
|
|
1083
1133
|
this.prev_length = 0;
|
|
1084
1134
|
/* Length of the best match at previous step. Matches not greater than this
|
|
@@ -1103,15 +1153,15 @@ function DeflateState() {
|
|
|
1103
1153
|
* max_insert_length is used only for compression levels <= 3.
|
|
1104
1154
|
*/
|
|
1105
1155
|
|
|
1106
|
-
this.level = 0;
|
|
1107
|
-
this.strategy = 0;
|
|
1156
|
+
this.level = 0; /* compression level (1..9) */
|
|
1157
|
+
this.strategy = 0; /* favor or force Huffman coding*/
|
|
1108
1158
|
|
|
1109
1159
|
this.good_match = 0;
|
|
1110
1160
|
/* Use a faster search when the previous match is longer than this */
|
|
1111
1161
|
|
|
1112
1162
|
this.nice_match = 0; /* Stop searching when current match exceeds this */
|
|
1113
1163
|
|
|
1114
|
-
|
|
1164
|
+
/* used by trees.c: */
|
|
1115
1165
|
|
|
1116
1166
|
/* Didn't use ct_data typedef below to suppress compiler warning */
|
|
1117
1167
|
|
|
@@ -1121,25 +1171,27 @@ function DeflateState() {
|
|
|
1121
1171
|
|
|
1122
1172
|
// Use flat array of DOUBLE size, with interleaved fata,
|
|
1123
1173
|
// because JS does not support effective
|
|
1124
|
-
this.dyn_ltree
|
|
1125
|
-
this.dyn_dtree
|
|
1126
|
-
this.bl_tree
|
|
1174
|
+
this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2);
|
|
1175
|
+
this.dyn_dtree = new utils.Buf16((2 * D_CODES + 1) * 2);
|
|
1176
|
+
this.bl_tree = new utils.Buf16((2 * BL_CODES + 1) * 2);
|
|
1127
1177
|
zero(this.dyn_ltree);
|
|
1128
1178
|
zero(this.dyn_dtree);
|
|
1129
1179
|
zero(this.bl_tree);
|
|
1130
|
-
|
|
1131
|
-
this.
|
|
1132
|
-
this.
|
|
1180
|
+
|
|
1181
|
+
this.l_desc = null; /* desc. for literal tree */
|
|
1182
|
+
this.d_desc = null; /* desc. for distance tree */
|
|
1183
|
+
this.bl_desc = null; /* desc. for bit length tree */
|
|
1133
1184
|
|
|
1134
1185
|
//ush bl_count[MAX_BITS+1];
|
|
1135
1186
|
this.bl_count = new utils.Buf16(MAX_BITS + 1);
|
|
1136
1187
|
/* number of codes at each bit length for an optimal tree */
|
|
1137
1188
|
|
|
1138
1189
|
//int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
|
|
1139
|
-
this.heap = new utils.Buf16(2 * L_CODES + 1);
|
|
1190
|
+
this.heap = new utils.Buf16(2 * L_CODES + 1); /* heap used to build the Huffman trees */
|
|
1140
1191
|
zero(this.heap);
|
|
1141
|
-
|
|
1142
|
-
this.
|
|
1192
|
+
|
|
1193
|
+
this.heap_len = 0; /* number of elements in the heap */
|
|
1194
|
+
this.heap_max = 0; /* element of largest frequency */
|
|
1143
1195
|
/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
|
|
1144
1196
|
* The same heap array is used to build all trees.
|
|
1145
1197
|
*/
|
|
@@ -1149,7 +1201,7 @@ function DeflateState() {
|
|
|
1149
1201
|
/* Depth of each subtree used as tie breaker for trees of equal frequency
|
|
1150
1202
|
*/
|
|
1151
1203
|
|
|
1152
|
-
this.l_buf = 0;
|
|
1204
|
+
this.l_buf = 0; /* buffer index for literals or lengths */
|
|
1153
1205
|
|
|
1154
1206
|
this.lit_bufsize = 0;
|
|
1155
1207
|
/* Size of match buffer for literals/lengths. There are 4 reasons for
|
|
@@ -1171,7 +1223,7 @@ function DeflateState() {
|
|
|
1171
1223
|
* - I can't count above 4
|
|
1172
1224
|
*/
|
|
1173
1225
|
|
|
1174
|
-
this.last_lit = 0;
|
|
1226
|
+
this.last_lit = 0; /* running index in l_buf */
|
|
1175
1227
|
|
|
1176
1228
|
this.d_buf = 0;
|
|
1177
1229
|
/* Buffer index for distances. To simplify the code, d_buf and l_buf have
|
|
@@ -1179,10 +1231,11 @@ function DeflateState() {
|
|
|
1179
1231
|
* array would be necessary.
|
|
1180
1232
|
*/
|
|
1181
1233
|
|
|
1182
|
-
this.opt_len = 0;
|
|
1183
|
-
this.static_len = 0;
|
|
1184
|
-
this.matches = 0;
|
|
1185
|
-
this.insert = 0;
|
|
1234
|
+
this.opt_len = 0; /* bit length of current block with optimal trees */
|
|
1235
|
+
this.static_len = 0; /* bit length of current block with static trees */
|
|
1236
|
+
this.matches = 0; /* number of string matches in current block */
|
|
1237
|
+
this.insert = 0; /* bytes at end of window left to insert */
|
|
1238
|
+
|
|
1186
1239
|
|
|
1187
1240
|
this.bi_buf = 0;
|
|
1188
1241
|
/* Output buffer. bits are inserted starting at the bottom (least
|
|
@@ -1202,27 +1255,37 @@ function DeflateState() {
|
|
|
1202
1255
|
* updated to the new high water mark.
|
|
1203
1256
|
*/
|
|
1204
1257
|
}
|
|
1258
|
+
|
|
1259
|
+
|
|
1205
1260
|
function deflateResetKeep(strm) {
|
|
1206
1261
|
var s;
|
|
1262
|
+
|
|
1207
1263
|
if (!strm || !strm.state) {
|
|
1208
1264
|
return err(strm, Z_STREAM_ERROR);
|
|
1209
1265
|
}
|
|
1266
|
+
|
|
1210
1267
|
strm.total_in = strm.total_out = 0;
|
|
1211
1268
|
strm.data_type = Z_UNKNOWN;
|
|
1269
|
+
|
|
1212
1270
|
s = strm.state;
|
|
1213
1271
|
s.pending = 0;
|
|
1214
1272
|
s.pending_out = 0;
|
|
1273
|
+
|
|
1215
1274
|
if (s.wrap < 0) {
|
|
1216
1275
|
s.wrap = -s.wrap;
|
|
1217
1276
|
/* was made negative by deflate(..., Z_FINISH); */
|
|
1218
1277
|
}
|
|
1219
|
-
s.status = s.wrap ? INIT_STATE : BUSY_STATE;
|
|
1220
|
-
strm.adler = s.wrap === 2 ?
|
|
1221
|
-
|
|
1278
|
+
s.status = (s.wrap ? INIT_STATE : BUSY_STATE);
|
|
1279
|
+
strm.adler = (s.wrap === 2) ?
|
|
1280
|
+
0 // crc32(0, Z_NULL, 0)
|
|
1281
|
+
:
|
|
1282
|
+
1; // adler32(0, Z_NULL, 0)
|
|
1222
1283
|
s.last_flush = Z_NO_FLUSH;
|
|
1223
1284
|
trees._tr_init(s);
|
|
1224
1285
|
return Z_OK;
|
|
1225
1286
|
}
|
|
1287
|
+
|
|
1288
|
+
|
|
1226
1289
|
function deflateReset(strm) {
|
|
1227
1290
|
var ret = deflateResetKeep(strm);
|
|
1228
1291
|
if (ret === Z_OK) {
|
|
@@ -1230,53 +1293,65 @@ function deflateReset(strm) {
|
|
|
1230
1293
|
}
|
|
1231
1294
|
return ret;
|
|
1232
1295
|
}
|
|
1296
|
+
|
|
1297
|
+
|
|
1233
1298
|
function deflateSetHeader(strm, head) {
|
|
1234
|
-
if (!strm || !strm.state) {
|
|
1235
|
-
|
|
1236
|
-
}
|
|
1237
|
-
if (strm.state.wrap !== 2) {
|
|
1238
|
-
return Z_STREAM_ERROR;
|
|
1239
|
-
}
|
|
1299
|
+
if (!strm || !strm.state) { return Z_STREAM_ERROR; }
|
|
1300
|
+
if (strm.state.wrap !== 2) { return Z_STREAM_ERROR; }
|
|
1240
1301
|
strm.state.gzhead = head;
|
|
1241
1302
|
return Z_OK;
|
|
1242
1303
|
}
|
|
1304
|
+
|
|
1305
|
+
|
|
1243
1306
|
function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
|
|
1244
|
-
if (!strm) {
|
|
1245
|
-
// === Z_NULL
|
|
1307
|
+
if (!strm) { // === Z_NULL
|
|
1246
1308
|
return Z_STREAM_ERROR;
|
|
1247
1309
|
}
|
|
1248
1310
|
var wrap = 1;
|
|
1311
|
+
|
|
1249
1312
|
if (level === Z_DEFAULT_COMPRESSION) {
|
|
1250
1313
|
level = 6;
|
|
1251
1314
|
}
|
|
1252
|
-
|
|
1253
|
-
|
|
1315
|
+
|
|
1316
|
+
if (windowBits < 0) { /* suppress zlib wrapper */
|
|
1254
1317
|
wrap = 0;
|
|
1255
1318
|
windowBits = -windowBits;
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
else if (windowBits > 15) {
|
|
1322
|
+
wrap = 2; /* write gzip wrapper instead */
|
|
1258
1323
|
windowBits -= 16;
|
|
1259
1324
|
}
|
|
1260
|
-
|
|
1325
|
+
|
|
1326
|
+
|
|
1327
|
+
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED ||
|
|
1328
|
+
windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
|
|
1329
|
+
strategy < 0 || strategy > Z_FIXED) {
|
|
1261
1330
|
return err(strm, Z_STREAM_ERROR);
|
|
1262
1331
|
}
|
|
1332
|
+
|
|
1333
|
+
|
|
1263
1334
|
if (windowBits === 8) {
|
|
1264
1335
|
windowBits = 9;
|
|
1265
1336
|
}
|
|
1266
1337
|
/* until 256-byte window bug fixed */
|
|
1267
1338
|
|
|
1268
1339
|
var s = new DeflateState();
|
|
1340
|
+
|
|
1269
1341
|
strm.state = s;
|
|
1270
1342
|
s.strm = strm;
|
|
1343
|
+
|
|
1271
1344
|
s.wrap = wrap;
|
|
1272
1345
|
s.gzhead = null;
|
|
1273
1346
|
s.w_bits = windowBits;
|
|
1274
1347
|
s.w_size = 1 << s.w_bits;
|
|
1275
1348
|
s.w_mask = s.w_size - 1;
|
|
1349
|
+
|
|
1276
1350
|
s.hash_bits = memLevel + 7;
|
|
1277
1351
|
s.hash_size = 1 << s.hash_bits;
|
|
1278
1352
|
s.hash_mask = s.hash_size - 1;
|
|
1279
1353
|
s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH);
|
|
1354
|
+
|
|
1280
1355
|
s.window = new utils.Buf8(s.w_size * 2);
|
|
1281
1356
|
s.head = new utils.Buf16(s.hash_size);
|
|
1282
1357
|
s.prev = new utils.Buf16(s.w_size);
|
|
@@ -1284,7 +1359,7 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
|
|
|
1284
1359
|
// Don't need mem init magic for JS.
|
|
1285
1360
|
//s.high_water = 0; /* nothing written to s->window yet */
|
|
1286
1361
|
|
|
1287
|
-
s.lit_bufsize = 1 << memLevel + 6; /* 16K elements by default */
|
|
1362
|
+
s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
|
|
1288
1363
|
|
|
1289
1364
|
s.pending_buf_size = s.lit_bufsize * 4;
|
|
1290
1365
|
|
|
@@ -1298,105 +1373,125 @@ function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
|
|
|
1298
1373
|
|
|
1299
1374
|
//s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
|
|
1300
1375
|
s.l_buf = (1 + 2) * s.lit_bufsize;
|
|
1376
|
+
|
|
1301
1377
|
s.level = level;
|
|
1302
1378
|
s.strategy = strategy;
|
|
1303
1379
|
s.method = method;
|
|
1380
|
+
|
|
1304
1381
|
return deflateReset(strm);
|
|
1305
1382
|
}
|
|
1383
|
+
|
|
1306
1384
|
function deflateInit(strm, level) {
|
|
1307
1385
|
return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
|
|
1308
1386
|
}
|
|
1387
|
+
|
|
1388
|
+
|
|
1309
1389
|
function deflate(strm, flush) {
|
|
1310
1390
|
var old_flush, s;
|
|
1311
1391
|
var beg, val; // for gzip header write only
|
|
1312
1392
|
|
|
1313
|
-
if (!strm || !strm.state ||
|
|
1393
|
+
if (!strm || !strm.state ||
|
|
1394
|
+
flush > Z_BLOCK || flush < 0) {
|
|
1314
1395
|
return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR;
|
|
1315
1396
|
}
|
|
1397
|
+
|
|
1316
1398
|
s = strm.state;
|
|
1317
|
-
|
|
1318
|
-
|
|
1399
|
+
|
|
1400
|
+
if (!strm.output ||
|
|
1401
|
+
(!strm.input && strm.avail_in !== 0) ||
|
|
1402
|
+
(s.status === FINISH_STATE && flush !== Z_FINISH)) {
|
|
1403
|
+
return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR);
|
|
1319
1404
|
}
|
|
1405
|
+
|
|
1320
1406
|
s.strm = strm; /* just in case */
|
|
1321
1407
|
old_flush = s.last_flush;
|
|
1322
1408
|
s.last_flush = flush;
|
|
1323
1409
|
|
|
1324
1410
|
/* Write the header */
|
|
1325
1411
|
if (s.status === INIT_STATE) {
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
strm.adler = 0;
|
|
1412
|
+
|
|
1413
|
+
if (s.wrap === 2) { // GZIP header
|
|
1414
|
+
strm.adler = 0; //crc32(0L, Z_NULL, 0);
|
|
1329
1415
|
put_byte(s, 31);
|
|
1330
1416
|
put_byte(s, 139);
|
|
1331
1417
|
put_byte(s, 8);
|
|
1332
|
-
if (!s.gzhead) {
|
|
1333
|
-
// s->gzhead == Z_NULL
|
|
1418
|
+
if (!s.gzhead) { // s->gzhead == Z_NULL
|
|
1334
1419
|
put_byte(s, 0);
|
|
1335
1420
|
put_byte(s, 0);
|
|
1336
1421
|
put_byte(s, 0);
|
|
1337
1422
|
put_byte(s, 0);
|
|
1338
1423
|
put_byte(s, 0);
|
|
1339
|
-
put_byte(s, s.level === 9 ? 2 :
|
|
1424
|
+
put_byte(s, s.level === 9 ? 2 :
|
|
1425
|
+
(s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?
|
|
1426
|
+
4 : 0));
|
|
1340
1427
|
put_byte(s, OS_CODE);
|
|
1341
1428
|
s.status = BUSY_STATE;
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1429
|
+
}
|
|
1430
|
+
else {
|
|
1431
|
+
put_byte(s, (s.gzhead.text ? 1 : 0) +
|
|
1432
|
+
(s.gzhead.hcrc ? 2 : 0) +
|
|
1433
|
+
(!s.gzhead.extra ? 0 : 4) +
|
|
1434
|
+
(!s.gzhead.name ? 0 : 8) +
|
|
1435
|
+
(!s.gzhead.comment ? 0 : 16)
|
|
1436
|
+
);
|
|
1344
1437
|
put_byte(s, s.gzhead.time & 0xff);
|
|
1345
|
-
put_byte(s, s.gzhead.time >> 8 & 0xff);
|
|
1346
|
-
put_byte(s, s.gzhead.time >> 16 & 0xff);
|
|
1347
|
-
put_byte(s, s.gzhead.time >> 24 & 0xff);
|
|
1348
|
-
put_byte(s, s.level === 9 ? 2 :
|
|
1438
|
+
put_byte(s, (s.gzhead.time >> 8) & 0xff);
|
|
1439
|
+
put_byte(s, (s.gzhead.time >> 16) & 0xff);
|
|
1440
|
+
put_byte(s, (s.gzhead.time >> 24) & 0xff);
|
|
1441
|
+
put_byte(s, s.level === 9 ? 2 :
|
|
1442
|
+
(s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?
|
|
1443
|
+
4 : 0));
|
|
1349
1444
|
put_byte(s, s.gzhead.os & 0xff);
|
|
1350
1445
|
if (s.gzhead.extra && s.gzhead.extra.length) {
|
|
1351
1446
|
put_byte(s, s.gzhead.extra.length & 0xff);
|
|
1352
|
-
put_byte(s, s.gzhead.extra.length >> 8 & 0xff);
|
|
1447
|
+
put_byte(s, (s.gzhead.extra.length >> 8) & 0xff);
|
|
1353
1448
|
}
|
|
1354
1449
|
if (s.gzhead.hcrc) {
|
|
1355
|
-
strm.adler = (
|
|
1450
|
+
strm.adler = crc32(strm.adler, s.pending_buf, s.pending, 0);
|
|
1356
1451
|
}
|
|
1357
1452
|
s.gzindex = 0;
|
|
1358
1453
|
s.status = EXTRA_STATE;
|
|
1359
1454
|
}
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
header += 31 - header % 31;
|
|
1379
|
-
s.status = BUSY_STATE;
|
|
1380
|
-
putShortMSB(s, header);
|
|
1455
|
+
}
|
|
1456
|
+
else // DEFLATE header
|
|
1457
|
+
{
|
|
1458
|
+
var header = (Z_DEFLATED + ((s.w_bits - 8) << 4)) << 8;
|
|
1459
|
+
var level_flags = -1;
|
|
1460
|
+
|
|
1461
|
+
if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {
|
|
1462
|
+
level_flags = 0;
|
|
1463
|
+
} else if (s.level < 6) {
|
|
1464
|
+
level_flags = 1;
|
|
1465
|
+
} else if (s.level === 6) {
|
|
1466
|
+
level_flags = 2;
|
|
1467
|
+
} else {
|
|
1468
|
+
level_flags = 3;
|
|
1469
|
+
}
|
|
1470
|
+
header |= (level_flags << 6);
|
|
1471
|
+
if (s.strstart !== 0) { header |= PRESET_DICT; }
|
|
1472
|
+
header += 31 - (header % 31);
|
|
1381
1473
|
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
strm.adler
|
|
1474
|
+
s.status = BUSY_STATE;
|
|
1475
|
+
putShortMSB(s, header);
|
|
1476
|
+
|
|
1477
|
+
/* Save the adler32 of the preset dictionary: */
|
|
1478
|
+
if (s.strstart !== 0) {
|
|
1479
|
+
putShortMSB(s, strm.adler >>> 16);
|
|
1480
|
+
putShortMSB(s, strm.adler & 0xffff);
|
|
1388
1481
|
}
|
|
1482
|
+
strm.adler = 1; // adler32(0L, Z_NULL, 0);
|
|
1483
|
+
}
|
|
1389
1484
|
}
|
|
1390
1485
|
|
|
1391
|
-
|
|
1486
|
+
//#ifdef GZIP
|
|
1392
1487
|
if (s.status === EXTRA_STATE) {
|
|
1393
|
-
if (s.gzhead.extra
|
|
1394
|
-
beg = s.pending;
|
|
1488
|
+
if (s.gzhead.extra/* != Z_NULL*/) {
|
|
1489
|
+
beg = s.pending; /* start of bytes to update crc */
|
|
1395
1490
|
|
|
1396
1491
|
while (s.gzindex < (s.gzhead.extra.length & 0xffff)) {
|
|
1397
1492
|
if (s.pending === s.pending_buf_size) {
|
|
1398
1493
|
if (s.gzhead.hcrc && s.pending > beg) {
|
|
1399
|
-
strm.adler = (
|
|
1494
|
+
strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
|
|
1400
1495
|
}
|
|
1401
1496
|
flush_pending(strm);
|
|
1402
1497
|
beg = s.pending;
|
|
@@ -1408,25 +1503,26 @@ function deflate(strm, flush) {
|
|
|
1408
1503
|
s.gzindex++;
|
|
1409
1504
|
}
|
|
1410
1505
|
if (s.gzhead.hcrc && s.pending > beg) {
|
|
1411
|
-
strm.adler = (
|
|
1506
|
+
strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
|
|
1412
1507
|
}
|
|
1413
1508
|
if (s.gzindex === s.gzhead.extra.length) {
|
|
1414
1509
|
s.gzindex = 0;
|
|
1415
1510
|
s.status = NAME_STATE;
|
|
1416
1511
|
}
|
|
1417
|
-
}
|
|
1512
|
+
}
|
|
1513
|
+
else {
|
|
1418
1514
|
s.status = NAME_STATE;
|
|
1419
1515
|
}
|
|
1420
1516
|
}
|
|
1421
1517
|
if (s.status === NAME_STATE) {
|
|
1422
|
-
if (s.gzhead.name
|
|
1423
|
-
beg = s.pending;
|
|
1518
|
+
if (s.gzhead.name/* != Z_NULL*/) {
|
|
1519
|
+
beg = s.pending; /* start of bytes to update crc */
|
|
1424
1520
|
//int val;
|
|
1425
1521
|
|
|
1426
1522
|
do {
|
|
1427
1523
|
if (s.pending === s.pending_buf_size) {
|
|
1428
1524
|
if (s.gzhead.hcrc && s.pending > beg) {
|
|
1429
|
-
strm.adler = (
|
|
1525
|
+
strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
|
|
1430
1526
|
}
|
|
1431
1527
|
flush_pending(strm);
|
|
1432
1528
|
beg = s.pending;
|
|
@@ -1443,26 +1539,28 @@ function deflate(strm, flush) {
|
|
|
1443
1539
|
}
|
|
1444
1540
|
put_byte(s, val);
|
|
1445
1541
|
} while (val !== 0);
|
|
1542
|
+
|
|
1446
1543
|
if (s.gzhead.hcrc && s.pending > beg) {
|
|
1447
|
-
strm.adler = (
|
|
1544
|
+
strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
|
|
1448
1545
|
}
|
|
1449
1546
|
if (val === 0) {
|
|
1450
1547
|
s.gzindex = 0;
|
|
1451
1548
|
s.status = COMMENT_STATE;
|
|
1452
1549
|
}
|
|
1453
|
-
}
|
|
1550
|
+
}
|
|
1551
|
+
else {
|
|
1454
1552
|
s.status = COMMENT_STATE;
|
|
1455
1553
|
}
|
|
1456
1554
|
}
|
|
1457
1555
|
if (s.status === COMMENT_STATE) {
|
|
1458
|
-
if (s.gzhead.comment
|
|
1459
|
-
beg = s.pending;
|
|
1556
|
+
if (s.gzhead.comment/* != Z_NULL*/) {
|
|
1557
|
+
beg = s.pending; /* start of bytes to update crc */
|
|
1460
1558
|
//int val;
|
|
1461
1559
|
|
|
1462
1560
|
do {
|
|
1463
1561
|
if (s.pending === s.pending_buf_size) {
|
|
1464
1562
|
if (s.gzhead.hcrc && s.pending > beg) {
|
|
1465
|
-
strm.adler = (
|
|
1563
|
+
strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
|
|
1466
1564
|
}
|
|
1467
1565
|
flush_pending(strm);
|
|
1468
1566
|
beg = s.pending;
|
|
@@ -1479,13 +1577,15 @@ function deflate(strm, flush) {
|
|
|
1479
1577
|
}
|
|
1480
1578
|
put_byte(s, val);
|
|
1481
1579
|
} while (val !== 0);
|
|
1580
|
+
|
|
1482
1581
|
if (s.gzhead.hcrc && s.pending > beg) {
|
|
1483
|
-
strm.adler = (
|
|
1582
|
+
strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
|
|
1484
1583
|
}
|
|
1485
1584
|
if (val === 0) {
|
|
1486
1585
|
s.status = HCRC_STATE;
|
|
1487
1586
|
}
|
|
1488
|
-
}
|
|
1587
|
+
}
|
|
1588
|
+
else {
|
|
1489
1589
|
s.status = HCRC_STATE;
|
|
1490
1590
|
}
|
|
1491
1591
|
}
|
|
@@ -1496,15 +1596,16 @@ function deflate(strm, flush) {
|
|
|
1496
1596
|
}
|
|
1497
1597
|
if (s.pending + 2 <= s.pending_buf_size) {
|
|
1498
1598
|
put_byte(s, strm.adler & 0xff);
|
|
1499
|
-
put_byte(s, strm.adler >> 8 & 0xff);
|
|
1599
|
+
put_byte(s, (strm.adler >> 8) & 0xff);
|
|
1500
1600
|
strm.adler = 0; //crc32(0L, Z_NULL, 0);
|
|
1501
1601
|
s.status = BUSY_STATE;
|
|
1502
1602
|
}
|
|
1503
|
-
}
|
|
1603
|
+
}
|
|
1604
|
+
else {
|
|
1504
1605
|
s.status = BUSY_STATE;
|
|
1505
1606
|
}
|
|
1506
1607
|
}
|
|
1507
|
-
|
|
1608
|
+
//#endif
|
|
1508
1609
|
|
|
1509
1610
|
/* Flush as much pending output as possible */
|
|
1510
1611
|
if (s.pending !== 0) {
|
|
@@ -1524,7 +1625,8 @@ function deflate(strm, flush) {
|
|
|
1524
1625
|
* flushes. For repeated and useless calls with Z_FINISH, we keep
|
|
1525
1626
|
* returning Z_STREAM_END instead of Z_BUF_ERROR.
|
|
1526
1627
|
*/
|
|
1527
|
-
} else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) &&
|
|
1628
|
+
} else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) &&
|
|
1629
|
+
flush !== Z_FINISH) {
|
|
1528
1630
|
return err(strm, Z_BUF_ERROR);
|
|
1529
1631
|
}
|
|
1530
1632
|
|
|
@@ -1535,8 +1637,12 @@ function deflate(strm, flush) {
|
|
|
1535
1637
|
|
|
1536
1638
|
/* Start a new block or continue the current one.
|
|
1537
1639
|
*/
|
|
1538
|
-
if (strm.avail_in !== 0 || s.lookahead !== 0 ||
|
|
1539
|
-
|
|
1640
|
+
if (strm.avail_in !== 0 || s.lookahead !== 0 ||
|
|
1641
|
+
(flush !== Z_NO_FLUSH && s.status !== FINISH_STATE)) {
|
|
1642
|
+
var bstate = (s.strategy === Z_HUFFMAN_ONLY) ? deflate_huff(s, flush) :
|
|
1643
|
+
(s.strategy === Z_RLE ? deflate_rle(s, flush) :
|
|
1644
|
+
configuration_table[s.level].func(s, flush));
|
|
1645
|
+
|
|
1540
1646
|
if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) {
|
|
1541
1647
|
s.status = FINISH_STATE;
|
|
1542
1648
|
}
|
|
@@ -1557,15 +1663,15 @@ function deflate(strm, flush) {
|
|
|
1557
1663
|
if (bstate === BS_BLOCK_DONE) {
|
|
1558
1664
|
if (flush === Z_PARTIAL_FLUSH) {
|
|
1559
1665
|
trees._tr_align(s);
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1666
|
+
}
|
|
1667
|
+
else if (flush !== Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
|
|
1562
1668
|
|
|
1563
1669
|
trees._tr_stored_block(s, 0, 0, false);
|
|
1564
1670
|
/* For a full flush, this empty block will be recognized
|
|
1565
1671
|
* as a special marker by inflate_sync().
|
|
1566
1672
|
*/
|
|
1567
1673
|
if (flush === Z_FULL_FLUSH) {
|
|
1568
|
-
/*** CLEAR_HASH(s); ***/
|
|
1674
|
+
/*** CLEAR_HASH(s); ***/ /* forget history */
|
|
1569
1675
|
zero(s.head); // Fill with NIL (= 0);
|
|
1570
1676
|
|
|
1571
1677
|
if (s.lookahead === 0) {
|
|
@@ -1585,56 +1691,67 @@ function deflate(strm, flush) {
|
|
|
1585
1691
|
//Assert(strm->avail_out > 0, "bug2");
|
|
1586
1692
|
//if (strm.avail_out <= 0) { throw new Error("bug2");}
|
|
1587
1693
|
|
|
1588
|
-
if (flush !== Z_FINISH) {
|
|
1589
|
-
|
|
1590
|
-
}
|
|
1591
|
-
if (s.wrap <= 0) {
|
|
1592
|
-
return Z_STREAM_END;
|
|
1593
|
-
}
|
|
1694
|
+
if (flush !== Z_FINISH) { return Z_OK; }
|
|
1695
|
+
if (s.wrap <= 0) { return Z_STREAM_END; }
|
|
1594
1696
|
|
|
1595
1697
|
/* Write the trailer */
|
|
1596
1698
|
if (s.wrap === 2) {
|
|
1597
1699
|
put_byte(s, strm.adler & 0xff);
|
|
1598
|
-
put_byte(s, strm.adler >> 8 & 0xff);
|
|
1599
|
-
put_byte(s, strm.adler >> 16 & 0xff);
|
|
1600
|
-
put_byte(s, strm.adler >> 24 & 0xff);
|
|
1700
|
+
put_byte(s, (strm.adler >> 8) & 0xff);
|
|
1701
|
+
put_byte(s, (strm.adler >> 16) & 0xff);
|
|
1702
|
+
put_byte(s, (strm.adler >> 24) & 0xff);
|
|
1601
1703
|
put_byte(s, strm.total_in & 0xff);
|
|
1602
|
-
put_byte(s, strm.total_in >> 8 & 0xff);
|
|
1603
|
-
put_byte(s, strm.total_in >> 16 & 0xff);
|
|
1604
|
-
put_byte(s, strm.total_in >> 24 & 0xff);
|
|
1605
|
-
}
|
|
1704
|
+
put_byte(s, (strm.total_in >> 8) & 0xff);
|
|
1705
|
+
put_byte(s, (strm.total_in >> 16) & 0xff);
|
|
1706
|
+
put_byte(s, (strm.total_in >> 24) & 0xff);
|
|
1707
|
+
}
|
|
1708
|
+
else
|
|
1709
|
+
{
|
|
1606
1710
|
putShortMSB(s, strm.adler >>> 16);
|
|
1607
1711
|
putShortMSB(s, strm.adler & 0xffff);
|
|
1608
1712
|
}
|
|
1713
|
+
|
|
1609
1714
|
flush_pending(strm);
|
|
1610
1715
|
/* If avail_out is zero, the application will call deflate again
|
|
1611
1716
|
* to flush the rest.
|
|
1612
1717
|
*/
|
|
1613
|
-
if (s.wrap > 0) {
|
|
1614
|
-
s.wrap = -s.wrap;
|
|
1615
|
-
}
|
|
1718
|
+
if (s.wrap > 0) { s.wrap = -s.wrap; }
|
|
1616
1719
|
/* write the trailer only once! */
|
|
1617
1720
|
return s.pending !== 0 ? Z_OK : Z_STREAM_END;
|
|
1618
1721
|
}
|
|
1722
|
+
|
|
1619
1723
|
function deflateEnd(strm) {
|
|
1620
1724
|
var status;
|
|
1621
|
-
|
|
1725
|
+
|
|
1726
|
+
if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {
|
|
1622
1727
|
return Z_STREAM_ERROR;
|
|
1623
1728
|
}
|
|
1729
|
+
|
|
1624
1730
|
status = strm.state.status;
|
|
1625
|
-
if (status !== INIT_STATE &&
|
|
1731
|
+
if (status !== INIT_STATE &&
|
|
1732
|
+
status !== EXTRA_STATE &&
|
|
1733
|
+
status !== NAME_STATE &&
|
|
1734
|
+
status !== COMMENT_STATE &&
|
|
1735
|
+
status !== HCRC_STATE &&
|
|
1736
|
+
status !== BUSY_STATE &&
|
|
1737
|
+
status !== FINISH_STATE
|
|
1738
|
+
) {
|
|
1626
1739
|
return err(strm, Z_STREAM_ERROR);
|
|
1627
1740
|
}
|
|
1741
|
+
|
|
1628
1742
|
strm.state = null;
|
|
1743
|
+
|
|
1629
1744
|
return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;
|
|
1630
1745
|
}
|
|
1631
1746
|
|
|
1747
|
+
|
|
1632
1748
|
/* =========================================================================
|
|
1633
1749
|
* Initializes the compression dictionary from the given byte
|
|
1634
1750
|
* sequence without producing any compressed output.
|
|
1635
1751
|
*/
|
|
1636
1752
|
function deflateSetDictionary(strm, dictionary) {
|
|
1637
1753
|
var dictLength = dictionary.length;
|
|
1754
|
+
|
|
1638
1755
|
var s;
|
|
1639
1756
|
var str, n;
|
|
1640
1757
|
var wrap;
|
|
@@ -1642,26 +1759,29 @@ function deflateSetDictionary(strm, dictionary) {
|
|
|
1642
1759
|
var next;
|
|
1643
1760
|
var input;
|
|
1644
1761
|
var tmpDict;
|
|
1645
|
-
|
|
1762
|
+
|
|
1763
|
+
if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {
|
|
1646
1764
|
return Z_STREAM_ERROR;
|
|
1647
1765
|
}
|
|
1766
|
+
|
|
1648
1767
|
s = strm.state;
|
|
1649
1768
|
wrap = s.wrap;
|
|
1650
|
-
|
|
1769
|
+
|
|
1770
|
+
if (wrap === 2 || (wrap === 1 && s.status !== INIT_STATE) || s.lookahead) {
|
|
1651
1771
|
return Z_STREAM_ERROR;
|
|
1652
1772
|
}
|
|
1653
1773
|
|
|
1654
1774
|
/* when using zlib wrappers, compute Adler-32 for provided dictionary */
|
|
1655
1775
|
if (wrap === 1) {
|
|
1656
1776
|
/* adler32(strm->adler, dictionary, dictLength); */
|
|
1657
|
-
strm.adler = (
|
|
1777
|
+
strm.adler = adler32(strm.adler, dictionary, dictLength, 0);
|
|
1658
1778
|
}
|
|
1659
|
-
|
|
1779
|
+
|
|
1780
|
+
s.wrap = 0; /* avoid computing Adler-32 in read_buf */
|
|
1660
1781
|
|
|
1661
1782
|
/* if dictionary would fill window, just replace the history */
|
|
1662
1783
|
if (dictLength >= s.w_size) {
|
|
1663
|
-
if (wrap === 0) {
|
|
1664
|
-
/* already empty otherwise */
|
|
1784
|
+
if (wrap === 0) { /* already empty otherwise */
|
|
1665
1785
|
/*** CLEAR_HASH(s); ***/
|
|
1666
1786
|
zero(s.head); // Fill with NIL (= 0);
|
|
1667
1787
|
s.strstart = 0;
|
|
@@ -1688,8 +1808,10 @@ function deflateSetDictionary(strm, dictionary) {
|
|
|
1688
1808
|
n = s.lookahead - (MIN_MATCH - 1);
|
|
1689
1809
|
do {
|
|
1690
1810
|
/* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
|
|
1691
|
-
s.ins_h = (s.ins_h << s.hash_shift ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
|
|
1811
|
+
s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
|
|
1812
|
+
|
|
1692
1813
|
s.prev[str & s.w_mask] = s.head[s.ins_h];
|
|
1814
|
+
|
|
1693
1815
|
s.head[s.ins_h] = str;
|
|
1694
1816
|
str++;
|
|
1695
1817
|
} while (--n);
|
|
@@ -1709,7 +1831,10 @@ function deflateSetDictionary(strm, dictionary) {
|
|
|
1709
1831
|
s.wrap = wrap;
|
|
1710
1832
|
return Z_OK;
|
|
1711
1833
|
}
|
|
1712
|
-
|
|
1834
|
+
|
|
1835
|
+
|
|
1836
|
+
export { deflateInit, deflateInit2, deflateReset, deflateResetKeep, deflateSetHeader, deflate, deflateEnd, deflateSetDictionary };
|
|
1837
|
+
export var deflateInfo = 'pako deflate (from Nodeca project)';
|
|
1713
1838
|
|
|
1714
1839
|
/* Not implemented
|
|
1715
1840
|
exports.deflateBound = deflateBound;
|
|
@@ -1718,4 +1843,4 @@ exports.deflateParams = deflateParams;
|
|
|
1718
1843
|
exports.deflatePending = deflatePending;
|
|
1719
1844
|
exports.deflatePrime = deflatePrime;
|
|
1720
1845
|
exports.deflateTune = deflateTune;
|
|
1721
|
-
*/
|
|
1846
|
+
*/
|