pako.js 105 KB

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