PageSourceSearch

https://ai.xxmu.edu.cn/static/js/html-docx-js/dist/html-docx.js

js xxmu.edu.cn collected 2026-10-02 07:41:23 UTC 551,553 bytes, 13,216 lines download raw bytes

vendor: 148,333 bytes, lines 1-3773
1!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.htmlDocx=e()}}(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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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(_dereq_,module,exports){
2        /*!
3 * The buffer module from node.js, for the browser.
4 *
5 * @author   Feross Aboukhadijeh <[email protected]> <http://feross.org>
6 * @license  MIT
7 */
8
9        var base64 = _dereq_('base64-js')
10        var ieee754 = _dereq_('ieee754')
11        var isArray = _dereq_('is-array')
12
13        exports.Buffer = Buffer
14        exports.SlowBuffer = Buffer
15        exports.INSPECT_MAX_BYTES = 50
16        Buffer.poolSize = 8192 // not used by this implementation
17
18        var kMaxLength = 0x3fffffff
19
20        /**
21         * If `Buffer.TYPED_ARRAY_SUPPORT`:
22         *   === true    Use Uint8Array implementation (fastest)
23         *   === false   Use Object implementation (most compatible, even IE6)
24         *
25         * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
26         * Opera 11.6+, iOS 4.2+.
27         *
28         * Note:
29         *
30         * - Implementation must support adding new properties to `Uint8Array` instances.
31         *   Firefox 4-29 lacked support, fixed in Firefox 30+.
32         *   See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
33         *
34         *  - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
35         *
36         *  - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
37         *    incorrect length in some situations.
38         *
39         * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they will
40         * get the Object implementation, which is slower but will work correctly.
41         */
42        Buffer.TYPED_ARRAY_SUPPORT = (function () {
43            try {
44                var buf = new ArrayBuffer(0)
45                var arr = new Uint8Array(buf)
46                arr.foo = function () { return 42 }
47                return 42 === arr.foo() && // typed array instances can be augmented
48                    typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
49                    new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
50            } catch (e) {
51                return false
52            }
53        })()
54
55        /**
56         * Class: Buffer
57         * =============
58         *
59         * The Buffer constructor returns instances of `Uint8Array` that are augmented
60         * with function properties for all the node `Buffer` API functions. We use
61         * `Uint8Array` so that square bracket notation works as expected -- it returns
62         * a single octet.
63         *
64         * By augmenting the instances, we can avoid modifying the `Uint8Array`
65         * prototype.
66         */
67        function Buffer (subject, encoding, noZero) {
68            if (!(this instanceof Buffer))
69                return new Buffer(subject, encoding, noZero)
70
71            var type = typeof subject
72
73            // Find the length
74            var length
75            if (type === 'number')
76                length = subject > 0 ? subject >>> 0 : 0
77            else if (type === 'string') {
78                if (encoding === 'base64')
79                    subject = base64clean(subject)
80                length = Buffer.byteLength(subject, encoding)
81            } else if (type === 'object' && subject !== null) { // assume object is array-like
82                if (subject.type === 'Buffer' && isArray(subject.data))
83                    subject = subject.data
84                length = +subject.length > 0 ? Math.floor(+subject.length) : 0
85            } else
86                throw new TypeError('must start with number, buffer, array or string')
87
88            if (this.length > kMaxLength)
89                throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
90                    'size: 0x' + kMaxLength.toString(16) + ' bytes')
91
92            var buf
93            if (Buffer.TYPED_ARRAY_SUPPORT) {
94                // Preferred: Return an augmented `Uint8Array` instance for best performance
95                buf = Buffer._augment(new Uint8Array(length))
96            } else {
97                // Fallback: Return THIS instance of Buffer (created by `new`)
98                buf = this
99                buf.length = length
100                buf._isBuffer = true
101            }
102
103            var i
104            if (Buffer.TYPED_ARRAY_SUPPORT && typeof subject.byteLength === 'number') {
105                // Speed optimization -- use set if we're copying from a typed array
106                buf._set(subject)
107            } else if (isArrayish(subject)) {
108                // Treat array-ish objects as a byte array
109                if (Buffer.isBuffer(subject)) {
110                    for (i = 0; i < length; i++)
111                        buf[i] = subject.readUInt8(i)
112                } else {
113                    for (i = 0; i < length; i++)
114                        buf[i] = ((subject[i] % 256) + 256) % 256
115                }
116            } else if (type === 'string') {
117                buf.write(subject, 0, encoding)
118            } else if (type === 'number' && !Buffer.TYPED_ARRAY_SUPPORT && !noZero) {
119                for (i = 0; i < length; i++) {
120                    buf[i] = 0
121                }
122            }
123
124            return buf
125        }
126
127        Buffer.isBuffer = function (b) {
128            return !!(b != null && b._isBuffer)
129        }
130
131        Buffer.compare = function (a, b) {
132            if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b))
133                throw new TypeError('Arguments must be Buffers')
134
135            var x = a.length
136            var y = b.length
137            for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {}
138            if (i !== len) {
139                x = a[i]
140                y = b[i]
141            }
142            if (x < y) return -1
143            if (y < x) return 1
144            return 0
145        }
146
147        Buffer.isEncoding = function (encoding) {
148            switch (String(encoding).toLowerCase()) {
149                case 'hex':
150                case 'utf8':
151                case 'utf-8':
152                case 'ascii':
153                case 'binary':
154                case 'base64':
155                case 'raw':
156                case 'ucs2':
157                case 'ucs-2':
158                case 'utf16le':
159                case 'utf-16le':
160                    return true
161                default:
162                    return false
163            }
164        }
165
166        Buffer.concat = function (list, totalLength) {
167            if (!isArray(list)) throw new TypeError('Usage: Buffer.concat(list[, length])')
168
169            if (list.length === 0) {
170                return new Buffer(0)
171            } else if (list.length === 1) {
172                return list[0]
173            }
174
175            var i
176            if (totalLength === undefined) {
177                totalLength = 0
178                for (i = 0; i < list.length; i++) {
179                    totalLength += list[i].length
180                }
181            }
182
183            var buf = new Buffer(totalLength)
184            var pos = 0
185            for (i = 0; i < list.length; i++) {
186                var item = list[i]
187                item.copy(buf, pos)
188                pos += item.length
189            }
190            return buf
191        }
192
193        Buffer.byteLength = function (str, encoding) {
194            var ret
195            str = str + ''
196            switch (encoding || 'utf8') {
197                case 'ascii':
198                case 'binary':
199                case 'raw':
200                    ret = str.length
201                    break
202                case 'ucs2':
203                case 'ucs-2':
204                case 'utf16le':
205                case 'utf-16le':
206                    ret = str.length * 2
207                    break
208                case 'hex':
209                    ret = str.length >>> 1
210                    break
211                case 'utf8':
212                case 'utf-8':
213                    ret = utf8ToBytes(str).length
214                    break
215                case 'base64':
216                    ret = base64ToBytes(str).length
217                    break
218                default:
219                    ret = str.length
220            }
221            return ret
222        }
223
224// pre-set for values that may exist in the future
225        Buffer.prototype.length = undefined
226        Buffer.prototype.parent = undefined
227
228// toString(encoding, start=0, end=buffer.length)
229        Buffer.prototype.toString = function (encoding, start, end) {
230            var loweredCase = false
231
232            start = start >>> 0
233            end = end === undefined || end === Infinity ? this.length : end >>> 0
234
235            if (!encoding) encoding = 'utf8'
236            if (start < 0) start = 0
237            if (end > this.length) end = this.length
238            if (end <= start) return ''
239
240            while (true) {
241                switch (encoding) {
242                    case 'hex':
243                        return hexSlice(this, start, end)
244
245                    case 'utf8':
246                    case 'utf-8':
247                        return utf8Slice(this, start, end)
248
249                    case 'ascii':
250                        return asciiSlice(this, start, end)
251
252                    case 'binary':
253                        return binarySlice(this, start, end)
254
255                    case 'base64':
256                        return base64Slice(this, start, end)
257
258                    case 'ucs2':
259                    case 'ucs-2':
260                    case 'utf16le':
261                    case 'utf-16le':
262                        return utf16leSlice(this, start, end)
263
264                    default:
265                        if (loweredCase)
266                            throw new TypeError('Unknown encoding: ' + encoding)
267                        encoding = (encoding + '').toLowerCase()
268                        loweredCase = true
269                }
270            }
271        }
272
273        Buffer.prototype.equals = function (b) {
274            if(!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
275            return Buffer.compare(this, b) === 0
276        }
277
278        Buffer.prototype.inspect = function () {
279            var str = ''
280            var max = exports.INSPECT_MAX_BYTES
281            if (this.length > 0) {
282                str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
283                if (this.length > max)
284                    str += ' ... '
285            }
286            return '<Buffer ' + str + '>'
287        }
288
289        Buffer.prototype.compare = function (b) {
290            if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
291            return Buffer.compare(this, b)
292        }
293
294// `get` will be removed in Node 0.13+
295        Buffer.prototype.get = function (offset) {
296            console.log('.get() is deprecated. Access using array indexes instead.')
297            return this.readUInt8(offset)
298        }
299
300// `set` will be removed in Node 0.13+
301        Buffer.prototype.set = function (v, offset) {
302            console.log('.set() is deprecated. Access using array indexes instead.')
303            return this.writeUInt8(v, offset)
304        }
305
306        function hexWrite (buf, string, offset, length) {
307            offset = Number(offset) || 0
308            var remaining = buf.length - offset
309            if (!length) {
310                length = remaining
311            } else {
312                length = Number(length)
313                if (length > remaining) {
314                    length = remaining
315                }
316            }
317
318            // must be an even number of digits
319            var strLen = string.length
320            if (strLen % 2 !== 0) throw new Error('Invalid hex string')
321
322            if (length > strLen / 2) {
323                length = strLen / 2
324            }
325            for (var i = 0; i < length; i++) {
326                var byte = parseInt(string.substr(i * 2, 2), 16)
327                if (isNaN(byte)) throw new Error('Invalid hex string')
328                buf[offset + i] = byte
329            }
330            return i
331        }
332
333        function utf8Write (buf, string, offset, length) {
334            var charsWritten = blitBuffer(utf8ToBytes(string), buf, offset, length)
335            return charsWritten
336        }
337
338        function asciiWrite (buf, string, offset, length) {
339            var charsWritten = blitBuffer(asciiToBytes(string), buf, offset, length)
340            return charsWritten
341        }
342
343        function binaryWrite (buf, string, offset, length) {
344            return asciiWrite(buf, string, offset, length)
345        }
346
347        function base64Write (buf, string, offset, length) {
348            var charsWritten = blitBuffer(base64ToBytes(string), buf, offset, length)
349            return charsWritten
350        }
351
352        function utf16leWrite (buf, string, offset, length) {
353            var charsWritten = blitBuffer(utf16leToBytes(string), buf, offset, length, 2)
354            return charsWritten
355        }
356
357        Buffer.prototype.write = function (string, offset, length, encoding) {
358            // Support both (string, offset, length, encoding)
359            // and the legacy (string, encoding, offset, length)
360            if (isFinite(offset)) {
361                if (!isFinite(length)) {
362                    encoding = length
363                    length = undefined
364                }
365            } else {  // legacy
366                var swap = encoding
367                encoding = offset
368                offset = length
369                length = swap
370            }
371
372            offset = Number(offset) || 0
373            var remaining = this.length - offset
374            if (!length) {
375                length = remaining
376            } else {
377                length = Number(length)
378                if (length > remaining) {
379                    length = remaining
380                }
381            }
382            encoding = String(encoding || 'utf8').toLowerCase()
383
384            var ret
385            switch (encoding) {
386                case 'hex':
387                    ret = hexWrite(this, string, offset, length)
388                    break
389                case 'utf8':
390                case 'utf-8':
391                    ret = utf8Write(this, string, offset, length)
392                    break
393                case 'ascii':
394                    ret = asciiWrite(this, string, offset, length)
395                    break
396                case 'binary':
397                    ret = binaryWrite(this, string, offset, length)
398                    break
399                case 'base64':
400                    ret = base64Write(this, string, offset, length)
401                    break
402                case 'ucs2':
403                case 'ucs-2':
404                case 'utf16le':
405                case 'utf-16le':
406                    ret = utf16leWrite(this, string, offset, length)
407                    break
408                default:
409                    throw new TypeError('Unknown encoding: ' + encoding)
410            }
411            return ret
412        }
413
414        Buffer.prototype.toJSON = function () {
415            return {
416                type: 'Buffer',
417                data: Array.prototype.slice.call(this._arr || this, 0)
418            }
419        }
420
421        function base64Slice (buf, start, end) {
422            if (start === 0 && end === buf.length) {
423                return base64.fromByteArray(buf)
424            } else {
425                return base64.fromByteArray(buf.slice(start, end))
426            }
427        }
428
429        function utf8Slice (buf, start, end) {
430            var res = ''
431            var tmp = ''
432            end = Math.min(buf.length, end)
433
434            for (var i = start; i < end; i++) {
435                if (buf[i] <= 0x7F) {
436                    res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
437                    tmp = ''
438                } else {
439                    tmp += '%' + buf[i].toString(16)
440                }
441            }
442
443            return res + decodeUtf8Char(tmp)
444        }
445
446        function asciiSlice (buf, start, end) {
447            var ret = ''
448            end = Math.min(buf.length, end)
449
450            for (var i = start; i < end; i++) {
451                ret += String.fromCharCode(buf[i])
452            }
453            return ret
454        }
455
456        function binarySlice (buf, start, end) {
457            return asciiSlice(buf, start, end)
458        }
459
460        function hexSlice (buf, start, end) {
461            var len = buf.length
462
463            if (!start || start < 0) start = 0
464            if (!end || end < 0 || end > len) end = len
465
466            var out = ''
467            for (var i = start; i < end; i++) {
468                out += toHex(buf[i])
469            }
470            return out
471        }
472
473        function utf16leSlice (buf, start, end) {
474            var bytes = buf.slice(start, end)
475            var res = ''
476            for (var i = 0; i < bytes.length; i += 2) {
477                res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
478            }
479            return res
480        }
481
482        Buffer.prototype.slice = function (start, end) {
483            var len = this.length
484            start = ~~start
485            end = end === undefined ? len : ~~end
486
487            if (start < 0) {
488                start += len;
489                if (start < 0)
490                    start = 0
491            } else if (start > len) {
492                start = len
493            }
494
495            if (end < 0) {
496                end += len
497                if (end < 0)
498                    end = 0
499            } else if (end > len) {
500                end = len
501            }
502
503            if (end < start)
504                end = start
505
506            if (Buffer.TYPED_ARRAY_SUPPORT) {
507                return Buffer._augment(this.subarray(start, end))
508            } else {
509                var sliceLen = end - start
510                var newBuf = new Buffer(sliceLen, undefined, true)
511                for (var i = 0; i < sliceLen; i++) {
512                    newBuf[i] = this[i + start]
513                }
514                return newBuf
515            }
516        }
517
518        /*
519 * Need to make sure that buffer isn't trying to write out of bounds.
520 */
521        function checkOffset (offset, ext, length) {
522            if ((offset % 1) !== 0 || offset < 0)
523                throw new RangeError('offset is not uint')
524            if (offset + ext > length)
525                throw new RangeError('Trying to access beyond buffer length')
526        }
527
528        Buffer.prototype.readUInt8 = function (offset, noAssert) {
529            if (!noAssert)
530                checkOffset(offset, 1, this.length)
531            return this[offset]
532        }
533
534        Buffer.prototype.readUInt16LE = function (offset, noAssert) {
535            if (!noAssert)
536                checkOffset(offset, 2, this.length)
537            return this[offset] | (this[offset + 1] << 8)
538        }
539
540        Buffer.prototype.readUInt16BE = function (offset, noAssert) {
541            if (!noAssert)
542                checkOffset(offset, 2, this.length)
543            return (this[offset] << 8) | this[offset + 1]
544        }
545
546        Buffer.prototype.readUInt32LE = function (offset, noAssert) {
547            if (!noAssert)
548                checkOffset(offset, 4, this.length)
549
550            return ((this[offset]) |
551                    (this[offset + 1] << 8) |
552                    (this[offset + 2] << 16)) +
553                (this[offset + 3] * 0x1000000)
554        }
555
556        Buffer.prototype.readUInt32BE = function (offset, noAssert) {
557            if (!noAssert)
558                checkOffset(offset, 4, this.length)
559
560            return (this[offset] * 0x1000000) +
561                ((this[offset + 1] << 16) |
562                    (this[offset + 2] << 8) |
563                    this[offset + 3])
564        }
565
566        Buffer.prototype.readInt8 = function (offset, noAssert) {
567            if (!noAssert)
568                checkOffset(offset, 1, this.length)
569            if (!(this[offset] & 0x80))
570                return (this[offset])
571            return ((0xff - this[offset] + 1) * -1)
572        }
573
574        Buffer.prototype.readInt16LE = function (offset, noAssert) {
575            if (!noAssert)
576                checkOffset(offset, 2, this.length)
577            var val = this[offset] | (this[offset + 1] << 8)
578            return (val & 0x8000) ? val | 0xFFFF0000 : val
579        }
580
581        Buffer.prototype.readInt16BE = function (offset, noAssert) {
582            if (!noAssert)
583                checkOffset(offset, 2, this.length)
584            var val = this[offset + 1] | (this[offset] << 8)
585            return (val & 0x8000) ? val | 0xFFFF0000 : val
586        }
587
588        Buffer.prototype.readInt32LE = function (offset, noAssert) {
589            if (!noAssert)
590                checkOffset(offset, 4, this.length)
591
592            return (this[offset]) |
593                (this[offset + 1] << 8) |
594                (this[offset + 2] << 16) |
595                (this[offset + 3] << 24)
596        }
597
598        Buffer.prototype.readInt32BE = function (offset, noAssert) {
599            if (!noAssert)
600                checkOffset(offset, 4, this.length)
601
602            return (this[offset] << 24) |
603                (this[offset + 1] << 16) |
604                (this[offset + 2] << 8) |
605                (this[offset + 3])
606        }
607
608        Buffer.prototype.readFloatLE = function (offset, noAssert) {
609            if (!noAssert)
610                checkOffset(offset, 4, this.length)
611            return ieee754.read(this, offset, true, 23, 4)
612        }
613
614        Buffer.prototype.readFloatBE = function (offset, noAssert) {
615            if (!noAssert)
616                checkOffset(offset, 4, this.length)
617            return ieee754.read(this, offset, false, 23, 4)
618        }
619
620        Buffer.prototype.readDoubleLE = function (offset, noAssert) {
621            if (!noAssert)
622                checkOffset(offset, 8, this.length)
623            return ieee754.read(this, offset, true, 52, 8)
624        }
625
626        Buffer.prototype.readDoubleBE = function (offset, noAssert) {
627            if (!noAssert)
628                checkOffset(offset, 8, this.length)
629            return ieee754.read(this, offset, false, 52, 8)
630        }
631
632        function checkInt (buf, value, offset, ext, max, min) {
633            if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance')
634            if (value > max || value < min) throw new TypeError('value is out of bounds')
635            if (offset + ext > buf.length) throw new TypeError('index out of range')
636        }
637
638        Buffer.prototype.writeUInt8 = function (value, offset, noAssert) {
639            value = +value
640            offset = offset >>> 0
641            if (!noAssert)
642                checkInt(this, value, offset, 1, 0xff, 0)
643            if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
644            this[offset] = value
645            return offset + 1
646        }
647
648        function objectWriteUInt16 (buf, value, offset, littleEndian) {
649            if (value < 0) value = 0xffff + value + 1
650            for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) {
651                buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
652                    (littleEndian ? i : 1 - i) * 8
653            }
654        }
655
656        Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) {
657            value = +value
658            offset = offset >>> 0
659            if (!noAssert)
660                checkInt(this, value, offset, 2, 0xffff, 0)
661            if (Buffer.TYPED_ARRAY_SUPPORT) {
662                this[offset] = value
663                this[offset + 1] = (value >>> 8)
664            } else objectWriteUInt16(this, value, offset, true)
665            return offset + 2
666        }
667
668        Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) {
669            value = +value
670            offset = offset >>> 0
671            if (!noAssert)
672                checkInt(this, value, offset, 2, 0xffff, 0)
673            if (Buffer.TYPED_ARRAY_SUPPORT) {
674                this[offset] = (value >>> 8)
675                this[offset + 1] = value
676            } else objectWriteUInt16(this, value, offset, false)
677            return offset + 2
678        }
679
680        function objectWriteUInt32 (buf, value, offset, littleEndian) {
681            if (value < 0) value = 0xffffffff + value + 1
682            for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) {
683                buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
684            }
685        }
686
687        Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) {
688            value = +value
689            offset = offset >>> 0
690            if (!noAssert)
691                checkInt(this, value, offset, 4, 0xffffffff, 0)
692            if (Buffer.TYPED_ARRAY_SUPPORT) {
693                this[offset + 3] = (value >>> 24)
694                this[offset + 2] = (value >>> 16)
695                this[offset + 1] = (value >>> 8)
696                this[offset] = value
697            } else objectWriteUInt32(this, value, offset, true)
698            return offset + 4
699        }
700
701        Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) {
702            value = +value
703            offset = offset >>> 0
704            if (!noAssert)
705                checkInt(this, value, offset, 4, 0xffffffff, 0)
706            if (Buffer.TYPED_ARRAY_SUPPORT) {
707                this[offset] = (value >>> 24)
708                this[offset + 1] = (value >>> 16)
709                this[offset + 2] = (value >>> 8)
710                this[offset + 3] = value
711            } else objectWriteUInt32(this, value, offset, false)
712            return offset + 4
713        }
714
715        Buffer.prototype.writeInt8 = function (value, offset, noAssert) {
716            value = +value
717            offset = offset >>> 0
718            if (!noAssert)
719                checkInt(this, value, offset, 1, 0x7f, -0x80)
720            if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
721            if (value < 0) value = 0xff + value + 1
722            this[offset] = value
723            return offset + 1
724        }
725
726        Buffer.prototype.writeInt16LE = function (value, offset, noAssert) {
727            value = +value
728            offset = offset >>> 0
729            if (!noAssert)
730                checkInt(this, value, offset, 2, 0x7fff, -0x8000)
731            if (Buffer.TYPED_ARRAY_SUPPORT) {
732                this[offset] = value
733                this[offset + 1] = (value >>> 8)
734            } else objectWriteUInt16(this, value, offset, true)
735            return offset + 2
736        }
737
738        Buffer.prototype.writeInt16BE = function (value, offset, noAssert) {
739            value = +value
740            offset = offset >>> 0
741            if (!noAssert)
742                checkInt(this, value, offset, 2, 0x7fff, -0x8000)
743            if (Buffer.TYPED_ARRAY_SUPPORT) {
744                this[offset] = (value >>> 8)
745                this[offset + 1] = value
746            } else objectWriteUInt16(this, value, offset, false)
747            return offset + 2
748        }
749
750        Buffer.prototype.writeInt32LE = function (value, offset, noAssert) {
751            value = +value
752            offset = offset >>> 0
753            if (!noAssert)
754                checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
755            if (Buffer.TYPED_ARRAY_SUPPORT) {
756                this[offset] = value
757                this[offset + 1] = (value >>> 8)
758                this[offset + 2] = (value >>> 16)
759                this[offset + 3] = (value >>> 24)
760            } else objectWriteUInt32(this, value, offset, true)
761            return offset + 4
762        }
763
764        Buffer.prototype.writeInt32BE = function (value, offset, noAssert) {
765            value = +value
766            offset = offset >>> 0
767            if (!noAssert)
768                checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
769            if (value < 0) value = 0xffffffff + value + 1
770            if (Buffer.TYPED_ARRAY_SUPPORT) {
771                this[offset] = (value >>> 24)
772                this[offset + 1] = (value >>> 16)
773                this[offset + 2] = (value >>> 8)
774                this[offset + 3] = value
775            } else objectWriteUInt32(this, value, offset, false)
776            return offset + 4
777        }
778
779        function checkIEEE754 (buf, value, offset, ext, max, min) {
780            if (value > max || value < min) throw new TypeError('value is out of bounds')
781            if (offset + ext > buf.length) throw new TypeError('index out of range')
782        }
783
784        function writeFloat (buf, value, offset, littleEndian, noAssert) {
785            if (!noAssert)
786                checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
787            ieee754.write(buf, value, offset, littleEndian, 23, 4)
788            return offset + 4
789        }
790
791        Buffer.prototype.writeFloatLE = function (value, offset, noAssert) {
792            return writeFloat(this, value, offset, true, noAssert)
793        }
794
795        Buffer.prototype.writeFloatBE = function (value, offset, noAssert) {
796            return writeFloat(this, value, offset, false, noAssert)
797        }
798
799        function writeDouble (buf, value, offset, littleEndian, noAssert) {
800            if (!noAssert)
801                checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
802            ieee754.write(buf, value, offset, littleEndian, 52, 8)
803            return offset + 8
804        }
805
806        Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) {
807            return writeDouble(this, value, offset, true, noAssert)
808        }
809
810        Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) {
811            return writeDouble(this, value, offset, false, noAssert)
812        }
813
814// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
815        Buffer.prototype.copy = function (target, target_start, start, end) {
816            var source = this
817
818            if (!start) start = 0
819            if (!end && end !== 0) end = this.length
820            if (!target_start) target_start = 0
821
822            // Copy 0 bytes; we're done
823            if (end === start) return
824            if (target.length === 0 || source.length === 0) return
825
826            // Fatal error conditions
827            if (end < start) throw new TypeError('sourceEnd < sourceStart')
828            if (target_start < 0 || target_start >= target.length)
829                throw new TypeError('targetStart out of bounds')
830            if (start < 0 || start >= source.length) throw new TypeError('sourceStart out of bounds')
831            if (end < 0 || end > source.length) throw new TypeError('sourceEnd out of bounds')
832
833            // Are we oob?
834            if (end > this.length)
835                end = this.length
836            if (target.length - target_start < end - start)
837                end = target.length - target_start + start
838
839            var len = end - start
840
841            if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
842                for (var i = 0; i < len; i++) {
843                    target[i + target_start] = this[i + start]
844                }
845            } else {
846                target._set(this.subarray(start, start + len), target_start)
847            }
848        }
849
850// fill(value, start=0, end=buffer.length)
851        Buffer.prototype.fill = function (value, start, end) {
852            if (!value) value = 0
853            if (!start) start = 0
854            if (!end) end = this.length
855
856            if (end < start) throw new TypeError('end < start')
857
858            // Fill 0 bytes; we're done
859            if (end === start) return
860            if (this.length === 0) return
861
862            if (start < 0 || start >= this.length) throw new TypeError('start out of bounds')
863            if (end < 0 || end > this.length) throw new TypeError('end out of bounds')
864
865            var i
866            if (typeof value === 'number') {
867                for (i = start; i < end; i++) {
868                    this[i] = value
869                }
870            } else {
871                var bytes = utf8ToBytes(value.toString())
872                var len = bytes.length
873                for (i = start; i < end; i++) {
874                    this[i] = bytes[i % len]
875                }
876            }
877
878            return this
879        }
880
881        /**
882         * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
883         * Added in Node 0.12. Only available in browsers that support ArrayBuffer.
884         */
885        Buffer.prototype.toArrayBuffer = function () {
886            if (typeof Uint8Array !== 'undefined') {
887                if (Buffer.TYPED_ARRAY_SUPPORT) {
888                    return (new Buffer(this)).buffer
889                } else {
890                    var buf = new Uint8Array(this.length)
891                    for (var i = 0, len = buf.length; i < len; i += 1) {
892                        buf[i] = this[i]
893                    }
894                    return buf.buffer
895                }
896            } else {
897                throw new TypeError('Buffer.toArrayBuffer not supported in this browser')
898            }
899        }
900
901// HELPER FUNCTIONS
902// ================
903
904        var BP = Buffer.prototype
905
906        /**
907         * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods
908         */
909        Buffer._augment = function (arr) {
910            arr.constructor = Buffer
911            arr._isBuffer = true
912
913            // save reference to original Uint8Array get/set methods before overwriting
914            arr._get = arr.get
915            arr._set = arr.set
916
917            // deprecated, will be removed in node 0.13+
918            arr.get = BP.get
919            arr.set = BP.set
920
921            arr.write = BP.write
922            arr.toString = BP.toString
923            arr.toLocaleString = BP.toString
924            arr.toJSON = BP.toJSON
925            arr.equals = BP.equals
926            arr.compare = BP.compare
927            arr.copy = BP.copy
928            arr.slice = BP.slice
929            arr.readUInt8 = BP.readUInt8
930            arr.readUInt16LE = BP.readUInt16LE
931            arr.readUInt16BE = BP.readUInt16BE
932            arr.readUInt32LE = BP.readUInt32LE
933            arr.readUInt32BE = BP.readUInt32BE
934            arr.readInt8 = BP.readInt8
935            arr.readInt16LE = BP.readInt16LE
936            arr.readInt16BE = BP.readInt16BE
937            arr.readInt32LE = BP.readInt32LE
938            arr.readInt32BE = BP.readInt32BE
939            arr.readFloatLE = BP.readFloatLE
940            arr.readFloatBE = BP.readFloatBE
941            arr.readDoubleLE = BP.readDoubleLE
942            arr.readDoubleBE = BP.readDoubleBE
943            arr.writeUInt8 = BP.writeUInt8
944            arr.writeUInt16LE = BP.writeUInt16LE
945            arr.writeUInt16BE = BP.writeUInt16BE
946            arr.writeUInt32LE = BP.writeUInt32LE
947            arr.writeUInt32BE = BP.writeUInt32BE
948            arr.writeInt8 = BP.writeInt8
949            arr.writeInt16LE = BP.writeInt16LE
950            arr.writeInt16BE = BP.writeInt16BE
951            arr.writeInt32LE = BP.writeInt32LE
952            arr.writeInt32BE = BP.writeInt32BE
953            arr.writeFloatLE = BP.writeFloatLE
954            arr.writeFloatBE = BP.writeFloatBE
955            arr.writeDoubleLE = BP.writeDoubleLE
956            arr.writeDoubleBE = BP.writeDoubleBE
957            arr.fill = BP.fill
958            arr.inspect = BP.inspect
959            arr.toArrayBuffer = BP.toArrayBuffer
960
961            return arr
962        }
963
964        var INVALID_BASE64_RE = /[^+\/0-9A-z]/g
965
966        function base64clean (str) {
967            // Node strips out invalid characters like \n and \t from the string, base64-js does not
968            str = stringtrim(str).replace(INVALID_BASE64_RE, '')
969            // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
970            while (str.length % 4 !== 0) {
971                str = str + '='
972            }
973            return str
974        }
975
976        function stringtrim (str) {
977            if (str.trim) return str.trim()
978            return str.replace(/^\s+|\s+$/g, '')
979        }
980
981        function isArrayish (subject) {
982            return isArray(subject) || Buffer.isBuffer(subject) ||
983                subject && typeof subject === 'object' &&
984                typeof subject.length === 'number'
985        }
986
987        function toHex (n) {
988            if (n < 16) return '0' + n.toString(16)
989            return n.toString(16)
990        }
991
992        function utf8ToBytes (str) {
993            var byteArray = []
994            for (var i = 0; i < str.length; i++) {
995                var b = str.charCodeAt(i)
996                if (b <= 0x7F) {
997                    byteArray.push(b)
998                } else {
999                    var start = i
1000                    if (b >= 0xD800 && b <= 0xDFFF) i++
1001                    var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%')
1002                    for (var j = 0; j < h.length; j++) {
1003                        byteArray.push(parseInt(h[j], 16))
1004                    }
1005                }
1006            }
1007            return byteArray
1008        }
1009
1010        function asciiToBytes (str) {
1011            var byteArray = []
1012            for (var i = 0; i < str.length; i++) {
1013                // Node's code seems to be doing this and not & 0x7F..
1014                byteArray.push(str.charCodeAt(i) & 0xFF)
1015            }
1016            return byteArray
1017        }
1018
1019        function utf16leToBytes (str) {
1020            var c, hi, lo
1021            var byteArray = []
1022            for (var i = 0; i < str.length; i++) {
1023                c = str.charCodeAt(i)
1024                hi = c >> 8
1025                lo = c % 256
1026                byteArray.push(lo)
1027                byteArray.push(hi)
1028            }
1029
1030            return byteArray
1031        }
1032
1033        function base64ToBytes (str) {
1034            return base64.toByteArray(str)
1035        }
1036
1037        function blitBuffer (src, dst, offset, length, unitSize) {
1038            if (unitSize) length -= length % unitSize;
1039            for (var i = 0; i < length; i++) {
1040                if ((i + offset >= dst.length) || (i >= src.length))
1041                    break
1042                dst[i + offset] = src[i]
1043            }
1044            return i
1045        }
1046
1047        function decodeUtf8Char (str) {
1048            try {
1049                return decodeURIComponent(str)
1050            } catch (err) {
1051                return String.fromCharCode(0xFFFD) // UTF 8 invalid char
1052            }
1053        }
1054
1055    },{"base64-js":2,"ieee754":3,"is-array":4}],2:[function(_dereq_,module,exports){
1056        var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
1057
1058        ;(function (exports) {
1059            'use strict';
1060
1061            var Arr = (typeof Uint8Array !== 'undefined')
1062                ? Uint8Array
1063                : Array
1064
1065            var PLUS   = '+'.charCodeAt(0)
1066            var SLASH  = '/'.charCodeAt(0)
1067            var NUMBER = '0'.charCodeAt(0)
1068            var LOWER  = 'a'.charCodeAt(0)
1069            var UPPER  = 'A'.charCodeAt(0)
1070
1071            function decode (elt) {
1072                var code = elt.charCodeAt(0)
1073                if (code === PLUS)
1074                    return 62 // '+'
1075                if (code === SLASH)
1076                    return 63 // '/'
1077                if (code < NUMBER)
1078                    return -1 //no match
1079                if (code < NUMBER + 10)
1080                    return code - NUMBER + 26 + 26
1081                if (code < UPPER + 26)
1082                    return code - UPPER
1083                if (code < LOWER + 26)
1084                    return code - LOWER + 26
1085            }
1086
1087            function b64ToByteArray (b64) {
1088                var i, j, l, tmp, placeHolders, arr
1089
1090                if (b64.length % 4 > 0) {
1091                    throw new Error('Invalid string. Length must be a multiple of 4')
1092                }
1093
1094                // the number of equal signs (place holders)
1095                // if there are two placeholders, than the two characters before it
1096                // represent one byte
1097                // if there is only one, then the three characters before it represent 2 bytes
1098                // this is just a cheap hack to not do indexOf twice
1099                var len = b64.length
1100                placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
1101
1102                // base64 is 4/3 + up to two characters of the original data
1103                arr = new Arr(b64.length * 3 / 4 - placeHolders)
1104
1105                // if there are placeholders, only get up to the last complete 4 chars
1106                l = placeHolders > 0 ? b64.length - 4 : b64.length
1107
1108                var L = 0
1109
1110                function push (v) {
1111                    arr[L++] = v
1112                }
1113
1114                for (i = 0, j = 0; i < l; i += 4, j += 3) {
1115                    tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
1116                    push((tmp & 0xFF0000) >> 16)
1117                    push((tmp & 0xFF00) >> 8)
1118                    push(tmp & 0xFF)
1119                }
1120
1121                if (placeHolders === 2) {
1122                    tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
1123                    push(tmp & 0xFF)
1124                } else if (placeHolders === 1) {
1125                    tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
1126                    push((tmp >> 8) & 0xFF)
1127                    push(tmp & 0xFF)
1128                }
1129
1130                return arr
1131            }
1132
1133            function uint8ToBase64 (uint8) {
1134                var i,
1135                    extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
1136                    output = "",
1137                    temp, length
1138
1139                function encode (num) {
1140                    return lookup.charAt(num)
1141                }
1142
1143                function tripletToBase64 (num) {
1144                    return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
1145                }
1146
1147                // go through the array every three bytes, we'll deal with trailing stuff later
1148                for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
1149                    temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
1150                    output += tripletToBase64(temp)
1151                }
1152
1153                // pad the end with zeros, but make sure to not forget the extra bytes
1154                switch (extraBytes) {
1155                    case 1:
1156                        temp = uint8[uint8.length - 1]
1157                        output += encode(temp >> 2)
1158                        output += encode((temp << 4) & 0x3F)
1159                        output += '=='
1160                        break
1161                    case 2:
1162                        temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
1163                        output += encode(temp >> 10)
1164                        output += encode((temp >> 4) & 0x3F)
1165                        output += encode((temp << 2) & 0x3F)
1166                        output += '='
1167                        break
1168                }
1169
1170                return output
1171            }
1172
1173            exports.toByteArray = b64ToByteArray
1174            exports.fromByteArray = uint8ToBase64
1175        }(typeof exports === 'undefined' ? (this.base64js = {}) : exports))
1176
1177    },{}],3:[function(_dereq_,module,exports){
1178        exports.read = function (buffer, offset, isLE, mLen, nBytes) {
1179            var e, m
1180            var eLen = nBytes * 8 - mLen - 1
1181            var eMax = (1 << eLen) - 1
1182            var eBias = eMax >> 1
1183            var nBits = -7
1184            var i = isLE ? (nBytes - 1) : 0
1185            var d = isLE ? -1 : 1
1186            var s = buffer[offset + i]
1187
1188            i += d
1189
1190            e = s & ((1 << (-nBits)) - 1)
1191            s >>= (-nBits)
1192            nBits += eLen
1193            for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
1194
1195            m = e & ((1 << (-nBits)) - 1)
1196            e >>= (-nBits)
1197            nBits += mLen
1198            for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
1199
1200            if (e === 0) {
1201                e = 1 - eBias
1202            } else if (e === eMax) {
1203                return m ? NaN : ((s ? -1 : 1) * Infinity)
1204            } else {
1205                m = m + Math.pow(2, mLen)
1206                e = e - eBias
1207            }
1208            return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
1209        }
1210
1211        exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
1212            var e, m, c
1213            var eLen = nBytes * 8 - mLen - 1
1214            var eMax = (1 << eLen) - 1
1215            var eBias = eMax >> 1
1216            var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
1217            var i = isLE ? 0 : (nBytes - 1)
1218            var d = isLE ? 1 : -1
1219            var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
1220
1221            value = Math.abs(value)
1222
1223            if (isNaN(value) || value === Infinity) {
1224                m = isNaN(value) ? 1 : 0
1225                e = eMax
1226            } else {
1227                e = Math.floor(Math.log(value) / Math.LN2)
1228                if (value * (c = Math.pow(2, -e)) < 1) {
1229                    e--
1230                    c *= 2
1231                }
1232                if (e + eBias >= 1) {
1233                    value += rt / c
1234                } else {
1235                    value += rt * Math.pow(2, 1 - eBias)
1236                }
1237                if (value * c >= 2) {
1238                    e++
1239                    c /= 2
1240                }
1241
1242                if (e + eBias >= eMax) {
1243                    m = 0
1244                    e = eMax
1245                } else if (e + eBias >= 1) {
1246                    m = (value * c - 1) * Math.pow(2, mLen)
1247                    e = e + eBias
1248                } else {
1249                    m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
1250                    e = 0
1251                }
1252            }
1253
1254            for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
1255
1256            e = (e << mLen) | m
1257            eLen += mLen
1258            for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
1259
1260            buffer[offset + i - d] |= s * 128
1261        }
1262
1263    },{}],4:[function(_dereq_,module,exports){
1264
1265        /**
1266         * isArray
1267         */
1268
1269        var isArray = Array.isArray;
1270
1271        /**
1272         * toString
1273         */
1274
1275        var str = Object.prototype.toString;
1276
1277        /**
1278         * Whether or not the given `val`
1279         * is an array.
1280         *
1281         * example:
1282         *
1283         *        isArray([]);
1284         *        // > true
1285         *        isArray(arguments);
1286         *        // > false
1287         *        isArray('');
1288         *        // > false
1289         *
1290         * @param {mixed} val
1291         * @return {bool}
1292         */
1293
1294        module.exports = isArray || function (val) {
1295            return !! val && '[object Array]' == str.call(val);
1296        };
1297
1298    },{}],5:[function(_dereq_,module,exports){
1299        'use strict';
1300        var DataReader = _dereq_('./dataReader');
1301
1302        function ArrayReader(data) {
1303            if (data) {
1304                this.data = data;
1305                this.length = this.data.length;
1306                this.index = 0;
1307                this.zero = 0;
1308
1309                for(var i = 0; i < this.data.length; i++) {
1310                    data[i] = data[i] & 0xFF;
1311                }
1312            }
1313        }
1314        ArrayReader.prototype = new DataReader();
1315        /**
1316         * @see DataReader.byteAt
1317         */
1318        ArrayReader.prototype.byteAt = function(i) {
1319            return this.data[this.zero + i];
1320        };
1321        /**
1322         * @see DataReader.lastIndexOfSignature
1323         */
1324        ArrayReader.prototype.lastIndexOfSignature = function(sig) {
1325            var sig0 = sig.charCodeAt(0),
1326                sig1 = sig.charCodeAt(1),
1327                sig2 = sig.charCodeAt(2),
1328                sig3 = sig.charCodeAt(3);
1329            for (var i = this.length - 4; i >= 0; --i) {
1330                if (this.data[i] === sig0 && this.data[i + 1] === sig1 && this.data[i + 2] === sig2 && this.data[i + 3] === sig3) {
1331                    return i - this.zero;
1332                }
1333            }
1334
1335            return -1;
1336        };
1337        /**
1338         * @see DataReader.readData
1339         */
1340        ArrayReader.prototype.readData = function(size) {
1341            this.checkOffset(size);
1342            if(size === 0) {
1343                return [];
1344            }
1345            var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
1346            this.index += size;
1347            return result;
1348        };
1349        module.exports = ArrayReader;
1350
1351    },{"./dataReader":10}],6:[function(_dereq_,module,exports){
1352        'use strict';
1353// private property
1354        var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
1355
1356
1357// public method for encoding
1358        exports.encode = function(input, utf8) {
1359            var output = "";
1360            var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
1361            var i = 0;
1362
1363            while (i < input.length) {
1364
1365                chr1 = input.charCodeAt(i++);
1366                chr2 = input.charCodeAt(i++);
1367                chr3 = input.charCodeAt(i++);
1368
1369                enc1 = chr1 >> 2;
1370                enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
1371                enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
1372                enc4 = chr3 & 63;
1373
1374                if (isNaN(chr2)) {
1375                    enc3 = enc4 = 64;
1376                }
1377                else if (isNaN(chr3)) {
1378                    enc4 = 64;
1379                }
1380
1381                output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
1382
1383            }
1384
1385            return output;
1386        };
1387
1388// public method for decoding
1389        exports.decode = function(input, utf8) {
1390            var output = "";
1391            var chr1, chr2, chr3;
1392            var enc1, enc2, enc3, enc4;
1393            var i = 0;
1394
1395            input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
1396
1397            while (i < input.length) {
1398
1399                enc1 = _keyStr.indexOf(input.charAt(i++));
1400                enc2 = _keyStr.indexOf(input.charAt(i++));
1401                enc3 = _keyStr.indexOf(input.charAt(i++));
1402                enc4 = _keyStr.indexOf(input.charAt(i++));
1403
1404                chr1 = (enc1 << 2) | (enc2 >> 4);
1405                chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
1406                chr3 = ((enc3 & 3) << 6) | enc4;
1407
1408                output = output + String.fromCharCode(chr1);
1409
1410                if (enc3 != 64) {
1411                    output = output + String.fromCharCode(chr2);
1412                }
1413                if (enc4 != 64) {
1414                    output = output + String.fromCharCode(chr3);
1415                }
1416
1417            }
1418
1419            return output;
1420
1421        };
1422
1423    },{}],7:[function(_dereq_,module,exports){
1424        'use strict';
1425        function CompressedObject() {
1426            this.compressedSize = 0;
1427            this.uncompressedSize = 0;
1428            this.crc32 = 0;
1429            this.compressionMethod = null;
1430            this.compressedContent = null;
1431        }
1432
1433        CompressedObject.prototype = {
1434            /**
1435             * Return the decompressed content in an unspecified format.
1436             * The format will depend on the decompressor.
1437             * @return {Object} the decompressed content.
1438             */
1439            getContent: function() {
1440                return null; // see implementation
1441            },
1442            /**
1443             * Return the compressed content in an unspecified format.
1444             * The format will depend on the compressed conten source.
1445             * @return {Object} the compressed content.
1446             */
1447            getCompressedContent: function() {
1448                return null; // see implementation
1449            }
1450        };
1451        module.exports = CompressedObject;
1452
1453    },{}],8:[function(_dereq_,module,exports){
1454        'use strict';
1455        exports.STORE = {
1456            magic: "\x00\x00",
1457            compress: function(content, compressionOptions) {
1458                return content; // no compression
1459            },
1460            uncompress: function(content) {
1461                return content; // no compression
1462            },
1463            compressInputType: null,
1464            uncompressInputType: null
1465        };
1466        exports.DEFLATE = _dereq_('./flate');
1467
1468    },{"./flate":13}],9:[function(_dereq_,module,exports){
1469        'use strict';
1470
1471        var utils = _dereq_('./utils');
1472
1473        var table = [
1474            0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
1475            0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
1476            0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
1477            0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
1478            0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
1479            0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
1480            0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
1481            0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
1482            0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
1483            0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
1484            0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
1485            0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
1486            0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
1487            0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
1488            0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
1489            0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
1490            0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
1491            0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
1492            0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
1493            0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
1494            0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
1495            0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
1496            0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
1497            0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
1498            0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
1499            0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
1500            0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
1501            0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
1502            0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
1503            0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
1504            0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
1505            0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
1506            0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
1507            0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
1508            0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
1509            0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
1510            0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
1511            0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
1512            0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
1513            0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
1514            0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
1515            0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
1516            0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
1517            0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
1518            0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
1519            0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
1520            0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
1521            0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
1522            0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
1523            0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
1524            0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
1525            0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
1526            0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
1527            0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
1528            0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
1529            0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
1530            0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
1531            0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
1532            0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
1533            0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
1534            0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
1535            0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
1536            0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
1537            0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
1538        ];
1539
1540        /**
1541         *
1542         *  Javascript crc32
1543         *  http://www.webtoolkit.info/
1544         *
1545         */
1546        module.exports = function crc32(input, crc) {
1547            if (typeof input === "undefined" || !input.length) {
1548                return 0;
1549            }
1550
1551            var isArray = utils.getTypeOf(input) !== "string";
1552
1553            if (typeof(crc) == "undefined") {
1554                crc = 0;
1555            }
1556            var x = 0;
1557            var y = 0;
1558            var b = 0;
1559
1560            crc = crc ^ (-1);
1561            for (var i = 0, iTop = input.length; i < iTop; i++) {
1562                b = isArray ? input[i] : input.charCodeAt(i);
1563                y = (crc ^ b) & 0xFF;
1564                x = table[y];
1565                crc = (crc >>> 8) ^ x;
1566            }
1567
1568            return crc ^ (-1);
1569        };
1570// vim: set shiftwidth=4 softtabstop=4:
1571
1572    },{"./utils":26}],10:[function(_dereq_,module,exports){
1573        'use strict';
1574        var utils = _dereq_('./utils');
1575
1576        function DataReader(data) {
1577            this.data = null; // type : see implementation
1578            this.length = 0;
1579            this.index = 0;
1580            this.zero = 0;
1581        }
1582        DataReader.prototype = {
1583            /**
1584             * Check that the offset will not go too far.
1585             * @param {string} offset the additional offset to check.
1586             * @throws {Error} an Error if the offset is out of bounds.
1587             */
1588            checkOffset: function(offset) {
1589                this.checkIndex(this.index + offset);
1590            },
1591            /**
1592             * Check that the specifed index will not be too far.
1593             * @param {string} newIndex the index to check.
1594             * @throws {Error} an Error if the index is out of bounds.
1595             */
1596            checkIndex: function(newIndex) {
1597                if (this.length < this.zero + newIndex || newIndex < 0) {
1598                    throw new Error("End of data reached (data length = " + this.length + ", asked index = " + (newIndex) + "). Corrupted zip ?");
1599                }
1600            },
1601            /**
1602             * Change the index.
1603             * @param {number} newIndex The new index.
1604             * @throws {Error} if the new index is out of the data.
1605             */
1606            setIndex: function(newIndex) {
1607                this.checkIndex(newIndex);
1608                this.index = newIndex;
1609            },
1610            /**
1611             * Skip the next n bytes.
1612             * @param {number} n the number of bytes to skip.
1613             * @throws {Error} if the new index is out of the data.
1614             */
1615            skip: function(n) {
1616                this.setIndex(this.index + n);
1617            },
1618            /**
1619             * Get the byte at the specified index.
1620             * @param {number} i the index to use.
1621             * @return {number} a byte.
1622             */
1623            byteAt: function(i) {
1624                // see implementations
1625            },
1626            /**
1627             * Get the next number with a given byte size.
1628             * @param {number} size the number of bytes to read.
1629             * @return {number} the corresponding number.
1630             */
1631            readInt: function(size) {
1632                var result = 0,
1633                    i;
1634                this.checkOffset(size);
1635                for (i = this.index + size - 1; i >= this.index; i--) {
1636                    result = (result << 8) + this.byteAt(i);
1637                }
1638                this.index += size;
1639                return result;
1640            },
1641            /**
1642             * Get the next string with a given byte size.
1643             * @param {number} size the number of bytes to read.
1644             * @return {string} the corresponding string.
1645             */
1646            readString: function(size) {
1647                return utils.transformTo("string", this.readData(size));
1648            },
1649            /**
1650             * Get raw data without conversion, <size> bytes.
1651             * @param {number} size the number of bytes to read.
1652             * @return {Object} the raw data, implementation specific.
1653             */
1654            readData: function(size) {
1655                // see implementations
1656            },
1657            /**
1658             * Find the last occurence of a zip signature (4 bytes).
1659             * @param {string} sig the signature to find.
1660             * @return {number} the index of the last occurence, -1 if not found.
1661             */
1662            lastIndexOfSignature: function(sig) {
1663                // see implementations
1664            },
1665            /**
1666             * Get the next date.
1667             * @return {Date} the date.
1668             */
1669            readDate: function() {
1670                var dostime = this.readInt(4);
1671                return new Date(
1672                    ((dostime >> 25) & 0x7f) + 1980, // year
1673                    ((dostime >> 21) & 0x0f) - 1, // month
1674                    (dostime >> 16) & 0x1f, // day
1675                    (dostime >> 11) & 0x1f, // hour
1676                    (dostime >> 5) & 0x3f, // minute
1677                    (dostime & 0x1f) << 1); // second
1678            }
1679        };
1680        module.exports = DataReader;
1681
1682    },{"./utils":26}],11:[function(_dereq_,module,exports){
1683        'use strict';
1684        exports.base64 = false;
1685        exports.binary = false;
1686        exports.dir = false;
1687        exports.createFolders = false;
1688        exports.date = null;
1689        exports.compression = null;
1690        exports.compressionOptions = null;
1691        exports.comment = null;
1692        exports.unixPermissions = null;
1693        exports.dosPermissions = null;
1694
1695    },{}],12:[function(_dereq_,module,exports){
1696        'use strict';
1697        var utils = _dereq_('./utils');
1698
1699        /**
1700         * @deprecated
1701         * This function will be removed in a future version without replacement.
1702         */
1703        exports.string2binary = function(str) {
1704            return utils.string2binary(str);
1705        };
1706
1707        /**
1708         * @deprecated
1709         * This function will be removed in a future version without replacement.
1710         */
1711        exports.string2Uint8Array = function(str) {
1712            return utils.transformTo("uint8array", str);
1713        };
1714
1715        /**
1716         * @deprecated
1717         * This function will be removed in a future version without replacement.
1718         */
1719        exports.uint8Array2String = function(array) {
1720            return utils.transformTo("string", array);
1721        };
1722
1723        /**
1724         * @deprecated
1725         * This function will be removed in a future version without replacement.
1726         */
1727        exports.string2Blob = function(str) {
1728            var buffer = utils.transformTo("arraybuffer", str);
1729            return utils.arrayBuffer2Blob(buffer);
1730        };
1731
1732        /**
1733         * @deprecated
1734         * This function will be removed in a future version without replacement.
1735         */
1736        exports.arrayBuffer2Blob = function(buffer) {
1737            return utils.arrayBuffer2Blob(buffer);
1738        };
1739
1740        /**
1741         * @deprecated
1742         * This function will be removed in a future version without replacement.
1743         */
1744        exports.transformTo = function(outputType, input) {
1745            return utils.transformTo(outputType, input);
1746        };
1747
1748        /**
1749         * @deprecated
1750         * This function will be removed in a future version without replacement.
1751         */
1752        exports.getTypeOf = function(input) {
1753            return utils.getTypeOf(input);
1754        };
1755
1756        /**
1757         * @deprecated
1758         * This function will be removed in a future version without replacement.
1759         */
1760        exports.checkSupport = function(type) {
1761            return utils.checkSupport(type);
1762        };
1763
1764        /**
1765         * @deprecated
1766         * This value will be removed in a future version without replacement.
1767         */
1768        exports.MAX_VALUE_16BITS = utils.MAX_VALUE_16BITS;
1769
1770        /**
1771         * @deprecated
1772         * This value will be removed in a future version without replacement.
1773         */
1774        exports.MAX_VALUE_32BITS = utils.MAX_VALUE_32BITS;
1775
1776
1777        /**
1778         * @deprecated
1779         * This function will be removed in a future version without replacement.
1780         */
1781        exports.pretty = function(str) {
1782            return utils.pretty(str);
1783        };
1784
1785        /**
1786         * @deprecated
1787         * This function will be removed in a future version without replacement.
1788         */
1789        exports.findCompression = function(compressionMethod) {
1790            return utils.findCompression(compressionMethod);
1791        };
1792
1793        /**
1794         * @deprecated
1795         * This function will be removed in a future version without replacement.
1796         */
1797        exports.isRegExp = function (object) {
1798            return utils.isRegExp(object);
1799        };
1800
1801
1802    },{"./utils":26}],13:[function(_dereq_,module,exports){
1803        'use strict';
1804        var USE_TYPEDARRAY = (typeof Uint8Array !== 'undefined') && (typeof Uint16Array !== 'undefined') && (typeof Uint32Array !== 'undefined');
1805
1806        var pako = _dereq_("pako");
1807        exports.uncompressInputType = USE_TYPEDARRAY ? "uint8array" : "array";
1808        exports.compressInputType = USE_TYPEDARRAY ? "uint8array" : "array";
1809
1810        exports.magic = "\x08\x00";
1811        exports.compress = function(input, compressionOptions) {
1812            return pako.deflateRaw(input, {
1813                level : compressionOptions.level || -1 // default compression
1814            });
1815        };
1816        exports.uncompress =  function(input) {
1817            return pako.inflateRaw(input);
1818        };
1819
1820    },{"pako":29}],14:[function(_dereq_,module,exports){
1821        'use strict';
1822
1823        var base64 = _dereq_('./base64');
1824
1825        /**
1826         Usage:
1827         zip = new JSZip();
1828         zip.file("hello.txt", "Hello, World!").file("tempfile", "nothing");
1829         zip.folder("images").file("smile.gif", base64Data, {base64: true});
1830         zip.file("Xmas.txt", "Ho ho ho !", {date : new Date("December 25, 2007 00:00:01")});
1831         zip.remove("tempfile");
1832
1833         base64zip = zip.generate();
1834
1835         **/
1836
1837        /**
1838         * Representation a of zip file in js
1839         * @constructor
1840         * @param {String=|ArrayBuffer=|Uint8Array=} data the data to load, if any (optional).
1841         * @param {Object=} options the options for creating this objects (optional).
1842         */
1843        function JSZip(data, options) {
1844            // if this constructor is used without `new`, it adds `new` before itself:
1845            if(!(this instanceof JSZip)) return new JSZip(data, options);
1846
1847            // object containing the files :
1848            // {
1849            //   "folder/" : {...},
1850            //   "folder/data.txt" : {...}
1851            // }
1852            this.files = {};
1853
1854            this.comment = null;
1855
1856            // Where we are in the hierarchy
1857            this.root = "";
1858            if (data) {
1859                this.load(data, options);
1860            }
1861            this.clone = function() {
1862                var newObj = new JSZip();
1863                for (var i in this) {
1864                    if (typeof this[i] !== "function") {
1865                        newObj[i] = this[i];
1866                    }
1867                }
1868                return newObj;
1869            };
1870        }
1871        JSZip.prototype = _dereq_('./object');
1872        JSZip.prototype.load = _dereq_('./load');
1873        JSZip.support = _dereq_('./support');
1874        JSZip.defaults = _dereq_('./defaults');
1875
1876        /**
1877         * @deprecated
1878         * This namespace will be removed in a future version without replacement.
1879         */
1880        JSZip.utils = _dereq_('./deprecatedPublicUtils');
1881
1882        JSZip.base64 = {
1883            /**
1884             * @deprecated
1885             * This method will be removed in a future version without replacement.
1886             */
1887            encode : function(input) {
1888                return base64.encode(input);
1889            },
1890            /**
1891             * @deprecated
1892             * This method will be removed in a future version without replacement.
1893             */
1894            decode : function(input) {
1895                return base64.decode(input);
1896            }
1897        };
1898        JSZip.compressions = _dereq_('./compressions');
1899        module.exports = JSZip;
1900
1901    },{"./base64":6,"./compressions":8,"./defaults":11,"./deprecatedPublicUtils":12,"./load":15,"./object":18,"./support":22}],15:[function(_dereq_,module,exports){
1902        'use strict';
1903        var base64 = _dereq_('./base64');
1904        var utf8 = _dereq_('./utf8');
1905        var utils = _dereq_('./utils');
1906        var ZipEntries = _dereq_('./zipEntries');
1907        module.exports = function(data, options) {
1908            var files, zipEntries, i, input;
1909            options = utils.extend(options || {}, {
1910                base64: false,
1911                checkCRC32: false,
1912                optimizedBinaryString : false,
1913                createFolders: false,
1914                decodeFileName: utf8.utf8decode
1915            });
1916            if (options.base64) {
1917                data = base64.decode(data);
1918            }
1919
1920            zipEntries = new ZipEntries(data, options);
1921            files = zipEntries.files;
1922            for (i = 0; i < files.length; i++) {
1923                input = files[i];
1924                this.file(input.fileNameStr, input.decompressed, {
1925                    binary: true,
1926                    optimizedBinaryString: true,
1927                    date: input.date,
1928                    dir: input.dir,
1929                    comment : input.fileCommentStr.length ? input.fileCommentStr : null,
1930                    unixPermissions : input.unixPermissions,
1931                    dosPermissions : input.dosPermissions,
1932                    createFolders: options.createFolders
1933                });
1934            }
1935            if (zipEntries.zipComment.length) {
1936                this.comment = zipEntries.zipComment;
1937            }
1938
1939            return this;
1940        };
1941
1942    },{"./base64":6,"./utf8":25,"./utils":26,"./zipEntries":27}],16:[function(_dereq_,module,exports){
1943        (function (Buffer){
1944            'use strict';
1945            module.exports = function(data, encoding){
1946                return new Buffer(data, encoding);
1947            };
1948            module.exports.test = function(b){
1949                return Buffer.isBuffer(b);
1950            };
1951
1952        }).call(this,_dereq_("buffer").Buffer)
1953    },{"buffer":1}],17:[function(_dereq_,module,exports){
1954        'use strict';
1955        var Uint8ArrayReader = _dereq_('./uint8ArrayReader');
1956
1957        function NodeBufferReader(data) {
1958            this.data = data;
1959            this.length = this.data.length;
1960            this.index = 0;
1961            this.zero = 0;
1962        }
1963        NodeBufferReader.prototype = new Uint8ArrayReader();
1964
1965        /**
1966         * @see DataReader.readData
1967         */
1968        NodeBufferReader.prototype.readData = function(size) {
1969            this.checkOffset(size);
1970            var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
1971            this.index += size;
1972            return result;
1973        };
1974        module.exports = NodeBufferReader;
1975
1976    },{"./uint8ArrayReader":23}],18:[function(_dereq_,module,exports){
1977        'use strict';
1978        var support = _dereq_('./support');
1979        var utils = _dereq_('./utils');
1980        var crc32 = _dereq_('./crc32');
1981        var signature = _dereq_('./signature');
1982        var defaults = _dereq_('./defaults');
1983        var base64 = _dereq_('./base64');
1984        var compressions = _dereq_('./compressions');
1985        var CompressedObject = _dereq_('./compressedObject');
1986        var nodeBuffer = _dereq_('./nodeBuffer');
1987        var utf8 = _dereq_('./utf8');
1988        var StringWriter = _dereq_('./stringWriter');
1989        var Uint8ArrayWriter = _dereq_('./uint8ArrayWriter');
1990
1991        /**
1992         * Returns the raw data of a ZipObject, decompress the content if necessary.
1993         * @param {ZipObject} file the file to use.
1994         * @return {String|ArrayBuffer|Uint8Array|Buffer} the data.
1995         */
1996        var getRawData = function(file) {
1997            if (file._data instanceof CompressedObject) {
1998                file._data = file._data.getContent();
1999                file.options.binary = true;
2000                file.options.base64 = false;
2001
2002                if (utils.getTypeOf(file._data) === "uint8array") {
2003                    var copy = file._data;
2004                    // when reading an arraybuffer, the CompressedObject mechanism will keep it and subarray() a Uint8Array.
2005                    // if we request a file in the same format, we might get the same Uint8Array or its ArrayBuffer (the original zip file).
2006                    file._data = new Uint8Array(copy.length);
2007                    // with an empty Uint8Array, Opera fails with a "Offset larger than array size"
2008                    if (copy.length !== 0) {
2009                        file._data.set(copy, 0);
2010                    }
2011                }
2012            }
2013            return file._data;
2014        };
2015
2016        /**
2017         * Returns the data of a ZipObject in a binary form. If the content is an unicode string, encode it.
2018         * @param {ZipObject} file the file to use.
2019         * @return {String|ArrayBuffer|Uint8Array|Buffer} the data.
2020         */
2021        var getBinaryData = function(file) {
2022            var result = getRawData(file),
2023                type = utils.getTypeOf(result);
2024            if (type === "string") {
2025                if (!file.options.binary) {
2026                    // unicode text !
2027                    // unicode string => binary string is a painful process, check if we can avoid it.
2028                    if (support.nodebuffer) {
2029                        return nodeBuffer(result, "utf-8");
2030                    }
2031                }
2032                return file.asBinary();
2033            }
2034            return result;
2035        };
2036
2037        /**
2038         * Transform this._data into a string.
2039         * @param {function} filter a function String -> String, applied if not null on the result.
2040         * @return {String} the string representing this._data.
2041         */
2042        var dataToString = function(asUTF8) {
2043            var result = getRawData(this);
2044            if (result === null || typeof result === "undefined") {
2045                return "";
2046            }
2047            // if the data is a base64 string, we decode it before checking the encoding !
2048            if (this.options.base64) {
2049                result = base64.decode(result);
2050            }
2051            if (asUTF8 && this.options.binary) {
2052                // JSZip.prototype.utf8decode supports arrays as input
2053                // skip to array => string step, utf8decode will do it.
2054                result = out.utf8decode(result);
2055            }
2056            else {
2057                // no utf8 transformation, do the array => string step.
2058                result = utils.transformTo("string", result);
2059            }
2060
2061            if (!asUTF8 && !this.options.binary) {
2062                result = utils.transformTo("string", out.utf8encode(result));
2063            }
2064            return result;
2065        };
2066        /**
2067         * A simple object representing a file in the zip file.
2068         * @constructor
2069         * @param {string} name the name of the file
2070         * @param {String|ArrayBuffer|Uint8Array|Buffer} data the data
2071         * @param {Object} options the options of the file
2072         */
2073        var ZipObject = function(name, data, options) {
2074            this.name = name;
2075            this.dir = options.dir;
2076            this.date = options.date;
2077            this.comment = options.comment;
2078            this.unixPermissions = options.unixPermissions;
2079            this.dosPermissions = options.dosPermissions;
2080
2081            this._data = data;
2082            this.options = options;
2083
2084            /*
2085     * This object contains initial values for dir and date.
2086     * With them, we can check if the user changed the deprecated metadata in
2087     * `ZipObject#options` or not.
2088     */
2089            this._initialMetadata = {
2090                dir : options.dir,
2091                date : options.date
2092            };
2093        };
2094
2095        ZipObject.prototype = {
2096            /**
2097             * Return the content as UTF8 string.
2098             * @return {string} the UTF8 string.
2099             */
2100            asText: function() {
2101                return dataToString.call(this, true);
2102            },
2103            /**
2104             * Returns the binary content.
2105             * @return {string} the content as binary.
2106             */
2107            asBinary: function() {
2108                return dataToString.call(this, false);
2109            },
2110            /**
2111             * Returns the content as a nodejs Buffer.
2112             * @return {Buffer} the content as a Buffer.
2113             */
2114            asNodeBuffer: function() {
2115                var result = getBinaryData(this);
2116                return utils.transformTo("nodebuffer", result);
2117            },
2118            /**
2119             * Returns the content as an Uint8Array.
2120             * @return {Uint8Array} the content as an Uint8Array.
2121             */
2122            asUint8Array: function() {
2123                var result = getBinaryData(this);
2124                return utils.transformTo("uint8array", result);
2125            },
2126            /**
2127             * Returns the content as an ArrayBuffer.
2128             * @return {ArrayBuffer} the content as an ArrayBufer.
2129             */
2130            asArrayBuffer: function() {
2131                return this.asUint8Array().buffer;
2132            }
2133        };
2134
2135        /**
2136         * Transform an integer into a string in hexadecimal.
2137         * @private
2138         * @param {number} dec the number to convert.
2139         * @param {number} bytes the number of bytes to generate.
2140         * @returns {string} the result.
2141         */
2142        var decToHex = function(dec, bytes) {
2143            var hex = "",
2144                i;
2145            for (i = 0; i < bytes; i++) {
2146                hex += String.fromCharCode(dec & 0xff);
2147                dec = dec >>> 8;
2148            }
2149            return hex;
2150        };
2151
2152        /**
2153         * Transforms the (incomplete) options from the user into the complete
2154         * set of options to create a file.
2155         * @private
2156         * @param {Object} o the options from the user.
2157         * @return {Object} the complete set of options.
2158         */
2159        var prepareFileAttrs = function(o) {
2160            o = o || {};
2161            if (o.base64 === true && (o.binary === null || o.binary === undefined)) {
2162                o.binary = true;
2163            }
2164            o = utils.extend(o, defaults);
2165            o.date = o.date || new Date();
2166            if (o.compression !== null) o.compression = o.compression.toUpperCase();
2167
2168            return o;
2169        };
2170
2171        /**
2172         * Add a file in the current folder.
2173         * @private
2174         * @param {string} name the name of the file
2175         * @param {String|ArrayBuffer|Uint8Array|Buffer} data the data of the file
2176         * @param {Object} o the options of the file
2177         * @return {Object} the new file.
2178         */
2179        var fileAdd = function(name, data, o) {
2180            // be sure sub folders exist
2181            var dataType = utils.getTypeOf(data),
2182                parent;
2183
2184            o = prepareFileAttrs(o);
2185
2186            if (typeof o.unixPermissions === "string") {
2187                o.unixPermissions = parseInt(o.unixPermissions, 8);
2188            }
2189
2190            // UNX_IFDIR  0040000 see zipinfo.c
2191            if (o.unixPermissions && (o.unixPermissions & 0x4000)) {
2192                o.dir = true;
2193            }
2194            // Bit 4    Directory
2195            if (o.dosPermissions && (o.dosPermissions & 0x0010)) {
2196                o.dir = true;
2197            }
2198
2199            if (o.dir) {
2200                name = forceTrailingSlash(name);
2201            }
2202
2203            if (o.createFolders && (parent = parentFolder(name))) {
2204                folderAdd.call(this, parent, true);
2205            }
2206
2207            if (o.dir || data === null || typeof data === "undefined") {
2208                o.base64 = false;
2209                o.binary = false;
2210                data = null;
2211                dataType = null;
2212            }
2213            else if (dataType === "string") {
2214                if (o.binary && !o.base64) {
2215                    // optimizedBinaryString == true means that the file has already been filtered with a 0xFF mask
2216                    if (o.optimizedBinaryString !== true) {
2217                        // this is a string, not in a base64 format.
2218                        // Be sure that this is a correct "binary string"
2219                        data = utils.string2binary(data);
2220                    }
2221                }
2222            }
2223            else { // arraybuffer, uint8array, ...
2224                o.base64 = false;
2225                o.binary = true;
2226
2227                if (!dataType && !(data instanceof CompressedObject)) {
2228                    throw new Error("The data of '" + name + "' is in an unsupported format !");
2229                }
2230
2231                // special case : it's way easier to work with Uint8Array than with ArrayBuffer
2232                if (dataType === "arraybuffer") {
2233                    data = utils.transformTo("uint8array", data);
2234                }
2235            }
2236
2237            var object = new ZipObject(name, data, o);
2238            this.files[name] = object;
2239            return object;
2240        };
2241
2242        /**
2243         * Find the parent folder of the path.
2244         * @private
2245         * @param {string} path the path to use
2246         * @return {string} the parent folder, or ""
2247         */
2248        var parentFolder = function (path) {
2249            if (path.slice(-1) == '/') {
2250                path = path.substring(0, path.length - 1);
2251            }
2252            var lastSlash = path.lastIndexOf('/');
2253            return (lastSlash > 0) ? path.substring(0, lastSlash) : "";
2254        };
2255
2256
2257        /**
2258         * Returns the path with a slash at the end.
2259         * @private
2260         * @param {String} path the path to check.
2261         * @return {String} the path with a trailing slash.
2262         */
2263        var forceTrailingSlash = function(path) {
2264            // Check the name ends with a /
2265            if (path.slice(-1) != "/") {
2266                path += "/"; // IE doesn't like substr(-1)
2267            }
2268            return path;
2269        };
2270        /**
2271         * Add a (sub) folder in the current folder.
2272         * @private
2273         * @param {string} name the folder's name
2274         * @param {boolean=} [createFolders] If true, automatically create sub
2275         *  folders. Defaults to false.
2276         * @return {Object} the new folder.
2277         */
2278        var folderAdd = function(name, createFolders) {
2279            createFolders = (typeof createFolders !== 'undefined') ? createFolders : false;
2280
2281            name = forceTrailingSlash(name);
2282
2283            // Does this folder already exist?
2284            if (!this.files[name]) {
2285                fileAdd.call(this, name, null, {
2286                    dir: true,
2287                    createFolders: createFolders
2288                });
2289            }
2290            return this.files[name];
2291        };
2292
2293        /**
2294         * Generate a JSZip.CompressedObject for a given zipOject.
2295         * @param {ZipObject} file the object to read.
2296         * @param {JSZip.compression} compression the compression to use.
2297         * @param {Object} compressionOptions the options to use when compressing.
2298         * @return {JSZip.CompressedObject} the compressed result.
2299         */
2300        var generateCompressedObjectFrom = function(file, compression, compressionOptions) {
2301            var result = new CompressedObject(),
2302                content;
2303
2304            // the data has not been decompressed, we might reuse things !
2305            if (file._data instanceof CompressedObject) {
2306                result.uncompressedSize = file._data.uncompressedSize;
2307                result.crc32 = file._data.crc32;
2308
2309                if (result.uncompressedSize === 0 || file.dir) {
2310                    compression = compressions['STORE'];
2311                    result.compressedContent = "";
2312                    result.crc32 = 0;
2313                }
2314                else if (file._data.compressionMethod === compression.magic) {
2315                    result.compressedContent = file._data.getCompressedContent();
2316                }
2317                else {
2318                    content = file._data.getContent();
2319                    // need to decompress / recompress
2320                    result.compressedContent = compression.compress(utils.transformTo(compression.compressInputType, content), compressionOptions);
2321                }
2322            }
2323            else {
2324                // have uncompressed data
2325                content = getBinaryData(file);
2326                if (!content || content.length === 0 || file.dir) {
2327                    compression = compressions['STORE'];
2328                    content = "";
2329                }
2330                result.uncompressedSize = content.length;
2331                result.crc32 = crc32(content);
2332                result.compressedContent = compression.compress(utils.transformTo(compression.compressInputType, content), compressionOptions);
2333            }
2334
2335            result.compressedSize = result.compressedContent.length;
2336            result.compressionMethod = compression.magic;
2337
2338            return result;
2339        };
2340
2341
2342
2343
2344        /**
2345         * Generate the UNIX part of the external file attributes.
2346         * @param {Object} unixPermissions the unix permissions or null.
2347         * @param {Boolean} isDir true if the entry is a directory, false otherwise.
2348         * @return {Number} a 32 bit integer.
2349         *
2350         * adapted from http://unix.stackexchange.com/questions/14705/the-zip-formats-external-file-attribute :
2351         *
2352         * TTTTsstrwxrwxrwx0000000000ADVSHR
2353         * ^^^^____________________________ file type, see zipinfo.c (UNX_*)
2354         *     ^^^_________________________ setuid, setgid, sticky
2355         *        ^^^^^^^^^________________ permissions
2356         *                 ^^^^^^^^^^______ not used ?
2357         *                           ^^^^^^ DOS attribute bits : Archive, Directory, Volume label, System file, Hidden, Read only
2358         */
2359        var generateUnixExternalFileAttr = function (unixPermissions, isDir) {
2360
2361            var result = unixPermissions;
2362            if (!unixPermissions) {
2363                // I can't use octal values in strict mode, hence the hexa.
2364                //  040775 => 0x41fd
2365                // 0100664 => 0x81b4
2366                result = isDir ? 0x41fd : 0x81b4;
2367            }
2368
2369            return (result & 0xFFFF) << 16;
2370        };
2371
2372        /**
2373         * Generate the DOS part of the external file attributes.
2374         * @param {Object} dosPermissions the dos permissions or null.
2375         * @param {Boolean} isDir true if the entry is a directory, false otherwise.
2376         * @return {Number} a 32 bit integer.
2377         *
2378         * Bit 0     Read-Only
2379         * Bit 1     Hidden
2380         * Bit 2     System
2381         * Bit 3     Volume Label
2382         * Bit 4     Directory
2383         * Bit 5     Archive
2384         */
2385        var generateDosExternalFileAttr = function (dosPermissions, isDir) {
2386
2387            // the dir flag is already set for compatibility
2388
2389            return (dosPermissions || 0)  & 0x3F;
2390        };
2391
2392        /**
2393         * Generate the various parts used in the construction of the final zip file.
2394         * @param {string} name the file name.
2395         * @param {ZipObject} file the file content.
2396         * @param {JSZip.CompressedObject} compressedObject the compressed object.
2397         * @param {number} offset the current offset from the start of the zip file.
2398         * @param {String} platform let's pretend we are this platform (change platform dependents fields)
2399         * @param {Function} encodeFileName the function to encode the file name / comment.
2400         * @return {object} the zip parts.
2401         */
2402        var generateZipParts = function(name, file, compressedObject, offset, platform, encodeFileName) {
2403            var data = compressedObject.compressedContent,
2404                useCustomEncoding = encodeFileName !== utf8.utf8encode,
2405                encodedFileName = utils.transformTo("string", encodeFileName(file.name)),
2406                utfEncodedFileName = utils.transformTo("string", utf8.utf8encode(file.name)),
2407                comment = file.comment || "",
2408                encodedComment = utils.transformTo("string", encodeFileName(comment)),
2409                utfEncodedComment = utils.transformTo("string", utf8.utf8encode(comment)),
2410                useUTF8ForFileName = utfEncodedFileName.length !== file.name.length,
2411                useUTF8ForComment = utfEncodedComment.length !== comment.length,
2412                o = file.options,
2413                dosTime,
2414                dosDate,
2415                extraFields = "",
2416                unicodePathExtraField = "",
2417                unicodeCommentExtraField = "",
2418                dir, date;
2419
2420
2421            // handle the deprecated options.dir
2422            if (file._initialMetadata.dir !== file.dir) {
2423                dir = file.dir;
2424            } else {
2425                dir = o.dir;
2426            }
2427
2428            // handle the deprecated options.date
2429            if(file._initialMetadata.date !== file.date) {
2430                date = file.date;
2431            } else {
2432                date = o.date;
2433            }
2434
2435            var extFileAttr = 0;
2436            var versionMadeBy = 0;
2437            if (dir) {
2438                // dos or unix, we set the dos dir flag
2439                extFileAttr |= 0x00010;
2440            }
2441            if(platform === "UNIX") {
2442                versionMadeBy = 0x031E; // UNIX, version 3.0
2443                extFileAttr |= generateUnixExternalFileAttr(file.unixPermissions, dir);
2444            } else { // DOS or other, fallback to DOS
2445                versionMadeBy = 0x0014; // DOS, version 2.0
2446                extFileAttr |= generateDosExternalFileAttr(file.dosPermissions, dir);
2447            }
2448
2449            // date
2450            // @see http://www.delorie.com/djgpp/doc/rbinter/it/52/13.html
2451            // @see http://www.delorie.com/djgpp/doc/rbinter/it/65/16.html
2452            // @see http://www.delorie.com/djgpp/doc/rbinter/it/66/16.html
2453
2454            dosTime = date.getHours();
2455            dosTime = dosTime << 6;
2456            dosTime = dosTime | date.getMinutes();
2457            dosTime = dosTime << 5;
2458            dosTime = dosTime | date.getSeconds() / 2;
2459
2460            dosDate = date.getFullYear() - 1980;
2461            dosDate = dosDate << 4;
2462            dosDate = dosDate | (date.getMonth() + 1);
2463            dosDate = dosDate << 5;
2464            dosDate = dosDate | date.getDate();
2465
2466            if (useUTF8ForFileName) {
2467                // set the unicode path extra field. unzip needs at least one extra
2468                // field to correctly handle unicode path, so using the path is as good
2469                // as any other information. This could improve the situation with
2470                // other archive managers too.
2471                // This field is usually used without the utf8 flag, with a non
2472                // unicode path in the header (winrar, winzip). This helps (a bit)
2473                // with the messy Windows' default compressed folders feature but
2474                // breaks on p7zip which doesn't seek the unicode path extra field.
2475                // So for now, UTF-8 everywhere !
2476                unicodePathExtraField =
2477                    // Version
2478                    decToHex(1, 1) +
2479                    // NameCRC32
2480                    decToHex(crc32(encodedFileName), 4) +
2481                    // UnicodeName
2482                    utfEncodedFileName;
2483
2484                extraFields +=
2485                    // Info-ZIP Unicode Path Extra Field
2486                    "\x75\x70" +
2487                    // size
2488                    decToHex(unicodePathExtraField.length, 2) +
2489                    // content
2490                    unicodePathExtraField;
2491            }
2492
2493            if(useUTF8ForComment) {
2494
2495                unicodeCommentExtraField =
2496                    // Version
2497                    decToHex(1, 1) +
2498                    // CommentCRC32
2499                    decToHex(this.crc32(encodedComment), 4) +
2500                    // UnicodeName
2501                    utfEncodedComment;
2502
2503                extraFields +=
2504                    // Info-ZIP Unicode Path Extra Field
2505                    "\x75\x63" +
2506                    // size
2507                    decToHex(unicodeCommentExtraField.length, 2) +
2508                    // content
2509                    unicodeCommentExtraField;
2510            }
2511
2512            var header = "";
2513
2514            // version needed to extract
2515            header += "\x0A\x00";
2516            // general purpose bit flag
2517            // set bit 11 if utf8
2518            header += !useCustomEncoding && (useUTF8ForFileName || useUTF8ForComment) ? "\x00\x08" : "\x00\x00";
2519            // compression method
2520            header += compressedObject.compressionMethod;
2521            // last mod file time
2522            header += decToHex(dosTime, 2);
2523            // last mod file date
2524            header += decToHex(dosDate, 2);
2525            // crc-32
2526            header += decToHex(compressedObject.crc32, 4);
2527            // compressed size
2528            header += decToHex(compressedObject.compressedSize, 4);
2529            // uncompressed size
2530            header += decToHex(compressedObject.uncompressedSize, 4);
2531            // file name length
2532            header += decToHex(encodedFileName.length, 2);
2533            // extra field length
2534            header += decToHex(extraFields.length, 2);
2535
2536
2537            var fileRecord = signature.LOCAL_FILE_HEADER + header + encodedFileName + extraFields;
2538
2539            var dirRecord = signature.CENTRAL_FILE_HEADER +
2540                // version made by (00: DOS)
2541                decToHex(versionMadeBy, 2) +
2542                // file header (common to file and central directory)
2543                header +
2544                // file comment length
2545                decToHex(encodedComment.length, 2) +
2546                // disk number start
2547                "\x00\x00" +
2548                // internal file attributes TODO
2549                "\x00\x00" +
2550                // external file attributes
2551                decToHex(extFileAttr, 4) +
2552                // relative offset of local header
2553                decToHex(offset, 4) +
2554                // file name
2555                encodedFileName +
2556                // extra field
2557                extraFields +
2558                // file comment
2559                encodedComment;
2560
2561            return {
2562                fileRecord: fileRecord,
2563                dirRecord: dirRecord,
2564                compressedObject: compressedObject
2565            };
2566        };
2567
2568
2569// return the actual prototype of JSZip
2570        var out = {
2571            /**
2572             * Read an existing zip and merge the data in the current JSZip object.
2573             * The implementation is in jszip-load.js, don't forget to include it.
2574             * @param {String|ArrayBuffer|Uint8Array|Buffer} stream  The stream to load
2575             * @param {Object} options Options for loading the stream.
2576             *  options.base64 : is the stream in base64 ? default : false
2577             * @return {JSZip} the current JSZip object
2578             */
2579            load: function(stream, options) {
2580                throw new Error("Load method is not defined. Is the file jszip-load.js included ?");
2581            },
2582
2583            /**
2584             * Filter nested files/folders with the specified function.
2585             * @param {Function} search the predicate to use :
2586             * function (relativePath, file) {...}
2587             * It takes 2 arguments : the relative path and the file.
2588             * @return {Array} An array of matching elements.
2589             */
2590            filter: function(search) {
2591                var result = [],
2592                    filename, relativePath, file, fileClone;
2593                for (filename in this.files) {
2594                    if (!this.files.hasOwnProperty(filename)) {
2595                        continue;
2596                    }
2597                    file = this.files[filename];
2598                    // return a new object, don't let the user mess with our internal objects :)
2599                    fileClone = new ZipObject(file.name, file._data, utils.extend(file.options));
2600                    relativePath = filename.slice(this.root.length, filename.length);
2601                    if (filename.slice(0, this.root.length) === this.root && // the file is in the current root
2602                        search(relativePath, fileClone)) { // and the file matches the function
2603                        result.push(fileClone);
2604                    }
2605                }
2606                return result;
2607            },
2608
2609            /**
2610             * Add a file to the zip file, or search a file.
2611             * @param   {string|RegExp} name The name of the file to add (if data is defined),
2612             * the name of the file to find (if no data) or a regex to match files.
2613             * @param   {String|ArrayBuffer|Uint8Array|Buffer} data  The file data, either raw or base64 encoded
2614             * @param   {Object} o     File options
2615             * @return  {JSZip|Object|Array} this JSZip object (when adding a file),
2616             * a file (when searching by string) or an array of files (when searching by regex).
2617             */
2618            file: function(name, data, o) {
2619                if (arguments.length === 1) {
2620                    if (utils.isRegExp(name)) {
2621                        var regexp = name;
2622                        return this.filter(function(relativePath, file) {
2623                            return !file.dir && regexp.test(relativePath);
2624                        });
2625                    }
2626                    else { // text
2627                        return this.filter(function(relativePath, file) {
2628                            return !file.dir && relativePath === name;
2629                        })[0] || null;
2630                    }
2631                }
2632                else { // more than one argument : we have data !
2633                    name = this.root + name;
2634                    fileAdd.call(this, name, data, o);
2635                }
2636                return this;
2637            },
2638
2639            /**
2640             * Add a directory to the zip file, or search.
2641             * @param   {String|RegExp} arg The name of the directory to add, or a regex to search folders.
2642             * @return  {JSZip} an object with the new directory as the root, or an array containing matching folders.
2643             */
2644            folder: function(arg) {
2645                if (!arg) {
2646                    return this;
2647                }
2648
2649                if (utils.isRegExp(arg)) {
2650                    return this.filter(function(relativePath, file) {
2651                        return file.dir && arg.test(relativePath);
2652                    });
2653                }
2654
2655                // else, name is a new folder
2656                var name = this.root + arg;
2657                var newFolder = folderAdd.call(this, name);
2658
2659                // Allow chaining by returning a new object with this folder as the root
2660                var ret = this.clone();
2661                ret.root = newFolder.name;
2662                return ret;
2663            },
2664
2665            /**
2666             * Delete a file, or a directory and all sub-files, from the zip
2667             * @param {string} name the name of the file to delete
2668             * @return {JSZip} this JSZip object
2669             */
2670            remove: function(name) {
2671                name = this.root + name;
2672                var file = this.files[name];
2673                if (!file) {
2674                    // Look for any folders
2675                    if (name.slice(-1) != "/") {
2676                        name += "/";
2677                    }
2678                    file = this.files[name];
2679                }
2680
2681                if (file && !file.dir) {
2682                    // file
2683                    delete this.files[name];
2684                } else {
2685                    // maybe a folder, delete recursively
2686                    var kids = this.filter(function(relativePath, file) {
2687                        return file.name.slice(0, name.length) === name;
2688                    });
2689                    for (var i = 0; i < kids.length; i++) {
2690                        delete this.files[kids[i].name];
2691                    }
2692                }
2693
2694                return this;
2695            },
2696
2697            /**
2698             * Generate the complete zip file
2699             * @param {Object} options the options to generate the zip file :
2700             * - base64, (deprecated, use type instead) true to generate base64.
2701             * - compression, "STORE" by default.
2702             * - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob.
2703             * @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the zip file
2704             */
2705            generate: function(options) {
2706                options = utils.extend(options || {}, {
2707                    base64: true,
2708                    compression: "STORE",
2709                    compressionOptions : null,
2710                    type: "base64",
2711                    platform: "DOS",
2712                    comment: null,
2713                    mimeType: 'application/zip',
2714                    encodeFileName: utf8.utf8encode
2715                });
2716
2717                utils.checkSupport(options.type);
2718
2719                // accept nodejs `process.platform`
2720                if(
2721                    options.platform === 'darwin' ||
2722                    options.platform === 'freebsd' ||
2723                    options.platform === 'linux' ||
2724                    options.platform === 'sunos'
2725                ) {
2726                    options.platform = "UNIX";
2727                }
2728                if (options.platform === 'win32') {
2729                    options.platform = "DOS";
2730                }
2731
2732                var zipData = [],
2733                    localDirLength = 0,
2734                    centralDirLength = 0,
2735                    writer, i,
2736                    encodedComment = utils.transformTo("string", options.encodeFileName(options.comment || this.comment || ""));
2737
2738                // first, generate all the zip parts.
2739                for (var name in this.files) {
2740                    if (!this.files.hasOwnProperty(name)) {
2741                        continue;
2742                    }
2743                    var file = this.files[name];
2744
2745                    var compressionName = file.options.compression || options.compression.toUpperCase();
2746                    var compression = compressions[compressionName];
2747                    if (!compression) {
2748                        throw new Error(compressionName + " is not a valid compression method !");
2749                    }
2750                    var compressionOptions = file.options.compressionOptions || options.compressionOptions || {};
2751
2752                    var compressedObject = generateCompressedObjectFrom.call(this, file, compression, compressionOptions);
2753
2754                    var zipPart = generateZipParts.call(this, name, file, compressedObject, localDirLength, options.platform, options.encodeFileName);
2755                    localDirLength += zipPart.fileRecord.length + compressedObject.compressedSize;
2756                    centralDirLength += zipPart.dirRecord.length;
2757                    zipData.push(zipPart);
2758                }
2759
2760                var dirEnd = "";
2761
2762                // end of central dir signature
2763                dirEnd = signature.CENTRAL_DIRECTORY_END +
2764                    // number of this disk
2765                    "\x00\x00" +
2766                    // number of the disk with the start of the central directory
2767                    "\x00\x00" +
2768                    // total number of entries in the central directory on this disk
2769                    decToHex(zipData.length, 2) +
2770                    // total number of entries in the central directory
2771                    decToHex(zipData.length, 2) +
2772                    // size of the central directory   4 bytes
2773                    decToHex(centralDirLength, 4) +
2774                    // offset of start of central directory with respect to the starting disk number
2775                    decToHex(localDirLength, 4) +
2776                    // .ZIP file comment length
2777                    decToHex(encodedComment.length, 2) +
2778                    // .ZIP file comment
2779                    encodedComment;
2780
2781
2782                // we have all the parts (and the total length)
2783                // time to create a writer !
2784                var typeName = options.type.toLowerCase();
2785                if(typeName==="uint8array"||typeName==="arraybuffer"||typeName==="blob"||typeName==="nodebuffer") {
2786                    writer = new Uint8ArrayWriter(localDirLength + centralDirLength + dirEnd.length);
2787                }else{
2788                    writer = new StringWriter(localDirLength + centralDirLength + dirEnd.length);
2789                }
2790
2791                for (i = 0; i < zipData.length; i++) {
2792                    writer.append(zipData[i].fileRecord);
2793                    writer.append(zipData[i].compressedObject.compressedContent);
2794                }
2795                for (i = 0; i < zipData.length; i++) {
2796                    writer.append(zipData[i].dirRecord);
2797                }
2798
2799                writer.append(dirEnd);
2800
2801                var zip = writer.finalize();
2802
2803
2804
2805                switch(options.type.toLowerCase()) {
2806                    // case "zip is an Uint8Array"
2807                    case "uint8array" :
2808                    case "arraybuffer" :
2809                    case "nodebuffer" :
2810                        return utils.transformTo(options.type.toLowerCase(), zip);
2811                    case "blob" :
2812                        return utils.arrayBuffer2Blob(utils.transformTo("arraybuffer", zip), options.mimeType);
2813                    // case "zip is a string"
2814                    case "base64" :
2815                        return (options.base64) ? base64.encode(zip) : zip;
2816                    default : // case "string" :
2817                        return zip;
2818                }
2819
2820            },
2821
2822            /**
2823             * @deprecated
2824             * This method will be removed in a future version without replacement.
2825             */
2826            crc32: function (input, crc) {
2827                return crc32(input, crc);
2828            },
2829
2830            /**
2831             * @deprecated
2832             * This method will be removed in a future version without replacement.
2833             */
2834            utf8encode: function (string) {
2835                return utils.transformTo("string", utf8.utf8encode(string));
2836            },
2837
2838            /**
2839             * @deprecated
2840             * This method will be removed in a future version without replacement.
2841             */
2842            utf8decode: function (input) {
2843                return utf8.utf8decode(input);
2844            }
2845        };
2846        module.exports = out;
2847
2848    },{"./base64":6,"./compressedObject":7,"./compressions":8,"./crc32":9,"./defaults":11,"./nodeBuffer":16,"./signature":19,"./stringWriter":21,"./support":22,"./uint8ArrayWriter":24,"./utf8":25,"./utils":26}],19:[function(_dereq_,module,exports){
2849        'use strict';
2850        exports.LOCAL_FILE_HEADER = "PK\x03\x04";
2851        exports.CENTRAL_FILE_HEADER = "PK\x01\x02";
2852        exports.CENTRAL_DIRECTORY_END = "PK\x05\x06";
2853        exports.ZIP64_CENTRAL_DIRECTORY_LOCATOR = "PK\x06\x07";
2854        exports.ZIP64_CENTRAL_DIRECTORY_END = "PK\x06\x06";
2855        exports.DATA_DESCRIPTOR = "PK\x07\x08";
2856
2857    },{}],20:[function(_dereq_,module,exports){
2858        'use strict';
2859        var DataReader = _dereq_('./dataReader');
2860        var utils = _dereq_('./utils');
2861
2862        function StringReader(data, optimizedBinaryString) {
2863            this.data = data;
2864            if (!optimizedBinaryString) {
2865                this.data = utils.string2binary(this.data);
2866            }
2867            this.length = this.data.length;
2868            this.index = 0;
2869            this.zero = 0;
2870        }
2871        StringReader.prototype = new DataReader();
2872        /**
2873         * @see DataReader.byteAt
2874         */
2875        StringReader.prototype.byteAt = function(i) {
2876            return this.data.charCodeAt(this.zero + i);
2877        };
2878        /**
2879         * @see DataReader.lastIndexOfSignature
2880         */
2881        StringReader.prototype.lastIndexOfSignature = function(sig) {
2882            return this.data.lastIndexOf(sig) - this.zero;
2883        };
2884        /**
2885         * @see DataReader.readData
2886         */
2887        StringReader.prototype.readData = function(size) {
2888            this.checkOffset(size);
2889            // this will work because the constructor applied the "& 0xff" mask.
2890            var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
2891            this.index += size;
2892            return result;
2893        };
2894        module.exports = StringReader;
2895
2896    },{"./dataReader":10,"./utils":26}],21:[function(_dereq_,module,exports){
2897        'use strict';
2898
2899        var utils = _dereq_('./utils');
2900
2901        /**
2902         * An object to write any content to a string.
2903         * @constructor
2904         */
2905        var StringWriter = function() {
2906            this.data = [];
2907        };
2908        StringWriter.prototype = {
2909            /**
2910             * Append any content to the current string.
2911             * @param {Object} input the content to add.
2912             */
2913            append: function(input) {
2914                input = utils.transformTo("string", input);
2915                this.data.push(input);
2916            },
2917            /**
2918             * Finalize the construction an return the result.
2919             * @return {string} the generated string.
2920             */
2921            finalize: function() {
2922                return this.data.join("");
2923            }
2924        };
2925
2926        module.exports = StringWriter;
2927
2928    },{"./utils":26}],22:[function(_dereq_,module,exports){
2929        (function (Buffer){
2930            'use strict';
2931            exports.base64 = true;
2932            exports.array = true;
2933            exports.string = true;
2934            exports.arraybuffer = typeof ArrayBuffer !== "undefined" && typeof Uint8Array !== "undefined";
2935// contains true if JSZip can read/generate nodejs Buffer, false otherwise.
2936// Browserify will provide a Buffer implementation for browsers, which is
2937// an augmented Uint8Array (i.e., can be used as either Buffer or U8).
2938            exports.nodebuffer = typeof Buffer !== "undefined";
2939// contains true if JSZip can read/generate Uint8Array, false otherwise.
2940            exports.uint8array = typeof Uint8Array !== "undefined";
2941
2942            if (typeof ArrayBuffer === "undefined") {
2943                exports.blob = false;
2944            }
2945            else {
2946                var buffer = new ArrayBuffer(0);
2947                try {
2948                    exports.blob = new Blob([buffer], {
2949                        type: "application/zip"
2950                    }).size === 0;
2951                }
2952                catch (e) {
2953                    try {
2954                        var Builder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
2955                        var builder = new Builder();
2956                        builder.append(buffer);
2957                        exports.blob = builder.getBlob('application/zip').size === 0;
2958                    }
2959                    catch (e) {
2960                        exports.blob = false;
2961                    }
2962                }
2963            }
2964
2965        }).call(this,_dereq_("buffer").Buffer)
2966    },{"buffer":1}],23:[function(_dereq_,module,exports){
2967        'use strict';
2968        var ArrayReader = _dereq_('./arrayReader');
2969
2970        function Uint8ArrayReader(data) {
2971            if (data) {
2972                this.data = data;
2973                this.length = this.data.length;
2974                this.index = 0;
2975                this.zero = 0;
2976            }
2977        }
2978        Uint8ArrayReader.prototype = new ArrayReader();
2979        /**
2980         * @see DataReader.readData
2981         */
2982        Uint8ArrayReader.prototype.readData = function(size) {
2983            this.checkOffset(size);
2984            if(size === 0) {
2985                // in IE10, when using subarray(idx, idx), we get the array [0x00] instead of [].
2986                return new Uint8Array(0);
2987            }
2988            var result = this.data.subarray(this.zero + this.index, this.zero + this.index + size);
2989            this.index += size;
2990            return result;
2991        };
2992        module.exports = Uint8ArrayReader;
2993
2994    },{"./arrayReader":5}],24:[function(_dereq_,module,exports){
2995        'use strict';
2996
2997        var utils = _dereq_('./utils');
2998
2999        /**
3000         * An object to write any content to an Uint8Array.
3001         * @constructor
3002         * @param {number} length The length of the array.
3003         */
3004        var Uint8ArrayWriter = function(length) {
3005            this.data = new Uint8Array(length);
3006            this.index = 0;
3007        };
3008        Uint8ArrayWriter.prototype = {
3009            /**
3010             * Append any content to the current array.
3011             * @param {Object} input the content to add.
3012             */
3013            append: function(input) {
3014                if (input.length !== 0) {
3015                    // with an empty Uint8Array, Opera fails with a "Offset larger than array size"
3016                    input = utils.transformTo("uint8array", input);
3017                    this.data.set(input, this.index);
3018                    this.index += input.length;
3019                }
3020            },
3021            /**
3022             * Finalize the construction an return the result.
3023             * @return {Uint8Array} the generated array.
3024             */
3025            finalize: function() {
3026                return this.data;
3027            }
3028        };
3029
3030        module.exports = Uint8ArrayWriter;
3031
3032    },{"./utils":26}],25:[function(_dereq_,module,exports){
3033        'use strict';
3034
3035        var utils = _dereq_('./utils');
3036        var support = _dereq_('./support');
3037        var nodeBuffer = _dereq_('./nodeBuffer');
3038
3039        /**
3040         * The following functions come from pako, from pako/lib/utils/strings
3041         * released under the MIT license, see pako https://github.com/nodeca/pako/
3042         */
3043
3044// Table with utf8 lengths (calculated by first byte of sequence)
3045// Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
3046// because max possible codepoint is 0x10ffff
3047        var _utf8len = new Array(256);
3048        for (var i=0; i<256; i++) {
3049            _utf8len[i] = (i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1);
3050        }
3051        _utf8len[254]=_utf8len[254]=1; // Invalid sequence start
3052
3053// convert string to array (typed, when possible)
3054        var string2buf = function (str) {
3055            var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;
3056
3057            // count binary size
3058            for (m_pos = 0; m_pos < str_len; m_pos++) {
3059                c = str.charCodeAt(m_pos);
3060                if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {
3061                    c2 = str.charCodeAt(m_pos+1);
3062                    if ((c2 & 0xfc00) === 0xdc00) {
3063                        c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
3064                        m_pos++;
3065                    }
3066                }
3067                buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
3068            }
3069
3070            // allocate buffer
3071            if (support.uint8array) {
3072                buf = new Uint8Array(buf_len);
3073            } else {
3074                buf = new Array(buf_len);
3075            }
3076
3077            // convert
3078            for (i=0, m_pos = 0; i < buf_len; m_pos++) {
3079                c = str.charCodeAt(m_pos);
3080                if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {
3081                    c2 = str.charCodeAt(m_pos+1);
3082                    if ((c2 & 0xfc00) === 0xdc00) {
3083                        c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
3084                        m_pos++;
3085                    }
3086                }
3087                if (c < 0x80) {
3088                    /* one byte */
3089                    buf[i++] = c;
3090                } else if (c < 0x800) {
3091                    /* two bytes */
3092                    buf[i++] = 0xC0 | (c >>> 6);
3093                    buf[i++] = 0x80 | (c & 0x3f);
3094                } else if (c < 0x10000) {
3095                    /* three bytes */
3096                    buf[i++] = 0xE0 | (c >>> 12);
3097                    buf[i++] = 0x80 | (c >>> 6 & 0x3f);
3098                    buf[i++] = 0x80 | (c & 0x3f);
3099                } else {
3100                    /* four bytes */
3101                    buf[i++] = 0xf0 | (c >>> 18);
3102                    buf[i++] = 0x80 | (c >>> 12 & 0x3f);
3103                    buf[i++] = 0x80 | (c >>> 6 & 0x3f);
3104                    buf[i++] = 0x80 | (c & 0x3f);
3105                }
3106            }
3107
3108            return buf;
3109        };
3110
3111// Calculate max possible position in utf8 buffer,
3112// that will not break sequence. If that's not possible
3113// - (very small limits) return max size as is.
3114//
3115// buf[] - utf8 bytes array
3116// max   - length limit (mandatory);
3117        var utf8border = function(buf, max) {
3118            var pos;
3119
3120            max = max || buf.length;
3121            if (max > buf.length) { max = buf.length; }
3122
3123            // go back from last position, until start of sequence found
3124            pos = max-1;
3125            while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }
3126
3127            // Fuckup - very small and broken sequence,
3128            // return max, because we should return something anyway.
3129            if (pos < 0) { return max; }
3130
3131            // If we came to start of buffer - that means vuffer is too small,
3132            // return max too.
3133            if (pos === 0) { return max; }
3134
3135            return (pos + _utf8len[buf[pos]] > max) ? pos : max;
3136        };
3137
3138// convert array to string
3139        var buf2string = function (buf) {
3140            var str, i, out, c, c_len;
3141            var len = buf.length;
3142
3143            // Reserve max possible length (2 words per char)
3144            // NB: by unknown reasons, Array is significantly faster for
3145            //     String.fromCharCode.apply than Uint16Array.
3146            var utf16buf = new Array(len*2);
3147
3148            for (out=0, i=0; i<len;) {
3149                c = buf[i++];
3150                // quick process ascii
3151                if (c < 0x80) { utf16buf[out++] = c; continue; }
3152
3153                c_len = _utf8len[c];
3154                // skip 5 & 6 byte codes
3155                if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len-1; continue; }
3156
3157                // apply mask on first byte
3158                c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
3159                // join the rest
3160                while (c_len > 1 && i < len) {
3161                    c = (c << 6) | (buf[i++] & 0x3f);
3162                    c_len--;
3163                }
3164
3165                // terminated by end of string?
3166                if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }
3167
3168                if (c < 0x10000) {
3169                    utf16buf[out++] = c;
3170                } else {
3171                    c -= 0x10000;
3172                    utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);
3173                    utf16buf[out++] = 0xdc00 | (c & 0x3ff);
3174                }
3175            }
3176
3177            // shrinkBuf(utf16buf, out)
3178            if (utf16buf.length !== out) {
3179                if(utf16buf.subarray) {
3180                    utf16buf = utf16buf.subarray(0, out);
3181                } else {
3182                    utf16buf.length = out;
3183                }
3184            }
3185
3186            // return String.fromCharCode.apply(null, utf16buf);
3187            return utils.applyFromCharCode(utf16buf);
3188        };
3189
3190
3191// That's all for the pako functions.
3192
3193
3194        /**
3195         * Transform a javascript string into an array (typed if possible) of bytes,
3196         * UTF-8 encoded.
3197         * @param {String} str the string to encode
3198         * @return {Array|Uint8Array|Buffer} the UTF-8 encoded string.
3199         */
3200        exports.utf8encode = function utf8encode(str) {
3201            if (support.nodebuffer) {
3202                return nodeBuffer(str, "utf-8");
3203            }
3204
3205            return string2buf(str);
3206        };
3207
3208
3209        /**
3210         * Transform a bytes array (or a representation) representing an UTF-8 encoded
3211         * string into a javascript string.
3212         * @param {Array|Uint8Array|Buffer} buf the data de decode
3213         * @return {String} the decoded string.
3214         */
3215        exports.utf8decode = function utf8decode(buf) {
3216            if (support.nodebuffer) {
3217                return utils.transformTo("nodebuffer", buf).toString("utf-8");
3218            }
3219
3220            buf = utils.transformTo(support.uint8array ? "uint8array" : "array", buf);
3221
3222            // return buf2string(buf);
3223            // Chrome prefers to work with "small" chunks of data
3224            // for the method buf2string.
3225            // Firefox and Chrome has their own shortcut, IE doesn't seem to really care.
3226            var result = [], k = 0, len = buf.length, chunk = 65536;
3227            while (k < len) {
3228                var nextBoundary = utf8border(buf, Math.min(k + chunk, len));
3229                if (support.uint8array) {
3230                    result.push(buf2string(buf.subarray(k, nextBoundary)));
3231                } else {
3232                    result.push(buf2string(buf.slice(k, nextBoundary)));
3233                }
3234                k = nextBoundary;
3235            }
3236            return result.join("");
3237
3238        };
3239// vim: set shiftwidth=4 softtabstop=4:
3240
3241    },{"./nodeBuffer":16,"./support":22,"./utils":26}],26:[function(_dereq_,module,exports){
3242        'use strict';
3243        var support = _dereq_('./support');
3244        var compressions = _dereq_('./compressions');
3245        var nodeBuffer = _dereq_('./nodeBuffer');
3246        /**
3247         * Convert a string to a "binary string" : a string containing only char codes between 0 and 255.
3248         * @param {string} str the string to transform.
3249         * @return {String} the binary string.
3250         */
3251        exports.string2binary = function(str) {
3252            var result = "";
3253            for (var i = 0; i < str.length; i++) {
3254                result += String.fromCharCode(str.charCodeAt(i) & 0xff);
3255            }
3256            return result;
3257        };
3258        exports.arrayBuffer2Blob = function(buffer, mimeType) {
3259            exports.checkSupport("blob");
3260            mimeType = mimeType || 'application/zip';
3261
3262            try {
3263                // Blob constructor
3264                return new Blob([buffer], {
3265                    type: mimeType
3266                });
3267            }
3268            catch (e) {
3269
3270                try {
3271                    // deprecated, browser only, old way
3272                    var Builder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
3273                    var builder = new Builder();
3274                    builder.append(buffer);
3275                    return builder.getBlob(mimeType);
3276                }
3277                catch (e) {
3278
3279                    // well, fuck ?!
3280                    throw new Error("Bug : can't construct the Blob.");
3281                }
3282            }
3283
3284
3285        };
3286        /**
3287         * The identity function.
3288         * @param {Object} input the input.
3289         * @return {Object} the same input.
3290         */
3291        function identity(input) {
3292            return input;
3293        }
3294
3295        /**
3296         * Fill in an array with a string.
3297         * @param {String} str the string to use.
3298         * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to fill in (will be mutated).
3299         * @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated array.
3300         */
3301        function stringToArrayLike(str, array) {
3302            for (var i = 0; i < str.length; ++i) {
3303                array[i] = str.charCodeAt(i) & 0xFF;
3304            }
3305            return array;
3306        }
3307
3308        /**
3309         * Transform an array-like object to a string.
3310         * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.
3311         * @return {String} the result.
3312         */
3313        function arrayLikeToString(array) {
3314            // Performances notes :
3315            // --------------------
3316            // String.fromCharCode.apply(null, array) is the fastest, see
3317            // see http://jsperf.com/converting-a-uint8array-to-a-string/2
3318            // but the stack is limited (and we can get huge arrays !).
3319            //
3320            // result += String.fromCharCode(array[i]); generate too many strings !
3321            //
3322            // This code is inspired by http://jsperf.com/arraybuffer-to-string-apply-performance/2
3323            var chunk = 65536;
3324            var result = [],
3325                len = array.length,
3326                type = exports.getTypeOf(array),
3327                k = 0,
3328                canUseApply = true;
3329            try {
3330                switch(type) {
3331                    case "uint8array":
3332                        String.fromCharCode.apply(null, new Uint8Array(0));
3333                        break;
3334                    case "nodebuffer":
3335                        String.fromCharCode.apply(null, nodeBuffer(0));
3336                        break;
3337                }
3338            } catch(e) {
3339                canUseApply = false;
3340            }
3341
3342            // no apply : slow and painful algorithm
3343            // default browser on android 4.*
3344            if (!canUseApply) {
3345                var resultStr = "";
3346                for(var i = 0; i < array.length;i++) {
3347                    resultStr += String.fromCharCode(array[i]);
3348                }
3349                return resultStr;
3350            }
3351            while (k < len && chunk > 1) {
3352                try {
3353                    if (type === "array" || type === "nodebuffer") {
3354                        result.push(String.fromCharCode.apply(null, array.slice(k, Math.min(k + chunk, len))));
3355                    }
3356                    else {
3357                        result.push(String.fromCharCode.apply(null, array.subarray(k, Math.min(k + chunk, len))));
3358                    }
3359                    k += chunk;
3360                }
3361                catch (e) {
3362                    chunk = Math.floor(chunk / 2);
3363                }
3364            }
3365            return result.join("");
3366        }
3367
3368        exports.applyFromCharCode = arrayLikeToString;
3369
3370
3371        /**
3372         * Copy the data from an array-like to an other array-like.
3373         * @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayFrom the origin array.
3374         * @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayTo the destination array which will be mutated.
3375         * @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated destination array.
3376         */
3377        function arrayLikeToArrayLike(arrayFrom, arrayTo) {
3378            for (var i = 0; i < arrayFrom.length; i++) {
3379                arrayTo[i] = arrayFrom[i];
3380            }
3381            return arrayTo;
3382        }
3383
3384// a matrix containing functions to transform everything into everything.
3385        var transform = {};
3386
3387// string to ?
3388        transform["string"] = {
3389            "string": identity,
3390            "array": function(input) {
3391                return stringToArrayLike(input, new Array(input.length));
3392            },
3393            "arraybuffer": function(input) {
3394                return transform["string"]["uint8array"](input).buffer;
3395            },
3396            "uint8array": function(input) {
3397                return stringToArrayLike(input, new Uint8Array(input.length));
3398            },
3399            "nodebuffer": function(input) {
3400                return stringToArrayLike(input, nodeBuffer(input.length));
3401            }
3402        };
3403
3404// array to ?
3405        transform["array"] = {
3406            "string": arrayLikeToString,
3407            "array": identity,
3408            "arraybuffer": function(input) {
3409                return (new Uint8Array(input)).buffer;
3410            },
3411            "uint8array": function(input) {
3412                return new Uint8Array(input);
3413            },
3414            "nodebuffer": function(input) {
3415                return nodeBuffer(input);
3416            }
3417        };
3418
3419// arraybuffer to ?
3420        transform["arraybuffer"] = {
3421            "string": function(input) {
3422                return arrayLikeToString(new Uint8Array(input));
3423            },
3424            "array": function(input) {
3425                return arrayLikeToArrayLike(new Uint8Array(input), new Array(input.byteLength));
3426            },
3427            "arraybuffer": identity,
3428            "uint8array": function(input) {
3429                return new Uint8Array(input);
3430            },
3431            "nodebuffer": function(input) {
3432                return nodeBuffer(new Uint8Array(input));
3433            }
3434        };
3435
3436// uint8array to ?
3437        transform["uint8array"] = {
3438            "string": arrayLikeToString,
3439            "array": function(input) {
3440                return arrayLikeToArrayLike(input, new Array(input.length));
3441            },
3442            "arraybuffer": function(input) {
3443                return input.buffer;
3444            },
3445            "uint8array": identity,
3446            "nodebuffer": function(input) {
3447                return nodeBuffer(input);
3448            }
3449        };
3450
3451// nodebuffer to ?
3452        transform["nodebuffer"] = {
3453            "string": arrayLikeToString,
3454            "array": function(input) {
3455                return arrayLikeToArrayLike(input, new Array(input.length));
3456            },
3457            "arraybuffer": function(input) {
3458                return transform["nodebuffer"]["uint8array"](input).buffer;
3459            },
3460            "uint8array": function(input) {
3461                return arrayLikeToArrayLike(input, new Uint8Array(input.length));
3462            },
3463            "nodebuffer": identity
3464        };
3465
3466        /**
3467         * Transform an input into any type.
3468         * The supported output type are : string, array, uint8array, arraybuffer, nodebuffer.
3469         * If no output type is specified, the unmodified input will be returned.
3470         * @param {String} outputType the output type.
3471         * @param {String|Array|ArrayBuffer|Uint8Array|Buffer} input the input to convert.
3472         * @throws {Error} an Error if the browser doesn't support the requested output type.
3473         */
3474        exports.transformTo = function(outputType, input) {
3475            if (!input) {
3476                // undefined, null, etc
3477                // an empty string won't harm.
3478                input = "";
3479            }
3480            if (!outputType) {
3481                return input;
3482            }
3483            exports.checkSupport(outputType);
3484            var inputType = exports.getTypeOf(input);
3485            var result = transform[inputType][outputType](input);
3486            return result;
3487        };
3488
3489        /**
3490         * Return the type of the input.
3491         * The type will be in a format valid for JSZip.utils.transformTo : string, array, uint8array, arraybuffer.
3492         * @param {Object} input the input to identify.
3493         * @return {String} the (lowercase) type of the input.
3494         */
3495        exports.getTypeOf = function(input) {
3496            if (typeof input === "string") {
3497                return "string";
3498            }
3499            if (Object.prototype.toString.call(input) === "[object Array]") {
3500                return "array";
3501            }
3502            if (support.nodebuffer && nodeBuffer.test(input)) {
3503                return "nodebuffer";
3504            }
3505            if (support.uint8array && input instanceof Uint8Array) {
3506                return "uint8array";
3507            }
3508            if (support.arraybuffer && input instanceof ArrayBuffer) {
3509                return "arraybuffer";
3510            }
3511        };
3512
3513        /**
3514         * Throw an exception if the type is not supported.
3515         * @param {String} type the type to check.
3516         * @throws {Error} an Error if the browser doesn't support the requested type.
3517         */
3518        exports.checkSupport = function(type) {
3519            var supported = support[type.toLowerCase()];
3520            if (!supported) {
3521                throw new Error(type + " is not supported by this browser");
3522            }
3523        };
3524        exports.MAX_VALUE_16BITS = 65535;
3525        exports.MAX_VALUE_32BITS = -1; // well, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" is parsed as -1
3526
3527        /**
3528         * Prettify a string read as binary.
3529         * @param {string} str the string to prettify.
3530         * @return {string} a pretty string.
3531         */
3532        exports.pretty = function(str) {
3533            var res = '',
3534                code, i;
3535            for (i = 0; i < (str || "").length; i++) {
3536                code = str.charCodeAt(i);
3537                res += '\\x' + (code < 16 ? "0" : "") + code.toString(16).toUpperCase();
3538            }
3539            return res;
3540        };
3541
3542        /**
3543         * Find a compression registered in JSZip.
3544         * @param {string} compressionMethod the method magic to find.
3545         * @return {Object|null} the JSZip compression object, null if none found.
3546         */
3547        exports.findCompression = function(compressionMethod) {
3548            for (var method in compressions) {
3549                if (!compressions.hasOwnProperty(method)) {
3550                    continue;
3551                }
3552                if (compressions[method].magic === compressionMethod) {
3553                    return compressions[method];
3554                }
3555            }
3556            return null;
3557        };
3558        /**
3559         * Cross-window, cross-Node-context regular expression detection
3560         * @param  {Object}  object Anything
3561         * @return {Boolean}        true if the object is a regular expression,
3562         * false otherwise
3563         */
3564        exports.isRegExp = function (object) {
3565            return Object.prototype.toString.call(object) === "[object RegExp]";
3566        };
3567
3568        /**
3569         * Merge the objects passed as parameters into a new one.
3570         * @private
3571         * @param {...Object} var_args All objects to merge.
3572         * @return {Object} a new object with the data of the others.
3573         */
3574        exports.extend = function() {
3575            var result = {}, i, attr;
3576            for (i = 0; i < arguments.length; i++) { // arguments is not enumerable in some browsers
3577                for (attr in arguments[i]) {
3578                    if (arguments[i].hasOwnProperty(attr) && typeof result[attr] === "undefined") {
3579                        result[attr] = arguments[i][attr];
3580                    }
3581                }
3582            }
3583            return result;
3584        };
3585
3586
3587    },{"./compressions":8,"./nodeBuffer":16,"./support":22}],27:[function(_dereq_,module,exports){
3588        'use strict';
3589        var StringReader = _dereq_('./stringReader');
3590        var NodeBufferReader = _dereq_('./nodeBufferReader');
3591        var Uint8ArrayReader = _dereq_('./uint8ArrayReader');
3592        var ArrayReader = _dereq_('./arrayReader');
3593        var utils = _dereq_('./utils');
3594        var sig = _dereq_('./signature');
3595        var ZipEntry = _dereq_('./zipEntry');
3596        var support = _dereq_('./support');
3597        var jszipProto = _dereq_('./object');
3598//  class ZipEntries {{{
3599        /**
3600         * All the entries in the zip file.
3601         * @constructor
3602         * @param {String|ArrayBuffer|Uint8Array} data the binary stream to load.
3603         * @param {Object} loadOptions Options for loading the stream.
3604         */
3605        function ZipEntries(data, loadOptions) {
3606            this.files = [];
3607            this.loadOptions = loadOptions;
3608            if (data) {
3609                this.load(data);
3610            }
3611        }
3612        ZipEntries.prototype = {
3613            /**
3614             * Check that the reader is on the speficied signature.
3615             * @param {string} expectedSignature the expected signature.
3616             * @throws {Error} if it is an other signature.
3617             */
3618            checkSignature: function(expectedSignature) {
3619                var signature = this.reader.readString(4);
3620                if (signature !== expectedSignature) {
3621                    throw new Error("Corrupted zip or bug : unexpected signature " + "(" + utils.pretty(signature) + ", expected " + utils.pretty(expectedSignature) + ")");
3622                }
3623            },
3624            /**
3625             * Check if the given signature is at the given index.
3626             * @param {number} askedIndex the index to check.
3627             * @param {string} expectedSignature the signature to expect.
3628             * @return {boolean} true if the signature is here, false otherwise.
3629             */
3630            isSignature: function(askedIndex, expectedSignature) {
3631                var currentIndex = this.reader.index;
3632                this.reader.setIndex(askedIndex);
3633                var signature = this.reader.readString(4);
3634                var result = signature === expectedSignature;
3635                this.reader.setIndex(currentIndex);
3636                return result;
3637            },
3638            /**
3639             * Read the end of the central directory.
3640             */
3641            readBlockEndOfCentral: function() {
3642                this.diskNumber = this.reader.readInt(2);
3643                this.diskWithCentralDirStart = this.reader.readInt(2);
3644                this.centralDirRecordsOnThisDisk = this.reader.readInt(2);
3645                this.centralDirRecords = this.reader.readInt(2);
3646                this.centralDirSize = this.reader.readInt(4);
3647                this.centralDirOffset = this.reader.readInt(4);
3648
3649                this.zipCommentLength = this.reader.readInt(2);
3650                // warning : the encoding depends of the system locale
3651                // On a linux machine with LANG=en_US.utf8, this field is utf8 encoded.
3652                // On a windows machine, this field is encoded with the localized windows code page.
3653                var zipComment = this.reader.readData(this.zipCommentLength);
3654                var decodeParamType = support.uint8array ? "uint8array" : "array";
3655                // To get consistent behavior with the generation part, we will assume that
3656                // this is utf8 encoded unless specified otherwise.
3657                var decodeContent = utils.transformTo(decodeParamType, zipComment);
3658                this.zipComment = this.loadOptions.decodeFileName(decodeContent);
3659            },
3660            /**
3661             * Read the end of the Zip 64 central directory.
3662             * Not merged with the method readEndOfCentral :
3663             * The end of central can coexist with its Zip64 brother,
3664             * I don't want to read the wrong number of bytes !
3665             */
3666            readBlockZip64EndOfCentral: function() {
3667                this.zip64EndOfCentralSize = this.reader.readInt(8);
3668                this.versionMadeBy = this.reader.readString(2);
3669                this.versionNeeded = this.reader.readInt(2);
3670                this.diskNumber = this.reader.readInt(4);
3671                this.diskWithCentralDirStart = this.reader.readInt(4);
3672                this.centralDirRecordsOnThisDisk = this.reader.readInt(8);
3673                this.centralDirRecords = this.reader.readInt(8);
3674                this.centralDirSize = this.reader.readInt(8);
3675                this.centralDirOffset = this.reader.readInt(8);
3676
3677                this.zip64ExtensibleData = {};
3678                var extraDataSize = this.zip64EndOfCentralSize - 44,
3679                    index = 0,
3680                    extraFieldId,
3681                    extraFieldLength,
3682                    extraFieldValue;
3683                while (index < extraDataSize) {
3684                    extraFieldId = this.reader.readInt(2);
3685                    extraFieldLength = this.reader.readInt(4);
3686                    extraFieldValue = this.reader.readString(extraFieldLength);
3687                    this.zip64ExtensibleData[extraFieldId] = {
3688                        id: extraFieldId,
3689                        length: extraFieldLength,
3690                        value: extraFieldValue
3691                    };
3692                }
3693            },
3694            /**
3695             * Read the end of the Zip 64 central directory locator.
3696             */
3697            readBlockZip64EndOfCentralLocator: function() {
3698                this.diskWithZip64CentralDirStart = this.reader.readInt(4);
3699                this.relativeOffsetEndOfZip64CentralDir = this.reader.readInt(8);
3700                this.disksCount = this.reader.readInt(4);
3701                if (this.disksCount > 1) {
3702                    throw new Error("Multi-volumes zip are not supported");
3703                }
3704            },
3705            /**
3706             * Read the local files, based on the offset read in the central part.
3707             */
3708            readLocalFiles: function() {
3709                var i, file;
3710                for (i = 0; i < this.files.length; i++) {
3711                    file = this.files[i];
3712                    this.reader.setIndex(file.localHeaderOffset);
3713                    this.checkSignature(sig.LOCAL_FILE_HEADER);
3714                    file.readLocalPart(this.reader);
3715                    file.handleUTF8();
3716                    file.processAttributes();
3717                }
3718            },
3719            /**
3720             * Read the central directory.
3721             */
3722            readCentralDir: function() {
3723                var file;
3724
3725                this.reader.setIndex(this.centralDirOffset);
3726                while (this.reader.readString(4) === sig.CENTRAL_FILE_HEADER) {
3727                    file = new ZipEntry({
3728                        zip64: this.zip64
3729                    }, this.loadOptions);
3730                    file.readCentralPart(this.reader);
3731                    this.files.push(file);
3732                }
3733
3734                if (this.centralDirRecords !== this.files.length) {
3735                    if (this.centralDirRecords !== 0 && this.files.length === 0) {
3736                        // We expected some records but couldn't find ANY.
3737                        // This is really suspicious, as if something went wrong.
3738                        throw new Error("Corrupted zip or bug: expected " + this.centralDirRecords + " records in central dir, got " + this.files.length);
3739                    } else {
3740                        // We found some records but not all.
3741                        // Something is wrong but we got something for the user: no error here.
3742                        // console.warn("expected", this.centralDirRecords, "records in central dir, got", this.files.length);
3743                    }
3744                }
3745            },
3746            /**
3747             * Read the end of central directory.
3748             */
3749            readEndOfCentral: function() {
3750                var offset = this.reader.lastIndexOfSignature(sig.CENTRAL_DIRECTORY_END);
3751                if (offset < 0) {
3752                    // Check if the content is a truncated zip or complete garbage.
3753                    // A "LOCAL_FILE_HEADER" is not required at the beginning (auto
3754                    // extractible zip for example) but it can give a good hint.
3755                    // If an ajax request was used without responseType, we will also
3756                    // get unreadable data.
3757                    var isGarbage = !this.isSignature(0, sig.LOCAL_FILE_HEADER);
3758
3759                    if (isGarbage) {
3760                        throw new Error("Can't find end of central directory : is this a zip file ? " +
3761                            "If it is, see http://stuk.github.io/jszip/documentation/howto/read_zip.html");
3762                    } else {
3763                        throw new Error("Corrupted zip : can't find end of central directory");
3764                    }
3765                }
3766                this.reader.setIndex(offset);
3767                var endOfCentralDirOffset = offset;
3768                this.checkSignature(sig.CENTRAL_DIRECTORY_END);
3769                this.readBlockEndOfCentral();
3770
3771
3772                /* extract from the zip spec :
3773            4)  If one of the fields in the end of central directory
3774                record is too small to hold required data, the field
3775                should be set to -1 (0xFFFF or 0xFFFFFFFF) and the
3776                ZIP64 format record should be created.
3777            5)  The end of central directory record and the
3778                Zip64 end of central directory locator record must
3779                reside on the same disk when splitting or spanning
3780                an archive.
3781         */
3782                if (this.diskNumber === utils.MAX_VALUE_16BITS || this.diskWithCentralDirStart === utils.MAX_VALUE_16BITS || this.centralDirRecordsOnThisDisk === utils.MAX_VALUE_16BITS || this.centralDirRecords === utils.MAX_VALUE_16BITS || this.centralDirSize === utils.MAX_VALUE_32BITS || this.centralDirOffset === utils.MAX_VALUE_32BITS) {
3783                    this.zip64 = true;
3784
3785                    /*
3786            Warning : the zip64 extension is supported, but ONLY if the 64bits integer read from
3787            the zip file can fit into a 32bits integer. This cannot be solved : Javascript represents
3788            all numbers as 64-bit double precision IEEE 754 floating point numbers.
3789            So, we have 53bits for integers and bitwise operations treat everything as 32bits.
3790            see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Bitwise_Operators
3791            and http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf section 8.5
3792            */
3793
3794                    // should look for a zip64 EOCD locator
3795                    offset = this.reader.lastIndexOfSignature(sig.ZIP64_CENTRAL_DIRECTORY_LOCATOR);
3796                    if (offset < 0) {
3797                        throw new Error("Corrupted zip : can't find the ZIP64 end of central directory locator");
3798                    }
3799                    this.reader.setIndex(offset);
3800                    this.checkSignature(sig.ZIP64_CENTRAL_DIRECTORY_LOCATOR);
3801                    this.readBlockZip64EndOfCentralLocator();
3802
3803                    // now the zip64 EOCD record
3804                    if (!this.isSignature(this.relativeOffsetEndOfZip64CentralDir, sig.ZIP64_CENTRAL_DIRECTORY_END)) {
3805                        // console.warn("ZIP64 end of central directory not where expected.");
3806                        this.relativeOffsetEndOfZip64CentralDir = this.reader.lastIndexOfSignature(sig.ZIP64_CENTRAL_DIRECTORY_END);
3807                        if (this.relativeOffsetEndOfZip64CentralDir < 0) {
3808                            throw new Error("Corrupted zip : can't find the ZIP64 end of central directory");
3809                        }
3810                    }
3811                    this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir);
3812                    this.checkSignature(sig.ZIP64_CENTRAL_DIRECTORY_END);
3813                    this.readBlockZip64EndOfCentral();
3814                }
3815
3816                var expectedEndOfCentralDirOffset = this.centralDirOffset + this.centralDirSize;
3817                if (this.zip64) {
3818                    expectedEndOfCentralDirOffset += 20; // end of central dir 64 locator
3819                    expectedEndOfCentralDirOffset += 12 /* should not include the leading 12 bytes */ + this.zip64EndOfCentralSize;
3820                }
3821
3822                var extraBytes = endOfCentralDirOffset - expectedEndOfCentralDirOffset;
3823
3824                if (extraBytes > 0) {
3825                    // console.warn(extraBytes, "extra bytes at beginning or within zipfile");
3826                    if (this.isSignature(endOfCentralDirOffset, sig.CENTRAL_FILE_HEADER)) {
3827                        // The offsets seem wrong, but we have something at the specified offset.
3828                        // So… we keep it.
3829                    } else {
3830                        // the offset is wrong, update the "zero" of the reader
3831                        // this happens if data has been prepended (crx files for example)
3832                        this.reader.zero = extraBytes;
3833                    }
3834                } else if (extraBytes < 0) {
3835                    throw new Error("Corrupted zip: missing " + Math.abs(extraBytes) + " bytes.");
3836                }
3837            },
3838            prepareReader: function(data) {
3839                var type = utils.getTypeOf(data);
3840                utils.checkSupport(type);
3841                if (type === "string" && !support.uint8array) {
3842                    this.reader = new StringReader(data, this.loadOptions.optimizedBinaryString);
3843                }
3844                else if (type === "nodebuffer") {
3845                    this.reader = new NodeBufferReader(data);
3846                }
3847                else if (support.uint8array) {
3848                    this.reader = new Uint8ArrayReader(utils.transformTo("uint8array", data));
3849                } else if (support.array) {
3850                    this.reader = new ArrayReader(utils.transformTo("array", data));
3851                } else {
3852                    throw new Error("Unexpected error: unsupported type '" + type + "'");
3853                }
3854            },
3855            /**
3856             * Read a zip file and create ZipEntries.
3857             * @param {String|ArrayBuffer|Uint8Array|Buffer} data the binary string representing a zip file.
3858             */
3859            load: function(data) {
3860                this.prepareReader(data);
3861                this.readEndOfCentral();
3862                this.readCentralDir();
3863                this.readLocalFiles();
3864            }
3865        };
3866// }}} end of ZipEntries
3867        module.exports = ZipEntries;
3868
3869    },{"./arrayReader":5,"./nodeBufferReader":17,"./object":18,"./signature":19,"./stringReader":20,"./support":22,"./uint8ArrayReader":23,"./utils":26,"./zipEntry":28}],28:[function(_dereq_,module,exports){
3870        'use strict';
3871        var StringReader = _dereq_('./stringReader');
3872        var utils = _dereq_('./utils');
3873        var CompressedObject = _dereq_('./compressedObject');
3874        var jszipProto = _dereq_('./object');
3875        var support = _dereq_('./support');
3876
3877        var MADE_BY_DOS = 0x00;
3878        var MADE_BY_UNIX = 0x03;
3879
3880// class ZipEntry {{{
3881        /**
3882         * An entry in the zip file.
3883         * @constructor
3884         * @param {Object} options Options of the current file.
3885         * @param {Object} loadOptions Options for loading the stream.
3886         */
3887        function ZipEntry(options, loadOptions) {
3888            this.options = options;
3889            this.loadOptions = loadOptions;
3890        }
3891        ZipEntry.prototype = {
3892            /**
3893             * say if the file is encrypted.
3894             * @return {boolean} true if the file is encrypted, false otherwise.
3895             */
3896            isEncrypted: function() {
3897                // bit 1 is set
3898                return (this.bitFlag & 0x0001) === 0x0001;
3899            },
3900            /**
3901             * say if the file has utf-8 filename/comment.
3902             * @return {boolean} true if the filename/comment is in utf-8, false otherwise.
3903             */
3904            useUTF8: function() {
3905                // bit 11 is set
3906                return (this.bitFlag & 0x0800) === 0x0800;
3907            },
3908            /**
3909             * Prepare the function used to generate the compressed content from this ZipFile.
3910             * @param {DataReader} reader the reader to use.
3911             * @param {number} from the offset from where we should read the data.
3912             * @param {number} length the length of the data to read.
3913             * @return {Function} the callback to get the compressed content (the type depends of the DataReader class).
3914             */
3915            prepareCompressedContent: function(reader, from, length) {
3916                return function() {
3917                    var previousIndex = reader.index;
3918                    reader.setIndex(from);
3919                    var compressedFileData = reader.readData(length);
3920                    reader.setIndex(previousIndex);
3921
3922                    return compressedFileData;
3923                };
3924            },
3925            /**
3926             * Prepare the function used to generate the uncompressed content from this ZipFile.
3927             * @param {DataReader} reader the reader to use.
3928             * @param {number} from the offset from where we should read the data.
3929             * @param {number} length the length of the data to read.
3930             * @param {JSZip.compression} compression the compression used on this file.
3931             * @param {number} uncompressedSize the uncompressed size to expect.
3932             * @return {Function} the callback to get the uncompressed content (the type depends of the DataReader class).
3933             */
3934            prepareContent: function(reader, from, length, compression, uncompressedSize) {
3935                return function() {
3936
3937                    var compressedFileData = utils.transformTo(compression.uncompressInputType, this.getCompressedContent());
3938                    var uncompressedFileData = compression.uncompress(compressedFileData);
3939
3940                    if (uncompressedFileData.length !== uncompressedSize) {
3941                        throw new Error("Bug : uncompressed data size mismatch");
3942                    }
3943
3944                    return uncompressedFileData;
3945                };
3946            },
3947            /**
3948             * Read the local part of a zip file and add the info in this object.
3949             * @param {DataReader} reader the reader to use.
3950             */
3951            readLocalPart: function(reader) {
3952                var compression, localExtraFieldsLength;
3953
3954                // we already know everything from the central dir !
3955                // If the central dir data are false, we are doomed.
3956                // On the bright side, the local part is scary  : zip64, data descriptors, both, etc.
3957                // The less data we get here, the more reliable this should be.
3958                // Let's skip the whole header and dash to the data !
3959                reader.skip(22);
3960                // in some zip created on windows, the filename stored in the central dir contains \ instead of /.
3961                // Strangely, the filename here is OK.
3962                // I would love to treat these zip files as corrupted (see http://www.info-zip.org/FAQ.html#backslashes
3963                // or APPNOTE#4.4.17.1, "All slashes MUST be forward slashes '/'") but there are a lot of bad zip generators...
3964                // Search "unzip mismatching "local" filename continuing with "central" filename version" on
3965                // the internet.
3966                //
3967                // I think I see the logic here : the central directory is used to display
3968                // content and the local directory is used to extract the files. Mixing / and \
3969                // may be used to display \ to windows users and use / when extracting the files.
vendor: 12,966 bytes, lines 3970-4263
3970                // Unfortunately, this lead also to some issues : http://seclists.org/fulldisclosure/2009/Sep/394
3971                this.fileNameLength = reader.readInt(2);
3972                localExtraFieldsLength = reader.readInt(2); // can't be sure this will be the same as the central dir
3973                this.fileName = reader.readData(this.fileNameLength);
3974                reader.skip(localExtraFieldsLength);
3975
3976                if (this.compressedSize == -1 || this.uncompressedSize == -1) {
3977                    throw new Error("Bug or corrupted zip : didn't get enough informations from the central directory " + "(compressedSize == -1 || uncompressedSize == -1)");
3978                }
3979
3980                compression = utils.findCompression(this.compressionMethod);
3981                if (compression === null) { // no compression found
3982                    throw new Error("Corrupted zip : compression " + utils.pretty(this.compressionMethod) + " unknown (inner file : " +  utils.transformTo("string", this.fileName) + ")");
3983                }
3984                this.decompressed = new CompressedObject();
3985                this.decompressed.compressedSize = this.compressedSize;
3986                this.decompressed.uncompressedSize = this.uncompressedSize;
3987                this.decompressed.crc32 = this.crc32;
3988                this.decompressed.compressionMethod = this.compressionMethod;
3989                this.decompressed.getCompressedContent = this.prepareCompressedContent(reader, reader.index, this.compressedSize, compression);
3990                this.decompressed.getContent = this.prepareContent(reader, reader.index, this.compressedSize, compression, this.uncompressedSize);
3991
3992                // we need to compute the crc32...
3993                if (this.loadOptions.checkCRC32) {
3994                    this.decompressed = utils.transformTo("string", this.decompressed.getContent());
3995                    if (jszipProto.crc32(this.decompressed) !== this.crc32) {
3996                        throw new Error("Corrupted zip : CRC32 mismatch");
3997                    }
3998                }
3999            },
4000
4001            /**
4002             * Read the central part of a zip file and add the info in this object.
4003             * @param {DataReader} reader the reader to use.
4004             */
4005            readCentralPart: function(reader) {
4006                this.versionMadeBy = reader.readInt(2);
4007                this.versionNeeded = reader.readInt(2);
4008                this.bitFlag = reader.readInt(2);
4009                this.compressionMethod = reader.readString(2);
4010                this.date = reader.readDate();
4011                this.crc32 = reader.readInt(4);
4012                this.compressedSize = reader.readInt(4);
4013                this.uncompressedSize = reader.readInt(4);
4014                this.fileNameLength = reader.readInt(2);
4015                this.extraFieldsLength = reader.readInt(2);
4016                this.fileCommentLength = reader.readInt(2);
4017                this.diskNumberStart = reader.readInt(2);
4018                this.internalFileAttributes = reader.readInt(2);
4019                this.externalFileAttributes = reader.readInt(4);
4020                this.localHeaderOffset = reader.readInt(4);
4021
4022                if (this.isEncrypted()) {
4023                    throw new Error("Encrypted zip are not supported");
4024                }
4025
4026                this.fileName = reader.readData(this.fileNameLength);
4027                this.readExtraFields(reader);
4028                this.parseZIP64ExtraField(reader);
4029                this.fileComment = reader.readData(this.fileCommentLength);
4030            },
4031
4032            /**
4033             * Parse the external file attributes and get the unix/dos permissions.
4034             */
4035            processAttributes: function () {
4036                this.unixPermissions = null;
4037                this.dosPermissions = null;
4038                var madeBy = this.versionMadeBy >> 8;
4039
4040                // Check if we have the DOS directory flag set.
4041                // We look for it in the DOS and UNIX permissions
4042                // but some unknown platform could set it as a compatibility flag.
4043                this.dir = this.externalFileAttributes & 0x0010 ? true : false;
4044
4045                if(madeBy === MADE_BY_DOS) {
4046                    // first 6 bits (0 to 5)
4047                    this.dosPermissions = this.externalFileAttributes & 0x3F;
4048                }
4049
4050                if(madeBy === MADE_BY_UNIX) {
4051                    this.unixPermissions = (this.externalFileAttributes >> 16) & 0xFFFF;
4052                    // the octal permissions are in (this.unixPermissions & 0x01FF).toString(8);
4053                }
4054
4055                // fail safe : if the name ends with a / it probably means a folder
4056                if (!this.dir && this.fileNameStr.slice(-1) === '/') {
4057                    this.dir = true;
4058                }
4059            },
4060
4061            /**
4062             * Parse the ZIP64 extra field and merge the info in the current ZipEntry.
4063             * @param {DataReader} reader the reader to use.
4064             */
4065            parseZIP64ExtraField: function(reader) {
4066
4067                if (!this.extraFields[0x0001]) {
4068                    return;
4069                }
4070
4071                // should be something, preparing the extra reader
4072                var extraReader = new StringReader(this.extraFields[0x0001].value);
4073
4074                // I really hope that these 64bits integer can fit in 32 bits integer, because js
4075                // won't let us have more.
4076                if (this.uncompressedSize === utils.MAX_VALUE_32BITS) {
4077                    this.uncompressedSize = extraReader.readInt(8);
4078                }
4079                if (this.compressedSize === utils.MAX_VALUE_32BITS) {
4080                    this.compressedSize = extraReader.readInt(8);
4081                }
4082                if (this.localHeaderOffset === utils.MAX_VALUE_32BITS) {
4083                    this.localHeaderOffset = extraReader.readInt(8);
4084                }
4085                if (this.diskNumberStart === utils.MAX_VALUE_32BITS) {
4086                    this.diskNumberStart = extraReader.readInt(4);
4087                }
4088            },
4089            /**
4090             * Read the central part of a zip file and add the info in this object.
4091             * @param {DataReader} reader the reader to use.
4092             */
4093            readExtraFields: function(reader) {
4094                var start = reader.index,
4095                    extraFieldId,
4096                    extraFieldLength,
4097                    extraFieldValue;
4098
4099                this.extraFields = this.extraFields || {};
4100
4101                while (reader.index < start + this.extraFieldsLength) {
4102                    extraFieldId = reader.readInt(2);
4103                    extraFieldLength = reader.readInt(2);
4104                    extraFieldValue = reader.readString(extraFieldLength);
4105
4106                    this.extraFields[extraFieldId] = {
4107                        id: extraFieldId,
4108                        length: extraFieldLength,
4109                        value: extraFieldValue
4110                    };
4111                }
4112            },
4113            /**
4114             * Apply an UTF8 transformation if needed.
4115             */
4116            handleUTF8: function() {
4117                var decodeParamType = support.uint8array ? "uint8array" : "array";
4118                if (this.useUTF8()) {
4119                    this.fileNameStr = jszipProto.utf8decode(this.fileName);
4120                    this.fileCommentStr = jszipProto.utf8decode(this.fileComment);
4121                } else {
4122                    var upath = this.findExtraFieldUnicodePath();
4123                    if (upath !== null) {
4124                        this.fileNameStr = upath;
4125                    } else {
4126                        var fileNameByteArray =  utils.transformTo(decodeParamType, this.fileName);
4127                        this.fileNameStr = this.loadOptions.decodeFileName(fileNameByteArray);
4128                    }
4129
4130                    var ucomment = this.findExtraFieldUnicodeComment();
4131                    if (ucomment !== null) {
4132                        this.fileCommentStr = ucomment;
4133                    } else {
4134                        var commentByteArray =  utils.transformTo(decodeParamType, this.fileComment);
4135                        this.fileCommentStr = this.loadOptions.decodeFileName(commentByteArray);
4136                    }
4137                }
4138            },
4139
4140            /**
4141             * Find the unicode path declared in the extra field, if any.
4142             * @return {String} the unicode path, null otherwise.
4143             */
4144            findExtraFieldUnicodePath: function() {
4145                var upathField = this.extraFields[0x7075];
4146                if (upathField) {
4147                    var extraReader = new StringReader(upathField.value);
4148
4149                    // wrong version
4150                    if (extraReader.readInt(1) !== 1) {
4151                        return null;
4152                    }
4153
4154                    // the crc of the filename changed, this field is out of date.
4155                    if (jszipProto.crc32(this.fileName) !== extraReader.readInt(4)) {
4156                        return null;
4157                    }
4158
4159                    return jszipProto.utf8decode(extraReader.readString(upathField.length - 5));
4160                }
4161                return null;
4162            },
4163
4164            /**
4165             * Find the unicode comment declared in the extra field, if any.
4166             * @return {String} the unicode comment, null otherwise.
4167             */
4168            findExtraFieldUnicodeComment: function() {
4169                var ucommentField = this.extraFields[0x6375];
4170                if (ucommentField) {
4171                    var extraReader = new StringReader(ucommentField.value);
4172
4173                    // wrong version
4174                    if (extraReader.readInt(1) !== 1) {
4175                        return null;
4176                    }
4177
4178                    // the crc of the comment changed, this field is out of date.
4179                    if (jszipProto.crc32(this.fileComment) !== extraReader.readInt(4)) {
4180                        return null;
4181                    }
4182
4183                    return jszipProto.utf8decode(extraReader.readString(ucommentField.length - 5));
4184                }
4185                return null;
4186            }
4187        };
4188        module.exports = ZipEntry;
4189
4190    },{"./compressedObject":7,"./object":18,"./stringReader":20,"./support":22,"./utils":26}],29:[function(_dereq_,module,exports){
4191// Top level file is just a mixin of submodules & constants
4192        'use strict';
4193
4194        var assign    = _dereq_('./lib/utils/common').assign;
4195
4196        var deflate   = _dereq_('./lib/deflate');
4197        var inflate   = _dereq_('./lib/inflate');
4198        var constants = _dereq_('./lib/zlib/constants');
4199
4200        var pako = {};
4201
4202        assign(pako, deflate, inflate, constants);
4203
4204        module.exports = pako;
4205
4206    },{"./lib/deflate":30,"./lib/inflate":31,"./lib/utils/common":32,"./lib/zlib/constants":35}],30:[function(_dereq_,module,exports){
4207        'use strict';
4208
4209
4210        var zlib_deflate = _dereq_('./zlib/deflate');
4211        var utils        = _dereq_('./utils/common');
4212        var strings      = _dereq_('./utils/strings');
4213        var msg          = _dereq_('./zlib/messages');
4214        var ZStream      = _dereq_('./zlib/zstream');
4215
4216        var toString = Object.prototype.toString;
4217
4218        /* Public constants ==========================================================*/
4219        /* ===========================================================================*/
4220
4221        var Z_NO_FLUSH      = 0;
4222        var Z_FINISH        = 4;
4223
4224        var Z_OK            = 0;
4225        var Z_STREAM_END    = 1;
4226        var Z_SYNC_FLUSH    = 2;
4227
4228        var Z_DEFAULT_COMPRESSION = -1;
4229
4230        var Z_DEFAULT_STRATEGY    = 0;
4231
4232        var Z_DEFLATED  = 8;
4233
4234        /* ===========================================================================*/
4235
4236
4237        /**
4238         * class Deflate
4239         *
4240         * Generic JS-style wrapper for zlib calls. If you don't need
4241         * streaming behaviour - use more simple functions: [[deflate]],
4242         * [[deflateRaw]] and [[gzip]].
4243         **/
4244
4245        /* internal
4246 * Deflate.chunks -> Array
4247 *
4248 * Chunks of output data, if [[Deflate#onData]] not overriden.
4249 **/
4250
4251        /**
4252         * Deflate.result -> Uint8Array|Array
4253         *
4254         * Compressed result, generated by default [[Deflate#onData]]
4255         * and [[Deflate#onEnd]] handlers. Filled after you push last chunk
4256         * (call [[Deflate#push]] with `Z_FINISH` / `true` param)  or if you
4257         * push a chunk with explicit flush (call [[Deflate#push]] with
4258         * `Z_SYNC_FLUSH` param).
4259         **/
4260
4261        /**
4262         * Deflate.err -> Number
4263         *
4264         * Error code after deflate finished. 0 (Z_OK) on success.
4265         * You will not need it in real life, because deflate errors
4266         * are possible only on wrong options or bad `onData` / `onEnd`
4267         * custom handlers.
4268         **/
4269
4270        /**
4271         * Deflate.msg -> String
4272         *
4273         * Error message, if [[Deflate.err]] != 0
4274         **/
4275
4276
4277        /**
4278         * new Deflate(options)
4279         * - options (Object): zlib deflate options.
4280         *
4281         * Creates new deflator instance with specified params. Throws exception
4282         * on bad params. Supported options:
4283         *
4284         * - `level`
4285         * - `windowBits`
4286         * - `memLevel`
4287         * - `strategy`
4288         * - `dictionary`
4289         *
4290         * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
4291         * for more information on these.
4292         *
4293         * Additional options, for internal needs:
4294         *
4295         * - `chunkSize` - size of generated data chunks (16K by default)
4296         * - `raw` (Boolean) - do raw deflate
4297         * - `gzip` (Boolean) - create gzip wrapper
4298         * - `to` (String) - if equal to 'string', then result will be "binary string"
4299         *    (each char code [0..255])
4300         * - `header` (Object) - custom header for gzip
4301         *   - `text` (Boolean) - true if compressed data believed to be text
4302         *   - `time` (Number) - modification time, unix timestamp
4303         *   - `os` (Number) - operation system code
4304         *   - `extra` (Array) - array of bytes with extra data (max 65536)
4305         *   - `name` (String) - file name (binary string)
4306         *   - `comment` (String) - comment (binary string)
4307         *   - `hcrc` (Boolean) - true if header crc should be added
4308         *
4309         * ##### Example:
4310         *
4311         * ```javascript
4312         * var pako = require('pako')
4313         *   , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
4314         *   , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
4315         *
4316         * var deflate = new pako.Deflate({ level: 3});
4317         *
4318         * deflate.push(chunk1, false);
4319         * deflate.push(chunk2, true);  // true -> last chunk
4320         *
4321         * if (deflate.err) { throw new Error(deflate.err); }
4322         *
4323         * console.log(deflate.result);
4324         * ```
4325         **/
4326        function Deflate(options) {
vendor: 6,764 bytes, lines 4327-4498
4327            if (!(this instanceof Deflate)) return new Deflate(options);
4328
4329            this.options = utils.assign({
4330                level: Z_DEFAULT_COMPRESSION,
4331                method: Z_DEFLATED,
4332                chunkSize: 16384,
4333                windowBits: 15,
4334                memLevel: 8,
4335                strategy: Z_DEFAULT_STRATEGY,
4336                to: ''
4337            }, options || {});
4338
4339            var opt = this.options;
4340
4341            if (opt.raw && (opt.windowBits > 0)) {
4342                opt.windowBits = -opt.windowBits;
4343            }
4344
4345            else if (opt.gzip && (opt.windowBits > 0) && (opt.windowBits < 16)) {
4346                opt.windowBits += 16;
4347            }
4348
4349            this.err    = 0;      // error code, if happens (0 = Z_OK)
4350            this.msg    = '';     // error message
4351            this.ended  = false;  // used to avoid multiple onEnd() calls
4352            this.chunks = [];     // chunks of compressed data
4353
4354            this.strm = new ZStream();
4355            this.strm.avail_out = 0;
4356
4357            var status = zlib_deflate.deflateInit2(
4358                this.strm,
4359                opt.level,
4360                opt.method,
4361                opt.windowBits,
4362                opt.memLevel,
4363                opt.strategy
4364            );
4365
4366            if (status !== Z_OK) {
4367                throw new Error(msg[status]);
4368            }
4369
4370            if (opt.header) {
4371                zlib_deflate.deflateSetHeader(this.strm, opt.header);
4372            }
4373
4374            if (opt.dictionary) {
4375                var dict;
4376                // Convert data if needed
4377                if (typeof opt.dictionary === 'string') {
4378                    // If we need to compress text, change encoding to utf8.
4379                    dict = strings.string2buf(opt.dictionary);
4380                } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
4381                    dict = new Uint8Array(opt.dictionary);
4382                } else {
4383                    dict = opt.dictionary;
4384                }
4385
4386                status = zlib_deflate.deflateSetDictionary(this.strm, dict);
4387
4388                if (status !== Z_OK) {
4389                    throw new Error(msg[status]);
4390                }
4391
4392                this._dict_set = true;
4393            }
4394        }
4395
4396        /**
4397         * Deflate#push(data[, mode]) -> Boolean
4398         * - data (Uint8Array|Array|ArrayBuffer|String): input data. Strings will be
4399         *   converted to utf8 byte sequence.
4400         * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
4401         *   See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
4402         *
4403         * Sends input data to deflate pipe, generating [[Deflate#onData]] calls with
4404         * new compressed chunks. Returns `true` on success. The last data block must have
4405         * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
4406         * [[Deflate#onEnd]]. For interim explicit flushes (without ending the stream) you
4407         * can use mode Z_SYNC_FLUSH, keeping the compression context.
4408         *
4409         * On fail call [[Deflate#onEnd]] with error code and return false.
4410         *
4411         * We strongly recommend to use `Uint8Array` on input for best speed (output
4412         * array format is detected automatically). Also, don't skip last param and always
4413         * use the same type in your code (boolean or number). That will improve JS speed.
4414         *
4415         * For regular `Array`-s make sure all elements are [0..255].
4416         *
4417         * ##### Example
4418         *
4419         * ```javascript
4420         * push(chunk, false); // push one of data chunks
4421         * ...
4422         * push(chunk, true);  // push last chunk
4423         * ```
4424         **/
4425        Deflate.prototype.push = function (data, mode) {
4426            var strm = this.strm;
4427            var chunkSize = this.options.chunkSize;
4428            var status, _mode;
4429
4430            if (this.ended) { return false; }
4431
4432            _mode = (mode === ~~mode) ? mode : ((mode === true) ? Z_FINISH : Z_NO_FLUSH);
4433
4434            // Convert data if needed
4435            if (typeof data === 'string') {
4436                // If we need to compress text, change encoding to utf8.
4437                strm.input = strings.string2buf(data);
4438            } else if (toString.call(data) === '[object ArrayBuffer]') {
4439                strm.input = new Uint8Array(data);
4440            } else {
4441                strm.input = data;
4442            }
4443
4444            strm.next_in = 0;
4445            strm.avail_in = strm.input.length;
4446
4447            do {
4448                if (strm.avail_out === 0) {
4449                    strm.output = new utils.Buf8(chunkSize);
4450                    strm.next_out = 0;
4451                    strm.avail_out = chunkSize;
4452                }
4453                status = zlib_deflate.deflate(strm, _mode);    /* no bad return value */
4454
4455                if (status !== Z_STREAM_END && status !== Z_OK) {
4456                    this.onEnd(status);
4457                    this.ended = true;
4458                    return false;
4459                }
4460                if (strm.avail_out === 0 || (strm.avail_in === 0 && (_mode === Z_FINISH || _mode === Z_SYNC_FLUSH))) {
4461                    if (this.options.to === 'string') {
4462                        this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out)));
4463                    } else {
4464                        this.onData(utils.shrinkBuf(strm.output, strm.next_out));
4465                    }
4466                }
4467            } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END);
4468
4469            // Finalize on the last chunk.
4470            if (_mode === Z_FINISH) {
4471                status = zlib_deflate.deflateEnd(this.strm);
4472                this.onEnd(status);
4473                this.ended = true;
4474                return status === Z_OK;
4475            }
4476
4477            // callback interim results if Z_SYNC_FLUSH.
4478            if (_mode === Z_SYNC_FLUSH) {
4479                this.onEnd(Z_OK);
4480                strm.avail_out = 0;
4481                return true;
4482            }
4483
4484            return true;
4485        };
4486
4487
4488        /**
4489         * Deflate#onData(chunk) -> Void
4490         * - chunk (Uint8Array|Array|String): ouput data. Type of array depends
4491         *   on js engine support. When string output requested, each chunk
4492         *   will be string.
4493         *
4494         * By default, stores data blocks in `chunks[]` property and glue
4495         * those in `onEnd`. Override this handler, if you need another behaviour.
4496         **/
4497        Deflate.prototype.onData = function (chunk) {
4498            this.chunks.push(chunk);
4499        };
4500
4501
4502        /**
4503         * Deflate#onEnd(status) -> Void
4504         * - status (Number): deflate status. 0 (Z_OK) on success,
4505         *   other if not.
4506         *
4507         * Called once after you tell deflate that the input stream is
4508         * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
4509         * or if an error happened. By default - join collected chunks,
4510         * free memory and fill `results` / `err` properties.
4511         **/
4512        Deflate.prototype.onEnd = function (status) {
4513            // On success - join
4514            if (status === Z_OK) {
4515                if (this.options.to === 'string') {
4516                    this.result = this.chunks.join('');
4517                } else {
4518                    this.result = utils.flattenChunks(this.chunks);
4519                }
4520            }
4521            this.chunks = [];
4522            this.err = status;
4523            this.msg = this.strm.msg;
4524        };
4525
4526
4527        /**
4528         * deflate(data[, options]) -> Uint8Array|Array|String
4529         * - data (Uint8Array|Array|String): input data to compress.
4530         * - options (Object): zlib deflate options.
4531         *
4532         * Compress `data` with deflate algorithm and `options`.
4533         *
4534         * Supported options are:
4535         *
4536         * - level
4537         * - windowBits
4538         * - memLevel
4539         * - strategy
4540         * - dictionary
4541         *
4542         * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
4543         * for more information on these.
4544         *
4545         * Sugar (options):
4546         *
4547         * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
4548         *   negative windowBits implicitly.
4549         * - `to` (String) - if equal to 'string', then result will be "binary string"
4550         *    (each char code [0..255])
4551         *
4552         * ##### Example:
4553         *
4554         * ```javascript
4555         * var pako = require('pako')
4556         *   , data = Uint8Array([1,2,3,4,5,6,7,8,9]);
4557         *
4558         * console.log(pako.deflate(data));
4559         * ```
4560         **/
4561        function deflate(input, options) {
vendor: 6,983 bytes, lines 4562-4758
4562            var deflator = new Deflate(options);
4563
4564            deflator.push(input, true);
4565
4566            // That will never happens, if you don't cheat with options :)
4567            if (deflator.err) { throw deflator.msg; }
4568
4569            return deflator.result;
4570        }
4571
4572
4573        /**
4574         * deflateRaw(data[, options]) -> Uint8Array|Array|String
4575         * - data (Uint8Array|Array|String): input data to compress.
4576         * - options (Object): zlib deflate options.
4577         *
4578         * The same as [[deflate]], but creates raw data, without wrapper
4579         * (header and adler32 crc).
4580         **/
4581        function deflateRaw(input, options) {
4582            options = options || {};
4583            options.raw = true;
4584            return deflate(input, options);
4585        }
4586
4587
4588        /**
4589         * gzip(data[, options]) -> Uint8Array|Array|String
4590         * - data (Uint8Array|Array|String): input data to compress.
4591         * - options (Object): zlib deflate options.
4592         *
4593         * The same as [[deflate]], but create gzip wrapper instead of
4594         * deflate one.
4595         **/
4596        function gzip(input, options) {
4597            options = options || {};
4598            options.gzip = true;
4599            return deflate(input, options);
4600        }
4601
4602
4603        exports.Deflate = Deflate;
4604        exports.deflate = deflate;
4605        exports.deflateRaw = deflateRaw;
4606        exports.gzip = gzip;
4607
4608    },{"./utils/common":32,"./utils/strings":33,"./zlib/deflate":37,"./zlib/messages":42,"./zlib/zstream":44}],31:[function(_dereq_,module,exports){
4609        'use strict';
4610
4611
4612        var zlib_inflate = _dereq_('./zlib/inflate');
4613        var utils        = _dereq_('./utils/common');
4614        var strings      = _dereq_('./utils/strings');
4615        var c            = _dereq_('./zlib/constants');
4616        var msg          = _dereq_('./zlib/messages');
4617        var ZStream      = _dereq_('./zlib/zstream');
4618        var GZheader     = _dereq_('./zlib/gzheader');
4619
4620        var toString = Object.prototype.toString;
4621
4622        /**
4623         * class Inflate
4624         *
4625         * Generic JS-style wrapper for zlib calls. If you don't need
4626         * streaming behaviour - use more simple functions: [[inflate]]
4627         * and [[inflateRaw]].
4628         **/
4629
4630        /* internal
4631 * inflate.chunks -> Array
4632 *
4633 * Chunks of output data, if [[Inflate#onData]] not overriden.
4634 **/
4635
4636        /**
4637         * Inflate.result -> Uint8Array|Array|String
4638         *
4639         * Uncompressed result, generated by default [[Inflate#onData]]
4640         * and [[Inflate#onEnd]] handlers. Filled after you push last chunk
4641         * (call [[Inflate#push]] with `Z_FINISH` / `true` param) or if you
4642         * push a chunk with explicit flush (call [[Inflate#push]] with
4643         * `Z_SYNC_FLUSH` param).
4644         **/
4645
4646        /**
4647         * Inflate.err -> Number
4648         *
4649         * Error code after inflate finished. 0 (Z_OK) on success.
4650         * Should be checked if broken data possible.
4651         **/
4652
4653        /**
4654         * Inflate.msg -> String
4655         *
4656         * Error message, if [[Inflate.err]] != 0
4657         **/
4658
4659
4660        /**
4661         * new Inflate(options)
4662         * - options (Object): zlib inflate options.
4663         *
4664         * Creates new inflator instance with specified params. Throws exception
4665         * on bad params. Supported options:
4666         *
4667         * - `windowBits`
4668         * - `dictionary`
4669         *
4670         * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
4671         * for more information on these.
4672         *
4673         * Additional options, for internal needs:
4674         *
4675         * - `chunkSize` - size of generated data chunks (16K by default)
4676         * - `raw` (Boolean) - do raw inflate
4677         * - `to` (String) - if equal to 'string', then result will be converted
4678         *   from utf8 to utf16 (javascript) string. When string output requested,
4679         *   chunk length can differ from `chunkSize`, depending on content.
4680         *
4681         * By default, when no options set, autodetect deflate/gzip data format via
4682         * wrapper header.
4683         *
4684         * ##### Example:
4685         *
4686         * ```javascript
4687         * var pako = require('pako')
4688         *   , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
4689         *   , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
4690         *
4691         * var inflate = new pako.Inflate({ level: 3});
4692         *
4693         * inflate.push(chunk1, false);
4694         * inflate.push(chunk2, true);  // true -> last chunk
4695         *
4696         * if (inflate.err) { throw new Error(inflate.err); }
4697         *
4698         * console.log(inflate.result);
4699         * ```
4700         **/
4701        function Inflate(options) {
4702            if (!(this instanceof Inflate)) return new Inflate(options);
4703
4704            this.options = utils.assign({
4705                chunkSize: 16384,
4706                windowBits: 0,
4707                to: ''
4708            }, options || {});
4709
4710            var opt = this.options;
4711
4712            // Force window size for `raw` data, if not set directly,
4713            // because we have no header for autodetect.
4714            if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
4715                opt.windowBits = -opt.windowBits;
4716                if (opt.windowBits === 0) { opt.windowBits = -15; }
4717            }
4718
4719            // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
4720            if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&
4721                !(options && options.windowBits)) {
4722                opt.windowBits += 32;
4723            }
4724
4725            // Gzip header has no info about windows size, we can do autodetect only
4726            // for deflate. So, if window size not set, force it to max when gzip possible
4727            if ((opt.windowBits > 15) && (opt.windowBits < 48)) {
4728                // bit 3 (16) -> gzipped data
4729                // bit 4 (32) -> autodetect gzip/deflate
4730                if ((opt.windowBits & 15) === 0) {
4731                    opt.windowBits |= 15;
4732                }
4733            }
4734
4735            this.err    = 0;      // error code, if happens (0 = Z_OK)
4736            this.msg    = '';     // error message
4737            this.ended  = false;  // used to avoid multiple onEnd() calls
4738            this.chunks = [];     // chunks of compressed data
4739
4740            this.strm   = new ZStream();
4741            this.strm.avail_out = 0;
4742
4743            var status  = zlib_inflate.inflateInit2(
4744                this.strm,
4745                opt.windowBits
4746            );
4747
4748            if (status !== c.Z_OK) {
4749                throw new Error(msg[status]);
4750            }
4751
4752            this.header = new GZheader();
4753
4754            zlib_inflate.inflateGetHeader(this.strm, this.header);
4755        }
4756
4757        /**
4758         * Inflate#push(data[, mode]) -> Boolean
4759         * - data (Uint8Array|Array|ArrayBuffer|String): input data
4760         * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
4761         *   See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
4762         *
4763         * Sends input data to inflate pipe, generating [[Inflate#onData]] calls with
4764         * new output chunks. Returns `true` on success. The last data block must have
4765         * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
4766         * [[Inflate#onEnd]]. For interim explicit flushes (without ending the stream) you
4767         * can use mode Z_SYNC_FLUSH, keeping the decompression context.
4768         *
4769         * On fail call [[Inflate#onEnd]] with error code and return false.
4770         *
4771         * We strongly recommend to use `Uint8Array` on input for best speed (output
4772         * format is detected automatically). Also, don't skip last param and always
4773         * use the same type in your code (boolean or number). That will improve JS speed.
4774         *
4775         * For regular `Array`-s make sure all elements are [0..255].
4776         *
4777         * ##### Example
4778         *
4779         * ```javascript
4780         * push(chunk, false); // push one of data chunks
4781         * ...
4782         * push(chunk, true);  // push last chunk
4783         * ```
4784         **/
4785        Inflate.prototype.push = function (data, mode) {
4786            var strm = this.strm;
4787            var chunkSize = this.options.chunkSize;
4788            var dictionary = this.options.dictionary;
4789            var status, _mode;
4790            var next_out_utf8, tail, utf8str;
4791            var dict;
4792
4793            // Flag to properly process Z_BUF_ERROR on testing inflate call
4794            // when we check that all output data was flushed.
4795            var allowBufError = false;
4796
4797            if (this.ended) { return false; }
4798            _mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH);
4799
4800            // Convert data if needed
4801            if (typeof data === 'string') {
4802                // Only binary strings can be decompressed on practice
4803                strm.input = strings.binstring2buf(data);
4804            } else if (toString.call(data) === '[object ArrayBuffer]') {
4805                strm.input = new Uint8Array(data);
4806            } else {
4807                strm.input = data;
4808            }
4809
4810            strm.next_in = 0;
4811            strm.avail_in = strm.input.length;
4812
4813            do {
4814                if (strm.avail_out === 0) {
4815                    strm.output = new utils.Buf8(chunkSize);
4816                    strm.next_out = 0;
4817                    strm.avail_out = chunkSize;
4818                }
4819
4820                status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH);    /* no bad return value */
4821
4822                if (status === c.Z_NEED_DICT && dictionary) {
4823                    // Convert data if needed
4824                    if (typeof dictionary === 'string') {
4825                        dict = strings.string2buf(dictionary);
4826                    } else if (toString.call(dictionary) === '[object ArrayBuffer]') {
4827                        dict = new Uint8Array(dictionary);
4828                    } else {
4829                        dict = dictionary;
4830                    }
4831
4832                    status = zlib_inflate.inflateSetDictionary(this.strm, dict);
4833
4834                }
4835
4836                if (status === c.Z_BUF_ERROR && allowBufError === true) {
4837                    status = c.Z_OK;
4838                    allowBufError = false;
4839                }
4840
4841                if (status !== c.Z_STREAM_END && status !== c.Z_OK) {
4842                    this.onEnd(status);
4843                    this.ended = true;
4844                    return false;
4845                }
4846
4847                if (strm.next_out) {
4848                    if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && (_mode === c.Z_FINISH || _mode === c.Z_SYNC_FLUSH))) {
4849
4850                        if (this.options.to === 'string') {
4851
4852                            next_out_utf8 = strings.utf8border(strm.output, strm.next_out);
4853
4854                            tail = strm.next_out - next_out_utf8;
4855                            utf8str = strings.buf2string(strm.output, next_out_utf8);
4856
4857                            // move tail
4858                            strm.next_out = tail;
4859                            strm.avail_out = chunkSize - tail;
4860                            if (tail) { utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0); }
4861
4862                            this.onData(utf8str);
4863
4864                        } else {
4865                            this.onData(utils.shrinkBuf(strm.output, strm.next_out));
4866                        }
4867                    }
4868                }
4869
4870                // When no more input data, we should check that internal inflate buffers
4871                // are flushed. The only way to do it when avail_out = 0 - run one more
4872                // inflate pass. But if output data not exists, inflate return Z_BUF_ER
vendor: 97,403 bytes, lines 4872-7306
4872ROR.
4873                // Here we set flag to process this error properly.
4874                //
4875                // NOTE. Deflate does not return error in this case and does not needs such
4876                // logic.
4877                if (strm.avail_in === 0 && strm.avail_out === 0) {
4878                    allowBufError = true;
4879                }
4880
4881            } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== c.Z_STREAM_END);
4882
4883            if (status === c.Z_STREAM_END) {
4884                _mode = c.Z_FINISH;
4885            }
4886
4887            // Finalize on the last chunk.
4888            if (_mode === c.Z_FINISH) {
4889                status = zlib_inflate.inflateEnd(this.strm);
4890                this.onEnd(status);
4891                this.ended = true;
4892                return status === c.Z_OK;
4893            }
4894
4895            // callback interim results if Z_SYNC_FLUSH.
4896            if (_mode === c.Z_SYNC_FLUSH) {
4897                this.onEnd(c.Z_OK);
4898                strm.avail_out = 0;
4899                return true;
4900            }
4901
4902            return true;
4903        };
4904
4905
4906        /**
4907         * Inflate#onData(chunk) -> Void
4908         * - chunk (Uint8Array|Array|String): ouput data. Type of array depends
4909         *   on js engine support. When string output requested, each chunk
4910         *   will be string.
4911         *
4912         * By default, stores data blocks in `chunks[]` property and glue
4913         * those in `onEnd`. Override this handler, if you need another behaviour.
4914         **/
4915        Inflate.prototype.onData = function (chunk) {
4916            this.chunks.push(chunk);
4917        };
4918
4919
4920        /**
4921         * Inflate#onEnd(status) -> Void
4922         * - status (Number): inflate status. 0 (Z_OK) on success,
4923         *   other if not.
4924         *
4925         * Called either after you tell inflate that the input stream is
4926         * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
4927         * or if an error happened. By default - join collected chunks,
4928         * free memory and fill `results` / `err` properties.
4929         **/
4930        Inflate.prototype.onEnd = function (status) {
4931            // On success - join
4932            if (status === c.Z_OK) {
4933                if (this.options.to === 'string') {
4934                    // Glue & convert here, until we teach pako to send
4935                    // utf8 alligned strings to onData
4936                    this.result = this.chunks.join('');
4937                } else {
4938                    this.result = utils.flattenChunks(this.chunks);
4939                }
4940            }
4941            this.chunks = [];
4942            this.err = status;
4943            this.msg = this.strm.msg;
4944        };
4945
4946
4947        /**
4948         * inflate(data[, options]) -> Uint8Array|Array|String
4949         * - data (Uint8Array|Array|String): input data to decompress.
4950         * - options (Object): zlib inflate options.
4951         *
4952         * Decompress `data` with inflate/ungzip and `options`. Autodetect
4953         * format via wrapper header by default. That's why we don't provide
4954         * separate `ungzip` method.
4955         *
4956         * Supported options are:
4957         *
4958         * - windowBits
4959         *
4960         * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
4961         * for more information.
4962         *
4963         * Sugar (options):
4964         *
4965         * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
4966         *   negative windowBits implicitly.
4967         * - `to` (String) - if equal to 'string', then result will be converted
4968         *   from utf8 to utf16 (javascript) string. When string output requested,
4969         *   chunk length can differ from `chunkSize`, depending on content.
4970         *
4971         *
4972         * ##### Example:
4973         *
4974         * ```javascript
4975         * var pako = require('pako')
4976         *   , input = pako.deflate([1,2,3,4,5,6,7,8,9])
4977         *   , output;
4978         *
4979         * try {
4980         *   output = pako.inflate(input);
4981         * } catch (err)
4982         *   console.log(err);
4983         * }
4984         * ```
4985         **/
4986        function inflate(input, options) {
4987            var inflator = new Inflate(options);
4988
4989            inflator.push(input, true);
4990
4991            // That will never happens, if you don't cheat with options :)
4992            if (inflator.err) { throw inflator.msg; }
4993
4994            return inflator.result;
4995        }
4996
4997
4998        /**
4999         * inflateRaw(data[, options]) -> Uint8Array|Array|String
5000         * - data (Uint8Array|Array|String): input data to decompress.
5001         * - options (Object): zlib inflate options.
5002         *
5003         * The same as [[inflate]], but creates raw data, without wrapper
5004         * (header and adler32 crc).
5005         **/
5006        function inflateRaw(input, options) {
5007            options = options || {};
5008            options.raw = true;
5009            return inflate(input, options);
5010        }
5011
5012
5013        /**
5014         * ungzip(data[, options]) -> Uint8Array|Array|String
5015         * - data (Uint8Array|Array|String): input data to decompress.
5016         * - options (Object): zlib inflate options.
5017         *
5018         * Just shortcut to [[inflate]], because it autodetects format
5019         * by header.content. Done for convenience.
5020         **/
5021
5022
5023        exports.Inflate = Inflate;
5024        exports.inflate = inflate;
5025        exports.inflateRaw = inflateRaw;
5026        exports.ungzip  = inflate;
5027
5028    },{"./utils/common":32,"./utils/strings":33,"./zlib/constants":35,"./zlib/gzheader":38,"./zlib/inflate":40,"./zlib/messages":42,"./zlib/zstream":44}],32:[function(_dereq_,module,exports){
5029        'use strict';
5030
5031
5032        var TYPED_OK =  (typeof Uint8Array !== 'undefined') &&
5033            (typeof Uint16Array !== 'undefined') &&
5034            (typeof Int32Array !== 'undefined');
5035
5036
5037        exports.assign = function (obj /*from1, from2, from3, ...*/) {
5038            var sources = Array.prototype.slice.call(arguments, 1);
5039            while (sources.length) {
5040                var source = sources.shift();
5041                if (!source) { continue; }
5042
5043                if (typeof source !== 'object') {
5044                    throw new TypeError(source + 'must be non-object');
5045                }
5046
5047                for (var p in source) {
5048                    if (source.hasOwnProperty(p)) {
5049                        obj[p] = source[p];
5050                    }
5051                }
5052            }
5053
5054            return obj;
5055        };
5056
5057
5058// reduce buffer size, avoiding mem copy
5059        exports.shrinkBuf = function (buf, size) {
5060            if (buf.length === size) { return buf; }
5061            if (buf.subarray) { return buf.subarray(0, size); }
5062            buf.length = size;
5063            return buf;
5064        };
5065
5066
5067        var fnTyped = {
5068            arraySet: function (dest, src, src_offs, len, dest_offs) {
5069                if (src.subarray && dest.subarray) {
5070                    dest.set(src.subarray(src_offs, src_offs + len), dest_offs);
5071                    return;
5072                }
5073                // Fallback to ordinary array
5074                for (var i = 0; i < len; i++) {
5075                    dest[dest_offs + i] = src[src_offs + i];
5076                }
5077            },
5078            // Join array of chunks to single array.
5079            flattenChunks: function (chunks) {
5080                var i, l, len, pos, chunk, result;
5081
5082                // calculate data length
5083                len = 0;
5084                for (i = 0, l = chunks.length; i < l; i++) {
5085                    len += chunks[i].length;
5086                }
5087
5088                // join chunks
5089                result = new Uint8Array(len);
5090                pos = 0;
5091                for (i = 0, l = chunks.length; i < l; i++) {
5092                    chunk = chunks[i];
5093                    result.set(chunk, pos);
5094                    pos += chunk.length;
5095                }
5096
5097                return result;
5098            }
5099        };
5100
5101        var fnUntyped = {
5102            arraySet: function (dest, src, src_offs, len, dest_offs) {
5103                for (var i = 0; i < len; i++) {
5104                    dest[dest_offs + i] = src[src_offs + i];
5105                }
5106            },
5107            // Join array of chunks to single array.
5108            flattenChunks: function (chunks) {
5109                return [].concat.apply([], chunks);
5110            }
5111        };
5112
5113
5114// Enable/Disable typed arrays use, for testing
5115//
5116        exports.setTyped = function (on) {
5117            if (on) {
5118                exports.Buf8  = Uint8Array;
5119                exports.Buf16 = Uint16Array;
5120                exports.Buf32 = Int32Array;
5121                exports.assign(exports, fnTyped);
5122            } else {
5123                exports.Buf8  = Array;
5124                exports.Buf16 = Array;
5125                exports.Buf32 = Array;
5126                exports.assign(exports, fnUntyped);
5127            }
5128        };
5129
5130        exports.setTyped(TYPED_OK);
5131
5132    },{}],33:[function(_dereq_,module,exports){
5133// String encode/decode helpers
5134        'use strict';
5135
5136
5137        var utils = _dereq_('./common');
5138
5139
5140// Quick check if we can use fast array to bin string conversion
5141//
5142// - apply(Array) can fail on Android 2.2
5143// - apply(Uint8Array) can fail on iOS 5.1 Safary
5144//
5145        var STR_APPLY_OK = true;
5146        var STR_APPLY_UIA_OK = true;
5147
5148        try { String.fromCharCode.apply(null, [ 0 ]); } catch (__) { STR_APPLY_OK = false; }
5149        try { String.fromCharCode.apply(null, new Uint8Array(1)); } catch (__) { STR_APPLY_UIA_OK = false; }
5150
5151
5152// Table with utf8 lengths (calculated by first byte of sequence)
5153// Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
5154// because max possible codepoint is 0x10ffff
5155        var _utf8len = new utils.Buf8(256);
5156        for (var q = 0; q < 256; q++) {
5157            _utf8len[q] = (q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1);
5158        }
5159        _utf8len[254] = _utf8len[254] = 1; // Invalid sequence start
5160
5161
5162// convert string to array (typed, when possible)
5163        exports.string2buf = function (str) {
5164            var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;
5165
5166            // count binary size
5167            for (m_pos = 0; m_pos < str_len; m_pos++) {
5168                c = str.charCodeAt(m_pos);
5169                if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
5170                    c2 = str.charCodeAt(m_pos + 1);
5171                    if ((c2 & 0xfc00) === 0xdc00) {
5172                        c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
5173                        m_pos++;
5174                    }
5175                }
5176                buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
5177            }
5178
5179            // allocate buffer
5180            buf = new utils.Buf8(buf_len);
5181
5182            // convert
5183            for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
5184                c = str.charCodeAt(m_pos);
5185                if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
5186                    c2 = str.charCodeAt(m_pos + 1);
5187                    if ((c2 & 0xfc00) === 0xdc00) {
5188                        c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
5189                        m_pos++;
5190                    }
5191                }
5192                if (c < 0x80) {
5193                    /* one byte */
5194                    buf[i++] = c;
5195                } else if (c < 0x800) {
5196                    /* two bytes */
5197                    buf[i++] = 0xC0 | (c >>> 6);
5198                    buf[i++] = 0x80 | (c & 0x3f);
5199                } else if (c < 0x10000) {
5200                    /* three bytes */
5201                    buf[i++] = 0xE0 | (c >>> 12);
5202                    buf[i++] = 0x80 | (c >>> 6 & 0x3f);
5203                    buf[i++] = 0x80 | (c & 0x3f);
5204                } else {
5205                    /* four bytes */
5206                    buf[i++] = 0xf0 | (c >>> 18);
5207                    buf[i++] = 0x80 | (c >>> 12 & 0x3f);
5208                    buf[i++] = 0x80 | (c >>> 6 & 0x3f);
5209                    buf[i++] = 0x80 | (c & 0x3f);
5210                }
5211            }
5212
5213            return buf;
5214        };
5215
5216// Helper (used in 2 places)
5217        function buf2binstring(buf, len) {
5218            // use fallback for big arrays to avoid stack overflow
5219            if (len < 65537) {
5220                if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) {
5221                    return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));
5222                }
5223            }
5224
5225            var result = '';
5226            for (var i = 0; i < len; i++) {
5227                result += String.fromCharCode(buf[i]);
5228            }
5229            return result;
5230        }
5231
5232
5233// Convert byte array to binary string
5234        exports.buf2binstring = function (buf) {
5235            return buf2binstring(buf, buf.length);
5236        };
5237
5238
5239// Convert binary string (typed, when possible)
5240        exports.binstring2buf = function (str) {
5241            var buf = new utils.Buf8(str.length);
5242            for (var i = 0, len = buf.length; i < len; i++) {
5243                buf[i] = str.charCodeAt(i);
5244            }
5245            return buf;
5246        };
5247
5248
5249// convert array to string
5250        exports.buf2string = function (buf, max) {
5251            var i, out, c, c_len;
5252            var len = max || buf.length;
5253
5254            // Reserve max possible length (2 words per char)
5255            // NB: by unknown reasons, Array is significantly faster for
5256            //     String.fromCharCode.apply than Uint16Array.
5257            var utf16buf = new Array(len * 2);
5258
5259            for (out = 0, i = 0; i < len;) {
5260                c = buf[i++];
5261                // quick process ascii
5262                if (c < 0x80) { utf16buf[out++] = c; continue; }
5263
5264                c_len = _utf8len[c];
5265                // skip 5 & 6 byte codes
5266                if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len - 1; continue; }
5267
5268                // apply mask on first byte
5269                c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
5270                // join the rest
5271                while (c_len > 1 && i < len) {
5272                    c = (c << 6) | (buf[i++] & 0x3f);
5273                    c_len--;
5274                }
5275
5276                // terminated by end of string?
5277                if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }
5278
5279                if (c < 0x10000) {
5280                    utf16buf[out++] = c;
5281                } else {
5282                    c -= 0x10000;
5283                    utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);
5284                    utf16buf[out++] = 0xdc00 | (c & 0x3ff);
5285                }
5286            }
5287
5288            return buf2binstring(utf16buf, out);
5289        };
5290
5291
5292// Calculate max possible position in utf8 buffer,
5293// that will not break sequence. If that's not possible
5294// - (very small limits) return max size as is.
5295//
5296// buf[] - utf8 bytes array
5297// max   - length limit (mandatory);
5298        exports.utf8border = function (buf, max) {
5299            var pos;
5300
5301            max = max || buf.length;
5302            if (max > buf.length) { max = buf.length; }
5303
5304            // go back from last position, until start of sequence found
5305            pos = max - 1;
5306            while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }
5307
5308            // Fuckup - very small and broken sequence,
5309            // return max, because we should return something anyway.
5310            if (pos < 0) { return max; }
5311
5312            // If we came to start of buffer - that means vuffer is too small,
5313            // return max too.
5314            if (pos === 0) { return max; }
5315
5316            return (pos + _utf8len[buf[pos]] > max) ? pos : max;
5317        };
5318
5319    },{"./common":32}],34:[function(_dereq_,module,exports){
5320        'use strict';
5321
5322// Note: adler32 takes 12% for level 0 and 2% for level 6.
5323// It doesn't worth to make additional optimizationa as in original.
5324// Small size is preferable.
5325
5326        function adler32(adler, buf, len, pos) {
5327            var s1 = (adler & 0xffff) |0,
5328                s2 = ((adler >>> 16) & 0xffff) |0,
5329                n = 0;
5330
5331            while (len !== 0) {
5332                // Set limit ~ twice less than 5552, to keep
5333                // s2 in 31-bits, because we force signed ints.
5334                // in other case %= will fail.
5335                n = len > 2000 ? 2000 : len;
5336                len -= n;
5337
5338                do {
5339                    s1 = (s1 + buf[pos++]) |0;
5340                    s2 = (s2 + s1) |0;
5341                } while (--n);
5342
5343                s1 %= 65521;
5344                s2 %= 65521;
5345            }
5346
5347            return (s1 | (s2 << 16)) |0;
5348        }
5349
5350
5351        module.exports = adler32;
5352
5353    },{}],35:[function(_dereq_,module,exports){
5354        'use strict';
5355
5356
5357        module.exports = {
5358
5359            /* Allowed flush values; see deflate() and inflate() below for details */
5360            Z_NO_FLUSH:         0,
5361            Z_PARTIAL_FLUSH:    1,
5362            Z_SYNC_FLUSH:       2,
5363            Z_FULL_FLUSH:       3,
5364            Z_FINISH:           4,
5365            Z_BLOCK:            5,
5366            Z_TREES:            6,
5367
5368            /* Return codes for the compression/decompression functions. Negative values
5369  * are errors, positive values are used for special but normal events.
5370  */
5371            Z_OK:               0,
5372            Z_STREAM_END:       1,
5373            Z_NEED_DICT:        2,
5374            Z_ERRNO:           -1,
5375            Z_STREAM_ERROR:    -2,
5376            Z_DATA_ERROR:      -3,
5377            //Z_MEM_ERROR:     -4,
5378            Z_BUF_ERROR:       -5,
5379            //Z_VERSION_ERROR: -6,
5380
5381            /* compression levels */
5382            Z_NO_COMPRESSION:         0,
5383            Z_BEST_SPEED:             1,
5384            Z_BEST_COMPRESSION:       9,
5385            Z_DEFAULT_COMPRESSION:   -1,
5386
5387
5388            Z_FILTERED:               1,
5389            Z_HUFFMAN_ONLY:           2,
5390            Z_RLE:                    3,
5391            Z_FIXED:                  4,
5392            Z_DEFAULT_STRATEGY:       0,
5393
5394            /* Possible values of the data_type field (though see inflate()) */
5395            Z_BINARY:                 0,
5396            Z_TEXT:                   1,
5397            //Z_ASCII:                1, // = Z_TEXT (deprecated)
5398            Z_UNKNOWN:                2,
5399
5400            /* The deflate compression method */
5401            Z_DEFLATED:               8
5402            //Z_NULL:                 null // Use -1 or null inline, depending on var type
5403        };
5404
5405    },{}],36:[function(_dereq_,module,exports){
5406        'use strict';
5407
5408// Note: we can't get significant speed boost here.
5409// So write code to minimize size - no pregenerated tables
5410// and array tools dependencies.
5411
5412
5413// Use ordinary array, since untyped makes no boost here
5414        function makeTable() {
5415            var c, table = [];
5416
5417            for (var n = 0; n < 256; n++) {
5418                c = n;
5419                for (var k = 0; k < 8; k++) {
5420                    c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
5421                }
5422                table[n] = c;
5423            }
5424
5425            return table;
5426        }
5427
5428// Create table on load. Just 255 signed longs. Not a problem.
5429        var crcTable = makeTable();
5430
5431
5432        function crc32(crc, buf, len, pos) {
5433            var t = crcTable,
5434                end = pos + len;
5435
5436            crc ^= -1;
5437
5438            for (var i = pos; i < end; i++) {
5439                crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];
5440            }
5441
5442            return (crc ^ (-1)); // >>> 0;
5443        }
5444
5445
5446        module.exports = crc32;
5447
5448    },{}],37:[function(_dereq_,module,exports){
5449        'use strict';
5450
5451        var utils   = _dereq_('../utils/common');
5452        var trees   = _dereq_('./trees');
5453        var adler32 = _dereq_('./adler32');
5454        var crc32   = _dereq_('./crc32');
5455        var msg     = _dereq_('./messages');
5456
5457        /* Public constants ==========================================================*/
5458        /* ===========================================================================*/
5459
5460
5461        /* Allowed flush values; see deflate() and inflate() below for details */
5462        var Z_NO_FLUSH      = 0;
5463        var Z_PARTIAL_FLUSH = 1;
5464//var Z_SYNC_FLUSH    = 2;
5465        var Z_FULL_FLUSH    = 3;
5466        var Z_FINISH        = 4;
5467        var Z_BLOCK         = 5;
5468//var Z_TREES         = 6;
5469
5470
5471        /* Return codes for the compression/decompression functions. Negative values
5472 * are errors, positive values are used for special but normal events.
5473 */
5474        var Z_OK            = 0;
5475        var Z_STREAM_END    = 1;
5476//var Z_NEED_DICT     = 2;
5477//var Z_ERRNO         = -1;
5478        var Z_STREAM_ERROR  = -2;
5479        var Z_DATA_ERROR    = -3;
5480//var Z_MEM_ERROR     = -4;
5481        var Z_BUF_ERROR     = -5;
5482//var Z_VERSION_ERROR = -6;
5483
5484
5485        /* compression levels */
5486//var Z_NO_COMPRESSION      = 0;
5487//var Z_BEST_SPEED          = 1;
5488//var Z_BEST_COMPRESSION    = 9;
5489        var Z_DEFAULT_COMPRESSION = -1;
5490
5491
5492        var Z_FILTERED            = 1;
5493        var Z_HUFFMAN_ONLY        = 2;
5494        var Z_RLE                 = 3;
5495        var Z_FIXED               = 4;
5496        var Z_DEFAULT_STRATEGY    = 0;
5497
5498        /* Possible values of the data_type field (though see inflate()) */
5499//var Z_BINARY              = 0;
5500//var Z_TEXT                = 1;
5501//var Z_ASCII               = 1; // = Z_TEXT
5502        var Z_UNKNOWN             = 2;
5503
5504
5505        /* The deflate compression method */
5506        var Z_DEFLATED  = 8;
5507
5508        /*============================================================================*/
5509
5510
5511        var MAX_MEM_LEVEL = 9;
5512        /* Maximum value for memLevel in deflateInit2 */
5513        var MAX_WBITS = 15;
5514        /* 32K LZ77 window */
5515        var DEF_MEM_LEVEL = 8;
5516
5517
5518        var LENGTH_CODES  = 29;
5519        /* number of length codes, not counting the special END_BLOCK code */
5520        var LITERALS      = 256;
5521        /* number of literal bytes 0..255 */
5522        var L_CODES       = LITERALS + 1 + LENGTH_CODES;
5523        /* number of Literal or Length codes, including the END_BLOCK code */
5524        var D_CODES       = 30;
5525        /* number of distance codes */
5526        var BL_CODES      = 19;
5527        /* number of codes used to transfer the bit lengths */
5528        var HEAP_SIZE     = 2 * L_CODES + 1;
5529        /* maximum heap size */
5530        var MAX_BITS  = 15;
5531        /* All codes must not exceed MAX_BITS bits */
5532
5533        var MIN_MATCH = 3;
5534        var MAX_MATCH = 258;
5535        var MIN_LOOKAHEAD = (MAX_MATCH + MIN_MATCH + 1);
5536
5537        var PRESET_DICT = 0x20;
5538
5539        var INIT_STATE = 42;
5540        var EXTRA_STATE = 69;
5541        var NAME_STATE = 73;
5542        var COMMENT_STATE = 91;
5543        var HCRC_STATE = 103;
5544        var BUSY_STATE = 113;
5545        var FINISH_STATE = 666;
5546
5547        var BS_NEED_MORE      = 1; /* block not completed, need more input or more output */
5548        var BS_BLOCK_DONE     = 2; /* block flush performed */
5549        var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */
5550        var BS_FINISH_DONE    = 4; /* finish done, accept no more input or output */
5551
5552        var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.
5553
5554        function err(strm, errorCode) {
5555            strm.msg = msg[errorCode];
5556            return errorCode;
5557        }
5558
5559        function rank(f) {
5560            return ((f) << 1) - ((f) > 4 ? 9 : 0);
5561        }
5562
5563        function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
5564
5565
5566        /* =========================================================================
5567 * Flush as much pending output as possible. All deflate() output goes
5568 * through this function so some applications may wish to modify it
5569 * to avoid allocating a large strm->output buffer and copying into it.
5570 * (See also read_buf()).
5571 */
5572        function flush_pending(strm) {
5573            var s = strm.state;
5574
5575            //_tr_flush_bits(s);
5576            var len = s.pending;
5577            if (len > strm.avail_out) {
5578                len = strm.avail_out;
5579            }
5580            if (len === 0) { return; }
5581
5582            utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);
5583            strm.next_out += len;
5584            s.pending_out += len;
5585            strm.total_out += len;
5586            strm.avail_out -= len;
5587            s.pending -= len;
5588            if (s.pending === 0) {
5589                s.pending_out = 0;
5590            }
5591        }
5592
5593
5594        function flush_block_only(s, last) {
5595            trees._tr_flush_block(s, (s.block_start >= 0 ? s.block_start : -1), s.strstart - s.block_start, last);
5596            s.block_start = s.strstart;
5597            flush_pending(s.strm);
5598        }
5599
5600
5601        function put_byte(s, b) {
5602            s.pending_buf[s.pending++] = b;
5603        }
5604
5605
5606        /* =========================================================================
5607 * Put a short in the pending buffer. The 16-bit value is put in MSB order.
5608 * IN assertion: the stream state is correct and there is enough room in
5609 * pending_buf.
5610 */
5611        function putShortMSB(s, b) {
5612//  put_byte(s, (Byte)(b >> 8));
5613//  put_byte(s, (Byte)(b & 0xff));
5614            s.pending_buf[s.pending++] = (b >>> 8) & 0xff;
5615            s.pending_buf[s.pending++] = b & 0xff;
5616        }
5617
5618
5619        /* ===========================================================================
5620 * Read a new buffer from the current input stream, update the adler32
5621 * and total number of bytes read.  All deflate() input goes through
5622 * this function so some applications may wish to modify it to avoid
5623 * allocating a large strm->input buffer and copying from it.
5624 * (See also flush_pending()).
5625 */
5626        function read_buf(strm, buf, start, size) {
5627            var len = strm.avail_in;
5628
5629            if (len > size) { len = size; }
5630            if (len === 0) { return 0; }
5631
5632            strm.avail_in -= len;
5633
5634            // zmemcpy(buf, strm->next_in, len);
5635            utils.arraySet(buf, strm.input, strm.next_in, len, start);
5636            if (strm.state.wrap === 1) {
5637                strm.adler = adler32(strm.adler, buf, len, start);
5638            }
5639
5640            else if (strm.state.wrap === 2) {
5641                strm.adler = crc32(strm.adler, buf, len, start);
5642            }
5643
5644            strm.next_in += len;
5645            strm.total_in += len;
5646
5647            return len;
5648        }
5649
5650
5651        /* ===========================================================================
5652 * Set match_start to the longest match starting at the given string and
5653 * return its length. Matches shorter or equal to prev_length are discarded,
5654 * in which case the result is equal to prev_length and match_start is
5655 * garbage.
5656 * IN assertions: cur_match is the head of the hash chain for the current
5657 *   string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
5658 * OUT assertion: the match length is not greater than s->lookahead.
5659 */
5660        function longest_match(s, cur_match) {
5661            var chain_length = s.max_chain_length;      /* max hash chain length */
5662            var scan = s.strstart; /* current string */
5663            var match;                       /* matched string */
5664            var len;                           /* length of current match */
5665            var best_len = s.prev_length;              /* best match length so far */
5666            var nice_match = s.nice_match;             /* stop if match long enough */
5667            var limit = (s.strstart > (s.w_size - MIN_LOOKAHEAD)) ?
5668                s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0/*NIL*/;
5669
5670            var _win = s.window; // shortcut
5671
5672            var wmask = s.w_mask;
5673            var prev  = s.prev;
5674
5675            /* Stop when cur_match becomes <= limit. To simplify the code,
5676   * we prevent matches with the string of window index 0.
5677   */
5678
5679            var strend = s.strstart + MAX_MATCH;
5680            var scan_end1  = _win[scan + best_len - 1];
5681            var scan_end   = _win[scan + best_len];
5682
5683            /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
5684   * It is easy to get rid of this optimization if necessary.
5685   */
5686            // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
5687
5688            /* Do not waste too much time if we already have a good match: */
5689            if (s.prev_length >= s.good_match) {
5690                chain_length >>= 2;
5691            }
5692            /* Do not look for matches beyond the end of the input. This is necessary
5693   * to make deflate deterministic.
5694   */
5695            if (nice_match > s.lookahead) { nice_match = s.lookahead; }
5696
5697            // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
5698
5699            do {
5700                // Assert(cur_match < s->strstart, "no future");
5701                match = cur_match;
5702
5703                /* Skip to next match if the match length cannot increase
5704     * or if the match length is less than 2.  Note that the checks below
5705     * for insufficient lookahead only occur occasionally for performance
5706     * reasons.  Therefore uninitialized memory will be accessed, and
5707     * conditional jumps will be made that depend on those values.
5708     * However the length of the match is limited to the lookahead, so
5709     * the output of deflate is not affected by the uninitialized values.
5710     */
5711
5712                if (_win[match + best_len]     !== scan_end  ||
5713                    _win[match + best_len - 1] !== scan_end1 ||
5714                    _win[match]                !== _win[scan] ||
5715                    _win[++match]              !== _win[scan + 1]) {
5716                    continue;
5717                }
5718
5719                /* The check at best_len-1 can be removed because it will be made
5720     * again later. (This heuristic is not always a win.)
5721     * It is not necessary to compare scan[2] and match[2] since they
5722     * are always equal when the other bytes match, given that
5723     * the hash keys are equal and that HASH_BITS >= 8.
5724     */
5725                scan += 2;
5726                match++;
5727                // Assert(*scan == *match, "match[2]?");
5728
5729                /* We check for insufficient lookahead only every 8th comparison;
5730     * the 256th check will be made at strstart+258.
5731     */
5732                do {
5733                    /*jshint noempty:false*/
5734                } while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
5735                _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
5736                _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
5737                _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
5738                scan < strend);
5739
5740                // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
5741
5742                len = MAX_MATCH - (strend - scan);
5743                scan = strend - MAX_MATCH;
5744
5745                if (len > best_len) {
5746                    s.match_start = cur_match;
5747                    best_len = len;
5748                    if (len >= nice_match) {
5749                        break;
5750                    }
5751                    scan_end1  = _win[scan + best_len - 1];
5752                    scan_end   = _win[scan + best_len];
5753                }
5754            } while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0);
5755
5756            if (best_len <= s.lookahead) {
5757                return best_len;
5758            }
5759            return s.lookahead;
5760        }
5761
5762
5763        /* ===========================================================================
5764 * Fill the window when the lookahead becomes insufficient.
5765 * Updates strstart and lookahead.
5766 *
5767 * IN assertion: lookahead < MIN_LOOKAHEAD
5768 * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
5769 *    At least one byte has been read, or avail_in == 0; reads are
5770 *    performed for at least two bytes (required for the zip translate_eol
5771 *    option -- not supported here).
5772 */
5773        function fill_window(s) {
5774            var _w_size = s.w_size;
5775            var p, n, m, more, str;
5776
5777            //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
5778
5779            do {
5780                more = s.window_size - s.lookahead - s.strstart;
5781
5782                // JS ints have 32 bit, block below not needed
5783                /* Deal with !@#$% 64K limit: */
5784                //if (sizeof(int) <= 2) {
5785                //    if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
5786                //        more = wsize;
5787                //
5788                //  } else if (more == (unsigned)(-1)) {
5789                //        /* Very unlikely, but possible on 16 bit machine if
5790                //         * strstart == 0 && lookahead == 1 (input done a byte at time)
5791                //         */
5792                //        more--;
5793                //    }
5794                //}
5795
5796
5797                /* If the window is almost full and there is insufficient lookahead,
5798     * move the upper half to the lower one to make room in the upper half.
5799     */
5800                if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {
5801
5802                    utils.arraySet(s.window, s.window, _w_size, _w_size, 0);
5803                    s.match_start -= _w_size;
5804                    s.strstart -= _w_size;
5805                    /* we now have strstart >= MAX_DIST */
5806                    s.block_start -= _w_size;
5807
5808                    /* Slide the hash table (could be avoided with 32 bit values
5809       at the expense of memory usage). We slide even when level == 0
5810       to keep the hash table consistent if we switch back to level > 0
5811       later. (Using level 0 permanently is not an optimal usage of
5812       zlib, so we don't care about this pathological case.)
5813       */
5814
5815                    n = s.hash_size;
5816                    p = n;
5817                    do {
5818                        m = s.head[--p];
5819                        s.head[p] = (m >= _w_size ? m - _w_size : 0);
5820                    } while (--n);
5821
5822                    n = _w_size;
5823                    p = n;
5824                    do {
5825                        m = s.prev[--p];
5826                        s.prev[p] = (m >= _w_size ? m - _w_size : 0);
5827                        /* If n is not on any hash chain, prev[n] is garbage but
5828         * its value will never be used.
5829         */
5830                    } while (--n);
5831
5832                    more += _w_size;
5833                }
5834                if (s.strm.avail_in === 0) {
5835                    break;
5836                }
5837
5838                /* If there was no sliding:
5839     *    strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
5840     *    more == window_size - lookahead - strstart
5841     * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
5842     * => more >= window_size - 2*WSIZE + 2
5843     * In the BIG_MEM or MMAP case (not yet supported),
5844     *   window_size == input_size + MIN_LOOKAHEAD  &&
5845     *   strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
5846     * Otherwise, window_size == 2*WSIZE so more >= 2.
5847     * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
5848     */
5849                //Assert(more >= 2, "more < 2");
5850                n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);
5851                s.lookahead += n;
5852
5853                /* Initialize the hash value now that we have some input: */
5854                if (s.lookahead + s.insert >= MIN_MATCH) {
5855                    str = s.strstart - s.insert;
5856                    s.ins_h = s.window[str];
5857
5858                    /* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */
5859                    s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + 1]) & s.hash_mask;
5860//#if MIN_MATCH != 3
5861//        Call update_hash() MIN_MATCH-3 more times
5862//#endif
5863                    while (s.insert) {
5864                        /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
5865                        s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
5866
5867                        s.prev[str & s.w_mask] = s.head[s.ins_h];
5868                        s.head[s.ins_h] = str;
5869                        str++;
5870                        s.insert--;
5871                        if (s.lookahead + s.insert < MIN_MATCH) {
5872                            break;
5873                        }
5874                    }
5875                }
5876                /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
5877     * but this is not important since only literal bytes will be emitted.
5878     */
5879
5880            } while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0);
5881
5882            /* If the WIN_INIT bytes after the end of the current data have never been
5883   * written, then zero those bytes in order to avoid memory check reports of
5884   * the use of uninitialized (or uninitialised as Julian writes) bytes by
5885   * the longest match routines.  Update the high water mark for the next
5886   * time through here.  WIN_INIT is set to MAX_MATCH since the longest match
5887   * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
5888   */
5889//  if (s.high_water < s.window_size) {
5890//    var curr = s.strstart + s.lookahead;
5891//    var init = 0;
5892//
5893//    if (s.high_water < curr) {
5894//      /* Previous high water mark below current data -- zero WIN_INIT
5895//       * bytes or up to end of window, whichever is less.
5896//       */
5897//      init = s.window_size - curr;
5898//      if (init > WIN_INIT)
5899//        init = WIN_INIT;
5900//      zmemzero(s->window + curr, (unsigned)init);
5901//      s->high_water = curr + init;
5902//    }
5903//    else if (s->high_water < (ulg)curr + WIN_INIT) {
5904//      /* High water mark at or above current data, but below current data
5905//       * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
5906//       * to end of window, whichever is less.
5907//       */
5908//      init = (ulg)curr + WIN_INIT - s->high_water;
5909//      if (init > s->window_size - s->high_water)
5910//        init = s->window_size - s->high_water;
5911//      zmemzero(s->window + s->high_water, (unsigned)init);
5912//      s->high_water += init;
5913//    }
5914//  }
5915//
5916//  Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
5917//    "not enough room for search");
5918        }
5919
5920        /* ===========================================================================
5921 * Copy without compression as much as possible from the input stream, return
5922 * the current block state.
5923 * This function does not insert new strings in the dictionary since
5924 * uncompressible data is probably not useful. This function is used
5925 * only for the level=0 compression option.
5926 * NOTE: this function should be optimized to avoid extra copying from
5927 * window to pending_buf.
5928 */
5929        function deflate_stored(s, flush) {
5930            /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
5931   * to pending_buf_size, and each stored block has a 5 byte header:
5932   */
5933            var max_block_size = 0xffff;
5934
5935            if (max_block_size > s.pending_buf_size - 5) {
5936                max_block_size = s.pending_buf_size - 5;
5937            }
5938
5939            /* Copy as much as possible from input to output: */
5940            for (;;) {
5941                /* Fill the window as much as possible: */
5942                if (s.lookahead <= 1) {
5943
5944                    //Assert(s->strstart < s->w_size+MAX_DIST(s) ||
5945                    //  s->block_start >= (long)s->w_size, "slide too late");
5946//      if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) ||
5947//        s.block_start >= s.w_size)) {
5948//        throw  new Error("slide too late");
5949//      }
5950
5951                    fill_window(s);
5952                    if (s.lookahead === 0 && flush === Z_NO_FLUSH) {
5953                        return BS_NEED_MORE;
5954                    }
5955
5956                    if (s.lookahead === 0) {
5957                        break;
5958                    }
5959                    /* flush the current block */
5960                }
5961                //Assert(s->block_start >= 0L, "block gone");
5962//    if (s.block_start < 0) throw new Error("block gone");
5963
5964                s.strstart += s.lookahead;
5965                s.lookahead = 0;
5966
5967                /* Emit a stored block if pending_buf will be full: */
5968                var max_start = s.block_start + max_block_size;
5969
5970                if (s.strstart === 0 || s.strstart >= max_start) {
5971                    /* strstart == 0 is possible when wraparound on 16-bit machine */
5972                    s.lookahead = s.strstart - max_start;
5973                    s.strstart = max_start;
5974                    /*** FLUSH_BLOCK(s, 0); ***/
5975                    flush_block_only(s, false);
5976                    if (s.strm.avail_out === 0) {
5977                        return BS_NEED_MORE;
5978                    }
5979                    /***/
5980
5981
5982                }
5983                /* Flush if we may have to slide, otherwise block_start may become
5984     * negative and the data will be gone:
5985     */
5986                if (s.strstart - s.block_start >= (s.w_size - MIN_LOOKAHEAD)) {
5987                    /*** FLUSH_BLOCK(s, 0); ***/
5988                    flush_block_only(s, false);
5989                    if (s.strm.avail_out === 0) {
5990                        return BS_NEED_MORE;
5991                    }
5992                    /***/
5993                }
5994            }
5995
5996            s.insert = 0;
5997
5998            if (flush === Z_FINISH) {
5999                /*** FLUSH_BLOCK(s, 1); ***/
6000                flush_block_only(s, true);
6001                if (s.strm.avail_out === 0) {
6002                    return BS_FINISH_STARTED;
6003                }
6004                /***/
6005                return BS_FINISH_DONE;
6006            }
6007
6008            if (s.strstart > s.block_start) {
6009                /*** FLUSH_BLOCK(s, 0); ***/
6010                flush_block_only(s, false);
6011                if (s.strm.avail_out === 0) {
6012                    return BS_NEED_MORE;
6013                }
6014                /***/
6015            }
6016
6017            return BS_NEED_MORE;
6018        }
6019
6020        /* ===========================================================================
6021 * Compress as much as possible from the input stream, return the current
6022 * block state.
6023 * This function does not perform lazy evaluation of matches and inserts
6024 * new strings in the dictionary only for unmatched strings or for short
6025 * matches. It is used only for the fast compression options.
6026 */
6027        function deflate_fast(s, flush) {
6028            var hash_head;        /* head of the hash chain */
6029            var bflush;           /* set if current block must be flushed */
6030
6031            for (;;) {
6032                /* Make sure that we always have enough lookahead, except
6033     * at the end of the input file. We need MAX_MATCH bytes
6034     * for the next match, plus MIN_MATCH bytes to insert the
6035     * string following the next match.
6036     */
6037                if (s.lookahead < MIN_LOOKAHEAD) {
6038                    fill_window(s);
6039                    if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
6040                        return BS_NEED_MORE;
6041                    }
6042                    if (s.lookahead === 0) {
6043                        break; /* flush the current block */
6044                    }
6045                }
6046
6047                /* Insert the string window[strstart .. strstart+2] in the
6048     * dictionary, and set hash_head to the head of the hash chain:
6049     */
6050                hash_head = 0/*NIL*/;
6051                if (s.lookahead >= MIN_MATCH) {
6052                    /*** INSERT_STRING(s, s.strstart, hash_head); ***/
6053                    s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
6054                    hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
6055                    s.head[s.ins_h] = s.strstart;
6056                    /***/
6057                }
6058
6059                /* Find the longest match, discarding those <= prev_length.
6060     * At this point we have always match_length < MIN_MATCH
6061     */
6062                if (hash_head !== 0/*NIL*/ && ((s.strstart - hash_head) <= (s.w_size - MIN_LOOKAHEAD))) {
6063                    /* To simplify the code, we prevent matches with the string
6064       * of window index 0 (in particular we have to avoid a match
6065       * of the string with itself at the start of the input file).
6066       */
6067                    s.match_length = longest_match(s, hash_head);
6068                    /* longest_match() sets match_start */
6069                }
6070                if (s.match_length >= MIN_MATCH) {
6071                    // check_match(s, s.strstart, s.match_start, s.match_length); // for debug only
6072
6073                    /*** _tr_tally_dist(s, s.strstart - s.match_start,
6074                     s.match_length - MIN_MATCH, bflush); ***/
6075                    bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);
6076
6077                    s.lookahead -= s.match_length;
6078
6079                    /* Insert new strings in the hash table only if the match length
6080       * is not too large. This saves time but degrades compression.
6081       */
6082                    if (s.match_length <= s.max_lazy_match/*max_insert_length*/ && s.lookahead >= MIN_MATCH) {
6083                        s.match_length--; /* string at strstart already in table */
6084                        do {
6085                            s.strstart++;
6086                            /*** INSERT_STRING(s, s.strstart, hash_head); ***/
6087                            s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
6088                            hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
6089                            s.head[s.ins_h] = s.strstart;
6090                            /***/
6091                            /* strstart never exceeds WSIZE-MAX_MATCH, so there are
6092           * always MIN_MATCH bytes ahead.
6093           */
6094                        } while (--s.match_length !== 0);
6095                        s.strstart++;
6096                    } else
6097                    {
6098                        s.strstart += s.match_length;
6099                        s.match_length = 0;
6100                        s.ins_h = s.window[s.strstart];
6101                        /* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */
6102                        s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + 1]) & s.hash_mask;
6103
6104//#if MIN_MATCH != 3
6105//                Call UPDATE_HASH() MIN_MATCH-3 more times
6106//#endif
6107                        /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
6108         * matter since it will be recomputed at next deflate call.
6109         */
6110                    }
6111                } else {
6112                    /* No match, output a literal byte */
6113                    //Tracevv((stderr,"%c", s.window[s.strstart]));
6114                    /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
6115                    bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
6116
6117                    s.lookahead--;
6118                    s.strstart++;
6119                }
6120                if (bflush) {
6121                    /*** FLUSH_BLOCK(s, 0); ***/
6122                    flush_block_only(s, false);
6123                    if (s.strm.avail_out === 0) {
6124                        return BS_NEED_MORE;
6125                    }
6126                    /***/
6127                }
6128            }
6129            s.insert = ((s.strstart < (MIN_MATCH - 1)) ? s.strstart : MIN_MATCH - 1);
6130            if (flush === Z_FINISH) {
6131                /*** FLUSH_BLOCK(s, 1); ***/
6132                flush_block_only(s, true);
6133                if (s.strm.avail_out === 0) {
6134                    return BS_FINISH_STARTED;
6135                }
6136                /***/
6137                return BS_FINISH_DONE;
6138            }
6139            if (s.last_lit) {
6140                /*** FLUSH_BLOCK(s, 0); ***/
6141                flush_block_only(s, false);
6142                if (s.strm.avail_out === 0) {
6143                    return BS_NEED_MORE;
6144                }
6145                /***/
6146            }
6147            return BS_BLOCK_DONE;
6148        }
6149
6150        /* ===========================================================================
6151 * Same as above, but achieves better compression. We use a lazy
6152 * evaluation for matches: a match is finally adopted only if there is
6153 * no better match at the next window position.
6154 */
6155        function deflate_slow(s, flush) {
6156            var hash_head;          /* head of hash chain */
6157            var bflush;              /* set if current block must be flushed */
6158
6159            var max_insert;
6160
6161            /* Process the input block. */
6162            for (;;) {
6163                /* Make sure that we always have enough lookahead, except
6164     * at the end of the input file. We need MAX_MATCH bytes
6165     * for the next match, plus MIN_MATCH bytes to insert the
6166     * string following the next match.
6167     */
6168                if (s.lookahead < MIN_LOOKAHEAD) {
6169                    fill_window(s);
6170                    if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
6171                        return BS_NEED_MORE;
6172                    }
6173                    if (s.lookahead === 0) { break; } /* flush the current block */
6174                }
6175
6176                /* Insert the string window[strstart .. strstart+2] in the
6177     * dictionary, and set hash_head to the head of the hash chain:
6178     */
6179                hash_head = 0/*NIL*/;
6180                if (s.lookahead >= MIN_MATCH) {
6181                    /*** INSERT_STRING(s, s.strstart, hash_head); ***/
6182                    s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
6183                    hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
6184                    s.head[s.ins_h] = s.strstart;
6185                    /***/
6186                }
6187
6188                /* Find the longest match, discarding those <= prev_length.
6189     */
6190                s.prev_length = s.match_length;
6191                s.prev_match = s.match_start;
6192                s.match_length = MIN_MATCH - 1;
6193
6194                if (hash_head !== 0/*NIL*/ && s.prev_length < s.max_lazy_match &&
6195                    s.strstart - hash_head <= (s.w_size - MIN_LOOKAHEAD)/*MAX_DIST(s)*/) {
6196                    /* To simplify the code, we prevent matches with the string
6197       * of window index 0 (in particular we have to avoid a match
6198       * of the string with itself at the start of the input file).
6199       */
6200                    s.match_length = longest_match(s, hash_head);
6201                    /* longest_match() sets match_start */
6202
6203                    if (s.match_length <= 5 &&
6204                        (s.strategy === Z_FILTERED || (s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096/*TOO_FAR*/))) {
6205
6206                        /* If prev_match is also MIN_MATCH, match_start is garbage
6207         * but we will ignore the current match anyway.
6208         */
6209                        s.match_length = MIN_MATCH - 1;
6210                    }
6211                }
6212                /* If there was a match at the previous step and the current
6213     * match is not better, output the previous match:
6214     */
6215                if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) {
6216                    max_insert = s.strstart + s.lookahead - MIN_MATCH;
6217                    /* Do not insert strings in hash table beyond this. */
6218
6219                    //check_match(s, s.strstart-1, s.prev_match, s.prev_length);
6220
6221                    /***_tr_tally_dist(s, s.strstart - 1 - s.prev_match,
6222                     s.prev_length - MIN_MATCH, bflush);***/
6223                    bflush = trees._tr_tally(s, s.strstart - 1 - s.prev_match, s.prev_length - MIN_MATCH);
6224                    /* Insert in hash table all strings up to the end of the match.
6225       * strstart-1 and strstart are already inserted. If there is not
6226       * enough lookahead, the last two strings are not inserted in
6227       * the hash table.
6228       */
6229                    s.lookahead -= s.prev_length - 1;
6230                    s.prev_length -= 2;
6231                    do {
6232                        if (++s.strstart <= max_insert) {
6233                            /*** INSERT_STRING(s, s.strstart, hash_head); ***/
6234                            s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
6235                            hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
6236                            s.head[s.ins_h] = s.strstart;
6237                            /***/
6238                        }
6239                    } while (--s.prev_length !== 0);
6240                    s.match_available = 0;
6241                    s.match_length = MIN_MATCH - 1;
6242                    s.strstart++;
6243
6244                    if (bflush) {
6245                        /*** FLUSH_BLOCK(s, 0); ***/
6246                        flush_block_only(s, false);
6247                        if (s.strm.avail_out === 0) {
6248                            return BS_NEED_MORE;
6249                        }
6250                        /***/
6251                    }
6252
6253                } else if (s.match_available) {
6254                    /* If there was no match at the previous position, output a
6255       * single literal. If there was a match but the current match
6256       * is longer, truncate the previous match to a single literal.
6257       */
6258                    //Tracevv((stderr,"%c", s->window[s->strstart-1]));
6259                    /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
6260                    bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
6261
6262                    if (bflush) {
6263                        /*** FLUSH_BLOCK_ONLY(s, 0) ***/
6264                        flush_block_only(s, false);
6265                        /***/
6266                    }
6267                    s.strstart++;
6268                    s.lookahead--;
6269                    if (s.strm.avail_out === 0) {
6270                        return BS_NEED_MORE;
6271                    }
6272                } else {
6273                    /* There is no previous match to compare with, wait for
6274       * the next step to decide.
6275       */
6276                    s.match_available = 1;
6277                    s.strstart++;
6278                    s.lookahead--;
6279                }
6280            }
6281            //Assert (flush != Z_NO_FLUSH, "no flush?");
6282            if (s.match_available) {
6283                //Tracevv((stderr,"%c", s->window[s->strstart-1]));
6284                /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
6285                bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
6286
6287                s.match_available = 0;
6288            }
6289            s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;
6290            if (flush === Z_FINISH) {
6291                /*** FLUSH_BLOCK(s, 1); ***/
6292                flush_block_only(s, true);
6293                if (s.strm.avail_out === 0) {
6294                    return BS_FINISH_STARTED;
6295                }
6296                /***/
6297                return BS_FINISH_DONE;
6298            }
6299            if (s.last_lit) {
6300                /*** FLUSH_BLOCK(s, 0); ***/
6301                flush_block_only(s, false);
6302                if (s.strm.avail_out === 0) {
6303                    return BS_NEED_MORE;
6304                }
6305                /***/
6306            }
6307
6308            return BS_BLOCK_DONE;
6309        }
6310
6311
6312        /* ===========================================================================
6313 * For Z_RLE, simply look for runs of bytes, generate matches only of distance
6314 * one.  Do not maintain a hash table.  (It will be regenerated if this run of
6315 * deflate switches away from Z_RLE.)
6316 */
6317        function deflate_rle(s, flush) {
6318            var bflush;            /* set if current block must be flushed */
6319            var prev;              /* byte at distance one to match */
6320            var scan, strend;      /* scan goes up to strend for length of run */
6321
6322            var _win = s.window;
6323
6324            for (;;) {
6325                /* Make sure that we always have enough lookahead, except
6326     * at the end of the input file. We need MAX_MATCH bytes
6327     * for the longest run, plus one for the unrolled loop.
6328     */
6329                if (s.lookahead <= MAX_MATCH) {
6330                    fill_window(s);
6331                    if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) {
6332                        return BS_NEED_MORE;
6333                    }
6334                    if (s.lookahead === 0) { break; } /* flush the current block */
6335                }
6336
6337                /* See how many times the previous byte repeats */
6338                s.match_length = 0;
6339                if (s.lookahead >= MIN_MATCH && s.strstart > 0) {
6340                    scan = s.strstart - 1;
6341                    prev = _win[scan];
6342                    if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) {
6343                        strend = s.strstart + MAX_MATCH;
6344                        do {
6345                            /*jshint noempty:false*/
6346                        } while (prev === _win[++scan] && prev === _win[++scan] &&
6347                        prev === _win[++scan] && prev === _win[++scan] &&
6348                        prev === _win[++scan] && prev === _win[++scan] &&
6349                        prev === _win[++scan] && prev === _win[++scan] &&
6350                        scan < strend);
6351                        s.match_length = MAX_MATCH - (strend - scan);
6352                        if (s.match_length > s.lookahead) {
6353                            s.match_length = s.lookahead;
6354                        }
6355                    }
6356                    //Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
6357                }
6358
6359                /* Emit match if have run of MIN_MATCH or longer, else emit literal */
6360                if (s.match_length >= MIN_MATCH) {
6361                    //check_match(s, s.strstart, s.strstart - 1, s.match_length);
6362
6363                    /*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/
6364                    bflush = trees._tr_tally(s, 1, s.match_length - MIN_MATCH);
6365
6366                    s.lookahead -= s.match_length;
6367                    s.strstart += s.match_length;
6368                    s.match_length = 0;
6369                } else {
6370                    /* No match, output a literal byte */
6371                    //Tracevv((stderr,"%c", s->window[s->strstart]));
6372                    /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
6373                    bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
6374
6375                    s.lookahead--;
6376                    s.strstart++;
6377                }
6378                if (bflush) {
6379                    /*** FLUSH_BLOCK(s, 0); ***/
6380                    flush_block_only(s, false);
6381                    if (s.strm.avail_out === 0) {
6382                        return BS_NEED_MORE;
6383                    }
6384                    /***/
6385                }
6386            }
6387            s.insert = 0;
6388            if (flush === Z_FINISH) {
6389                /*** FLUSH_BLOCK(s, 1); ***/
6390                flush_block_only(s, true);
6391                if (s.strm.avail_out === 0) {
6392                    return BS_FINISH_STARTED;
6393                }
6394                /***/
6395                return BS_FINISH_DONE;
6396            }
6397            if (s.last_lit) {
6398                /*** FLUSH_BLOCK(s, 0); ***/
6399                flush_block_only(s, false);
6400                if (s.strm.avail_out === 0) {
6401                    return BS_NEED_MORE;
6402                }
6403                /***/
6404            }
6405            return BS_BLOCK_DONE;
6406        }
6407
6408        /* ===========================================================================
6409 * For Z_HUFFMAN_ONLY, do not look for matches.  Do not maintain a hash table.
6410 * (It will be regenerated if this run of deflate switches away from Huffman.)
6411 */
6412        function deflate_huff(s, flush) {
6413            var bflush;             /* set if current block must be flushed */
6414
6415            for (;;) {
6416                /* Make sure that we have a literal to write. */
6417                if (s.lookahead === 0) {
6418                    fill_window(s);
6419                    if (s.lookahead === 0) {
6420                        if (flush === Z_NO_FLUSH) {
6421                            return BS_NEED_MORE;
6422                        }
6423                        break;      /* flush the current block */
6424                    }
6425                }
6426
6427                /* Output a literal byte */
6428                s.match_length = 0;
6429                //Tracevv((stderr,"%c", s->window[s->strstart]));
6430                /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
6431                bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
6432                s.lookahead--;
6433                s.strstart++;
6434                if (bflush) {
6435                    /*** FLUSH_BLOCK(s, 0); ***/
6436                    flush_block_only(s, false);
6437                    if (s.strm.avail_out === 0) {
6438                        return BS_NEED_MORE;
6439                    }
6440                    /***/
6441                }
6442            }
6443            s.insert = 0;
6444            if (flush === Z_FINISH) {
6445                /*** FLUSH_BLOCK(s, 1); ***/
6446                flush_block_only(s, true);
6447                if (s.strm.avail_out === 0) {
6448                    return BS_FINISH_STARTED;
6449                }
6450                /***/
6451                return BS_FINISH_DONE;
6452            }
6453            if (s.last_lit) {
6454                /*** FLUSH_BLOCK(s, 0); ***/
6455                flush_block_only(s, false);
6456                if (s.strm.avail_out === 0) {
6457                    return BS_NEED_MORE;
6458                }
6459                /***/
6460            }
6461            return BS_BLOCK_DONE;
6462        }
6463
6464        /* Values for max_lazy_match, good_match and max_chain_length, depending on
6465 * the desired pack level (0..9). The values given below have been tuned to
6466 * exclude worst case performance for pathological files. Better values may be
6467 * found for specific files.
6468 */
6469        function Config(good_length, max_lazy, nice_length, max_chain, func) {
6470            this.good_length = good_length;
6471            this.max_lazy = max_lazy;
6472            this.nice_length = nice_length;
6473            this.max_chain = max_chain;
6474            this.func = func;
6475        }
6476
6477        var configuration_table;
6478
6479        configuration_table = [
6480            /*      good lazy nice chain */
6481            new Config(0, 0, 0, 0, deflate_stored),          /* 0 store only */
6482            new Config(4, 4, 8, 4, deflate_fast),            /* 1 max speed, no lazy matches */
6483            new Config(4, 5, 16, 8, deflate_fast),           /* 2 */
6484            new Config(4, 6, 32, 32, deflate_fast),          /* 3 */
6485
6486            new Config(4, 4, 16, 16, deflate_slow),          /* 4 lazy matches */
6487            new Config(8, 16, 32, 32, deflate_slow),         /* 5 */
6488            new Config(8, 16, 128, 128, deflate_slow),       /* 6 */
6489            new Config(8, 32, 128, 256, deflate_slow),       /* 7 */
6490            new Config(32, 128, 258, 1024, deflate_slow),    /* 8 */
6491            new Config(32, 258, 258, 4096, deflate_slow)     /* 9 max compression */
6492        ];
6493
6494
6495        /* ===========================================================================
6496 * Initialize the "longest match" routines for a new zlib stream
6497 */
6498        function lm_init(s) {
6499            s.window_size = 2 * s.w_size;
6500
6501            /*** CLEAR_HASH(s); ***/
6502            zero(s.head); // Fill with NIL (= 0);
6503
6504            /* Set the default configuration parameters:
6505   */
6506            s.max_lazy_match = configuration_table[s.level].max_lazy;
6507            s.good_match = configuration_table[s.level].good_length;
6508            s.nice_match = configuration_table[s.level].nice_length;
6509            s.max_chain_length = configuration_table[s.level].max_chain;
6510
6511            s.strstart = 0;
6512            s.block_start = 0;
6513            s.lookahead = 0;
6514            s.insert = 0;
6515            s.match_length = s.prev_length = MIN_MATCH - 1;
6516            s.match_available = 0;
6517            s.ins_h = 0;
6518        }
6519
6520
6521        function DeflateState() {
6522            this.strm = null;            /* pointer back to this zlib stream */
6523            this.status = 0;            /* as the name implies */
6524            this.pending_buf = null;      /* output still pending */
6525            this.pending_buf_size = 0;  /* size of pending_buf */
6526            this.pending_out = 0;       /* next pending byte to output to the stream */
6527            this.pending = 0;           /* nb of bytes in the pending buffer */
6528            this.wrap = 0;              /* bit 0 true for zlib, bit 1 true for gzip */
6529            this.gzhead = null;         /* gzip header information to write */
6530            this.gzindex = 0;           /* where in extra, name, or comment */
6531            this.method = Z_DEFLATED; /* can only be DEFLATED */
6532            this.last_flush = -1;   /* value of flush param for previous deflate call */
6533
6534            this.w_size = 0;  /* LZ77 window size (32K by default) */
6535            this.w_bits = 0;  /* log2(w_size)  (8..16) */
6536            this.w_mask = 0;  /* w_size - 1 */
6537
6538            this.window = null;
6539            /* Sliding window. Input bytes are read into the second half of the window,
6540   * and move to the first half later to keep a dictionary of at least wSize
6541   * bytes. With this organization, matches are limited to a distance of
6542   * wSize-MAX_MATCH bytes, but this ensures that IO is always
6543   * performed with a length multiple of the block size.
6544   */
6545
6546            this.window_size = 0;
6547            /* Actual size of window: 2*wSize, except when the user input buffer
6548   * is directly used as sliding window.
6549   */
6550
6551            this.prev = null;
6552            /* Link to older string with same hash index. To limit the size of this
6553   * array to 64K, this link is maintained only for the last 32K strings.
6554   * An index in this array is thus a window index modulo 32K.
6555   */
6556
6557            this.head = null;   /* Heads of the hash chains or NIL. */
6558
6559            this.ins_h = 0;       /* hash index of string to be inserted */
6560            this.hash_size = 0;   /* number of elements in hash table */
6561            this.hash_bits = 0;   /* log2(hash_size) */
6562            this.hash_mask = 0;   /* hash_size-1 */
6563
6564            this.hash_shift = 0;
6565            /* Number of bits by which ins_h must be shifted at each input
6566   * step. It must be such that after MIN_MATCH steps, the oldest
6567   * byte no longer takes part in the hash key, that is:
6568   *   hash_shift * MIN_MATCH >= hash_bits
6569   */
6570
6571            this.block_start = 0;
6572            /* Window position at the beginning of the current output block. Gets
6573   * negative when the window is moved backwards.
6574   */
6575
6576            this.match_length = 0;      /* length of best match */
6577            this.prev_match = 0;        /* previous match */
6578            this.match_available = 0;   /* set if previous match exists */
6579            this.strstart = 0;          /* start of string to insert */
6580            this.match_start = 0;       /* start of matching string */
6581            this.lookahead = 0;         /* number of valid bytes ahead in window */
6582
6583            this.prev_length = 0;
6584            /* Length of the best match at previous step. Matches not greater than this
6585   * are discarded. This is used in the lazy match evaluation.
6586   */
6587
6588            this.max_chain_length = 0;
6589            /* To speed up deflation, hash chains are never searched beyond this
6590   * length.  A higher limit improves compression ratio but degrades the
6591   * speed.
6592   */
6593
6594            this.max_lazy_match = 0;
6595            /* Attempt to find a better match only when the current match is strictly
6596   * smaller than this value. This mechanism is used only for compression
6597   * levels >= 4.
6598   */
6599            // That's alias to max_lazy_match, don't use directly
6600            //this.max_insert_length = 0;
6601            /* Insert new strings in the hash table only if the match length is not
6602   * greater than this length. This saves time but degrades compression.
6603   * max_insert_length is used only for compression levels <= 3.
6604   */
6605
6606            this.level = 0;     /* compression level (1..9) */
6607            this.strategy = 0;  /* favor or force Huffman coding*/
6608
6609            this.good_match = 0;
6610            /* Use a faster search when the previous match is longer than this */
6611
6612            this.nice_match = 0; /* Stop searching when current match exceeds this */
6613
6614            /* used by trees.c: */
6615
6616            /* Didn't use ct_data typedef below to suppress compiler warning */
6617
6618            // struct ct_data_s dyn_ltree[HEAP_SIZE];   /* literal and length tree */
6619            // struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
6620            // struct ct_data_s bl_tree[2*BL_CODES+1];  /* Huffman tree for bit lengths */
6621
6622            // Use flat array of DOUBLE size, with interleaved fata,
6623            // because JS does not support effective
6624            this.dyn_ltree  = new utils.Buf16(HEAP_SIZE * 2);
6625            this.dyn_dtree  = new utils.Buf16((2 * D_CODES + 1) * 2);
6626            this.bl_tree    = new utils.Buf16((2 * BL_CODES + 1) * 2);
6627            zero(this.dyn_ltree);
6628            zero(this.dyn_dtree);
6629            zero(this.bl_tree);
6630
6631            this.l_desc   = null;         /* desc. for literal tree */
6632            this.d_desc   = null;         /* desc. for distance tree */
6633            this.bl_desc  = null;         /* desc. for bit length tree */
6634
6635            //ush bl_count[MAX_BITS+1];
6636            this.bl_count = new utils.Buf16(MAX_BITS + 1);
6637            /* number of codes at each bit length for an optimal tree */
6638
6639            //int heap[2*L_CODES+1];      /* heap used to build the Huffman trees */
6640            this.heap = new utils.Buf16(2 * L_CODES + 1);  /* heap used to build the Huffman trees */
6641            zero(this.heap);
6642
6643            this.heap_len = 0;               /* number of elements in the heap */
6644            this.heap_max = 0;               /* element of largest frequency */
6645            /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
6646   * The same heap array is used to build all trees.
6647   */
6648
6649            this.depth = new utils.Buf16(2 * L_CODES + 1); //uch depth[2*L_CODES+1];
6650            zero(this.depth);
6651            /* Depth of each subtree used as tie breaker for trees of equal frequency
6652   */
6653
6654            this.l_buf = 0;          /* buffer index for literals or lengths */
6655
6656            this.lit_bufsize = 0;
6657            /* Size of match buffer for literals/lengths.  There are 4 reasons for
6658   * limiting lit_bufsize to 64K:
6659   *   - frequencies can be kept in 16 bit counters
6660   *   - if compression is not successful for the first block, all input
6661   *     data is still in the window so we can still emit a stored block even
6662   *     when input comes from standard input.  (This can also be done for
6663   *     all blocks if lit_bufsize is not greater than 32K.)
6664   *   - if compression is not successful for a file smaller than 64K, we can
6665   *     even emit a stored file instead of a stored block (saving 5 bytes).
6666   *     This is applicable only for zip (not gzip or zlib).
6667   *   - creating new Huffman trees less frequently may not provide fast
6668   *     adaptation to changes in the input data statistics. (Take for
6669   *     example a binary file with poorly compressible code followed by
6670   *     a highly compressible string table.) Smaller buffer sizes give
6671   *     fast adaptation but have of course the overhead of transmitting
6672   *     trees more frequently.
6673   *   - I can't count above 4
6674   */
6675
6676            this.last_lit = 0;      /* running index in l_buf */
6677
6678            this.d_buf = 0;
6679            /* Buffer index for distances. To simplify the code, d_buf and l_buf have
6680   * the same number of elements. To use different lengths, an extra flag
6681   * array would be necessary.
6682   */
6683
6684            this.opt_len = 0;       /* bit length of current block with optimal trees */
6685            this.static_len = 0;    /* bit length of current block with static trees */
6686            this.matches = 0;       /* number of string matches in current block */
6687            this.insert = 0;        /* bytes at end of window left to insert */
6688
6689
6690            this.bi_buf = 0;
6691            /* Output buffer. bits are inserted starting at the bottom (least
6692   * significant bits).
6693   */
6694            this.bi_valid = 0;
6695            /* Number of valid bits in bi_buf.  All bits above the last valid bit
6696   * are always zero.
6697   */
6698
6699            // Used for window memory init. We safely ignore it for JS. That makes
6700            // sense only for pointers and memory check tools.
6701            //this.high_water = 0;
6702            /* High water mark offset in window for initialized bytes -- bytes above
6703   * this are set to zero in order to avoid memory check warnings when
6704   * longest match routines access bytes past the input.  This is then
6705   * updated to the new high water mark.
6706   */
6707        }
6708
6709
6710        function deflateResetKeep(strm) {
6711            var s;
6712
6713            if (!strm || !strm.state) {
6714                return err(strm, Z_STREAM_ERROR);
6715            }
6716
6717            strm.total_in = strm.total_out = 0;
6718            strm.data_type = Z_UNKNOWN;
6719
6720            s = strm.state;
6721            s.pending = 0;
6722            s.pending_out = 0;
6723
6724            if (s.wrap < 0) {
6725                s.wrap = -s.wrap;
6726                /* was made negative by deflate(..., Z_FINISH); */
6727            }
6728            s.status = (s.wrap ? INIT_STATE : BUSY_STATE);
6729            strm.adler = (s.wrap === 2) ?
6730                0  // crc32(0, Z_NULL, 0)
6731                :
6732                1; // adler32(0, Z_NULL, 0)
6733            s.last_flush = Z_NO_FLUSH;
6734            trees._tr_init(s);
6735            return Z_OK;
6736        }
6737
6738
6739        function deflateReset(strm) {
6740            var ret = deflateResetKeep(strm);
6741            if (ret === Z_OK) {
6742                lm_init(strm.state);
6743            }
6744            return ret;
6745        }
6746
6747
6748        function deflateSetHeader(strm, head) {
6749            if (!strm || !strm.state) { return Z_STREAM_ERROR; }
6750            if (strm.state.wrap !== 2) { return Z_STREAM_ERROR; }
6751            strm.state.gzhead = head;
6752            return Z_OK;
6753        }
6754
6755
6756        function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
6757            if (!strm) { // === Z_NULL
6758                return Z_STREAM_ERROR;
6759            }
6760            var wrap = 1;
6761
6762            if (level === Z_DEFAULT_COMPRESSION) {
6763                level = 6;
6764            }
6765
6766            if (windowBits < 0) { /* suppress zlib wrapper */
6767                wrap = 0;
6768                windowBits = -windowBits;
6769            }
6770
6771            else if (windowBits > 15) {
6772                wrap = 2;           /* write gzip wrapper instead */
6773                windowBits -= 16;
6774            }
6775
6776
6777            if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED ||
6778                windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
6779                strategy < 0 || strategy > Z_FIXED) {
6780                return err(strm, Z_STREAM_ERROR);
6781            }
6782
6783
6784            if (windowBits === 8) {
6785                windowBits = 9;
6786            }
6787            /* until 256-byte window bug fixed */
6788
6789            var s = new DeflateState();
6790
6791            strm.state = s;
6792            s.strm = strm;
6793
6794            s.wrap = wrap;
6795            s.gzhead = null;
6796            s.w_bits = windowBits;
6797            s.w_size = 1 << s.w_bits;
6798            s.w_mask = s.w_size - 1;
6799
6800            s.hash_bits = memLevel + 7;
6801            s.hash_size = 1 << s.hash_bits;
6802            s.hash_mask = s.hash_size - 1;
6803            s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH);
6804
6805            s.window = new utils.Buf8(s.w_size * 2);
6806            s.head = new utils.Buf16(s.hash_size);
6807            s.prev = new utils.Buf16(s.w_size);
6808
6809            // Don't need mem init magic for JS.
6810            //s.high_water = 0;  /* nothing written to s->window yet */
6811
6812            s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
6813
6814            s.pending_buf_size = s.lit_bufsize * 4;
6815            s.pending_buf = new utils.Buf8(s.pending_buf_size);
6816
6817            s.d_buf = s.lit_bufsize >> 1;
6818            s.l_buf = (1 + 2) * s.lit_bufsize;
6819
6820            s.level = level;
6821            s.strategy = strategy;
6822            s.method = method;
6823
6824            return deflateReset(strm);
6825        }
6826
6827        function deflateInit(strm, level) {
6828            return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
6829        }
6830
6831
6832        function deflate(strm, flush) {
6833            var old_flush, s;
6834            var beg, val; // for gzip header write only
6835
6836            if (!strm || !strm.state ||
6837                flush > Z_BLOCK || flush < 0) {
6838                return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR;
6839            }
6840
6841            s = strm.state;
6842
6843            if (!strm.output ||
6844                (!strm.input && strm.avail_in !== 0) ||
6845                (s.status === FINISH_STATE && flush !== Z_FINISH)) {
6846                return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR);
6847            }
6848
6849            s.strm = strm; /* just in case */
6850            old_flush = s.last_flush;
6851            s.last_flush = flush;
6852
6853            /* Write the header */
6854            if (s.status === INIT_STATE) {
6855
6856                if (s.wrap === 2) { // GZIP header
6857                    strm.adler = 0;  //crc32(0L, Z_NULL, 0);
6858                    put_byte(s, 31);
6859                    put_byte(s, 139);
6860                    put_byte(s, 8);
6861                    if (!s.gzhead) { // s->gzhead == Z_NULL
6862                        put_byte(s, 0);
6863                        put_byte(s, 0);
6864                        put_byte(s, 0);
6865                        put_byte(s, 0);
6866                        put_byte(s, 0);
6867                        put_byte(s, s.level === 9 ? 2 :
6868                            (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?
6869                                4 : 0));
6870                        put_byte(s, OS_CODE);
6871                        s.status = BUSY_STATE;
6872                    }
6873                    else {
6874                        put_byte(s, (s.gzhead.text ? 1 : 0) +
6875                            (s.gzhead.hcrc ? 2 : 0) +
6876                            (!s.gzhead.extra ? 0 : 4) +
6877                            (!s.gzhead.name ? 0 : 8) +
6878                            (!s.gzhead.comment ? 0 : 16)
6879                        );
6880                        put_byte(s, s.gzhead.time & 0xff);
6881                        put_byte(s, (s.gzhead.time >> 8) & 0xff);
6882                        put_byte(s, (s.gzhead.time >> 16) & 0xff);
6883                        put_byte(s, (s.gzhead.time >> 24) & 0xff);
6884                        put_byte(s, s.level === 9 ? 2 :
6885                            (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?
6886                                4 : 0));
6887                        put_byte(s, s.gzhead.os & 0xff);
6888                        if (s.gzhead.extra && s.gzhead.extra.length) {
6889                            put_byte(s, s.gzhead.extra.length & 0xff);
6890                            put_byte(s, (s.gzhead.extra.length >> 8) & 0xff);
6891                        }
6892                        if (s.gzhead.hcrc) {
6893                            strm.adler = crc32(strm.adler, s.pending_buf, s.pending, 0);
6894                        }
6895                        s.gzindex = 0;
6896                        s.status = EXTRA_STATE;
6897                    }
6898                }
6899                else // DEFLATE header
6900                {
6901                    var header = (Z_DEFLATED + ((s.w_bits - 8) << 4)) << 8;
6902                    var level_flags = -1;
6903
6904                    if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {
6905                        level_flags = 0;
6906                    } else if (s.level < 6) {
6907                        level_flags = 1;
6908                    } else if (s.level === 6) {
6909                        level_flags = 2;
6910                    } else {
6911                        level_flags = 3;
6912                    }
6913                    header |= (level_flags << 6);
6914                    if (s.strstart !== 0) { header |= PRESET_DICT; }
6915                    header += 31 - (header % 31);
6916
6917                    s.status = BUSY_STATE;
6918                    putShortMSB(s, header);
6919
6920                    /* Save the adler32 of the preset dictionary: */
6921                    if (s.strstart !== 0) {
6922                        putShortMSB(s, strm.adler >>> 16);
6923                        putShortMSB(s, strm.adler & 0xffff);
6924                    }
6925                    strm.adler = 1; // adler32(0L, Z_NULL, 0);
6926                }
6927            }
6928
6929//#ifdef GZIP
6930            if (s.status === EXTRA_STATE) {
6931                if (s.gzhead.extra/* != Z_NULL*/) {
6932                    beg = s.pending;  /* start of bytes to update crc */
6933
6934                    while (s.gzindex < (s.gzhead.extra.length & 0xffff)) {
6935                        if (s.pending === s.pending_buf_size) {
6936                            if (s.gzhead.hcrc && s.pending > beg) {
6937                                strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
6938                            }
6939                            flush_pending(strm);
6940                            beg = s.pending;
6941                            if (s.pending === s.pending_buf_size) {
6942                                break;
6943                            }
6944                        }
6945                        put_byte(s, s.gzhead.extra[s.gzindex] & 0xff);
6946                        s.gzindex++;
6947                    }
6948                    if (s.gzhead.hcrc && s.pending > beg) {
6949                        strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
6950                    }
6951                    if (s.gzindex === s.gzhead.extra.length) {
6952                        s.gzindex = 0;
6953                        s.status = NAME_STATE;
6954                    }
6955                }
6956                else {
6957                    s.status = NAME_STATE;
6958                }
6959            }
6960            if (s.status === NAME_STATE) {
6961                if (s.gzhead.name/* != Z_NULL*/) {
6962                    beg = s.pending;  /* start of bytes to update crc */
6963                    //int val;
6964
6965                    do {
6966                        if (s.pending === s.pending_buf_size) {
6967                            if (s.gzhead.hcrc && s.pending > beg) {
6968                                strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
6969                            }
6970                            flush_pending(strm);
6971                            beg = s.pending;
6972                            if (s.pending === s.pending_buf_size) {
6973                                val = 1;
6974                                break;
6975                            }
6976                        }
6977                        // JS specific: little magic to add zero terminator to end of string
6978                        if (s.gzindex < s.gzhead.name.length) {
6979                            val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff;
6980                        } else {
6981                            val = 0;
6982                        }
6983                        put_byte(s, val);
6984                    } while (val !== 0);
6985
6986                    if (s.gzhead.hcrc && s.pending > beg) {
6987                        strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
6988                    }
6989                    if (val === 0) {
6990                        s.gzindex = 0;
6991                        s.status = COMMENT_STATE;
6992                    }
6993                }
6994                else {
6995                    s.status = COMMENT_STATE;
6996                }
6997            }
6998            if (s.status === COMMENT_STATE) {
6999                if (s.gzhead.comment/* != Z_NULL*/) {
7000                    beg = s.pending;  /* start of bytes to update crc */
7001                    //int val;
7002
7003                    do {
7004                        if (s.pending === s.pending_buf_size) {
7005                            if (s.gzhead.hcrc && s.pending > beg) {
7006                                strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
7007                            }
7008                            flush_pending(strm);
7009                            beg = s.pending;
7010                            if (s.pending === s.pending_buf_size) {
7011                                val = 1;
7012                                break;
7013                            }
7014                        }
7015                        // JS specific: little magic to add zero terminator to end of string
7016                        if (s.gzindex < s.gzhead.comment.length) {
7017                            val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff;
7018                        } else {
7019                            val = 0;
7020                        }
7021                        put_byte(s, val);
7022                    } while (val !== 0);
7023
7024                    if (s.gzhead.hcrc && s.pending > beg) {
7025                        strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
7026                    }
7027                    if (val === 0) {
7028                        s.status = HCRC_STATE;
7029                    }
7030                }
7031                else {
7032                    s.status = HCRC_STATE;
7033                }
7034            }
7035            if (s.status === HCRC_STATE) {
7036                if (s.gzhead.hcrc) {
7037                    if (s.pending + 2 > s.pending_buf_size) {
7038                        flush_pending(strm);
7039                    }
7040                    if (s.pending + 2 <= s.pending_buf_size) {
7041                        put_byte(s, strm.adler & 0xff);
7042                        put_byte(s, (strm.adler >> 8) & 0xff);
7043                        strm.adler = 0; //crc32(0L, Z_NULL, 0);
7044                        s.status = BUSY_STATE;
7045                    }
7046                }
7047                else {
7048                    s.status = BUSY_STATE;
7049                }
7050            }
7051//#endif
7052
7053            /* Flush as much pending output as possible */
7054            if (s.pending !== 0) {
7055                flush_pending(strm);
7056                if (strm.avail_out === 0) {
7057                    /* Since avail_out is 0, deflate will be called again with
7058       * more output space, but possibly with both pending and
7059       * avail_in equal to zero. There won't be anything to do,
7060       * but this is not an error situation so make sure we
7061       * return OK instead of BUF_ERROR at next call of deflate:
7062       */
7063                    s.last_flush = -1;
7064                    return Z_OK;
7065                }
7066
7067                /* Make sure there is something to do and avoid duplicate consecutive
7068     * flushes. For repeated and useless calls with Z_FINISH, we keep
7069     * returning Z_STREAM_END instead of Z_BUF_ERROR.
7070     */
7071            } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) &&
7072                flush !== Z_FINISH) {
7073                return err(strm, Z_BUF_ERROR);
7074            }
7075
7076            /* User must not provide more input after the first FINISH: */
7077            if (s.status === FINISH_STATE && strm.avail_in !== 0) {
7078                return err(strm, Z_BUF_ERROR);
7079            }
7080
7081            /* Start a new block or continue the current one.
7082   */
7083            if (strm.avail_in !== 0 || s.lookahead !== 0 ||
7084                (flush !== Z_NO_FLUSH && s.status !== FINISH_STATE)) {
7085                var bstate = (s.strategy === Z_HUFFMAN_ONLY) ? deflate_huff(s, flush) :
7086                    (s.strategy === Z_RLE ? deflate_rle(s, flush) :
7087                        configuration_table[s.level].func(s, flush));
7088
7089                if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) {
7090                    s.status = FINISH_STATE;
7091                }
7092                if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) {
7093                    if (strm.avail_out === 0) {
7094                        s.last_flush = -1;
7095                        /* avoid BUF_ERROR next call, see above */
7096                    }
7097                    return Z_OK;
7098                    /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
7099       * of deflate should use the same flush parameter to make sure
7100       * that the flush is complete. So we don't have to output an
7101       * empty block here, this will be done at next call. This also
7102       * ensures that for a very small output buffer, we emit at most
7103       * one empty block.
7104       */
7105                }
7106                if (bstate === BS_BLOCK_DONE) {
7107                    if (flush === Z_PARTIAL_FLUSH) {
7108                        trees._tr_align(s);
7109                    }
7110                    else if (flush !== Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
7111
7112                        trees._tr_stored_block(s, 0, 0, false);
7113                        /* For a full flush, this empty block will be recognized
7114         * as a special marker by inflate_sync().
7115         */
7116                        if (flush === Z_FULL_FLUSH) {
7117                            /*** CLEAR_HASH(s); ***/             /* forget history */
7118                            zero(s.head); // Fill with NIL (= 0);
7119
7120                            if (s.lookahead === 0) {
7121                                s.strstart = 0;
7122                                s.block_start = 0;
7123                                s.insert = 0;
7124                            }
7125                        }
7126                    }
7127                    flush_pending(strm);
7128                    if (strm.avail_out === 0) {
7129                        s.last_flush = -1; /* avoid BUF_ERROR at next call, see above */
7130                        return Z_OK;
7131                    }
7132                }
7133            }
7134            //Assert(strm->avail_out > 0, "bug2");
7135            //if (strm.avail_out <= 0) { throw new Error("bug2");}
7136
7137            if (flush !== Z_FINISH) { return Z_OK; }
7138            if (s.wrap <= 0) { return Z_STREAM_END; }
7139
7140            /* Write the trailer */
7141            if (s.wrap === 2) {
7142                put_byte(s, strm.adler & 0xff);
7143                put_byte(s, (strm.adler >> 8) & 0xff);
7144                put_byte(s, (strm.adler >> 16) & 0xff);
7145                put_byte(s, (strm.adler >> 24) & 0xff);
7146                put_byte(s, strm.total_in & 0xff);
7147                put_byte(s, (strm.total_in >> 8) & 0xff);
7148                put_byte(s, (strm.total_in >> 16) & 0xff);
7149                put_byte(s, (strm.total_in >> 24) & 0xff);
7150            }
7151            else
7152            {
7153                putShortMSB(s, strm.adler >>> 16);
7154                putShortMSB(s, strm.adler & 0xffff);
7155            }
7156
7157            flush_pending(strm);
7158            /* If avail_out is zero, the application will call deflate again
7159   * to flush the rest.
7160   */
7161            if (s.wrap > 0) { s.wrap = -s.wrap; }
7162            /* write the trailer only once! */
7163            return s.pending !== 0 ? Z_OK : Z_STREAM_END;
7164        }
7165
7166        function deflateEnd(strm) {
7167            var status;
7168
7169            if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {
7170                return Z_STREAM_ERROR;
7171            }
7172
7173            status = strm.state.status;
7174            if (status !== INIT_STATE &&
7175                status !== EXTRA_STATE &&
7176                status !== NAME_STATE &&
7177                status !== COMMENT_STATE &&
7178                status !== HCRC_STATE &&
7179                status !== BUSY_STATE &&
7180                status !== FINISH_STATE
7181            ) {
7182                return err(strm, Z_STREAM_ERROR);
7183            }
7184
7185            strm.state = null;
7186
7187            return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;
7188        }
7189
7190
7191        /* =========================================================================
7192 * Initializes the compression dictionary from the given byte
7193 * sequence without producing any compressed output.
7194 */
7195        function deflateSetDictionary(strm, dictionary) {
7196            var dictLength = dictionary.length;
7197
7198            var s;
7199            var str, n;
7200            var wrap;
7201            var avail;
7202            var next;
7203            var input;
7204            var tmpDict;
7205
7206            if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {
7207                return Z_STREAM_ERROR;
7208            }
7209
7210            s = strm.state;
7211            wrap = s.wrap;
7212
7213            if (wrap === 2 || (wrap === 1 && s.status !== INIT_STATE) || s.lookahead) {
7214                return Z_STREAM_ERROR;
7215            }
7216
7217            /* when using zlib wrappers, compute Adler-32 for provided dictionary */
7218            if (wrap === 1) {
7219                /* adler32(strm->adler, dictionary, dictLength); */
7220                strm.adler = adler32(strm.adler, dictionary, dictLength, 0);
7221            }
7222
7223            s.wrap = 0;   /* avoid computing Adler-32 in read_buf */
7224
7225            /* if dictionary would fill window, just replace the history */
7226            if (dictLength >= s.w_size) {
7227                if (wrap === 0) {            /* already empty otherwise */
7228                    /*** CLEAR_HASH(s); ***/
7229                    zero(s.head); // Fill with NIL (= 0);
7230                    s.strstart = 0;
7231                    s.block_start = 0;
7232                    s.insert = 0;
7233                }
7234                /* use the tail */
7235                // dictionary = dictionary.slice(dictLength - s.w_size);
7236                tmpDict = new utils.Buf8(s.w_size);
7237                utils.arraySet(tmpDict, dictionary, dictLength - s.w_size, s.w_size, 0);
7238                dictionary = tmpDict;
7239                dictLength = s.w_size;
7240            }
7241            /* insert dictionary into window and hash */
7242            avail = strm.avail_in;
7243            next = strm.next_in;
7244            input = strm.input;
7245            strm.avail_in = dictLength;
7246            strm.next_in = 0;
7247            strm.input = dictionary;
7248            fill_window(s);
7249            while (s.lookahead >= MIN_MATCH) {
7250                str = s.strstart;
7251                n = s.lookahead - (MIN_MATCH - 1);
7252                do {
7253                    /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
7254                    s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
7255
7256                    s.prev[str & s.w_mask] = s.head[s.ins_h];
7257
7258                    s.head[s.ins_h] = str;
7259                    str++;
7260                } while (--n);
7261                s.strstart = str;
7262                s.lookahead = MIN_MATCH - 1;
7263                fill_window(s);
7264            }
7265            s.strstart += s.lookahead;
7266            s.block_start = s.strstart;
7267            s.insert = s.lookahead;
7268            s.lookahead = 0;
7269            s.match_length = s.prev_length = MIN_MATCH - 1;
7270            s.match_available = 0;
7271            strm.next_in = next;
7272            strm.input = input;
7273            strm.avail_in = avail;
7274            s.wrap = wrap;
7275            return Z_OK;
7276        }
7277
7278
7279        exports.deflateInit = deflateInit;
7280        exports.deflateInit2 = deflateInit2;
7281        exports.deflateReset = deflateReset;
7282        exports.deflateResetKeep = deflateResetKeep;
7283        exports.deflateSetHeader = deflateSetHeader;
7284        exports.deflate = deflate;
7285        exports.deflateEnd = deflateEnd;
7286        exports.deflateSetDictionary = deflateSetDictionary;
7287        exports.deflateInfo = 'pako deflate (from Nodeca project)';
7288
7289        /* Not implemented
7290exports.deflateBound = deflateBound;
7291exports.deflateCopy = deflateCopy;
7292exports.deflateParams = deflateParams;
7293exports.deflatePending = deflatePending;
7294exports.deflatePrime = deflatePrime;
7295exports.deflateTune = deflateTune;
7296*/
7297
7298    },{"../utils/common":32,"./adler32":34,"./crc32":36,"./messages":42,"./trees":43}],38:[function(_dereq_,module,exports){
7299        'use strict';
7300
7301
7302        function GZheader() {
7303            /* true if compressed data believed to be text */
7304            this.text       = 0;
7305            /* modification time */
7306            this.time       = 0;
7307            /* extra flags (not used when writing a gzip file) */
7308            this.xflags     = 0;
7309            /* operating system */
7310            this.os         = 0;
7311            /* pointer to extra field or Z_NULL if none */
7312            this.extra      = null;
7313            /* extra field length (valid if extra != Z_NULL) */
7314            this.extra_len  = 0; // Actually, we don't need it in JS,
7315                                 // but leave for few code modifications
7316
7317            //
7318            // Setup limits is not necessary because in js we should not preallocate memory
7319            // for inflate use constant limit in 65536 bytes
7320            //
7321
7322            /* space at extra (only when reading header) */
7323            // this.extra_max  = 0;
7324            /* pointer to zero-terminated file name or Z_NULL */
7325            this.name       = '';
7326            /* space at name (only when reading header) */
7327            // this.name_max   = 0;
7328            /* pointer to zero-terminated comment or Z_NULL */
7329            this.comment    = '';
7330            /* space at comment (only when reading header) */
7331            // this.comm_max   = 0;
7332            /* true if there was or will be a header crc */
7333            this.hcrc       = 0;
7334            /* true when done reading gzip header (not used when writing a gzip file) */
7335            this.done       = false;
7336        }
7337
7338        module.exports = GZheader;
7339
7340    },{}],39:[function(_dereq_,module,exports){
7341        'use strict';
7342
7343// See state defs from inflate.js
7344        var BAD = 30;       /* got a data error -- remain here until reset */
7345        var TYPE = 12;      /* i: waiting for type bits, including last-flag bit */
7346
7347        /*
7348   Decode literal, length, and distance codes and write out the resulting
7349   literal and match bytes until either not enough input or output is
7350   available, an end-of-block is encountered, or a data error is encountered.
7351   When large enough input and output buffers are supplied to inflate(), for
7352   example, a 16K input buffer and a 64K output buffer, more than 95% of the
7353   inflate execution time is spent in this routine.
7354
7355   Entry assumptions:
7356
7357        state.mode === LEN
7358        strm.avail_in >= 6
7359        strm.avail_out >= 258
7360        start >= strm.avail_out
7361        state.bits < 8
7362
7363   On return, state.mode is one of:
7364
7365        LEN -- ran out of enough output space or enough available input
7366        TYPE -- reached end of block code, inflate() to interpret next block
7367        BAD -- error in block data
7368
7369   Notes:
7370
7371    - The maximum input bits used by a length/distance pair is 15 bits for the
7372      length code, 5 bits for the length extra, 15 bits for the distance code,
7373      and 13 bits for the distance extra.  This totals 48 bits, or six bytes.
7374      Therefore if strm.avail_in >= 6, then there is enough input to avoid
7375      checking for available input while decoding.
7376
7377    - The maximum bytes that a single length/distance pair can output is 258
7378      bytes, which is the maximum length that can be coded.  inflate_fast()
7379      requires strm.avail_out >= 258 for each loop to avoid checking for
7380      output space.
7381 */
7382        module.exports = function inflate_fast(strm, start) {
7383            var state;
7384            var _in;                    /* local strm.input */
7385            var last;                   /* have enough input while in < last */
7386            var _out;                   /* local strm.output */
7387            var beg;                    /* inflate()'s initial strm.output */
7388            var end;                    /* while out < end, enough space available */
7389//#ifdef INFLATE_STRICT
7390            var dmax;                   /* maximum distance from zlib header */
7391//#endif
7392            var wsize;                  /* window size or zero if not using window */
7393            var whave;                  /* valid bytes in the window */
7394            var wnext;                  /* window write index */
7395            // Use `s_window` instead `window`, avoid conflict with instrumentation tools
7396            var s_window;               /* allocated sliding window, if wsize != 0 */
7397            var hold;                   /* local strm.hold */
7398            var bits;                   /* local strm.bits */
7399            var lcode;                  /* local strm.lencode */
7400            var dcode;
vendor: 19,023 bytes, lines 7400-7742
7400                  /* local strm.distcode */
7401            var lmask;                  /* mask for first level of length codes */
7402            var dmask;                  /* mask for first level of distance codes */
7403            var here;                   /* retrieved table entry */
7404            var op;                     /* code bits, operation, extra bits, or */
7405            /*  window position, window bytes to copy */
7406            var len;                    /* match length, unused bytes */
7407            var dist;                   /* match distance */
7408            var from;                   /* where to copy match from */
7409            var from_source;
7410
7411
7412            var input, output; // JS specific, because we have no pointers
7413
7414            /* copy state to local variables */
7415            state = strm.state;
7416            //here = state.here;
7417            _in = strm.next_in;
7418            input = strm.input;
7419            last = _in + (strm.avail_in - 5);
7420            _out = strm.next_out;
7421            output = strm.output;
7422            beg = _out - (start - strm.avail_out);
7423            end = _out + (strm.avail_out - 257);
7424//#ifdef INFLATE_STRICT
7425            dmax = state.dmax;
7426//#endif
7427            wsize = state.wsize;
7428            whave = state.whave;
7429            wnext = state.wnext;
7430            s_window = state.window;
7431            hold = state.hold;
7432            bits = state.bits;
7433            lcode = state.lencode;
7434            dcode = state.distcode;
7435            lmask = (1 << state.lenbits) - 1;
7436            dmask = (1 << state.distbits) - 1;
7437
7438
7439            /* decode literals and length/distances until end-of-block or not enough
7440     input data or output space */
7441
7442            top:
7443                do {
7444                    if (bits < 15) {
7445                        hold += input[_in++] << bits;
7446                        bits += 8;
7447                        hold += input[_in++] << bits;
7448                        bits += 8;
7449                    }
7450
7451                    here = lcode[hold & lmask];
7452
7453                    dolen:
7454                        for (;;) { // Goto emulation
7455                            op = here >>> 24/*here.bits*/;
7456                            hold >>>= op;
7457                            bits -= op;
7458                            op = (here >>> 16) & 0xff/*here.op*/;
7459                            if (op === 0) {                          /* literal */
7460                                //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
7461                                //        "inflate:         literal '%c'\n" :
7462                                //        "inflate:         literal 0x%02x\n", here.val));
7463                                output[_out++] = here & 0xffff/*here.val*/;
7464                            }
7465                            else if (op & 16) {                     /* length base */
7466                                len = here & 0xffff/*here.val*/;
7467                                op &= 15;                           /* number of extra bits */
7468                                if (op) {
7469                                    if (bits < op) {
7470                                        hold += input[_in++] << bits;
7471                                        bits += 8;
7472                                    }
7473                                    len += hold & ((1 << op) - 1);
7474                                    hold >>>= op;
7475                                    bits -= op;
7476                                }
7477                                //Tracevv((stderr, "inflate:         length %u\n", len));
7478                                if (bits < 15) {
7479                                    hold += input[_in++] << bits;
7480                                    bits += 8;
7481                                    hold += input[_in++] << bits;
7482                                    bits += 8;
7483                                }
7484                                here = dcode[hold & dmask];
7485
7486                                dodist:
7487                                    for (;;) { // goto emulation
7488                                        op = here >>> 24/*here.bits*/;
7489                                        hold >>>= op;
7490                                        bits -= op;
7491                                        op = (here >>> 16) & 0xff/*here.op*/;
7492
7493                                        if (op & 16) {                      /* distance base */
7494                                            dist = here & 0xffff/*here.val*/;
7495                                            op &= 15;                       /* number of extra bits */
7496                                            if (bits < op) {
7497                                                hold += input[_in++] << bits;
7498                                                bits += 8;
7499                                                if (bits < op) {
7500                                                    hold += input[_in++] << bits;
7501                                                    bits += 8;
7502                                                }
7503                                            }
7504                                            dist += hold & ((1 << op) - 1);
7505//#ifdef INFLATE_STRICT
7506                                            if (dist > dmax) {
7507                                                strm.msg = 'invalid distance too far back';
7508                                                state.mode = BAD;
7509                                                break top;
7510                                            }
7511//#endif
7512                                            hold >>>= op;
7513                                            bits -= op;
7514                                            //Tracevv((stderr, "inflate:         distance %u\n", dist));
7515                                            op = _out - beg;                /* max distance in output */
7516                                            if (dist > op) {                /* see if copy from window */
7517                                                op = dist - op;               /* distance back in window */
7518                                                if (op > whave) {
7519                                                    if (state.sane) {
7520                                                        strm.msg = 'invalid distance too far back';
7521                                                        state.mode = BAD;
7522                                                        break top;
7523                                                    }
7524
7525// (!) This block is disabled in zlib defailts,
7526// don't enable it for binary compatibility
7527//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
7528//                if (len <= op - whave) {
7529//                  do {
7530//                    output[_out++] = 0;
7531//                  } while (--len);
7532//                  continue top;
7533//                }
7534//                len -= op - whave;
7535//                do {
7536//                  output[_out++] = 0;
7537//                } while (--op > whave);
7538//                if (op === 0) {
7539//                  from = _out - dist;
7540//                  do {
7541//                    output[_out++] = output[from++];
7542//                  } while (--len);
7543//                  continue top;
7544//                }
7545//#endif
7546                                                }
7547                                                from = 0; // window index
7548                                                from_source = s_window;
7549                                                if (wnext === 0) {           /* very common case */
7550                                                    from += wsize - op;
7551                                                    if (op < len) {         /* some from window */
7552                                                        len -= op;
7553                                                        do {
7554                                                            output[_out++] = s_window[from++];
7555                                                        } while (--op);
7556                                                        from = _out - dist;  /* rest from output */
7557                                                        from_source = output;
7558                                                    }
7559                                                }
7560                                                else if (wnext < op) {      /* wrap around window */
7561                                                    from += wsize + wnext - op;
7562                                                    op -= wnext;
7563                                                    if (op < len) {         /* some from end of window */
7564                                                        len -= op;
7565                                                        do {
7566                                                            output[_out++] = s_window[from++];
7567                                                        } while (--op);
7568                                                        from = 0;
7569                                                        if (wnext < len) {  /* some from start of window */
7570                                                            op = wnext;
7571                                                            len -= op;
7572                                                            do {
7573                                                                output[_out++] = s_window[from++];
7574                                                            } while (--op);
7575                                                            from = _out - dist;      /* rest from output */
7576                                                            from_source = output;
7577                                                        }
7578                                                    }
7579                                                }
7580                                                else {                      /* contiguous in window */
7581                                                    from += wnext - op;
7582                                                    if (op < len) {         /* some from window */
7583                                                        len -= op;
7584                                                        do {
7585                                                            output[_out++] = s_window[from++];
7586                                                        } while (--op);
7587                                                        from = _out - dist;  /* rest from output */
7588                                                        from_source = output;
7589                                                    }
7590                                                }
7591                                                while (len > 2) {
7592                                                    output[_out++] = from_source[from++];
7593                                                    output[_out++] = from_source[from++];
7594                                                    output[_out++] = from_source[from++];
7595                                                    len -= 3;
7596                                                }
7597                                                if (len) {
7598                                                    output[_out++] = from_source[from++];
7599                                                    if (len > 1) {
7600                                                        output[_out++] = from_source[from++];
7601                                                    }
7602                                                }
7603                                            }
7604                                            else {
7605                                                from = _out - dist;          /* copy direct from output */
7606                                                do {                        /* minimum length is three */
7607                                                    output[_out++] = output[from++];
7608                                                    output[_out++] = output[from++];
7609                                                    output[_out++] = output[from++];
7610                                                    len -= 3;
7611                                                } while (len > 2);
7612                                                if (len) {
7613                                                    output[_out++] = output[from++];
7614                                                    if (len > 1) {
7615                                                        output[_out++] = output[from++];
7616                                                    }
7617                                                }
7618                                            }
7619                                        }
7620                                        else if ((op & 64) === 0) {          /* 2nd level distance code */
7621                                            here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
7622                                            continue dodist;
7623                                        }
7624                                        else {
7625                                            strm.msg = 'invalid distance code';
7626                                            state.mode = BAD;
7627                                            break top;
7628                                        }
7629
7630                                        break; // need to emulate goto via "continue"
7631                                    }
7632                            }
7633                            else if ((op & 64) === 0) {              /* 2nd level length code */
7634                                here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
7635                                continue dolen;
7636                            }
7637                            else if (op & 32) {                     /* end-of-block */
7638                                //Tracevv((stderr, "inflate:         end of block\n"));
7639                                state.mode = TYPE;
7640                                break top;
7641                            }
7642                            else {
7643                                strm.msg = 'invalid literal/length code';
7644                                state.mode = BAD;
7645                                break top;
7646                            }
7647
7648                            break; // need to emulate goto via "continue"
7649                        }
7650                } while (_in < last && _out < end);
7651
7652            /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
7653            len = bits >> 3;
7654            _in -= len;
7655            bits -= len << 3;
7656            hold &= (1 << bits) - 1;
7657
7658            /* update state and return */
7659            strm.next_in = _in;
7660            strm.next_out = _out;
7661            strm.avail_in = (_in < last ? 5 + (last - _in) : 5 - (_in - last));
7662            strm.avail_out = (_out < end ? 257 + (end - _out) : 257 - (_out - end));
7663            state.hold = hold;
7664            state.bits = bits;
7665            return;
7666        };
7667
7668    },{}],40:[function(_dereq_,module,exports){
7669        'use strict';
7670
7671
7672        var utils         = _dereq_('../utils/common');
7673        var adler32       = _dereq_('./adler32');
7674        var crc32         = _dereq_('./crc32');
7675        var inflate_fast  = _dereq_('./inffast');
7676        var inflate_table = _dereq_('./inftrees');
7677
7678        var CODES = 0;
7679        var LENS = 1;
7680        var DISTS = 2;
7681
7682        /* Public constants ==========================================================*/
7683        /* ===========================================================================*/
7684
7685
7686        /* Allowed flush values; see deflate() and inflate() below for details */
7687//var Z_NO_FLUSH      = 0;
7688//var Z_PARTIAL_FLUSH = 1;
7689//var Z_SYNC_FLUSH    = 2;
7690//var Z_FULL_FLUSH    = 3;
7691        var Z_FINISH        = 4;
7692        var Z_BLOCK         = 5;
7693        var Z_TREES         = 6;
7694
7695
7696        /* Return codes for the compression/decompression functions. Negative values
7697 * are errors, positive values are used for special but normal events.
7698 */
7699        var Z_OK            = 0;
7700        var Z_STREAM_END    = 1;
7701        var Z_NEED_DICT     = 2;
7702//var Z_ERRNO         = -1;
7703        var Z_STREAM_ERROR  = -2;
7704        var Z_DATA_ERROR    = -3;
7705        var Z_MEM_ERROR     = -4;
7706        var Z_BUF_ERROR     = -5;
7707//var Z_VERSION_ERROR = -6;
7708
7709        /* The deflate compression method */
7710        var Z_DEFLATED  = 8;
7711
7712
7713        /* STATES ====================================================================*/
7714        /* ===========================================================================*/
7715
7716
7717        var    HEAD = 1;       /* i: waiting for magic header */
7718        var    FLAGS = 2;      /* i: waiting for method and flags (gzip) */
7719        var    TIME = 3;       /* i: waiting for modification time (gzip) */
7720        var    OS = 4;         /* i: waiting for extra flags and operating system (gzip) */
7721        var    EXLEN = 5;      /* i: waiting for extra length (gzip) */
7722        var    EXTRA = 6;      /* i: waiting for extra bytes (gzip) */
7723        var    NAME = 7;       /* i: waiting for end of file name (gzip) */
7724        var    COMMENT = 8;    /* i: waiting for end of comment (gzip) */
7725        var    HCRC = 9;       /* i: waiting for header crc (gzip) */
7726        var    DICTID = 10;    /* i: waiting for dictionary check value */
7727        var    DICT = 11;      /* waiting for inflateSetDictionary() call */
7728        var        TYPE = 12;      /* i: waiting for type bits, including last-flag bit */
7729        var        TYPEDO = 13;    /* i: same, but skip check to exit inflate on new block */
7730        var        STORED = 14;    /* i: waiting for stored size (length and complement) */
7731        var        COPY_ = 15;     /* i/o: same as COPY below, but only first time in */
7732        var        COPY = 16;      /* i/o: waiting for input or output to copy stored block */
7733        var        TABLE = 17;     /* i: waiting for dynamic block table lengths */
7734        var        LENLENS = 18;   /* i: waiting for code length code lengths */
7735        var        CODELENS = 19;  /* i: waiting for length/lit and distance code lengths */
7736        var            LEN_ = 20;      /* i: same as LEN below, but only first time in */
7737        var            LEN = 21;       /* i: waiting for length/lit/eob code */
7738        var            LENEXT = 22;    /* i: waiting for length extra bits */
7739        var            DIST = 23;      /* i: waiting for distance code */
7740        var            DISTEXT = 24;   /* i: waiting for distance extra bits */
7741        var            MATCH = 25;     /* o: waiting for output space to copy string */
7742        var            LIT = 26;       /* o: waiting for output space to write literal */
7743        var    CHECK = 27;     /* i: waiting for 32-bit check value */
7744        var    LENGTH = 28;    /* i: waiting for 32-bit length (gzip) */
7745        var    DONE = 29;      /* finished check, done -- remain here until reset */
7746        var    BAD = 30;       /* got a data error -- remain here until reset */
7747        var    MEM = 31;       /* got an inflate() memory error -- remain here until reset */
7748        var    SYNC = 32;      /* looking for synchronization bytes to restart inflate() */
7749
7750        /* ===========================================================================*/
7751
7752
7753
7754        var ENOUGH_LENS = 852;
7755        var ENOUGH_DISTS = 592;
7756//var ENOUGH =  (ENOUGH_LENS+ENOUGH_DISTS);
7757
7758        var MAX_WBITS = 15;
7759        /* 32K LZ77 window */
7760        var DEF_WBITS = MAX_WBITS;
7761
7762
7763        function zswap32(q) {
7764            return  (((q >>> 24) & 0xff) +
7765                ((q >>> 8) & 0xff00) +
7766                ((q & 0xff00) << 8) +
7767                ((q & 0xff) << 24));
7768        }
7769
7770
7771        function InflateState() {
7772            this.mode = 0;             /* current inflate mode */
7773            this.last = false;          /* true if processing last block */
7774            this.wrap = 0;              /* bit 0 true for zlib, bit 1 true for gzip */
7775            this.havedict = false;      /* true if dictionary provided */
7776            this.flags = 0;             /* gzip header method and flags (0 if zlib) */
7777            this.dmax = 0;              /* zlib header max distance (INFLATE_STRICT) */
7778            this.check = 0;             /* protected copy of check value */
7779            this.total = 0;             /* protected copy of output count */
7780            // TODO: may be {}
7781            this.head = null;           /* where to save gzip header information */
7782
7783            /* sliding window */
7784            this.wbits = 0;             /* log base 2 of requested window size */
7785            this.wsize = 0;             /* window size or zero if not using window */
7786            this.whave = 0;             /* valid bytes in the window */
7787            this.wnext = 0;             /* window write index */
7788            this.window = null;         /* allocated sliding window, if needed */
7789
7790            /* bit accumulator */
7791            this.hold = 0;              /* input bit accumulator */
7792            this.bits = 0;              /* number of bits in "in" */
7793
7794            /* for string and stored block copying */
7795            this.length = 0;            /* literal or length of data to copy */
7796            this.offset = 0;            /* distance back to copy string from */
7797
7798            /* for table and code decoding */
7799            this.extra = 0;             /* extra bits needed */
7800
7801            /* fixed and dynamic code tables */
7802            this.lencode = null;          /* starting table for length/literal codes */
7803            this.distcode = null;         /* starting table for distance codes */
7804            this.lenbits = 0;           /* index bits for lencode */
7805            this.distbits = 0;          /* index bits for distcode */
7806
7807            /* dynamic table building */
7808            this.ncode = 0;             /* number of code length code lengths */
7809            this.nlen = 0;              /* number of length code lengths */
7810            this.ndist = 0;             /* number of distance code lengths */
7811            this.have = 0;              /* number of code lengths in lens[] */
7812            this.next = null;              /* next available space in codes[] */
7813
7814            this.lens = new utils.Buf16(320); /* temporary storage for code lengths */
7815            this.work = new utils.Buf16(288); /* work area for code table building */
7816
7817            /*
7818   because we don't have pointers in js, we use lencode and distcode directly
7819   as buffers so we don't need codes
7820  */
7821            //this.codes = new utils.Buf32(ENOUGH);       /* space for code tables */
7822            this.lendyn = null;              /* dynamic table for length/literal codes (JS specific) */
7823            this.distdyn = null;             /* dynamic table for distance codes (JS specific) */
7824            this.sane = 0;
vendor: 95,178 bytes, lines 7824-9876
7824                   /* if false, allow invalid distance too far */
7825            this.back = 0;                   /* bits back of last unprocessed length/lit */
7826            this.was = 0;                    /* initial length of match */
7827        }
7828
7829        function inflateResetKeep(strm) {
7830            var state;
7831
7832            if (!strm || !strm.state) { return Z_STREAM_ERROR; }
7833            state = strm.state;
7834            strm.total_in = strm.total_out = state.total = 0;
7835            strm.msg = ''; /*Z_NULL*/
7836            if (state.wrap) {       /* to support ill-conceived Java test suite */
7837                strm.adler = state.wrap & 1;
7838            }
7839            state.mode = HEAD;
7840            state.last = 0;
7841            state.havedict = 0;
7842            state.dmax = 32768;
7843            state.head = null/*Z_NULL*/;
7844            state.hold = 0;
7845            state.bits = 0;
7846            //state.lencode = state.distcode = state.next = state.codes;
7847            state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS);
7848            state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS);
7849
7850            state.sane = 1;
7851            state.back = -1;
7852            //Tracev((stderr, "inflate: reset\n"));
7853            return Z_OK;
7854        }
7855
7856        function inflateReset(strm) {
7857            var state;
7858
7859            if (!strm || !strm.state) { return Z_STREAM_ERROR; }
7860            state = strm.state;
7861            state.wsize = 0;
7862            state.whave = 0;
7863            state.wnext = 0;
7864            return inflateResetKeep(strm);
7865
7866        }
7867
7868        function inflateReset2(strm, windowBits) {
7869            var wrap;
7870            var state;
7871
7872            /* get the state */
7873            if (!strm || !strm.state) { return Z_STREAM_ERROR; }
7874            state = strm.state;
7875
7876            /* extract wrap request from windowBits parameter */
7877            if (windowBits < 0) {
7878                wrap = 0;
7879                windowBits = -windowBits;
7880            }
7881            else {
7882                wrap = (windowBits >> 4) + 1;
7883                if (windowBits < 48) {
7884                    windowBits &= 15;
7885                }
7886            }
7887
7888            /* set number of window bits, free window if different */
7889            if (windowBits && (windowBits < 8 || windowBits > 15)) {
7890                return Z_STREAM_ERROR;
7891            }
7892            if (state.window !== null && state.wbits !== windowBits) {
7893                state.window = null;
7894            }
7895
7896            /* update state and reset the rest of it */
7897            state.wrap = wrap;
7898            state.wbits = windowBits;
7899            return inflateReset(strm);
7900        }
7901
7902        function inflateInit2(strm, windowBits) {
7903            var ret;
7904            var state;
7905
7906            if (!strm) { return Z_STREAM_ERROR; }
7907            //strm.msg = Z_NULL;                 /* in case we return an error */
7908
7909            state = new InflateState();
7910
7911            //if (state === Z_NULL) return Z_MEM_ERROR;
7912            //Tracev((stderr, "inflate: allocated\n"));
7913            strm.state = state;
7914            state.window = null/*Z_NULL*/;
7915            ret = inflateReset2(strm, windowBits);
7916            if (ret !== Z_OK) {
7917                strm.state = null/*Z_NULL*/;
7918            }
7919            return ret;
7920        }
7921
7922        function inflateInit(strm) {
7923            return inflateInit2(strm, DEF_WBITS);
7924        }
7925
7926
7927        /*
7928 Return state with length and distance decoding tables and index sizes set to
7929 fixed code decoding.  Normally this returns fixed tables from inffixed.h.
7930 If BUILDFIXED is defined, then instead this routine builds the tables the
7931 first time it's called, and returns those tables the first time and
7932 thereafter.  This reduces the size of the code by about 2K bytes, in
7933 exchange for a little execution time.  However, BUILDFIXED should not be
7934 used for threaded applications, since the rewriting of the tables and virgin
7935 may not be thread-safe.
7936 */
7937        var virgin = true;
7938
7939        var lenfix, distfix; // We have no pointers in JS, so keep tables separate
7940
7941        function fixedtables(state) {
7942            /* build fixed huffman tables if first call (may not be thread safe) */
7943            if (virgin) {
7944                var sym;
7945
7946                lenfix = new utils.Buf32(512);
7947                distfix = new utils.Buf32(32);
7948
7949                /* literal/length table */
7950                sym = 0;
7951                while (sym < 144) { state.lens[sym++] = 8; }
7952                while (sym < 256) { state.lens[sym++] = 9; }
7953                while (sym < 280) { state.lens[sym++] = 7; }
7954                while (sym < 288) { state.lens[sym++] = 8; }
7955
7956                inflate_table(LENS,  state.lens, 0, 288, lenfix,   0, state.work, { bits: 9 });
7957
7958                /* distance table */
7959                sym = 0;
7960                while (sym < 32) { state.lens[sym++] = 5; }
7961
7962                inflate_table(DISTS, state.lens, 0, 32,   distfix, 0, state.work, { bits: 5 });
7963
7964                /* do this just once */
7965                virgin = false;
7966            }
7967
7968            state.lencode = lenfix;
7969            state.lenbits = 9;
7970            state.distcode = distfix;
7971            state.distbits = 5;
7972        }
7973
7974
7975        /*
7976 Update the window with the last wsize (normally 32K) bytes written before
7977 returning.  If window does not exist yet, create it.  This is only called
7978 when a window is already in use, or when output has been written during this
7979 inflate call, but the end of the deflate stream has not been reached yet.
7980 It is also called to create a window for dictionary data when a dictionary
7981 is loaded.
7982
7983 Providing output buffers larger than 32K to inflate() should provide a speed
7984 advantage, since only the last 32K of output is copied to the sliding window
7985 upon return from inflate(), and since all distances after the first 32K of
7986 output will fall in the output data, making match copies simpler and faster.
7987 The advantage may be dependent on the size of the processor's data caches.
7988 */
7989        function updatewindow(strm, src, end, copy) {
7990            var dist;
7991            var state = strm.state;
7992
7993            /* if it hasn't been done already, allocate space for the window */
7994            if (state.window === null) {
7995                state.wsize = 1 << state.wbits;
7996                state.wnext = 0;
7997                state.whave = 0;
7998
7999                state.window = new utils.Buf8(state.wsize);
8000            }
8001
8002            /* copy state->wsize or less output bytes into the circular window */
8003            if (copy >= state.wsize) {
8004                utils.arraySet(state.window, src, end - state.wsize, state.wsize, 0);
8005                state.wnext = 0;
8006                state.whave = state.wsize;
8007            }
8008            else {
8009                dist = state.wsize - state.wnext;
8010                if (dist > copy) {
8011                    dist = copy;
8012                }
8013                //zmemcpy(state->window + state->wnext, end - copy, dist);
8014                utils.arraySet(state.window, src, end - copy, dist, state.wnext);
8015                copy -= dist;
8016                if (copy) {
8017                    //zmemcpy(state->window, end - copy, copy);
8018                    utils.arraySet(state.window, src, end - copy, copy, 0);
8019                    state.wnext = copy;
8020                    state.whave = state.wsize;
8021                }
8022                else {
8023                    state.wnext += dist;
8024                    if (state.wnext === state.wsize) { state.wnext = 0; }
8025                    if (state.whave < state.wsize) { state.whave += dist; }
8026                }
8027            }
8028            return 0;
8029        }
8030
8031        function inflate(strm, flush) {
8032            var state;
8033            var input, output;          // input/output buffers
8034            var next;                   /* next input INDEX */
8035            var put;                    /* next output INDEX */
8036            var have, left;             /* available input and output */
8037            var hold;                   /* bit buffer */
8038            var bits;                   /* bits in bit buffer */
8039            var _in, _out;              /* save starting available input and output */
8040            var copy;                   /* number of stored or match bytes to copy */
8041            var from;                   /* where to copy match bytes from */
8042            var from_source;
8043            var here = 0;               /* current decoding table entry */
8044            var here_bits, here_op, here_val; // paked "here" denormalized (JS specific)
8045            //var last;                   /* parent table entry */
8046            var last_bits, last_op, last_val; // paked "last" denormalized (JS specific)
8047            var len;                    /* length to copy for repeats, bits to drop */
8048            var ret;                    /* return code */
8049            var hbuf = new utils.Buf8(4);    /* buffer for gzip header crc calculation */
8050            var opts;
8051
8052            var n; // temporary var for NEED_BITS
8053
8054            var order = /* permutation of code lengths */
8055                [ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 ];
8056
8057
8058            if (!strm || !strm.state || !strm.output ||
8059                (!strm.input && strm.avail_in !== 0)) {
8060                return Z_STREAM_ERROR;
8061            }
8062
8063            state = strm.state;
8064            if (state.mode === TYPE) { state.mode = TYPEDO; }    /* skip check */
8065
8066
8067            //--- LOAD() ---
8068            put = strm.next_out;
8069            output = strm.output;
8070            left = strm.avail_out;
8071            next = strm.next_in;
8072            input = strm.input;
8073            have = strm.avail_in;
8074            hold = state.hold;
8075            bits = state.bits;
8076            //---
8077
8078            _in = have;
8079            _out = left;
8080            ret = Z_OK;
8081
8082            inf_leave: // goto emulation
8083                for (;;) {
8084                    switch (state.mode) {
8085                        case HEAD:
8086                            if (state.wrap === 0) {
8087                                state.mode = TYPEDO;
8088                                break;
8089                            }
8090                            //=== NEEDBITS(16);
8091                            while (bits < 16) {
8092                                if (have === 0) { break inf_leave; }
8093                                have--;
8094                                hold += input[next++] << bits;
8095                                bits += 8;
8096                            }
8097                            //===//
8098                            if ((state.wrap & 2) && hold === 0x8b1f) {  /* gzip header */
8099                                state.check = 0/*crc32(0L, Z_NULL, 0)*/;
8100                                //=== CRC2(state.check, hold);
8101                                hbuf[0] = hold & 0xff;
8102                                hbuf[1] = (hold >>> 8) & 0xff;
8103                                state.check = crc32(state.check, hbuf, 2, 0);
8104                                //===//
8105
8106                                //=== INITBITS();
8107                                hold = 0;
8108                                bits = 0;
8109                                //===//
8110                                state.mode = FLAGS;
8111                                break;
8112                            }
8113                            state.flags = 0;           /* expect zlib header */
8114                            if (state.head) {
8115                                state.head.done = false;
8116                            }
8117                            if (!(state.wrap & 1) ||   /* check if zlib header allowed */
8118                                (((hold & 0xff)/*BITS(8)*/ << 8) + (hold >> 8)) % 31) {
8119                                strm.msg = 'incorrect header check';
8120                                state.mode = BAD;
8121                                break;
8122                            }
8123                            if ((hold & 0x0f)/*BITS(4)*/ !== Z_DEFLATED) {
8124                                strm.msg = 'unknown compression method';
8125                                state.mode = BAD;
8126                                break;
8127                            }
8128                            //--- DROPBITS(4) ---//
8129                            hold >>>= 4;
8130                            bits -= 4;
8131                            //---//
8132                            len = (hold & 0x0f)/*BITS(4)*/ + 8;
8133                            if (state.wbits === 0) {
8134                                state.wbits = len;
8135                            }
8136                            else if (len > state.wbits) {
8137                                strm.msg = 'invalid window size';
8138                                state.mode = BAD;
8139                                break;
8140                            }
8141                            state.dmax = 1 << len;
8142                            //Tracev((stderr, "inflate:   zlib header ok\n"));
8143                            strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
8144                            state.mode = hold & 0x200 ? DICTID : TYPE;
8145                            //=== INITBITS();
8146                            hold = 0;
8147                            bits = 0;
8148                            //===//
8149                            break;
8150                        case FLAGS:
8151                            //=== NEEDBITS(16); */
8152                            while (bits < 16) {
8153                                if (have === 0) { break inf_leave; }
8154                                have--;
8155                                hold += input[next++] << bits;
8156                                bits += 8;
8157                            }
8158                            //===//
8159                            state.flags = hold;
8160                            if ((state.flags & 0xff) !== Z_DEFLATED) {
8161                                strm.msg = 'unknown compression method';
8162                                state.mode = BAD;
8163                                break;
8164                            }
8165                            if (state.flags & 0xe000) {
8166                                strm.msg = 'unknown header flags set';
8167                                state.mode = BAD;
8168                                break;
8169                            }
8170                            if (state.head) {
8171                                state.head.text = ((hold >> 8) & 1);
8172                            }
8173                            if (state.flags & 0x0200) {
8174                                //=== CRC2(state.check, hold);
8175                                hbuf[0] = hold & 0xff;
8176                                hbuf[1] = (hold >>> 8) & 0xff;
8177                                state.check = crc32(state.check, hbuf, 2, 0);
8178                                //===//
8179                            }
8180                            //=== INITBITS();
8181                            hold = 0;
8182                            bits = 0;
8183                            //===//
8184                            state.mode = TIME;
8185                        /* falls through */
8186                        case TIME:
8187                            //=== NEEDBITS(32); */
8188                            while (bits < 32) {
8189                                if (have === 0) { break inf_leave; }
8190                                have--;
8191                                hold += input[next++] << bits;
8192                                bits += 8;
8193                            }
8194                            //===//
8195                            if (state.head) {
8196                                state.head.time = hold;
8197                            }
8198                            if (state.flags & 0x0200) {
8199                                //=== CRC4(state.check, hold)
8200                                hbuf[0] = hold & 0xff;
8201                                hbuf[1] = (hold >>> 8) & 0xff;
8202                                hbuf[2] = (hold >>> 16) & 0xff;
8203                                hbuf[3] = (hold >>> 24) & 0xff;
8204                                state.check = crc32(state.check, hbuf, 4, 0);
8205                                //===
8206                            }
8207                            //=== INITBITS();
8208                            hold = 0;
8209                            bits = 0;
8210                            //===//
8211                            state.mode = OS;
8212                        /* falls through */
8213                        case OS:
8214                            //=== NEEDBITS(16); */
8215                            while (bits < 16) {
8216                                if (have === 0) { break inf_leave; }
8217                                have--;
8218                                hold += input[next++] << bits;
8219                                bits += 8;
8220                            }
8221                            //===//
8222                            if (state.head) {
8223                                state.head.xflags = (hold & 0xff);
8224                                state.head.os = (hold >> 8);
8225                            }
8226                            if (state.flags & 0x0200) {
8227                                //=== CRC2(state.check, hold);
8228                                hbuf[0] = hold & 0xff;
8229                                hbuf[1] = (hold >>> 8) & 0xff;
8230                                state.check = crc32(state.check, hbuf, 2, 0);
8231                                //===//
8232                            }
8233                            //=== INITBITS();
8234                            hold = 0;
8235                            bits = 0;
8236                            //===//
8237                            state.mode = EXLEN;
8238                        /* falls through */
8239                        case EXLEN:
8240                            if (state.flags & 0x0400) {
8241                                //=== NEEDBITS(16); */
8242                                while (bits < 16) {
8243                                    if (have === 0) { break inf_leave; }
8244                                    have--;
8245                                    hold += input[next++] << bits;
8246                                    bits += 8;
8247                                }
8248                                //===//
8249                                state.length = hold;
8250                                if (state.head) {
8251                                    state.head.extra_len = hold;
8252                                }
8253                                if (state.flags & 0x0200) {
8254                                    //=== CRC2(state.check, hold);
8255                                    hbuf[0] = hold & 0xff;
8256                                    hbuf[1] = (hold >>> 8) & 0xff;
8257                                    state.check = crc32(state.check, hbuf, 2, 0);
8258                                    //===//
8259                                }
8260                                //=== INITBITS();
8261                                hold = 0;
8262                                bits = 0;
8263                                //===//
8264                            }
8265                            else if (state.head) {
8266                                state.head.extra = null/*Z_NULL*/;
8267                            }
8268                            state.mode = EXTRA;
8269                        /* falls through */
8270                        case EXTRA:
8271                            if (state.flags & 0x0400) {
8272                                copy = state.length;
8273                                if (copy > have) { copy = have; }
8274                                if (copy) {
8275                                    if (state.head) {
8276                                        len = state.head.extra_len - state.length;
8277                                        if (!state.head.extra) {
8278                                            // Use untyped array for more conveniend processing later
8279                                            state.head.extra = new Array(state.head.extra_len);
8280                                        }
8281                                        utils.arraySet(
8282                                            state.head.extra,
8283                                            input,
8284                                            next,
8285                                            // extra field is limited to 65536 bytes
8286                                            // - no need for additional size check
8287                                            copy,
8288                                            /*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
8289                                            len
8290                                        );
8291                                        //zmemcpy(state.head.extra + len, next,
8292                                        //        len + copy > state.head.extra_max ?
8293                                        //        state.head.extra_max - len : copy);
8294                                    }
8295                                    if (state.flags & 0x0200) {
8296                                        state.check = crc32(state.check, input, copy, next);
8297                                    }
8298                                    have -= copy;
8299                                    next += copy;
8300                                    state.length -= copy;
8301                                }
8302                                if (state.length) { break inf_leave; }
8303                            }
8304                            state.length = 0;
8305                            state.mode = NAME;
8306                        /* falls through */
8307                        case NAME:
8308                            if (state.flags & 0x0800) {
8309                                if (have === 0) { break inf_leave; }
8310                                copy = 0;
8311                                do {
8312                                    // TODO: 2 or 1 bytes?
8313                                    len = input[next + copy++];
8314                                    /* use constant limit because in js we should not preallocate memory */
8315                                    if (state.head && len &&
8316                                        (state.length < 65536 /*state.head.name_max*/)) {
8317                                        state.head.name += String.fromCharCode(len);
8318                                    }
8319                                } while (len && copy < have);
8320
8321                                if (state.flags & 0x0200) {
8322                                    state.check = crc32(state.check, input, copy, next);
8323                                }
8324                                have -= copy;
8325                                next += copy;
8326                                if (len) { break inf_leave; }
8327                            }
8328                            else if (state.head) {
8329                                state.head.name = null;
8330                            }
8331                            state.length = 0;
8332                            state.mode = COMMENT;
8333                        /* falls through */
8334                        case COMMENT:
8335                            if (state.flags & 0x1000) {
8336                                if (have === 0) { break inf_leave; }
8337                                copy = 0;
8338                                do {
8339                                    len = input[next + copy++];
8340                                    /* use constant limit because in js we should not preallocate memory */
8341                                    if (state.head && len &&
8342                                        (state.length < 65536 /*state.head.comm_max*/)) {
8343                                        state.head.comment += String.fromCharCode(len);
8344                                    }
8345                                } while (len && copy < have);
8346                                if (state.flags & 0x0200) {
8347                                    state.check = crc32(state.check, input, copy, next);
8348                                }
8349                                have -= copy;
8350                                next += copy;
8351                                if (len) { break inf_leave; }
8352                            }
8353                            else if (state.head) {
8354                                state.head.comment = null;
8355                            }
8356                            state.mode = HCRC;
8357                        /* falls through */
8358                        case HCRC:
8359                            if (state.flags & 0x0200) {
8360                                //=== NEEDBITS(16); */
8361                                while (bits < 16) {
8362                                    if (have === 0) { break inf_leave; }
8363                                    have--;
8364                                    hold += input[next++] << bits;
8365                                    bits += 8;
8366                                }
8367                                //===//
8368                                if (hold !== (state.check & 0xffff)) {
8369                                    strm.msg = 'header crc mismatch';
8370                                    state.mode = BAD;
8371                                    break;
8372                                }
8373                                //=== INITBITS();
8374                                hold = 0;
8375                                bits = 0;
8376                                //===//
8377                            }
8378                            if (state.head) {
8379                                state.head.hcrc = ((state.flags >> 9) & 1);
8380                                state.head.done = true;
8381                            }
8382                            strm.adler = state.check = 0;
8383                            state.mode = TYPE;
8384                            break;
8385                        case DICTID:
8386                            //=== NEEDBITS(32); */
8387                            while (bits < 32) {
8388                                if (have === 0) { break inf_leave; }
8389                                have--;
8390                                hold += input[next++] << bits;
8391                                bits += 8;
8392                            }
8393                            //===//
8394                            strm.adler = state.check = zswap32(hold);
8395                            //=== INITBITS();
8396                            hold = 0;
8397                            bits = 0;
8398                            //===//
8399                            state.mode = DICT;
8400                        /* falls through */
8401                        case DICT:
8402                            if (state.havedict === 0) {
8403                                //--- RESTORE() ---
8404                                strm.next_out = put;
8405                                strm.avail_out = left;
8406                                strm.next_in = next;
8407                                strm.avail_in = have;
8408                                state.hold = hold;
8409                                state.bits = bits;
8410                                //---
8411                                return Z_NEED_DICT;
8412                            }
8413                            strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
8414                            state.mode = TYPE;
8415                        /* falls through */
8416                        case TYPE:
8417                            if (flush === Z_BLOCK || flush === Z_TREES) { break inf_leave; }
8418                        /* falls through */
8419                        case TYPEDO:
8420                            if (state.last) {
8421                                //--- BYTEBITS() ---//
8422                                hold >>>= bits & 7;
8423                                bits -= bits & 7;
8424                                //---//
8425                                state.mode = CHECK;
8426                                break;
8427                            }
8428                            //=== NEEDBITS(3); */
8429                            while (bits < 3) {
8430                                if (have === 0) { break inf_leave; }
8431                                have--;
8432                                hold += input[next++] << bits;
8433                                bits += 8;
8434                            }
8435                            //===//
8436                            state.last = (hold & 0x01)/*BITS(1)*/;
8437                            //--- DROPBITS(1) ---//
8438                            hold >>>= 1;
8439                            bits -= 1;
8440                            //---//
8441
8442                            switch ((hold & 0x03)/*BITS(2)*/) {
8443                                case 0:                             /* stored block */
8444                                    //Tracev((stderr, "inflate:     stored block%s\n",
8445                                    //        state.last ? " (last)" : ""));
8446                                    state.mode = STORED;
8447                                    break;
8448                                case 1:                             /* fixed block */
8449                                    fixedtables(state);
8450                                    //Tracev((stderr, "inflate:     fixed codes block%s\n",
8451                                    //        state.last ? " (last)" : ""));
8452                                    state.mode = LEN_;             /* decode codes */
8453                                    if (flush === Z_TREES) {
8454                                        //--- DROPBITS(2) ---//
8455                                        hold >>>= 2;
8456                                        bits -= 2;
8457                                        //---//
8458                                        break inf_leave;
8459                                    }
8460                                    break;
8461                                case 2:                             /* dynamic block */
8462                                    //Tracev((stderr, "inflate:     dynamic codes block%s\n",
8463                                    //        state.last ? " (last)" : ""));
8464                                    state.mode = TABLE;
8465                                    break;
8466                                case 3:
8467                                    strm.msg = 'invalid block type';
8468                                    state.mode = BAD;
8469                            }
8470                            //--- DROPBITS(2) ---//
8471                            hold >>>= 2;
8472                            bits -= 2;
8473                            //---//
8474                            break;
8475                        case STORED:
8476                            //--- BYTEBITS() ---// /* go to byte boundary */
8477                            hold >>>= bits & 7;
8478                            bits -= bits & 7;
8479                            //---//
8480                            //=== NEEDBITS(32); */
8481                            while (bits < 32) {
8482                                if (have === 0) { break inf_leave; }
8483                                have--;
8484                                hold += input[next++] << bits;
8485                                bits += 8;
8486                            }
8487                            //===//
8488                            if ((hold & 0xffff) !== ((hold >>> 16) ^ 0xffff)) {
8489                                strm.msg = 'invalid stored block lengths';
8490                                state.mode = BAD;
8491                                break;
8492                            }
8493                            state.length = hold & 0xffff;
8494                            //Tracev((stderr, "inflate:       stored length %u\n",
8495                            //        state.length));
8496                            //=== INITBITS();
8497                            hold = 0;
8498                            bits = 0;
8499                            //===//
8500                            state.mode = COPY_;
8501                            if (flush === Z_TREES) { break inf_leave; }
8502                        /* falls through */
8503                        case COPY_:
8504                            state.mode = COPY;
8505                        /* falls through */
8506                        case COPY:
8507                            copy = state.length;
8508                            if (copy) {
8509                                if (copy > have) { copy = have; }
8510                                if (copy > left) { copy = left; }
8511                                if (copy === 0) { break inf_leave; }
8512                                //--- zmemcpy(put, next, copy); ---
8513                                utils.arraySet(output, input, next, copy, put);
8514                                //---//
8515                                have -= copy;
8516                                next += copy;
8517                                left -= copy;
8518                                put += copy;
8519                                state.length -= copy;
8520                                break;
8521                            }
8522                            //Tracev((stderr, "inflate:       stored end\n"));
8523                            state.mode = TYPE;
8524                            break;
8525                        case TABLE:
8526                            //=== NEEDBITS(14); */
8527                            while (bits < 14) {
8528                                if (have === 0) { break inf_leave; }
8529                                have--;
8530                                hold += input[next++] << bits;
8531                                bits += 8;
8532                            }
8533                            //===//
8534                            state.nlen = (hold & 0x1f)/*BITS(5)*/ + 257;
8535                            //--- DROPBITS(5) ---//
8536                            hold >>>= 5;
8537                            bits -= 5;
8538                            //---//
8539                            state.ndist = (hold & 0x1f)/*BITS(5)*/ + 1;
8540                            //--- DROPBITS(5) ---//
8541                            hold >>>= 5;
8542                            bits -= 5;
8543                            //---//
8544                            state.ncode = (hold & 0x0f)/*BITS(4)*/ + 4;
8545                            //--- DROPBITS(4) ---//
8546                            hold >>>= 4;
8547                            bits -= 4;
8548                            //---//
8549//#ifndef PKZIP_BUG_WORKAROUND
8550                            if (state.nlen > 286 || state.ndist > 30) {
8551                                strm.msg = 'too many length or distance symbols';
8552                                state.mode = BAD;
8553                                break;
8554                            }
8555//#endif
8556                            //Tracev((stderr, "inflate:       table sizes ok\n"));
8557                            state.have = 0;
8558                            state.mode = LENLENS;
8559                        /* falls through */
8560                        case LENLENS:
8561                            while (state.have < state.ncode) {
8562                                //=== NEEDBITS(3);
8563                                while (bits < 3) {
8564                                    if (have === 0) { break inf_leave; }
8565                                    have--;
8566                                    hold += input[next++] << bits;
8567                                    bits += 8;
8568                                }
8569                                //===//
8570                                state.lens[order[state.have++]] = (hold & 0x07);//BITS(3);
8571                                //--- DROPBITS(3) ---//
8572                                hold >>>= 3;
8573                                bits -= 3;
8574                                //---//
8575                            }
8576                            while (state.have < 19) {
8577                                state.lens[order[state.have++]] = 0;
8578                            }
8579                            // We have separate tables & no pointers. 2 commented lines below not needed.
8580                            //state.next = state.codes;
8581                            //state.lencode = state.next;
8582                            // Switch to use dynamic table
8583                            state.lencode = state.lendyn;
8584                            state.lenbits = 7;
8585
8586                            opts = { bits: state.lenbits };
8587                            ret = inflate_table(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts);
8588                            state.lenbits = opts.bits;
8589
8590                            if (ret) {
8591                                strm.msg = 'invalid code lengths set';
8592                                state.mode = BAD;
8593                                break;
8594                            }
8595                            //Tracev((stderr, "inflate:       code lengths ok\n"));
8596                            state.have = 0;
8597                            state.mode = CODELENS;
8598                        /* falls through */
8599                        case CODELENS:
8600                            while (state.have < state.nlen + state.ndist) {
8601                                for (;;) {
8602                                    here = state.lencode[hold & ((1 << state.lenbits) - 1)];/*BITS(state.lenbits)*/
8603                                    here_bits = here >>> 24;
8604                                    here_op = (here >>> 16) & 0xff;
8605                                    here_val = here & 0xffff;
8606
8607                                    if ((here_bits) <= bits) { break; }
8608                                    //--- PULLBYTE() ---//
8609                                    if (have === 0) { break inf_leave; }
8610                                    have--;
8611                                    hold += input[next++] << bits;
8612                                    bits += 8;
8613                                    //---//
8614                                }
8615                                if (here_val < 16) {
8616                                    //--- DROPBITS(here.bits) ---//
8617                                    hold >>>= here_bits;
8618                                    bits -= here_bits;
8619                                    //---//
8620                                    state.lens[state.have++] = here_val;
8621                                }
8622                                else {
8623                                    if (here_val === 16) {
8624                                        //=== NEEDBITS(here.bits + 2);
8625                                        n = here_bits + 2;
8626                                        while (bits < n) {
8627                                            if (have === 0) { break inf_leave; }
8628                                            have--;
8629                                            hold += input[next++] << bits;
8630                                            bits += 8;
8631                                        }
8632                                        //===//
8633                                        //--- DROPBITS(here.bits) ---//
8634                                        hold >>>= here_bits;
8635                                        bits -= here_bits;
8636                                        //---//
8637                                        if (state.have === 0) {
8638                                            strm.msg = 'invalid bit length repeat';
8639                                            state.mode = BAD;
8640                                            break;
8641                                        }
8642                                        len = state.lens[state.have - 1];
8643                                        copy = 3 + (hold & 0x03);//BITS(2);
8644                                        //--- DROPBITS(2) ---//
8645                                        hold >>>= 2;
8646                                        bits -= 2;
8647                                        //---//
8648                                    }
8649                                    else if (here_val === 17) {
8650                                        //=== NEEDBITS(here.bits + 3);
8651                                        n = here_bits + 3;
8652                                        while (bits < n) {
8653                                            if (have === 0) { break inf_leave; }
8654                                            have--;
8655                                            hold += input[next++] << bits;
8656                                            bits += 8;
8657                                        }
8658                                        //===//
8659                                        //--- DROPBITS(here.bits) ---//
8660                                        hold >>>= here_bits;
8661                                        bits -= here_bits;
8662                                        //---//
8663                                        len = 0;
8664                                        copy = 3 + (hold & 0x07);//BITS(3);
8665                                        //--- DROPBITS(3) ---//
8666                                        hold >>>= 3;
8667                                        bits -= 3;
8668                                        //---//
8669                                    }
8670                                    else {
8671                                        //=== NEEDBITS(here.bits + 7);
8672                                        n = here_bits + 7;
8673                                        while (bits < n) {
8674                                            if (have === 0) { break inf_leave; }
8675                                            have--;
8676                                            hold += input[next++] << bits;
8677                                            bits += 8;
8678                                        }
8679                                        //===//
8680                                        //--- DROPBITS(here.bits) ---//
8681                                        hold >>>= here_bits;
8682                                        bits -= here_bits;
8683                                        //---//
8684                                        len = 0;
8685                                        copy = 11 + (hold & 0x7f);//BITS(7);
8686                                        //--- DROPBITS(7) ---//
8687                                        hold >>>= 7;
8688                                        bits -= 7;
8689                                        //---//
8690                                    }
8691                                    if (state.have + copy > state.nlen + state.ndist) {
8692                                        strm.msg = 'invalid bit length repeat';
8693                                        state.mode = BAD;
8694                                        break;
8695                                    }
8696                                    while (copy--) {
8697                                        state.lens[state.have++] = len;
8698                                    }
8699                                }
8700                            }
8701
8702                            /* handle error breaks in while */
8703                            if (state.mode === BAD) { break; }
8704
8705                            /* check for end-of-block code (better have one) */
8706                            if (state.lens[256] === 0) {
8707                                strm.msg = 'invalid code -- missing end-of-block';
8708                                state.mode = BAD;
8709                                break;
8710                            }
8711
8712                            /* build code tables -- note: do not change the lenbits or distbits
8713         values here (9 and 6) without reading the comments in inftrees.h
8714         concerning the ENOUGH constants, which depend on those values */
8715                            state.lenbits = 9;
8716
8717                            opts = { bits: state.lenbits };
8718                            ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts);
8719                            // We have separate tables & no pointers. 2 commented lines below not needed.
8720                            // state.next_index = opts.table_index;
8721                            state.lenbits = opts.bits;
8722                            // state.lencode = state.next;
8723
8724                            if (ret) {
8725                                strm.msg = 'invalid literal/lengths set';
8726                                state.mode = BAD;
8727                                break;
8728                            }
8729
8730                            state.distbits = 6;
8731                            //state.distcode.copy(state.codes);
8732                            // Switch to use dynamic table
8733                            state.distcode = state.distdyn;
8734                            opts = { bits: state.distbits };
8735                            ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);
8736                            // We have separate tables & no pointers. 2 commented lines below not needed.
8737                            // state.next_index = opts.table_index;
8738                            state.distbits = opts.bits;
8739                            // state.distcode = state.next;
8740
8741                            if (ret) {
8742                                strm.msg = 'invalid distances set';
8743                                state.mode = BAD;
8744                                break;
8745                            }
8746                            //Tracev((stderr, 'inflate:       codes ok\n'));
8747                            state.mode = LEN_;
8748                            if (flush === Z_TREES) { break inf_leave; }
8749                        /* falls through */
8750                        case LEN_:
8751                            state.mode = LEN;
8752                        /* falls through */
8753                        case LEN:
8754                            if (have >= 6 && left >= 258) {
8755                                //--- RESTORE() ---
8756                                strm.next_out = put;
8757                                strm.avail_out = left;
8758                                strm.next_in = next;
8759                                strm.avail_in = have;
8760                                state.hold = hold;
8761                                state.bits = bits;
8762                                //---
8763                                inflate_fast(strm, _out);
8764                                //--- LOAD() ---
8765                                put = strm.next_out;
8766                                output = strm.output;
8767                                left = strm.avail_out;
8768                                next = strm.next_in;
8769                                input = strm.input;
8770                                have = strm.avail_in;
8771                                hold = state.hold;
8772                                bits = state.bits;
8773                                //---
8774
8775                                if (state.mode === TYPE) {
8776                                    state.back = -1;
8777                                }
8778                                break;
8779                            }
8780                            state.back = 0;
8781                            for (;;) {
8782                                here = state.lencode[hold & ((1 << state.lenbits) - 1)];  /*BITS(state.lenbits)*/
8783                                here_bits = here >>> 24;
8784                                here_op = (here >>> 16) & 0xff;
8785                                here_val = here & 0xffff;
8786
8787                                if (here_bits <= bits) { break; }
8788                                //--- PULLBYTE() ---//
8789                                if (have === 0) { break inf_leave; }
8790                                have--;
8791                                hold += input[next++] << bits;
8792                                bits += 8;
8793                                //---//
8794                            }
8795                            if (here_op && (here_op & 0xf0) === 0) {
8796                                last_bits = here_bits;
8797                                last_op = here_op;
8798                                last_val = here_val;
8799                                for (;;) {
8800                                    here = state.lencode[last_val +
8801                                    ((hold & ((1 << (last_bits + last_op)) - 1))/*BITS(last.bits + last.op)*/ >> last_bits)];
8802                                    here_bits = here >>> 24;
8803                                    here_op = (here >>> 16) & 0xff;
8804                                    here_val = here & 0xffff;
8805
8806                                    if ((last_bits + here_bits) <= bits) { break; }
8807                                    //--- PULLBYTE() ---//
8808                                    if (have === 0) { break inf_leave; }
8809                                    have--;
8810                                    hold += input[next++] << bits;
8811                                    bits += 8;
8812                                    //---//
8813                                }
8814                                //--- DROPBITS(last.bits) ---//
8815                                hold >>>= last_bits;
8816                                bits -= last_bits;
8817                                //---//
8818                                state.back += last_bits;
8819                            }
8820                            //--- DROPBITS(here.bits) ---//
8821                            hold >>>= here_bits;
8822                            bits -= here_bits;
8823                            //---//
8824                            state.back += here_bits;
8825                            state.length = here_val;
8826                            if (here_op === 0) {
8827                                //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
8828                                //        "inflate:         literal '%c'\n" :
8829                                //        "inflate:         literal 0x%02x\n", here.val));
8830                                state.mode = LIT;
8831                                break;
8832                            }
8833                            if (here_op & 32) {
8834                                //Tracevv((stderr, "inflate:         end of block\n"));
8835                                state.back = -1;
8836                                state.mode = TYPE;
8837                                break;
8838                            }
8839                            if (here_op & 64) {
8840                                strm.msg = 'invalid literal/length code';
8841                                state.mode = BAD;
8842                                break;
8843                            }
8844                            state.extra = here_op & 15;
8845                            state.mode = LENEXT;
8846                        /* falls through */
8847                        case LENEXT:
8848                            if (state.extra) {
8849                                //=== NEEDBITS(state.extra);
8850                                n = state.extra;
8851                                while (bits < n) {
8852                                    if (have === 0) { break inf_leave; }
8853                                    have--;
8854                                    hold += input[next++] << bits;
8855                                    bits += 8;
8856                                }
8857                                //===//
8858                                state.length += hold & ((1 << state.extra) - 1)/*BITS(state.extra)*/;
8859                                //--- DROPBITS(state.extra) ---//
8860                                hold >>>= state.extra;
8861                                bits -= state.extra;
8862                                //---//
8863                                state.back += state.extra;
8864                            }
8865                            //Tracevv((stderr, "inflate:         length %u\n", state.length));
8866                            state.was = state.length;
8867                            state.mode = DIST;
8868                        /* falls through */
8869                        case DIST:
8870                            for (;;) {
8871                                here = state.distcode[hold & ((1 << state.distbits) - 1)];/*BITS(state.distbits)*/
8872                                here_bits = here >>> 24;
8873                                here_op = (here >>> 16) & 0xff;
8874                                here_val = here & 0xffff;
8875
8876                                if ((here_bits) <= bits) { break; }
8877                                //--- PULLBYTE() ---//
8878                                if (have === 0) { break inf_leave; }
8879                                have--;
8880                                hold += input[next++] << bits;
8881                                bits += 8;
8882                                //---//
8883                            }
8884                            if ((here_op & 0xf0) === 0) {
8885                                last_bits = here_bits;
8886                                last_op = here_op;
8887                                last_val = here_val;
8888                                for (;;) {
8889                                    here = state.distcode[last_val +
8890                                    ((hold & ((1 << (last_bits + last_op)) - 1))/*BITS(last.bits + last.op)*/ >> last_bits)];
8891                                    here_bits = here >>> 24;
8892                                    here_op = (here >>> 16) & 0xff;
8893                                    here_val = here & 0xffff;
8894
8895                                    if ((last_bits + here_bits) <= bits) { break; }
8896                                    //--- PULLBYTE() ---//
8897                                    if (have === 0) { break inf_leave; }
8898                                    have--;
8899                                    hold += input[next++] << bits;
8900                                    bits += 8;
8901                                    //---//
8902                                }
8903                                //--- DROPBITS(last.bits) ---//
8904                                hold >>>= last_bits;
8905                                bits -= last_bits;
8906                                //---//
8907                                state.back += last_bits;
8908                            }
8909                            //--- DROPBITS(here.bits) ---//
8910                            hold >>>= here_bits;
8911                            bits -= here_bits;
8912                            //---//
8913                            state.back += here_bits;
8914                            if (here_op & 64) {
8915                                strm.msg = 'invalid distance code';
8916                                state.mode = BAD;
8917                                break;
8918                            }
8919                            state.offset = here_val;
8920                            state.extra = (here_op) & 15;
8921                            state.mode = DISTEXT;
8922                        /* falls through */
8923                        case DISTEXT:
8924                            if (state.extra) {
8925                                //=== NEEDBITS(state.extra);
8926                                n = state.extra;
8927                                while (bits < n) {
8928                                    if (have === 0) { break inf_leave; }
8929                                    have--;
8930                                    hold += input[next++] << bits;
8931                                    bits += 8;
8932                                }
8933                                //===//
8934                                state.offset += hold & ((1 << state.extra) - 1)/*BITS(state.extra)*/;
8935                                //--- DROPBITS(state.extra) ---//
8936                                hold >>>= state.extra;
8937                                bits -= state.extra;
8938                                //---//
8939                                state.back += state.extra;
8940                            }
8941//#ifdef INFLATE_STRICT
8942                            if (state.offset > state.dmax) {
8943                                strm.msg = 'invalid distance too far back';
8944                                state.mode = BAD;
8945                                break;
8946                            }
8947//#endif
8948                            //Tracevv((stderr, "inflate:         distance %u\n", state.offset));
8949                            state.mode = MATCH;
8950                        /* falls through */
8951                        case MATCH:
8952                            if (left === 0) { break inf_leave; }
8953                            copy = _out - left;
8954                            if (state.offset > copy) {         /* copy from window */
8955                                copy = state.offset - copy;
8956                                if (copy > state.whave) {
8957                                    if (state.sane) {
8958                                        strm.msg = 'invalid distance too far back';
8959                                        state.mode = BAD;
8960                                        break;
8961                                    }
8962// (!) This block is disabled in zlib defailts,
8963// don't enable it for binary compatibility
8964//#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
8965//          Trace((stderr, "inflate.c too far\n"));
8966//          copy -= state.whave;
8967//          if (copy > state.length) { copy = state.length; }
8968//          if (copy > left) { copy = left; }
8969//          left -= copy;
8970//          state.length -= copy;
8971//          do {
8972//            output[put++] = 0;
8973//          } while (--copy);
8974//          if (state.length === 0) { state.mode = LEN; }
8975//          break;
8976//#endif
8977                                }
8978                                if (copy > state.wnext) {
8979                                    copy -= state.wnext;
8980                                    from = state.wsize - copy;
8981                                }
8982                                else {
8983                                    from = state.wnext - copy;
8984                                }
8985                                if (copy > state.length) { copy = state.length; }
8986                                from_source = state.window;
8987                            }
8988                            else {                              /* copy from output */
8989                                from_source = output;
8990                                from = put - state.offset;
8991                                copy = state.length;
8992                            }
8993                            if (copy > left) { copy = left; }
8994                            left -= copy;
8995                            state.length -= copy;
8996                            do {
8997                                output[put++] = from_source[from++];
8998                            } while (--copy);
8999                            if (state.length === 0) { state.mode = LEN; }
9000                            break;
9001                        case LIT:
9002                            if (left === 0) { break inf_leave; }
9003                            output[put++] = state.length;
9004                            left--;
9005                            state.mode = LEN;
9006                            break;
9007                        case CHECK:
9008                            if (state.wrap) {
9009                                //=== NEEDBITS(32);
9010                                while (bits < 32) {
9011                                    if (have === 0) { break inf_leave; }
9012                                    have--;
9013                                    // Use '|' insdead of '+' to make sure that result is signed
9014                                    hold |= input[next++] << bits;
9015                                    bits += 8;
9016                                }
9017                                //===//
9018                                _out -= left;
9019                                strm.total_out += _out;
9020                                state.total += _out;
9021                                if (_out) {
9022                                    strm.adler = state.check =
9023                                        /*UPDATE(state.check, put - _out, _out);*/
9024                                        (state.flags ? crc32(state.check, output, _out, put - _out) : adler32(state.check, output, _out, put - _out));
9025
9026                                }
9027                                _out = left;
9028                                // NB: crc32 stored as signed 32-bit int, zswap32 returns signed too
9029                                if ((state.flags ? hold : zswap32(hold)) !== state.check) {
9030                                    strm.msg = 'incorrect data check';
9031                                    state.mode = BAD;
9032                                    break;
9033                                }
9034                                //=== INITBITS();
9035                                hold = 0;
9036                                bits = 0;
9037                                //===//
9038                                //Tracev((stderr, "inflate:   check matches trailer\n"));
9039                            }
9040                            state.mode = LENGTH;
9041                        /* falls through */
9042                        case LENGTH:
9043                            if (state.wrap && state.flags) {
9044                                //=== NEEDBITS(32);
9045                                while (bits < 32) {
9046                                    if (have === 0) { break inf_leave; }
9047                                    have--;
9048                                    hold += input[next++] << bits;
9049                                    bits += 8;
9050                                }
9051                                //===//
9052                                if (hold !== (state.total & 0xffffffff)) {
9053                                    strm.msg = 'incorrect length check';
9054                                    state.mode = BAD;
9055                                    break;
9056                                }
9057                                //=== INITBITS();
9058                                hold = 0;
9059                                bits = 0;
9060                                //===//
9061                                //Tracev((stderr, "inflate:   length matches trailer\n"));
9062                            }
9063                            state.mode = DONE;
9064                        /* falls through */
9065                        case DONE:
9066                            ret = Z_STREAM_END;
9067                            break inf_leave;
9068                        case BAD:
9069                            ret = Z_DATA_ERROR;
9070                            break inf_leave;
9071                        case MEM:
9072                            return Z_MEM_ERROR;
9073                        case SYNC:
9074                        /* falls through */
9075                        default:
9076                            return Z_STREAM_ERROR;
9077                    }
9078                }
9079
9080            // inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave"
9081
9082            /*
9083     Return from inflate(), updating the total counts and the check value.
9084     If there was no progress during the inflate() call, return a buffer
9085     error.  Call updatewindow() to create and/or update the window state.
9086     Note: a memory error from inflate() is non-recoverable.
9087   */
9088
9089            //--- RESTORE() ---
9090            strm.next_out = put;
9091            strm.avail_out = left;
9092            strm.next_in = next;
9093            strm.avail_in = have;
9094            state.hold = hold;
9095            state.bits = bits;
9096            //---
9097
9098            if (state.wsize || (_out !== strm.avail_out && state.mode < BAD &&
9099                (state.mode < CHECK || flush !== Z_FINISH))) {
9100                if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) {
9101                    state.mode = MEM;
9102                    return Z_MEM_ERROR;
9103                }
9104            }
9105            _in -= strm.avail_in;
9106            _out -= strm.avail_out;
9107            strm.total_in += _in;
9108            strm.total_out += _out;
9109            state.total += _out;
9110            if (state.wrap && _out) {
9111                strm.adler = state.check = /*UPDATE(state.check, strm.next_out - _out, _out);*/
9112                    (state.flags ? crc32(state.check, output, _out, strm.next_out - _out) : adler32(state.check, output, _out, strm.next_out - _out));
9113            }
9114            strm.data_type = state.bits + (state.last ? 64 : 0) +
9115                (state.mode === TYPE ? 128 : 0) +
9116                (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);
9117            if (((_in === 0 && _out === 0) || flush === Z_FINISH) && ret === Z_OK) {
9118                ret = Z_BUF_ERROR;
9119            }
9120            return ret;
9121        }
9122
9123        function inflateEnd(strm) {
9124
9125            if (!strm || !strm.state /*|| strm->zfree == (free_func)0*/) {
9126                return Z_STREAM_ERROR;
9127            }
9128
9129            var state = strm.state;
9130            if (state.window) {
9131                state.window = null;
9132            }
9133            strm.state = null;
9134            return Z_OK;
9135        }
9136
9137        function inflateGetHeader(strm, head) {
9138            var state;
9139
9140            /* check state */
9141            if (!strm || !strm.state) { return Z_STREAM_ERROR; }
9142            state = strm.state;
9143            if ((state.wrap & 2) === 0) { return Z_STREAM_ERROR; }
9144
9145            /* save header structure */
9146            state.head = head;
9147            head.done = false;
9148            return Z_OK;
9149        }
9150
9151        function inflateSetDictionary(strm, dictionary) {
9152            var dictLength = dictionary.length;
9153
9154            var state;
9155            var dictid;
9156            var ret;
9157
9158            /* check state */
9159            if (!strm /* == Z_NULL */ || !strm.state /* == Z_NULL */) { return Z_STREAM_ERROR; }
9160            state = strm.state;
9161
9162            if (state.wrap !== 0 && state.mode !== DICT) {
9163                return Z_STREAM_ERROR;
9164            }
9165
9166            /* check for correct dictionary identifier */
9167            if (state.mode === DICT) {
9168                dictid = 1; /* adler32(0, null, 0)*/
9169                /* dictid = adler32(dictid, dictionary, dictLength); */
9170                dictid = adler32(dictid, dictionary, dictLength, 0);
9171                if (dictid !== state.check) {
9172                    return Z_DATA_ERROR;
9173                }
9174            }
9175            /* copy dictionary to window using updatewindow(), which will amend the
9176   existing dictionary if appropriate */
9177            ret = updatewindow(strm, dictionary, dictLength, dictLength);
9178            if (ret) {
9179                state.mode = MEM;
9180                return Z_MEM_ERROR;
9181            }
9182            state.havedict = 1;
9183            // Tracev((stderr, "inflate:   dictionary set\n"));
9184            return Z_OK;
9185        }
9186
9187        exports.inflateReset = inflateReset;
9188        exports.inflateReset2 = inflateReset2;
9189        exports.inflateResetKeep = inflateResetKeep;
9190        exports.inflateInit = inflateInit;
9191        exports.inflateInit2 = inflateInit2;
9192        exports.inflate = inflate;
9193        exports.inflateEnd = inflateEnd;
9194        exports.inflateGetHeader = inflateGetHeader;
9195        exports.inflateSetDictionary = inflateSetDictionary;
9196        exports.inflateInfo = 'pako inflate (from Nodeca project)';
9197
9198        /* Not implemented
9199exports.inflateCopy = inflateCopy;
9200exports.inflateGetDictionary = inflateGetDictionary;
9201exports.inflateMark = inflateMark;
9202exports.inflatePrime = inflatePrime;
9203exports.inflateSync = inflateSync;
9204exports.inflateSyncPoint = inflateSyncPoint;
9205exports.inflateUndermine = inflateUndermine;
9206*/
9207
9208    },{"../utils/common":32,"./adler32":34,"./crc32":36,"./inffast":39,"./inftrees":41}],41:[function(_dereq_,module,exports){
9209        'use strict';
9210
9211
9212        var utils = _dereq_('../utils/common');
9213
9214        var MAXBITS = 15;
9215        var ENOUGH_LENS = 852;
9216        var ENOUGH_DISTS = 592;
9217//var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
9218
9219        var CODES = 0;
9220        var LENS = 1;
9221        var DISTS = 2;
9222
9223        var lbase = [ /* Length codes 257..285 base */
9224            3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
9225            35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
9226        ];
9227
9228        var lext = [ /* Length codes 257..285 extra */
9229            16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
9230            19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78
9231        ];
9232
9233        var dbase = [ /* Distance codes 0..29 base */
9234            1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
9235            257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
9236            8193, 12289, 16385, 24577, 0, 0
9237        ];
9238
9239        var dext = [ /* Distance codes 0..29 extra */
9240            16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
9241            23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
9242            28, 28, 29, 29, 64, 64
9243        ];
9244
9245        module.exports = function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts)
9246        {
9247            var bits = opts.bits;
9248            //here = opts.here; /* table entry for duplication */
9249
9250            var len = 0;               /* a code's length in bits */
9251            var sym = 0;               /* index of code symbols */
9252            var min = 0, max = 0;          /* minimum and maximum code lengths */
9253            var root = 0;              /* number of index bits for root table */
9254            var curr = 0;              /* number of index bits for current table */
9255            var drop = 0;              /* code bits to drop for sub-table */
9256            var left = 0;                   /* number of prefix codes available */
9257            var used = 0;              /* code entries in table used */
9258            var huff = 0;              /* Huffman code */
9259            var incr;              /* for incrementing code, index */
9260            var fill;              /* index for replicating entries */
9261            var low;               /* low bits for current root entry */
9262            var mask;              /* mask for low root bits */
9263            var next;             /* next available space in table */
9264            var base = null;     /* base value table to use */
9265            var base_index = 0;
9266//  var shoextra;    /* extra bits table to use */
9267            var end;                    /* use base and extra for symbol > end */
9268            var count = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1];    /* number of codes of each length */
9269            var offs = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1];     /* offsets in table for each length */
9270            var extra = null;
9271            var extra_index = 0;
9272
9273            var here_bits, here_op, here_val;
9274
9275            /*
9276   Process a set of code lengths to create a canonical Huffman code.  The
9277   code lengths are lens[0..codes-1].  Each length corresponds to the
9278   symbols 0..codes-1.  The Huffman code is generated by first sorting the
9279   symbols by length from short to long, and retaining the symbol order
9280   for codes with equal lengths.  Then the code starts with all zero bits
9281   for the first code of the shortest length, and the codes are integer
9282   increments for the same length, and zeros are appended as the length
9283   increases.  For the deflate format, these bits are stored backwards
9284   from their more natural integer increment ordering, and so when the
9285   decoding tables are built in the large loop below, the integer codes
9286   are incremented backwards.
9287
9288   This routine assumes, but does not check, that all of the entries in
9289   lens[] are in the range 0..MAXBITS.  The caller must assure this.
9290   1..MAXBITS is interpreted as that code length.  zero means that that
9291   symbol does not occur in this code.
9292
9293   The codes are sorted by computing a count of codes for each length,
9294   creating from that a table of starting indices for each length in the
9295   sorted table, and then entering the symbols in order in the sorted
9296   table.  The sorted table is work[], with that space being provided by
9297   the caller.
9298
9299   The length counts are used for other purposes as well, i.e. finding
9300   the minimum and maximum length codes, determining if there are any
9301   codes at all, checking for a valid set of lengths, and looking ahead
9302   at length counts to determine sub-table sizes when building the
9303   decoding tables.
9304   */
9305
9306            /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
9307            for (len = 0; len <= MAXBITS; len++) {
9308                count[len] = 0;
9309            }
9310            for (sym = 0; sym < codes; sym++) {
9311                count[lens[lens_index + sym]]++;
9312            }
9313
9314            /* bound code lengths, force root to be within code lengths */
9315            root = bits;
9316            for (max = MAXBITS; max >= 1; max--) {
9317                if (count[max] !== 0) { break; }
9318            }
9319            if (root > max) {
9320                root = max;
9321            }
9322            if (max === 0) {                     /* no symbols to code at all */
9323                //table.op[opts.table_index] = 64;  //here.op = (var char)64;    /* invalid code marker */
9324                //table.bits[opts.table_index] = 1;   //here.bits = (var char)1;
9325                //table.val[opts.table_index++] = 0;   //here.val = (var short)0;
9326                table[table_index++] = (1 << 24) | (64 << 16) | 0;
9327
9328
9329                //table.op[opts.table_index] = 64;
9330                //table.bits[opts.table_index] = 1;
9331                //table.val[opts.table_index++] = 0;
9332                table[table_index++] = (1 << 24) | (64 << 16) | 0;
9333
9334                opts.bits = 1;
9335                return 0;     /* no symbols, but wait for decoding to report error */
9336            }
9337            for (min = 1; min < max; min++) {
9338                if (count[min] !== 0) { break; }
9339            }
9340            if (root < min) {
9341                root = min;
9342            }
9343
9344            /* check for an over-subscribed or incomplete set of lengths */
9345            left = 1;
9346            for (len = 1; len <= MAXBITS; len++) {
9347                left <<= 1;
9348                left -= count[len];
9349                if (left < 0) {
9350                    return -1;
9351                }        /* over-subscribed */
9352            }
9353            if (left > 0 && (type === CODES || max !== 1)) {
9354                return -1;                      /* incomplete set */
9355            }
9356
9357            /* generate offsets into symbol table for each length for sorting */
9358            offs[1] = 0;
9359            for (len = 1; len < MAXBITS; len++) {
9360                offs[len + 1] = offs[len] + count[len];
9361            }
9362
9363            /* sort symbols by length, by symbol order within each length */
9364            for (sym = 0; sym < codes; sym++) {
9365                if (lens[lens_index + sym] !== 0) {
9366                    work[offs[lens[lens_index + sym]]++] = sym;
9367                }
9368            }
9369
9370            /*
9371   Create and fill in decoding tables.  In this loop, the table being
9372   filled is at next and has curr index bits.  The code being used is huff
9373   with length len.  That code is converted to an index by dropping drop
9374   bits off of the bottom.  For codes where len is less than drop + curr,
9375   those top drop + curr - len bits are incremented through all values to
9376   fill the table with replicated entries.
9377
9378   root is the number of index bits for the root table.  When len exceeds
9379   root, sub-tables are created pointed to by the root entry with an index
9380   of the low root bits of huff.  This is saved in low to check for when a
9381   new sub-table should be started.  drop is zero when the root table is
9382   being filled, and drop is root when sub-tables are being filled.
9383
9384   When a new sub-table is needed, it is necessary to look ahead in the
9385   code lengths to determine what size sub-table is needed.  The length
9386   counts are used for this, and so count[] is decremented as codes are
9387   entered in the tables.
9388
9389   used keeps track of how many table entries have been allocated from the
9390   provided *table space.  It is checked for LENS and DIST tables against
9391   the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
9392   the initial root table size constants.  See the comments in inftrees.h
9393   for more information.
9394
9395   sym increments through all symbols, and the loop terminates when
9396   all codes of length max, i.e. all codes, have been processed.  This
9397   routine permits incomplete codes, so another loop after this one fills
9398   in the rest of the decoding tables with invalid code markers.
9399   */
9400
9401            /* set up for code type */
9402            // poor man optimization - use if-else instead of switch,
9403            // to avoid deopts in old v8
9404            if (type === CODES) {
9405                base = extra = work;    /* dummy value--not used */
9406                end = 19;
9407
9408            } else if (type === LENS) {
9409                base = lbase;
9410                base_index -= 257;
9411                extra = lext;
9412                extra_index -= 257;
9413                end = 256;
9414
9415            } else {                    /* DISTS */
9416                base = dbase;
9417                extra = dext;
9418                end = -1;
9419            }
9420
9421            /* initialize opts for loop */
9422            huff = 0;                   /* starting code */
9423            sym = 0;                    /* starting code symbol */
9424            len = min;                  /* starting code length */
9425            next = table_index;              /* current table to fill in */
9426            curr = root;                /* current table index bits */
9427            drop = 0;                   /* current bits to drop from code for index */
9428            low = -1;                   /* trigger new sub-table when len > root */
9429            used = 1 << root;          /* use root table entries */
9430            mask = used - 1;            /* mask for comparing low */
9431
9432            /* check available table space */
9433            if ((type === LENS && used > ENOUGH_LENS) ||
9434                (type === DISTS && used > ENOUGH_DISTS)) {
9435                return 1;
9436            }
9437
9438            var i = 0;
9439            /* process all codes and make table entries */
9440            for (;;) {
9441                i++;
9442                /* create table entry */
9443                here_bits = len - drop;
9444                if (work[sym] < end) {
9445                    here_op = 0;
9446                    here_val = work[sym];
9447                }
9448                else if (work[sym] > end) {
9449                    here_op = extra[extra_index + work[sym]];
9450                    here_val = base[base_index + work[sym]];
9451                }
9452                else {
9453                    here_op = 32 + 64;         /* end of block */
9454                    here_val = 0;
9455                }
9456
9457                /* replicate for those indices with low len bits equal to huff */
9458                incr = 1 << (len - drop);
9459                fill = 1 << curr;
9460                min = fill;                 /* save offset to next table */
9461                do {
9462                    fill -= incr;
9463                    table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0;
9464                } while (fill !== 0);
9465
9466                /* backwards increment the len-bit code huff */
9467                incr = 1 << (len - 1);
9468                while (huff & incr) {
9469                    incr >>= 1;
9470                }
9471                if (incr !== 0) {
9472                    huff &= incr - 1;
9473                    huff += incr;
9474                } else {
9475                    huff = 0;
9476                }
9477
9478                /* go to next symbol, update count, len */
9479                sym++;
9480                if (--count[len] === 0) {
9481                    if (len === max) { break; }
9482                    len = lens[lens_index + work[sym]];
9483                }
9484
9485                /* create new sub-table if needed */
9486                if (len > root && (huff & mask) !== low) {
9487                    /* if first time, transition to sub-tables */
9488                    if (drop === 0) {
9489                        drop = root;
9490                    }
9491
9492                    /* increment past last table */
9493                    next += min;            /* here min is 1 << curr */
9494
9495                    /* determine length of next table */
9496                    curr = len - drop;
9497                    left = 1 << curr;
9498                    while (curr + drop < max) {
9499                        left -= count[curr + drop];
9500                        if (left <= 0) { break; }
9501                        curr++;
9502                        left <<= 1;
9503                    }
9504
9505                    /* check for enough space */
9506                    used += 1 << curr;
9507                    if ((type === LENS && used > ENOUGH_LENS) ||
9508                        (type === DISTS && used > ENOUGH_DISTS)) {
9509                        return 1;
9510                    }
9511
9512                    /* point entry in root table to sub-table */
9513                    low = huff & mask;
9514                    /*table.op[low] = curr;
9515      table.bits[low] = root;
9516      table.val[low] = next - opts.table_index;*/
9517                    table[low] = (root << 24) | (curr << 16) | (next - table_index) |0;
9518                }
9519            }
9520
9521            /* fill in remaining table entry if code is incomplete (guaranteed to have
9522   at most one remaining entry, since if the code is incomplete, the
9523   maximum code length that was allowed to get this far is one bit) */
9524            if (huff !== 0) {
9525                //table.op[next + huff] = 64;            /* invalid code marker */
9526                //table.bits[next + huff] = len - drop;
9527                //table.val[next + huff] = 0;
9528                table[next + huff] = ((len - drop) << 24) | (64 << 16) |0;
9529            }
9530
9531            /* set return parameters */
9532            //opts.table_index += used;
9533            opts.bits = root;
9534            return 0;
9535        };
9536
9537    },{"../utils/common":32}],42:[function(_dereq_,module,exports){
9538        'use strict';
9539
9540        module.exports = {
9541            2:      'need dictionary',     /* Z_NEED_DICT       2  */
9542            1:      'stream end',          /* Z_STREAM_END      1  */
9543            0:      '',                    /* Z_OK              0  */
9544            '-1':   'file error',          /* Z_ERRNO         (-1) */
9545            '-2':   'stream error',        /* Z_STREAM_ERROR  (-2) */
9546            '-3':   'data error',          /* Z_DATA_ERROR    (-3) */
9547            '-4':   'insufficient memory', /* Z_MEM_ERROR     (-4) */
9548            '-5':   'buffer error',        /* Z_BUF_ERROR     (-5) */
9549            '-6':   'incompatible version' /* Z_VERSION_ERROR (-6) */
9550        };
9551
9552    },{}],43:[function(_dereq_,module,exports){
9553        'use strict';
9554
9555
9556        var utils = _dereq_('../utils/common');
9557
9558        /* Public constants ==========================================================*/
9559        /* ===========================================================================*/
9560
9561
9562//var Z_FILTERED          = 1;
9563//var Z_HUFFMAN_ONLY      = 2;
9564//var Z_RLE               = 3;
9565        var Z_FIXED               = 4;
9566//var Z_DEFAULT_STRATEGY  = 0;
9567
9568        /* Possible values of the data_type field (though see inflate()) */
9569        var Z_BINARY              = 0;
9570        var Z_TEXT                = 1;
9571//var Z_ASCII             = 1; // = Z_TEXT
9572        var Z_UNKNOWN             = 2;
9573
9574        /*============================================================================*/
9575
9576
9577        function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
9578
9579// From zutil.h
9580
9581        var STORED_BLOCK = 0;
9582        var STATIC_TREES = 1;
9583        var DYN_TREES    = 2;
9584        /* The three kinds of block type */
9585
9586        var MIN_MATCH    = 3;
9587        var MAX_MATCH    = 258;
9588        /* The minimum and maximum match lengths */
9589
9590// From deflate.h
9591        /* ===========================================================================
9592 * Internal compression state.
9593 */
9594
9595        var LENGTH_CODES  = 29;
9596        /* number of length codes, not counting the special END_BLOCK code */
9597
9598        var LITERALS      = 256;
9599        /* number of literal bytes 0..255 */
9600
9601        var L_CODES       = LITERALS + 1 + LENGTH_CODES;
9602        /* number of Literal or Length codes, including the END_BLOCK code */
9603
9604        var D_CODES       = 30;
9605        /* number of distance codes */
9606
9607        var BL_CODES      = 19;
9608        /* number of codes used to transfer the bit lengths */
9609
9610        var HEAP_SIZE     = 2 * L_CODES + 1;
9611        /* maximum heap size */
9612
9613        var MAX_BITS      = 15;
9614        /* All codes must not exceed MAX_BITS bits */
9615
9616        var Buf_size      = 16;
9617        /* size of bit buffer in bi_buf */
9618
9619
9620        /* ===========================================================================
9621 * Constants
9622 */
9623
9624        var MAX_BL_BITS = 7;
9625        /* Bit length codes must not exceed MAX_BL_BITS bits */
9626
9627        var END_BLOCK   = 256;
9628        /* end of block literal code */
9629
9630        var REP_3_6     = 16;
9631        /* repeat previous bit length 3-6 times (2 bits of repeat count) */
9632
9633        var REPZ_3_10   = 17;
9634        /* repeat a zero length 3-10 times  (3 bits of repeat count) */
9635
9636        var REPZ_11_138 = 18;
9637        /* repeat a zero length 11-138 times  (7 bits of repeat count) */
9638
9639        /* eslint-disable comma-spacing,array-bracket-spacing */
9640        var extra_lbits =   /* extra bits for each length code */
9641            [0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0];
9642
9643        var extra_dbits =   /* extra bits for each distance code */
9644            [0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];
9645
9646        var extra_blbits =  /* extra bits for each bit length code */
9647            [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7];
9648
9649        var bl_order =
9650            [16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];
9651        /* eslint-enable comma-spacing,array-bracket-spacing */
9652
9653        /* The lengths of the bit length codes are sent in order of decreasing
9654 * probability, to avoid transmitting the lengths for unused bit length codes.
9655 */
9656
9657        /* ===========================================================================
9658 * Local data. These are initialized only once.
9659 */
9660
9661// We pre-fill arrays with 0 to avoid uninitialized gaps
9662
9663        var DIST_CODE_LEN = 512; /* see definition of array dist_code below */
9664
9665// !!!! Use flat array insdead of structure, Freq = i*2, Len = i*2+1
9666        var static_ltree  = new Array((L_CODES + 2) * 2);
9667        zero(static_ltree);
9668        /* The static literal tree. Since the bit lengths are imposed, there is no
9669 * need for the L_CODES extra codes used during heap construction. However
9670 * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
9671 * below).
9672 */
9673
9674        var static_dtree  = new Array(D_CODES * 2);
9675        zero(static_dtree);
9676        /* The static distance tree. (Actually a trivial tree since all codes use
9677 * 5 bits.)
9678 */
9679
9680        var _dist_code    = new Array(DIST_CODE_LEN);
9681        zero(_dist_code);
9682        /* Distance codes. The first 256 values correspond to the distances
9683 * 3 .. 258, the last 256 values correspond to the top 8 bits of
9684 * the 15 bit distances.
9685 */
9686
9687        var _length_code  = new Array(MAX_MATCH - MIN_MATCH + 1);
9688        zero(_length_code);
9689        /* length code for each normalized match length (0 == MIN_MATCH) */
9690
9691        var base_length   = new Array(LENGTH_CODES);
9692        zero(base_length);
9693        /* First normalized length for each code (0 = MIN_MATCH) */
9694
9695        var base_dist     = new Array(D_CODES);
9696        zero(base_dist);
9697        /* First normalized distance for each code (0 = distance of 1) */
9698
9699
9700        function StaticTreeDesc(static_tree, extra_bits, extra_base, elems, max_length) {
9701
9702            this.static_tree  = static_tree;  /* static tree or NULL */
9703            this.extra_bits   = extra_bits;   /* extra bits for each code or NULL */
9704            this.extra_base   = extra_base;   /* base index for extra_bits */
9705            this.elems        = elems;        /* max number of elements in the tree */
9706            this.max_length   = max_length;   /* max bit length for the codes */
9707
9708            // show if `static_tree` has data or dummy - needed for monomorphic objects
9709            this.has_stree    = static_tree && static_tree.length;
9710        }
9711
9712
9713        var static_l_desc;
9714        var static_d_desc;
9715        var static_bl_desc;
9716
9717
9718        function TreeDesc(dyn_tree, stat_desc) {
9719            this.dyn_tree = dyn_tree;     /* the dynamic tree */
9720            this.max_code = 0;            /* largest code with non zero frequency */
9721            this.stat_desc = stat_desc;   /* the corresponding static tree */
9722        }
9723
9724
9725
9726        function d_code(dist) {
9727            return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];
9728        }
9729
9730
9731        /* ===========================================================================
9732 * Output a short LSB first on the stream.
9733 * IN assertion: there is enough room in pendingBuf.
9734 */
9735        function put_short(s, w) {
9736//    put_byte(s, (uch)((w) & 0xff));
9737//    put_byte(s, (uch)((ush)(w) >> 8));
9738            s.pending_buf[s.pending++] = (w) & 0xff;
9739            s.pending_buf[s.pending++] = (w >>> 8) & 0xff;
9740        }
9741
9742
9743        /* ===========================================================================
9744 * Send a value on a given number of bits.
9745 * IN assertion: length <= 16 and value fits in length bits.
9746 */
9747        function send_bits(s, value, length) {
9748            if (s.bi_valid > (Buf_size - length)) {
9749                s.bi_buf |= (value << s.bi_valid) & 0xffff;
9750                put_short(s, s.bi_buf);
9751                s.bi_buf = value >> (Buf_size - s.bi_valid);
9752                s.bi_valid += length - Buf_size;
9753            } else {
9754                s.bi_buf |= (value << s.bi_valid) & 0xffff;
9755                s.bi_valid += length;
9756            }
9757        }
9758
9759
9760        function send_code(s, c, tree) {
9761            send_bits(s, tree[c * 2]/*.Code*/, tree[c * 2 + 1]/*.Len*/);
9762        }
9763
9764
9765        /* ===========================================================================
9766 * Reverse the first len bits of a code, using straightforward code (a faster
9767 * method would use a table)
9768 * IN assertion: 1 <= len <= 15
9769 */
9770        function bi_reverse(code, len) {
9771            var res = 0;
9772            do {
9773                res |= code & 1;
9774                code >>>= 1;
9775                res <<= 1;
9776            } while (--len > 0);
9777            return res >>> 1;
9778        }
9779
9780
9781        /* ===========================================================================
9782 * Flush the bit buffer, keeping at most 7 bits in it.
9783 */
9784        function bi_flush(s) {
9785            if (s.bi_valid === 16) {
9786                put_short(s, s.bi_buf);
9787                s.bi_buf = 0;
9788                s.bi_valid = 0;
9789
9790            } else if (s.bi_valid >= 8) {
9791                s.pending_buf[s.pending++] = s.bi_buf & 0xff;
9792                s.bi_buf >>= 8;
9793                s.bi_valid -= 8;
9794            }
9795        }
9796
9797
9798        /* ===========================================================================
9799 * Compute the optimal bit lengths for a tree and update the total bit length
9800 * for the current block.
9801 * IN assertion: the fields freq and dad are set, heap[heap_max] and
9802 *    above are the tree nodes sorted by increasing frequency.
9803 * OUT assertions: the field len is set to the optimal bit length, the
9804 *     array bl_count contains the frequencies for each bit length.
9805 *     The length opt_len is updated; static_len is also updated if stree is
9806 *     not null.
9807 */
9808        function gen_bitlen(s, desc)
9809//    deflate_state *s;
9810//    tree_desc *desc;    /* the tree descriptor */
9811        {
9812            var tree            = desc.dyn_tree;
9813            var max_code        = desc.max_code;
9814            var stree           = desc.stat_desc.static_tree;
9815            var has_stree       = desc.stat_desc.has_stree;
9816            var extra           = desc.stat_desc.extra_bits;
9817            var base            = desc.stat_desc.extra_base;
9818            var max_length      = desc.stat_desc.max_length;
9819            var h;              /* heap index */
9820            var n, m;           /* iterate over the tree elements */
9821            var bits;           /* bit length */
9822            var xbits;          /* extra bits */
9823            var f;              /* frequency */
9824            var overflow = 0;   /* number of elements with bit length too large */
9825
9826            for (bits = 0; bits <= MAX_BITS; bits++) {
9827                s.bl_count[bits] = 0;
9828            }
9829
9830            /* In a first pass, compute the optimal bit lengths (which may
9831   * overflow in the case of the bit length tree).
9832   */
9833            tree[s.heap[s.heap_max] * 2 + 1]/*.Len*/ = 0; /* root of the heap */
9834
9835            for (h = s.heap_max + 1; h < HEAP_SIZE; h++) {
9836                n = s.heap[h];
9837                bits = tree[tree[n * 2 + 1]/*.Dad*/ * 2 + 1]/*.Len*/ + 1;
9838                if (bits > max_length) {
9839                    bits = max_length;
9840                    overflow++;
9841                }
9842                tree[n * 2 + 1]/*.Len*/ = bits;
9843                /* We overwrite tree[n].Dad which is no longer needed */
9844
9845                if (n > max_code) { continue; } /* not a leaf node */
9846
9847                s.bl_count[bits]++;
9848                xbits = 0;
9849                if (n >= base) {
9850                    xbits = extra[n - base];
9851                }
9852                f = tree[n * 2]/*.Freq*/;
9853                s.opt_len += f * (bits + xbits);
9854                if (has_stree) {
9855                    s.static_len += f * (stree[n * 2 + 1]/*.Len*/ + xbits);
9856                }
9857            }
9858            if (overflow === 0) { return; }
9859
9860            // Trace((stderr,"\nbit length overflow\n"));
9861            /* This happens for example on obj2 and pic of the Calgary corpus */
9862
9863            /* Find the first bit length which could increase: */
9864            do {
9865                bits = max_length - 1;
9866                while (s.bl_count[bits] === 0) { bits--; }
9867                s.bl_count[bits]--;      /* move one leaf down the tree */
9868                s.bl_count[bits + 1] += 2; /* move one overflow item as its brother */
9869                s.bl_count[max_length]--;
9870                /* The brother of the overflow item also moves one step up,
9871     * but this does not affect bl_count[max_length]
9872     */
9873                overflow -= 2;
9874            } while (overflow > 0);
9875
9876            /* Now recompute all bit lengths, scanning in increasing frequency.
9877   * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
9878   * lengths instead of fixing only the wrong ones. This idea is taken
9879   * from 'ar' written by Haruhiko Okumura.)
9880   */
9881            for (bits = max_length; bits !== 0; bits--) {
9882                n = s.bl_count[bits];
9883                while (n !== 0) {
9884                    m = s.heap[--h];
9885                    if (m > max_code) { continue; }
9886                    if (tree[m * 2 + 1]/*.Len*/ !== bits) {
9887                        // Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
9888                        s.opt_len += (bits - tree[m * 2 + 1]/*.Len*/) * tree[m * 2]/*.Freq*/;
9889                        tree[m * 2 + 1]/*.Len*/ = bits;
9890                    }
9891                    n--;
9892                }
9893            }
9894        }
9895
9896
9897        /* ===========================================================================
9898 * Generate the codes for a given tree and bit counts (which need not be
9899 * optimal).
9900 * IN assertion: the array bl_count contains the bit length statistics for
9901 * the given tree and the field len is set for all tree elements.
9902 * OUT assertion: the field code is set for all tree elements of non
9903 *     zero code length.
9904 */
9905        function gen_codes(tree, max_code, bl_count)
9906//    ct_data *tree;             /* the tree to decorate */
9907//    int max_code;              /* largest code with non zero frequency */
9908//    ushf *bl_count;            /* number of codes at each bit length */
9909        {
9910            var next_code = new Array(MAX_BITS + 1); /* next code value for each bit length */
9911            var code = 0;              /* running code value */
9912            var bits;                  /* bit index */
9913            var n;                     /* code index */
9914
9915            /* The distribution counts are first used to generate the code values
9916   * without bit reversal.
9917   */
9918            for (bits = 1; bits <= MAX_BITS; bits++) {
9919                next_code[bits] = code = (code + bl_count[bits - 1]) << 1;
9920            }
9921            /* Check that the bit counts in bl_count are consistent. The last code
9922   * must be all ones.
9923   */
9924            //Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
9925            //        "inconsistent bit counts");
9926            //Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
9927
9928            for (n = 0;  n <= max_code; n++) {
9929                var len = tree[n * 2 + 1]/*.Len*/;
9930                if (len === 0) { continue; }
9931                /* Now reverse the bits */
9932                tree[n * 2]/*.Code*/ = bi_reverse(next_code[len]++, len);
9933
9934                //Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
9935                //     n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
9936            }
9937        }
9938
9939
9940        /* ===========================================================================
9941 * Initialize the various 'constant' tables.
9942 */
9943        function tr_static_init() {
9944            var n;        /* iterates over tree elements */
9945            var bits;     /* bit counter */
9946            var length;   /* length value */
9947            var code;     /* code value */
9948            var dist;     /* distance index */
9949            var bl_count = new Array(MAX_BITS + 1);
9950            /* number of codes at each bit length for an optimal tree */
9951
9952            // do check in _tr_init()
9953            //if (static_init_done) return;
9954
9955            /* For some embedded targets, global variables are not initialized: */
9956            /*#ifdef NO_INIT_GLOBAL_POINTERS
9957  static_l_desc.static_tree = static_ltree;
9958  static_l_desc.extra_bits = extra_lbits;
9959  static_d_desc.static_tree = static_dtree;
9960  static_d_desc.extra_bits = extra_dbits;
9961  static_bl_desc.extra_bits = extra_blbits;
9962#endif*/
9963
9964            /* Initialize the mapping length (0..255) -> length code (0..28) */
9965            length = 0;
9966            for (code = 0; code < LENGTH_CODES - 1; code++) {
9967                base_length[code] = length;
9968                for (n = 0; n < (1 << extra_lbits[code]); n++) {
9969                    _length_code[length++] = code;
9970                }
9971            }
9972            //Assert (length == 256, "tr_static_init: length != 256");
9973            /* Note that the length 255 (match length 258) can be represented
9974   * in two different ways: code 284 + 5 bits or code 285, so we
9975   * overwrite length_code[255] to use the best encoding:
9976   */
9977            _length_code[length - 1] = code;
9978
9979            /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
9980            dist = 0;
9981            for (code = 0;
vendor: 124,891 bytes, lines 9981-13104
9981 code < 16; code++) {
9982                base_dist[code] = dist;
9983                for (n = 0; n < (1 << extra_dbits[code]); n++) {
9984                    _dist_code[dist++] = code;
9985                }
9986            }
9987            //Assert (dist == 256, "tr_static_init: dist != 256");
9988            dist >>= 7; /* from now on, all distances are divided by 128 */
9989            for (; code < D_CODES; code++) {
9990                base_dist[code] = dist << 7;
9991                for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) {
9992                    _dist_code[256 + dist++] = code;
9993                }
9994            }
9995            //Assert (dist == 256, "tr_static_init: 256+dist != 512");
9996
9997            /* Construct the codes of the static literal tree */
9998            for (bits = 0; bits <= MAX_BITS; bits++) {
9999                bl_count[bits] = 0;
10000            }
10001
10002            n = 0;
10003            while (n <= 143) {
10004                static_ltree[n * 2 + 1]/*.Len*/ = 8;
10005                n++;
10006                bl_count[8]++;
10007            }
10008            while (n <= 255) {
10009                static_ltree[n * 2 + 1]/*.Len*/ = 9;
10010                n++;
10011                bl_count[9]++;
10012            }
10013            while (n <= 279) {
10014                static_ltree[n * 2 + 1]/*.Len*/ = 7;
10015                n++;
10016                bl_count[7]++;
10017            }
10018            while (n <= 287) {
10019                static_ltree[n * 2 + 1]/*.Len*/ = 8;
10020                n++;
10021                bl_count[8]++;
10022            }
10023            /* Codes 286 and 287 do not exist, but we must include them in the
10024   * tree construction to get a canonical Huffman tree (longest code
10025   * all ones)
10026   */
10027            gen_codes(static_ltree, L_CODES + 1, bl_count);
10028
10029            /* The static distance tree is trivial: */
10030            for (n = 0; n < D_CODES; n++) {
10031                static_dtree[n * 2 + 1]/*.Len*/ = 5;
10032                static_dtree[n * 2]/*.Code*/ = bi_reverse(n, 5);
10033            }
10034
10035            // Now data ready and we can init static trees
10036            static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS + 1, L_CODES, MAX_BITS);
10037            static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0,          D_CODES, MAX_BITS);
10038            static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0,         BL_CODES, MAX_BL_BITS);
10039
10040            //static_init_done = true;
10041        }
10042
10043
10044        /* ===========================================================================
10045 * Initialize a new block.
10046 */
10047        function init_block(s) {
10048            var n; /* iterates over tree elements */
10049
10050            /* Initialize the trees. */
10051            for (n = 0; n < L_CODES;  n++) { s.dyn_ltree[n * 2]/*.Freq*/ = 0; }
10052            for (n = 0; n < D_CODES;  n++) { s.dyn_dtree[n * 2]/*.Freq*/ = 0; }
10053            for (n = 0; n < BL_CODES; n++) { s.bl_tree[n * 2]/*.Freq*/ = 0; }
10054
10055            s.dyn_ltree[END_BLOCK * 2]/*.Freq*/ = 1;
10056            s.opt_len = s.static_len = 0;
10057            s.last_lit = s.matches = 0;
10058        }
10059
10060
10061        /* ===========================================================================
10062 * Flush the bit buffer and align the output on a byte boundary
10063 */
10064        function bi_windup(s)
10065        {
10066            if (s.bi_valid > 8) {
10067                put_short(s, s.bi_buf);
10068            } else if (s.bi_valid > 0) {
10069                //put_byte(s, (Byte)s->bi_buf);
10070                s.pending_buf[s.pending++] = s.bi_buf;
10071            }
10072            s.bi_buf = 0;
10073            s.bi_valid = 0;
10074        }
10075
10076        /* ===========================================================================
10077 * Copy a stored block, storing first the length and its
10078 * one's complement if requested.
10079 */
10080        function copy_block(s, buf, len, header)
10081//DeflateState *s;
10082//charf    *buf;    /* the input data */
10083//unsigned len;     /* its length */
10084//int      header;  /* true if block header must be written */
10085        {
10086            bi_windup(s);        /* align on byte boundary */
10087
10088            if (header) {
10089                put_short(s, len);
10090                put_short(s, ~len);
10091            }
10092//  while (len--) {
10093//    put_byte(s, *buf++);
10094//  }
10095            utils.arraySet(s.pending_buf, s.window, buf, len, s.pending);
10096            s.pending += len;
10097        }
10098
10099        /* ===========================================================================
10100 * Compares to subtrees, using the tree depth as tie breaker when
10101 * the subtrees have equal frequency. This minimizes the worst case length.
10102 */
10103        function smaller(tree, n, m, depth) {
10104            var _n2 = n * 2;
10105            var _m2 = m * 2;
10106            return (tree[_n2]/*.Freq*/ < tree[_m2]/*.Freq*/ ||
10107                (tree[_n2]/*.Freq*/ === tree[_m2]/*.Freq*/ && depth[n] <= depth[m]));
10108        }
10109
10110        /* ===========================================================================
10111 * Restore the heap property by moving down the tree starting at node k,
10112 * exchanging a node with the smallest of its two sons if necessary, stopping
10113 * when the heap property is re-established (each father smaller than its
10114 * two sons).
10115 */
10116        function pqdownheap(s, tree, k)
10117//    deflate_state *s;
10118//    ct_data *tree;  /* the tree to restore */
10119//    int k;               /* node to move down */
10120        {
10121            var v = s.heap[k];
10122            var j = k << 1;  /* left son of k */
10123            while (j <= s.heap_len) {
10124                /* Set j to the smallest of the two sons: */
10125                if (j < s.heap_len &&
10126                    smaller(tree, s.heap[j + 1], s.heap[j], s.depth)) {
10127                    j++;
10128                }
10129                /* Exit if v is smaller than both sons */
10130                if (smaller(tree, v, s.heap[j], s.depth)) { break; }
10131
10132                /* Exchange v with the smallest son */
10133                s.heap[k] = s.heap[j];
10134                k = j;
10135
10136                /* And continue down the tree, setting j to the left son of k */
10137                j <<= 1;
10138            }
10139            s.heap[k] = v;
10140        }
10141
10142
10143// inlined manually
10144// var SMALLEST = 1;
10145
10146        /* ===========================================================================
10147 * Send the block data compressed using the given Huffman trees
10148 */
10149        function compress_block(s, ltree, dtree)
10150//    deflate_state *s;
10151//    const ct_data *ltree; /* literal tree */
10152//    const ct_data *dtree; /* distance tree */
10153        {
10154            var dist;           /* distance of matched string */
10155            var lc;             /* match length or unmatched char (if dist == 0) */
10156            var lx = 0;         /* running index in l_buf */
10157            var code;           /* the code to send */
10158            var extra;          /* number of extra bits to send */
10159
10160            if (s.last_lit !== 0) {
10161                do {
10162                    dist = (s.pending_buf[s.d_buf + lx * 2] << 8) | (s.pending_buf[s.d_buf + lx * 2 + 1]);
10163                    lc = s.pending_buf[s.l_buf + lx];
10164                    lx++;
10165
10166                    if (dist === 0) {
10167                        send_code(s, lc, ltree); /* send a literal byte */
10168                        //Tracecv(isgraph(lc), (stderr," '%c' ", lc));
10169                    } else {
10170                        /* Here, lc is the match length - MIN_MATCH */
10171                        code = _length_code[lc];
10172                        send_code(s, code + LITERALS + 1, ltree); /* send the length code */
10173                        extra = extra_lbits[code];
10174                        if (extra !== 0) {
10175                            lc -= base_length[code];
10176                            send_bits(s, lc, extra);       /* send the extra length bits */
10177                        }
10178                        dist--; /* dist is now the match distance - 1 */
10179                        code = d_code(dist);
10180                        //Assert (code < D_CODES, "bad d_code");
10181
10182                        send_code(s, code, dtree);       /* send the distance code */
10183                        extra = extra_dbits[code];
10184                        if (extra !== 0) {
10185                            dist -= base_dist[code];
10186                            send_bits(s, dist, extra);   /* send the extra distance bits */
10187                        }
10188                    } /* literal or match pair ? */
10189
10190                    /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
10191                    //Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
10192                    //       "pendingBuf overflow");
10193
10194                } while (lx < s.last_lit);
10195            }
10196
10197            send_code(s, END_BLOCK, ltree);
10198        }
10199
10200
10201        /* ===========================================================================
10202 * Construct one Huffman tree and assigns the code bit strings and lengths.
10203 * Update the total bit length for the current block.
10204 * IN assertion: the field freq is set for all tree elements.
10205 * OUT assertions: the fields len and code are set to the optimal bit length
10206 *     and corresponding code. The length opt_len is updated; static_len is
10207 *     also updated if stree is not null. The field max_code is set.
10208 */
10209        function build_tree(s, desc)
10210//    deflate_state *s;
10211//    tree_desc *desc; /* the tree descriptor */
10212        {
10213            var tree     = desc.dyn_tree;
10214            var stree    = desc.stat_desc.static_tree;
10215            var has_stree = desc.stat_desc.has_stree;
10216            var elems    = desc.stat_desc.elems;
10217            var n, m;          /* iterate over heap elements */
10218            var max_code = -1; /* largest code with non zero frequency */
10219            var node;          /* new node being created */
10220
10221            /* Construct the initial heap, with least frequent element in
10222   * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
10223   * heap[0] is not used.
10224   */
10225            s.heap_len = 0;
10226            s.heap_max = HEAP_SIZE;
10227
10228            for (n = 0; n < elems; n++) {
10229                if (tree[n * 2]/*.Freq*/ !== 0) {
10230                    s.heap[++s.heap_len] = max_code = n;
10231                    s.depth[n] = 0;
10232
10233                } else {
10234                    tree[n * 2 + 1]/*.Len*/ = 0;
10235                }
10236            }
10237
10238            /* The pkzip format requires that at least one distance code exists,
10239   * and that at least one bit should be sent even if there is only one
10240   * possible code. So to avoid special checks later on we force at least
10241   * two codes of non zero frequency.
10242   */
10243            while (s.heap_len < 2) {
10244                node = s.heap[++s.heap_len] = (max_code < 2 ? ++max_code : 0);
10245                tree[node * 2]/*.Freq*/ = 1;
10246                s.depth[node] = 0;
10247                s.opt_len--;
10248
10249                if (has_stree) {
10250                    s.static_len -= stree[node * 2 + 1]/*.Len*/;
10251                }
10252                /* node is 0 or 1 so it does not have extra bits */
10253            }
10254            desc.max_code = max_code;
10255
10256            /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
10257   * establish sub-heaps of increasing lengths:
10258   */
10259            for (n = (s.heap_len >> 1/*int /2*/); n >= 1; n--) { pqdownheap(s, tree, n); }
10260
10261            /* Construct the Huffman tree by repeatedly combining the least two
10262   * frequent nodes.
10263   */
10264            node = elems;              /* next internal node of the tree */
10265            do {
10266                //pqremove(s, tree, n);  /* n = node of least frequency */
10267                /*** pqremove ***/
10268                n = s.heap[1/*SMALLEST*/];
10269                s.heap[1/*SMALLEST*/] = s.heap[s.heap_len--];
10270                pqdownheap(s, tree, 1/*SMALLEST*/);
10271                /***/
10272
10273                m = s.heap[1/*SMALLEST*/]; /* m = node of next least frequency */
10274
10275                s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */
10276                s.heap[--s.heap_max] = m;
10277
10278                /* Create a new node father of n and m */
10279                tree[node * 2]/*.Freq*/ = tree[n * 2]/*.Freq*/ + tree[m * 2]/*.Freq*/;
10280                s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;
10281                tree[n * 2 + 1]/*.Dad*/ = tree[m * 2 + 1]/*.Dad*/ = node;
10282
10283                /* and insert the new node in the heap */
10284                s.heap[1/*SMALLEST*/] = node++;
10285                pqdownheap(s, tree, 1/*SMALLEST*/);
10286
10287            } while (s.heap_len >= 2);
10288
10289            s.heap[--s.heap_max] = s.heap[1/*SMALLEST*/];
10290
10291            /* At this point, the fields freq and dad are set. We can now
10292   * generate the bit lengths.
10293   */
10294            gen_bitlen(s, desc);
10295
10296            /* The field len is now set, we can generate the bit codes */
10297            gen_codes(tree, max_code, s.bl_count);
10298        }
10299
10300
10301        /* ===========================================================================
10302 * Scan a literal or distance tree to determine the frequencies of the codes
10303 * in the bit length tree.
10304 */
10305        function scan_tree(s, tree, max_code)
10306//    deflate_state *s;
10307//    ct_data *tree;   /* the tree to be scanned */
10308//    int max_code;    /* and its largest code of non zero frequency */
10309        {
10310            var n;                     /* iterates over all tree elements */
10311            var prevlen = -1;          /* last emitted length */
10312            var curlen;                /* length of current code */
10313
10314            var nextlen = tree[0 * 2 + 1]/*.Len*/; /* length of next code */
10315
10316            var count = 0;             /* repeat count of the current code */
10317            var max_count = 7;         /* max repeat count */
10318            var min_count = 4;         /* min repeat count */
10319
10320            if (nextlen === 0) {
10321                max_count = 138;
10322                min_count = 3;
10323            }
10324            tree[(max_code + 1) * 2 + 1]/*.Len*/ = 0xffff; /* guard */
10325
10326            for (n = 0; n <= max_code; n++) {
10327                curlen = nextlen;
10328                nextlen = tree[(n + 1) * 2 + 1]/*.Len*/;
10329
10330                if (++count < max_count && curlen === nextlen) {
10331                    continue;
10332
10333                } else if (count < min_count) {
10334                    s.bl_tree[curlen * 2]/*.Freq*/ += count;
10335
10336                } else if (curlen !== 0) {
10337
10338                    if (curlen !== prevlen) { s.bl_tree[curlen * 2]/*.Freq*/++; }
10339                    s.bl_tree[REP_3_6 * 2]/*.Freq*/++;
10340
10341                } else if (count <= 10) {
10342                    s.bl_tree[REPZ_3_10 * 2]/*.Freq*/++;
10343
10344                } else {
10345                    s.bl_tree[REPZ_11_138 * 2]/*.Freq*/++;
10346                }
10347
10348                count = 0;
10349                prevlen = curlen;
10350
10351                if (nextlen === 0) {
10352                    max_count = 138;
10353                    min_count = 3;
10354
10355                } else if (curlen === nextlen) {
10356                    max_count = 6;
10357                    min_count = 3;
10358
10359                } else {
10360                    max_count = 7;
10361                    min_count = 4;
10362                }
10363            }
10364        }
10365
10366
10367        /* ===========================================================================
10368 * Send a literal or distance tree in compressed form, using the codes in
10369 * bl_tree.
10370 */
10371        function send_tree(s, tree, max_code)
10372//    deflate_state *s;
10373//    ct_data *tree; /* the tree to be scanned */
10374//    int max_code;       /* and its largest code of non zero frequency */
10375        {
10376            var n;                     /* iterates over all tree elements */
10377            var prevlen = -1;          /* last emitted length */
10378            var curlen;                /* length of current code */
10379
10380            var nextlen = tree[0 * 2 + 1]/*.Len*/; /* length of next code */
10381
10382            var count = 0;             /* repeat count of the current code */
10383            var max_count = 7;         /* max repeat count */
10384            var min_count = 4;         /* min repeat count */
10385
10386            /* tree[max_code+1].Len = -1; */  /* guard already set */
10387            if (nextlen === 0) {
10388                max_count = 138;
10389                min_count = 3;
10390            }
10391
10392            for (n = 0; n <= max_code; n++) {
10393                curlen = nextlen;
10394                nextlen = tree[(n + 1) * 2 + 1]/*.Len*/;
10395
10396                if (++count < max_count && curlen === nextlen) {
10397                    continue;
10398
10399                } else if (count < min_count) {
10400                    do { send_code(s, curlen, s.bl_tree); } while (--count !== 0);
10401
10402                } else if (curlen !== 0) {
10403                    if (curlen !== prevlen) {
10404                        send_code(s, curlen, s.bl_tree);
10405                        count--;
10406                    }
10407                    //Assert(count >= 3 && count <= 6, " 3_6?");
10408                    send_code(s, REP_3_6, s.bl_tree);
10409                    send_bits(s, count - 3, 2);
10410
10411                } else if (count <= 10) {
10412                    send_code(s, REPZ_3_10, s.bl_tree);
10413                    send_bits(s, count - 3, 3);
10414
10415                } else {
10416                    send_code(s, REPZ_11_138, s.bl_tree);
10417                    send_bits(s, count - 11, 7);
10418                }
10419
10420                count = 0;
10421                prevlen = curlen;
10422                if (nextlen === 0) {
10423                    max_count = 138;
10424                    min_count = 3;
10425
10426                } else if (curlen === nextlen) {
10427                    max_count = 6;
10428                    min_count = 3;
10429
10430                } else {
10431                    max_count = 7;
10432                    min_count = 4;
10433                }
10434            }
10435        }
10436
10437
10438        /* ===========================================================================
10439 * Construct the Huffman tree for the bit lengths and return the index in
10440 * bl_order of the last bit length code to send.
10441 */
10442        function build_bl_tree(s) {
10443            var max_blindex;  /* index of last bit length code of non zero freq */
10444
10445            /* Determine the bit length frequencies for literal and distance trees */
10446            scan_tree(s, s.dyn_ltree, s.l_desc.max_code);
10447            scan_tree(s, s.dyn_dtree, s.d_desc.max_code);
10448
10449            /* Build the bit length tree: */
10450            build_tree(s, s.bl_desc);
10451            /* opt_len now includes the length of the tree representations, except
10452   * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
10453   */
10454
10455            /* Determine the number of bit length codes to send. The pkzip format
10456   * requires that at least 4 bit length codes be sent. (appnote.txt says
10457   * 3 but the actual value used is 4.)
10458   */
10459            for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {
10460                if (s.bl_tree[bl_order[max_blindex] * 2 + 1]/*.Len*/ !== 0) {
10461                    break;
10462                }
10463            }
10464            /* Update opt_len to include the bit length tree and counts */
10465            s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
10466            //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
10467            //        s->opt_len, s->static_len));
10468
10469            return max_blindex;
10470        }
10471
10472
10473        /* ===========================================================================
10474 * Send the header for a block using dynamic Huffman trees: the counts, the
10475 * lengths of the bit length codes, the literal tree and the distance tree.
10476 * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
10477 */
10478        function send_all_trees(s, lcodes, dcodes, blcodes)
10479//    deflate_state *s;
10480//    int lcodes, dcodes, blcodes; /* number of codes for each tree */
10481        {
10482            var rank;                    /* index in bl_order */
10483
10484            //Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
10485            //Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
10486            //        "too many codes");
10487            //Tracev((stderr, "\nbl counts: "));
10488            send_bits(s, lcodes - 257, 5); /* not +255 as stated in appnote.txt */
10489            send_bits(s, dcodes - 1,   5);
10490            send_bits(s, blcodes - 4,  4); /* not -3 as stated in appnote.txt */
10491            for (rank = 0; rank < blcodes; rank++) {
10492                //Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
10493                send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1]/*.Len*/, 3);
10494            }
10495            //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
10496
10497            send_tree(s, s.dyn_ltree, lcodes - 1); /* literal tree */
10498            //Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
10499
10500            send_tree(s, s.dyn_dtree, dcodes - 1); /* distance tree */
10501            //Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
10502        }
10503
10504
10505        /* ===========================================================================
10506 * Check if the data type is TEXT or BINARY, using the following algorithm:
10507 * - TEXT if the two conditions below are satisfied:
10508 *    a) There are no non-portable control characters belonging to the
10509 *       "black list" (0..6, 14..25, 28..31).
10510 *    b) There is at least one printable character belonging to the
10511 *       "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
10512 * - BINARY otherwise.
10513 * - The following partially-portable control characters form a
10514 *   "gray list" that is ignored in this detection algorithm:
10515 *   (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
10516 * IN assertion: the fields Freq of dyn_ltree are set.
10517 */
10518        function detect_data_type(s) {
10519            /* black_mask is the bit mask of black-listed bytes
10520   * set bits 0..6, 14..25, and 28..31
10521   * 0xf3ffc07f = binary 11110011111111111100000001111111
10522   */
10523            var black_mask = 0xf3ffc07f;
10524            var n;
10525
10526            /* Check for non-textual ("black-listed") bytes. */
10527            for (n = 0; n <= 31; n++, black_mask >>>= 1) {
10528                if ((black_mask & 1) && (s.dyn_ltree[n * 2]/*.Freq*/ !== 0)) {
10529                    return Z_BINARY;
10530                }
10531            }
10532
10533            /* Check for textual ("white-listed") bytes. */
10534            if (s.dyn_ltree[9 * 2]/*.Freq*/ !== 0 || s.dyn_ltree[10 * 2]/*.Freq*/ !== 0 ||
10535                s.dyn_ltree[13 * 2]/*.Freq*/ !== 0) {
10536                return Z_TEXT;
10537            }
10538            for (n = 32; n < LITERALS; n++) {
10539                if (s.dyn_ltree[n * 2]/*.Freq*/ !== 0) {
10540                    return Z_TEXT;
10541                }
10542            }
10543
10544            /* There are no "black-listed" or "white-listed" bytes:
10545   * this stream either is empty or has tolerated ("gray-listed") bytes only.
10546   */
10547            return Z_BINARY;
10548        }
10549
10550
10551        var static_init_done = false;
10552
10553        /* ===========================================================================
10554 * Initialize the tree data structures for a new zlib stream.
10555 */
10556        function _tr_init(s)
10557        {
10558
10559            if (!static_init_done) {
10560                tr_static_init();
10561                static_init_done = true;
10562            }
10563
10564            s.l_desc  = new TreeDesc(s.dyn_ltree, static_l_desc);
10565            s.d_desc  = new TreeDesc(s.dyn_dtree, static_d_desc);
10566            s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc);
10567
10568            s.bi_buf = 0;
10569            s.bi_valid = 0;
10570
10571            /* Initialize the first block of the first file: */
10572            init_block(s);
10573        }
10574
10575
10576        /* ===========================================================================
10577 * Send a stored block
10578 */
10579        function _tr_stored_block(s, buf, stored_len, last)
10580//DeflateState *s;
10581//charf *buf;       /* input block */
10582//ulg stored_len;   /* length of input block */
10583//int last;         /* one if this is the last block for a file */
10584        {
10585            send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3);    /* send block type */
10586            copy_block(s, buf, stored_len, true); /* with header */
10587        }
10588
10589
10590        /* ===========================================================================
10591 * Send one empty static block to give enough lookahead for inflate.
10592 * This takes 10 bits, of which 7 may remain in the bit buffer.
10593 */
10594        function _tr_align(s) {
10595            send_bits(s, STATIC_TREES << 1, 3);
10596            send_code(s, END_BLOCK, static_ltree);
10597            bi_flush(s);
10598        }
10599
10600
10601        /* ===========================================================================
10602 * Determine the best encoding for the current block: dynamic trees, static
10603 * trees or store, and output the encoded block to the zip file.
10604 */
10605        function _tr_flush_block(s, buf, stored_len, last)
10606//DeflateState *s;
10607//charf *buf;       /* input block, or NULL if too old */
10608//ulg stored_len;   /* length of input block */
10609//int last;         /* one if this is the last block for a file */
10610        {
10611            var opt_lenb, static_lenb;  /* opt_len and static_len in bytes */
10612            var max_blindex = 0;        /* index of last bit length code of non zero freq */
10613
10614            /* Build the Huffman trees unless a stored block is forced */
10615            if (s.level > 0) {
10616
10617                /* Check if the file is binary or text */
10618                if (s.strm.data_type === Z_UNKNOWN) {
10619                    s.strm.data_type = detect_data_type(s);
10620                }
10621
10622                /* Construct the literal and distance trees */
10623                build_tree(s, s.l_desc);
10624                // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
10625                //        s->static_len));
10626
10627                build_tree(s, s.d_desc);
10628                // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
10629                //        s->static_len));
10630                /* At this point, opt_len and static_len are the total bit lengths of
10631     * the compressed block data, excluding the tree representations.
10632     */
10633
10634                /* Build the bit length tree for the above two trees, and get the index
10635     * in bl_order of the last bit length code to send.
10636     */
10637                max_blindex = build_bl_tree(s);
10638
10639                /* Determine the best encoding. Compute the block lengths in bytes. */
10640                opt_lenb = (s.opt_len + 3 + 7) >>> 3;
10641                static_lenb = (s.static_len + 3 + 7) >>> 3;
10642
10643                // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
10644                //        opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
10645                //        s->last_lit));
10646
10647                if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }
10648
10649            } else {
10650                // Assert(buf != (char*)0, "lost buf");
10651                opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
10652            }
10653
10654            if ((stored_len + 4 <= opt_lenb) && (buf !== -1)) {
10655                /* 4: two words for the lengths */
10656
10657                /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
10658     * Otherwise we can't have processed more than WSIZE input bytes since
10659     * the last block flush, because compression would have been
10660     * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
10661     * transform a block into a stored block.
10662     */
10663                _tr_stored_block(s, buf, stored_len, last);
10664
10665            } else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) {
10666
10667                send_bits(s, (STATIC_TREES << 1) + (last ? 1 : 0), 3);
10668                compress_block(s, static_ltree, static_dtree);
10669
10670            } else {
10671                send_bits(s, (DYN_TREES << 1) + (last ? 1 : 0), 3);
10672                send_all_trees(s, s.l_desc.max_code + 1, s.d_desc.max_code + 1, max_blindex + 1);
10673                compress_block(s, s.dyn_ltree, s.dyn_dtree);
10674            }
10675            // Assert (s->compressed_len == s->bits_sent, "bad compressed size");
10676            /* The above check is made mod 2^32, for files larger than 512 MB
10677   * and uLong implemented on 32 bits.
10678   */
10679            init_block(s);
10680
10681            if (last) {
10682                bi_windup(s);
10683            }
10684            // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
10685            //       s->compressed_len-7*last));
10686        }
10687
10688        /* ===========================================================================
10689 * Save the match info and tally the frequency counts. Return true if
10690 * the current block must be flushed.
10691 */
10692        function _tr_tally(s, dist, lc)
10693//    deflate_state *s;
10694//    unsigned dist;  /* distance of matched string */
10695//    unsigned lc;    /* match length-MIN_MATCH or unmatched char (if dist==0) */
10696        {
10697            //var out_length, in_length, dcode;
10698
10699            s.pending_buf[s.d_buf + s.last_lit * 2]     = (dist >>> 8) & 0xff;
10700            s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff;
10701
10702            s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff;
10703            s.last_lit++;
10704
10705            if (dist === 0) {
10706                /* lc is the unmatched char */
10707                s.dyn_ltree[lc * 2]/*.Freq*/++;
10708            } else {
10709                s.matches++;
10710                /* Here, lc is the match length - MIN_MATCH */
10711                dist--;             /* dist = match distance - 1 */
10712                //Assert((ush)dist < (ush)MAX_DIST(s) &&
10713                //       (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
10714                //       (ush)d_code(dist) < (ush)D_CODES,  "_tr_tally: bad match");
10715
10716                s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2]/*.Freq*/++;
10717                s.dyn_dtree[d_code(dist) * 2]/*.Freq*/++;
10718            }
10719
10720// (!) This block is disabled in zlib defailts,
10721// don't enable it for binary compatibility
10722
10723//#ifdef TRUNCATE_BLOCK
10724//  /* Try to guess if it is profitable to stop the current block here */
10725//  if ((s.last_lit & 0x1fff) === 0 && s.level > 2) {
10726//    /* Compute an upper bound for the compressed length */
10727//    out_length = s.last_lit*8;
10728//    in_length = s.strstart - s.block_start;
10729//
10730//    for (dcode = 0; dcode < D_CODES; dcode++) {
10731//      out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]);
10732//    }
10733//    out_length >>>= 3;
10734//    //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
10735//    //       s->last_lit, in_length, out_length,
10736//    //       100L - out_length*100L/in_length));
10737//    if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) {
10738//      return true;
10739//    }
10740//  }
10741//#endif
10742
10743            return (s.last_lit === s.lit_bufsize - 1);
10744            /* We avoid equality with lit_bufsize because of wraparound at 64K
10745   * on 16 bit machines and because stored blocks are restricted to
10746   * 64K-1 bytes.
10747   */
10748        }
10749
10750        exports._tr_init  = _tr_init;
10751        exports._tr_stored_block = _tr_stored_block;
10752        exports._tr_flush_block  = _tr_flush_block;
10753        exports._tr_tally = _tr_tally;
10754        exports._tr_align = _tr_align;
10755
10756    },{"../utils/common":32}],44:[function(_dereq_,module,exports){
10757        'use strict';
10758
10759
10760        function ZStream() {
10761            /* next input byte */
10762            this.input = null; // JS specific, because we have no pointers
10763            this.next_in = 0;
10764            /* number of bytes available at input */
10765            this.avail_in = 0;
10766            /* total number of input bytes read so far */
10767            this.total_in = 0;
10768            /* next output byte should be put there */
10769            this.output = null; // JS specific, because we have no pointers
10770            this.next_out = 0;
10771            /* remaining free space at output */
10772            this.avail_out = 0;
10773            /* total number of bytes output so far */
10774            this.total_out = 0;
10775            /* last error message, NULL if no error */
10776            this.msg = ''/*Z_NULL*/;
10777            /* not visible by applications */
10778            this.state = null;
10779            /* best guess about the data type: binary or text */
10780            this.data_type = 2/*Z_UNKNOWN*/;
10781            /* adler32 value of the uncompressed data */
10782            this.adler = 0;
10783        }
10784
10785        module.exports = ZStream;
10786
10787    },{}],45:[function(_dereq_,module,exports){
10788        /**
10789         * lodash 3.2.0 (Custom Build) <https://lodash.com/>
10790         * Build: `lodash modularize exports="npm" -o ./`
10791         * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
10792         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
10793         * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
10794         * Available under MIT license <https://lodash.com/license>
10795         */
10796        var root = _dereq_('lodash._root');
10797
10798        /** Used as references for various `Number` constants. */
10799        var INFINITY = 1 / 0;
10800
10801        /** `Object#toString` result references. */
10802        var symbolTag = '[object Symbol]';
10803
10804        /** Used to match HTML entities and HTML characters. */
10805        var reUnescapedHtml = /[&<>"'`]/g,
10806            reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
10807
10808        /** Used to map characters to HTML entities. */
10809        var htmlEscapes = {
10810            '&': '&amp;',
10811            '<': '&lt;',
10812            '>': '&gt;',
10813            '"': '&quot;',
10814            "'": '&#39;',
10815            '`': '&#96;'
10816        };
10817
10818        /**
10819         * Used by `_.escape` to convert characters to HTML entities.
10820         *
10821         * @private
10822         * @param {string} chr The matched character to escape.
10823         * @returns {string} Returns the escaped character.
10824         */
10825        function escapeHtmlChar(chr) {
10826            return htmlEscapes[chr];
10827        }
10828
10829        /** Used for built-in method references. */
10830        var objectProto = Object.prototype;
10831
10832        /**
10833         * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
10834         * of values.
10835         */
10836        var objectToString = objectProto.toString;
10837
10838        /** Built-in value references. */
10839        var Symbol = root.Symbol;
10840
10841        /** Used to convert symbols to primitives and strings. */
10842        var symbolProto = Symbol ? Symbol.prototype : undefined,
10843            symbolToString = Symbol ? symbolProto.toString : undefined;
10844
10845        /**
10846         * Checks if `value` is object-like. A value is object-like if it's not `null`
10847         * and has a `typeof` result of "object".
10848         *
10849         * @static
10850         * @memberOf _
10851         * @category Lang
10852         * @param {*} value The value to check.
10853         * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
10854         * @example
10855         *
10856         * _.isObjectLike({});
10857         * // => true
10858         *
10859         * _.isObjectLike([1, 2, 3]);
10860         * // => true
10861         *
10862         * _.isObjectLike(_.noop);
10863         * // => false
10864         *
10865         * _.isObjectLike(null);
10866         * // => false
10867         */
10868        function isObjectLike(value) {
10869            return !!value && typeof value == 'object';
10870        }
10871
10872        /**
10873         * Checks if `value` is classified as a `Symbol` primitive or object.
10874         *
10875         * @static
10876         * @memberOf _
10877         * @category Lang
10878         * @param {*} value The value to check.
10879         * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
10880         * @example
10881         *
10882         * _.isSymbol(Symbol.iterator);
10883         * // => true
10884         *
10885         * _.isSymbol('abc');
10886         * // => false
10887         */
10888        function isSymbol(value) {
10889            return typeof value == 'symbol' ||
10890                (isObjectLike(value) && objectToString.call(value) == symbolTag);
10891        }
10892
10893        /**
10894         * Converts `value` to a string if it's not one. An empty string is returned
10895         * for `null` and `undefined` values. The sign of `-0` is preserved.
10896         *
10897         * @static
10898         * @memberOf _
10899         * @category Lang
10900         * @param {*} value The value to process.
10901         * @returns {string} Returns the string.
10902         * @example
10903         *
10904         * _.toString(null);
10905         * // => ''
10906         *
10907         * _.toString(-0);
10908         * // => '-0'
10909         *
10910         * _.toString([1, 2, 3]);
10911         * // => '1,2,3'
10912         */
10913        function toString(value) {
10914            // Exit early for strings to avoid a performance hit in some environments.
10915            if (typeof value == 'string') {
10916                return value;
10917            }
10918            if (value == null) {
10919                return '';
10920            }
10921            if (isSymbol(value)) {
10922                return Symbol ? symbolToString.call(value) : '';
10923            }
10924            var result = (value + '');
10925            return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
10926        }
10927
10928        /**
10929         * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
10930         * their corresponding HTML entities.
10931         *
10932         * **Note:** No other characters are escaped. To escape additional
10933         * characters use a third-party library like [_he_](https://mths.be/he).
10934         *
10935         * Though the ">" character is escaped for symmetry, characters like
10936         * ">" and "/" don't need escaping in HTML and have no special meaning
10937         * unless they're part of a tag or unquoted attribute value.
10938         * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
10939         * (under "semi-related fun fact") for more details.
10940         *
10941         * Backticks are escaped because in IE < 9, they can break out of
10942         * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
10943         * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
10944         * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
10945         * for more details.
10946         *
10947         * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
10948         * to reduce XSS vectors.
10949         *
10950         * @static
10951         * @memberOf _
10952         * @category String
10953         * @param {string} [string=''] The string to escape.
10954         * @returns {string} Returns the escaped string.
10955         * @example
10956         *
10957         * _.escape('fred, barney, & pebbles');
10958         * // => 'fred, barney, &amp; pebbles'
10959         */
10960        function escape(string) {
10961            string = toString(string);
10962            return (string && reHasUnescapedHtml.test(string))
10963                ? string.replace(reUnescapedHtml, escapeHtmlChar)
10964                : string;
10965        }
10966
10967        module.exports = escape;
10968
10969    },{"lodash._root":46}],46:[function(_dereq_,module,exports){
10970        (function (global){
10971            /**
10972             * lodash 3.0.1 (Custom Build) <https://lodash.com/>
10973             * Build: `lodash modularize exports="npm" -o ./`
10974             * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
10975             * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
10976             * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
10977             * Available under MIT license <https://lodash.com/license>
10978             */
10979
10980            /** Used to determine if values are of the language type `Object`. */
10981            var objectTypes = {
10982                'function': true,
10983                'object': true
10984            };
10985
10986            /** Detect free variable `exports`. */
10987            var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType)
10988                ? exports
10989                : undefined;
10990
10991            /** Detect free variable `module`. */
10992            var freeModule = (objectTypes[typeof module] && module && !module.nodeType)
10993                ? module
10994                : undefined;
10995
10996            /** Detect free variable `global` from Node.js. */
10997            var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
10998
10999            /** Detect free variable `self`. */
11000            var freeSelf = checkGlobal(objectTypes[typeof self] && self);
11001
11002            /** Detect free variable `window`. */
11003            var freeWindow = checkGlobal(objectTypes[typeof window] && window);
11004
11005            /** Detect `this` as the global object. */
11006            var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
11007
11008            /**
11009             * Used as a reference to the global object.
11010             *
11011             * The `this` value is used if it's the global object to avoid Greasemonkey's
11012             * restricted `window` object, otherwise the `window` object is used.
11013             */
11014            var root = freeGlobal ||
11015                ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) ||
11016                freeSelf || thisGlobal || Function('return this')();
11017
11018            /**
11019             * Checks if `value` is a global object.
11020             *
11021             * @private
11022             * @param {*} value The value to check.
11023             * @returns {null|Object} Returns `value` if it's a global object, else `null`.
11024             */
11025            function checkGlobal(value) {
11026                return (value && value.Object === Object) ? value : null;
11027            }
11028
11029            module.exports = root;
11030
11031        }).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
11032    },{}],47:[function(_dereq_,module,exports){
11033        /**
11034         * lodash 3.3.2 (Custom Build) <https://lodash.com/>
11035         * Build: `lodash modern modularize exports="npm" -o ./`
11036         * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
11037         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
11038         * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
11039         * Available under MIT license <https://lodash.com/license>
11040         */
11041        var arrayCopy = _dereq_('lodash._arraycopy'),
11042            arrayEach = _dereq_('lodash._arrayeach'),
11043            createAssigner = _dereq_('lodash._createassigner'),
11044            isArguments = _dereq_('lodash.isarguments'),
11045            isArray = _dereq_('lodash.isarray'),
11046            isPlainObject = _dereq_('lodash.isplainobject'),
11047            isTypedArray = _dereq_('lodash.istypedarray'),
11048            keys = _dereq_('lodash.keys'),
11049            toPlainObject = _dereq_('lodash.toplainobject');
11050
11051        /**
11052         * Checks if `value` is object-like.
11053         *
11054         * @private
11055         * @param {*} value The value to check.
11056         * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
11057         */
11058        function isObjectLike(value) {
11059            return !!value && typeof value == 'object';
11060        }
11061
11062        /**
11063         * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
11064         * of an array-like value.
11065         */
11066        var MAX_SAFE_INTEGER = 9007199254740991;
11067
11068        /**
11069         * The base implementation of `_.merge` without support for argument juggling,
11070         * multiple sources, and `this` binding `customizer` functions.
11071         *
11072         * @private
11073         * @param {Object} object The destination object.
11074         * @param {Object} source The source object.
11075         * @param {Function} [customizer] The function to customize merged values.
11076         * @param {Array} [stackA=[]] Tracks traversed source objects.
11077         * @param {Array} [stackB=[]] Associates values with source counterparts.
11078         * @returns {Object} Returns `object`.
11079         */
11080        function baseMerge(object, source, customizer, stackA, stackB) {
11081            if (!isObject(object)) {
11082                return object;
11083            }
11084            var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
11085                props = isSrcArr ? undefined : keys(source);
11086
11087            arrayEach(props || source, function(srcValue, key) {
11088                if (props) {
11089                    key = srcValue;
11090                    srcValue = source[key];
11091                }
11092                if (isObjectLike(srcValue)) {
11093                    stackA || (stackA = []);
11094                    stackB || (stackB = []);
11095                    baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
11096                }
11097                else {
11098                    var value = object[key],
11099                        result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
11100                        isCommon = result === undefined;
11101
11102                    if (isCommon) {
11103                        result = srcValue;
11104                    }
11105                    if ((result !== undefined || (isSrcArr && !(key in object))) &&
11106                        (isCommon || (result === result ? (result !== value) : (value === value)))) {
11107                        object[key] = result;
11108                    }
11109                }
11110            });
11111            return object;
11112        }
11113
11114        /**
11115         * A specialized version of `baseMerge` for arrays and objects which performs
11116         * deep merges and tracks traversed objects enabling objects with circular
11117         * references to be merged.
11118         *
11119         * @private
11120         * @param {Object} object The destination object.
11121         * @param {Object} source The source object.
11122         * @param {string} key The key of the value to merge.
11123         * @param {Function} mergeFunc The function to merge values.
11124         * @param {Function} [customizer] The function to customize merged values.
11125         * @param {Array} [stackA=[]] Tracks traversed source objects.
11126         * @param {Array} [stackB=[]] Associates values with source counterparts.
11127         * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
11128         */
11129        function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
11130            var length = stackA.length,
11131                srcValue = source[key];
11132
11133            while (length--) {
11134                if (stackA[length] == srcValue) {
11135                    object[key] = stackB[length];
11136                    return;
11137                }
11138            }
11139            var value = object[key],
11140                result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
11141                isCommon = result === undefined;
11142
11143            if (isCommon) {
11144                result = srcValue;
11145                if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
11146                    result = isArray(value)
11147                        ? value
11148                        : (isArrayLike(value) ? arrayCopy(value) : []);
11149                }
11150                else if (isPlainObject(srcValue) || isArguments(srcValue)) {
11151                    result = isArguments(value)
11152                        ? toPlainObject(value)
11153                        : (isPlainObject(value) ? value : {});
11154                }
11155                else {
11156                    isCommon = false;
11157                }
11158            }
11159            // Add the source value to the stack of traversed objects and associate
11160            // it with its merged value.
11161            stackA.push(srcValue);
11162            stackB.push(result);
11163
11164            if (isCommon) {
11165                // Recursively merge objects and arrays (susceptible to call stack limits).
11166                object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
11167            } else if (result === result ? (result !== value) : (value === value)) {
11168                object[key] = result;
11169            }
11170        }
11171
11172        /**
11173         * The base implementation of `_.property` without support for deep paths.
11174         *
11175         * @private
11176         * @param {string} key The key of the property to get.
11177         * @returns {Function} Returns the new function.
11178         */
11179        function baseProperty(key) {
11180            return function(object) {
11181                return object == null ? undefined : object[key];
11182            };
11183        }
11184
11185        /**
11186         * Gets the "length" property value of `object`.
11187         *
11188         * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
11189         * that affects Safari on at least iOS 8.1-8.3 ARM64.
11190         *
11191         * @private
11192         * @param {Object} object The object to query.
11193         * @returns {*} Returns the "length" value.
11194         */
11195        var getLength = baseProperty('length');
11196
11197        /**
11198         * Checks if `value` is array-like.
11199         *
11200         * @private
11201         * @param {*} value The value to check.
11202         * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
11203         */
11204        function isArrayLike(value) {
11205            return value != null && isLength(getLength(value));
11206        }
11207
11208        /**
11209         * Checks if `value` is a valid array-like length.
11210         *
11211         * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
11212         *
11213         * @private
11214         * @param {*} value The value to check.
11215         * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
11216         */
11217        function isLength(value) {
11218            return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
11219        }
11220
11221        /**
11222         * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
11223         * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
11224         *
11225         * @static
11226         * @memberOf _
11227         * @category Lang
11228         * @param {*} value The value to check.
11229         * @returns {boolean} Returns `true` if `value` is an object, else `false`.
11230         * @example
11231         *
11232         * _.isObject({});
11233         * // => true
11234         *
11235         * _.isObject([1, 2, 3]);
11236         * // => true
11237         *
11238         * _.isObject(1);
11239         * // => false
11240         */
11241        function isObject(value) {
11242            // Avoid a V8 JIT bug in Chrome 19-20.
11243            // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
11244            var type = typeof value;
11245            return !!value && (type == 'object' || type == 'function');
11246        }
11247
11248        /**
11249         * Recursively merges own enumerable properties of the source object(s), that
11250         * don't resolve to `undefined` into the destination object. Subsequent sources
11251         * overwrite property assignments of previous sources. If `customizer` is
11252         * provided it is invoked to produce the merged values of the destination and
11253         * source properties. If `customizer` returns `undefined` merging is handled
11254         * by the method instead. The `customizer` is bound to `thisArg` and invoked
11255         * with five arguments: (objectValue, sourceValue, key, object, source).
11256         *
11257         * @static
11258         * @memberOf _
11259         * @category Object
11260         * @param {Object} object The destination object.
11261         * @param {...Object} [sources] The source objects.
11262         * @param {Function} [customizer] The function to customize assigned values.
11263         * @param {*} [thisArg] The `this` binding of `customizer`.
11264         * @returns {Object} Returns `object`.
11265         * @example
11266         *
11267         * var users = {
11268         *   'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
11269         * };
11270         *
11271         * var ages = {
11272         *   'data': [{ 'age': 36 }, { 'age': 40 }]
11273         * };
11274         *
11275         * _.merge(users, ages);
11276         * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
11277         *
11278         * // using a customizer callback
11279         * var object = {
11280         *   'fruits': ['apple'],
11281         *   'vegetables': ['beet']
11282         * };
11283         *
11284         * var other = {
11285         *   'fruits': ['banana'],
11286         *   'vegetables': ['carrot']
11287         * };
11288         *
11289         * _.merge(object, other, function(a, b) {
11290         *   if (_.isArray(a)) {
11291         *     return a.concat(b);
11292         *   }
11293         * });
11294         * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
11295         */
11296        var merge = createAssigner(baseMerge);
11297
11298        module.exports = merge;
11299
11300    },{"lodash._arraycopy":48,"lodash._arrayeach":49,"lodash._createassigner":50,"lodash.isarguments":55,"lodash.isarray":56,"lodash.isplainobject":57,"lodash.istypedarray":59,"lodash.keys":60,"lodash.toplainobject":62}],48:[function(_dereq_,module,exports){
11301        /**
11302         * lodash 3.0.0 (Custom Build) <https://lodash.com/>
11303         * Build: `lodash modern modularize exports="npm" -o ./`
11304         * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
11305         * Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
11306         * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
11307         * Available under MIT license <https://lodash.com/license>
11308         */
11309
11310        /**
11311         * Copies the values of `source` to `array`.
11312         *
11313         * @private
11314         * @param {Array} source The array to copy values from.
11315         * @param {Array} [array=[]] The array to copy values to.
11316         * @returns {Array} Returns `array`.
11317         */
11318        function arrayCopy(source, array) {
11319            var index = -1,
11320                length = source.length;
11321
11322            array || (array = Array(length));
11323            while (++index < length) {
11324                array[index] = source[index];
11325            }
11326            return array;
11327        }
11328
11329        module.exports = arrayCopy;
11330
11331    },{}],49:[function(_dereq_,module,exports){
11332        /**
11333         * lodash 3.0.0 (Custom Build) <https://lodash.com/>
11334         * Build: `lodash modern modularize exports="npm" -o ./`
11335         * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
11336         * Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
11337         * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
11338         * Available under MIT license <https://lodash.com/license>
11339         */
11340
11341        /**
11342         * A specialized version of `_.forEach` for arrays without support for callback
11343         * shorthands or `this` binding.
11344         *
11345         * @private
11346         * @param {Array} array The array to iterate over.
11347         * @param {Function} iteratee The function invoked per iteration.
11348         * @returns {Array} Returns `array`.
11349         */
11350        function arrayEach(array, iteratee) {
11351            var index = -1,
11352                length = array.length;
11353
11354            while (++index < length) {
11355                if (iteratee(array[index], index, array) === false) {
11356                    break;
11357                }
11358            }
11359            return array;
11360        }
11361
11362        module.exports = arrayEach;
11363
11364    },{}],50:[function(_dereq_,module,exports){
11365        /**
11366         * lodash 3.1.1 (Custom Build) <https://lodash.com/>
11367         * Build: `lodash modern modularize exports="npm" -o ./`
11368         * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
11369         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
11370         * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
11371         * Available under MIT license <https://lodash.com/license>
11372         */
11373        var bindCallback = _dereq_('lodash._bindcallback'),
11374            isIterateeCall = _dereq_('lodash._isiterateecall'),
11375            restParam = _dereq_('lodash.restparam');
11376
11377        /**
11378         * Creates a function that assigns properties of source object(s) to a given
11379         * destination object.
11380         *
11381         * **Note:** This function is used to create `_.assign`, `_.defaults`, and `_.merge`.
11382         *
11383         * @private
11384         * @param {Function} assigner The function to assign values.
11385         * @returns {Function} Returns the new assigner function.
11386         */
11387        function createAssigner(assigner) {
11388            return restParam(function(object, sources) {
11389                var index = -1,
11390                    length = object == null ? 0 : sources.length,
11391                    customizer = length > 2 ? sources[length - 2] : undefined,
11392                    guard = length > 2 ? sources[2] : undefined,
11393                    thisArg = length > 1 ? sources[length - 1] : undefined;
11394
11395                if (typeof customizer == 'function') {
11396                    customizer = bindCallback(customizer, thisArg, 5);
11397                    length -= 2;
11398                } else {
11399                    customizer = typeof thisArg == 'function' ? thisArg : undefined;
11400                    length -= (customizer ? 1 : 0);
11401                }
11402                if (guard && isIterateeCall(sources[0], sources[1], guard)) {
11403                    customizer = length < 3 ? undefined : customizer;
11404                    length = 1;
11405                }
11406                while (++index < length) {
11407                    var source = sources[index];
11408                    if (source) {
11409                        assigner(object, source, customizer);
11410                    }
11411                }
11412                return object;
11413            });
11414        }
11415
11416        module.exports = createAssigner;
11417
11418    },{"lodash._bindcallback":51,"lodash._isiterateecall":52,"lodash.restparam":53}],51:[function(_dereq_,module,exports){
11419        /**
11420         * lodash 3.0.1 (Custom Build) <https://lodash.com/>
11421         * Build: `lodash modern modularize exports="npm" -o ./`
11422         * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
11423         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
11424         * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
11425         * Available under MIT license <https://lodash.com/license>
11426         */
11427
11428        /**
11429         * A specialized version of `baseCallback` which only supports `this` binding
11430         * and specifying the number of arguments to provide to `func`.
11431         *
11432         * @private
11433         * @param {Function} func The function to bind.
11434         * @param {*} thisArg The `this` binding of `func`.
11435         * @param {number} [argCount] The number of arguments to provide to `func`.
11436         * @returns {Function} Returns the callback.
11437         */
11438        function bindCallback(func, thisArg, argCount) {
11439            if (typeof func != 'function') {
11440                return identity;
11441            }
11442            if (thisArg === undefined) {
11443                return func;
11444            }
11445            switch (argCount) {
11446                case 1: return function(value) {
11447                    return func.call(thisArg, value);
11448                };
11449                case 3: return function(value, index, collection) {
11450                    return func.call(thisArg, value, index, collection);
11451                };
11452                case 4: return function(accumulator, value, index, collection) {
11453                    return func.call(thisArg, accumulator, value, index, collection);
11454                };
11455                case 5: return function(value, other, key, object, source) {
11456                    return func.call(thisArg, value, other, key, object, source);
11457                };
11458            }
11459            return function() {
11460                return func.apply(thisArg, arguments);
11461            };
11462        }
11463
11464        /**
11465         * This method returns the first argument provided to it.
11466         *
11467         * @static
11468         * @memberOf _
11469         * @category Utility
11470         * @param {*} value Any value.
11471         * @returns {*} Returns `value`.
11472         * @example
11473         *
11474         * var object = { 'user': 'fred' };
11475         *
11476         * _.identity(object) === object;
11477         * // => true
11478         */
11479        function identity(value) {
11480            return value;
11481        }
11482
11483        module.exports = bindCallback;
11484
11485    },{}],52:[function(_dereq_,module,exports){
11486        /**
11487         * lodash 3.0.9 (Custom Build) <https://lodash.com/>
11488         * Build: `lodash modern modularize exports="npm" -o ./`
11489         * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
11490         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
11491         * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
11492         * Available under MIT license <https://lodash.com/license>
11493         */
11494
11495        /** Used to detect unsigned integer values. */
11496        var reIsUint = /^\d+$/;
11497
11498        /**
11499         * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
11500         * of an array-like value.
11501         */
11502        var MAX_SAFE_INTEGER = 9007199254740991;
11503
11504        /**
11505         * The base implementation of `_.property` without support for deep paths.
11506         *
11507         * @private
11508         * @param {string} key The key of the property to get.
11509         * @returns {Function} Returns the new function.
11510         */
11511        function baseProperty(key) {
11512            return function(object) {
11513                return object == null ? undefined : object[key];
11514            };
11515        }
11516
11517        /**
11518         * Gets the "length" property value of `object`.
11519         *
11520         * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
11521         * that affects Safari on at least iOS 8.1-8.3 ARM64.
11522         *
11523         * @private
11524         * @param {Object} object The object to query.
11525         * @returns {*} Returns the "length" value.
11526         */
11527        var getLength = baseProperty('length');
11528
11529        /**
11530         * Checks if `value` is array-like.
11531         *
11532         * @private
11533         * @param {*} value The value to check.
11534         * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
11535         */
11536        function isArrayLike(value) {
11537            return value != null && isLength(getLength(value));
11538        }
11539
11540        /**
11541         * Checks if `value` is a valid array-like index.
11542         *
11543         * @private
11544         * @param {*} value The value to check.
11545         * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
11546         * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
11547         */
11548        function isIndex(value, length) {
11549            value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
11550            length = length == null ? MAX_SAFE_INTEGER : length;
11551            return value > -1 && value % 1 == 0 && value < length;
11552        }
11553
11554        /**
11555         * Checks if the provided arguments are from an iteratee call.
11556         *
11557         * @private
11558         * @param {*} value The potential iteratee value argument.
11559         * @param {*} index The potential iteratee index or key argument.
11560         * @param {*} object The potential iteratee object argument.
11561         * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
11562         */
11563        function isIterateeCall(value, index, object) {
11564            if (!isObject(object)) {
11565                return false;
11566            }
11567            var type = typeof index;
11568            if (type == 'number'
11569                ? (isArrayLike(object) && isIndex(index, object.length))
11570                : (type == 'string' && index in object)) {
11571                var other = object[index];
11572                return value === value ? (value === other) : (other !== other);
11573            }
11574            return false;
11575        }
11576
11577        /**
11578         * Checks if `value` is a valid array-like length.
11579         *
11580         * **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
11581         *
11582         * @private
11583         * @param {*} value The value to check.
11584         * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
11585         */
11586        function isLength(value) {
11587            return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
11588        }
11589
11590        /**
11591         * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
11592         * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
11593         *
11594         * @static
11595         * @memberOf _
11596         * @category Lang
11597         * @param {*} value The value to check.
11598         * @returns {boolean} Returns `true` if `value` is an object, else `false`.
11599         * @example
11600         *
11601         * _.isObject({});
11602         * // => true
11603         *
11604         * _.isObject([1, 2, 3]);
11605         * // => true
11606         *
11607         * _.isObject(1);
11608         * // => false
11609         */
11610        function isObject(value) {
11611            // Avoid a V8 JIT bug in Chrome 19-20.
11612            // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
11613            var type = typeof value;
11614            return !!value && (type == 'object' || type == 'function');
11615        }
11616
11617        module.exports = isIterateeCall;
11618
11619    },{}],53:[function(_dereq_,module,exports){
11620        /**
11621         * lodash 3.6.1 (Custom Build) <https://lodash.com/>
11622         * Build: `lodash modern modularize exports="npm" -o ./`
11623         * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
11624         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
11625         * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
11626         * Available under MIT license <https://lodash.com/license>
11627         */
11628
11629        /** Used as the `TypeError` message for "Functions" methods. */
11630        var FUNC_ERROR_TEXT = 'Expected a function';
11631
11632        /* Native method references for those with the same name as other `lodash` methods. */
11633        var nativeMax = Math.max;
11634
11635        /**
11636         * Creates a function that invokes `func` with the `this` binding of the
11637         * created function and arguments from `start` and beyond provided as an array.
11638         *
11639         * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
11640         *
11641         * @static
11642         * @memberOf _
11643         * @category Function
11644         * @param {Function} func The function to apply a rest parameter to.
11645         * @param {number} [start=func.length-1] The start position of the rest parameter.
11646         * @returns {Function} Returns the new function.
11647         * @example
11648         *
11649         * var say = _.restParam(function(what, names) {
11650         *   return what + ' ' + _.initial(names).join(', ') +
11651         *     (_.size(names) > 1 ? ', & ' : '') + _.last(names);
11652         * });
11653         *
11654         * say('hello', 'fred', 'barney', 'pebbles');
11655         * // => 'hello fred, barney, & pebbles'
11656         */
11657        function restParam(func, start) {
11658            if (typeof func != 'function') {
11659                throw new TypeError(FUNC_ERROR_TEXT);
11660            }
11661            start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
11662            return function() {
11663                var args = arguments,
11664                    index = -1,
11665                    length = nativeMax(args.length - start, 0),
11666                    rest = Array(length);
11667
11668                while (++index < length) {
11669                    rest[index] = args[start + index];
11670                }
11671                switch (start) {
11672                    case 0: return func.call(this, rest);
11673                    case 1: return func.call(this, args[0], rest);
11674                    case 2: return func.call(this, args[0], args[1], rest);
11675                }
11676                var otherArgs = Array(start + 1);
11677                index = -1;
11678                while (++index < start) {
11679                    otherArgs[index] = args[index];
11680                }
11681                otherArgs[start] = rest;
11682                return func.apply(this, otherArgs);
11683            };
11684        }
11685
11686        module.exports = restParam;
11687
11688    },{}],54:[function(_dereq_,module,exports){
11689        /**
11690         * lodash 3.9.1 (Custom Build) <https://lodash.com/>
11691         * Build: `lodash modern modularize exports="npm" -o ./`
11692         * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
11693         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
11694         * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
11695         * Available under MIT license <https://lodash.com/license>
11696         */
11697
11698        /** `Object#toString` result references. */
11699        var funcTag = '[object Function]';
11700
11701        /** Used to detect host constructors (Safari > 5). */
11702        var reIsHostCtor = /^\[object .+?Constructor\]$/;
11703
11704        /**
11705         * Checks if `value` is object-like.
11706         *
11707         * @private
11708         * @param {*} value The value to check.
11709         * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
11710         */
11711        function isObjectLike(value) {
11712            return !!value && typeof value == 'object';
11713        }
11714
11715        /** Used for native method references. */
11716        var objectProto = Object.prototype;
11717
11718        /** Used to resolve the decompiled source of functions. */
11719        var fnToString = Function.prototype.toString;
11720
11721        /** Used to check objects for own properties. */
11722        var hasOwnProperty = objectProto.hasOwnProperty;
11723
11724        /**
11725         * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
11726         * of values.
11727         */
11728        var objToString = objectProto.toString;
11729
11730        /** Used to detect if a method is native. */
11731        var reIsNative = RegExp('^' +
11732            fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
11733                .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
11734        );
11735
11736        /**
11737         * Gets the native function at `key` of `object`.
11738         *
11739         * @private
11740         * @param {Object} object The object to query.
11741         * @param {string} key The key of the method to get.
11742         * @returns {*} Returns the function if it's native, else `undefined`.
11743         */
11744        function getNative(object, key) {
11745            var value = object == null ? undefined : object[key];
11746            return isNative(value) ? value : undefined;
11747        }
11748
11749        /**
11750         * Checks if `value` is classified as a `Function` object.
11751         *
11752         * @static
11753         * @memberOf _
11754         * @category Lang
11755         * @param {*} value The value to check.
11756         * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
11757         * @example
11758         *
11759         * _.isFunction(_);
11760         * // => true
11761         *
11762         * _.isFunction(/abc/);
11763         * // => false
11764         */
11765        function isFunction(value) {
11766            // The use of `Object#toString` avoids issues with the `typeof` operator
11767            // in older versions of Chrome and Safari which return 'function' for regexes
11768            // and Safari 8 equivalents which return 'object' for typed array constructors.
11769            return isObject(value) && objToString.call(value) == funcTag;
11770        }
11771
11772        /**
11773         * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
11774         * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
11775         *
11776         * @static
11777         * @memberOf _
11778         * @category Lang
11779         * @param {*} value The value to check.
11780         * @returns {boolean} Returns `true` if `value` is an object, else `false`.
11781         * @example
11782         *
11783         * _.isObject({});
11784         * // => true
11785         *
11786         * _.isObject([1, 2, 3]);
11787         * // => true
11788         *
11789         * _.isObject(1);
11790         * // => false
11791         */
11792        function isObject(value) {
11793            // Avoid a V8 JIT bug in Chrome 19-20.
11794            // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
11795            var type = typeof value;
11796            return !!value && (type == 'object' || type == 'function');
11797        }
11798
11799        /**
11800         * Checks if `value` is a native function.
11801         *
11802         * @static
11803         * @memberOf _
11804         * @category Lang
11805         * @param {*} value The value to check.
11806         * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
11807         * @example
11808         *
11809         * _.isNative(Array.prototype.push);
11810         * // => true
11811         *
11812         * _.isNative(_);
11813         * // => false
11814         */
11815        function isNative(value) {
11816            if (value == null) {
11817                return false;
11818            }
11819            if (isFunction(value)) {
11820                return reIsNative.test(fnToString.call(value));
11821            }
11822            return isObjectLike(value) && reIsHostCtor.test(value);
11823        }
11824
11825        module.exports = getNative;
11826
11827    },{}],55:[function(_dereq_,module,exports){
11828        /**
11829         * lodash 3.0.8 (Custom Build) <https://lodash.com/>
11830         * Build: `lodash modularize exports="npm" -o ./`
11831         * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
11832         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
11833         * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
11834         * Available under MIT license <https://lodash.com/license>
11835         */
11836
11837        /** Used as references for various `Number` constants. */
11838        var MAX_SAFE_INTEGER = 9007199254740991;
11839
11840        /** `Object#toString` result references. */
11841        var argsTag = '[object Arguments]',
11842            funcTag = '[object Function]',
11843            genTag = '[object GeneratorFunction]';
11844
11845        /** Used for built-in method references. */
11846        var objectProto = Object.prototype;
11847
11848        /** Used to check objects for own properties. */
11849        var hasOwnProperty = objectProto.hasOwnProperty;
11850
11851        /**
11852         * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
11853         * of values.
11854         */
11855        var objectToString = objectProto.toString;
11856
11857        /** Built-in value references. */
11858        var propertyIsEnumerable = objectProto.propertyIsEnumerable;
11859
11860        /**
11861         * The base implementation of `_.property` without support for deep paths.
11862         *
11863         * @private
11864         * @param {string} key The key of the property to get.
11865         * @returns {Function} Returns the new function.
11866         */
11867        function baseProperty(key) {
11868            return function(object) {
11869                return object == null ? undefined : object[key];
11870            };
11871        }
11872
11873        /**
11874         * Gets the "length" property value of `object`.
11875         *
11876         * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
11877         * that affects Safari on at least iOS 8.1-8.3 ARM64.
11878         *
11879         * @private
11880         * @param {Object} object The object to query.
11881         * @returns {*} Returns the "length" value.
11882         */
11883        var getLength = baseProperty('length');
11884
11885        /**
11886         * Checks if `value` is likely an `arguments` object.
11887         *
11888         * @static
11889         * @memberOf _
11890         * @category Lang
11891         * @param {*} value The value to check.
11892         * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
11893         * @example
11894         *
11895         * _.isArguments(function() { return arguments; }());
11896         * // => true
11897         *
11898         * _.isArguments([1, 2, 3]);
11899         * // => false
11900         */
11901        function isArguments(value) {
11902            // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
11903            return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
11904                (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
11905        }
11906
11907        /**
11908         * Checks if `value` is array-like. A value is considered array-like if it's
11909         * not a function and has a `value.length` that's an integer greater than or
11910         * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
11911         *
11912         * @static
11913         * @memberOf _
11914         * @category Lang
11915         * @param {*} value The value to check.
11916         * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
11917         * @example
11918         *
11919         * _.isArrayLike([1, 2, 3]);
11920         * // => true
11921         *
11922         * _.isArrayLike(document.body.children);
11923         * // => true
11924         *
11925         * _.isArrayLike('abc');
11926         * // => true
11927         *
11928         * _.isArrayLike(_.noop);
11929         * // => false
11930         */
11931        function isArrayLike(value) {
11932            return value != null && isLength(getLength(value)) && !isFunction(value);
11933        }
11934
11935        /**
11936         * This method is like `_.isArrayLike` except that it also checks if `value`
11937         * is an object.
11938         *
11939         * @static
11940         * @memberOf _
11941         * @category Lang
11942         * @param {*} value The value to check.
11943         * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
11944         * @example
11945         *
11946         * _.isArrayLikeObject([1, 2, 3]);
11947         * // => true
11948         *
11949         * _.isArrayLikeObject(document.body.children);
11950         * // => true
11951         *
11952         * _.isArrayLikeObject('abc');
11953         * // => false
11954         *
11955         * _.isArrayLikeObject(_.noop);
11956         * // => false
11957         */
11958        function isArrayLikeObject(value) {
11959            return isObjectLike(value) && isArrayLike(value);
11960        }
11961
11962        /**
11963         * Checks if `value` is classified as a `Function` object.
11964         *
11965         * @static
11966         * @memberOf _
11967         * @category Lang
11968         * @param {*} value The value to check.
11969         * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
11970         * @example
11971         *
11972         * _.isFunction(_);
11973         * // => true
11974         *
11975         * _.isFunction(/abc/);
11976         * // => false
11977         */
11978        function isFunction(value) {
11979            // The use of `Object#toString` avoids issues with the `typeof` operator
11980            // in Safari 8 which returns 'object' for typed array and weak map constructors,
11981            // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
11982            var tag = isObject(value) ? objectToString.call(value) : '';
11983            return tag == funcTag || tag == genTag;
11984        }
11985
11986        /**
11987         * Checks if `value` is a valid array-like length.
11988         *
11989         * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
11990         *
11991         * @static
11992         * @memberOf _
11993         * @category Lang
11994         * @param {*} value The value to check.
11995         * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
11996         * @example
11997         *
11998         * _.isLength(3);
11999         * // => true
12000         *
12001         * _.isLength(Number.MIN_VALUE);
12002         * // => false
12003         *
12004         * _.isLength(Infinity);
12005         * // => false
12006         *
12007         * _.isLength('3');
12008         * // => false
12009         */
12010        function isLength(value) {
12011            return typeof value == 'number' &&
12012                value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
12013        }
12014
12015        /**
12016         * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
12017         * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
12018         *
12019         * @static
12020         * @memberOf _
12021         * @category Lang
12022         * @param {*} value The value to check.
12023         * @returns {boolean} Returns `true` if `value` is an object, else `false`.
12024         * @example
12025         *
12026         * _.isObject({});
12027         * // => true
12028         *
12029         * _.isObject([1, 2, 3]);
12030         * // => true
12031         *
12032         * _.isObject(_.noop);
12033         * // => true
12034         *
12035         * _.isObject(null);
12036         * // => false
12037         */
12038        function isObject(value) {
12039            var type = typeof value;
12040            return !!value && (type == 'object' || type == 'function');
12041        }
12042
12043        /**
12044         * Checks if `value` is object-like. A value is object-like if it's not `null`
12045         * and has a `typeof` result of "object".
12046         *
12047         * @static
12048         * @memberOf _
12049         * @category Lang
12050         * @param {*} value The value to check.
12051         * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
12052         * @example
12053         *
12054         * _.isObjectLike({});
12055         * // => true
12056         *
12057         * _.isObjectLike([1, 2, 3]);
12058         * // => true
12059         *
12060         * _.isObjectLike(_.noop);
12061         * // => false
12062         *
12063         * _.isObjectLike(null);
12064         * // => false
12065         */
12066        function isObjectLike(value) {
12067            return !!value && typeof value == 'object';
12068        }
12069
12070        module.exports = isArguments;
12071
12072    },{}],56:[function(_dereq_,module,exports){
12073        /**
12074         * lodash 3.0.4 (Custom Build) <https://lodash.com/>
12075         * Build: `lodash modern modularize exports="npm" -o ./`
12076         * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
12077         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
12078         * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
12079         * Available under MIT license <https://lodash.com/license>
12080         */
12081
12082        /** `Object#toString` result references. */
12083        var arrayTag = '[object Array]',
12084            funcTag = '[object Function]';
12085
12086        /** Used to detect host constructors (Safari > 5). */
12087        var reIsHostCtor = /^\[object .+?Constructor\]$/;
12088
12089        /**
12090         * Checks if `value` is object-like.
12091         *
12092         * @private
12093         * @param {*} value The value to check.
12094         * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
12095         */
12096        function isObjectLike(value) {
12097            return !!value && typeof value == 'object';
12098        }
12099
12100        /** Used for native method references. */
12101        var objectProto = Object.prototype;
12102
12103        /** Used to resolve the decompiled source of functions. */
12104        var fnToString = Function.prototype.toString;
12105
12106        /** Used to check objects for own properties. */
12107        var hasOwnProperty = objectProto.hasOwnProperty;
12108
12109        /**
12110         * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
12111         * of values.
12112         */
12113        var objToString = objectProto.toString;
12114
12115        /** Used to detect if a method is native. */
12116        var reIsNative = RegExp('^' +
12117            fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
12118                .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
12119        );
12120
12121        /* Native method references for those with the same name as other `lodash` methods. */
12122        var nativeIsArray = getNative(Array, 'isArray');
12123
12124        /**
12125         * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
12126         * of an array-like value.
12127         */
12128        var MAX_SAFE_INTEGER = 9007199254740991;
12129
12130        /**
12131         * Gets the native function at `key` of `object`.
12132         *
12133         * @private
12134         * @param {Object} object The object to query.
12135         * @param {string} key The key of the method to get.
12136         * @returns {*} Returns the function if it's native, else `undefined`.
12137         */
12138        function getNative(object, key) {
12139            var value = object == null ? undefined : object[key];
12140            return isNative(value) ? value : undefined;
12141        }
12142
12143        /**
12144         * Checks if `value` is a valid array-like length.
12145         *
12146         * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
12147         *
12148         * @private
12149         * @param {*} value The value to check.
12150         * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
12151         */
12152        function isLength(value) {
12153            return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
12154        }
12155
12156        /**
12157         * Checks if `value` is classified as an `Array` object.
12158         *
12159         * @static
12160         * @memberOf _
12161         * @category Lang
12162         * @param {*} value The value to check.
12163         * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
12164         * @example
12165         *
12166         * _.isArray([1, 2, 3]);
12167         * // => true
12168         *
12169         * _.isArray(function() { return arguments; }());
12170         * // => false
12171         */
12172        var isArray = nativeIsArray || function(value) {
12173            return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
12174        };
12175
12176        /**
12177         * Checks if `value` is classified as a `Function` object.
12178         *
12179         * @static
12180         * @memberOf _
12181         * @category Lang
12182         * @param {*} value The value to check.
12183         * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
12184         * @example
12185         *
12186         * _.isFunction(_);
12187         * // => true
12188         *
12189         * _.isFunction(/abc/);
12190         * // => false
12191         */
12192        function isFunction(value) {
12193            // The use of `Object#toString` avoids issues with the `typeof` operator
12194            // in older versions of Chrome and Safari which return 'function' for regexes
12195            // and Safari 8 equivalents which return 'object' for typed array constructors.
12196            return isObject(value) && objToString.call(value) == funcTag;
12197        }
12198
12199        /**
12200         * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
12201         * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
12202         *
12203         * @static
12204         * @memberOf _
12205         * @category Lang
12206         * @param {*} value The value to check.
12207         * @returns {boolean} Returns `true` if `value` is an object, else `false`.
12208         * @example
12209         *
12210         * _.isObject({});
12211         * // => true
12212         *
12213         * _.isObject([1, 2, 3]);
12214         * // => true
12215         *
12216         * _.isObject(1);
12217         * // => false
12218         */
12219        function isObject(value) {
12220            // Avoid a V8 JIT bug in Chrome 19-20.
12221            // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
12222            var type = typeof value;
12223            return !!value && (type == 'object' || type == 'function');
12224        }
12225
12226        /**
12227         * Checks if `value` is a native function.
12228         *
12229         * @static
12230         * @memberOf _
12231         * @category Lang
12232         * @param {*} value The value to check.
12233         * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
12234         * @example
12235         *
12236         * _.isNative(Array.prototype.push);
12237         * // => true
12238         *
12239         * _.isNative(_);
12240         * // => false
12241         */
12242        function isNative(value) {
12243            if (value == null) {
12244                return false;
12245            }
12246            if (isFunction(value)) {
12247                return reIsNative.test(fnToString.call(value));
12248            }
12249            return isObjectLike(value) && reIsHostCtor.test(value);
12250        }
12251
12252        module.exports = isArray;
12253
12254    },{}],57:[function(_dereq_,module,exports){
12255        /**
12256         * lodash 3.2.0 (Custom Build) <https://lodash.com/>
12257         * Build: `lodash modern modularize exports="npm" -o ./`
12258         * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
12259         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
12260         * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
12261         * Available under MIT license <https://lodash.com/license>
12262         */
12263        var baseFor = _dereq_('lodash._basefor'),
12264            isArguments = _dereq_('lodash.isarguments'),
12265            keysIn = _dereq_('lodash.keysin');
12266
12267        /** `Object#toString` result references. */
12268        var objectTag = '[object Object]';
12269
12270        /**
12271         * Checks if `value` is object-like.
12272         *
12273         * @private
12274         * @param {*} value The value to check.
12275         * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
12276         */
12277        function isObjectLike(value) {
12278            return !!value && typeof value == 'object';
12279        }
12280
12281        /** Used for native method references. */
12282        var objectProto = Object.prototype;
12283
12284        /** Used to check objects for own properties. */
12285        var hasOwnProperty = objectProto.hasOwnProperty;
12286
12287        /**
12288         * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
12289         * of values.
12290         */
12291        var objToString = objectProto.toString;
12292
12293        /**
12294         * The base implementation of `_.forIn` without support for callback
12295         * shorthands and `this` binding.
12296         *
12297         * @private
12298         * @param {Object} object The object to iterate over.
12299         * @param {Function} iteratee The function invoked per iteration.
12300         * @returns {Object} Returns `object`.
12301         */
12302        function baseForIn(object, iteratee) {
12303            return baseFor(object, iteratee, keysIn);
12304        }
12305
12306        /**
12307         * Checks if `value` is a plain object, that is, an object created by the
12308         * `Object` constructor or one with a `[[Prototype]]` of `null`.
12309         *
12310         * **Note:** This method assumes objects created by the `Object` constructor
12311         * have no inherited enumerable properties.
12312         *
12313         * @static
12314         * @memberOf _
12315         * @category Lang
12316         * @param {*} value The value to check.
12317         * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
12318         * @example
12319         *
12320         * function Foo() {
12321         *   this.a = 1;
12322         * }
12323         *
12324         * _.isPlainObject(new Foo);
12325         * // => false
12326         *
12327         * _.isPlainObject([1, 2, 3]);
12328         * // => false
12329         *
12330         * _.isPlainObject({ 'x': 0, 'y': 0 });
12331         * // => true
12332         *
12333         * _.isPlainObject(Object.create(null));
12334         * // => true
12335         */
12336        function isPlainObject(value) {
12337            var Ctor;
12338
12339            // Exit early for non `Object` objects.
12340            if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isArguments(value)) ||
12341                (!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
12342                return false;
12343            }
12344            // IE < 9 iterates inherited properties before own properties. If the first
12345            // iterated property is an object's own property then there are no inherited
12346            // enumerable properties.
12347            var result;
12348            // In most environments an object's own properties are iterated before
12349            // its inherited properties. If the last iterated property is an object's
12350            // own property then there are no inherited enumerable properties.
12351            baseForIn(value, function(subValue, key) {
12352                result = key;
12353            });
12354            return result === undefined || hasOwnProperty.call(value, result);
12355        }
12356
12357        module.exports = isPlainObject;
12358
12359    },{"lodash._basefor":58,"lodash.isarguments":55,"lodash.keysin":61}],58:[function(_dereq_,module,exports){
12360        /**
12361         * lodash 3.0.3 (Custom Build) <https://lodash.com/>
12362         * Build: `lodash modularize exports="npm" -o ./`
12363         * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
12364         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
12365         * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
12366         * Available under MIT license <https://lodash.com/license>
12367         */
12368
12369        /**
12370         * The base implementation of `baseForIn` and `baseForOwn` which iterates
12371         * over `object` properties returned by `keysFunc` invoking `iteratee` for
12372         * each property. Iteratee functions may exit iteration early by explicitly
12373         * returning `false`.
12374         *
12375         * @private
12376         * @param {Object} object The object to iterate over.
12377         * @param {Function} iteratee The function invoked per iteration.
12378         * @param {Function} keysFunc The function to get the keys of `object`.
12379         * @returns {Object} Returns `object`.
12380         */
12381        var baseFor = createBaseFor();
12382
12383        /**
12384         * Creates a base function for methods like `_.forIn`.
12385         *
12386         * @private
12387         * @param {boolean} [fromRight] Specify iterating from right to left.
12388         * @returns {Function} Returns the new base function.
12389         */
12390        function createBaseFor(fromRight) {
12391            return function(object, iteratee, keysFunc) {
12392                var index = -1,
12393                    iterable = Object(object),
12394                    props = keysFunc(object),
12395                    length = props.length;
12396
12397                while (length--) {
12398                    var key = props[fromRight ? length : ++index];
12399                    if (iteratee(iterable[key], key, iterable) === false) {
12400                        break;
12401                    }
12402                }
12403                return object;
12404            };
12405        }
12406
12407        module.exports = baseFor;
12408
12409    },{}],59:[function(_dereq_,module,exports){
12410        /**
12411         * lodash 3.0.6 (Custom Build) <https://lodash.com/>
12412         * Build: `lodash modularize exports="npm" -o ./`
12413         * Copyright jQuery Foundation and other contributors <https://jquery.org/>
12414         * Released under MIT license <https://lodash.com/license>
12415         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
12416         * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
12417         */
12418
12419        /** Used as references for various `Number` constants. */
12420        var MAX_SAFE_INTEGER = 9007199254740991;
12421
12422        /** `Object#toString` result references. */
12423        var argsTag = '[object Arguments]',
12424            arrayTag = '[object Array]',
12425            boolTag = '[object Boolean]',
12426            dateTag = '[object Date]',
12427            errorTag = '[object Error]',
12428            funcTag = '[object Function]',
12429            mapTag = '[object Map]',
12430            numberTag = '[object Number]',
12431            objectTag = '[object Object]',
12432            regexpTag = '[object RegExp]',
12433            setTag = '[object Set]',
12434            stringTag = '[object String]',
12435            weakMapTag = '[object WeakMap]';
12436
12437        var arrayBufferTag = '[object ArrayBuffer]',
12438            dataViewTag = '[object DataView]',
12439            float32Tag = '[object Float32Array]',
12440            float64Tag = '[object Float64Array]',
12441            int8Tag = '[object Int8Array]',
12442            int16Tag = '[object Int16Array]',
12443            int32Tag = '[object Int32Array]',
12444            uint8Tag = '[object Uint8Array]',
12445            uint8ClampedTag = '[object Uint8ClampedArray]',
12446            uint16Tag = '[object Uint16Array]',
12447            uint32Tag = '[object Uint32Array]';
12448
12449        /** Used to identify `toStringTag` values of typed arrays. */
12450        var typedArrayTags = {};
12451        typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
12452            typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
12453                typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
12454                    typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
12455                        typedArrayTags[uint32Tag] = true;
12456        typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
12457            typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
12458                typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
12459                    typedArrayTags[errorTag] = typedArrayTags[funcTag] =
12460                        typedArrayTags[mapTag] = typedArrayTags[numberTag] =
12461                            typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
12462                                typedArrayTags[setTag] = typedArrayTags[stringTag] =
12463                                    typedArrayTags[weakMapTag] = false;
12464
12465        /** Used for built-in method references. */
12466        var objectProto = Object.prototype;
12467
12468        /**
12469         * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
12470         * of values.
12471         */
12472        var objectToString = objectProto.toString;
12473
12474        /**
12475         * Checks if `value` is a valid array-like length.
12476         *
12477         * **Note:** This function is loosely based on
12478         * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
12479         *
12480         * @static
12481         * @memberOf _
12482         * @since 4.0.0
12483         * @category Lang
12484         * @param {*} value The value to check.
12485         * @returns {boolean} Returns `true` if `value` is a valid length,
12486         *  else `false`.
12487         * @example
12488         *
12489         * _.isLength(3);
12490         * // => true
12491         *
12492         * _.isLength(Number.MIN_VALUE);
12493         * // => false
12494         *
12495         * _.isLength(Infinity);
12496         * // => false
12497         *
12498         * _.isLength('3');
12499         * // => false
12500         */
12501        function isLength(value) {
12502            return typeof value == 'number' &&
12503                value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
12504        }
12505
12506        /**
12507         * Checks if `value` is object-like. A value is object-like if it's not `null`
12508         * and has a `typeof` result of "object".
12509         *
12510         * @static
12511         * @memberOf _
12512         * @since 4.0.0
12513         * @category Lang
12514         * @param {*} value The value to check.
12515         * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
12516         * @example
12517         *
12518         * _.isObjectLike({});
12519         * // => true
12520         *
12521         * _.isObjectLike([1, 2, 3]);
12522         * // => true
12523         *
12524         * _.isObjectLike(_.noop);
12525         * // => false
12526         *
12527         * _.isObjectLike(null);
12528         * // => false
12529         */
12530        function isObjectLike(value) {
12531            return !!value && typeof value == 'object';
12532        }
12533
12534        /**
12535         * Checks if `value` is classified as a typed array.
12536         *
12537         * @static
12538         * @memberOf _
12539         * @since 3.0.0
12540         * @category Lang
12541         * @param {*} value The value to check.
12542         * @returns {boolean} Returns `true` if `value` is correctly classified,
12543         *  else `false`.
12544         * @example
12545         *
12546         * _.isTypedArray(new Uint8Array);
12547         * // => true
12548         *
12549         * _.isTypedArray([]);
12550         * // => false
12551         */
12552        function isTypedArray(value) {
12553            return isObjectLike(value) &&
12554                isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
12555        }
12556
12557        module.exports = isTypedArray;
12558
12559    },{}],60:[function(_dereq_,module,exports){
12560        /**
12561         * lodash 3.1.2 (Custom Build) <https://lodash.com/>
12562         * Build: `lodash modern modularize exports="npm" -o ./`
12563         * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
12564         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
12565         * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
12566         * Available under MIT license <https://lodash.com/license>
12567         */
12568        var getNative = _dereq_('lodash._getnative'),
12569            isArguments = _dereq_('lodash.isarguments'),
12570            isArray = _dereq_('lodash.isarray');
12571
12572        /** Used to detect unsigned integer values. */
12573        var reIsUint = /^\d+$/;
12574
12575        /** Used for native method references. */
12576        var objectProto = Object.prototype;
12577
12578        /** Used to check objects for own properties. */
12579        var hasOwnProperty = objectProto.hasOwnProperty;
12580
12581        /* Native method references for those with the same name as other `lodash` methods. */
12582        var nativeKeys = getNative(Object, 'keys');
12583
12584        /**
12585         * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
12586         * of an array-like value.
12587         */
12588        var MAX_SAFE_INTEGER = 9007199254740991;
12589
12590        /**
12591         * The base implementation of `_.property` without support for deep paths.
12592         *
12593         * @private
12594         * @param {string} key The key of the property to get.
12595         * @returns {Function} Returns the new function.
12596         */
12597        function baseProperty(key) {
12598            return function(object) {
12599                return object == null ? undefined : object[key];
12600            };
12601        }
12602
12603        /**
12604         * Gets the "length" property value of `object`.
12605         *
12606         * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
12607         * that affects Safari on at least iOS 8.1-8.3 ARM64.
12608         *
12609         * @private
12610         * @param {Object} object The object to query.
12611         * @returns {*} Returns the "length" value.
12612         */
12613        var getLength = baseProperty('length');
12614
12615        /**
12616         * Checks if `value` is array-like.
12617         *
12618         * @private
12619         * @param {*} value The value to check.
12620         * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
12621         */
12622        function isArrayLike(value) {
12623            return value != null && isLength(getLength(value));
12624        }
12625
12626        /**
12627         * Checks if `value` is a valid array-like index.
12628         *
12629         * @private
12630         * @param {*} value The value to check.
12631         * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
12632         * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
12633         */
12634        function isIndex(value, length) {
12635            value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
12636            length = length == null ? MAX_SAFE_INTEGER : length;
12637            return value > -1 && value % 1 == 0 && value < length;
12638        }
12639
12640        /**
12641         * Checks if `value` is a valid array-like length.
12642         *
12643         * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
12644         *
12645         * @private
12646         * @param {*} value The value to check.
12647         * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
12648         */
12649        function isLength(value) {
12650            return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
12651        }
12652
12653        /**
12654         * A fallback implementation of `Object.keys` which creates an array of the
12655         * own enumerable property names of `object`.
12656         *
12657         * @private
12658         * @param {Object} object The object to query.
12659         * @returns {Array} Returns the array of property names.
12660         */
12661        function shimKeys(object) {
12662            var props = keysIn(object),
12663                propsLength = props.length,
12664                length = propsLength && object.length;
12665
12666            var allowIndexes = !!length && isLength(length) &&
12667                (isArray(object) || isArguments(object));
12668
12669            var index = -1,
12670                result = [];
12671
12672            while (++index < propsLength) {
12673                var key = props[index];
12674                if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
12675                    result.push(key);
12676                }
12677            }
12678            return result;
12679        }
12680
12681        /**
12682         * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
12683         * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
12684         *
12685         * @static
12686         * @memberOf _
12687         * @category Lang
12688         * @param {*} value The value to check.
12689         * @returns {boolean} Returns `true` if `value` is an object, else `false`.
12690         * @example
12691         *
12692         * _.isObject({});
12693         * // => true
12694         *
12695         * _.isObject([1, 2, 3]);
12696         * // => true
12697         *
12698         * _.isObject(1);
12699         * // => false
12700         */
12701        function isObject(value) {
12702            // Avoid a V8 JIT bug in Chrome 19-20.
12703            // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
12704            var type = typeof value;
12705            return !!value && (type == 'object' || type == 'function');
12706        }
12707
12708        /**
12709         * Creates an array of the own enumerable property names of `object`.
12710         *
12711         * **Note:** Non-object values are coerced to objects. See the
12712         * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
12713         * for more details.
12714         *
12715         * @static
12716         * @memberOf _
12717         * @category Object
12718         * @param {Object} object The object to query.
12719         * @returns {Array} Returns the array of property names.
12720         * @example
12721         *
12722         * function Foo() {
12723         *   this.a = 1;
12724         *   this.b = 2;
12725         * }
12726         *
12727         * Foo.prototype.c = 3;
12728         *
12729         * _.keys(new Foo);
12730         * // => ['a', 'b'] (iteration order is not guaranteed)
12731         *
12732         * _.keys('hi');
12733         * // => ['0', '1']
12734         */
12735        var keys = !nativeKeys ? shimKeys : function(object) {
12736            var Ctor = object == null ? undefined : object.constructor;
12737            if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
12738                (typeof object != 'function' && isArrayLike(object))) {
12739                return shimKeys(object);
12740            }
12741            return isObject(object) ? nativeKeys(object) : [];
12742        };
12743
12744        /**
12745         * Creates an array of the own and inherited enumerable property names of `object`.
12746         *
12747         * **Note:** Non-object values are coerced to objects.
12748         *
12749         * @static
12750         * @memberOf _
12751         * @category Object
12752         * @param {Object} object The object to query.
12753         * @returns {Array} Returns the array of property names.
12754         * @example
12755         *
12756         * function Foo() {
12757         *   this.a = 1;
12758         *   this.b = 2;
12759         * }
12760         *
12761         * Foo.prototype.c = 3;
12762         *
12763         * _.keysIn(new Foo);
12764         * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
12765         */
12766        function keysIn(object) {
12767            if (object == null) {
12768                return [];
12769            }
12770            if (!isObject(object)) {
12771                object = Object(object);
12772            }
12773            var length = object.length;
12774            length = (length && isLength(length) &&
12775                (isArray(object) || isArguments(object)) && length) || 0;
12776
12777            var Ctor = object.constructor,
12778                index = -1,
12779                isProto = typeof Ctor == 'function' && Ctor.prototype === object,
12780                result = Array(length),
12781                skipIndexes = length > 0;
12782
12783            while (++index < length) {
12784                result[index] = (index + '');
12785            }
12786            for (var key in object) {
12787                if (!(skipIndexes && isIndex(key, length)) &&
12788                    !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
12789                    result.push(key);
12790                }
12791            }
12792            return result;
12793        }
12794
12795        module.exports = keys;
12796
12797    },{"lodash._getnative":54,"lodash.isarguments":55,"lodash.isarray":56}],61:[function(_dereq_,module,exports){
12798        /**
12799         * lodash 3.0.8 (Custom Build) <https://lodash.com/>
12800         * Build: `lodash modern modularize exports="npm" -o ./`
12801         * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
12802         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
12803         * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
12804         * Available under MIT license <https://lodash.com/license>
12805         */
12806        var isArguments = _dereq_('lodash.isarguments'),
12807            isArray = _dereq_('lodash.isarray');
12808
12809        /** Used to detect unsigned integer values. */
12810        var reIsUint = /^\d+$/;
12811
12812        /** Used for native method references. */
12813        var objectProto = Object.prototype;
12814
12815        /** Used to check objects for own properties. */
12816        var hasOwnProperty = objectProto.hasOwnProperty;
12817
12818        /**
12819         * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
12820         * of an array-like value.
12821         */
12822        var MAX_SAFE_INTEGER = 9007199254740991;
12823
12824        /**
12825         * Checks if `value` is a valid array-like index.
12826         *
12827         * @private
12828         * @param {*} value The value to check.
12829         * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
12830         * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
12831         */
12832        function isIndex(value, length) {
12833            value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
12834            length = length == null ? MAX_SAFE_INTEGER : length;
12835            return value > -1 && value % 1 == 0 && value < length;
12836        }
12837
12838        /**
12839         * Checks if `value` is a valid array-like length.
12840         *
12841         * **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
12842         *
12843         * @private
12844         * @param {*} value The value to check.
12845         * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
12846         */
12847        function isLength(value) {
12848            return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
12849        }
12850
12851        /**
12852         * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
12853         * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
12854         *
12855         * @static
12856         * @memberOf _
12857         * @category Lang
12858         * @param {*} value The value to check.
12859         * @returns {boolean} Returns `true` if `value` is an object, else `false`.
12860         * @example
12861         *
12862         * _.isObject({});
12863         * // => true
12864         *
12865         * _.isObject([1, 2, 3]);
12866         * // => true
12867         *
12868         * _.isObject(1);
12869         * // => false
12870         */
12871        function isObject(value) {
12872            // Avoid a V8 JIT bug in Chrome 19-20.
12873            // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
12874            var type = typeof value;
12875            return !!value && (type == 'object' || type == 'function');
12876        }
12877
12878        /**
12879         * Creates an array of the own and inherited enumerable property names of `object`.
12880         *
12881         * **Note:** Non-object values are coerced to objects.
12882         *
12883         * @static
12884         * @memberOf _
12885         * @category Object
12886         * @param {Object} object The object to query.
12887         * @returns {Array} Returns the array of property names.
12888         * @example
12889         *
12890         * function Foo() {
12891         *   this.a = 1;
12892         *   this.b = 2;
12893         * }
12894         *
12895         * Foo.prototype.c = 3;
12896         *
12897         * _.keysIn(new Foo);
12898         * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
12899         */
12900        function keysIn(object) {
12901            if (object == null) {
12902                return [];
12903            }
12904            if (!isObject(object)) {
12905                object = Object(object);
12906            }
12907            var length = object.length;
12908            length = (length && isLength(length) &&
12909                (isArray(object) || isArguments(object)) && length) || 0;
12910
12911            var Ctor = object.constructor,
12912                index = -1,
12913                isProto = typeof Ctor == 'function' && Ctor.prototype === object,
12914                result = Array(length),
12915                skipIndexes = length > 0;
12916
12917            while (++index < length) {
12918                result[index] = (index + '');
12919            }
12920            for (var key in object) {
12921                if (!(skipIndexes && isIndex(key, length)) &&
12922                    !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
12923                    result.push(key);
12924                }
12925            }
12926            return result;
12927        }
12928
12929        module.exports = keysIn;
12930
12931    },{"lodash.isarguments":55,"lodash.isarray":56}],62:[function(_dereq_,module,exports){
12932        /**
12933         * lodash 3.0.0 (Custom Build) <https://lodash.com/>
12934         * Build: `lodash modern modularize exports="npm" -o ./`
12935         * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
12936         * Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
12937         * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
12938         * Available under MIT license <https://lodash.com/license>
12939         */
12940        var baseCopy = _dereq_('lodash._basecopy'),
12941            keysIn = _dereq_('lodash.keysin');
12942
12943        /**
12944         * Converts `value` to a plain object flattening inherited enumerable
12945         * properties of `value` to own properties of the plain object.
12946         *
12947         * @static
12948         * @memberOf _
12949         * @category Lang
12950         * @param {*} value The value to convert.
12951         * @returns {Object} Returns the converted plain object.
12952         * @example
12953         *
12954         * function Foo() {
12955         *   this.b = 2;
12956         * }
12957         *
12958         * Foo.prototype.c = 3;
12959         *
12960         * _.assign({ 'a': 1 }, new Foo);
12961         * // => { 'a': 1, 'b': 2 }
12962         *
12963         * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
12964         * // => { 'a': 1, 'b': 2, 'c': 3 }
12965         */
12966        function toPlainObject(value) {
12967            return baseCopy(value, keysIn(value));
12968        }
12969
12970        module.exports = toPlainObject;
12971
12972    },{"lodash._basecopy":63,"lodash.keysin":61}],63:[function(_dereq_,module,exports){
12973        /**
12974         * lodash 3.0.1 (Custom Build) <https://lodash.com/>
12975         * Build: `lodash modern modularize exports="npm" -o ./`
12976         * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
12977         * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
12978         * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
12979         * Available under MIT license <https://lodash.com/license>
12980         */
12981
12982        /**
12983         * Copies properties of `source` to `object`.
12984         *
12985         * @private
12986         * @param {Object} source The object to copy properties from.
12987         * @param {Array} props The property names to copy.
12988         * @param {Object} [object={}] The object to copy properties to.
12989         * @returns {Object} Returns `object`.
12990         */
12991        function baseCopy(source, props, object) {
12992            object || (object = {});
12993
12994            var index = -1,
12995                length = props.length;
12996
12997            while (++index < length) {
12998                var key = props[index];
12999                object[key] = source[key];
13000            }
13001            return object;
13002        }
13003
13004        module.exports = baseCopy;
13005
13006    },{}],64:[function(_dereq_,module,exports){
13007        var JSZip, fs, internal;
13008
13009        JSZip = _dereq_('jszip');
13010
13011        internal = _dereq_('./internal');
13012
13013
13014
13015        module.exports = {
13016            asBlob: function(html, options) {
13017                var zip;
13018                zip = new JSZip();
13019                internal.addFiles(zip, html, options);
13020                return internal.generateDocument(zip);
13021            }
13022        };
13023
13024
13025    },{"./internal":65,"jszip":14}],65:[function(_dereq_,module,exports){
13026        (function (global,Buffer){
13027            var documentTemplate, fs, utils, _;
13028
13029
13030
13031            documentTemplate = _dereq_('./templates/document');
13032
13033            utils = _dereq_('./utils');
13034
13035            _ = {
13036                merge: _dereq_('lodash.merge')
13037            };
13038
13039            module.exports = {
13040                generateDocument: function(zip) {
13041                    var buffer;
13042                    buffer = zip.generate({
13043                        type: 'arraybuffer'
13044                    });
13045                    if (global.Blob) {
13046                        return new Blob([buffer], {
13047                            type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
13048                        });
13049                    } else if (global.Buffer) {
13050                        return new Buffer(new Uint8Array(buffer));
13051                    } else {
13052                        throw new Error("Neither Blob nor Buffer are accessible in this environment. " + "Consider adding Blob.js shim");
13053                    }
13054                },
13055                renderDocumentFile: function(documentOptions) {
13056                    var templateData;
13057                    if (documentOptions == null) {
13058                        documentOptions = {};
13059                    }
13060                    templateData = _.merge({
13061                        margins: {
13062                            top: 1440,
13063                            right: 1440,
13064                            bottom: 1440,
13065                            left: 1440,
13066                            header: 720,
13067                            footer: 720,
13068                            gutter: 0
13069                        }
13070                    }, (function() {
13071                        switch (documentOptions.orientation) {
13072                            case 'landscape':
13073                                return {
13074                                    height: 12240,
13075                                    width: 15840,
13076                                    orient: 'landscape'
13077                                };
13078                            default:
13079                                return {
13080                                    width: 12240,
13081                                    height: 15840,
13082                                    orient: 'portrait'
13083                                };
13084                        }
13085                    })(), {
13086                        margins: documentOptions.margins
13087                    });
13088                    return documentTemplate(templateData);
13089                },
13090                addFiles: function(zip, htmlSource, documentOptions) {
13091                    zip.file('[Content_Types].xml', Buffer("PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pgo8VHlwZXMgeG1sbnM9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9wYWNrYWdlLzIwMDYvY29udGVudC10eXBlcyI+CiAgPERlZmF1bHQgRXh0ZW5zaW9uPSJyZWxzIiBDb250ZW50VHlwZT0KICAgICJhcHBsaWNhdGlvbi92bmQub3BlbnhtbGZvcm1hdHMtcGFja2FnZS5yZWxhdGlvbnNoaXBzK3htbCIgLz4KICA8T3ZlcnJpZGUgUGFydE5hbWU9Ii93b3JkL2RvY3VtZW50LnhtbCIgQ29udGVudFR5cGU9CiAgICAiYXBwbGljYXRpb24vdm5kLm9wZW54bWxmb3JtYXRzLW9mZmljZWRvY3VtZW50LndvcmRwcm9jZXNzaW5nbWwuZG9jdW1lbnQubWFpbit4bWwiLz4KICA8T3ZlcnJpZGUgUGFydE5hbWU9Ii93b3JkL2FmY2h1bmsubWh0IiBDb250ZW50VHlwZT0ibWVzc2FnZS9yZmM4MjIiLz4KPC9UeXBlcz4K","base64"));
13092                    zip.folder('_rels').file('.rels', Buffer("PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pgo8UmVsYXRpb25zaGlwcyB4bWxucz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL3BhY2thZ2UvMjAwNi9yZWxhdGlvbnNoaXBzIj4KICA8UmVsYXRpb25zaGlwCiAgICAgIFR5cGU9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9vZmZpY2VEb2N1bWVudC8yMDA2L3JlbGF0aW9uc2hpcHMvb2ZmaWNlRG9jdW1lbnQiCiAgICAgIFRhcmdldD0iL3dvcmQvZG9jdW1lbnQueG1sIiBJZD0iUjA5YzgzZmFmYzA2NzQ4OGUiIC8+CjwvUmVsYXRpb25zaGlwcz4K","base64"));
13093                    return zip.folder('word').file('document.xml', this.renderDocumentFile(documentOptions)).file('afchunk.mht', utils.getMHTdocument(htmlSource)).folder('_rels').file('document.xml.rels', Buffer("PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pgo8UmVsYXRpb25zaGlwcyB4bWxucz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL3BhY2thZ2UvMjAwNi9yZWxhdGlvbnNoaXBzIj4KICA8UmVsYXRpb25zaGlwIFR5cGU9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9vZmZpY2VEb2N1bWVudC8yMDA2L3JlbGF0aW9uc2hpcHMvYUZDaHVuayIKICAgIFRhcmdldD0iL3dvcmQvYWZjaHVuay5taHQiIElkPSJodG1sQ2h1bmsiIC8+CjwvUmVsYXRpb25zaGlwcz4K","base64"));
13094                }
13095            };
13096
13097
13098        }).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},_dereq_("buffer").Buffer)
13099    },{"./templates/document":66,"./utils":69,"buffer":1,"lodash.merge":47}],66:[function(_dereq_,module,exports){
13100        var _ = {escape: _dereq_("lodash.escape")};
13101        module.exports = function(obj){
13102            var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};
13103            with(obj||{}){
13104                __p+='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<w:document\n  xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"\n  xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"\n  xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"\n  xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"\n  xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"\n  xmlns:ns6="http://schemas.openxmlformats.org/schemaLibrary/2006/main"\n  xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"\n  xmlns:ns8="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing"\n  xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram"\n  xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"\n  xmlns:ns11="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"\n  xmlns:dsp="http://schemas.microsoft.com/office/drawing/2008/diagram"\n  xmlns:ns13="urn:schemas-microsoft-com:office:excel"\n  xmlns:o="ur
13104n:schemas-microsoft-com:office:office"\n  xmlns:v="urn:schemas-microsoft-com:vml"\n  xmlns:w10="urn:schemas-microsoft-com:office:word"\n  xmlns:ns17="urn:schemas-microsoft-com:office:powerpoint"\n  xmlns:odx="http://opendope.org/xpaths"\n  xmlns:odc="http://opendope.org/conditions"\n  xmlns:odq="http://opendope.org/questions"\n  xmlns:odi="http://opendope.org/components"\n  xmlns:odgm="http://opendope.org/SmartArt/DataHierarchy"\n  xmlns:ns24="http://schemas.openxmlformats.org/officeDocument/2006/bibliography"\n  xmlns:ns25="http://schemas.openxmlformats.org/drawingml/2006/compatibility"\n  xmlns:ns26="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas">\n  <w:body>\n    <w:altChunk r:id="htmlChunk" />\n    <w:sectPr>\n      <w:pgSz w:w="'+
13105                    ((__t=( width ))==null?'':__t)+
13106                    '" w:h="'+
13107                    ((__t=( height ))==null?'':__t)+
13108                    '" w:orient="'+
13109                    ((__t=( orient ))==null?'':__t)+
13110                    '" />\n      <w:pgMar w:top="'+
13111                    ((__t=( margins.top ))==null?'':__t)+
13112                    '"\n               w:right="'+
13113                    ((__t=( margins.right ))==null?'':__t)+
13114                    '"\n               w:bottom="'+
13115                    ((__t=( margins.bottom ))==null?'':__t)+
13116                    '"\n               w:left="'+
13117                    ((__t=( margins.left ))==null?'':__t)+
13118                    '"\n               w:header="'+
13119                    ((__t=( margins.header ))==null?'':__t)+
13120                    '"\n               w:footer="'+
13121                    ((__t=( margins.footer ))==null?'':__t)+
13122                    '"\n               w:gutter="'+
13123                    ((__t=( margins.gutter ))==null?'':__t)+
13124                    '"/>\n    </w:sectPr>\n  </w:body>\n</w:document>\n';
13125            }
13126            return __p;
13127        };
13128
13129    },{"lodash.escape":45}],67:[function(_dereq_,module,exports){
13130        var _ = {escape: _dereq_("lodash.escape")};
13131        module.exports = function(obj){
13132            var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};
13133            with(obj||{}){
13134                __p+='MIME-Version: 1.0\nContent-Type: multipart/related;\n    type="text/html";\n    boundary="----=mhtDocumentPart"\n\n\n------=mhtDocumentPart\nContent-Type: text/html;\n    charset="utf-8"\nContent-Transfer-Encoding: quoted-printable\nContent-Location: file:///C:/fake/document.html\n\n'+
13135                    ((__t=( htmlSource ))==null?'':__t)+
13136                    '\n\n'+
13137                    ((__t=( contentParts ))==null?'':__t)+
13138                    '\n\n------=mhtDocumentPart--\n';
13139            }
13140            return __p;
13141        };
13142
13143    },{"lodash.escape":45}],68:[function(_dereq_,module,exports){
13144        var _ = {escape: _dereq_("lodash.escape")};
13145        module.exports = function(obj){
13146            var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};
13147            with(obj||{}){
13148                __p+='------=mhtDocumentPart\nContent-Type: '+
13149                    ((__t=( contentType ))==null?'':__t)+
13150                    '\nContent-Transfer-Encoding: '+
13151                    ((__t=( contentEncoding ))==null?'':__t)+
13152                    '\nContent-Location: '+
13153                    ((__t=( contentLocation ))==null?'':__t)+
13154                    '\n\n'+
13155                    ((__t=( encodedContent ))==null?'':__t)+
13156                    '\n';
13157            }
13158            return __p;
13159        };
13160
13161    },{"lodash.escape":45}],69:[function(_dereq_,module,exports){
13162        var mhtDocumentTemplate, mhtPartTemplate;
13163
13164        mhtDocumentTemplate = _dereq_('./templates/mht_document');
13165
13166        mhtPartTemplate = _dereq_('./templates/mht_part');
13167
13168        module.exports = {
13169            getMHTdocument: function(htmlSource) {
13170                var imageContentParts, _ref;
13171                _ref = this._prepareImageParts(htmlSource), htmlSource = _ref.htmlSource, imageContentParts = _ref.imageContentParts;
13172                htmlSource = htmlSource.replace(/\=/g, '=3D');
13173                return mhtDocumentTemplate({
13174                    htmlSource: htmlSource,
13175                    contentParts: imageContentParts.join('\n')
13176                });
13177            },
13178            _prepareImageParts: function(htmlSource) {
vendor: 1,743 bytes, lines 13179-13216
13179                var imageContentParts, inlinedReplacer, inlinedSrcPattern;
13180                imageContentParts = [];
13181                inlinedSrcPattern = /"data:(\w+\/\w+);(\w+),(\S+)"/g;
13182                inlinedReplacer = function(match, contentType, contentEncoding, encodedContent) {
13183                    var contentLocation, extension, index;
13184                    index = imageContentParts.length;
13185                    extension = contentType.split('/')[1];
13186                    contentLocation = "file:///C:/fake/image" + index + "." + extension;
13187                    imageContentParts.push(mhtPartTemplate({
13188                        contentType: contentType,
13189                        contentEncoding: contentEncoding,
13190                        contentLocation: contentLocation,
13191                        encodedContent: encodedContent
13192                    }));
13193                    return "\"" + contentLocation + "\"";
13194                };
13195                if (typeof htmlSource === 'string') {
13196                    if (!/<img/g.test(htmlSource)) {
13197                        return {
13198                            htmlSource: htmlSource,
13199                            imageContentParts: imageContentParts
13200                        };
13201                    }
13202                    htmlSource = htmlSource.replace(inlinedSrcPattern, inlinedReplacer);
13203                    return {
13204                        htmlSource: htmlSource,
13205                        imageContentParts: imageContentParts
13206                    };
13207                } else {
13208                    throw new Error("Not a valid source provided!");
13209                }
13210            }
13211        };
13212
13213
13214    },{"./templates/mht_document":67,"./templates/mht_part":68}]},{},[64])
13215(64)
13216});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.