Skip to content
Snippets Groups Projects
base64zip.js 305 KiB
Newer Older
Recolic's avatar
.
Recolic committed
            // 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).
             **/
            
            /**
Recolic's avatar
.
Recolic committed
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200
             * 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];
                  }
                }
              }
            
              return obj;
            };
            
            
            // reduce buffer size, avoiding mem copy
            exports.shrinkBuf = function (buf, size) {
              if (buf.length === size) { return buf; }
              if (buf.subarray) { return buf.subarray(0, size); }
              buf.length = size;
              return buf;
            };
            
            
            var fnTyped = {
              arraySet: function (dest, src, src_offs, len, dest_offs) {
                if (src.subarray && dest.subarray) {
                  dest.set(src.subarray(src_offs, src_offs + len), dest_offs);
                  return;
                }
                // Fallback to ordinary array
                for (var i = 0; i < len; i++) {
                  dest[dest_offs + i] = src[src_offs + i];
                }
              },
              // Join array of chunks to single array.
              flattenChunks: function (chunks) {
                var i, l, len, pos, chunk, result;
            
                // calculate data length
                len = 0;
                for (i = 0, l = chunks.length; i < l; i++) {
                  len += chunks[i].length;
                }
            
                // join chunks
                result = new Uint8Array(len);
                pos = 0;
                for (i = 0, l = chunks.length; i < l; i++) {
                  chunk = chunks[i];
                  result.set(chunk, pos);
                  pos += chunk.length;
                }
            
                return result;
              }
            };
            
            var fnUntyped = {
              arraySet: function (dest, src, src_offs, len, dest_offs) {
                for (var i = 0; i < len; i++) {
                  dest[dest_offs + i] = src[src_offs + i];
                }
              },
              // Join array of chunks to single array.
              flattenChunks: function (chunks) {
                return [].concat.apply([], chunks);
              }
            };
            
            
            // Enable/Disable typed arrays use, for testing
            //
            exports.setTyped = function (on) {
              if (on) {
                exports.Buf8  = Uint8Array;
                exports.Buf16 = Uint16Array;
                exports.Buf32 = Int32Array;
                exports.assign(exports, fnTyped);
              } else {
                exports.Buf8  = Array;
                exports.Buf16 = Array;
                exports.Buf32 = Array;
                exports.assign(exports, fnUntyped);
              }
            };
            
            exports.setTyped(TYPED_OK);
            
            },{}],4:[function(require,module,exports){
            // String encode/decode helpers
            'use strict';
            
            
            var utils = require('./common');
            
            
            // Quick check if we can use fast array to bin string conversion
            //
            // - apply(Array) can fail on Android 2.2
            // - apply(Uint8Array) can fail on iOS 5.1 Safari
            //
            var STR_APPLY_OK = true;
            var STR_APPLY_UIA_OK = true;
            
            try { String.fromCharCode.apply(null, [ 0 ]); } catch (__) { STR_APPLY_OK = false; }
            try { String.fromCharCode.apply(null, new Uint8Array(1)); } catch (__) { STR_APPLY_UIA_OK = false; }
            
            
            // Table with utf8 lengths (calculated by first byte of sequence)
            // Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
            // because max possible codepoint is 0x10ffff
            var _utf8len = new utils.Buf8(256);
            for (var q = 0; q < 256; q++) {
              _utf8len[q] = (q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1);
            }
            _utf8len[254] = _utf8len[254] = 1; // Invalid sequence start
            
            
            // convert string to array (typed, when possible)
            exports.string2buf = function (str) {
              var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;
            
              // count binary size
              for (m_pos = 0; m_pos < str_len; m_pos++) {
                c = str.charCodeAt(m_pos);
                if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
                  c2 = str.charCodeAt(m_pos + 1);
                  if ((c2 & 0xfc00) === 0xdc00) {
                    c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
                    m_pos++;
                  }
                }
                buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
              }
            
              // allocate buffer
              buf = new utils.Buf8(buf_len);
            
              // convert
              for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
                c = str.charCodeAt(m_pos);
                if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
                  c2 = str.charCodeAt(m_pos + 1);
                  if ((c2 & 0xfc00) === 0xdc00) {
                    c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
                    m_pos++;
                  }
                }
                if (c < 0x80) {
                  /* one byte */
                  buf[i++] = c;
                } else if (c < 0x800) {
                  /* two bytes */
                  buf[i++] = 0xC0 | (c >>> 6);
                  buf[i++] = 0x80 | (c & 0x3f);
                } else if (c < 0x10000) {
                  /* three bytes */
                  buf[i++] = 0xE0 | (c >>> 12);
                  buf[i++] = 0x80 | (c >>> 6 & 0x3f);
                  buf[i++] = 0x80 | (c & 0x3f);
                } else {
                  /* four bytes */
                  buf[i++] = 0xf0 | (c >>> 18);
                  buf[i++] = 0x80 | (c >>> 12 & 0x3f);
                  buf[i++] = 0x80 | (c >>> 6 & 0x3f);
                  buf[i++] = 0x80 | (c & 0x3f);
                }
              }
            
              return buf;
            };
            
            // Helper (used in 2 places)
            function buf2binstring(buf, len) {
              // On Chrome, the arguments in a function call that are allowed is `65534`.
              // If the length of the buffer is smaller than that, we can use this optimization,
              // otherwise we will take a slower path.
              if (len < 65534) {
                if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) {
                  return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));
                }
              }
            
              var result = '';
              for (var i = 0; i < len; i++) {
                result += String.fromCharCode(buf[i]);
              }
              return result;
            }
            
            
            // Convert byte array to binary string
            exports.buf2binstring = function (buf) {
              return buf2binstring(buf, buf.length);
            };
            
            
            // Convert binary string (typed, when possible)
            exports.binstring2buf = function (str) {
              var buf = new utils.Buf8(str.length);
              for (var i = 0, len = buf.length; i < len; i++) {
                buf[i] = str.charCodeAt(i);
              }
              return buf;
            };
            
            
            // convert array to string
            exports.buf2string = function (buf, max) {
              var i, out, c, c_len;
              var len = max || buf.length;
            
              // Reserve max possible length (2 words per char)
              // NB: by unknown reasons, Array is significantly faster for
              //     String.fromCharCode.apply than Uint16Array.
              var utf16buf = new Array(len * 2);
            
              for (out = 0, i = 0; i < len;) {
                c = buf[i++];
                // quick process ascii
                if (c < 0x80) { utf16buf[out++] = c; continue; }
            
                c_len = _utf8len[c];
                // skip 5 & 6 byte codes
                if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len - 1; continue; }
            
                // apply mask on first byte
                c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
                // join the rest
                while (c_len > 1 && i < len) {
                  c = (c << 6) | (buf[i++] & 0x3f);
                  c_len--;
                }
            
                // terminated by end of string?
                if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }
            
                if (c < 0x10000) {
                  utf16buf[out++] = c;
                } else {
                  c -= 0x10000;
                  utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);
                  utf16buf[out++] = 0xdc00 | (c & 0x3ff);
                }
              }
            
              return buf2binstring(utf16buf, out);
            };
            
            
            // Calculate max possible position in utf8 buffer,
            // that will not break sequence. If that's not possible
            // - (very small limits) return max size as is.
            //
            // buf[] - utf8 bytes array
            // max   - length limit (mandatory);
            exports.utf8border = function (buf, max) {
              var pos;
            
              max = max || buf.length;
              if (max > buf.length) { max = buf.length; }
            
              // go back from last position, until start of sequence found
              pos = max - 1;
              while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }
            
              // Very small and broken sequence,
              // return max, because we should return something anyway.
              if (pos < 0) { return max; }
            
              // If we came to start of buffer - that means buffer is too small,
              // return max too.
              if (pos === 0) { return max; }
            
              return (pos + _utf8len[buf[pos]] > max) ? pos : max;
            };
            
            },{"./common":3}],5:[function(require,module,exports){
            'use strict';
            
            // Note: adler32 takes 12% for level 0 and 2% for level 6.
            // It isn't worth it to make additional optimizations as in original.
            // Small size is preferable.
            
            // (C) 1995-2013 Jean-loup Gailly and Mark Adler
            // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
            //
            // This software is provided 'as-is', without any express or implied
            // warranty. In no event will the authors be held liable for any damages
            // arising from the use of this software.
            //
            // Permission is granted to anyone to use this software for any purpose,
            // including commercial applications, and to alter it and redistribute it
            // freely, subject to the following restrictions:
            //
            // 1. The origin of this software must not be misrepresented; you must not
            //   claim that you wrote the original software. If you use this software
            //   in a product, an acknowledgment in the product documentation would be
            //   appreciated but is not required.
            // 2. Altered source versions must be plainly marked as such, and must not be
            //   misrepresented as being the original software.
            // 3. This notice may not be removed or altered from any source distribution.
            
            function adler32(adler, buf, len, pos) {
              var s1 = (adler & 0xffff) |0,
                  s2 = ((adler >>> 16) & 0xffff) |0,
                  n = 0;
            
              while (len !== 0) {
                // Set limit ~ twice less than 5552, to keep
                // s2 in 31-bits, because we force signed ints.
                // in other case %= will fail.
                n = len > 2000 ? 2000 : len;
                len -= n;
            
                do {
                  s1 = (s1 + buf[pos++]) |0;
                  s2 = (s2 + s1) |0;
                } while (--n);
            
                s1 %= 65521;
                s2 %= 65521;
              }
            
              return (s1 | (s2 << 16)) |0;
            }
            
            
            module.exports = adler32;
            
            },{}],6:[function(require,module,exports){
            'use strict';
            
            // (C) 1995-2013 Jean-loup Gailly and Mark Adler
            // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
            //
            // This software is provided 'as-is', without any express or implied
            // warranty. In no event will the authors be held liable for any damages
            // arising from the use of this software.
            //
            // Permission is granted to anyone to use this software for any purpose,
            // including commercial applications, and to alter it and redistribute it
            // freely, subject to the following restrictions:
            //
            // 1. The origin of this software must not be misrepresented; you must not
            //   claim that you wrote the original software. If you use this software
            //   in a product, an acknowledgment in the product documentation would be
            //   appreciated but is not required.
            // 2. Altered source versions must be plainly marked as such, and must not be
            //   misrepresented as being the original software.
            // 3. This notice may not be removed or altered from any source distribution.
            
            module.exports = {
            
              /* Allowed flush values; see deflate() and inflate() below for details */
              Z_NO_FLUSH:         0,
              Z_PARTIAL_FLUSH:    1,
              Z_SYNC_FLUSH:       2,
              Z_FULL_FLUSH:       3,
              Z_FINISH:           4,
              Z_BLOCK:            5,
              Z_TREES:            6,
            
              /* Return codes for the compression/decompression functions. Negative values
              * are errors, positive values are used for special but normal events.
              */
              Z_OK:               0,
              Z_STREAM_END:       1,
              Z_NEED_DICT:        2,
              Z_ERRNO:           -1,
              Z_STREAM_ERROR:    -2,
              Z_DATA_ERROR:      -3,
              //Z_MEM_ERROR:     -4,
              Z_BUF_ERROR:       -5,
              //Z_VERSION_ERROR: -6,
            
              /* compression levels */
              Z_NO_COMPRESSION:         0,
              Z_BEST_SPEED:             1,
              Z_BEST_COMPRESSION:       9,
              Z_DEFAULT_COMPRESSION:   -1,
            
            
              Z_FILTERED:               1,
              Z_HUFFMAN_ONLY:           2,
              Z_RLE:                    3,
              Z_FIXED:                  4,
              Z_DEFAULT_STRATEGY:       0,
            
              /* Possible values of the data_type field (though see inflate()) */
              Z_BINARY:                 0,
              Z_TEXT:                   1,
              //Z_ASCII:                1, // = Z_TEXT (deprecated)
              Z_UNKNOWN:                2,
            
              /* The deflate compression method */
              Z_DEFLATED:               8
              //Z_NULL:                 null // Use -1 or null inline, depending on var type
            };
            
            },{}],7:[function(require,module,exports){
            'use strict';
            
            // Note: we can't get significant speed boost here.
            // So write code to minimize size - no pregenerated tables
            // and array tools dependencies.
            
            // (C) 1995-2013 Jean-loup Gailly and Mark Adler
            // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
            //
            // This software is provided 'as-is', without any express or implied
            // warranty. In no event will the authors be held liable for any damages
            // arising from the use of this software.
            //
            // Permission is granted to anyone to use this software for any purpose,
            // including commercial applications, and to alter it and redistribute it
            // freely, subject to the following restrictions:
            //
            // 1. The origin of this software must not be misrepresented; you must not
            //   claim that you wrote the original software. If you use this software
            //   in a product, an acknowledgment in the product documentation would be
            //   appreciated but is not required.
            // 2. Altered source versions must be plainly marked as such, and must not be
            //   misrepresented as being the original software.
            // 3. This notice may not be removed or altered from any source distribution.
            
            // Use ordinary array, since untyped makes no boost here
            function makeTable() {
              var c, table = [];
            
              for (var n = 0; n < 256; n++) {
                c = n;
                for (var k = 0; k < 8; k++) {
                  c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
                }
                table[n] = c;
              }
            
              return table;
            }
            
            // Create table on load. Just 255 signed longs. Not a problem.
            var crcTable = makeTable();
            
            
            function crc32(crc, buf, len, pos) {
              var t = crcTable,
                  end = pos + len;
            
              crc ^= -1;
            
              for (var i = pos; i < end; i++) {
                crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];
              }
            
              return (crc ^ (-1)); // >>> 0;
            }
            
            
            module.exports = crc32;
            
            },{}],8:[function(require,module,exports){
            'use strict';
            
            // (C) 1995-2013 Jean-loup Gailly and Mark Adler
            // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
            //
            // This software is provided 'as-is', without any express or implied
            // warranty. In no event will the authors be held liable for any damages
            // arising from the use of this software.
            //
            // Permission is granted to anyone to use this software for any purpose,
            // including commercial applications, and to alter it and redistribute it
            // freely, subject to the following restrictions:
            //
            // 1. The origin of this software must not be misrepresented; you must not
            //   claim that you wrote the original software. If you use this software
            //   in a product, an acknowledgment in the product documentation would be
            //   appreciated but is not required.
            // 2. Altered source versions must be plainly marked as such, and must not be
            //   misrepresented as being the original software.
            // 3. This notice may not be removed or altered from any source distribution.
            
            var utils   = require('../utils/common');
            var trees   = require('./trees');
            var adler32 = require('./adler32');
            var crc32   = require('./crc32');
            var msg     = require('./messages');
            
            /* Public constants ==========================================================*/
            /* ===========================================================================*/
            
            
            /* Allowed flush values; see deflate() and inflate() below for details */
            var Z_NO_FLUSH      = 0;
            var Z_PARTIAL_FLUSH = 1;
            //var Z_SYNC_FLUSH    = 2;
            var Z_FULL_FLUSH    = 3;
            var Z_FINISH        = 4;
            var Z_BLOCK         = 5;
            //var Z_TREES         = 6;
            
            
            /* Return codes for the compression/decompression functions. Negative values
             * are errors, positive values are used for special but normal events.
             */
            var Z_OK            = 0;
            var Z_STREAM_END    = 1;
            //var Z_NEED_DICT     = 2;
            //var Z_ERRNO         = -1;
            var Z_STREAM_ERROR  = -2;
            var Z_DATA_ERROR    = -3;
            //var Z_MEM_ERROR     = -4;
            var Z_BUF_ERROR     = -5;
            //var Z_VERSION_ERROR = -6;
            
            
            /* compression levels */
            //var Z_NO_COMPRESSION      = 0;
            //var Z_BEST_SPEED          = 1;
            //var Z_BEST_COMPRESSION    = 9;
            var Z_DEFAULT_COMPRESSION = -1;
            
            
            var Z_FILTERED            = 1;
            var Z_HUFFMAN_ONLY        = 2;
            var Z_RLE                 = 3;
            var Z_FIXED               = 4;
            var Z_DEFAULT_STRATEGY    = 0;
            
            /* Possible values of the data_type field (though see inflate()) */
            //var Z_BINARY              = 0;
            //var Z_TEXT                = 1;
            //var Z_ASCII               = 1; // = Z_TEXT
            var Z_UNKNOWN             = 2;
            
            
            /* The deflate compression method */
            var Z_DEFLATED  = 8;
            
            /*============================================================================*/
            
            
            var MAX_MEM_LEVEL = 9;
            /* Maximum value for memLevel in deflateInit2 */
            var MAX_WBITS = 15;
            /* 32K LZ77 window */
            var DEF_MEM_LEVEL = 8;
            
            
            var LENGTH_CODES  = 29;
            /* number of length codes, not counting the special END_BLOCK code */
            var LITERALS      = 256;
            /* number of literal bytes 0..255 */
            var L_CODES       = LITERALS + 1 + LENGTH_CODES;
            /* number of Literal or Length codes, including the END_BLOCK code */
            var D_CODES       = 30;
            /* number of distance codes */
            var BL_CODES      = 19;
            /* number of codes used to transfer the bit lengths */
            var HEAP_SIZE     = 2 * L_CODES + 1;
            /* maximum heap size */
            var MAX_BITS  = 15;
            /* All codes must not exceed MAX_BITS bits */
            
            var MIN_MATCH = 3;
            var MAX_MATCH = 258;
            var MIN_LOOKAHEAD = (MAX_MATCH + MIN_MATCH + 1);
            
            var PRESET_DICT = 0x20;
            
            var INIT_STATE = 42;
            var EXTRA_STATE = 69;
            var NAME_STATE = 73;
            var COMMENT_STATE = 91;
            var HCRC_STATE = 103;
            var BUSY_STATE = 113;
            var FINISH_STATE = 666;
            
            var BS_NEED_MORE      = 1; /* block not completed, need more input or more output */
            var BS_BLOCK_DONE     = 2; /* block flush performed */
            var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */
            var BS_FINISH_DONE    = 4; /* finish done, accept no more input or output */
            
            var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.
            
            function err(strm, errorCode) {
              strm.msg = msg[errorCode];
              return errorCode;
            }
            
            function rank(f) {
              return ((f) << 1) - ((f) > 4 ? 9 : 0);
            }
            
            function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
            
            
            /* =========================================================================
             * Flush as much pending output as possible. All deflate() output goes
             * through this function so some applications may wish to modify it
             * to avoid allocating a large strm->output buffer and copying into it.
             * (See also read_buf()).
             */
            function flush_pending(strm) {
              var s = strm.state;
            
              //_tr_flush_bits(s);
              var len = s.pending;
              if (len > strm.avail_out) {
                len = strm.avail_out;
              }
              if (len === 0) { return; }
            
              utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);
              strm.next_out += len;
              s.pending_out += len;
              strm.total_out += len;
              strm.avail_out -= len;
              s.pending -= len;
              if (s.pending === 0) {
                s.pending_out = 0;
              }
            }
            
            
            function flush_block_only(s, last) {
              trees._tr_flush_block(s, (s.block_start >= 0 ? s.block_start : -1), s.strstart - s.block_start, last);
              s.block_start = s.strstart;
              flush_pending(s.strm);
            }
            
            
            function put_byte(s, b) {
              s.pending_buf[s.pending++] = b;
            }
            
            
            /* =========================================================================
             * Put a short in the pending buffer. The 16-bit value is put in MSB order.
             * IN assertion: the stream state is correct and there is enough room in
             * pending_buf.
             */
            function putShortMSB(s, b) {
            //  put_byte(s, (Byte)(b >> 8));
            //  put_byte(s, (Byte)(b & 0xff));
              s.pending_buf[s.pending++] = (b >>> 8) & 0xff;
              s.pending_buf[s.pending++] = b & 0xff;
            }
            
            
            /* ===========================================================================
             * Read a new buffer from the current input stream, update the adler32
             * and total number of bytes read.  All deflate() input goes through
             * this function so some applications may wish to modify it to avoid
             * allocating a large strm->input buffer and copying from it.
             * (See also flush_pending()).
             */
            function read_buf(strm, buf, start, size) {
              var len = strm.avail_in;
            
              if (len > size) { len = size; }
              if (len === 0) { return 0; }
            
              strm.avail_in -= len;
            
              // zmemcpy(buf, strm->next_in, len);
              utils.arraySet(buf, strm.input, strm.next_in, len, start);
              if (strm.state.wrap === 1) {
                strm.adler = adler32(strm.adler, buf, len, start);
              }
            
              else if (strm.state.wrap === 2) {
                strm.adler = crc32(strm.adler, buf, len, start);
              }
            
              strm.next_in += len;
              strm.total_in += len;
            
              return len;
            }
            
            
            /* ===========================================================================
             * Set match_start to the longest match starting at the given string and
             * return its length. Matches shorter or equal to prev_length are discarded,
             * in which case the result is equal to prev_length and match_start is
             * garbage.
             * IN assertions: cur_match is the head of the hash chain for the current
             *   string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
             * OUT assertion: the match length is not greater than s->lookahead.
             */
            function longest_match(s, cur_match) {
              var chain_length = s.max_chain_length;      /* max hash chain length */
              var scan = s.strstart; /* current string */
              var match;                       /* matched string */
              var len;                           /* length of current match */
              var best_len = s.prev_length;              /* best match length so far */
              var nice_match = s.nice_match;             /* stop if match long enough */
              var limit = (s.strstart > (s.w_size - MIN_LOOKAHEAD)) ?
                  s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0/*NIL*/;
            
              var _win = s.window; // shortcut
            
              var wmask = s.w_mask;
              var prev  = s.prev;
            
              /* Stop when cur_match becomes <= limit. To simplify the code,
               * we prevent matches with the string of window index 0.
               */
            
              var strend = s.strstart + MAX_MATCH;
              var scan_end1  = _win[scan + best_len - 1];
              var scan_end   = _win[scan + best_len];
            
              /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
               * It is easy to get rid of this optimization if necessary.
               */
              // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
            
              /* Do not waste too much time if we already have a good match: */
              if (s.prev_length >= s.good_match) {
                chain_length >>= 2;
              }
              /* Do not look for matches beyond the end of the input. This is necessary
               * to make deflate deterministic.
               */
              if (nice_match > s.lookahead) { nice_match = s.lookahead; }
            
              // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
            
              do {
                // Assert(cur_match < s->strstart, "no future");
                match = cur_match;
            
                /* Skip to next match if the match length cannot increase
                 * or if the match length is less than 2.  Note that the checks below
                 * for insufficient lookahead only occur occasionally for performance
                 * reasons.  Therefore uninitialized memory will be accessed, and
                 * conditional jumps will be made that depend on those values.
                 * However the length of the match is limited to the lookahead, so
                 * the output of deflate is not affected by the uninitialized values.
                 */
            
                if (_win[match + best_len]     !== scan_end  ||
                    _win[match + best_len - 1] !== scan_end1 ||
                    _win[match]                !== _win[scan] ||
                    _win[++match]              !== _win[scan + 1]) {
                  continue;
                }
            
                /* The check at best_len-1 can be removed because it will be made
                 * again later. (This heuristic is not always a win.)
                 * It is not necessary to compare scan[2] and match[2] since they
                 * are always equal when the other bytes match, given that
                 * the hash keys are equal and that HASH_BITS >= 8.
                 */
                scan += 2;
                match++;
                // Assert(*scan == *match, "match[2]?");
            
                /* We check for insufficient lookahead only every 8th comparison;
                 * the 256th check will be made at strstart+258.
                 */
                do {
                  /*jshint noempty:false*/
                } while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
                         _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
                         _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
                         _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
                         scan < strend);
            
                // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
            
                len = MAX_MATCH - (strend - scan);
                scan = strend - MAX_MATCH;
            
                if (len > best_len) {
                  s.match_start = cur_match;
                  best_len = len;
                  if (len >= nice_match) {
                    break;
                  }
                  scan_end1  = _win[scan + best_len - 1];
                  scan_end   = _win[scan + best_len];
                }
              } while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0);
            
              if (best_len <= s.lookahead) {
                return best_len;
              }
              return s.lookahead;
            }
            
            
            /* ===========================================================================
             * Fill the window when the lookahead becomes insufficient.
             * Updates strstart and lookahead.
             *
             * IN assertion: lookahead < MIN_LOOKAHEAD
             * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
             *    At least one byte has been read, or avail_in == 0; reads are
             *    performed for at least two bytes (required for the zip translate_eol
             *    option -- not supported here).
             */
            function fill_window(s) {
              var _w_size = s.w_size;
              var p, n, m, more, str;
            
              //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
            
              do {
                more = s.window_size - s.lookahead - s.strstart;
            
                // JS ints have 32 bit, block below not needed
                /* Deal with !@#$% 64K limit: */
                //if (sizeof(int) <= 2) {
                //    if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
                //        more = wsize;
                //
                //  } else if (more == (unsigned)(-1)) {
                //        /* Very unlikely, but possible on 16 bit machine if
                //         * strstart == 0 && lookahead == 1 (input done a byte at time)
                //         */
                //        more--;
                //    }
                //}
            
            
                /* If the window is almost full and there is insufficient lookahead,
                 * move the upper half to the lower one to make room in the upper half.
                 */
                if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {
            
                  utils.arraySet(s.window, s.window, _w_size, _w_size, 0);
                  s.match_start -= _w_size;
                  s.strstart -= _w_size;
                  /* we now have strstart >= MAX_DIST */
                  s.block_start -= _w_size;
            
                  /* Slide the hash table (could be avoided with 32 bit values
                   at the expense of memory usage). We slide even when level == 0
                   to keep the hash table consistent if we switch back to level > 0
                   later. (Using level 0 permanently is not an optimal usage of
                   zlib, so we don't care about this pathological case.)
                   */
            
                  n = s.hash_size;
                  p = n;
                  do {
                    m = s.head[--p];
                    s.head[p] = (m >= _w_size ? m - _w_size : 0);
                  } while (--n);
            
                  n = _w_size;
                  p = n;
                  do {
                    m = s.prev[--p];
                    s.prev[p] = (m >= _w_size ? m - _w_size : 0);
                    /* If n is not on any hash chain, prev[n] is garbage but
                     * its value will never be used.
                     */
                  } while (--n);
            
                  more += _w_size;
                }
                if (s.strm.avail_in === 0) {
                  break;
                }
            
                /* If there was no sliding:
                 *    strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
                 *    more == window_size - lookahead - strstart
                 * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
                 * => more >= window_size - 2*WSIZE + 2
                 * In the BIG_MEM or MMAP case (not yet supported),
                 *   window_size == input_size + MIN_LOOKAHEAD  &&
                 *   strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
                 * Otherwise, window_size == 2*WSIZE so more >= 2.
                 * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
                 */
                //Assert(more >= 2, "more < 2");
                n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);
                s.lookahead += n;
            
                /* Initialize the hash value now that we have some input: */
                if (s.lookahead + s.insert >= MIN_MATCH) {
                  str = s.strstart - s.insert;
                  s.ins_h = s.window[str];
            
                  /* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */
                  s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + 1]) & s.hash_mask;
            //#if MIN_MATCH != 3
            //        Call update_hash() MIN_MATCH-3 more times
            //#endif
                  while (s.insert) {
                    /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
                    s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
            
                    s.prev[str & s.w_mask] = s.head[s.ins_h];
                    s.head[s.ins_h] = str;
                    str++;
                    s.insert--;
                    if (s.lookahead + s.insert < MIN_MATCH) {
                      break;
                    }
                  }
                }
                /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
                 * but this is not important since only literal bytes will be emitted.
                 */
            
              } while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0);
            
              /* If the WIN_INIT bytes after the end of the current data have never been
               * written, then zero those bytes in order to avoid memory check reports of
               * the use of uninitialized (or uninitialised as Julian writes) bytes by
               * the longest match routines.  Update the high water mark for the next
               * time through here.  WIN_INIT is set to MAX_MATCH since the longest match
               * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
               */
            //  if (s.high_water < s.window_size) {
            //    var curr = s.strstart + s.lookahead;
            //    var init = 0;
            //
            //    if (s.high_water < curr) {
            //      /* Previous high water mark below current data -- zero WIN_INIT
            //       * bytes or up to end of window, whichever is less.
            //       */
            //      init = s.window_size - curr;
            //      if (init > WIN_INIT)
            //        init = WIN_INIT;
            //      zmemzero(s->window + curr, (unsigned)init);
            //      s->high_water = curr + init;
            //    }
            //    else if (s->high_water < (ulg)curr + WIN_INIT) {
            //      /* High water mark at or above current data, but below current data
            //       * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
            //       * to end of window, whichever is less.
            //       */
            //      init = (ulg)curr + WIN_INIT - s->high_water;
            //      if (init > s->window_size - s->high_water)
            //        init = s->window_size - s->high_water;
            //      zmemzero(s->window + s->high_water, (unsigned)init);
            //      s->high_water += init;
            //    }
            //  }
            //
            //  Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
            //    "not enough room for search");
            }
            
            /* ===========================================================================
             * Copy without compression as much as possible from the input stream, return
             * the current block state.
             * This function does not insert new strings in the dictionary since
             * uncompressible data is probably not useful. This function is used
             * only for the level=0 compression option.
             * NOTE: this function should be optimized to avoid extra copying from
             * window to pending_buf.
             */
            function deflate_stored(s, flush) {
              /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
               * to pending_buf_size, and each stored block has a 5 byte header:
               */
              var max_block_size = 0xffff;
            
              if (max_block_size > s.pending_buf_size - 5) {
                max_block_size = s.pending_buf_size - 5;
              }
            
              /* Copy as much as possible from input to output: */
              for (;;) {
                /* Fill the window as much as possible: */
                if (s.lookahead <= 1) {
            
                  //Assert(s->strstart < s->w_size+MAX_DIST(s) ||
                  //  s->block_start >= (long)s->w_size, "slide too late");
            //      if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) ||
            //        s.block_start >= s.w_size)) {
            //        throw  new Error("slide too late");
            //      }
            
                  fill_window(s);
                  if (s.lookahead === 0 && flush === Z_NO_FLUSH) {
                    return BS_NEED_MORE;
                  }
            
                  if (s.lookahead === 0) {
                    break;
                  }
                  /* flush the current block */
                }
                //Assert(s->block_start >= 0L, "block gone");
            //    if (s.block_start < 0) throw new Error("block gone");
            
                s.strstart += s.lookahead;
                s.lookahead = 0;
            
                /* Emit a stored block if pending_buf will be full: */
                var max_start = s.block_start + max_block_size;
            
                if (s.strstart === 0 || s.strstart >= max_start) {
                  /* strstart == 0 is possible when wraparound on 16-bit machine */
                  s.lookahead = s.strstart - max_start;
                  s.strstart = max_start;
                  /*** FLUSH_BLOCK(s, 0); ***/
                  flush_block_only(s, false);
                  if (s.strm.avail_out === 0) {
                    return BS_NEED_MORE;
                  }
                  /***/
            
            
                }
                /* Flush if we may have to slide, otherwise block_start may become
                 * negative and the data will be gone:
                 */
                if (s.strstart - s.block_start >= (s.w_size - MIN_LOOKAHEAD)) {
                  /*** FLUSH_BLOCK(s, 0); ***/
                  flush_block_only(s, false);
                  if (s.strm.avail_out === 0) {
                    return BS_NEED_MORE;
                  }
                  /***/
                }
              }
            
              s.insert = 0;
            
              if (flush === Z_FINISH) {
                /*** FLUSH_BLOCK(s, 1); ***/
                flush_block_only(s, true);
                if (s.strm.avail_out === 0) {
                  return BS_FINISH_STARTED;
                }
                /***/
                return BS_FINISH_DONE;
              }
            
              if (s.strstart > s.block_start) {
                /*** FLUSH_BLOCK(s, 0); ***/
                flush_block_only(s, false);
                if (s.strm.avail_out === 0) {
                  return BS_NEED_MORE;
                }
                /***/
              }
            
              return BS_NEED_MORE;
            }
            
            /* ===========================================================================
             * Compress as much as possible from the input stream, return the current
             * block state.
             * This function does not perform lazy evaluation of matches and inserts
             * new strings in the dictionary only for unmatched strings or for short
             * matches. It is used only for the fast compression options.
             */
            function deflate_fast(s, flush) {
              var hash_head;        /* head of the hash chain */
              var bflush;           /* set if current block must be flushed */
            
              for (;;) {
                /* Make sure that we always have enough lookahead, except
                 * at the end of the input file. We need MAX_MATCH bytes
                 * for the next match, plus MIN_MATCH bytes to insert the
                 * string following the next match.
                 */
                if (s.lookahead < MIN_LOOKAHEAD) {
                  fill_window(s);
                  if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
                    return BS_NEED_MORE;
                  }
                  if (s.lookahead === 0) {
                    break; /* flush the current block */
                  }
                }
            
                /* Insert the string window[strstart .. strstart+2] in the
                 * dictionary, and set hash_head to the head of the hash chain:
                 */
                hash_head = 0/*NIL*/;
                if (s.lookahead >= MIN_MATCH) {
                  /*** INSERT_STRING(s, s.strstart, hash_head); ***/
                  s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
                  hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
                  s.head[s.ins_h] = s.strstart;
                  /***/
                }
            
                /* Find the longest match, discarding those <= prev_length.
                 * At this point we have always match_length < MIN_MATCH
                 */
                if (hash_head !== 0/*NIL*/ && ((s.strstart - hash_head) <= (s.w_size - MIN_LOOKAHEAD))) {
                  /* To simplify the code, we prevent matches with the string
                   * of window index 0 (in particular we have to avoid a match
                   * of the string with itself at the start of the input file).
                   */
                  s.match_length = longest_match(s, hash_head);
                  /* longest_match() sets match_start */
                }
                if (s.match_length >= MIN_MATCH) {
                  // check_match(s, s.strstart, s.match_start, s.match_length); // for debug only
            
                  /*** _tr_tally_dist(s, s.strstart - s.match_start,
                                 s.match_length - MIN_MATCH, bflush); ***/
                  bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);
            
                  s.lookahead -= s.match_length;
            
                  /* Insert new strings in the hash table only if the match length
                   * is not too large. This saves time but degrades compression.
                   */
                  if (s.match_length <= s.max_lazy_match/*max_insert_length*/ && s.lookahead >= MIN_MATCH) {
                    s.match_length--; /* string at strstart already in table */
                    do {
                      s.strstart++;
                      /*** INSERT_STRING(s, s.strstart, hash_head); ***/
                      s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
                      hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
                      s.head[s.ins_h] = s.strstart;
                      /***/
                      /* strstart never exceeds WSIZE-MAX_MATCH, so there are
                       * always MIN_MATCH bytes ahead.
                       */
                    } while (--s.match_length !== 0);
                    s.strstart++;
                  } else
                  {
                    s.strstart += s.match_length;
                    s.match_length = 0;
                    s.ins_h = s.window[s.strstart];
                    /* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */
                    s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + 1]) & s.hash_mask;
            
            //#if MIN_MATCH != 3
            //                Call UPDATE_HASH() MIN_MATCH-3 more times
            //#endif
                    /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
                     * matter since it will be recomputed at next deflate call.
                     */
                  }
                } else {
                  /* No match, output a literal byte */
                  //Tracevv((stderr,"%c", s.window[s.strstart]));
                  /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
                  bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
            
                  s.lookahead--;
                  s.strstart++;
                }
                if (bflush) {
                  /*** FLUSH_BLOCK(s, 0); ***/
                  flush_block_only(s, false);
                  if (s.strm.avail_out === 0) {
                    return BS_NEED_MORE;
                  }
                  /***/
                }
              }
              s.insert = ((s.strstart < (MIN_MATCH - 1)) ? s.strstart : MIN_MATCH - 1);
              if (flush === Z_FINISH) {
                /*** FLUSH_BLOCK(s, 1); ***/
                flush_block_only(s, true);
                if (s.strm.avail_out === 0) {
                  return BS_FINISH_STARTED;
                }
                /***/
                return BS_FINISH_DONE;
              }
              if (s.last_lit) {
                /*** FLUSH_BLOCK(s, 0); ***/
                flush_block_only(s, false);
                if (s.strm.avail_out === 0) {
                  return BS_NEED_MORE;
                }
                /***/
              }
              return BS_BLOCK_DONE;
            }
            
            /* ===========================================================================
             * Same as above, but achieves better compression. We use a lazy
             * evaluation for matches: a match is finally adopted only if there is
             * no better match at the next window position.
             */
            function deflate_slow(s, flush) {
              var hash_head;          /* head of hash chain */
              var bflush;              /* set if current block must be flushed */
            
              var max_insert;
            
              /* Process the input block. */
              for (;;) {
                /* Make sure that we always have enough lookahead, except
                 * at the end of the input file. We need MAX_MATCH bytes
                 * for the next match, plus MIN_MATCH bytes to insert the
                 * string following the next match.
                 */
                if (s.lookahead < MIN_LOOKAHEAD) {
                  fill_window(s);
                  if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
                    return BS_NEED_MORE;
                  }
                  if (s.lookahead === 0) { break; } /* flush the current block */
                }
            
                /* Insert the string window[strstart .. strstart+2] in the
                 * dictionary, and set hash_head to the head of the hash chain:
Loading
Loading full blame...