1/* zlib-inflate.js -- JavaScript implementation for the zlib inflate.
3 LastModified: Apr 12 2012
4 Copyright (C) 2012 Masanao Izumo <iz@onicos.co.jp>
6 This library is one of the JavaScript zlib implementation.
7 Some API's are modified from the original.
8 Only inflate API is implemented.
10 The original copyright notice (zlib 1.2.6):
12 Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler
14 This software is provided 'as-is', without any express or implied
15 warranty. In no event will the authors be held liable for any damages
16 arising from the use of this software.
18 Permission is granted to anyone to use this software for any purpose,
19 including commercial applications, and to alter it and redistribute it
20 freely, subject to the following restrictions:
22 1. The origin of this software must not be misrepresented; you must not
23 claim that you wrote the original software. If you use this software
24 in a product, an acknowledgment in the product documentation would be
25 appreciated but is not required.
26 2. Altered source versions must be plainly marked as such, and must not be
27 misrepresented as being the original software.
28 3. This notice may not be removed or altered from any source distribution.
30 Jean-loup Gailly Mark Adler
31 jloup@gzip.org madler@alumni.caltech.edu
34 The data format used by the zlib library is described by RFCs (Request for
35 Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
36 (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
41==============================================================================
42Usage: z_stream = ZLIB.inflateInit([windowBits]);
44 Create the stream object for decompression.
45 See zlib.h for windowBits information.
47==============================================================================
48Usage: decoded_string = z_stream.inflate(encoded_string [, {OPTIONS...}]);
51 next_in: decode start offset for encoded_string.
53 avail_in: // TODO document. See zlib.h for the information.
55 avail_out: // TODO document. See zlib.h for the information.
57 flush: // TODO document. See zlib.h for the information.
59Ex: decoded_string = z_stream.inflate(encoded_string);
60 decoded_string = z_stream.inflate(encoded_string,
62 avail_in: encoded_string.length,
64 flush: ZLIB.Z_NO_FLUSH});
66 See zlib.h for more information.
68==============================================================================
69Usage: z_stream.inflateReset();
74if( typeof ZLIB === 'undefined' ) {
75 alert('ZLIB is not defined. SRC zlib.js before zlib-inflate.js')
80/* inflate.c -- zlib decompression
81 * Copyright (C) 1995-2011 Mark Adler
82 * For conditions of distribution and use, see copyright notice in zlib.h
88var HEAD = 0; /* i: waiting for magic header */
89var FLAGS = 1; /* i: waiting for method and flags (gzip) */
90var TIME = 2; /* i: waiting for modification time (gzip) */
91var OS = 3; /* i: waiting for extra flags and operating system (gzip) */
92var EXLEN = 4; /* i: waiting for extra length (gzip) */
93var EXTRA = 5; /* i: waiting for extra bytes (gzip) */
94var NAME = 6; /* i: waiting for end of file name (gzip) */
95var COMMENT = 7; /* i: waiting for end of comment (gzip) */
96var HCRC = 8; /* i: waiting for header crc (gzip) */
97var DICTID = 9; /* i: waiting for dictionary check value */
98var DICT = 10; /* waiting for inflateSetDictionary() call */
99var TYPE = 11; /* i: waiting for type bits, including last-flag bit */
100var TYPEDO = 12; /* i: same, but skip check to exit inflate on new block */
101var STORED = 13; /* i: waiting for stored size (length and complement) */
102var COPY_ = 14; /* i/o: same as COPY below, but only first time in */
103var COPY = 15; /* i/o: waiting for input or output to copy stored block */
104var TABLE = 16; /* i: waiting for dynamic block table lengths */
105var LENLENS = 17; /* i: waiting for code length code lengths */
106var CODELENS = 18; /* i: waiting for length/lit and distance code lengths */
107var LEN_ = 19; /* i: same as LEN below, but only first time in */
108var LEN = 20; /* i: waiting for length/lit/eob code */
109var LENEXT = 21; /* i: waiting for length extra bits */
110var DIST = 22; /* i: waiting for distance code */
111var DISTEXT = 23; /* i: waiting for distance extra bits */
112var MATCH = 24; /* o: waiting for output space to copy string */
113var LIT = 25; /* o: waiting for output space to write literal */
114var CHECK = 26; /* i: waiting for 32-bit check value */
115var LENGTH = 27; /* i: waiting for 32-bit length (gzip) */
116var DONE = 28; /* finished check, done -- remain here until reset */
117var BAD = 29; /* got a data error -- remain here until reset */
118var MEM = 30; /* got an inflate() memory error -- remain here until reset */
119var SYNC = 31; /* looking for synchronization bytes to restart inflate() */
121/* Maximum size of the dynamic table. The maximum number of code structures is
122 1444, which is the sum of 852 for literal/length codes and 592 for distance
123 codes. These values were found by exhaustive searches using the program
124 examples/enough.c found in the zlib distribtution. The arguments to that
125 program are the number of symbols, the initial root table size, and the
126 maximum bit length of a code. "enough 286 9 15" for literal/length codes
127 returns returns 852, and "enough 30 6 15" for distance codes returns 592.
128 The initial root table size (9 or 6) is found in the fifth argument of the
129 inflate_table() calls in inflate.c and infback.c. If the root table size is
130 changed, then these maximum sizes would be need to be recalculated and
132var ENOUGH_LENS = 852;
133var ENOUGH_DISTS = 592;
134var ENOUGH = (ENOUGH_LENS + ENOUGH_DISTS);
136/* Type of code to build for inflate_table() */
143var inflate_table_lbase = [ /* Length codes 257..285 base */
144 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
145 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0];
146var inflate_table_lext = [ /* Length codes 257..285 extra */
147 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
148 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 203, 69];
149var inflate_table_dbase = [ /* Distance codes 0..29 base */
150 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
151 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
152 8193, 12289, 16385, 24577, 0, 0];
153var inflate_table_dext = [ /* Distance codes 0..29 extra */
154 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
155 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
156 28, 28, 29, 29, 64, 64];
158/* inftrees.c -- generate Huffman trees for efficient decoding
159 * Copyright (C) 1995-2012 Mark Adler
160 * For conditions of distribution and use, see copyright notice in zlib.h
163ZLIB.inflate_copyright =
164 ' inflate 1.2.6 Copyright 1995-2012 Mark Adler ';
166 If you use the zlib library in a product, an acknowledgment is welcome
167 in the documentation of your product. If for some reason you cannot
168 include such an acknowledgment, I would appreciate that you keep this
169 copyright string in the executable of your product.
173 Build a set of tables to decode the provided canonical Huffman code.
174 The code lengths are lens[0..codes-1]. The result starts at *table,
175 whose indices are 0..2^bits-1. work is a writable array of at least
176 lens shorts, which is used as a work area. type is the type of code
177 to be generated, CODES, LENS, or DISTS. On return, zero is success,
178 -1 is an invalid code, and +1 means that ENOUGH isn't enough. table
179 on return points to the next available entry's address. bits is the
180 requested root table index bits, and on return it is the actual root
181 table index bits. It will differ if the request is greater than the
182 longest code or if it is less than the shortest code.
184function inflate_table(state, type)
187 var table = state.next;
188 var bits = (type == DISTS ? state.distbits : state.lenbits);
189 var work = state.work;
190 var lens = state.lens;
191 var lens_offset = (type == DISTS ? state.nlen : 0);
192 var state_codes = state.codes;
196 else if(type == DISTS)
201 var len; /* a code's length in bits */
202 var sym; /* index of code symbols */
203 var min, max; /* minimum and maximum code lengths */
204 var root; /* number of index bits for root table */
205 var curr; /* number of index bits for current table */
206 var drop; /* code bits to drop for sub-table */
207 var left; /* number of prefix codes available */
208 var used; /* code entries in table used */
209 var huff; /* Huffman code */
210 var incr; /* for incrementing code, index */
211 var fill; /* index for replicating entries */
212 var low; /* low bits for current root entry */
213 var mask; /* mask for low root bits */
214 var here; /* table entry for duplication */
215 var next; /* next available space in table */
216 var base; /* base value table to use */
218 var extra; /* extra bits table to use */
220 var end; /* use base and extra for symbol > end */
221 var count = new Array(MAXBITS+1); /* number of codes of each length */
222 var offs = new Array(MAXBITS+1); /* offsets in table for each length */
225 Process a set of code lengths to create a canonical Huffman code. The
226 code lengths are lens[0..codes-1]. Each length corresponds to the
227 symbols 0..codes-1. The Huffman code is generated by first sorting the
228 symbols by length from short to long, and retaining the symbol order
229 for codes with equal lengths. Then the code starts with all zero bits
230 for the first code of the shortest length, and the codes are integer
231 increments for the same length, and zeros are appended as the length
232 increases. For the deflate format, these bits are stored backwards
233 from their more natural integer increment ordering, and so when the
234 decoding tables are built in the large loop below, the integer codes
235 are incremented backwards.
237 This routine assumes, but does not check, that all of the entries in
238 lens[] are in the range 0..MAXBITS. The caller must assure this.
239 1..MAXBITS is interpreted as that code length. zero means that that
240 symbol does not occur in this code.
242 The codes are sorted by computing a count of codes for each length,
243 creating from that a table of starting indices for each length in the
244 sorted table, and then entering the symbols in order in the sorted
245 table. The sorted table is work[], with that space being provided by
248 The length counts are used for other purposes as well, i.e. finding
249 the minimum and maximum length codes, determining if there are any
250 codes at all, checking for a valid set of lengths, and looking ahead
251 at length counts to determine sub-table sizes when building the
255 /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
256 for (len = 0; len <= MAXBITS; len++)
258 for (sym = 0; sym < codes; sym++)
259 count[lens[lens_offset + sym]]++;
261 /* bound code lengths, force root to be within code lengths */
264 for (max = MAXBITS; max >= 1; max--)
265 if (count[max] != 0) break;
266 if (root > max) root = max;
268 /* no symbols to code at all */
269 /* invalid code marker */
270 here = {op:64, bits:1, val:0};
271 state_codes[table++] = here; /* make a table to force an error */
272 state_codes[table++] = here;
273 if(type == DISTS) state.distbits = 1; else state.lenbits = 1; // *bits = 1;
275 return 0; /* no symbols, but wait for decoding to report error */
277 for (min = 1; min < max; min++)
278 if (count[min] != 0) break;
279 if (root < min) root = min;
281 /* check for an over-subscribed or incomplete set of lengths */
283 for (len = 1; len <= MAXBITS; len++) {
286 if (left < 0) return -1; /* over-subscribed */
288 if (left > 0 && (type == CODES || max != 1)) {
290 return -1; /* incomplete set */
293 /* generate offsets into symbol table for each length for sorting */
295 for (len = 1; len < MAXBITS; len++)
296 offs[len + 1] = offs[len] + count[len];
298 /* sort symbols by length, by symbol order within each length */
299 for (sym = 0; sym < codes; sym++)
300 if (lens[lens_offset + sym] != 0) work[offs[lens[lens_offset + sym]]++] = sym;
303 Create and fill in decoding tables. In this loop, the table being
304 filled is at next and has curr index bits. The code being used is huff
305 with length len. That code is converted to an index by dropping drop
306 bits off of the bottom. For codes where len is less than drop + curr,
307 those top drop + curr - len bits are incremented through all values to
308 fill the table with replicated entries.
310 root is the number of index bits for the root table. When len exceeds
311 root, sub-tables are created pointed to by the root entry with an index
312 of the low root bits of huff. This is saved in low to check for when a
313 new sub-table should be started. drop is zero when the root table is
314 being filled, and drop is root when sub-tables are being filled.
316 When a new sub-table is needed, it is necessary to look ahead in the
317 code lengths to determine what size sub-table is needed. The length
318 counts are used for this, and so count[] is decremented as codes are
319 entered in the tables.
321 used keeps track of how many table entries have been allocated from the
322 provided *table space. It is checked for LENS and DIST tables against
323 the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
324 the initial root table size constants. See the comments in inftrees.h
325 for more information.
327 sym increments through all symbols, and the loop terminates when
328 all codes of length max, i.e. all codes, have been processed. This
329 routine permits incomplete codes, so another loop after this one fills
330 in the rest of the decoding tables with invalid code markers.
333 /* set up for code type */
336 base = extra = work; /* dummy value--not used */
342 base = inflate_table_lbase;
343 base_offset = -257; // base -= 257;
344 extra = inflate_table_lext;
345 extra_offset = -257; // extra -= 257;
349 base = inflate_table_dbase;
350 extra = inflate_table_dext;
356 /* initialize state for loop */
357 huff = 0; /* starting code */
358 sym = 0; /* starting code symbol */
359 len = min; /* starting code length */
360 next = table; /* current table to fill in */
361 curr = root; /* current table index bits */
362 drop = 0; /* current bits to drop from code for index */
363 low = -1; /* trigger new sub-table when len > root */
364 used = 1 << root; /* use root table entries */
365 mask = used - 1; /* mask for comparing low */
367 /* check available table space */
368 if ((type == LENS && used >= ENOUGH_LENS) ||
369 (type == DISTS && used >= ENOUGH_DISTS)) {
374 /* process all codes and make table entries */
376 /* create table entry */
377 here = {op:0, bits:len - drop, val:0};
378 if (work[sym] < end) {
379 here.val = work[sym];
381 else if (work[sym] > end) {
382 here.op = extra[extra_offset + work[sym]];
383 here.val = base[base_offset + work[sym]];
386 here.op = 32 + 64; /* end of block */
389 /* replicate for those indices with low len bits equal to huff */
390 incr = 1 << (len - drop);
392 min = fill; /* save offset to next table */
395 state_codes[next + (huff >>> drop) + fill] = here;
398 /* backwards increment the len-bit code huff */
399 incr = 1 << (len - 1);
409 /* go to next symbol, update count, len */
411 if (--(count[len]) == 0) {
412 if (len == max) break;
413 len = lens[lens_offset + work[sym]];
416 /* create new sub-table if needed */
417 if (len > root && (huff & mask) != low) {
418 /* if first time, transition to sub-tables */
422 /* increment past last table */
423 next += min; /* here min is 1 << curr */
425 /* determine length of next table */
428 while (curr + drop < max) {
429 left -= count[curr + drop];
430 if (left <= 0) break;
435 /* check for enough space */
437 if ((type == LENS && used >= ENOUGH_LENS) ||
438 (type == DISTS && used >= ENOUGH_DISTS)) {
443 /* point entry in root table to sub-table */
445 state_codes[table + low] = {op:curr, bits:root, val:next - table};
449 /* fill in remaining table entry if code is incomplete (guaranteed to have
450 at most one remaining entry, since if the code is incomplete, the
451 maximum code length that was allowed to get this far is one bit) */
453 state_codes[next + huff] = {op:64, bits:len - drop, val:0};
456 /* set return parameters */
457 state.next = table + used;
458 if(type == DISTS) state.distbits = root; else state.lenbits = root; //*bits = root;
462/* inffast.c -- fast decoding
463 * Copyright (C) 1995-2008, 2010 Mark Adler
464 * For conditions of distribution and use, see copyright notice in zlib.h
468 Decode literal, length, and distance codes and write out the resulting
469 literal and match bytes until either not enough input or output is
470 available, an end-of-block is encountered, or a data error is encountered.
471 When large enough input and output buffers are supplied to inflate(), for
472 example, a 16K input buffer and a 64K output buffer, more than 95% of the
473 inflate execution time is spent in this routine.
479 strm->avail_out >= 258
480 start >= strm->avail_out
483 On return, state->mode is one of:
485 LEN -- ran out of enough output space or enough available input
486 TYPE -- reached end of block code, inflate() to interpret next block
487 BAD -- error in block data
491 - The maximum input bits used by a length/distance pair is 15 bits for the
492 length code, 5 bits for the length extra, 15 bits for the distance code,
493 and 13 bits for the distance extra. This totals 48 bits, or six bytes.
494 Therefore if strm->avail_in >= 6, then there is enough input to avoid
495 checking for available input while decoding.
497 - The maximum bytes that a single length/distance pair can output is 258
498 bytes, which is the maximum length that can be coded. inflate_fast()
499 requires strm->avail_out >= 258 for each loop to avoid checking for
502function inflate_fast(strm,
503 start) /* inflate()'s starting value for strm->avail_out */
506 var input_data; /* local strm->input_data */
507 var next_in; /* zlib.js: index of input_data */
508 var last; /* while next_in < last, enough input available */
509 var out; /* local strm.next_out */
510 var beg; /* inflate()'s initial strm.next_out */
511 var end; /* while out < end, enough space available */
512//NOSPRT #ifdef INFLATE_STRICT
513// unsigned dmax; /* maximum distance from zlib header */
515 var wsize; /* window size or zero if not using window */
516 var whave; /* valid bytes in the window */
517 var wnext; /* window write index */
518 var window; /* allocated sliding window, if wsize != 0 */
519 var hold; /* local strm->hold */
520 var bits; /* local strm->bits */
521 var codes; /* zlib.js: local state.codes */
522 var lcode; /* local strm->lencode */
523 var dcode; /* local strm->distcode */
524 var lmask; /* mask for first level of length codes */
525 var dmask; /* mask for first level of distance codes */
526 var here; /* retrieved table entry */
527 var op; /* code bits, operation, extra bits, or */
528 /* window position, window bytes to copy */
529 var len; /* match length, unused bytes */
530 var dist; /* match distance */
531 // var from; /* where to copy match from */
532 var from_window_offset = -1; /* index of window[] */
533 var from_out_offset = -1; /* index of next_out[] */
535 /* copy state to local variables */
537 input_data = strm.input_data;
538 next_in = strm.next_in;
539 last = next_in + strm.avail_in - 5;
541 beg = out - (start - strm.avail_out);
542 end = out + (strm.avail_out - 257);
543//NOSPRT #ifdef INFLATE_STRICT
544// dmax = state->dmax;
549 window = state.window;
553 lcode = state.lencode;
554 dcode = state.distcode;
555 lmask = (1 << state.lenbits) - 1;
556 dmask = (1 << state.distbits) - 1;
558 /* decode literals and length/distances until end-of-block or not enough
559 input data or output space */
562 hold += (input_data.charCodeAt(next_in++) & 0xff) << bits;
564 hold += (input_data.charCodeAt(next_in++) & 0xff) << bits;
567 here = codes[lcode + (hold & lmask)];
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 strm.output_data += String.fromCharCode(here.val);
580 else if (op & 16) { /* length base */
582 op &= 15; /* number of extra bits */
585 hold += (input_data.charCodeAt(next_in++) & 0xff) << bits;
588 len += hold & ((1 << op) - 1);
592// Tracevv((stderr, "inflate: length %u\n", len));
594 hold += (input_data.charCodeAt(next_in++) & 0xff) << bits;
596 hold += (input_data.charCodeAt(next_in++) & 0xff) << bits;
599 here = codes[dcode + (hold & dmask)];
600 dodist: while(true) {
605 if (op & 16) { /* distance base */
607 op &= 15; /* number of extra bits */
609 hold += (input_data.charCodeAt(next_in++) & 0xff) << bits;
612 hold += (input_data.charCodeAt(next_in++) & 0xff) << bits;
616 dist += hold & ((1 << op) - 1);
617//NOSPRT #ifdef INFLATE_STRICT
619// strm->msg = (char *)"invalid distance too far back";
626// Tracevv((stderr, "inflate: distance %u\n", dist));
627 op = out - beg; /* max distance in output */
628 if (dist > op) { /* see if copy from window */
629 op = dist - op; /* distance back in window */
632 strm.msg = 'invalid distance too far back';
636//NOSPRT #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
637// if (len <= op - whave) {
646// } while (--op > whave);
650// PUP(out) = PUP(from);
657 from_window_offset = 0;
658 from_out_offset = -1;
659 if (wnext == 0) { /* very common case */
660 from_window_offset += wsize - op;
661 if (op < len) { /* some from window */
663 strm.output_data += window.substring(from_window_offset, from_window_offset + op);
666 from_window_offset = -1;
667 from_out_offset = out - dist; /* rest from output */
670//NOTREACHED else if (wnext < op) { /* wrap around window */
671//NOTREACHED from += wsize + wnext - op;
672//NOTREACHED op -= wnext;
673//NOTREACHED if (op < len) { /* some from end of window */
674//NOTREACHED len -= op;
676//NOTREACHED PUP(out) = PUP(from);
677//NOTREACHED } while (--op);
678//NOTREACHED from = window - OFF;
679//NOTREACHED if (wnext < len) { /* some from start of window */
680//NOTREACHED op = wnext;
681//NOTREACHED len -= op;
683//NOTREACHED PUP(out) = PUP(from);
684//NOTREACHED } while (--op);
685//NOTREACHED from = out - dist; /* rest from output */
689 else { /* contiguous in window */
690 from_window_offset += wnext - op;
691 if (op < len) { /* some from window */
693 strm.output_data += window.substring(from_window_offset, from_window_offset + op);
695 from_window_offset = -1;
696 from_out_offset = out - dist; /* rest from output */
701 from_window_offset = -1;
702 from_out_offset = out - dist; /* copy direct from output */
705 if (from_window_offset >= 0) {
706 strm.output_data += window.substring(from_window_offset, from_window_offset + len);
708 from_window_offset += len;
711 if(len_inner > out - from_out_offset)
712 len_inner = out - from_out_offset;
713 strm.output_data += strm.output_data.substring(
714 from_out_offset, from_out_offset + len_inner);
717 from_out_offset += len_inner;
720 strm.output_data += strm.output_data.charAt(from_out_offset++);
721 strm.output_data += strm.output_data.charAt(from_out_offset++);
722 strm.output_data += strm.output_data.charAt(from_out_offset++);
726 strm.output_data += strm.output_data.charAt(from_out_offset++);
728 strm.output_data += strm.output_data.charAt(from_out_offset++);
732 else if ((op & 64) == 0) { /* 2nd level distance code */
733 here = codes[dcode + (here.val + (hold & ((1 << op) - 1)))];
734 continue dodist; // goto dodist
737 strm.msg = 'invalid distance code';
743 else if ((op & 64) == 0) { /* 2nd level length code */
744 here = codes[lcode + (here.val + (hold & ((1 << op) - 1)))];
745 continue dolen; // goto dolen;
747 else if (op & 32) { /* end-of-block */
748 // Tracevv((stderr, "inflate: end of block\n"));
753 strm.msg = 'invalid literal/length code';
758 } while (next_in < last && out < end);
760 /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
764 hold &= (1 << bits) - 1;
766 /* update state and return */
767 strm.next_in = next_in;
769 strm.avail_in = (next_in < last ? 5 + (last - next_in) : 5 - (next_in - last));
770 strm.avail_out = (out < end ?
771 257 + (end - out) : 257 - (out - end));
776function new_array(size)
779 var ary = new Array(size);
780 for(i = 0; i < size; i++)
785function getarg(opts, name, def_value)
787 return (opts && (name in opts)) ? opts[name] : def_value;
790function checksum_none()
796 * z_stream constructor
799function inflate_state()
803 this.mode = 0; /* current inflate mode */
804 this.last = 0; /* true if processing last block */
805 this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */
806 this.havedict = 0; /* true if dictionary provided */
807 this.flags = 0; /* gzip header method and flags (0 if zlib) */
808 this.dmax = 0; /* zlib header max distance (INFLATE_STRICT) */
809 this.check = 0; /* protected copy of check value */
810 this.total = 0; /* protected copy of output count */
811 this.head = null; /* where to save gzip header information */
813 this.wbits = 0; /* log base 2 of requested window size */
814 this.wsize = 0; /* window size or zero if not using window */
815 this.whave = 0; /* valid bytes in the window */
816 this.wnext = 0; /* window write index (TODO remove) */
817 this.window = null; /* allocated sliding window, if needed */
818 /* bit accumulator */
819 this.hold = 0; /* input bit accumulator */
820 this.bits = 0; /* number of bits in "in" */
821 /* for string and stored block copying */
822 this.length = 0; /* literal or length of data to copy */
823 this.offset = 0; /* distance back to copy string from */
824 /* for table and code decoding */
825 this.extra = 0; /* extra bits needed */
826 /* fixed and dynamic code tables */
828 /* zlib.js: modified implementation: lencode, distcode, next are offset of codes[] */
829 this.lencode = 0; /* starting table for length/literal codes */
830 this.distcode = 0; /* starting table for distance codes */
831 this.lenbits = 0; /* index bits for lencode */
832 this.distbits = 0; /* index bits for distcode */
833 /* dynamic table building */
834 this.ncode = 0; /* number of code length code lengths */
835 this.nlen = 0; /* number of length code lengths */
836 this.ndist = 0; /* number of distance code lengths */
837 this.have = 0; /* number of code lengths in lens[] */
838 this.next = 0; /* next available space in codes[] */
839 this.lens = new_array(320); /* temporary storage for code lengths */
840 this.work = new_array(288); /* work area for code table building */
841 this.codes = new Array(ENOUGH); /* space for code tables */
842 var c = {op:0, bits:0, val:0};
843 for(i = 0; i < ENOUGH; i++)
845 this.sane = 0; /* if false, allow invalid distance too far */
846 this.back = 0; /* bits back of last unprocessed length/lit */
847 this.was = 0; /* initial length of match */
850ZLIB.inflateResetKeep = function(strm)
854 if (!strm || !strm.state) return ZLIB.Z_STREAM_ERROR;
856 strm.total_in = strm.total_out = state.total = 0;
858 if (state.wrap) { /* to support ill-conceived Java test suite */
859 strm.adler = state.wrap & 1;
877// Usage: strm = ZLIB.inflateReset(z_stream [, windowBits]);
878ZLIB.inflateReset = function(strm, windowBits)
884 if (!strm || !strm.state) return ZLIB.Z_STREAM_ERROR;
887 if(typeof windowBits === "undefined")
888 windowBits = DEF_WBITS;
890 /* extract wrap request from windowBits parameter */
891 if (windowBits < 0) {
893 windowBits = -windowBits;
896 wrap = (windowBits >>> 4) + 1;
901 if(wrap == 1 && (typeof ZLIB.adler32 === 'function')) {
902 strm.checksum_function = ZLIB.adler32;
903 } else if(wrap == 2 && (typeof ZLIB.crc32 === 'function')) {
904 strm.checksum_function = ZLIB.crc32;
906 strm.checksum_function = checksum_none;
909 /* set number of window bits, free window if different */
910 if (windowBits && (windowBits < 8 || windowBits > 15))
911 return ZLIB.Z_STREAM_ERROR;
912 if (state.window && state.wbits != windowBits) {
916 /* update state and reset the rest of it */
918 state.wbits = windowBits;
922 return ZLIB.inflateResetKeep(strm);
925// Usage: strm = ZLIB.inflateInit([windowBits]);
926ZLIB.inflateInit = function(windowBits)
928 var strm = new ZLIB.z_stream();
929 strm.state = new inflate_state();
930 ZLIB.inflateReset(strm, windowBits);
934ZLIB.inflatePrime = function(strm, bits, value)
938 if (!strm || !strm.state) return ZLIB.Z_STREAM_ERROR;
945 if (bits > 16 || state.bits + bits > 32) return ZLIB.Z_STREAM_ERROR;
946 value &= (1 << bits) - 1;
947 state.hold += value << state.bits;
952var lenfix_ary = null;
953var distfix_ary = null;
954function fixedtables(state)
957 if (!lenfix_ary) lenfix_ary = [ { op: 96, bits: 7, val: 0 }, { op: 0, bits: 8, val: 80 }, { op: 0, bits: 8, val: 16 }, { op: 20, bits: 8, val: 115 }, { op: 18, bits: 7, val: 31 }, { op: 0, bits: 8, val: 112 }, { op: 0, bits: 8, val: 48 }, { op: 0, bits: 9, val: 192 }, { op: 16, bits: 7, val: 10 }, { op: 0, bits: 8, val: 96 }, { op: 0, bits: 8, val: 32 }, { op: 0, bits: 9, val: 160 }, { op: 0, bits: 8, val: 0 }, { op: 0, bits: 8, val: 128 }, { op: 0, bits: 8, val: 64 }, { op: 0, bits: 9, val: 224 }, { op: 16, bits: 7, val: 6 }, { op: 0, bits: 8, val: 88 }, { op: 0, bits: 8, val: 24 }, { op: 0, bits: 9, val: 144 }, { op: 19, bits: 7, val: 59 }, { op: 0, bits: 8, val: 120 }, { op: 0, bits: 8, val: 56 }, { op: 0, bits: 9, val: 208 }, { op: 17, bits: 7, val: 17 }, { op: 0, bits: 8, val: 104 }, { op: 0, bits: 8, val: 40 }, { op: 0, bits: 9, val: 176 }, { op: 0, bits: 8, val: 8 }, { op: 0, bits: 8, val: 136 }, { op: 0, bits: 8, val: 72 }, { op: 0, bits: 9, val: 240 }, { op: 16, bits: 7, val: 4 }, { op: 0, bits: 8, val: 84 }, { op: 0, bits: 8, val: 20 }, { op: 21, bits: 8, val: 227 }, { op: 19, bits: 7, val: 43 }, { op: 0, bits: 8, val: 116 }, { op: 0, bits: 8, val: 52 }, { op: 0, bits: 9, val: 200 }, { op: 17, bits: 7, val: 13 }, { op: 0, bits: 8, val: 100 }, { op: 0, bits: 8, val: 36 }, { op: 0, bits: 9, val: 168 }, { op: 0, bits: 8, val: 4 }, { op: 0, bits: 8, val: 132 }, { op: 0, bits: 8, val: 68 }, { op: 0, bits: 9, val: 232 }, { op: 16, bits: 7, val: 8 }, { op: 0, bits: 8, val: 92 }, { op: 0, bits: 8, val: 28 }, { op: 0, bits: 9, val: 152 }, { op: 20, bits: 7, val: 83 }, { op: 0, bits: 8, val: 124 }, { op: 0, bits: 8, val: 60 }, { op: 0, bits: 9, val: 216 }, { op: 18, bits: 7, val: 23 }, { op: 0, bits: 8, val: 108 }, { op: 0, bits: 8, val: 44 }, { op: 0, bits: 9, val: 184 }, { op: 0, bits: 8, val: 12 }, { op: 0, bits: 8, val: 140 }, { op: 0, bits: 8, val: 76 }, { op: 0, bits: 9, val: 248 }, { op: 16, bits: 7, val: 3 }, { op: 0, bits: 8, val: 82 }, { op: 0, bits: 8, val: 18 }, { op: 21, bits: 8, val: 163 }, { op: 19, bits: 7, val: 35 }, { op: 0, bits: 8, val: 114 }, { op: 0, bits: 8, val: 50 }, { op: 0, bits: 9, val: 196 }, { op: 17, bits: 7, val: 11 }, { op: 0, bits: 8, val: 98 }, { op: 0, bits: 8, val: 34 }, { op: 0, bits: 9, val: 164 }, { op: 0, bits: 8, val: 2 }, { op: 0, bits: 8, val: 130 }, { op: 0, bits: 8, val: 66 }, { op: 0, bits: 9, val: 228 }, { op: 16, bits: 7, val: 7 }, { op: 0, bits: 8, val: 90 }, { op: 0, bits: 8, val: 26 }, { op: 0, bits: 9, val: 148 }, { op: 20, bits: 7, val: 67 }, { op: 0, bits: 8, val: 122 }, { op: 0, bits: 8, val: 58 }, { op: 0, bits: 9, val: 212 }, { op: 18, bits: 7, val: 19 }, { op: 0, bits: 8, val: 106 }, { op: 0, bits: 8, val: 42 }, { op: 0, bits: 9, val: 180 }, { op: 0, bits: 8, val: 10 }, { op: 0, bits: 8, val: 138 }, { op: 0, bits: 8, val: 74 }, { op: 0, bits: 9, val: 244 }, { op: 16, bits: 7, val: 5 }, { op: 0, bits: 8, val: 86 }, { op: 0, bits: 8, val: 22 }, { op: 64, bits: 8, val: 0 }, { op: 19, bits: 7, val: 51 }, { op: 0, bits: 8, val: 118 }, { op: 0, bits: 8, val: 54 }, { op: 0, bits: 9, val: 204 }, { op: 17, bits: 7, val: 15 }, { op: 0, bits: 8, val: 102 }, { op: 0, bits: 8, val: 38 }, { op: 0, bits: 9, val: 172 }, { op: 0, bits: 8, val: 6 }, { op: 0, bits: 8, val: 134 }, { op: 0, bits: 8, val: 70 }, { op: 0, bits: 9, val: 236 }, { op: 16, bits: 7, val: 9 }, { op: 0, bits: 8, val: 94 }, { op: 0, bits: 8, val: 30 }, { op: 0, bits: 9, val: 156 }, { op: 20, bits: 7, val: 99 }, { op: 0, bits: 8, val: 126 }, { op: 0, bits: 8, val: 62 }, { op: 0, bits: 9, val: 220 }, { op: 18, bits: 7, val: 27 }, { op: 0, bits: 8, val: 110 }, { op: 0, bits: 8, val: 46 }, { op: 0, bits: 9, val: 188 }, { op: 0, bits: 8, val: 14 }, { op: 0, bits: 8, val: 142 }, { op: 0, bits: 8, val: 78 }, { op: 0, bits: 9, val: 252 }, { op: 96, bits: 7, val: 0 }, { op: 0, bits: 8, val: 81 }, { op: 0, bits: 8, val: 17 }, { op: 21, bits: 8, val: 131 }, { op: 18, bits: 7, val: 31 }, { op: 0, bits: 8, val: 113 }, { op: 0, bits: 8, val: 49 }, { op: 0, bits: 9, val: 194 }, { op: 16, bits: 7, val: 10 }, { op: 0, bits: 8, val: 97 }, { op: 0, bits: 8, val: 33 }, { op: 0, bits: 9, val: 162 }, { op: 0, bits: 8, val: 1 }, { op: 0, bits: 8, val: 129 }, { op: 0, bits: 8, val: 65 }, { op: 0, bits: 9, val: 226 }, { op: 16, bits: 7, val: 6 }, { op: 0, bits: 8, val: 89 }, { op: 0, bits: 8, val: 25 }, { op: 0, bits: 9, val: 146 }, { op: 19, bits: 7, val: 59 }, { op: 0, bits: 8, val: 121 }, { op: 0, bits: 8, val: 57 }, { op: 0, bits: 9, val: 210 }, { op: 17, bits: 7, val: 17 }, { op: 0, bits: 8, val: 105 }, { op: 0, bits: 8, val: 41 }, { op: 0, bits: 9, val: 178 }, { op: 0, bits: 8, val: 9 }, { op: 0, bits: 8, val: 137 }, { op: 0, bits: 8, val: 73 }, { op: 0, bits: 9, val: 242 }, { op: 16, bits: 7, val: 4 }, { op: 0, bits: 8, val: 85 }, { op: 0, bits: 8, val: 21 }, { op: 16, bits: 8, val: 258 }, { op: 19, bits: 7, val: 43 }, { op: 0, bits: 8, val: 117 }, { op: 0, bits: 8, val: 53 }, { op: 0, bits: 9, val: 202 }, { op: 17, bits: 7, val: 13 }, { op: 0, bits: 8, val: 101 }, { op: 0, bits: 8, val: 37 }, { op: 0, bits: 9, val: 170 }, { op: 0, bits: 8, val: 5 }, { op: 0, bits: 8, val: 133 }, { op: 0, bits: 8, val: 69 }, { op: 0, bits: 9, val: 234 }, { op: 16, bits: 7, val: 8 }, { op: 0, bits: 8, val: 93 }, { op: 0, bits: 8, val: 29 }, { op: 0, bits: 9, val: 154 }, { op: 20, bits: 7, val: 83 }, { op: 0, bits: 8, val: 125 }, { op: 0, bits: 8, val: 61 }, { op: 0, bits: 9, val: 218 }, { op: 18, bits: 7, val: 23 }, { op: 0, bits: 8, val: 109 }, { op: 0, bits: 8, val: 45 }, { op: 0, bits: 9, val: 186 }, { op: 0, bits: 8, val: 13 }, { op: 0, bits: 8, val: 141 }, { op: 0, bits: 8, val: 77 }, { op: 0, bits: 9, val: 250 }, { op: 16, bits: 7, val: 3 }, { op: 0, bits: 8, val: 83 }, { op: 0, bits: 8, val: 19 }, { op: 21, bits: 8, val: 195 }, { op: 19, bits: 7, val: 35 }, { op: 0, bits: 8, val: 115 }, { op: 0, bits: 8, val: 51 }, { op: 0, bits: 9, val: 198 }, { op: 17, bits: 7, val: 11 }, { op: 0, bits: 8, val: 99 }, { op: 0, bits: 8, val: 35 }, { op: 0, bits: 9, val: 166 }, { op: 0, bits: 8, val: 3 }, { op: 0, bits: 8, val: 131 }, { op: 0, bits: 8, val: 67 }, { op: 0, bits: 9, val: 230 }, { op: 16, bits: 7, val: 7 }, { op: 0, bits: 8, val: 91 }, { op: 0, bits: 8, val: 27 }, { op: 0, bits: 9, val: 150 }, { op: 20, bits: 7, val: 67 }, { op: 0, bits: 8, val: 123 }, { op: 0, bits: 8, val: 59 }, { op: 0, bits: 9, val: 214 }, { op: 18, bits: 7, val: 19 }, { op: 0, bits: 8, val: 107 }, { op: 0, bits: 8, val: 43 }, { op: 0, bits: 9, val: 182 }, { op: 0, bits: 8, val: 11 }, { op: 0, bits: 8, val: 139 }, { op: 0, bits: 8, val: 75 }, { op: 0, bits: 9, val: 246 }, { op: 16, bits: 7, val: 5 }, { op: 0, bits: 8, val: 87 }, { op: 0, bits: 8, val: 23 }, { op: 64, bits: 8, val: 0 }, { op: 19, bits: 7, val: 51 }, { op: 0, bits: 8, val: 119 }, { op: 0, bits: 8, val: 55 }, { op: 0, bits: 9, val: 206 }, { op: 17, bits: 7, val: 15 }, { op: 0, bits: 8, val: 103 }, { op: 0, bits: 8, val: 39 }, { op: 0, bits: 9, val: 174 }, { op: 0, bits: 8, val: 7 }, { op: 0, bits: 8, val: 135 }, { op: 0, bits: 8, val: 71 }, { op: 0, bits: 9, val: 238 }, { op: 16, bits: 7, val: 9 }, { op: 0, bits: 8, val: 95 }, { op: 0, bits: 8, val: 31 }, { op: 0, bits: 9, val: 158 }, { op: 20, bits: 7, val: 99 }, { op: 0, bits: 8, val: 127 }, { op: 0, bits: 8, val: 63 }, { op: 0, bits: 9, val: 222 }, { op: 18, bits: 7, val: 27 }, { op: 0, bits: 8, val: 111 }, { op: 0, bits: 8, val: 47 }, { op: 0, bits: 9, val: 190 }, { op: 0, bits: 8, val: 15 }, { op: 0, bits: 8, val: 143 }, { op: 0, bits: 8, val: 79 }, { op: 0, bits: 9, val: 254 }, { op: 96, bits: 7, val: 0 }, { op: 0, bits: 8, val: 80 }, { op: 0, bits: 8, val: 16 }, { op: 20, bits: 8, val: 115 }, { op: 18, bits: 7, val: 31 }, { op: 0, bits: 8, val: 112 }, { op: 0, bits: 8, val: 48 }, { op: 0, bits: 9, val: 193 }, { op: 16, bits: 7, val: 10 }, { op: 0, bits: 8, val: 96 }, { op: 0, bits: 8, val: 32 }, { op: 0, bits: 9, val: 161 }, { op: 0, bits: 8, val: 0 }, { op: 0, bits: 8, val: 128 }, { op: 0, bits: 8, val: 64 }, { op: 0, bits: 9, val: 225 }, { op: 16, bits: 7, val: 6 }, { op: 0, bits: 8, val: 88 }, { op: 0, bits: 8, val: 24 }, { op: 0, bits: 9, val: 145 }, { op: 19, bits: 7, val: 59 }, { op: 0, bits: 8, val: 120 }, { op: 0, bits: 8, val: 56 }, { op: 0, bits: 9, val: 209 }, { op: 17, bits: 7, val: 17 }, { op: 0, bits: 8, val: 104 }, { op: 0, bits: 8, val: 40 }, { op: 0, bits: 9, val: 177 }, { op: 0, bits: 8, val: 8 }, { op: 0, bits: 8, val: 136 }, { op: 0, bits: 8, val: 72 }, { op: 0, bits: 9, val: 241 }, { op: 16, bits: 7, val: 4 }, { op: 0, bits: 8, val: 84 }, { op: 0, bits: 8, val: 20 }, { op: 21, bits: 8, val: 227 }, { op: 19, bits: 7, val: 43 }, { op: 0, bits: 8, val: 116 }, { op: 0, bits: 8, val: 52 }, { op: 0, bits: 9, val: 201 }, { op: 17, bits: 7, val: 13 }, { op: 0, bits: 8, val: 100 }, { op: 0, bits: 8, val: 36 }, { op: 0, bits: 9, val: 169 }, { op: 0, bits: 8, val: 4 }, { op: 0, bits: 8, val: 132 }, { op: 0, bits: 8, val: 68 }, { op: 0, bits: 9, val: 233 }, { op: 16, bits: 7, val: 8 }, { op: 0, bits: 8, val: 92 }, { op: 0, bits: 8, val: 28 }, { op: 0, bits: 9, val: 153 }, { op: 20, bits: 7, val: 83 }, { op: 0, bits: 8, val: 124 }, { op: 0, bits: 8, val: 60 }, { op: 0, bits: 9, val: 217 }, { op: 18, bits: 7, val: 23 }, { op: 0, bits: 8, val: 108 }, { op: 0, bits: 8, val: 44 }, { op: 0, bits: 9, val: 185 }, { op: 0, bits: 8, val: 12 }, { op: 0, bits: 8, val: 140 }, { op: 0, bits: 8, val: 76 }, { op: 0, bits: 9, val: 249 }, { op: 16, bits: 7, val: 3 }, { op: 0, bits: 8, val: 82 }, { op: 0, bits: 8, val: 18 }, { op: 21, bits: 8, val: 163 }, { op: 19, bits: 7, val: 35 }, { op: 0, bits: 8, val: 114 }, { op: 0, bits: 8, val: 50 }, { op: 0, bits: 9, val: 197 }, { op: 17, bits: 7, val: 11 }, { op: 0, bits: 8, val: 98 }, { op: 0, bits: 8, val: 34 }, { op: 0, bits: 9, val: 165 }, { op: 0, bits: 8, val: 2 }, { op: 0, bits: 8, val: 130 }, { op: 0, bits: 8, val: 66 }, { op: 0, bits: 9, val: 229 }, { op: 16, bits: 7, val: 7 }, { op: 0, bits: 8, val: 90 }, { op: 0, bits: 8, val: 26 }, { op: 0, bits: 9, val: 149 }, { op: 20, bits: 7, val: 67 }, { op: 0, bits: 8, val: 122 }, { op: 0, bits: 8, val: 58 },{ op: 0, bits: 9, val: 213 }, { op: 18, bits: 7, val: 19 }, { op: 0, bits: 8, val: 106 }, { op: 0, bits: 8, val: 42 }, { op: 0, bits: 9, val: 181 }, { op: 0, bits: 8, val: 10 }, { op: 0, bits: 8, val: 138 },{ op: 0, bits: 8, val: 74 }, { op: 0, bits: 9, val: 245 }, { op: 16, bits: 7, val: 5 }, { op: 0, bits: 8, val: 86 }, { op: 0, bits: 8, val: 22 }, { op: 64, bits: 8, val: 0 }, { op: 19, bits: 7, val: 51 },{ op: 0, bits: 8, val: 118 }, { op: 0, bits: 8, val: 54 }, { op: 0, bits: 9, val: 205 }, { op: 17, bits: 7, val: 15 }, { op: 0, bits: 8, val: 102 }, { op: 0, bits: 8, val: 38 }, { op: 0, bits: 9, val: 173 },{ op: 0, bits: 8, val: 6 }, { op: 0, bits: 8, val: 134 }, { op: 0, bits: 8, val: 70 }, { op: 0, bits: 9, val: 237 }, { op: 16, bits: 7, val: 9 }, { op: 0, bits: 8, val: 94 }, { op: 0, bits: 8, val: 30 },{ op: 0, bits: 9, val: 157 }, { op: 20, bits: 7, val: 99 }, { op: 0, bits: 8, val: 126 }, { op: 0, bits: 8, val: 62 }, { op: 0, bits: 9, val: 221 }, { op: 18, bits: 7, val: 27 }, { op: 0, bits: 8, val: 110 }, { op: 0, bits: 8, val: 46 }, { op: 0, bits: 9, val: 189 }, { op: 0, bits: 8, val: 14 }, { op: 0, bits: 8, val: 142 }, { op: 0, bits: 8, val: 78 }, { op: 0, bits: 9, val: 253 }, { op: 96, bits: 7, val: 0 }, { op: 0, bits: 8, val: 81 }, { op: 0, bits: 8, val: 17 }, { op: 21, bits: 8, val: 131 }, { op: 18, bits: 7, val: 31 }, { op: 0, bits: 8, val: 113 }, { op: 0, bits: 8, val: 49 }, { op: 0, bits: 9, val: 195 }, { op: 16, bits: 7, val: 10 }, { op: 0, bits: 8, val: 97 }, { op: 0, bits: 8, val: 33 }, { op: 0, bits: 9, val: 163 }, { op: 0, bits: 8, val: 1 }, { op: 0, bits: 8, val: 129 }, { op: 0, bits: 8, val: 65 }, { op: 0, bits: 9, val: 227 }, { op: 16, bits: 7, val: 6 }, { op: 0, bits: 8, val: 89 }, { op: 0, bits: 8, val: 25 }, { op: 0, bits: 9, val: 147 }, { op: 19, bits: 7, val: 59 }, { op: 0, bits: 8, val: 121 }, { op: 0, bits: 8, val: 57 }, { op: 0, bits: 9, val: 211 }, { op: 17, bits: 7, val: 17 }, { op: 0, bits: 8, val: 105 }, { op: 0, bits: 8, val: 41 }, { op: 0, bits: 9, val: 179 }, { op: 0, bits: 8, val: 9 },{ op: 0, bits: 8, val: 137 }, { op: 0, bits: 8, val: 73 }, { op: 0, bits: 9, val: 243 }, { op: 16, bits: 7, val: 4 }, { op: 0, bits: 8, val: 85 }, { op: 0, bits: 8, val: 21 }, { op: 16, bits: 8, val: 258 },{ op: 19, bits: 7, val: 43 }, { op: 0, bits: 8, val: 117 }, { op: 0, bits: 8, val: 53 }, { op: 0, bits: 9, val: 203 }, { op: 17, bits: 7, val: 13 }, { op: 0, bits: 8, val: 101 }, { op: 0, bits: 8, val: 37 },{ op: 0, bits: 9, val: 171 }, { op: 0, bits: 8, val: 5 }, { op: 0, bits: 8, val: 133 }, { op: 0, bits: 8, val: 69 }, { op: 0, bits: 9, val: 235 }, { op: 16, bits: 7, val: 8 }, { op: 0, bits: 8, val: 93 },{ op: 0, bits: 8, val: 29 }, { op: 0, bits: 9, val: 155 }, { op: 20, bits: 7, val: 83 }, { op: 0, bits: 8, val: 125 }, { op: 0, bits: 8, val: 61 }, { op: 0, bits: 9, val: 219 }, { op: 18, bits: 7, val: 23 },{ op: 0, bits: 8, val: 109 }, { op: 0, bits: 8, val: 45 }, { op: 0, bits: 9, val: 187 }, { op: 0, bits: 8, val: 13 }, { op: 0, bits: 8, val: 141 }, { op: 0, bits: 8, val: 77 }, { op: 0, bits: 9, val: 251 }, { op: 16, bits: 7, val: 3 }, { op: 0, bits: 8, val: 83 }, { op: 0, bits: 8, val: 19 }, { op: 21, bits: 8, val: 195 }, { op: 19, bits: 7, val: 35 }, { op: 0, bits: 8, val: 115 }, { op: 0, bits: 8, val: 51 }, { op: 0, bits: 9, val: 199 }, { op: 17, bits: 7, val: 11 }, { op: 0, bits: 8, val: 99 }, { op: 0, bits: 8, val: 35 }, { op: 0, bits: 9, val: 167 }, { op: 0, bits: 8, val: 3 }, { op: 0, bits: 8, val: 131 }, { op: 0, bits: 8, val: 67 }, { op: 0, bits: 9, val: 231 }, { op: 16, bits: 7, val: 7 }, { op: 0, bits: 8, val: 91 }, { op: 0, bits: 8, val: 27 }, { op: 0, bits: 9, val: 151 }, { op: 20, bits: 7, val: 67 }, { op: 0, bits: 8, val: 123 }, { op: 0, bits: 8, val: 59 }, { op: 0, bits: 9, val: 215 }, { op: 18, bits: 7, val: 19 }, { op: 0, bits: 8, val: 107 }, { op: 0, bits: 8, val: 43 }, { op: 0, bits: 9, val: 183 }, { op: 0, bits: 8, val: 11 }, { op: 0, bits: 8, val: 139 }, { op: 0, bits: 8, val: 75 }, { op: 0, bits: 9, val: 247 }, { op: 16, bits: 7, val: 5 }, { op: 0, bits: 8, val: 87 }, { op: 0, bits: 8, val: 23 }, { op: 64, bits: 8, val: 0 }, { op: 19, bits: 7, val: 51 }, { op: 0, bits: 8, val: 119 }, { op: 0, bits: 8, val: 55 }, { op: 0, bits: 9, val: 207 }, { op: 17, bits: 7, val: 15 }, { op: 0, bits: 8, val: 103 }, { op: 0, bits: 8, val: 39 }, { op: 0, bits: 9, val: 175 }, { op: 0, bits: 8, val: 7 }, { op: 0, bits: 8, val: 135 }, { op: 0, bits: 8, val: 71 }, { op: 0, bits: 9, val: 239 }, { op: 16, bits: 7, val: 9 }, { op: 0, bits: 8, val: 95 }, { op: 0, bits: 8, val: 31 }, { op: 0, bits: 9, val: 159 }, { op: 20, bits: 7, val: 99 }, { op: 0, bits: 8, val: 127 }, { op: 0, bits: 8, val: 63 }, { op: 0, bits: 9, val: 223 }, { op: 18, bits: 7, val: 27 }, { op: 0, bits: 8, val: 111 }, { op: 0, bits: 8, val: 47 }, { op: 0, bits: 9, val: 191 }, { op: 0, bits: 8, val: 15 }, { op: 0, bits: 8, val: 143 }, { op: 0, bits: 8, val: 79 }, { op: 0, bits: 9, val: 255 } ];
958 if (!distfix_ary) distfix_ary = [ { op: 16, bits: 5, val: 1 }, { op: 23, bits: 5, val: 257 }, { op: 19, bits: 5, val: 17 }, { op: 27, bits: 5, val: 4097 }, { op: 17, bits: 5, val: 5 }, { op: 25, bits: 5, val: 1025 }, { op: 21, bits: 5, val: 65 }, { op: 29, bits: 5, val: 16385 }, { op: 16, bits: 5, val: 3 }, { op: 24, bits: 5, val: 513 }, { op: 20, bits: 5, val: 33 }, { op: 28, bits: 5, val: 8193 }, { op: 18, bits: 5, val: 9 }, { op: 26, bits: 5, val: 2049 }, { op: 22, bits: 5, val: 129 }, { op: 64, bits: 5, val: 0 }, { op: 16, bits: 5, val: 2 }, { op: 23, bits: 5, val: 385 }, { op: 19, bits: 5, val: 25 }, { op: 27, bits: 5, val: 6145 }, { op: 17, bits: 5, val: 7 }, { op: 25, bits: 5, val: 1537 }, { op: 21, bits: 5, val: 97 }, { op: 29, bits: 5, val: 24577 }, { op: 16, bits: 5, val: 4 }, { op: 24, bits: 5, val: 769 }, { op: 20, bits: 5, val: 49 }, { op: 28, bits: 5, val: 12289 }, { op: 18, bits: 5, val: 13 }, { op: 26, bits: 5, val: 3073 }, { op: 22, bits: 5, val: 193 }, { op: 64, bits: 5, val: 0 } ];
960 state.distcode = 512;
961 for (i = 0; i < 512; i++) { state.codes[i] = lenfix_ary[i]; }
962 for (i = 0; i < 32; i++) { state.codes[i + 512] = distfix_ary[i]; }
968 Update the window with the last wsize (normally 32K) bytes written before
969 returning. If window does not exist yet, create it. This is only called
970 when a window is already in use, or when output has been written during this
971 inflate call, but the end of the deflate stream has not been reached yet.
972 It is also called to create a window for dictionary data when a dictionary
975 Providing output buffers larger than 32K to inflate() should provide a speed
976 advantage, since only the last 32K of output is copied to the sliding window
977 upon return from inflate(), and since all distances after the first 32K of
978 output will fall in the output data, making match copies simpler and faster.
979 The advantage may be dependent on the size of the processor's data caches.
981function updatewindow(strm)
983 var state = strm.state;
984 var out = strm.output_data.length;
986 /* if it hasn't been done already, allocate space for the window */
987 if (state.window === null) {
991 /* if window not in use yet, initialize */
992 if (state.wsize == 0) {
993 state.wsize = 1 << state.wbits;
996 // zlib.js: Sliding window
997 if (out >= state.wsize) {
998 state.window = strm.output_data.substring(out - state.wsize);
1000 if(state.whave + out < state.wsize) {
1001 state.window += strm.output_data;
1003 state.window = state.window.substring(state.whave - (state.wsize - out)) + strm.output_data;
1006 state.whave = state.window.length;
1007 if(state.whave < state.wsize) {
1008 state.wnext = state.whave;
1017function CRC2(strm, word)
1019 var hbuf = [word & 0xff, (word >>> 8) & 0xff];
1020 strm.state.check = strm.checksum_function(strm.state.check, hbuf, 0, 2);
1023function CRC4(strm, word)
1025 var hbuf = [word & 0xff,
1026 (word >>> 8) & 0xff,
1027 (word >>> 16) & 0xff,
1028 (word >>> 24) & 0xff];
1029 strm.state.check = strm.checksum_function(strm.state.check, hbuf, 0, 4);
1032/* Load registers with state in inflate() for speed */
1033function LOAD(strm, s)
1035 s.strm = strm; /* z_stream */
1036 s.left = strm.avail_out; /* available output */
1037 s.next = strm.next_in; /* next input */
1038 s.have = strm.avail_in; /* available input */
1039 s.hold = strm.state.hold; /* bit buffer */
1040 s.bits = strm.state.bits; /* bits in bit buffer */
1044/* Restore state from registers in inflate() */
1048 strm.next_in = s.next;
1049 strm.avail_out = s.left;
1050 strm.avail_in = s.have;
1051 strm.state.hold = s.hold;
1052 strm.state.bits = s.bits;
1055/* Clear the input bit accumulator */
1062/* Get a byte of input into the bit accumulator, or return from inflate()
1063 if there is no input available. */
1066 if (s.have == 0) return false;
1068 s.hold += (s.strm.input_data.charCodeAt(s.next++) & 0xff) << s.bits;
1073/* Assure that there are at least n bits in the bit accumulator. If there is
1074 not enough available input to do that, then return from inflate(). */
1075function NEEDBITS(s, n)
1077 // if(typeof n != 'number') throw 'ERROR';
1078 while (s.bits < n) {
1085/* Return the low n bits of the bit accumulator (n < 16) */
1088 return s.hold & ((1 << n) - 1);
1091/* Remove n bits from the bit accumulator */
1092function DROPBITS(s, n)
1094 // if(typeof n != 'number') throw 'ERROR';
1099/* Remove zero to seven bits as needed to go to a byte boundary */
1102 s.hold >>>= s.bits & 7;
1103 s.bits -= s.bits & 7;
1106/* Reverse the bytes in a 32-bit value */
1109 return ((q >>> 24) & 0xff) +
1110 ((q >>> 8) & 0xff00) +
1111 ((q & 0xff00) << 8) +
1116 inflate() uses a state machine to process as much input data and generate as
1117 much output data as possible before returning. The state machine is
1118 structured roughly as follows:
1120 for (;;) switch (state) {
1123 if (not enough input data or output space to make progress)
1125 ... make progress ...
1131 so when inflate() is called again, the same case is attempted again, and
1132 if the appropriate resources are provided, the machine proceeds to the
1133 next state. The NEEDBITS() macro is usually the way the state evaluates
1134 whether it can proceed or should return. NEEDBITS() does the return if
1135 the requested bits are not available. The typical use of the BITS macros
1139 ... do something with BITS(n) ...
1142 where NEEDBITS(n) either returns from inflate() if there isn't enough
1143 input left to load n bits into the accumulator, or it continues. BITS(n)
1144 gives the low n bits in the accumulator. When done, DROPBITS(n) drops
1145 the low n bits off the accumulator. INITBITS() clears the accumulator
1146 and sets the number of available bits to zero. BYTEBITS() discards just
1147 enough bits to put the accumulator on a byte boundary. After BYTEBITS()
1148 and a NEEDBITS(8), then BITS(8) would return the next byte in the stream.
1150 NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return
1151 if there is no input available. The decoding of variable length codes uses
1152 PULLBYTE() directly in order to pull just enough bytes to decode the next
1155 Some states loop until they get enough input, making sure that enough
1156 state information is maintained to continue the loop where it left off
1157 if NEEDBITS() returns in the loop. For example, want, need, and keep
1158 would all have to actually be part of the saved state in case NEEDBITS()
1162 while (want < need) {
1164 keep[want++] = BITS(n);
1170 As shown above, if the next state is also the next case, then the break
1173 A state may also return if there is not enough output space available to
1174 complete that state. Those states are copying stored data, writing a
1175 literal byte, and copying a matching string.
1177 When returning, a "goto inf_leave" is used to update the total counters,
1178 update the check value, and determine whether any progress has been made
1179 during that inflate() call in order to return the proper return code.
1180 Progress is defined as a change in either strm->avail_in or strm->avail_out.
1181 When there is a window, goto inf_leave will update the window with the last
1182 output written. If a goto inf_leave occurs in the middle of decompression
1183 and there is no window currently, goto inf_leave will create one and copy
1184 output to the window for the next call of inflate().
1186 In this implementation, the flush parameter of inflate() only affects the
1187 return code (per zlib.h). inflate() always writes as much as possible to
1188 strm->next_out, given the space available and the provided input--the effect
1189 documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers
1190 the allocation of and copying into a sliding window until necessary, which
1191 provides the effect documented in zlib.h for Z_FINISH when the entire input
1192 stream available. So the only thing the flush parameter actually does is:
1193 when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it
1194 will return Z_BUF_ERROR if it has not reached the end of the stream.
1197/* permutation of code lengths */
1198var inflate_order = [
1199 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
1200ZLIB.inflate = function(strm, flush)
1204 var _in, out; /* save starting available input and output */
1205 var copy; /* number of stored or match bytes to copy */
1206 var from_window_offset = -1; /* index of window[] */
1207 var from_out_offset = -1; /* index of next_out[] */
1208 var here; /* current decoding table entry */
1209 var last; /* parent table entry */
1210 var len; /* length to copy for repeats, bits to drop */
1211 var ret; /* return code */
1213 if (!strm || !strm.state ||
1214 (!strm.input_data && strm.avail_in != 0))
1215 return ZLIB.Z_STREAM_ERROR;
1218 if (state.mode == TYPE) state.mode = TYPEDO; /* skip check */
1227inf_leave: for (;;) {
1228 switch (state.mode) {
1230 if (state.wrap == 0) {
1231 state.mode = TYPEDO;
1234 if(!NEEDBITS(s, 16)) break inf_leave;
1236 if ((state.wrap & 2) && s.hold == 0x8b1f) { /* gzip header */
1237 state.check = strm.checksum_function(0, null, 0, 0);
1243 state.flags = 0; /* expect zlib header */
1244 if (state.head !== null)
1245 state.head.done = -1;
1246 if (!(state.wrap & 1) || /* check if zlib header allowed */
1250 ((BITS(s, 8) << 8) + (s.hold >>> 8)) % 31) {
1251 strm.msg = 'incorrect header check';
1255 if (BITS(s, 4) != ZLIB.Z_DEFLATED) {
1256 strm.msg = 'unknown compression method';
1262 len = BITS(s, 4) + 8;
1263 if (state.wbits == 0)
1265 else if (len > state.wbits) {
1266 strm.msg = 'invalid window size';
1270 state.dmax = 1 << len;
1271// Tracev((stderr, "inflate: zlib header ok\n"));
1272 strm.adler = state.check = strm.checksum_function(0, null, 0, 0);
1273 state.mode = s.hold & 0x200 ? DICTID : TYPE;
1278 if(!NEEDBITS(s, 16)) break inf_leave;
1279 state.flags = s.hold;
1280 if ((state.flags & 0xff) != ZLIB.Z_DEFLATED) {
1281 strm.msg = "unknown compression method";
1285 if (state.flags & 0xe000) {
1286 strm.msg = "unknown header flags set";
1290 if (state.head !== null)
1291 state.head.text = (s.hold >>> 8) & 1;
1292 if (state.flags & 0x0200) {
1298 if(!NEEDBITS(s, 32)) break inf_leave;
1299 if (state.head !== null)
1300 state.head.time = s.hold;
1301 if (state.flags & 0x0200) {
1307 if(!NEEDBITS(s, 16)) break inf_leave;
1308 if (state.head !== null) {
1309 state.head.xflags = s.hold & 0xff;
1310 state.head.os = s.hold >>> 8;
1312 if (state.flags & 0x0200) {
1318 if (state.flags & 0x0400) {
1319 if(!NEEDBITS(s, 16)) break inf_leave;
1320 state.length = s.hold;
1321 if (state.head !== null) {
1322 state.head.extra_len = s.hold;
1324 if (state.flags & 0x0200) {
1328 state.head.extra = "";
1330 else if (state.head !== null) {
1331 state.head.extra = null;
1335 if (state.flags & 0x0400) {
1336 copy = state.length;
1337 if (copy > s.have) copy = s.have;
1339 if (state.head !== null &&
1340 state.head.extra !== null) {
1341 len = state.head.extra_len - state.length;
1343 zmemcpy(state->head->extra + len, next,
1344 len + copy > state->head->extra_max ?
1345 state->head->extra_max - len : copy);
1347 state.head.extra += strm.input_data.substring(
1348 s.next, s.next + (len + copy > state.head.extra_max ?
1349 state.head.extra_max - len : copy));
1352 if (state.flags & 0x0200)
1353 state.check = strm.checksum_function(state.check, strm.input_data, s.next, copy);
1356 state.length -= copy;
1358 if (state.length) break inf_leave;
1363 if (state.flags & 0x0800) {
1364 if (s.have == 0) break inf_leave;
1365 if (state.head !== null && state.head.name === null) {
1366 state.head.name = "";
1369 // TODO end = strm.input_data.indexOf("\0", s.next);
1370 // TODO state.length => state.head.name.length
1372 len = strm.input_data.charAt(s.next + copy); copy++;
1375 if (state.head !== null &&
1376 state.length < state.head.name_max) {
1377 state.head.name += len;
1380 } while (copy < s.have);
1381 if (state.flags & 0x0200) {
1382 state.check = strm.checksum_function(state.check, strm.input_data, s.next, copy);
1386 if (len !== "\0") break inf_leave;
1388 else if (state.head !== null)
1389 state.head.name = null;
1391 state.mode = COMMENT;
1393 if (state.flags & 0x1000) {
1394 if (s.have == 0) break inf_leave;
1396 if (state.head !== null && state.head.comment === null) {
1397 state.head.comment = "";
1399 // TODO end = strm.input_data.indexOf("\0", s.next);
1400 // TODO state.length => state.head.comment.length
1402 len = strm.input_data.charAt(s.next + copy); copy++;
1405 if (state.head !== null &&
1406 state.length < state.head.comm_max) {
1407 state.head.comment += len;
1410 } while (copy < s.have);
1411 if (state.flags & 0x0200)
1412 state.check = strm.checksum_function(state.check, strm.input_data, s.next, copy);
1415 if (len !== "\0") break inf_leave;
1417 else if (state.head !== null)
1418 state.head.comment = null;
1421 if (state.flags & 0x0200) {
1422 if(!NEEDBITS(s, 16)) break inf_leave;
1423 if (s.hold != (state.check & 0xffff)) {
1424 strm.msg = "header crc mismatch";
1430 if (state.head !== null) {
1431 state.head.hcrc = (state.flags >>> 9) & 1;
1432 state.head.done = 1;
1434 strm.adler = state.check = strm.checksum_function(0, null, 0, 0);
1439 if(!NEEDBITS(s, 32)) break inf_leave;
1440 strm.adler = state.check = REVERSE(s.hold);
1444 if (state.havedict == 0) {
1446 return ZLIB.Z_NEED_DICT;
1448 strm.adler = state.check = strm.checksum_function(0, null, 0, 0);
1451 if (flush == ZLIB.Z_BLOCK || flush == ZLIB.Z_TREES) break inf_leave;
1458 if(!NEEDBITS(s, 3)) break inf_leave;
1459 state.last = BITS(s, 1);
1461 switch (BITS(s, 2)) {
1462 case 0: /* stored block */
1463// Tracev((stderr, "inflate: stored block%s\n",
1464// state->last ? " (last)" : ""));
1465 state.mode = STORED;
1467 case 1: /* fixed block */
1469// Tracev((stderr, "inflate: fixed codes block%s\n",
1470// state->last ? " (last)" : ""));
1471 state.mode = LEN_; /* decode codes */
1472 if (flush == ZLIB.Z_TREES) {
1477 case 2: /* dynamic block */
1478// Tracev((stderr, "inflate: dynamic codes block%s\n",
1479// state->last ? " (last)" : ""));
1483 strm.msg = 'invalid block type';
1489 BYTEBITS(s); /* go to byte boundary */
1490 if(!NEEDBITS(s, 32)) break inf_leave;
1491 if ((s.hold & 0xffff) != (((s.hold >>> 16) & 0xffff) ^ 0xffff)) {
1492 strm.msg = 'invalid stored block lengths';
1496 state.length = s.hold & 0xffff;
1497// Tracev((stderr, "inflate: stored length %u\n",
1501 if (flush == ZLIB.Z_TREES) break inf_leave;
1505 copy = state.length;
1507 if (copy > s.have) copy = s.have;
1508 if (copy > s.left) copy = s.left;
1509 if (copy == 0) break inf_leave;
1510 strm.output_data += strm.input_data.substring(s.next, s.next + copy);
1511 strm.next_out += copy;
1515 state.length -= copy;
1518// Tracev((stderr, "inflate: stored end\n"));
1522 if(!NEEDBITS(s, 14)) break inf_leave;
1523 state.nlen = BITS(s, 5) + 257;
1525 state.ndist = BITS(s, 5) + 1;
1527 state.ncode = BITS(s, 4) + 4;
1529//#ifndef PKZIP_BUG_WORKAROUND
1530 if (state.nlen > 286 || state.ndist > 30) {
1531 strm.msg = 'too many length or distance symbols';
1536// Tracev((stderr, "inflate: table sizes ok\n"));
1538 state.mode = LENLENS;
1540 while (state.have < state.ncode) {
1541 if(!NEEDBITS(s, 3)) break inf_leave;
1542 var tmp = BITS(s, 3);
1543 state.lens[inflate_order[state.have++]] = tmp;
1546 while (state.have < 19)
1547 state.lens[inflate_order[state.have++]] = 0;
1552// ret = inflate_table(CODES, state->lens, 19, &(state->next),
1553// &(state->lenbits), state->work);
1554 ret = inflate_table(state, CODES);
1557 strm.msg = 'invalid code lengths set';
1561// Tracev((stderr, "inflate: code lengths ok\n"));
1563 state.mode = CODELENS;
1565 while (state.have < state.nlen + state.ndist) {
1567 here = state.codes[state.lencode + BITS(s, state.lenbits)];
1568 if (here.bits <= s.bits) break;
1569 if(!PULLBYTE(s)) break inf_leave;
1571 if (here.val < 16) {
1572 DROPBITS(s, here.bits);
1573 state.lens[state.have++] = here.val;
1576 if (here.val == 16) {
1577 if(!NEEDBITS(s, here.bits + 2)) break inf_leave;
1578 DROPBITS(s, here.bits);
1579 if (state.have == 0) {
1580 strm.msg = 'invalid bit length repeat';
1584 len = state.lens[state.have - 1];
1585 copy = 3 + BITS(s, 2);
1588 else if (here.val == 17) {
1589 if(!NEEDBITS(s, here.bits + 3)) break inf_leave;
1590 DROPBITS(s, here.bits);
1592 copy = 3 + BITS(s, 3);
1596 if(!NEEDBITS(s, here.bits + 7)) break inf_leave;
1597 DROPBITS(s, here.bits);
1599 copy = 11 + BITS(s, 7);
1602 if (state.have + copy > state.nlen + state.ndist) {
1603 strm.msg = 'invalid bit length repeat';
1608 state.lens[state.have++] = len;
1612 /* handle error breaks in while */
1613 if (state.mode == BAD) break;
1615 /* check for end-of-block code (better have one) */
1616 if (state.lens[256] == 0) {
1617 strm.msg = 'invalid code -- missing end-of-block';
1622 /* build code tables -- note: do not change the lenbits or distbits
1623 values here (9 and 6) without reading the comments in inftrees.h
1624 concerning the ENOUGH constants, which depend on those values */
1626 state.lencode = state.next;
1628// ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
1629// &(state->lenbits), state->work);
1630 ret = inflate_table(state, LENS);
1632 strm.msg = 'invalid literal/lengths set';
1636 state.distcode = state.next;
1638// ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, &(state->next),
1639// &(state->distbits), state->work);
1640 ret = inflate_table(state, DISTS);
1642 strm.msg = 'invalid distances set';
1646// Tracev((stderr, "inflate: codes ok\n"));
1648 if (flush == ZLIB.Z_TREES) break inf_leave;
1652 if (s.have >= 6 && s.left >= 258) {
1654 inflate_fast(strm, out);
1656 if (state.mode == TYPE)
1662 here = state.codes[state.lencode + BITS(s, state.lenbits)];
1663 if (here.bits <= s.bits) break;
1664 if(!PULLBYTE(s)) break inf_leave;
1666 if (here.op && (here.op & 0xf0) == 0) {
1669 here = state.codes[state.lencode + last.val +
1670 (BITS(s, last.bits + last.op) >>> last.bits)];
1671 if (last.bits + here.bits <= s.bits) break;
1672 if(!PULLBYTE(s)) break inf_leave;
1674 DROPBITS(s, last.bits);
1675 state.back += last.bits;
1677 DROPBITS(s, here.bits);
1678 state.back += here.bits;
1679 state.length = here.val;
1681// Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
1682// "inflate: literal '%c'\n" :
1683// "inflate: literal 0x%02x\n", here.val));
1688// Tracevv((stderr, "inflate: end of block\n"));
1694 strm.msg = 'invalid literal/length code';
1698 state.extra = here.op & 15;
1699 state.mode = LENEXT;
1702 if(!NEEDBITS(s, state.extra)) break inf_leave;
1703 state.length += BITS(s, state.extra);
1704 DROPBITS(s, state.extra);
1705 state.back += state.extra;
1707 //Tracevv((stderr, "inflate: length %u\n", state->length));
1708 state.was = state.length;
1712 here = state.codes[state.distcode + BITS(s, state.distbits)];
1713 if (here.bits <= s.bits) break;
1714 if(!PULLBYTE(s)) break inf_leave;
1716 if ((here.op & 0xf0) == 0) {
1719 here = state.codes[state.distcode + last.val +
1720 (BITS(s, last.bits + last.op) >>> last.bits)];
1721 if ((last.bits + here.bits) <= s.bits) break;
1722 if(!PULLBYTE(s)) break inf_leave;
1724 DROPBITS(s, last.bits);
1725 state.back += last.bits;
1727 DROPBITS(s, here.bits);
1728 state.back += here.bits;
1730 strm.msg = 'invalid distance code';
1734 state.offset = here.val;
1735 state.extra = here.op & 15;
1736 state.mode = DISTEXT;
1739 if(!NEEDBITS(s, state.extra)) break inf_leave;
1740 state.offset += BITS(s, state.extra);
1741 DROPBITS(s, state.extra);
1742 state.back += state.extra;
1744//NOSPRT #ifdef INFLATE_STRICT
1745// if (state->offset > state->dmax) {
1746// strm->msg = (char *)"invalid distance too far back";
1747// state->mode = BAD;
1751// Tracevv((stderr, "inflate: distance %u\n", state->offset));
1754 if (s.left == 0) break inf_leave;
1755 copy = out - s.left;
1756 if (state.offset > copy) { /* copy from window */
1757 copy = state.offset - copy;
1758 if (copy > state.whave) {
1760 strm.msg = 'invalid distance too far back';
1764//NOSPRT #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
1765// Trace((stderr, "inflate.c too far\n"));
1766// copy -= state->whave;
1767// if (copy > state->length) copy = state->length;
1768// if (copy > left) copy = left;
1770// state->length -= copy;
1774// if (state->length == 0) state->mode = LEN;
1778 if (copy > state.wnext) {
1779 copy -= state.wnext;
1780 // from = state->window + (state->wsize - copy);
1781 from_window_offset = state.wsize - copy;
1782 from_out_offset = -1;
1785 // from = state->window + (state->wnext - copy);
1786 from_window_offset = state.wnext - copy;
1787 from_out_offset = -1;
1789 if (copy > state.length) copy = state.length;
1791 else { /* copy from output */
1792 // from = put - state->offset;
1793 from_window_offset = -1;
1794 from_out_offset = strm.next_out - state.offset;
1795 copy = state.length;
1797 if (copy > s.left) copy = s.left;
1799 state.length -= copy;
1800 if( from_window_offset >= 0 ) {
1801 strm.output_data += state.window.substring(from_window_offset, from_window_offset + copy);
1802 strm.next_out += copy;
1805 strm.next_out += copy;
1807 strm.output_data += strm.output_data.charAt(from_out_offset++);
1810 if (state.length == 0) state.mode = LEN;
1813 if (s.left == 0) break inf_leave;
1815 strm.output_data += String.fromCharCode(state.length);
1817 //*put++ = (unsigned char)(state->length);
1824 if(!NEEDBITS(s, 32)) break inf_leave;
1826 strm.total_out += out;
1829 strm.adler = state.check =
1830 strm.checksum_function(state.check, strm.output_data, strm.output_data.length - out, out);
1834 state.flags ? s.hold :
1836 REVERSE(s.hold)) != state.check) {
1837 strm.msg = "incorrect data check";
1842//debug("## inflate: check matches trailer\n");
1843// Tracev((stderr, "inflate: check matches trailer\n"));
1846 state.mode = LENGTH;
1848 if (state.wrap && state.flags) {
1849 if(!NEEDBITS(s, 32)) break inf_leave;
1850 if (s.hold != (state.total & 0xffffffff)) {
1851 strm.msg = 'incorrect length check';
1856 //Tracev((stderr, "inflate: length matches trailer\n"));
1861 ret = ZLIB.Z_STREAM_END;
1864 ret = ZLIB.Z_DATA_ERROR;
1867 return ZLIB.Z_MEM_ERROR;
1870 return ZLIB.Z_STREAM_ERROR;
1874 Return from inflate(), updating the total counts and the check value.
1875 If there was no progress during the inflate() call, return a buffer
1876 error. Call updatewindow() to create and/or update the window state.
1877 Note: a memory error from inflate() is non-recoverable.
1881 if (state.wsize || (out != strm.avail_out && state.mode < BAD &&
1882 (state.mode < CHECK || flush != ZLIB.Z_FINISH)))
1883 if (updatewindow(strm)) {
1885 return ZLIB.Z_MEM_ERROR;
1887 _in -= strm.avail_in;
1888 out -= strm.avail_out;
1889 strm.total_in += _in;
1890 strm.total_out += out;
1892 if (state.wrap && out)
1893 strm.adler = state.check = strm.checksum_function(state.check, strm.output_data, 0, strm.output_data.length);
1894 strm.data_type = state.bits + (state.last ? 64 : 0) +
1895 (state.mode == TYPE ? 128 : 0) +
1896 (state.mode == LEN_ || state.mode == COPY_ ? 256 : 0);
1897 if (((_in == 0 && out == 0) || flush == ZLIB.Z_FINISH) && ret == ZLIB.Z_OK)
1898 ret = ZLIB.Z_BUF_ERROR;
1902ZLIB.inflateEnd = function(strm)
1905 if (!strm || !strm.state )
1906 return ZLIB.Z_STREAM_ERROR;
1908 state.window = null;
1910 // Tracev((stderr, "inflate: end\n"));
1914ZLIB.z_stream.prototype.inflate = function(input_string, opts)
1918 var DEFAULT_BUFFER_SIZE = 16384;
1920 this.input_data = input_string;
1921 this.next_in = getarg(opts, 'next_in', 0);
1922 this.avail_in = getarg(opts, 'avail_in', input_string.length - this.next_in);
1924 flush = getarg(opts, 'flush', ZLIB.Z_SYNC_FLUSH);
1925 avail_out = getarg(opts, 'avail_out', -1);
1929 this.avail_out = (avail_out >= 0 ? avail_out : DEFAULT_BUFFER_SIZE);
1930 this.output_data = '';
1932 this.error = ZLIB.inflate(this, flush);
1933 if(avail_out >= 0) {
1934 return this.output_data;
1936 result += this.output_data;
1937 if(this.avail_out > 0) {
1940 } while(this.error == ZLIB.Z_OK);
1945ZLIB.z_stream.prototype.inflateReset = function(windowBits)
1947 return ZLIB.inflateReset(this, windowBits);