You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pako_inflate.js 128KB

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