您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

pako_inflate.js 106KB

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