Skip to content
Snippets Groups Projects
base64zip.js 305 KiB
Newer Older
Recolic's avatar
.
Recolic committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
            // SRC: https://github.com/beatgammit/base64-js
            (function(r){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=r()}else if(typeof define==="function"&&define.amd){define([],r)}else{var e;if(typeof window!=="undefined"){e=window}else if(typeof global!=="undefined"){e=global}else if(typeof self!=="undefined"){e=self}else{e=this}e.base64js=r()}})(function(){var r,e,n;return function(){function r(e,n,t){function o(f,i){if(!n[f]){if(!e[f]){var u="function"==typeof require&&require;if(!i&&u)return u(f,!0);if(a)return a(f,!0);var v=new Error("Cannot find module '"+f+"'");throw v.code="MODULE_NOT_FOUND",v}var d=n[f]={exports:{}};e[f][0].call(d.exports,function(r){var n=e[f][1][r];return o(n||r)},d,d.exports,r,e,n,t)}return n[f].exports}for(var a="function"==typeof require&&require,f=0;f<t.length;f++)o(t[f]);return o}return r}()({"/":[function(r,e,n){"use strict";n.byteLength=d;n.toByteArray=h;n.fromByteArray=p;var t=[];var o=[];var a=typeof Uint8Array!=="undefined"?Uint8Array:Array;var f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var i=0,u=f.length;i<u;++i){t[i]=f[i];o[f.charCodeAt(i)]=i}o["-".charCodeAt(0)]=62;o["_".charCodeAt(0)]=63;function v(r){var e=r.length;if(e%4>0){throw new Error("Invalid string. Length must be a multiple of 4")}var n=r.indexOf("=");if(n===-1)n=e;var t=n===e?0:4-n%4;return[n,t]}function d(r){var e=v(r);var n=e[0];var t=e[1];return(n+t)*3/4-t}function c(r,e,n){return(e+n)*3/4-n}function h(r){var e;var n=v(r);var t=n[0];var f=n[1];var i=new a(c(r,t,f));var u=0;var d=f>0?t-4:t;for(var h=0;h<d;h+=4){e=o[r.charCodeAt(h)]<<18|o[r.charCodeAt(h+1)]<<12|o[r.charCodeAt(h+2)]<<6|o[r.charCodeAt(h+3)];i[u++]=e>>16&255;i[u++]=e>>8&255;i[u++]=e&255}if(f===2){e=o[r.charCodeAt(h)]<<2|o[r.charCodeAt(h+1)]>>4;i[u++]=e&255}if(f===1){e=o[r.charCodeAt(h)]<<10|o[r.charCodeAt(h+1)]<<4|o[r.charCodeAt(h+2)]>>2;i[u++]=e>>8&255;i[u++]=e&255}return i}function s(r){return t[r>>18&63]+t[r>>12&63]+t[r>>6&63]+t[r&63]}function l(r,e,n){var t;var o=[];for(var a=e;a<n;a+=3){t=(r[a]<<16&16711680)+(r[a+1]<<8&65280)+(r[a+2]&255);o.push(s(t))}return o.join("")}function p(r){var e;var n=r.length;var o=n%3;var a=[];var f=16383;for(var i=0,u=n-o;i<u;i+=f){a.push(l(r,i,i+f>u?u:i+f))}if(o===1){e=r[n-1];a.push(t[e>>2]+t[e<<4&63]+"==")}else if(o===2){e=(r[n-2]<<8)+r[n-1];a.push(t[e>>10]+t[e>>4&63]+t[e<<2&63]+"=")}return a.join("")}},{}]},{},[])("/")});
            // SRC: https://github.com/solderjs/TextEncoderLite
            function TextEncoderLite() {
            }
            function TextDecoderLite() {
            }
            
            (function () {
            'use strict';
            
            // Taken from https://github.com/feross/buffer/blob/master/index.js
            // Thanks Feross et al! :-)
            
            function utf8ToBytes (string, units) {
              units = units || Infinity
              var codePoint
              var length = string.length
              var leadSurrogate = null
              var bytes = []
              var i = 0
            
              for (; i < length; i++) {
                codePoint = string.charCodeAt(i)
            
                // is surrogate component
                if (codePoint > 0xD7FF && codePoint < 0xE000) {
                  // last char was a lead
                  if (leadSurrogate) {
                    // 2 leads in a row
                    if (codePoint < 0xDC00) {
                      if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
                      leadSurrogate = codePoint
                      continue
                    } else {
                      // valid surrogate pair
                      codePoint = leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00 | 0x10000
                      leadSurrogate = null
                    }
                  } else {
                    // no lead yet
            
                    if (codePoint > 0xDBFF) {
                      // unexpected trail
                      if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
                      continue
                    } else if (i + 1 === length) {
                      // unpaired lead
                      if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
                      continue
                    } else {
                      // valid lead
                      leadSurrogate = codePoint
                      continue
                    }
                  }
                } else if (leadSurrogate) {
                  // valid bmp char, but last char was a lead
                  if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
                  leadSurrogate = null
                }
            
                // encode utf8
                if (codePoint < 0x80) {
                  if ((units -= 1) < 0) break
                  bytes.push(codePoint)
                } else if (codePoint < 0x800) {
                  if ((units -= 2) < 0) break
                  bytes.push(
                    codePoint >> 0x6 | 0xC0,
                    codePoint & 0x3F | 0x80
                  )
                } else if (codePoint < 0x10000) {
                  if ((units -= 3) < 0) break
                  bytes.push(
                    codePoint >> 0xC | 0xE0,
                    codePoint >> 0x6 & 0x3F | 0x80,
                    codePoint & 0x3F | 0x80
                  )
                } else if (codePoint < 0x200000) {
                  if ((units -= 4) < 0) break
                  bytes.push(
                    codePoint >> 0x12 | 0xF0,
                    codePoint >> 0xC & 0x3F | 0x80,
                    codePoint >> 0x6 & 0x3F | 0x80,
                    codePoint & 0x3F | 0x80
                  )
                } else {
                  throw new Error('Invalid code point')
                }
              }
            
              return bytes
            }
            
            function utf8Slice (buf, start, end) {
              var res = ''
              var tmp = ''
              end = Math.min(buf.length, end || Infinity)
              start = start || 0;
            
              for (var i = start; i < end; i++) {
                if (buf[i] <= 0x7F) {
                  res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
                  tmp = ''
                } else {
                  tmp += '%' + buf[i].toString(16)
                }
              }
            
              return res + decodeUtf8Char(tmp)
            }
            
            function decodeUtf8Char (str) {
              try {
                return decodeURIComponent(str)
              } catch (err) {
                return String.fromCharCode(0xFFFD) // UTF 8 invalid char
              }
            }
            
            TextEncoderLite.prototype.encode = function (str) {
              var result;
            
              if ('undefined' === typeof Uint8Array) {
                result = utf8ToBytes(str);
              } else {
                result = new Uint8Array(utf8ToBytes(str));
              }
            
              return result;
            };
            
            TextDecoderLite.prototype.decode = function (bytes) {
              return utf8Slice(bytes, 0, bytes.length);
            }
            
            }());
            
            if(typeof module === "object" && module) {
              module.exports.TextDecoderLite = TextDecoderLite;
              module.exports.TextEncoderLite = TextEncoderLite;
            }
            // SRC: https://github.com/nodeca/pako
            /* pako 1.0.10 nodeca/pako */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.pako = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
            'use strict';
            
            
            var zlib_deflate = require('./zlib/deflate');
            var utils        = require('./utils/common');
            var strings      = require('./utils/strings');
            var msg          = require('./zlib/messages');
            var ZStream      = require('./zlib/zstream');
            
            var toString = Object.prototype.toString;
            
            /* Public constants ==========================================================*/
            /* ===========================================================================*/
            
            var Z_NO_FLUSH      = 0;
            var Z_FINISH        = 4;
            
            var Z_OK            = 0;
            var Z_STREAM_END    = 1;
            var Z_SYNC_FLUSH    = 2;
            
            var Z_DEFAULT_COMPRESSION = -1;
            
            var Z_DEFAULT_STRATEGY    = 0;
            
            var Z_DEFLATED  = 8;
            
            /* ===========================================================================*/
            
            
            /**
             * class Deflate
             *
             * Generic JS-style wrapper for zlib calls. If you don't need
             * streaming behaviour - use more simple functions: [[deflate]],
             * [[deflateRaw]] and [[gzip]].
             **/
            
            /* internal
             * Deflate.chunks -> Array
             *
             * Chunks of output data, if [[Deflate#onData]] not overridden.
             **/
            
            /**
             * Deflate.result -> Uint8Array|Array
             *
             * Compressed result, generated by default [[Deflate#onData]]
             * and [[Deflate#onEnd]] handlers. Filled after you push last chunk
             * (call [[Deflate#push]] with `Z_FINISH` / `true` param)  or if you
             * push a chunk with explicit flush (call [[Deflate#push]] with
             * `Z_SYNC_FLUSH` param).
             **/
            
            /**
             * Deflate.err -> Number
             *
             * Error code after deflate finished. 0 (Z_OK) on success.
             * You will not need it in real life, because deflate errors
             * are possible only on wrong options or bad `onData` / `onEnd`
             * custom handlers.
             **/
            
            /**
             * Deflate.msg -> String
             *
             * Error message, if [[Deflate.err]] != 0
             **/
            
            
            /**
             * new Deflate(options)
             * - options (Object): zlib deflate options.
             *
             * Creates new deflator instance with specified params. Throws exception
             * on bad params. Supported options:
             *
             * - `level`
             * - `windowBits`
             * - `memLevel`
             * - `strategy`
             * - `dictionary`
             *
             * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
             * for more information on these.
             *
             * Additional options, for internal needs:
             *
             * - `chunkSize` - size of generated data chunks (16K by default)
             * - `raw` (Boolean) - do raw deflate
             * - `gzip` (Boolean) - create gzip wrapper
             * - `to` (String) - if equal to 'string', then result will be "binary string"
             *    (each char code [0..255])
             * - `header` (Object) - custom header for gzip
             *   - `text` (Boolean) - true if compressed data believed to be text
             *   - `time` (Number) - modification time, unix timestamp
             *   - `os` (Number) - operation system code
             *   - `extra` (Array) - array of bytes with extra data (max 65536)
             *   - `name` (String) - file name (binary string)
             *   - `comment` (String) - comment (binary string)
             *   - `hcrc` (Boolean) - true if header crc should be added
             *
             * ##### Example:
             *
             * ```javascript
             * var pako = require('pako')
             *   , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
             *   , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
             *
             * var deflate = new pako.Deflate({ level: 3});
             *
             * deflate.push(chunk1, false);
             * deflate.push(chunk2, true);  // true -> last chunk
             *
             * if (deflate.err) { throw new Error(deflate.err); }
             *
             * console.log(deflate.result);
             * ```
             **/
            function Deflate(options) {
              if (!(this instanceof Deflate)) return new Deflate(options);
            
              this.options = utils.assign({
                level: Z_DEFAULT_COMPRESSION,
                method: Z_DEFLATED,
                chunkSize: 16384,
                windowBits: 15,
                memLevel: 8,
                strategy: Z_DEFAULT_STRATEGY,
                to: ''
              }, options || {});
            
              var opt = this.options;
            
              if (opt.raw && (opt.windowBits > 0)) {
                opt.windowBits = -opt.windowBits;
              }
            
              else if (opt.gzip && (opt.windowBits > 0) && (opt.windowBits < 16)) {
                opt.windowBits += 16;
              }
            
              this.err    = 0;      // error code, if happens (0 = Z_OK)
              this.msg    = '';     // error message
              this.ended  = false;  // used to avoid multiple onEnd() calls
              this.chunks = [];     // chunks of compressed data
            
              this.strm = new ZStream();
              this.strm.avail_out = 0;
            
              var status = zlib_deflate.deflateInit2(
                this.strm,
                opt.level,
                opt.method,
                opt.windowBits,
                opt.memLevel,
                opt.strategy
              );
            
              if (status !== Z_OK) {
                throw new Error(msg[status]);
              }
            
              if (opt.header) {
                zlib_deflate.deflateSetHeader(this.strm, opt.header);
              }
            
              if (opt.dictionary) {
                var dict;
                // Convert data if needed
                if (typeof opt.dictionary === 'string') {
                  // If we need to compress text, change encoding to utf8.
                  dict = strings.string2buf(opt.dictionary);
                } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
                  dict = new Uint8Array(opt.dictionary);
                } else {
                  dict = opt.dictionary;
                }
            
                status = zlib_deflate.deflateSetDictionary(this.strm, dict);
            
                if (status !== Z_OK) {
                  throw new Error(msg[status]);
                }
            
                this._dict_set = true;
              }
            }
            
            /**
             * Deflate#push(data[, mode]) -> Boolean
             * - data (Uint8Array|Array|ArrayBuffer|String): input data. Strings will be
             *   converted to utf8 byte sequence.
             * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
             *   See constants. Skipped or `false` means Z_NO_FLUSH, `true` means Z_FINISH.
             *
             * Sends input data to deflate pipe, generating [[Deflate#onData]] calls with
             * new compressed chunks. Returns `true` on success. The last data block must have
             * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
             * [[Deflate#onEnd]]. For interim explicit flushes (without ending the stream) you
             * can use mode Z_SYNC_FLUSH, keeping the compression context.
             *
             * On fail call [[Deflate#onEnd]] with error code and return false.
             *
             * We strongly recommend to use `Uint8Array` on input for best speed (output
             * array format is detected automatically). Also, don't skip last param and always
             * use the same type in your code (boolean or number). That will improve JS speed.
             *
             * For regular `Array`-s make sure all elements are [0..255].
             *
             * ##### Example
             *
             * ```javascript
             * push(chunk, false); // push one of data chunks
             * ...
             * push(chunk, true);  // push last chunk
             * ```
             **/
            Deflate.prototype.push = function (data, mode) {
              var strm = this.strm;
              var chunkSize = this.options.chunkSize;
              var status, _mode;
            
              if (this.ended) { return false; }
            
              _mode = (mode === ~~mode) ? mode : ((mode === true) ? Z_FINISH : Z_NO_FLUSH);
            
              // Convert data if needed
              if (typeof data === 'string') {
                // If we need to compress text, change encoding to utf8.
                strm.input = strings.string2buf(data);
              } else if (toString.call(data) === '[object ArrayBuffer]') {
                strm.input = new Uint8Array(data);
              } else {
                strm.input = data;
              }
            
              strm.next_in = 0;
              strm.avail_in = strm.input.length;
            
              do {
                if (strm.avail_out === 0) {
                  strm.output = new utils.Buf8(chunkSize);
                  strm.next_out = 0;
                  strm.avail_out = chunkSize;
                }
                status = zlib_deflate.deflate(strm, _mode);    /* no bad return value */
            
                if (status !== Z_STREAM_END && status !== Z_OK) {
                  this.onEnd(status);
                  this.ended = true;
                  return false;
                }
                if (strm.avail_out === 0 || (strm.avail_in === 0 && (_mode === Z_FINISH || _mode === Z_SYNC_FLUSH))) {
                  if (this.options.to === 'string') {
                    this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out)));
                  } else {
                    this.onData(utils.shrinkBuf(strm.output, strm.next_out));
                  }
                }
              } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END);
            
              // Finalize on the last chunk.
              if (_mode === Z_FINISH) {
                status = zlib_deflate.deflateEnd(this.strm);
                this.onEnd(status);
                this.ended = true;
                return status === Z_OK;
              }
            
              // callback interim results if Z_SYNC_FLUSH.
              if (_mode === Z_SYNC_FLUSH) {
                this.onEnd(Z_OK);
                strm.avail_out = 0;
                return true;
              }
            
              return true;
            };
            
            
            /**
             * Deflate#onData(chunk) -> Void
             * - chunk (Uint8Array|Array|String): output data. Type of array depends
             *   on js engine support. When string output requested, each chunk
             *   will be string.
             *
             * By default, stores data blocks in `chunks[]` property and glue
             * those in `onEnd`. Override this handler, if you need another behaviour.
             **/
            Deflate.prototype.onData = function (chunk) {
              this.chunks.push(chunk);
            };
            
            
            /**
             * Deflate#onEnd(status) -> Void
             * - status (Number): deflate status. 0 (Z_OK) on success,
             *   other if not.
             *
             * Called once after you tell deflate that the input stream is
             * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
             * or if an error happened. By default - join collected chunks,
             * free memory and fill `results` / `err` properties.
             **/
            Deflate.prototype.onEnd = function (status) {
              // On success - join
              if (status === Z_OK) {
                if (this.options.to === 'string') {
                  this.result = this.chunks.join('');
                } else {
                  this.result = utils.flattenChunks(this.chunks);
                }
              }
              this.chunks = [];
              this.err = status;
              this.msg = this.strm.msg;
            };
            
            
            /**
             * deflate(data[, options]) -> Uint8Array|Array|String
             * - data (Uint8Array|Array|String): input data to compress.
             * - options (Object): zlib deflate options.
             *
             * Compress `data` with deflate algorithm and `options`.
             *
             * Supported options are:
             *
             * - level
             * - windowBits
             * - memLevel
             * - strategy
             * - dictionary
             *
             * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
             * for more information on these.
             *
             * Sugar (options):
             *
             * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
             *   negative windowBits implicitly.
             * - `to` (String) - if equal to 'string', then result will be "binary string"
             *    (each char code [0..255])
             *
             * ##### Example:
             *
             * ```javascript
             * var pako = require('pako')
             *   , data = Uint8Array([1,2,3,4,5,6,7,8,9]);
             *
             * console.log(pako.deflate(data));
             * ```
             **/
            function deflate(input, options) {
              var deflator = new Deflate(options);
            
              deflator.push(input, true);
            
              // That will never happens, if you don't cheat with options :)
              if (deflator.err) { throw deflator.msg || msg[deflator.err]; }
            
              return deflator.result;
            }
            
            
            /**
             * deflateRaw(data[, options]) -> Uint8Array|Array|String
             * - data (Uint8Array|Array|String): input data to compress.
             * - options (Object): zlib deflate options.
             *
             * The same as [[deflate]], but creates raw data, without wrapper
             * (header and adler32 crc).
             **/
            function deflateRaw(input, options) {
              options = options || {};
              options.raw = true;
              return deflate(input, options);
            }
            
            
            /**
             * gzip(data[, options]) -> Uint8Array|Array|String
             * - data (Uint8Array|Array|String): input data to compress.
             * - options (Object): zlib deflate options.
             *
             * The same as [[deflate]], but create gzip wrapper instead of
             * deflate one.
             **/
            function gzip(input, options) {
              options = options || {};
              options.gzip = true;
              return deflate(input, options);
            }
            
            
            exports.Deflate = Deflate;
            exports.deflate = deflate;
            exports.deflateRaw = deflateRaw;
            exports.gzip = gzip;
            
            },{"./utils/common":3,"./utils/strings":4,"./zlib/deflate":8,"./zlib/messages":13,"./zlib/zstream":15}],2:[function(require,module,exports){
            'use strict';
            
            
            var zlib_inflate = require('./zlib/inflate');
            var utils        = require('./utils/common');
            var strings      = require('./utils/strings');
            var c            = require('./zlib/constants');
            var msg          = require('./zlib/messages');
            var ZStream      = require('./zlib/zstream');
            var GZheader     = require('./zlib/gzheader');
            
            var toString = Object.prototype.toString;
            
            /**
             * class Inflate
             *
             * Generic JS-style wrapper for zlib calls. If you don't need
             * streaming behaviour - use more simple functions: [[inflate]]
             * and [[inflateRaw]].
             **/
            
            /* internal
             * inflate.chunks -> Array
             *
             * Chunks of output data, if [[Inflate#onData]] not overridden.
             **/
            
            /**
             * Inflate.result -> Uint8Array|Array|String
             *
             * Uncompressed result, generated by default [[Inflate#onData]]
             * and [[Inflate#onEnd]] handlers. Filled after you push last chunk
             * (call [[Inflate#push]] with `Z_FINISH` / `true` param) or if you
             * push a chunk with explicit flush (call [[Inflate#push]] with
             * `Z_SYNC_FLUSH` param).
             **/
            
            /**
             * Inflate.err -> Number
             *
             * Error code after inflate finished. 0 (Z_OK) on success.
             * Should be checked if broken data possible.
             **/
            
            /**
             * Inflate.msg -> String
             *
             * Error message, if [[Inflate.err]] != 0
             **/
            
            
            /**
             * new Inflate(options)
             * - options (Object): zlib inflate options.
             *
             * Creates new inflator instance with specified params. Throws exception
             * on bad params. Supported options:
             *
             * - `windowBits`
             * - `dictionary`
             *
             * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
             * for more information on these.
             *
             * Additional options, for internal needs:
             *
             * - `chunkSize` - size of generated data chunks (16K by default)
             * - `raw` (Boolean) - do raw inflate
             * - `to` (String) - if equal to 'string', then result will be converted
             *   from utf8 to utf16 (javascript) string. When string output requested,
             *   chunk length can differ from `chunkSize`, depending on content.
             *
             * By default, when no options set, autodetect deflate/gzip data format via
             * wrapper header.
             *
             * ##### Example:
             *
             * ```javascript
             * var pako = require('pako')
             *   , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
             *   , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
             *
             * var inflate = new pako.Inflate({ level: 3});
             *
             * inflate.push(chunk1, false);
             * inflate.push(chunk2, true);  // true -> last chunk
             *
             * if (inflate.err) { throw new Error(inflate.err); }
             *
             * console.log(inflate.result);
             * ```
             **/
            function Inflate(options) {
              if (!(this instanceof Inflate)) return new Inflate(options);
            
              this.options = utils.assign({
                chunkSize: 16384,
                windowBits: 0,
                to: ''
              }, options || {});
            
              var opt = this.options;
            
              // Force window size for `raw` data, if not set directly,
              // because we have no header for autodetect.
              if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
                opt.windowBits = -opt.windowBits;
                if (opt.windowBits === 0) { opt.windowBits = -15; }
              }
            
              // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
              if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&
                  !(options && options.windowBits)) {
                opt.windowBits += 32;
              }
            
              // Gzip header has no info about windows size, we can do autodetect only
              // for deflate. So, if window size not set, force it to max when gzip possible
              if ((opt.windowBits > 15) && (opt.windowBits < 48)) {
                // bit 3 (16) -> gzipped data
                // bit 4 (32) -> autodetect gzip/deflate
                if ((opt.windowBits & 15) === 0) {
                  opt.windowBits |= 15;
                }
              }
            
              this.err    = 0;      // error code, if happens (0 = Z_OK)
              this.msg    = '';     // error message
              this.ended  = false;  // used to avoid multiple onEnd() calls
              this.chunks = [];     // chunks of compressed data
            
              this.strm   = new ZStream();
              this.strm.avail_out = 0;
            
              var status  = zlib_inflate.inflateInit2(
                this.strm,
                opt.windowBits
              );
            
              if (status !== c.Z_OK) {
                throw new Error(msg[status]);
              }
            
              this.header = new GZheader();
            
              zlib_inflate.inflateGetHeader(this.strm, this.header);
            
              // Setup dictionary
              if (opt.dictionary) {
                // Convert data if needed
                if (typeof opt.dictionary === 'string') {
                  opt.dictionary = strings.string2buf(opt.dictionary);
                } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
                  opt.dictionary = new Uint8Array(opt.dictionary);
                }
                if (opt.raw) { //In raw mode we need to set the dictionary early
                  status = zlib_inflate.inflateSetDictionary(this.strm, opt.dictionary);
                  if (status !== c.Z_OK) {
                    throw new Error(msg[status]);
                  }
                }
              }
            }
            
            /**
             * Inflate#push(data[, mode]) -> Boolean
             * - data (Uint8Array|Array|ArrayBuffer|String): input data
             * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
             *   See constants. Skipped or `false` means Z_NO_FLUSH, `true` means Z_FINISH.
             *
             * Sends input data to inflate pipe, generating [[Inflate#onData]] calls with
             * new output chunks. Returns `true` on success. The last data block must have
             * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
             * [[Inflate#onEnd]]. For interim explicit flushes (without ending the stream) you
             * can use mode Z_SYNC_FLUSH, keeping the decompression context.
             *
             * On fail call [[Inflate#onEnd]] with error code and return false.
             *
             * We strongly recommend to use `Uint8Array` on input for best speed (output
             * format is detected automatically). Also, don't skip last param and always
             * use the same type in your code (boolean or number). That will improve JS speed.
             *
             * For regular `Array`-s make sure all elements are [0..255].
             *
             * ##### Example
             *
             * ```javascript
             * push(chunk, false); // push one of data chunks
             * ...
             * push(chunk, true);  // push last chunk
             * ```
             **/
            Inflate.prototype.push = function (data, mode) {
              var strm = this.strm;
              var chunkSize = this.options.chunkSize;
              var dictionary = this.options.dictionary;
              var status, _mode;
              var next_out_utf8, tail, utf8str;
            
              // Flag to properly process Z_BUF_ERROR on testing inflate call
              // when we check that all output data was flushed.
              var allowBufError = false;
            
              if (this.ended) { return false; }
              _mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH);
            
              // Convert data if needed
              if (typeof data === 'string') {
                // Only binary strings can be decompressed on practice
                strm.input = strings.binstring2buf(data);
              } else if (toString.call(data) === '[object ArrayBuffer]') {
                strm.input = new Uint8Array(data);
              } else {
                strm.input = data;
              }
            
              strm.next_in = 0;
              strm.avail_in = strm.input.length;
            
              do {
                if (strm.avail_out === 0) {
                  strm.output = new utils.Buf8(chunkSize);
                  strm.next_out = 0;
                  strm.avail_out = chunkSize;
                }
            
                status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH);    /* no bad return value */
            
                if (status === c.Z_NEED_DICT && dictionary) {
                  status = zlib_inflate.inflateSetDictionary(this.strm, dictionary);
                }
            
                if (status === c.Z_BUF_ERROR && allowBufError === true) {
                  status = c.Z_OK;
                  allowBufError = false;
                }
            
                if (status !== c.Z_STREAM_END && status !== c.Z_OK) {
                  this.onEnd(status);
                  this.ended = true;
                  return false;
                }
            
                if (strm.next_out) {
                  if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && (_mode === c.Z_FINISH || _mode === c.Z_SYNC_FLUSH))) {
            
                    if (this.options.to === 'string') {
            
                      next_out_utf8 = strings.utf8border(strm.output, strm.next_out);
            
                      tail = strm.next_out - next_out_utf8;
                      utf8str = strings.buf2string(strm.output, next_out_utf8);
            
                      // move tail
                      strm.next_out = tail;
                      strm.avail_out = chunkSize - tail;
                      if (tail) { utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0); }
            
                      this.onData(utf8str);
            
                    } else {
                      this.onData(utils.shrinkBuf(strm.output, strm.next_out));
                    }
                  }
                }
            
                // When no more input data, we should check that internal inflate buffers
                // are flushed. The only way to do it when avail_out = 0 - run one more
                // inflate pass. But if output data not exists, inflate return Z_BUF_ERROR.
                // Here we set flag to process this error properly.
                //
                // NOTE. Deflate does not return error in this case and does not needs such
                // logic.
                if (strm.avail_in === 0 && strm.avail_out === 0) {
                  allowBufError = true;
                }
            
              } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== c.Z_STREAM_END);
            
              if (status === c.Z_STREAM_END) {
                _mode = c.Z_FINISH;
              }
            
              // Finalize on the last chunk.
              if (_mode === c.Z_FINISH) {
                status = zlib_inflate.inflateEnd(this.strm);
                this.onEnd(status);
                this.ended = true;
                return status === c.Z_OK;
              }
            
              // callback interim results if Z_SYNC_FLUSH.
              if (_mode === c.Z_SYNC_FLUSH) {
                this.onEnd(c.Z_OK);
                strm.avail_out = 0;
                return true;
              }
            
              return true;
            };
            
            
            /**
             * Inflate#onData(chunk) -> Void
             * - chunk (Uint8Array|Array|String): output data. Type of array depends
             *   on js engine support. When string output requested, each chunk
             *   will be string.
             *
             * By default, stores data blocks in `chunks[]` property and glue
             * those in `onEnd`. Override this handler, if you need another behaviour.
             **/
            Inflate.prototype.onData = function (chunk) {
              this.chunks.push(chunk);
            };
            
            
            /**
             * Inflate#onEnd(status) -> Void
             * - status (Number): inflate status. 0 (Z_OK) on success,
             *   other if not.
             *
             * Called either after you tell inflate that the input stream is
             * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
             * or if an error happened. By default - join collected chunks,
             * free memory and fill `results` / `err` properties.
             **/
            Inflate.prototype.onEnd = function (status) {
              // On success - join
              if (status === c.Z_OK) {
                if (this.options.to === 'string') {
                  // Glue & convert here, until we teach pako to send
                  // utf8 aligned strings to onData
                  this.result = this.chunks.join('');
                } else {
                  this.result = utils.flattenChunks(this.chunks);
                }
              }
              this.chunks = [];
              this.err = status;
              this.msg = this.strm.msg;
            };
            
            
            /**
             * inflate(data[, options]) -> Uint8Array|Array|String
             * - data (Uint8Array|Array|String): input data to decompress.
             * - options (Object): zlib inflate options.
             *
             * Decompress `data` with inflate/ungzip and `options`. Autodetect
             * format via wrapper header by default. That's why we don't provide
             * separate `ungzip` method.
             *
             * Supported options are:
             *
             * - windowBits
             *
             * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
             * for more information.
             *
             * Sugar (options):
             *
             * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
             *   negative windowBits implicitly.
             * - `to` (String) - if equal to 'string', then result will be converted
             *   from utf8 to utf16 (javascript) string. When string output requested,
             *   chunk length can differ from `chunkSize`, depending on content.
             *
             *
             * ##### Example:
             *
             * ```javascript
             * var pako = require('pako')
             *   , input = pako.deflate([1,2,3,4,5,6,7,8,9])
             *   , output;
             *
             * try {
             *   output = pako.inflate(input);
             * } catch (err)
             *   console.log(err);
             * }
             * ```
             **/
            function inflate(input, options) {
              var inflator = new Inflate(options);
            
              inflator.push(input, true);
            
              // That will never happens, if you don't cheat with options :)
              if (inflator.err) { throw inflator.msg || msg[inflator.err]; }
            
              return inflator.result;
            }
            
            
            /**
             * inflateRaw(data[, options]) -> Uint8Array|Array|String
             * - data (Uint8Array|Array|String): input data to decompress.
             * - options (Object): zlib inflate options.
             *
             * The same as [[inflate]], but creates raw data, without wrapper
             * (header and adler32 crc).
             **/
            function inflateRaw(input, options) {
              options = options || {};
              options.raw = true;
              return inflate(input, options);
            }
            
            
            /**
             * ungzip(data[, options]) -> Uint8Array|Array|String
             * - data (Uint8Array|Array|String): input data to decompress.
             * - options (Object): zlib inflate options.
             *
             * Just shortcut to [[inflate]], because it autodetects format
             * by header.content. Done for convenience.
             **/
            
            
            exports.Inflate = Inflate;
            exports.inflate = inflate;
            exports.inflateRaw = inflateRaw;
            exports.ungzip  = inflate;
            
            },{"./utils/common":3,"./utils/strings":4,"./zlib/constants":6,"./zlib/gzheader":9,"./zlib/inflate":11,"./zlib/messages":13,"./zlib/zstream":15}],3:[function(require,module,exports){
            'use strict';
            
            
            var TYPED_OK =  (typeof Uint8Array !== 'undefined') &&
                            (typeof Uint16Array !== 'undefined') &&
                            (typeof Int32Array !== 'undefined');
            
            function _has(obj, key) {
              return Object.prototype.hasOwnProperty.call(obj, key);
            }
            
            exports.assign = function (obj /*from1, from2, from3, ...*/) {
              var sources = Array.prototype.slice.call(arguments, 1);
              while (sources.length) {
                var source = sources.shift();
                if (!source) { continue; }
            
                if (typeof source !== 'object') {
                  throw new TypeError(source + 'must be non-object');
                }
            
                for (var p in source) {
                  if (_has(source, p)) {
                    obj[p] = source[p];
                  }
                }
              }