Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80540 views
1
/* pako 0.2.6 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
'use strict';
3
4
5
var TYPED_OK = (typeof Uint8Array !== 'undefined') &&
6
(typeof Uint16Array !== 'undefined') &&
7
(typeof Int32Array !== 'undefined');
8
9
10
exports.assign = function (obj /*from1, from2, from3, ...*/) {
11
var sources = Array.prototype.slice.call(arguments, 1);
12
while (sources.length) {
13
var source = sources.shift();
14
if (!source) { continue; }
15
16
if (typeof(source) !== 'object') {
17
throw new TypeError(source + 'must be non-object');
18
}
19
20
for (var p in source) {
21
if (source.hasOwnProperty(p)) {
22
obj[p] = source[p];
23
}
24
}
25
}
26
27
return obj;
28
};
29
30
31
// reduce buffer size, avoiding mem copy
32
exports.shrinkBuf = function (buf, size) {
33
if (buf.length === size) { return buf; }
34
if (buf.subarray) { return buf.subarray(0, size); }
35
buf.length = size;
36
return buf;
37
};
38
39
40
var fnTyped = {
41
arraySet: function (dest, src, src_offs, len, dest_offs) {
42
if (src.subarray && dest.subarray) {
43
dest.set(src.subarray(src_offs, src_offs+len), dest_offs);
44
return;
45
}
46
// Fallback to ordinary array
47
for(var i=0; i<len; i++) {
48
dest[dest_offs + i] = src[src_offs + i];
49
}
50
},
51
// Join array of chunks to single array.
52
flattenChunks: function(chunks) {
53
var i, l, len, pos, chunk, result;
54
55
// calculate data length
56
len = 0;
57
for (i=0, l=chunks.length; i<l; i++) {
58
len += chunks[i].length;
59
}
60
61
// join chunks
62
result = new Uint8Array(len);
63
pos = 0;
64
for (i=0, l=chunks.length; i<l; i++) {
65
chunk = chunks[i];
66
result.set(chunk, pos);
67
pos += chunk.length;
68
}
69
70
return result;
71
}
72
};
73
74
var fnUntyped = {
75
arraySet: function (dest, src, src_offs, len, dest_offs) {
76
for(var i=0; i<len; i++) {
77
dest[dest_offs + i] = src[src_offs + i];
78
}
79
},
80
// Join array of chunks to single array.
81
flattenChunks: function(chunks) {
82
return [].concat.apply([], chunks);
83
}
84
};
85
86
87
// Enable/Disable typed arrays use, for testing
88
//
89
exports.setTyped = function (on) {
90
if (on) {
91
exports.Buf8 = Uint8Array;
92
exports.Buf16 = Uint16Array;
93
exports.Buf32 = Int32Array;
94
exports.assign(exports, fnTyped);
95
} else {
96
exports.Buf8 = Array;
97
exports.Buf16 = Array;
98
exports.Buf32 = Array;
99
exports.assign(exports, fnUntyped);
100
}
101
};
102
103
exports.setTyped(TYPED_OK);
104
},{}],2:[function(require,module,exports){
105
// String encode/decode helpers
106
'use strict';
107
108
109
var utils = require('./common');
110
111
112
// Quick check if we can use fast array to bin string conversion
113
//
114
// - apply(Array) can fail on Android 2.2
115
// - apply(Uint8Array) can fail on iOS 5.1 Safary
116
//
117
var STR_APPLY_OK = true;
118
var STR_APPLY_UIA_OK = true;
119
120
try { String.fromCharCode.apply(null, [0]); } catch(__) { STR_APPLY_OK = false; }
121
try { String.fromCharCode.apply(null, new Uint8Array(1)); } catch(__) { STR_APPLY_UIA_OK = false; }
122
123
124
// Table with utf8 lengths (calculated by first byte of sequence)
125
// Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
126
// because max possible codepoint is 0x10ffff
127
var _utf8len = new utils.Buf8(256);
128
for (var i=0; i<256; i++) {
129
_utf8len[i] = (i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1);
130
}
131
_utf8len[254]=_utf8len[254]=1; // Invalid sequence start
132
133
134
// convert string to array (typed, when possible)
135
exports.string2buf = function (str) {
136
var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;
137
138
// count binary size
139
for (m_pos = 0; m_pos < str_len; m_pos++) {
140
c = str.charCodeAt(m_pos);
141
if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {
142
c2 = str.charCodeAt(m_pos+1);
143
if ((c2 & 0xfc00) === 0xdc00) {
144
c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
145
m_pos++;
146
}
147
}
148
buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
149
}
150
151
// allocate buffer
152
buf = new utils.Buf8(buf_len);
153
154
// convert
155
for (i=0, m_pos = 0; i < buf_len; m_pos++) {
156
c = str.charCodeAt(m_pos);
157
if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {
158
c2 = str.charCodeAt(m_pos+1);
159
if ((c2 & 0xfc00) === 0xdc00) {
160
c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
161
m_pos++;
162
}
163
}
164
if (c < 0x80) {
165
/* one byte */
166
buf[i++] = c;
167
} else if (c < 0x800) {
168
/* two bytes */
169
buf[i++] = 0xC0 | (c >>> 6);
170
buf[i++] = 0x80 | (c & 0x3f);
171
} else if (c < 0x10000) {
172
/* three bytes */
173
buf[i++] = 0xE0 | (c >>> 12);
174
buf[i++] = 0x80 | (c >>> 6 & 0x3f);
175
buf[i++] = 0x80 | (c & 0x3f);
176
} else {
177
/* four bytes */
178
buf[i++] = 0xf0 | (c >>> 18);
179
buf[i++] = 0x80 | (c >>> 12 & 0x3f);
180
buf[i++] = 0x80 | (c >>> 6 & 0x3f);
181
buf[i++] = 0x80 | (c & 0x3f);
182
}
183
}
184
185
return buf;
186
};
187
188
// Helper (used in 2 places)
189
function buf2binstring(buf, len) {
190
// use fallback for big arrays to avoid stack overflow
191
if (len < 65537) {
192
if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) {
193
return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));
194
}
195
}
196
197
var result = '';
198
for(var i=0; i < len; i++) {
199
result += String.fromCharCode(buf[i]);
200
}
201
return result;
202
}
203
204
205
// Convert byte array to binary string
206
exports.buf2binstring = function(buf) {
207
return buf2binstring(buf, buf.length);
208
};
209
210
211
// Convert binary string (typed, when possible)
212
exports.binstring2buf = function(str) {
213
var buf = new utils.Buf8(str.length);
214
for(var i=0, len=buf.length; i < len; i++) {
215
buf[i] = str.charCodeAt(i);
216
}
217
return buf;
218
};
219
220
221
// convert array to string
222
exports.buf2string = function (buf, max) {
223
var i, out, c, c_len;
224
var len = max || buf.length;
225
226
// Reserve max possible length (2 words per char)
227
// NB: by unknown reasons, Array is significantly faster for
228
// String.fromCharCode.apply than Uint16Array.
229
var utf16buf = new Array(len*2);
230
231
for (out=0, i=0; i<len;) {
232
c = buf[i++];
233
// quick process ascii
234
if (c < 0x80) { utf16buf[out++] = c; continue; }
235
236
c_len = _utf8len[c];
237
// skip 5 & 6 byte codes
238
if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len-1; continue; }
239
240
// apply mask on first byte
241
c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
242
// join the rest
243
while (c_len > 1 && i < len) {
244
c = (c << 6) | (buf[i++] & 0x3f);
245
c_len--;
246
}
247
248
// terminated by end of string?
249
if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }
250
251
if (c < 0x10000) {
252
utf16buf[out++] = c;
253
} else {
254
c -= 0x10000;
255
utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);
256
utf16buf[out++] = 0xdc00 | (c & 0x3ff);
257
}
258
}
259
260
return buf2binstring(utf16buf, out);
261
};
262
263
264
// Calculate max possible position in utf8 buffer,
265
// that will not break sequence. If that's not possible
266
// - (very small limits) return max size as is.
267
//
268
// buf[] - utf8 bytes array
269
// max - length limit (mandatory);
270
exports.utf8border = function(buf, max) {
271
var pos;
272
273
max = max || buf.length;
274
if (max > buf.length) { max = buf.length; }
275
276
// go back from last position, until start of sequence found
277
pos = max-1;
278
while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }
279
280
// Fuckup - very small and broken sequence,
281
// return max, because we should return something anyway.
282
if (pos < 0) { return max; }
283
284
// If we came to start of buffer - that means vuffer is too small,
285
// return max too.
286
if (pos === 0) { return max; }
287
288
return (pos + _utf8len[buf[pos]] > max) ? pos : max;
289
};
290
291
},{"./common":1}],3:[function(require,module,exports){
292
'use strict';
293
294
// Note: adler32 takes 12% for level 0 and 2% for level 6.
295
// It doesn't worth to make additional optimizationa as in original.
296
// Small size is preferable.
297
298
function adler32(adler, buf, len, pos) {
299
var s1 = (adler & 0xffff) |0
300
, s2 = ((adler >>> 16) & 0xffff) |0
301
, n = 0;
302
303
while (len !== 0) {
304
// Set limit ~ twice less than 5552, to keep
305
// s2 in 31-bits, because we force signed ints.
306
// in other case %= will fail.
307
n = len > 2000 ? 2000 : len;
308
len -= n;
309
310
do {
311
s1 = (s1 + buf[pos++]) |0;
312
s2 = (s2 + s1) |0;
313
} while (--n);
314
315
s1 %= 65521;
316
s2 %= 65521;
317
}
318
319
return (s1 | (s2 << 16)) |0;
320
}
321
322
323
module.exports = adler32;
324
},{}],4:[function(require,module,exports){
325
module.exports = {
326
327
/* Allowed flush values; see deflate() and inflate() below for details */
328
Z_NO_FLUSH: 0,
329
Z_PARTIAL_FLUSH: 1,
330
Z_SYNC_FLUSH: 2,
331
Z_FULL_FLUSH: 3,
332
Z_FINISH: 4,
333
Z_BLOCK: 5,
334
Z_TREES: 6,
335
336
/* Return codes for the compression/decompression functions. Negative values
337
* are errors, positive values are used for special but normal events.
338
*/
339
Z_OK: 0,
340
Z_STREAM_END: 1,
341
Z_NEED_DICT: 2,
342
Z_ERRNO: -1,
343
Z_STREAM_ERROR: -2,
344
Z_DATA_ERROR: -3,
345
//Z_MEM_ERROR: -4,
346
Z_BUF_ERROR: -5,
347
//Z_VERSION_ERROR: -6,
348
349
/* compression levels */
350
Z_NO_COMPRESSION: 0,
351
Z_BEST_SPEED: 1,
352
Z_BEST_COMPRESSION: 9,
353
Z_DEFAULT_COMPRESSION: -1,
354
355
356
Z_FILTERED: 1,
357
Z_HUFFMAN_ONLY: 2,
358
Z_RLE: 3,
359
Z_FIXED: 4,
360
Z_DEFAULT_STRATEGY: 0,
361
362
/* Possible values of the data_type field (though see inflate()) */
363
Z_BINARY: 0,
364
Z_TEXT: 1,
365
//Z_ASCII: 1, // = Z_TEXT (deprecated)
366
Z_UNKNOWN: 2,
367
368
/* The deflate compression method */
369
Z_DEFLATED: 8
370
//Z_NULL: null // Use -1 or null inline, depending on var type
371
};
372
},{}],5:[function(require,module,exports){
373
'use strict';
374
375
// Note: we can't get significant speed boost here.
376
// So write code to minimize size - no pregenerated tables
377
// and array tools dependencies.
378
379
380
// Use ordinary array, since untyped makes no boost here
381
function makeTable() {
382
var c, table = [];
383
384
for(var n =0; n < 256; n++){
385
c = n;
386
for(var k =0; k < 8; k++){
387
c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
388
}
389
table[n] = c;
390
}
391
392
return table;
393
}
394
395
// Create table on load. Just 255 signed longs. Not a problem.
396
var crcTable = makeTable();
397
398
399
function crc32(crc, buf, len, pos) {
400
var t = crcTable
401
, end = pos + len;
402
403
crc = crc ^ (-1);
404
405
for (var i = pos; i < end; i++ ) {
406
crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];
407
}
408
409
return (crc ^ (-1)); // >>> 0;
410
}
411
412
413
module.exports = crc32;
414
},{}],6:[function(require,module,exports){
415
'use strict';
416
417
418
function GZheader() {
419
/* true if compressed data believed to be text */
420
this.text = 0;
421
/* modification time */
422
this.time = 0;
423
/* extra flags (not used when writing a gzip file) */
424
this.xflags = 0;
425
/* operating system */
426
this.os = 0;
427
/* pointer to extra field or Z_NULL if none */
428
this.extra = null;
429
/* extra field length (valid if extra != Z_NULL) */
430
this.extra_len = 0; // Actually, we don't need it in JS,
431
// but leave for few code modifications
432
433
//
434
// Setup limits is not necessary because in js we should not preallocate memory
435
// for inflate use constant limit in 65536 bytes
436
//
437
438
/* space at extra (only when reading header) */
439
// this.extra_max = 0;
440
/* pointer to zero-terminated file name or Z_NULL */
441
this.name = '';
442
/* space at name (only when reading header) */
443
// this.name_max = 0;
444
/* pointer to zero-terminated comment or Z_NULL */
445
this.comment = '';
446
/* space at comment (only when reading header) */
447
// this.comm_max = 0;
448
/* true if there was or will be a header crc */
449
this.hcrc = 0;
450
/* true when done reading gzip header (not used when writing a gzip file) */
451
this.done = false;
452
}
453
454
module.exports = GZheader;
455
},{}],7:[function(require,module,exports){
456
'use strict';
457
458
// See state defs from inflate.js
459
var BAD = 30; /* got a data error -- remain here until reset */
460
var TYPE = 12; /* i: waiting for type bits, including last-flag bit */
461
462
/*
463
Decode literal, length, and distance codes and write out the resulting
464
literal and match bytes until either not enough input or output is
465
available, an end-of-block is encountered, or a data error is encountered.
466
When large enough input and output buffers are supplied to inflate(), for
467
example, a 16K input buffer and a 64K output buffer, more than 95% of the
468
inflate execution time is spent in this routine.
469
470
Entry assumptions:
471
472
state.mode === LEN
473
strm.avail_in >= 6
474
strm.avail_out >= 258
475
start >= strm.avail_out
476
state.bits < 8
477
478
On return, state.mode is one of:
479
480
LEN -- ran out of enough output space or enough available input
481
TYPE -- reached end of block code, inflate() to interpret next block
482
BAD -- error in block data
483
484
Notes:
485
486
- The maximum input bits used by a length/distance pair is 15 bits for the
487
length code, 5 bits for the length extra, 15 bits for the distance code,
488
and 13 bits for the distance extra. This totals 48 bits, or six bytes.
489
Therefore if strm.avail_in >= 6, then there is enough input to avoid
490
checking for available input while decoding.
491
492
- The maximum bytes that a single length/distance pair can output is 258
493
bytes, which is the maximum length that can be coded. inflate_fast()
494
requires strm.avail_out >= 258 for each loop to avoid checking for
495
output space.
496
*/
497
module.exports = function inflate_fast(strm, start) {
498
var state;
499
var _in; /* local strm.input */
500
var last; /* have enough input while in < last */
501
var _out; /* local strm.output */
502
var beg; /* inflate()'s initial strm.output */
503
var end; /* while out < end, enough space available */
504
//#ifdef INFLATE_STRICT
505
var dmax; /* maximum distance from zlib header */
506
//#endif
507
var wsize; /* window size or zero if not using window */
508
var whave; /* valid bytes in the window */
509
var wnext; /* window write index */
510
var window; /* allocated sliding window, if wsize != 0 */
511
var hold; /* local strm.hold */
512
var bits; /* local strm.bits */
513
var lcode; /* local strm.lencode */
514
var dcode; /* local strm.distcode */
515
var lmask; /* mask for first level of length codes */
516
var dmask; /* mask for first level of distance codes */
517
var here; /* retrieved table entry */
518
var op; /* code bits, operation, extra bits, or */
519
/* window position, window bytes to copy */
520
var len; /* match length, unused bytes */
521
var dist; /* match distance */
522
var from; /* where to copy match from */
523
var from_source;
524
525
526
var input, output; // JS specific, because we have no pointers
527
528
/* copy state to local variables */
529
state = strm.state;
530
//here = state.here;
531
_in = strm.next_in;
532
input = strm.input;
533
last = _in + (strm.avail_in - 5);
534
_out = strm.next_out;
535
output = strm.output;
536
beg = _out - (start - strm.avail_out);
537
end = _out + (strm.avail_out - 257);
538
//#ifdef INFLATE_STRICT
539
dmax = state.dmax;
540
//#endif
541
wsize = state.wsize;
542
whave = state.whave;
543
wnext = state.wnext;
544
window = state.window;
545
hold = state.hold;
546
bits = state.bits;
547
lcode = state.lencode;
548
dcode = state.distcode;
549
lmask = (1 << state.lenbits) - 1;
550
dmask = (1 << state.distbits) - 1;
551
552
553
/* decode literals and length/distances until end-of-block or not enough
554
input data or output space */
555
556
top:
557
do {
558
if (bits < 15) {
559
hold += input[_in++] << bits;
560
bits += 8;
561
hold += input[_in++] << bits;
562
bits += 8;
563
}
564
565
here = lcode[hold & lmask];
566
567
dolen:
568
for (;;) { // Goto emulation
569
op = here >>> 24/*here.bits*/;
570
hold >>>= op;
571
bits -= op;
572
op = (here >>> 16) & 0xff/*here.op*/;
573
if (op === 0) { /* literal */
574
//Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
575
// "inflate: literal '%c'\n" :
576
// "inflate: literal 0x%02x\n", here.val));
577
output[_out++] = here & 0xffff/*here.val*/;
578
}
579
else if (op & 16) { /* length base */
580
len = here & 0xffff/*here.val*/;
581
op &= 15; /* number of extra bits */
582
if (op) {
583
if (bits < op) {
584
hold += input[_in++] << bits;
585
bits += 8;
586
}
587
len += hold & ((1 << op) - 1);
588
hold >>>= op;
589
bits -= op;
590
}
591
//Tracevv((stderr, "inflate: length %u\n", len));
592
if (bits < 15) {
593
hold += input[_in++] << bits;
594
bits += 8;
595
hold += input[_in++] << bits;
596
bits += 8;
597
}
598
here = dcode[hold & dmask];
599
600
dodist:
601
for (;;) { // goto emulation
602
op = here >>> 24/*here.bits*/;
603
hold >>>= op;
604
bits -= op;
605
op = (here >>> 16) & 0xff/*here.op*/;
606
607
if (op & 16) { /* distance base */
608
dist = here & 0xffff/*here.val*/;
609
op &= 15; /* number of extra bits */
610
if (bits < op) {
611
hold += input[_in++] << bits;
612
bits += 8;
613
if (bits < op) {
614
hold += input[_in++] << bits;
615
bits += 8;
616
}
617
}
618
dist += hold & ((1 << op) - 1);
619
//#ifdef INFLATE_STRICT
620
if (dist > dmax) {
621
strm.msg = 'invalid distance too far back';
622
state.mode = BAD;
623
break top;
624
}
625
//#endif
626
hold >>>= op;
627
bits -= op;
628
//Tracevv((stderr, "inflate: distance %u\n", dist));
629
op = _out - beg; /* max distance in output */
630
if (dist > op) { /* see if copy from window */
631
op = dist - op; /* distance back in window */
632
if (op > whave) {
633
if (state.sane) {
634
strm.msg = 'invalid distance too far back';
635
state.mode = BAD;
636
break top;
637
}
638
639
// (!) This block is disabled in zlib defailts,
640
// don't enable it for binary compatibility
641
//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
642
// if (len <= op - whave) {
643
// do {
644
// output[_out++] = 0;
645
// } while (--len);
646
// continue top;
647
// }
648
// len -= op - whave;
649
// do {
650
// output[_out++] = 0;
651
// } while (--op > whave);
652
// if (op === 0) {
653
// from = _out - dist;
654
// do {
655
// output[_out++] = output[from++];
656
// } while (--len);
657
// continue top;
658
// }
659
//#endif
660
}
661
from = 0; // window index
662
from_source = window;
663
if (wnext === 0) { /* very common case */
664
from += wsize - op;
665
if (op < len) { /* some from window */
666
len -= op;
667
do {
668
output[_out++] = window[from++];
669
} while (--op);
670
from = _out - dist; /* rest from output */
671
from_source = output;
672
}
673
}
674
else if (wnext < op) { /* wrap around window */
675
from += wsize + wnext - op;
676
op -= wnext;
677
if (op < len) { /* some from end of window */
678
len -= op;
679
do {
680
output[_out++] = window[from++];
681
} while (--op);
682
from = 0;
683
if (wnext < len) { /* some from start of window */
684
op = wnext;
685
len -= op;
686
do {
687
output[_out++] = window[from++];
688
} while (--op);
689
from = _out - dist; /* rest from output */
690
from_source = output;
691
}
692
}
693
}
694
else { /* contiguous in window */
695
from += wnext - op;
696
if (op < len) { /* some from window */
697
len -= op;
698
do {
699
output[_out++] = window[from++];
700
} while (--op);
701
from = _out - dist; /* rest from output */
702
from_source = output;
703
}
704
}
705
while (len > 2) {
706
output[_out++] = from_source[from++];
707
output[_out++] = from_source[from++];
708
output[_out++] = from_source[from++];
709
len -= 3;
710
}
711
if (len) {
712
output[_out++] = from_source[from++];
713
if (len > 1) {
714
output[_out++] = from_source[from++];
715
}
716
}
717
}
718
else {
719
from = _out - dist; /* copy direct from output */
720
do { /* minimum length is three */
721
output[_out++] = output[from++];
722
output[_out++] = output[from++];
723
output[_out++] = output[from++];
724
len -= 3;
725
} while (len > 2);
726
if (len) {
727
output[_out++] = output[from++];
728
if (len > 1) {
729
output[_out++] = output[from++];
730
}
731
}
732
}
733
}
734
else if ((op & 64) === 0) { /* 2nd level distance code */
735
here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
736
continue dodist;
737
}
738
else {
739
strm.msg = 'invalid distance code';
740
state.mode = BAD;
741
break top;
742
}
743
744
break; // need to emulate goto via "continue"
745
}
746
}
747
else if ((op & 64) === 0) { /* 2nd level length code */
748
here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
749
continue dolen;
750
}
751
else if (op & 32) { /* end-of-block */
752
//Tracevv((stderr, "inflate: end of block\n"));
753
state.mode = TYPE;
754
break top;
755
}
756
else {
757
strm.msg = 'invalid literal/length code';
758
state.mode = BAD;
759
break top;
760
}
761
762
break; // need to emulate goto via "continue"
763
}
764
} while (_in < last && _out < end);
765
766
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */
767
len = bits >> 3;
768
_in -= len;
769
bits -= len << 3;
770
hold &= (1 << bits) - 1;
771
772
/* update state and return */
773
strm.next_in = _in;
774
strm.next_out = _out;
775
strm.avail_in = (_in < last ? 5 + (last - _in) : 5 - (_in - last));
776
strm.avail_out = (_out < end ? 257 + (end - _out) : 257 - (_out - end));
777
state.hold = hold;
778
state.bits = bits;
779
return;
780
};
781
782
},{}],8:[function(require,module,exports){
783
'use strict';
784
785
786
var utils = require('../utils/common');
787
var adler32 = require('./adler32');
788
var crc32 = require('./crc32');
789
var inflate_fast = require('./inffast');
790
var inflate_table = require('./inftrees');
791
792
var CODES = 0;
793
var LENS = 1;
794
var DISTS = 2;
795
796
/* Public constants ==========================================================*/
797
/* ===========================================================================*/
798
799
800
/* Allowed flush values; see deflate() and inflate() below for details */
801
//var Z_NO_FLUSH = 0;
802
//var Z_PARTIAL_FLUSH = 1;
803
//var Z_SYNC_FLUSH = 2;
804
//var Z_FULL_FLUSH = 3;
805
var Z_FINISH = 4;
806
var Z_BLOCK = 5;
807
var Z_TREES = 6;
808
809
810
/* Return codes for the compression/decompression functions. Negative values
811
* are errors, positive values are used for special but normal events.
812
*/
813
var Z_OK = 0;
814
var Z_STREAM_END = 1;
815
var Z_NEED_DICT = 2;
816
//var Z_ERRNO = -1;
817
var Z_STREAM_ERROR = -2;
818
var Z_DATA_ERROR = -3;
819
var Z_MEM_ERROR = -4;
820
var Z_BUF_ERROR = -5;
821
//var Z_VERSION_ERROR = -6;
822
823
/* The deflate compression method */
824
var Z_DEFLATED = 8;
825
826
827
/* STATES ====================================================================*/
828
/* ===========================================================================*/
829
830
831
var HEAD = 1; /* i: waiting for magic header */
832
var FLAGS = 2; /* i: waiting for method and flags (gzip) */
833
var TIME = 3; /* i: waiting for modification time (gzip) */
834
var OS = 4; /* i: waiting for extra flags and operating system (gzip) */
835
var EXLEN = 5; /* i: waiting for extra length (gzip) */
836
var EXTRA = 6; /* i: waiting for extra bytes (gzip) */
837
var NAME = 7; /* i: waiting for end of file name (gzip) */
838
var COMMENT = 8; /* i: waiting for end of comment (gzip) */
839
var HCRC = 9; /* i: waiting for header crc (gzip) */
840
var DICTID = 10; /* i: waiting for dictionary check value */
841
var DICT = 11; /* waiting for inflateSetDictionary() call */
842
var TYPE = 12; /* i: waiting for type bits, including last-flag bit */
843
var TYPEDO = 13; /* i: same, but skip check to exit inflate on new block */
844
var STORED = 14; /* i: waiting for stored size (length and complement) */
845
var COPY_ = 15; /* i/o: same as COPY below, but only first time in */
846
var COPY = 16; /* i/o: waiting for input or output to copy stored block */
847
var TABLE = 17; /* i: waiting for dynamic block table lengths */
848
var LENLENS = 18; /* i: waiting for code length code lengths */
849
var CODELENS = 19; /* i: waiting for length/lit and distance code lengths */
850
var LEN_ = 20; /* i: same as LEN below, but only first time in */
851
var LEN = 21; /* i: waiting for length/lit/eob code */
852
var LENEXT = 22; /* i: waiting for length extra bits */
853
var DIST = 23; /* i: waiting for distance code */
854
var DISTEXT = 24; /* i: waiting for distance extra bits */
855
var MATCH = 25; /* o: waiting for output space to copy string */
856
var LIT = 26; /* o: waiting for output space to write literal */
857
var CHECK = 27; /* i: waiting for 32-bit check value */
858
var LENGTH = 28; /* i: waiting for 32-bit length (gzip) */
859
var DONE = 29; /* finished check, done -- remain here until reset */
860
var BAD = 30; /* got a data error -- remain here until reset */
861
var MEM = 31; /* got an inflate() memory error -- remain here until reset */
862
var SYNC = 32; /* looking for synchronization bytes to restart inflate() */
863
864
/* ===========================================================================*/
865
866
867
868
var ENOUGH_LENS = 852;
869
var ENOUGH_DISTS = 592;
870
//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
871
872
var MAX_WBITS = 15;
873
/* 32K LZ77 window */
874
var DEF_WBITS = MAX_WBITS;
875
876
877
function ZSWAP32(q) {
878
return (((q >>> 24) & 0xff) +
879
((q >>> 8) & 0xff00) +
880
((q & 0xff00) << 8) +
881
((q & 0xff) << 24));
882
}
883
884
885
function InflateState() {
886
this.mode = 0; /* current inflate mode */
887
this.last = false; /* true if processing last block */
888
this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */
889
this.havedict = false; /* true if dictionary provided */
890
this.flags = 0; /* gzip header method and flags (0 if zlib) */
891
this.dmax = 0; /* zlib header max distance (INFLATE_STRICT) */
892
this.check = 0; /* protected copy of check value */
893
this.total = 0; /* protected copy of output count */
894
// TODO: may be {}
895
this.head = null; /* where to save gzip header information */
896
897
/* sliding window */
898
this.wbits = 0; /* log base 2 of requested window size */
899
this.wsize = 0; /* window size or zero if not using window */
900
this.whave = 0; /* valid bytes in the window */
901
this.wnext = 0; /* window write index */
902
this.window = null; /* allocated sliding window, if needed */
903
904
/* bit accumulator */
905
this.hold = 0; /* input bit accumulator */
906
this.bits = 0; /* number of bits in "in" */
907
908
/* for string and stored block copying */
909
this.length = 0; /* literal or length of data to copy */
910
this.offset = 0; /* distance back to copy string from */
911
912
/* for table and code decoding */
913
this.extra = 0; /* extra bits needed */
914
915
/* fixed and dynamic code tables */
916
this.lencode = null; /* starting table for length/literal codes */
917
this.distcode = null; /* starting table for distance codes */
918
this.lenbits = 0; /* index bits for lencode */
919
this.distbits = 0; /* index bits for distcode */
920
921
/* dynamic table building */
922
this.ncode = 0; /* number of code length code lengths */
923
this.nlen = 0; /* number of length code lengths */
924
this.ndist = 0; /* number of distance code lengths */
925
this.have = 0; /* number of code lengths in lens[] */
926
this.next = null; /* next available space in codes[] */
927
928
this.lens = new utils.Buf16(320); /* temporary storage for code lengths */
929
this.work = new utils.Buf16(288); /* work area for code table building */
930
931
/*
932
because we don't have pointers in js, we use lencode and distcode directly
933
as buffers so we don't need codes
934
*/
935
//this.codes = new utils.Buf32(ENOUGH); /* space for code tables */
936
this.lendyn = null; /* dynamic table for length/literal codes (JS specific) */
937
this.distdyn = null; /* dynamic table for distance codes (JS specific) */
938
this.sane = 0; /* if false, allow invalid distance too far */
939
this.back = 0; /* bits back of last unprocessed length/lit */
940
this.was = 0; /* initial length of match */
941
}
942
943
function inflateResetKeep(strm) {
944
var state;
945
946
if (!strm || !strm.state) { return Z_STREAM_ERROR; }
947
state = strm.state;
948
strm.total_in = strm.total_out = state.total = 0;
949
strm.msg = ''; /*Z_NULL*/
950
if (state.wrap) { /* to support ill-conceived Java test suite */
951
strm.adler = state.wrap & 1;
952
}
953
state.mode = HEAD;
954
state.last = 0;
955
state.havedict = 0;
956
state.dmax = 32768;
957
state.head = null/*Z_NULL*/;
958
state.hold = 0;
959
state.bits = 0;
960
//state.lencode = state.distcode = state.next = state.codes;
961
state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS);
962
state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS);
963
964
state.sane = 1;
965
state.back = -1;
966
//Tracev((stderr, "inflate: reset\n"));
967
return Z_OK;
968
}
969
970
function inflateReset(strm) {
971
var state;
972
973
if (!strm || !strm.state) { return Z_STREAM_ERROR; }
974
state = strm.state;
975
state.wsize = 0;
976
state.whave = 0;
977
state.wnext = 0;
978
return inflateResetKeep(strm);
979
980
}
981
982
function inflateReset2(strm, windowBits) {
983
var wrap;
984
var state;
985
986
/* get the state */
987
if (!strm || !strm.state) { return Z_STREAM_ERROR; }
988
state = strm.state;
989
990
/* extract wrap request from windowBits parameter */
991
if (windowBits < 0) {
992
wrap = 0;
993
windowBits = -windowBits;
994
}
995
else {
996
wrap = (windowBits >> 4) + 1;
997
if (windowBits < 48) {
998
windowBits &= 15;
999
}
1000
}
1001
1002
/* set number of window bits, free window if different */
1003
if (windowBits && (windowBits < 8 || windowBits > 15)) {
1004
return Z_STREAM_ERROR;
1005
}
1006
if (state.window !== null && state.wbits !== windowBits) {
1007
state.window = null;
1008
}
1009
1010
/* update state and reset the rest of it */
1011
state.wrap = wrap;
1012
state.wbits = windowBits;
1013
return inflateReset(strm);
1014
}
1015
1016
function inflateInit2(strm, windowBits) {
1017
var ret;
1018
var state;
1019
1020
if (!strm) { return Z_STREAM_ERROR; }
1021
//strm.msg = Z_NULL; /* in case we return an error */
1022
1023
state = new InflateState();
1024
1025
//if (state === Z_NULL) return Z_MEM_ERROR;
1026
//Tracev((stderr, "inflate: allocated\n"));
1027
strm.state = state;
1028
state.window = null/*Z_NULL*/;
1029
ret = inflateReset2(strm, windowBits);
1030
if (ret !== Z_OK) {
1031
strm.state = null/*Z_NULL*/;
1032
}
1033
return ret;
1034
}
1035
1036
function inflateInit(strm) {
1037
return inflateInit2(strm, DEF_WBITS);
1038
}
1039
1040
1041
/*
1042
Return state with length and distance decoding tables and index sizes set to
1043
fixed code decoding. Normally this returns fixed tables from inffixed.h.
1044
If BUILDFIXED is defined, then instead this routine builds the tables the
1045
first time it's called, and returns those tables the first time and
1046
thereafter. This reduces the size of the code by about 2K bytes, in
1047
exchange for a little execution time. However, BUILDFIXED should not be
1048
used for threaded applications, since the rewriting of the tables and virgin
1049
may not be thread-safe.
1050
*/
1051
var virgin = true;
1052
1053
var lenfix, distfix; // We have no pointers in JS, so keep tables separate
1054
1055
function fixedtables(state) {
1056
/* build fixed huffman tables if first call (may not be thread safe) */
1057
if (virgin) {
1058
var sym;
1059
1060
lenfix = new utils.Buf32(512);
1061
distfix = new utils.Buf32(32);
1062
1063
/* literal/length table */
1064
sym = 0;
1065
while (sym < 144) { state.lens[sym++] = 8; }
1066
while (sym < 256) { state.lens[sym++] = 9; }
1067
while (sym < 280) { state.lens[sym++] = 7; }
1068
while (sym < 288) { state.lens[sym++] = 8; }
1069
1070
inflate_table(LENS, state.lens, 0, 288, lenfix, 0, state.work, {bits: 9});
1071
1072
/* distance table */
1073
sym = 0;
1074
while (sym < 32) { state.lens[sym++] = 5; }
1075
1076
inflate_table(DISTS, state.lens, 0, 32, distfix, 0, state.work, {bits: 5});
1077
1078
/* do this just once */
1079
virgin = false;
1080
}
1081
1082
state.lencode = lenfix;
1083
state.lenbits = 9;
1084
state.distcode = distfix;
1085
state.distbits = 5;
1086
}
1087
1088
1089
/*
1090
Update the window with the last wsize (normally 32K) bytes written before
1091
returning. If window does not exist yet, create it. This is only called
1092
when a window is already in use, or when output has been written during this
1093
inflate call, but the end of the deflate stream has not been reached yet.
1094
It is also called to create a window for dictionary data when a dictionary
1095
is loaded.
1096
1097
Providing output buffers larger than 32K to inflate() should provide a speed
1098
advantage, since only the last 32K of output is copied to the sliding window
1099
upon return from inflate(), and since all distances after the first 32K of
1100
output will fall in the output data, making match copies simpler and faster.
1101
The advantage may be dependent on the size of the processor's data caches.
1102
*/
1103
function updatewindow(strm, src, end, copy) {
1104
var dist;
1105
var state = strm.state;
1106
1107
/* if it hasn't been done already, allocate space for the window */
1108
if (state.window === null) {
1109
state.wsize = 1 << state.wbits;
1110
state.wnext = 0;
1111
state.whave = 0;
1112
1113
state.window = new utils.Buf8(state.wsize);
1114
}
1115
1116
/* copy state->wsize or less output bytes into the circular window */
1117
if (copy >= state.wsize) {
1118
utils.arraySet(state.window,src, end - state.wsize, state.wsize, 0);
1119
state.wnext = 0;
1120
state.whave = state.wsize;
1121
}
1122
else {
1123
dist = state.wsize - state.wnext;
1124
if (dist > copy) {
1125
dist = copy;
1126
}
1127
//zmemcpy(state->window + state->wnext, end - copy, dist);
1128
utils.arraySet(state.window,src, end - copy, dist, state.wnext);
1129
copy -= dist;
1130
if (copy) {
1131
//zmemcpy(state->window, end - copy, copy);
1132
utils.arraySet(state.window,src, end - copy, copy, 0);
1133
state.wnext = copy;
1134
state.whave = state.wsize;
1135
}
1136
else {
1137
state.wnext += dist;
1138
if (state.wnext === state.wsize) { state.wnext = 0; }
1139
if (state.whave < state.wsize) { state.whave += dist; }
1140
}
1141
}
1142
return 0;
1143
}
1144
1145
function inflate(strm, flush) {
1146
var state;
1147
var input, output; // input/output buffers
1148
var next; /* next input INDEX */
1149
var put; /* next output INDEX */
1150
var have, left; /* available input and output */
1151
var hold; /* bit buffer */
1152
var bits; /* bits in bit buffer */
1153
var _in, _out; /* save starting available input and output */
1154
var copy; /* number of stored or match bytes to copy */
1155
var from; /* where to copy match bytes from */
1156
var from_source;
1157
var here = 0; /* current decoding table entry */
1158
var here_bits, here_op, here_val; // paked "here" denormalized (JS specific)
1159
//var last; /* parent table entry */
1160
var last_bits, last_op, last_val; // paked "last" denormalized (JS specific)
1161
var len; /* length to copy for repeats, bits to drop */
1162
var ret; /* return code */
1163
var hbuf = new utils.Buf8(4); /* buffer for gzip header crc calculation */
1164
var opts;
1165
1166
var n; // temporary var for NEED_BITS
1167
1168
var order = /* permutation of code lengths */
1169
[16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
1170
1171
1172
if (!strm || !strm.state || !strm.output ||
1173
(!strm.input && strm.avail_in !== 0)) {
1174
return Z_STREAM_ERROR;
1175
}
1176
1177
state = strm.state;
1178
if (state.mode === TYPE) { state.mode = TYPEDO; } /* skip check */
1179
1180
1181
//--- LOAD() ---
1182
put = strm.next_out;
1183
output = strm.output;
1184
left = strm.avail_out;
1185
next = strm.next_in;
1186
input = strm.input;
1187
have = strm.avail_in;
1188
hold = state.hold;
1189
bits = state.bits;
1190
//---
1191
1192
_in = have;
1193
_out = left;
1194
ret = Z_OK;
1195
1196
inf_leave: // goto emulation
1197
for (;;) {
1198
switch (state.mode) {
1199
case HEAD:
1200
if (state.wrap === 0) {
1201
state.mode = TYPEDO;
1202
break;
1203
}
1204
//=== NEEDBITS(16);
1205
while (bits < 16) {
1206
if (have === 0) { break inf_leave; }
1207
have--;
1208
hold += input[next++] << bits;
1209
bits += 8;
1210
}
1211
//===//
1212
if ((state.wrap & 2) && hold === 0x8b1f) { /* gzip header */
1213
state.check = 0/*crc32(0L, Z_NULL, 0)*/;
1214
//=== CRC2(state.check, hold);
1215
hbuf[0] = hold & 0xff;
1216
hbuf[1] = (hold >>> 8) & 0xff;
1217
state.check = crc32(state.check, hbuf, 2, 0);
1218
//===//
1219
1220
//=== INITBITS();
1221
hold = 0;
1222
bits = 0;
1223
//===//
1224
state.mode = FLAGS;
1225
break;
1226
}
1227
state.flags = 0; /* expect zlib header */
1228
if (state.head) {
1229
state.head.done = false;
1230
}
1231
if (!(state.wrap & 1) || /* check if zlib header allowed */
1232
(((hold & 0xff)/*BITS(8)*/ << 8) + (hold >> 8)) % 31) {
1233
strm.msg = 'incorrect header check';
1234
state.mode = BAD;
1235
break;
1236
}
1237
if ((hold & 0x0f)/*BITS(4)*/ !== Z_DEFLATED) {
1238
strm.msg = 'unknown compression method';
1239
state.mode = BAD;
1240
break;
1241
}
1242
//--- DROPBITS(4) ---//
1243
hold >>>= 4;
1244
bits -= 4;
1245
//---//
1246
len = (hold & 0x0f)/*BITS(4)*/ + 8;
1247
if (state.wbits === 0) {
1248
state.wbits = len;
1249
}
1250
else if (len > state.wbits) {
1251
strm.msg = 'invalid window size';
1252
state.mode = BAD;
1253
break;
1254
}
1255
state.dmax = 1 << len;
1256
//Tracev((stderr, "inflate: zlib header ok\n"));
1257
strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
1258
state.mode = hold & 0x200 ? DICTID : TYPE;
1259
//=== INITBITS();
1260
hold = 0;
1261
bits = 0;
1262
//===//
1263
break;
1264
case FLAGS:
1265
//=== NEEDBITS(16); */
1266
while (bits < 16) {
1267
if (have === 0) { break inf_leave; }
1268
have--;
1269
hold += input[next++] << bits;
1270
bits += 8;
1271
}
1272
//===//
1273
state.flags = hold;
1274
if ((state.flags & 0xff) !== Z_DEFLATED) {
1275
strm.msg = 'unknown compression method';
1276
state.mode = BAD;
1277
break;
1278
}
1279
if (state.flags & 0xe000) {
1280
strm.msg = 'unknown header flags set';
1281
state.mode = BAD;
1282
break;
1283
}
1284
if (state.head) {
1285
state.head.text = ((hold >> 8) & 1);
1286
}
1287
if (state.flags & 0x0200) {
1288
//=== CRC2(state.check, hold);
1289
hbuf[0] = hold & 0xff;
1290
hbuf[1] = (hold >>> 8) & 0xff;
1291
state.check = crc32(state.check, hbuf, 2, 0);
1292
//===//
1293
}
1294
//=== INITBITS();
1295
hold = 0;
1296
bits = 0;
1297
//===//
1298
state.mode = TIME;
1299
/* falls through */
1300
case TIME:
1301
//=== NEEDBITS(32); */
1302
while (bits < 32) {
1303
if (have === 0) { break inf_leave; }
1304
have--;
1305
hold += input[next++] << bits;
1306
bits += 8;
1307
}
1308
//===//
1309
if (state.head) {
1310
state.head.time = hold;
1311
}
1312
if (state.flags & 0x0200) {
1313
//=== CRC4(state.check, hold)
1314
hbuf[0] = hold & 0xff;
1315
hbuf[1] = (hold >>> 8) & 0xff;
1316
hbuf[2] = (hold >>> 16) & 0xff;
1317
hbuf[3] = (hold >>> 24) & 0xff;
1318
state.check = crc32(state.check, hbuf, 4, 0);
1319
//===
1320
}
1321
//=== INITBITS();
1322
hold = 0;
1323
bits = 0;
1324
//===//
1325
state.mode = OS;
1326
/* falls through */
1327
case OS:
1328
//=== NEEDBITS(16); */
1329
while (bits < 16) {
1330
if (have === 0) { break inf_leave; }
1331
have--;
1332
hold += input[next++] << bits;
1333
bits += 8;
1334
}
1335
//===//
1336
if (state.head) {
1337
state.head.xflags = (hold & 0xff);
1338
state.head.os = (hold >> 8);
1339
}
1340
if (state.flags & 0x0200) {
1341
//=== CRC2(state.check, hold);
1342
hbuf[0] = hold & 0xff;
1343
hbuf[1] = (hold >>> 8) & 0xff;
1344
state.check = crc32(state.check, hbuf, 2, 0);
1345
//===//
1346
}
1347
//=== INITBITS();
1348
hold = 0;
1349
bits = 0;
1350
//===//
1351
state.mode = EXLEN;
1352
/* falls through */
1353
case EXLEN:
1354
if (state.flags & 0x0400) {
1355
//=== NEEDBITS(16); */
1356
while (bits < 16) {
1357
if (have === 0) { break inf_leave; }
1358
have--;
1359
hold += input[next++] << bits;
1360
bits += 8;
1361
}
1362
//===//
1363
state.length = hold;
1364
if (state.head) {
1365
state.head.extra_len = hold;
1366
}
1367
if (state.flags & 0x0200) {
1368
//=== CRC2(state.check, hold);
1369
hbuf[0] = hold & 0xff;
1370
hbuf[1] = (hold >>> 8) & 0xff;
1371
state.check = crc32(state.check, hbuf, 2, 0);
1372
//===//
1373
}
1374
//=== INITBITS();
1375
hold = 0;
1376
bits = 0;
1377
//===//
1378
}
1379
else if (state.head) {
1380
state.head.extra = null/*Z_NULL*/;
1381
}
1382
state.mode = EXTRA;
1383
/* falls through */
1384
case EXTRA:
1385
if (state.flags & 0x0400) {
1386
copy = state.length;
1387
if (copy > have) { copy = have; }
1388
if (copy) {
1389
if (state.head) {
1390
len = state.head.extra_len - state.length;
1391
if (!state.head.extra) {
1392
// Use untyped array for more conveniend processing later
1393
state.head.extra = new Array(state.head.extra_len);
1394
}
1395
utils.arraySet(
1396
state.head.extra,
1397
input,
1398
next,
1399
// extra field is limited to 65536 bytes
1400
// - no need for additional size check
1401
copy,
1402
/*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
1403
len
1404
);
1405
//zmemcpy(state.head.extra + len, next,
1406
// len + copy > state.head.extra_max ?
1407
// state.head.extra_max - len : copy);
1408
}
1409
if (state.flags & 0x0200) {
1410
state.check = crc32(state.check, input, copy, next);
1411
}
1412
have -= copy;
1413
next += copy;
1414
state.length -= copy;
1415
}
1416
if (state.length) { break inf_leave; }
1417
}
1418
state.length = 0;
1419
state.mode = NAME;
1420
/* falls through */
1421
case NAME:
1422
if (state.flags & 0x0800) {
1423
if (have === 0) { break inf_leave; }
1424
copy = 0;
1425
do {
1426
// TODO: 2 or 1 bytes?
1427
len = input[next + copy++];
1428
/* use constant limit because in js we should not preallocate memory */
1429
if (state.head && len &&
1430
(state.length < 65536 /*state.head.name_max*/)) {
1431
state.head.name += String.fromCharCode(len);
1432
}
1433
} while (len && copy < have);
1434
1435
if (state.flags & 0x0200) {
1436
state.check = crc32(state.check, input, copy, next);
1437
}
1438
have -= copy;
1439
next += copy;
1440
if (len) { break inf_leave; }
1441
}
1442
else if (state.head) {
1443
state.head.name = null;
1444
}
1445
state.length = 0;
1446
state.mode = COMMENT;
1447
/* falls through */
1448
case COMMENT:
1449
if (state.flags & 0x1000) {
1450
if (have === 0) { break inf_leave; }
1451
copy = 0;
1452
do {
1453
len = input[next + copy++];
1454
/* use constant limit because in js we should not preallocate memory */
1455
if (state.head && len &&
1456
(state.length < 65536 /*state.head.comm_max*/)) {
1457
state.head.comment += String.fromCharCode(len);
1458
}
1459
} while (len && copy < have);
1460
if (state.flags & 0x0200) {
1461
state.check = crc32(state.check, input, copy, next);
1462
}
1463
have -= copy;
1464
next += copy;
1465
if (len) { break inf_leave; }
1466
}
1467
else if (state.head) {
1468
state.head.comment = null;
1469
}
1470
state.mode = HCRC;
1471
/* falls through */
1472
case HCRC:
1473
if (state.flags & 0x0200) {
1474
//=== NEEDBITS(16); */
1475
while (bits < 16) {
1476
if (have === 0) { break inf_leave; }
1477
have--;
1478
hold += input[next++] << bits;
1479
bits += 8;
1480
}
1481
//===//
1482
if (hold !== (state.check & 0xffff)) {
1483
strm.msg = 'header crc mismatch';
1484
state.mode = BAD;
1485
break;
1486
}
1487
//=== INITBITS();
1488
hold = 0;
1489
bits = 0;
1490
//===//
1491
}
1492
if (state.head) {
1493
state.head.hcrc = ((state.flags >> 9) & 1);
1494
state.head.done = true;
1495
}
1496
strm.adler = state.check = 0 /*crc32(0L, Z_NULL, 0)*/;
1497
state.mode = TYPE;
1498
break;
1499
case DICTID:
1500
//=== NEEDBITS(32); */
1501
while (bits < 32) {
1502
if (have === 0) { break inf_leave; }
1503
have--;
1504
hold += input[next++] << bits;
1505
bits += 8;
1506
}
1507
//===//
1508
strm.adler = state.check = ZSWAP32(hold);
1509
//=== INITBITS();
1510
hold = 0;
1511
bits = 0;
1512
//===//
1513
state.mode = DICT;
1514
/* falls through */
1515
case DICT:
1516
if (state.havedict === 0) {
1517
//--- RESTORE() ---
1518
strm.next_out = put;
1519
strm.avail_out = left;
1520
strm.next_in = next;
1521
strm.avail_in = have;
1522
state.hold = hold;
1523
state.bits = bits;
1524
//---
1525
return Z_NEED_DICT;
1526
}
1527
strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
1528
state.mode = TYPE;
1529
/* falls through */
1530
case TYPE:
1531
if (flush === Z_BLOCK || flush === Z_TREES) { break inf_leave; }
1532
/* falls through */
1533
case TYPEDO:
1534
if (state.last) {
1535
//--- BYTEBITS() ---//
1536
hold >>>= bits & 7;
1537
bits -= bits & 7;
1538
//---//
1539
state.mode = CHECK;
1540
break;
1541
}
1542
//=== NEEDBITS(3); */
1543
while (bits < 3) {
1544
if (have === 0) { break inf_leave; }
1545
have--;
1546
hold += input[next++] << bits;
1547
bits += 8;
1548
}
1549
//===//
1550
state.last = (hold & 0x01)/*BITS(1)*/;
1551
//--- DROPBITS(1) ---//
1552
hold >>>= 1;
1553
bits -= 1;
1554
//---//
1555
1556
switch ((hold & 0x03)/*BITS(2)*/) {
1557
case 0: /* stored block */
1558
//Tracev((stderr, "inflate: stored block%s\n",
1559
// state.last ? " (last)" : ""));
1560
state.mode = STORED;
1561
break;
1562
case 1: /* fixed block */
1563
fixedtables(state);
1564
//Tracev((stderr, "inflate: fixed codes block%s\n",
1565
// state.last ? " (last)" : ""));
1566
state.mode = LEN_; /* decode codes */
1567
if (flush === Z_TREES) {
1568
//--- DROPBITS(2) ---//
1569
hold >>>= 2;
1570
bits -= 2;
1571
//---//
1572
break inf_leave;
1573
}
1574
break;
1575
case 2: /* dynamic block */
1576
//Tracev((stderr, "inflate: dynamic codes block%s\n",
1577
// state.last ? " (last)" : ""));
1578
state.mode = TABLE;
1579
break;
1580
case 3:
1581
strm.msg = 'invalid block type';
1582
state.mode = BAD;
1583
}
1584
//--- DROPBITS(2) ---//
1585
hold >>>= 2;
1586
bits -= 2;
1587
//---//
1588
break;
1589
case STORED:
1590
//--- BYTEBITS() ---// /* go to byte boundary */
1591
hold >>>= bits & 7;
1592
bits -= bits & 7;
1593
//---//
1594
//=== NEEDBITS(32); */
1595
while (bits < 32) {
1596
if (have === 0) { break inf_leave; }
1597
have--;
1598
hold += input[next++] << bits;
1599
bits += 8;
1600
}
1601
//===//
1602
if ((hold & 0xffff) !== ((hold >>> 16) ^ 0xffff)) {
1603
strm.msg = 'invalid stored block lengths';
1604
state.mode = BAD;
1605
break;
1606
}
1607
state.length = hold & 0xffff;
1608
//Tracev((stderr, "inflate: stored length %u\n",
1609
// state.length));
1610
//=== INITBITS();
1611
hold = 0;
1612
bits = 0;
1613
//===//
1614
state.mode = COPY_;
1615
if (flush === Z_TREES) { break inf_leave; }
1616
/* falls through */
1617
case COPY_:
1618
state.mode = COPY;
1619
/* falls through */
1620
case COPY:
1621
copy = state.length;
1622
if (copy) {
1623
if (copy > have) { copy = have; }
1624
if (copy > left) { copy = left; }
1625
if (copy === 0) { break inf_leave; }
1626
//--- zmemcpy(put, next, copy); ---
1627
utils.arraySet(output, input, next, copy, put);
1628
//---//
1629
have -= copy;
1630
next += copy;
1631
left -= copy;
1632
put += copy;
1633
state.length -= copy;
1634
break;
1635
}
1636
//Tracev((stderr, "inflate: stored end\n"));
1637
state.mode = TYPE;
1638
break;
1639
case TABLE:
1640
//=== NEEDBITS(14); */
1641
while (bits < 14) {
1642
if (have === 0) { break inf_leave; }
1643
have--;
1644
hold += input[next++] << bits;
1645
bits += 8;
1646
}
1647
//===//
1648
state.nlen = (hold & 0x1f)/*BITS(5)*/ + 257;
1649
//--- DROPBITS(5) ---//
1650
hold >>>= 5;
1651
bits -= 5;
1652
//---//
1653
state.ndist = (hold & 0x1f)/*BITS(5)*/ + 1;
1654
//--- DROPBITS(5) ---//
1655
hold >>>= 5;
1656
bits -= 5;
1657
//---//
1658
state.ncode = (hold & 0x0f)/*BITS(4)*/ + 4;
1659
//--- DROPBITS(4) ---//
1660
hold >>>= 4;
1661
bits -= 4;
1662
//---//
1663
//#ifndef PKZIP_BUG_WORKAROUND
1664
if (state.nlen > 286 || state.ndist > 30) {
1665
strm.msg = 'too many length or distance symbols';
1666
state.mode = BAD;
1667
break;
1668
}
1669
//#endif
1670
//Tracev((stderr, "inflate: table sizes ok\n"));
1671
state.have = 0;
1672
state.mode = LENLENS;
1673
/* falls through */
1674
case LENLENS:
1675
while (state.have < state.ncode) {
1676
//=== NEEDBITS(3);
1677
while (bits < 3) {
1678
if (have === 0) { break inf_leave; }
1679
have--;
1680
hold += input[next++] << bits;
1681
bits += 8;
1682
}
1683
//===//
1684
state.lens[order[state.have++]] = (hold & 0x07);//BITS(3);
1685
//--- DROPBITS(3) ---//
1686
hold >>>= 3;
1687
bits -= 3;
1688
//---//
1689
}
1690
while (state.have < 19) {
1691
state.lens[order[state.have++]] = 0;
1692
}
1693
// We have separate tables & no pointers. 2 commented lines below not needed.
1694
//state.next = state.codes;
1695
//state.lencode = state.next;
1696
// Switch to use dynamic table
1697
state.lencode = state.lendyn;
1698
state.lenbits = 7;
1699
1700
opts = {bits: state.lenbits};
1701
ret = inflate_table(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts);
1702
state.lenbits = opts.bits;
1703
1704
if (ret) {
1705
strm.msg = 'invalid code lengths set';
1706
state.mode = BAD;
1707
break;
1708
}
1709
//Tracev((stderr, "inflate: code lengths ok\n"));
1710
state.have = 0;
1711
state.mode = CODELENS;
1712
/* falls through */
1713
case CODELENS:
1714
while (state.have < state.nlen + state.ndist) {
1715
for (;;) {
1716
here = state.lencode[hold & ((1 << state.lenbits) - 1)];/*BITS(state.lenbits)*/
1717
here_bits = here >>> 24;
1718
here_op = (here >>> 16) & 0xff;
1719
here_val = here & 0xffff;
1720
1721
if ((here_bits) <= bits) { break; }
1722
//--- PULLBYTE() ---//
1723
if (have === 0) { break inf_leave; }
1724
have--;
1725
hold += input[next++] << bits;
1726
bits += 8;
1727
//---//
1728
}
1729
if (here_val < 16) {
1730
//--- DROPBITS(here.bits) ---//
1731
hold >>>= here_bits;
1732
bits -= here_bits;
1733
//---//
1734
state.lens[state.have++] = here_val;
1735
}
1736
else {
1737
if (here_val === 16) {
1738
//=== NEEDBITS(here.bits + 2);
1739
n = here_bits + 2;
1740
while (bits < n) {
1741
if (have === 0) { break inf_leave; }
1742
have--;
1743
hold += input[next++] << bits;
1744
bits += 8;
1745
}
1746
//===//
1747
//--- DROPBITS(here.bits) ---//
1748
hold >>>= here_bits;
1749
bits -= here_bits;
1750
//---//
1751
if (state.have === 0) {
1752
strm.msg = 'invalid bit length repeat';
1753
state.mode = BAD;
1754
break;
1755
}
1756
len = state.lens[state.have - 1];
1757
copy = 3 + (hold & 0x03);//BITS(2);
1758
//--- DROPBITS(2) ---//
1759
hold >>>= 2;
1760
bits -= 2;
1761
//---//
1762
}
1763
else if (here_val === 17) {
1764
//=== NEEDBITS(here.bits + 3);
1765
n = here_bits + 3;
1766
while (bits < n) {
1767
if (have === 0) { break inf_leave; }
1768
have--;
1769
hold += input[next++] << bits;
1770
bits += 8;
1771
}
1772
//===//
1773
//--- DROPBITS(here.bits) ---//
1774
hold >>>= here_bits;
1775
bits -= here_bits;
1776
//---//
1777
len = 0;
1778
copy = 3 + (hold & 0x07);//BITS(3);
1779
//--- DROPBITS(3) ---//
1780
hold >>>= 3;
1781
bits -= 3;
1782
//---//
1783
}
1784
else {
1785
//=== NEEDBITS(here.bits + 7);
1786
n = here_bits + 7;
1787
while (bits < n) {
1788
if (have === 0) { break inf_leave; }
1789
have--;
1790
hold += input[next++] << bits;
1791
bits += 8;
1792
}
1793
//===//
1794
//--- DROPBITS(here.bits) ---//
1795
hold >>>= here_bits;
1796
bits -= here_bits;
1797
//---//
1798
len = 0;
1799
copy = 11 + (hold & 0x7f);//BITS(7);
1800
//--- DROPBITS(7) ---//
1801
hold >>>= 7;
1802
bits -= 7;
1803
//---//
1804
}
1805
if (state.have + copy > state.nlen + state.ndist) {
1806
strm.msg = 'invalid bit length repeat';
1807
state.mode = BAD;
1808
break;
1809
}
1810
while (copy--) {
1811
state.lens[state.have++] = len;
1812
}
1813
}
1814
}
1815
1816
/* handle error breaks in while */
1817
if (state.mode === BAD) { break; }
1818
1819
/* check for end-of-block code (better have one) */
1820
if (state.lens[256] === 0) {
1821
strm.msg = 'invalid code -- missing end-of-block';
1822
state.mode = BAD;
1823
break;
1824
}
1825
1826
/* build code tables -- note: do not change the lenbits or distbits
1827
values here (9 and 6) without reading the comments in inftrees.h
1828
concerning the ENOUGH constants, which depend on those values */
1829
state.lenbits = 9;
1830
1831
opts = {bits: state.lenbits};
1832
ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts);
1833
// We have separate tables & no pointers. 2 commented lines below not needed.
1834
// state.next_index = opts.table_index;
1835
state.lenbits = opts.bits;
1836
// state.lencode = state.next;
1837
1838
if (ret) {
1839
strm.msg = 'invalid literal/lengths set';
1840
state.mode = BAD;
1841
break;
1842
}
1843
1844
state.distbits = 6;
1845
//state.distcode.copy(state.codes);
1846
// Switch to use dynamic table
1847
state.distcode = state.distdyn;
1848
opts = {bits: state.distbits};
1849
ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);
1850
// We have separate tables & no pointers. 2 commented lines below not needed.
1851
// state.next_index = opts.table_index;
1852
state.distbits = opts.bits;
1853
// state.distcode = state.next;
1854
1855
if (ret) {
1856
strm.msg = 'invalid distances set';
1857
state.mode = BAD;
1858
break;
1859
}
1860
//Tracev((stderr, 'inflate: codes ok\n'));
1861
state.mode = LEN_;
1862
if (flush === Z_TREES) { break inf_leave; }
1863
/* falls through */
1864
case LEN_:
1865
state.mode = LEN;
1866
/* falls through */
1867
case LEN:
1868
if (have >= 6 && left >= 258) {
1869
//--- RESTORE() ---
1870
strm.next_out = put;
1871
strm.avail_out = left;
1872
strm.next_in = next;
1873
strm.avail_in = have;
1874
state.hold = hold;
1875
state.bits = bits;
1876
//---
1877
inflate_fast(strm, _out);
1878
//--- LOAD() ---
1879
put = strm.next_out;
1880
output = strm.output;
1881
left = strm.avail_out;
1882
next = strm.next_in;
1883
input = strm.input;
1884
have = strm.avail_in;
1885
hold = state.hold;
1886
bits = state.bits;
1887
//---
1888
1889
if (state.mode === TYPE) {
1890
state.back = -1;
1891
}
1892
break;
1893
}
1894
state.back = 0;
1895
for (;;) {
1896
here = state.lencode[hold & ((1 << state.lenbits) -1)]; /*BITS(state.lenbits)*/
1897
here_bits = here >>> 24;
1898
here_op = (here >>> 16) & 0xff;
1899
here_val = here & 0xffff;
1900
1901
if (here_bits <= bits) { break; }
1902
//--- PULLBYTE() ---//
1903
if (have === 0) { break inf_leave; }
1904
have--;
1905
hold += input[next++] << bits;
1906
bits += 8;
1907
//---//
1908
}
1909
if (here_op && (here_op & 0xf0) === 0) {
1910
last_bits = here_bits;
1911
last_op = here_op;
1912
last_val = here_val;
1913
for (;;) {
1914
here = state.lencode[last_val +
1915
((hold & ((1 << (last_bits + last_op)) -1))/*BITS(last.bits + last.op)*/ >> last_bits)];
1916
here_bits = here >>> 24;
1917
here_op = (here >>> 16) & 0xff;
1918
here_val = here & 0xffff;
1919
1920
if ((last_bits + here_bits) <= bits) { break; }
1921
//--- PULLBYTE() ---//
1922
if (have === 0) { break inf_leave; }
1923
have--;
1924
hold += input[next++] << bits;
1925
bits += 8;
1926
//---//
1927
}
1928
//--- DROPBITS(last.bits) ---//
1929
hold >>>= last_bits;
1930
bits -= last_bits;
1931
//---//
1932
state.back += last_bits;
1933
}
1934
//--- DROPBITS(here.bits) ---//
1935
hold >>>= here_bits;
1936
bits -= here_bits;
1937
//---//
1938
state.back += here_bits;
1939
state.length = here_val;
1940
if (here_op === 0) {
1941
//Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
1942
// "inflate: literal '%c'\n" :
1943
// "inflate: literal 0x%02x\n", here.val));
1944
state.mode = LIT;
1945
break;
1946
}
1947
if (here_op & 32) {
1948
//Tracevv((stderr, "inflate: end of block\n"));
1949
state.back = -1;
1950
state.mode = TYPE;
1951
break;
1952
}
1953
if (here_op & 64) {
1954
strm.msg = 'invalid literal/length code';
1955
state.mode = BAD;
1956
break;
1957
}
1958
state.extra = here_op & 15;
1959
state.mode = LENEXT;
1960
/* falls through */
1961
case LENEXT:
1962
if (state.extra) {
1963
//=== NEEDBITS(state.extra);
1964
n = state.extra;
1965
while (bits < n) {
1966
if (have === 0) { break inf_leave; }
1967
have--;
1968
hold += input[next++] << bits;
1969
bits += 8;
1970
}
1971
//===//
1972
state.length += hold & ((1 << state.extra) -1)/*BITS(state.extra)*/;
1973
//--- DROPBITS(state.extra) ---//
1974
hold >>>= state.extra;
1975
bits -= state.extra;
1976
//---//
1977
state.back += state.extra;
1978
}
1979
//Tracevv((stderr, "inflate: length %u\n", state.length));
1980
state.was = state.length;
1981
state.mode = DIST;
1982
/* falls through */
1983
case DIST:
1984
for (;;) {
1985
here = state.distcode[hold & ((1 << state.distbits) -1)];/*BITS(state.distbits)*/
1986
here_bits = here >>> 24;
1987
here_op = (here >>> 16) & 0xff;
1988
here_val = here & 0xffff;
1989
1990
if ((here_bits) <= bits) { break; }
1991
//--- PULLBYTE() ---//
1992
if (have === 0) { break inf_leave; }
1993
have--;
1994
hold += input[next++] << bits;
1995
bits += 8;
1996
//---//
1997
}
1998
if ((here_op & 0xf0) === 0) {
1999
last_bits = here_bits;
2000
last_op = here_op;
2001
last_val = here_val;
2002
for (;;) {
2003
here = state.distcode[last_val +
2004
((hold & ((1 << (last_bits + last_op)) -1))/*BITS(last.bits + last.op)*/ >> last_bits)];
2005
here_bits = here >>> 24;
2006
here_op = (here >>> 16) & 0xff;
2007
here_val = here & 0xffff;
2008
2009
if ((last_bits + here_bits) <= bits) { break; }
2010
//--- PULLBYTE() ---//
2011
if (have === 0) { break inf_leave; }
2012
have--;
2013
hold += input[next++] << bits;
2014
bits += 8;
2015
//---//
2016
}
2017
//--- DROPBITS(last.bits) ---//
2018
hold >>>= last_bits;
2019
bits -= last_bits;
2020
//---//
2021
state.back += last_bits;
2022
}
2023
//--- DROPBITS(here.bits) ---//
2024
hold >>>= here_bits;
2025
bits -= here_bits;
2026
//---//
2027
state.back += here_bits;
2028
if (here_op & 64) {
2029
strm.msg = 'invalid distance code';
2030
state.mode = BAD;
2031
break;
2032
}
2033
state.offset = here_val;
2034
state.extra = (here_op) & 15;
2035
state.mode = DISTEXT;
2036
/* falls through */
2037
case DISTEXT:
2038
if (state.extra) {
2039
//=== NEEDBITS(state.extra);
2040
n = state.extra;
2041
while (bits < n) {
2042
if (have === 0) { break inf_leave; }
2043
have--;
2044
hold += input[next++] << bits;
2045
bits += 8;
2046
}
2047
//===//
2048
state.offset += hold & ((1 << state.extra) -1)/*BITS(state.extra)*/;
2049
//--- DROPBITS(state.extra) ---//
2050
hold >>>= state.extra;
2051
bits -= state.extra;
2052
//---//
2053
state.back += state.extra;
2054
}
2055
//#ifdef INFLATE_STRICT
2056
if (state.offset > state.dmax) {
2057
strm.msg = 'invalid distance too far back';
2058
state.mode = BAD;
2059
break;
2060
}
2061
//#endif
2062
//Tracevv((stderr, "inflate: distance %u\n", state.offset));
2063
state.mode = MATCH;
2064
/* falls through */
2065
case MATCH:
2066
if (left === 0) { break inf_leave; }
2067
copy = _out - left;
2068
if (state.offset > copy) { /* copy from window */
2069
copy = state.offset - copy;
2070
if (copy > state.whave) {
2071
if (state.sane) {
2072
strm.msg = 'invalid distance too far back';
2073
state.mode = BAD;
2074
break;
2075
}
2076
// (!) This block is disabled in zlib defailts,
2077
// don't enable it for binary compatibility
2078
//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
2079
// Trace((stderr, "inflate.c too far\n"));
2080
// copy -= state.whave;
2081
// if (copy > state.length) { copy = state.length; }
2082
// if (copy > left) { copy = left; }
2083
// left -= copy;
2084
// state.length -= copy;
2085
// do {
2086
// output[put++] = 0;
2087
// } while (--copy);
2088
// if (state.length === 0) { state.mode = LEN; }
2089
// break;
2090
//#endif
2091
}
2092
if (copy > state.wnext) {
2093
copy -= state.wnext;
2094
from = state.wsize - copy;
2095
}
2096
else {
2097
from = state.wnext - copy;
2098
}
2099
if (copy > state.length) { copy = state.length; }
2100
from_source = state.window;
2101
}
2102
else { /* copy from output */
2103
from_source = output;
2104
from = put - state.offset;
2105
copy = state.length;
2106
}
2107
if (copy > left) { copy = left; }
2108
left -= copy;
2109
state.length -= copy;
2110
do {
2111
output[put++] = from_source[from++];
2112
} while (--copy);
2113
if (state.length === 0) { state.mode = LEN; }
2114
break;
2115
case LIT:
2116
if (left === 0) { break inf_leave; }
2117
output[put++] = state.length;
2118
left--;
2119
state.mode = LEN;
2120
break;
2121
case CHECK:
2122
if (state.wrap) {
2123
//=== NEEDBITS(32);
2124
while (bits < 32) {
2125
if (have === 0) { break inf_leave; }
2126
have--;
2127
// Use '|' insdead of '+' to make sure that result is signed
2128
hold |= input[next++] << bits;
2129
bits += 8;
2130
}
2131
//===//
2132
_out -= left;
2133
strm.total_out += _out;
2134
state.total += _out;
2135
if (_out) {
2136
strm.adler = state.check =
2137
/*UPDATE(state.check, put - _out, _out);*/
2138
(state.flags ? crc32(state.check, output, _out, put - _out) : adler32(state.check, output, _out, put - _out));
2139
2140
}
2141
_out = left;
2142
// NB: crc32 stored as signed 32-bit int, ZSWAP32 returns signed too
2143
if ((state.flags ? hold : ZSWAP32(hold)) !== state.check) {
2144
strm.msg = 'incorrect data check';
2145
state.mode = BAD;
2146
break;
2147
}
2148
//=== INITBITS();
2149
hold = 0;
2150
bits = 0;
2151
//===//
2152
//Tracev((stderr, "inflate: check matches trailer\n"));
2153
}
2154
state.mode = LENGTH;
2155
/* falls through */
2156
case LENGTH:
2157
if (state.wrap && state.flags) {
2158
//=== NEEDBITS(32);
2159
while (bits < 32) {
2160
if (have === 0) { break inf_leave; }
2161
have--;
2162
hold += input[next++] << bits;
2163
bits += 8;
2164
}
2165
//===//
2166
if (hold !== (state.total & 0xffffffff)) {
2167
strm.msg = 'incorrect length check';
2168
state.mode = BAD;
2169
break;
2170
}
2171
//=== INITBITS();
2172
hold = 0;
2173
bits = 0;
2174
//===//
2175
//Tracev((stderr, "inflate: length matches trailer\n"));
2176
}
2177
state.mode = DONE;
2178
/* falls through */
2179
case DONE:
2180
ret = Z_STREAM_END;
2181
break inf_leave;
2182
case BAD:
2183
ret = Z_DATA_ERROR;
2184
break inf_leave;
2185
case MEM:
2186
return Z_MEM_ERROR;
2187
case SYNC:
2188
/* falls through */
2189
default:
2190
return Z_STREAM_ERROR;
2191
}
2192
}
2193
2194
// inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave"
2195
2196
/*
2197
Return from inflate(), updating the total counts and the check value.
2198
If there was no progress during the inflate() call, return a buffer
2199
error. Call updatewindow() to create and/or update the window state.
2200
Note: a memory error from inflate() is non-recoverable.
2201
*/
2202
2203
//--- RESTORE() ---
2204
strm.next_out = put;
2205
strm.avail_out = left;
2206
strm.next_in = next;
2207
strm.avail_in = have;
2208
state.hold = hold;
2209
state.bits = bits;
2210
//---
2211
2212
if (state.wsize || (_out !== strm.avail_out && state.mode < BAD &&
2213
(state.mode < CHECK || flush !== Z_FINISH))) {
2214
if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) {
2215
state.mode = MEM;
2216
return Z_MEM_ERROR;
2217
}
2218
}
2219
_in -= strm.avail_in;
2220
_out -= strm.avail_out;
2221
strm.total_in += _in;
2222
strm.total_out += _out;
2223
state.total += _out;
2224
if (state.wrap && _out) {
2225
strm.adler = state.check = /*UPDATE(state.check, strm.next_out - _out, _out);*/
2226
(state.flags ? crc32(state.check, output, _out, strm.next_out - _out) : adler32(state.check, output, _out, strm.next_out - _out));
2227
}
2228
strm.data_type = state.bits + (state.last ? 64 : 0) +
2229
(state.mode === TYPE ? 128 : 0) +
2230
(state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);
2231
if (((_in === 0 && _out === 0) || flush === Z_FINISH) && ret === Z_OK) {
2232
ret = Z_BUF_ERROR;
2233
}
2234
return ret;
2235
}
2236
2237
function inflateEnd(strm) {
2238
2239
if (!strm || !strm.state /*|| strm->zfree == (free_func)0*/) {
2240
return Z_STREAM_ERROR;
2241
}
2242
2243
var state = strm.state;
2244
if (state.window) {
2245
state.window = null;
2246
}
2247
strm.state = null;
2248
return Z_OK;
2249
}
2250
2251
function inflateGetHeader(strm, head) {
2252
var state;
2253
2254
/* check state */
2255
if (!strm || !strm.state) { return Z_STREAM_ERROR; }
2256
state = strm.state;
2257
if ((state.wrap & 2) === 0) { return Z_STREAM_ERROR; }
2258
2259
/* save header structure */
2260
state.head = head;
2261
head.done = false;
2262
return Z_OK;
2263
}
2264
2265
2266
exports.inflateReset = inflateReset;
2267
exports.inflateReset2 = inflateReset2;
2268
exports.inflateResetKeep = inflateResetKeep;
2269
exports.inflateInit = inflateInit;
2270
exports.inflateInit2 = inflateInit2;
2271
exports.inflate = inflate;
2272
exports.inflateEnd = inflateEnd;
2273
exports.inflateGetHeader = inflateGetHeader;
2274
exports.inflateInfo = 'pako inflate (from Nodeca project)';
2275
2276
/* Not implemented
2277
exports.inflateCopy = inflateCopy;
2278
exports.inflateGetDictionary = inflateGetDictionary;
2279
exports.inflateMark = inflateMark;
2280
exports.inflatePrime = inflatePrime;
2281
exports.inflateSetDictionary = inflateSetDictionary;
2282
exports.inflateSync = inflateSync;
2283
exports.inflateSyncPoint = inflateSyncPoint;
2284
exports.inflateUndermine = inflateUndermine;
2285
*/
2286
},{"../utils/common":1,"./adler32":3,"./crc32":5,"./inffast":7,"./inftrees":9}],9:[function(require,module,exports){
2287
'use strict';
2288
2289
2290
var utils = require('../utils/common');
2291
2292
var MAXBITS = 15;
2293
var ENOUGH_LENS = 852;
2294
var ENOUGH_DISTS = 592;
2295
//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
2296
2297
var CODES = 0;
2298
var LENS = 1;
2299
var DISTS = 2;
2300
2301
var lbase = [ /* Length codes 257..285 base */
2302
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
2303
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
2304
];
2305
2306
var lext = [ /* Length codes 257..285 extra */
2307
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
2308
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78
2309
];
2310
2311
var dbase = [ /* Distance codes 0..29 base */
2312
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
2313
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
2314
8193, 12289, 16385, 24577, 0, 0
2315
];
2316
2317
var dext = [ /* Distance codes 0..29 extra */
2318
16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
2319
23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
2320
28, 28, 29, 29, 64, 64
2321
];
2322
2323
module.exports = function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts)
2324
{
2325
var bits = opts.bits;
2326
//here = opts.here; /* table entry for duplication */
2327
2328
var len = 0; /* a code's length in bits */
2329
var sym = 0; /* index of code symbols */
2330
var min = 0, max = 0; /* minimum and maximum code lengths */
2331
var root = 0; /* number of index bits for root table */
2332
var curr = 0; /* number of index bits for current table */
2333
var drop = 0; /* code bits to drop for sub-table */
2334
var left = 0; /* number of prefix codes available */
2335
var used = 0; /* code entries in table used */
2336
var huff = 0; /* Huffman code */
2337
var incr; /* for incrementing code, index */
2338
var fill; /* index for replicating entries */
2339
var low; /* low bits for current root entry */
2340
var mask; /* mask for low root bits */
2341
var next; /* next available space in table */
2342
var base = null; /* base value table to use */
2343
var base_index = 0;
2344
// var shoextra; /* extra bits table to use */
2345
var end; /* use base and extra for symbol > end */
2346
var count = new utils.Buf16(MAXBITS+1); //[MAXBITS+1]; /* number of codes of each length */
2347
var offs = new utils.Buf16(MAXBITS+1); //[MAXBITS+1]; /* offsets in table for each length */
2348
var extra = null;
2349
var extra_index = 0;
2350
2351
var here_bits, here_op, here_val;
2352
2353
/*
2354
Process a set of code lengths to create a canonical Huffman code. The
2355
code lengths are lens[0..codes-1]. Each length corresponds to the
2356
symbols 0..codes-1. The Huffman code is generated by first sorting the
2357
symbols by length from short to long, and retaining the symbol order
2358
for codes with equal lengths. Then the code starts with all zero bits
2359
for the first code of the shortest length, and the codes are integer
2360
increments for the same length, and zeros are appended as the length
2361
increases. For the deflate format, these bits are stored backwards
2362
from their more natural integer increment ordering, and so when the
2363
decoding tables are built in the large loop below, the integer codes
2364
are incremented backwards.
2365
2366
This routine assumes, but does not check, that all of the entries in
2367
lens[] are in the range 0..MAXBITS. The caller must assure this.
2368
1..MAXBITS is interpreted as that code length. zero means that that
2369
symbol does not occur in this code.
2370
2371
The codes are sorted by computing a count of codes for each length,
2372
creating from that a table of starting indices for each length in the
2373
sorted table, and then entering the symbols in order in the sorted
2374
table. The sorted table is work[], with that space being provided by
2375
the caller.
2376
2377
The length counts are used for other purposes as well, i.e. finding
2378
the minimum and maximum length codes, determining if there are any
2379
codes at all, checking for a valid set of lengths, and looking ahead
2380
at length counts to determine sub-table sizes when building the
2381
decoding tables.
2382
*/
2383
2384
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
2385
for (len = 0; len <= MAXBITS; len++) {
2386
count[len] = 0;
2387
}
2388
for (sym = 0; sym < codes; sym++) {
2389
count[lens[lens_index + sym]]++;
2390
}
2391
2392
/* bound code lengths, force root to be within code lengths */
2393
root = bits;
2394
for (max = MAXBITS; max >= 1; max--) {
2395
if (count[max] !== 0) { break; }
2396
}
2397
if (root > max) {
2398
root = max;
2399
}
2400
if (max === 0) { /* no symbols to code at all */
2401
//table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */
2402
//table.bits[opts.table_index] = 1; //here.bits = (var char)1;
2403
//table.val[opts.table_index++] = 0; //here.val = (var short)0;
2404
table[table_index++] = (1 << 24) | (64 << 16) | 0;
2405
2406
2407
//table.op[opts.table_index] = 64;
2408
//table.bits[opts.table_index] = 1;
2409
//table.val[opts.table_index++] = 0;
2410
table[table_index++] = (1 << 24) | (64 << 16) | 0;
2411
2412
opts.bits = 1;
2413
return 0; /* no symbols, but wait for decoding to report error */
2414
}
2415
for (min = 1; min < max; min++) {
2416
if (count[min] !== 0) { break; }
2417
}
2418
if (root < min) {
2419
root = min;
2420
}
2421
2422
/* check for an over-subscribed or incomplete set of lengths */
2423
left = 1;
2424
for (len = 1; len <= MAXBITS; len++) {
2425
left <<= 1;
2426
left -= count[len];
2427
if (left < 0) {
2428
return -1;
2429
} /* over-subscribed */
2430
}
2431
if (left > 0 && (type === CODES || max !== 1)) {
2432
return -1; /* incomplete set */
2433
}
2434
2435
/* generate offsets into symbol table for each length for sorting */
2436
offs[1] = 0;
2437
for (len = 1; len < MAXBITS; len++) {
2438
offs[len + 1] = offs[len] + count[len];
2439
}
2440
2441
/* sort symbols by length, by symbol order within each length */
2442
for (sym = 0; sym < codes; sym++) {
2443
if (lens[lens_index + sym] !== 0) {
2444
work[offs[lens[lens_index + sym]]++] = sym;
2445
}
2446
}
2447
2448
/*
2449
Create and fill in decoding tables. In this loop, the table being
2450
filled is at next and has curr index bits. The code being used is huff
2451
with length len. That code is converted to an index by dropping drop
2452
bits off of the bottom. For codes where len is less than drop + curr,
2453
those top drop + curr - len bits are incremented through all values to
2454
fill the table with replicated entries.
2455
2456
root is the number of index bits for the root table. When len exceeds
2457
root, sub-tables are created pointed to by the root entry with an index
2458
of the low root bits of huff. This is saved in low to check for when a
2459
new sub-table should be started. drop is zero when the root table is
2460
being filled, and drop is root when sub-tables are being filled.
2461
2462
When a new sub-table is needed, it is necessary to look ahead in the
2463
code lengths to determine what size sub-table is needed. The length
2464
counts are used for this, and so count[] is decremented as codes are
2465
entered in the tables.
2466
2467
used keeps track of how many table entries have been allocated from the
2468
provided *table space. It is checked for LENS and DIST tables against
2469
the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
2470
the initial root table size constants. See the comments in inftrees.h
2471
for more information.
2472
2473
sym increments through all symbols, and the loop terminates when
2474
all codes of length max, i.e. all codes, have been processed. This
2475
routine permits incomplete codes, so another loop after this one fills
2476
in the rest of the decoding tables with invalid code markers.
2477
*/
2478
2479
/* set up for code type */
2480
// poor man optimization - use if-else instead of switch,
2481
// to avoid deopts in old v8
2482
if (type === CODES) {
2483
base = extra = work; /* dummy value--not used */
2484
end = 19;
2485
} else if (type === LENS) {
2486
base = lbase;
2487
base_index -= 257;
2488
extra = lext;
2489
extra_index -= 257;
2490
end = 256;
2491
} else { /* DISTS */
2492
base = dbase;
2493
extra = dext;
2494
end = -1;
2495
}
2496
2497
/* initialize opts for loop */
2498
huff = 0; /* starting code */
2499
sym = 0; /* starting code symbol */
2500
len = min; /* starting code length */
2501
next = table_index; /* current table to fill in */
2502
curr = root; /* current table index bits */
2503
drop = 0; /* current bits to drop from code for index */
2504
low = -1; /* trigger new sub-table when len > root */
2505
used = 1 << root; /* use root table entries */
2506
mask = used - 1; /* mask for comparing low */
2507
2508
/* check available table space */
2509
if ((type === LENS && used > ENOUGH_LENS) ||
2510
(type === DISTS && used > ENOUGH_DISTS)) {
2511
return 1;
2512
}
2513
2514
var i=0;
2515
/* process all codes and make table entries */
2516
for (;;) {
2517
i++;
2518
/* create table entry */
2519
here_bits = len - drop;
2520
if (work[sym] < end) {
2521
here_op = 0;
2522
here_val = work[sym];
2523
}
2524
else if (work[sym] > end) {
2525
here_op = extra[extra_index + work[sym]];
2526
here_val = base[base_index + work[sym]];
2527
}
2528
else {
2529
here_op = 32 + 64; /* end of block */
2530
here_val = 0;
2531
}
2532
2533
/* replicate for those indices with low len bits equal to huff */
2534
incr = 1 << (len - drop);
2535
fill = 1 << curr;
2536
min = fill; /* save offset to next table */
2537
do {
2538
fill -= incr;
2539
table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0;
2540
} while (fill !== 0);
2541
2542
/* backwards increment the len-bit code huff */
2543
incr = 1 << (len - 1);
2544
while (huff & incr) {
2545
incr >>= 1;
2546
}
2547
if (incr !== 0) {
2548
huff &= incr - 1;
2549
huff += incr;
2550
} else {
2551
huff = 0;
2552
}
2553
2554
/* go to next symbol, update count, len */
2555
sym++;
2556
if (--count[len] === 0) {
2557
if (len === max) { break; }
2558
len = lens[lens_index + work[sym]];
2559
}
2560
2561
/* create new sub-table if needed */
2562
if (len > root && (huff & mask) !== low) {
2563
/* if first time, transition to sub-tables */
2564
if (drop === 0) {
2565
drop = root;
2566
}
2567
2568
/* increment past last table */
2569
next += min; /* here min is 1 << curr */
2570
2571
/* determine length of next table */
2572
curr = len - drop;
2573
left = 1 << curr;
2574
while (curr + drop < max) {
2575
left -= count[curr + drop];
2576
if (left <= 0) { break; }
2577
curr++;
2578
left <<= 1;
2579
}
2580
2581
/* check for enough space */
2582
used += 1 << curr;
2583
if ((type === LENS && used > ENOUGH_LENS) ||
2584
(type === DISTS && used > ENOUGH_DISTS)) {
2585
return 1;
2586
}
2587
2588
/* point entry in root table to sub-table */
2589
low = huff & mask;
2590
/*table.op[low] = curr;
2591
table.bits[low] = root;
2592
table.val[low] = next - opts.table_index;*/
2593
table[low] = (root << 24) | (curr << 16) | (next - table_index) |0;
2594
}
2595
}
2596
2597
/* fill in remaining table entry if code is incomplete (guaranteed to have
2598
at most one remaining entry, since if the code is incomplete, the
2599
maximum code length that was allowed to get this far is one bit) */
2600
if (huff !== 0) {
2601
//table.op[next + huff] = 64; /* invalid code marker */
2602
//table.bits[next + huff] = len - drop;
2603
//table.val[next + huff] = 0;
2604
table[next + huff] = ((len - drop) << 24) | (64 << 16) |0;
2605
}
2606
2607
/* set return parameters */
2608
//opts.table_index += used;
2609
opts.bits = root;
2610
return 0;
2611
};
2612
2613
},{"../utils/common":1}],10:[function(require,module,exports){
2614
'use strict';
2615
2616
module.exports = {
2617
'2': 'need dictionary', /* Z_NEED_DICT 2 */
2618
'1': 'stream end', /* Z_STREAM_END 1 */
2619
'0': '', /* Z_OK 0 */
2620
'-1': 'file error', /* Z_ERRNO (-1) */
2621
'-2': 'stream error', /* Z_STREAM_ERROR (-2) */
2622
'-3': 'data error', /* Z_DATA_ERROR (-3) */
2623
'-4': 'insufficient memory', /* Z_MEM_ERROR (-4) */
2624
'-5': 'buffer error', /* Z_BUF_ERROR (-5) */
2625
'-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */
2626
};
2627
},{}],11:[function(require,module,exports){
2628
'use strict';
2629
2630
2631
function ZStream() {
2632
/* next input byte */
2633
this.input = null; // JS specific, because we have no pointers
2634
this.next_in = 0;
2635
/* number of bytes available at input */
2636
this.avail_in = 0;
2637
/* total number of input bytes read so far */
2638
this.total_in = 0;
2639
/* next output byte should be put there */
2640
this.output = null; // JS specific, because we have no pointers
2641
this.next_out = 0;
2642
/* remaining free space at output */
2643
this.avail_out = 0;
2644
/* total number of bytes output so far */
2645
this.total_out = 0;
2646
/* last error message, NULL if no error */
2647
this.msg = ''/*Z_NULL*/;
2648
/* not visible by applications */
2649
this.state = null;
2650
/* best guess about the data type: binary or text */
2651
this.data_type = 2/*Z_UNKNOWN*/;
2652
/* adler32 value of the uncompressed data */
2653
this.adler = 0;
2654
}
2655
2656
module.exports = ZStream;
2657
},{}],"/lib/inflate.js":[function(require,module,exports){
2658
'use strict';
2659
2660
2661
var zlib_inflate = require('./zlib/inflate.js');
2662
var utils = require('./utils/common');
2663
var strings = require('./utils/strings');
2664
var c = require('./zlib/constants');
2665
var msg = require('./zlib/messages');
2666
var zstream = require('./zlib/zstream');
2667
var gzheader = require('./zlib/gzheader');
2668
2669
var toString = Object.prototype.toString;
2670
2671
/**
2672
* class Inflate
2673
*
2674
* Generic JS-style wrapper for zlib calls. If you don't need
2675
* streaming behaviour - use more simple functions: [[inflate]]
2676
* and [[inflateRaw]].
2677
**/
2678
2679
/* internal
2680
* inflate.chunks -> Array
2681
*
2682
* Chunks of output data, if [[Inflate#onData]] not overriden.
2683
**/
2684
2685
/**
2686
* Inflate.result -> Uint8Array|Array|String
2687
*
2688
* Uncompressed result, generated by default [[Inflate#onData]]
2689
* and [[Inflate#onEnd]] handlers. Filled after you push last chunk
2690
* (call [[Inflate#push]] with `Z_FINISH` / `true` param).
2691
**/
2692
2693
/**
2694
* Inflate.err -> Number
2695
*
2696
* Error code after inflate finished. 0 (Z_OK) on success.
2697
* Should be checked if broken data possible.
2698
**/
2699
2700
/**
2701
* Inflate.msg -> String
2702
*
2703
* Error message, if [[Inflate.err]] != 0
2704
**/
2705
2706
2707
/**
2708
* new Inflate(options)
2709
* - options (Object): zlib inflate options.
2710
*
2711
* Creates new inflator instance with specified params. Throws exception
2712
* on bad params. Supported options:
2713
*
2714
* - `windowBits`
2715
*
2716
* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
2717
* for more information on these.
2718
*
2719
* Additional options, for internal needs:
2720
*
2721
* - `chunkSize` - size of generated data chunks (16K by default)
2722
* - `raw` (Boolean) - do raw inflate
2723
* - `to` (String) - if equal to 'string', then result will be converted
2724
* from utf8 to utf16 (javascript) string. When string output requested,
2725
* chunk length can differ from `chunkSize`, depending on content.
2726
*
2727
* By default, when no options set, autodetect deflate/gzip data format via
2728
* wrapper header.
2729
*
2730
* ##### Example:
2731
*
2732
* ```javascript
2733
* var pako = require('pako')
2734
* , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
2735
* , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
2736
*
2737
* var inflate = new pako.Inflate({ level: 3});
2738
*
2739
* inflate.push(chunk1, false);
2740
* inflate.push(chunk2, true); // true -> last chunk
2741
*
2742
* if (inflate.err) { throw new Error(inflate.err); }
2743
*
2744
* console.log(inflate.result);
2745
* ```
2746
**/
2747
var Inflate = function(options) {
2748
2749
this.options = utils.assign({
2750
chunkSize: 16384,
2751
windowBits: 0,
2752
to: ''
2753
}, options || {});
2754
2755
var opt = this.options;
2756
2757
// Force window size for `raw` data, if not set directly,
2758
// because we have no header for autodetect.
2759
if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
2760
opt.windowBits = -opt.windowBits;
2761
if (opt.windowBits === 0) { opt.windowBits = -15; }
2762
}
2763
2764
// If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
2765
if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&
2766
!(options && options.windowBits)) {
2767
opt.windowBits += 32;
2768
}
2769
2770
// Gzip header has no info about windows size, we can do autodetect only
2771
// for deflate. So, if window size not set, force it to max when gzip possible
2772
if ((opt.windowBits > 15) && (opt.windowBits < 48)) {
2773
// bit 3 (16) -> gzipped data
2774
// bit 4 (32) -> autodetect gzip/deflate
2775
if ((opt.windowBits & 15) === 0) {
2776
opt.windowBits |= 15;
2777
}
2778
}
2779
2780
this.err = 0; // error code, if happens (0 = Z_OK)
2781
this.msg = ''; // error message
2782
this.ended = false; // used to avoid multiple onEnd() calls
2783
this.chunks = []; // chunks of compressed data
2784
2785
this.strm = new zstream();
2786
this.strm.avail_out = 0;
2787
2788
var status = zlib_inflate.inflateInit2(
2789
this.strm,
2790
opt.windowBits
2791
);
2792
2793
if (status !== c.Z_OK) {
2794
throw new Error(msg[status]);
2795
}
2796
2797
this.header = new gzheader();
2798
2799
zlib_inflate.inflateGetHeader(this.strm, this.header);
2800
};
2801
2802
/**
2803
* Inflate#push(data[, mode]) -> Boolean
2804
* - data (Uint8Array|Array|ArrayBuffer|String): input data
2805
* - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
2806
* See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
2807
*
2808
* Sends input data to inflate pipe, generating [[Inflate#onData]] calls with
2809
* new output chunks. Returns `true` on success. The last data block must have
2810
* mode Z_FINISH (or `true`). That flush internal pending buffers and call
2811
* [[Inflate#onEnd]].
2812
*
2813
* On fail call [[Inflate#onEnd]] with error code and return false.
2814
*
2815
* We strongly recommend to use `Uint8Array` on input for best speed (output
2816
* format is detected automatically). Also, don't skip last param and always
2817
* use the same type in your code (boolean or number). That will improve JS speed.
2818
*
2819
* For regular `Array`-s make sure all elements are [0..255].
2820
*
2821
* ##### Example
2822
*
2823
* ```javascript
2824
* push(chunk, false); // push one of data chunks
2825
* ...
2826
* push(chunk, true); // push last chunk
2827
* ```
2828
**/
2829
Inflate.prototype.push = function(data, mode) {
2830
var strm = this.strm;
2831
var chunkSize = this.options.chunkSize;
2832
var status, _mode;
2833
var next_out_utf8, tail, utf8str;
2834
2835
if (this.ended) { return false; }
2836
_mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH);
2837
2838
// Convert data if needed
2839
if (typeof data === 'string') {
2840
// Only binary strings can be decompressed on practice
2841
strm.input = strings.binstring2buf(data);
2842
} else if (toString.call(data) === '[object ArrayBuffer]') {
2843
strm.input = new Uint8Array(data);
2844
} else {
2845
strm.input = data;
2846
}
2847
2848
strm.next_in = 0;
2849
strm.avail_in = strm.input.length;
2850
2851
do {
2852
if (strm.avail_out === 0) {
2853
strm.output = new utils.Buf8(chunkSize);
2854
strm.next_out = 0;
2855
strm.avail_out = chunkSize;
2856
}
2857
2858
status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH); /* no bad return value */
2859
2860
if (status !== c.Z_STREAM_END && status !== c.Z_OK) {
2861
this.onEnd(status);
2862
this.ended = true;
2863
return false;
2864
}
2865
2866
if (strm.next_out) {
2867
if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && _mode === c.Z_FINISH)) {
2868
2869
if (this.options.to === 'string') {
2870
2871
next_out_utf8 = strings.utf8border(strm.output, strm.next_out);
2872
2873
tail = strm.next_out - next_out_utf8;
2874
utf8str = strings.buf2string(strm.output, next_out_utf8);
2875
2876
// move tail
2877
strm.next_out = tail;
2878
strm.avail_out = chunkSize - tail;
2879
if (tail) { utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0); }
2880
2881
this.onData(utf8str);
2882
2883
} else {
2884
this.onData(utils.shrinkBuf(strm.output, strm.next_out));
2885
}
2886
}
2887
}
2888
} while ((strm.avail_in > 0) && status !== c.Z_STREAM_END);
2889
2890
if (status === c.Z_STREAM_END) {
2891
_mode = c.Z_FINISH;
2892
}
2893
// Finalize on the last chunk.
2894
if (_mode === c.Z_FINISH) {
2895
status = zlib_inflate.inflateEnd(this.strm);
2896
this.onEnd(status);
2897
this.ended = true;
2898
return status === c.Z_OK;
2899
}
2900
2901
return true;
2902
};
2903
2904
2905
/**
2906
* Inflate#onData(chunk) -> Void
2907
* - chunk (Uint8Array|Array|String): ouput data. Type of array depends
2908
* on js engine support. When string output requested, each chunk
2909
* will be string.
2910
*
2911
* By default, stores data blocks in `chunks[]` property and glue
2912
* those in `onEnd`. Override this handler, if you need another behaviour.
2913
**/
2914
Inflate.prototype.onData = function(chunk) {
2915
this.chunks.push(chunk);
2916
};
2917
2918
2919
/**
2920
* Inflate#onEnd(status) -> Void
2921
* - status (Number): inflate status. 0 (Z_OK) on success,
2922
* other if not.
2923
*
2924
* Called once after you tell inflate that input stream complete
2925
* or error happenned. By default - join collected chunks,
2926
* free memory and fill `results` / `err` properties.
2927
**/
2928
Inflate.prototype.onEnd = function(status) {
2929
// On success - join
2930
if (status === c.Z_OK) {
2931
if (this.options.to === 'string') {
2932
// Glue & convert here, until we teach pako to send
2933
// utf8 alligned strings to onData
2934
this.result = this.chunks.join('');
2935
} else {
2936
this.result = utils.flattenChunks(this.chunks);
2937
}
2938
}
2939
this.chunks = [];
2940
this.err = status;
2941
this.msg = this.strm.msg;
2942
};
2943
2944
2945
/**
2946
* inflate(data[, options]) -> Uint8Array|Array|String
2947
* - data (Uint8Array|Array|String): input data to decompress.
2948
* - options (Object): zlib inflate options.
2949
*
2950
* Decompress `data` with inflate/ungzip and `options`. Autodetect
2951
* format via wrapper header by default. That's why we don't provide
2952
* separate `ungzip` method.
2953
*
2954
* Supported options are:
2955
*
2956
* - windowBits
2957
*
2958
* [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
2959
* for more information.
2960
*
2961
* Sugar (options):
2962
*
2963
* - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
2964
* negative windowBits implicitly.
2965
* - `to` (String) - if equal to 'string', then result will be converted
2966
* from utf8 to utf16 (javascript) string. When string output requested,
2967
* chunk length can differ from `chunkSize`, depending on content.
2968
*
2969
*
2970
* ##### Example:
2971
*
2972
* ```javascript
2973
* var pako = require('pako')
2974
* , input = pako.deflate([1,2,3,4,5,6,7,8,9])
2975
* , output;
2976
*
2977
* try {
2978
* output = pako.inflate(input);
2979
* } catch (err)
2980
* console.log(err);
2981
* }
2982
* ```
2983
**/
2984
function inflate(input, options) {
2985
var inflator = new Inflate(options);
2986
2987
inflator.push(input, true);
2988
2989
// That will never happens, if you don't cheat with options :)
2990
if (inflator.err) { throw inflator.msg; }
2991
2992
return inflator.result;
2993
}
2994
2995
2996
/**
2997
* inflateRaw(data[, options]) -> Uint8Array|Array|String
2998
* - data (Uint8Array|Array|String): input data to decompress.
2999
* - options (Object): zlib inflate options.
3000
*
3001
* The same as [[inflate]], but creates raw data, without wrapper
3002
* (header and adler32 crc).
3003
**/
3004
function inflateRaw(input, options) {
3005
options = options || {};
3006
options.raw = true;
3007
return inflate(input, options);
3008
}
3009
3010
3011
/**
3012
* ungzip(data[, options]) -> Uint8Array|Array|String
3013
* - data (Uint8Array|Array|String): input data to decompress.
3014
* - options (Object): zlib inflate options.
3015
*
3016
* Just shortcut to [[inflate]], because it autodetects format
3017
* by header.content. Done for convenience.
3018
**/
3019
3020
3021
exports.Inflate = Inflate;
3022
exports.inflate = inflate;
3023
exports.inflateRaw = inflateRaw;
3024
exports.ungzip = inflate;
3025
3026
},{"./utils/common":1,"./utils/strings":2,"./zlib/constants":4,"./zlib/gzheader":6,"./zlib/inflate.js":8,"./zlib/messages":10,"./zlib/zstream":11}]},{},[])("/lib/inflate.js")
3027
});
3028