pako.es5.js 233 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688
  1. /*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */
  2. (function (global, factory) {
  3. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  4. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  5. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.pako = {}));
  6. })(this, (function (exports) { 'use strict';
  7. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  8. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  9. //
  10. // This software is provided 'as-is', without any express or implied
  11. // warranty. In no event will the authors be held liable for any damages
  12. // arising from the use of this software.
  13. //
  14. // Permission is granted to anyone to use this software for any purpose,
  15. // including commercial applications, and to alter it and redistribute it
  16. // freely, subject to the following restrictions:
  17. //
  18. // 1. The origin of this software must not be misrepresented; you must not
  19. // claim that you wrote the original software. If you use this software
  20. // in a product, an acknowledgment in the product documentation would be
  21. // appreciated but is not required.
  22. // 2. Altered source versions must be plainly marked as such, and must not be
  23. // misrepresented as being the original software.
  24. // 3. This notice may not be removed or altered from any source distribution.
  25. /* eslint-disable space-unary-ops */
  26. /* Public constants ==========================================================*/
  27. /* ===========================================================================*/
  28. //const Z_FILTERED = 1;
  29. //const Z_HUFFMAN_ONLY = 2;
  30. //const Z_RLE = 3;
  31. var Z_FIXED$1 = 4;
  32. //const Z_DEFAULT_STRATEGY = 0;
  33. /* Possible values of the data_type field (though see inflate()) */
  34. var Z_BINARY = 0;
  35. var Z_TEXT = 1;
  36. //const Z_ASCII = 1; // = Z_TEXT
  37. var Z_UNKNOWN$1 = 2;
  38. /*============================================================================*/
  39. function zero$1(buf) {
  40. var len = buf.length;
  41. while (--len >= 0) {
  42. buf[len] = 0;
  43. }
  44. }
  45. // From zutil.h
  46. var STORED_BLOCK = 0;
  47. var STATIC_TREES = 1;
  48. var DYN_TREES = 2;
  49. /* The three kinds of block type */
  50. var MIN_MATCH$1 = 3;
  51. var MAX_MATCH$1 = 258;
  52. /* The minimum and maximum match lengths */
  53. // From deflate.h
  54. /* ===========================================================================
  55. * Internal compression state.
  56. */
  57. var LENGTH_CODES$1 = 29;
  58. /* number of length codes, not counting the special END_BLOCK code */
  59. var LITERALS$1 = 256;
  60. /* number of literal bytes 0..255 */
  61. var L_CODES$1 = LITERALS$1 + 1 + LENGTH_CODES$1;
  62. /* number of Literal or Length codes, including the END_BLOCK code */
  63. var D_CODES$1 = 30;
  64. /* number of distance codes */
  65. var BL_CODES$1 = 19;
  66. /* number of codes used to transfer the bit lengths */
  67. var HEAP_SIZE$1 = 2 * L_CODES$1 + 1;
  68. /* maximum heap size */
  69. var MAX_BITS$1 = 15;
  70. /* All codes must not exceed MAX_BITS bits */
  71. var Buf_size = 16;
  72. /* size of bit buffer in bi_buf */
  73. /* ===========================================================================
  74. * Constants
  75. */
  76. var MAX_BL_BITS = 7;
  77. /* Bit length codes must not exceed MAX_BL_BITS bits */
  78. var END_BLOCK = 256;
  79. /* end of block literal code */
  80. var REP_3_6 = 16;
  81. /* repeat previous bit length 3-6 times (2 bits of repeat count) */
  82. var REPZ_3_10 = 17;
  83. /* repeat a zero length 3-10 times (3 bits of repeat count) */
  84. var REPZ_11_138 = 18;
  85. /* repeat a zero length 11-138 times (7 bits of repeat count) */
  86. /* eslint-disable comma-spacing,array-bracket-spacing */
  87. var extra_lbits = /* extra bits for each length code */
  88. new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0]);
  89. var extra_dbits = /* extra bits for each distance code */
  90. new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13]);
  91. var extra_blbits = /* extra bits for each bit length code */
  92. new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7]);
  93. var bl_order = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
  94. /* eslint-enable comma-spacing,array-bracket-spacing */
  95. /* The lengths of the bit length codes are sent in order of decreasing
  96. * probability, to avoid transmitting the lengths for unused bit length codes.
  97. */
  98. /* ===========================================================================
  99. * Local data. These are initialized only once.
  100. */
  101. // We pre-fill arrays with 0 to avoid uninitialized gaps
  102. var DIST_CODE_LEN = 512; /* see definition of array dist_code below */
  103. // !!!! Use flat array instead of structure, Freq = i*2, Len = i*2+1
  104. var static_ltree = new Array((L_CODES$1 + 2) * 2);
  105. zero$1(static_ltree);
  106. /* The static literal tree. Since the bit lengths are imposed, there is no
  107. * need for the L_CODES extra codes used during heap construction. However
  108. * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
  109. * below).
  110. */
  111. var static_dtree = new Array(D_CODES$1 * 2);
  112. zero$1(static_dtree);
  113. /* The static distance tree. (Actually a trivial tree since all codes use
  114. * 5 bits.)
  115. */
  116. var _dist_code = new Array(DIST_CODE_LEN);
  117. zero$1(_dist_code);
  118. /* Distance codes. The first 256 values correspond to the distances
  119. * 3 .. 258, the last 256 values correspond to the top 8 bits of
  120. * the 15 bit distances.
  121. */
  122. var _length_code = new Array(MAX_MATCH$1 - MIN_MATCH$1 + 1);
  123. zero$1(_length_code);
  124. /* length code for each normalized match length (0 == MIN_MATCH) */
  125. var base_length = new Array(LENGTH_CODES$1);
  126. zero$1(base_length);
  127. /* First normalized length for each code (0 = MIN_MATCH) */
  128. var base_dist = new Array(D_CODES$1);
  129. zero$1(base_dist);
  130. /* First normalized distance for each code (0 = distance of 1) */
  131. function StaticTreeDesc(static_tree, extra_bits, extra_base, elems, max_length) {
  132. this.static_tree = static_tree; /* static tree or NULL */
  133. this.extra_bits = extra_bits; /* extra bits for each code or NULL */
  134. this.extra_base = extra_base; /* base index for extra_bits */
  135. this.elems = elems; /* max number of elements in the tree */
  136. this.max_length = max_length; /* max bit length for the codes */
  137. // show if `static_tree` has data or dummy - needed for monomorphic objects
  138. this.has_stree = static_tree && static_tree.length;
  139. }
  140. var static_l_desc;
  141. var static_d_desc;
  142. var static_bl_desc;
  143. function TreeDesc(dyn_tree, stat_desc) {
  144. this.dyn_tree = dyn_tree; /* the dynamic tree */
  145. this.max_code = 0; /* largest code with non zero frequency */
  146. this.stat_desc = stat_desc; /* the corresponding static tree */
  147. }
  148. var d_code = function d_code(dist) {
  149. return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];
  150. };
  151. /* ===========================================================================
  152. * Output a short LSB first on the stream.
  153. * IN assertion: there is enough room in pendingBuf.
  154. */
  155. var put_short = function put_short(s, w) {
  156. // put_byte(s, (uch)((w) & 0xff));
  157. // put_byte(s, (uch)((ush)(w) >> 8));
  158. s.pending_buf[s.pending++] = w & 0xff;
  159. s.pending_buf[s.pending++] = w >>> 8 & 0xff;
  160. };
  161. /* ===========================================================================
  162. * Send a value on a given number of bits.
  163. * IN assertion: length <= 16 and value fits in length bits.
  164. */
  165. var send_bits = function send_bits(s, value, length) {
  166. if (s.bi_valid > Buf_size - length) {
  167. s.bi_buf |= value << s.bi_valid & 0xffff;
  168. put_short(s, s.bi_buf);
  169. s.bi_buf = value >> Buf_size - s.bi_valid;
  170. s.bi_valid += length - Buf_size;
  171. } else {
  172. s.bi_buf |= value << s.bi_valid & 0xffff;
  173. s.bi_valid += length;
  174. }
  175. };
  176. var send_code = function send_code(s, c, tree) {
  177. send_bits(s, tree[c * 2] /*.Code*/, tree[c * 2 + 1] /*.Len*/);
  178. };
  179. /* ===========================================================================
  180. * Reverse the first len bits of a code, using straightforward code (a faster
  181. * method would use a table)
  182. * IN assertion: 1 <= len <= 15
  183. */
  184. var bi_reverse = function bi_reverse(code, len) {
  185. var res = 0;
  186. do {
  187. res |= code & 1;
  188. code >>>= 1;
  189. res <<= 1;
  190. } while (--len > 0);
  191. return res >>> 1;
  192. };
  193. /* ===========================================================================
  194. * Flush the bit buffer, keeping at most 7 bits in it.
  195. */
  196. var bi_flush = function bi_flush(s) {
  197. if (s.bi_valid === 16) {
  198. put_short(s, s.bi_buf);
  199. s.bi_buf = 0;
  200. s.bi_valid = 0;
  201. } else if (s.bi_valid >= 8) {
  202. s.pending_buf[s.pending++] = s.bi_buf & 0xff;
  203. s.bi_buf >>= 8;
  204. s.bi_valid -= 8;
  205. }
  206. };
  207. /* ===========================================================================
  208. * Compute the optimal bit lengths for a tree and update the total bit length
  209. * for the current block.
  210. * IN assertion: the fields freq and dad are set, heap[heap_max] and
  211. * above are the tree nodes sorted by increasing frequency.
  212. * OUT assertions: the field len is set to the optimal bit length, the
  213. * array bl_count contains the frequencies for each bit length.
  214. * The length opt_len is updated; static_len is also updated if stree is
  215. * not null.
  216. */
  217. var gen_bitlen = function gen_bitlen(s, desc) {
  218. // deflate_state *s;
  219. // tree_desc *desc; /* the tree descriptor */
  220. var tree = desc.dyn_tree;
  221. var max_code = desc.max_code;
  222. var stree = desc.stat_desc.static_tree;
  223. var has_stree = desc.stat_desc.has_stree;
  224. var extra = desc.stat_desc.extra_bits;
  225. var base = desc.stat_desc.extra_base;
  226. var max_length = desc.stat_desc.max_length;
  227. var h; /* heap index */
  228. var n, m; /* iterate over the tree elements */
  229. var bits; /* bit length */
  230. var xbits; /* extra bits */
  231. var f; /* frequency */
  232. var overflow = 0; /* number of elements with bit length too large */
  233. for (bits = 0; bits <= MAX_BITS$1; bits++) {
  234. s.bl_count[bits] = 0;
  235. }
  236. /* In a first pass, compute the optimal bit lengths (which may
  237. * overflow in the case of the bit length tree).
  238. */
  239. tree[s.heap[s.heap_max] * 2 + 1] /*.Len*/ = 0; /* root of the heap */
  240. for (h = s.heap_max + 1; h < HEAP_SIZE$1; h++) {
  241. n = s.heap[h];
  242. bits = tree[tree[n * 2 + 1] /*.Dad*/ * 2 + 1] /*.Len*/ + 1;
  243. if (bits > max_length) {
  244. bits = max_length;
  245. overflow++;
  246. }
  247. tree[n * 2 + 1] /*.Len*/ = bits;
  248. /* We overwrite tree[n].Dad which is no longer needed */
  249. if (n > max_code) {
  250. continue;
  251. } /* not a leaf node */
  252. s.bl_count[bits]++;
  253. xbits = 0;
  254. if (n >= base) {
  255. xbits = extra[n - base];
  256. }
  257. f = tree[n * 2] /*.Freq*/;
  258. s.opt_len += f * (bits + xbits);
  259. if (has_stree) {
  260. s.static_len += f * (stree[n * 2 + 1] /*.Len*/ + xbits);
  261. }
  262. }
  263. if (overflow === 0) {
  264. return;
  265. }
  266. // Tracev((stderr,"\nbit length overflow\n"));
  267. /* This happens for example on obj2 and pic of the Calgary corpus */
  268. /* Find the first bit length which could increase: */
  269. do {
  270. bits = max_length - 1;
  271. while (s.bl_count[bits] === 0) {
  272. bits--;
  273. }
  274. s.bl_count[bits]--; /* move one leaf down the tree */
  275. s.bl_count[bits + 1] += 2; /* move one overflow item as its brother */
  276. s.bl_count[max_length]--;
  277. /* The brother of the overflow item also moves one step up,
  278. * but this does not affect bl_count[max_length]
  279. */
  280. overflow -= 2;
  281. } while (overflow > 0);
  282. /* Now recompute all bit lengths, scanning in increasing frequency.
  283. * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
  284. * lengths instead of fixing only the wrong ones. This idea is taken
  285. * from 'ar' written by Haruhiko Okumura.)
  286. */
  287. for (bits = max_length; bits !== 0; bits--) {
  288. n = s.bl_count[bits];
  289. while (n !== 0) {
  290. m = s.heap[--h];
  291. if (m > max_code) {
  292. continue;
  293. }
  294. if (tree[m * 2 + 1] /*.Len*/ !== bits) {
  295. // Tracev((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  296. s.opt_len += (bits - tree[m * 2 + 1] /*.Len*/) * tree[m * 2] /*.Freq*/;
  297. tree[m * 2 + 1] /*.Len*/ = bits;
  298. }
  299. n--;
  300. }
  301. }
  302. };
  303. /* ===========================================================================
  304. * Generate the codes for a given tree and bit counts (which need not be
  305. * optimal).
  306. * IN assertion: the array bl_count contains the bit length statistics for
  307. * the given tree and the field len is set for all tree elements.
  308. * OUT assertion: the field code is set for all tree elements of non
  309. * zero code length.
  310. */
  311. var gen_codes = function gen_codes(tree, max_code, bl_count) {
  312. // ct_data *tree; /* the tree to decorate */
  313. // int max_code; /* largest code with non zero frequency */
  314. // ushf *bl_count; /* number of codes at each bit length */
  315. var next_code = new Array(MAX_BITS$1 + 1); /* next code value for each bit length */
  316. var code = 0; /* running code value */
  317. var bits; /* bit index */
  318. var n; /* code index */
  319. /* The distribution counts are first used to generate the code values
  320. * without bit reversal.
  321. */
  322. for (bits = 1; bits <= MAX_BITS$1; bits++) {
  323. code = code + bl_count[bits - 1] << 1;
  324. next_code[bits] = code;
  325. }
  326. /* Check that the bit counts in bl_count are consistent. The last code
  327. * must be all ones.
  328. */
  329. //Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  330. // "inconsistent bit counts");
  331. //Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  332. for (n = 0; n <= max_code; n++) {
  333. var len = tree[n * 2 + 1] /*.Len*/;
  334. if (len === 0) {
  335. continue;
  336. }
  337. /* Now reverse the bits */
  338. tree[n * 2] /*.Code*/ = bi_reverse(next_code[len]++, len);
  339. //Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  340. // n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  341. }
  342. };
  343. /* ===========================================================================
  344. * Initialize the various 'constant' tables.
  345. */
  346. var tr_static_init = function tr_static_init() {
  347. var n; /* iterates over tree elements */
  348. var bits; /* bit counter */
  349. var length; /* length value */
  350. var code; /* code value */
  351. var dist; /* distance index */
  352. var bl_count = new Array(MAX_BITS$1 + 1);
  353. /* number of codes at each bit length for an optimal tree */
  354. // do check in _tr_init()
  355. //if (static_init_done) return;
  356. /* For some embedded targets, global variables are not initialized: */
  357. /*#ifdef NO_INIT_GLOBAL_POINTERS
  358. static_l_desc.static_tree = static_ltree;
  359. static_l_desc.extra_bits = extra_lbits;
  360. static_d_desc.static_tree = static_dtree;
  361. static_d_desc.extra_bits = extra_dbits;
  362. static_bl_desc.extra_bits = extra_blbits;
  363. #endif*/
  364. /* Initialize the mapping length (0..255) -> length code (0..28) */
  365. length = 0;
  366. for (code = 0; code < LENGTH_CODES$1 - 1; code++) {
  367. base_length[code] = length;
  368. for (n = 0; n < 1 << extra_lbits[code]; n++) {
  369. _length_code[length++] = code;
  370. }
  371. }
  372. //Assert (length == 256, "tr_static_init: length != 256");
  373. /* Note that the length 255 (match length 258) can be represented
  374. * in two different ways: code 284 + 5 bits or code 285, so we
  375. * overwrite length_code[255] to use the best encoding:
  376. */
  377. _length_code[length - 1] = code;
  378. /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
  379. dist = 0;
  380. for (code = 0; code < 16; code++) {
  381. base_dist[code] = dist;
  382. for (n = 0; n < 1 << extra_dbits[code]; n++) {
  383. _dist_code[dist++] = code;
  384. }
  385. }
  386. //Assert (dist == 256, "tr_static_init: dist != 256");
  387. dist >>= 7; /* from now on, all distances are divided by 128 */
  388. for (; code < D_CODES$1; code++) {
  389. base_dist[code] = dist << 7;
  390. for (n = 0; n < 1 << extra_dbits[code] - 7; n++) {
  391. _dist_code[256 + dist++] = code;
  392. }
  393. }
  394. //Assert (dist == 256, "tr_static_init: 256+dist != 512");
  395. /* Construct the codes of the static literal tree */
  396. for (bits = 0; bits <= MAX_BITS$1; bits++) {
  397. bl_count[bits] = 0;
  398. }
  399. n = 0;
  400. while (n <= 143) {
  401. static_ltree[n * 2 + 1] /*.Len*/ = 8;
  402. n++;
  403. bl_count[8]++;
  404. }
  405. while (n <= 255) {
  406. static_ltree[n * 2 + 1] /*.Len*/ = 9;
  407. n++;
  408. bl_count[9]++;
  409. }
  410. while (n <= 279) {
  411. static_ltree[n * 2 + 1] /*.Len*/ = 7;
  412. n++;
  413. bl_count[7]++;
  414. }
  415. while (n <= 287) {
  416. static_ltree[n * 2 + 1] /*.Len*/ = 8;
  417. n++;
  418. bl_count[8]++;
  419. }
  420. /* Codes 286 and 287 do not exist, but we must include them in the
  421. * tree construction to get a canonical Huffman tree (longest code
  422. * all ones)
  423. */
  424. gen_codes(static_ltree, L_CODES$1 + 1, bl_count);
  425. /* The static distance tree is trivial: */
  426. for (n = 0; n < D_CODES$1; n++) {
  427. static_dtree[n * 2 + 1] /*.Len*/ = 5;
  428. static_dtree[n * 2] /*.Code*/ = bi_reverse(n, 5);
  429. }
  430. // Now data ready and we can init static trees
  431. static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS$1 + 1, L_CODES$1, MAX_BITS$1);
  432. static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES$1, MAX_BITS$1);
  433. static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES$1, MAX_BL_BITS);
  434. //static_init_done = true;
  435. };
  436. /* ===========================================================================
  437. * Initialize a new block.
  438. */
  439. var init_block = function init_block(s) {
  440. var n; /* iterates over tree elements */
  441. /* Initialize the trees. */
  442. for (n = 0; n < L_CODES$1; n++) {
  443. s.dyn_ltree[n * 2] /*.Freq*/ = 0;
  444. }
  445. for (n = 0; n < D_CODES$1; n++) {
  446. s.dyn_dtree[n * 2] /*.Freq*/ = 0;
  447. }
  448. for (n = 0; n < BL_CODES$1; n++) {
  449. s.bl_tree[n * 2] /*.Freq*/ = 0;
  450. }
  451. s.dyn_ltree[END_BLOCK * 2] /*.Freq*/ = 1;
  452. s.opt_len = s.static_len = 0;
  453. s.sym_next = s.matches = 0;
  454. };
  455. /* ===========================================================================
  456. * Flush the bit buffer and align the output on a byte boundary
  457. */
  458. var bi_windup = function bi_windup(s) {
  459. if (s.bi_valid > 8) {
  460. put_short(s, s.bi_buf);
  461. } else if (s.bi_valid > 0) {
  462. //put_byte(s, (Byte)s->bi_buf);
  463. s.pending_buf[s.pending++] = s.bi_buf;
  464. }
  465. s.bi_buf = 0;
  466. s.bi_valid = 0;
  467. };
  468. /* ===========================================================================
  469. * Compares to subtrees, using the tree depth as tie breaker when
  470. * the subtrees have equal frequency. This minimizes the worst case length.
  471. */
  472. var smaller = function smaller(tree, n, m, depth) {
  473. var _n2 = n * 2;
  474. var _m2 = m * 2;
  475. return tree[_n2] /*.Freq*/ < tree[_m2] /*.Freq*/ || tree[_n2] /*.Freq*/ === tree[_m2] /*.Freq*/ && depth[n] <= depth[m];
  476. };
  477. /* ===========================================================================
  478. * Restore the heap property by moving down the tree starting at node k,
  479. * exchanging a node with the smallest of its two sons if necessary, stopping
  480. * when the heap property is re-established (each father smaller than its
  481. * two sons).
  482. */
  483. var pqdownheap = function pqdownheap(s, tree, k) {
  484. // deflate_state *s;
  485. // ct_data *tree; /* the tree to restore */
  486. // int k; /* node to move down */
  487. var v = s.heap[k];
  488. var j = k << 1; /* left son of k */
  489. while (j <= s.heap_len) {
  490. /* Set j to the smallest of the two sons: */
  491. if (j < s.heap_len && smaller(tree, s.heap[j + 1], s.heap[j], s.depth)) {
  492. j++;
  493. }
  494. /* Exit if v is smaller than both sons */
  495. if (smaller(tree, v, s.heap[j], s.depth)) {
  496. break;
  497. }
  498. /* Exchange v with the smallest son */
  499. s.heap[k] = s.heap[j];
  500. k = j;
  501. /* And continue down the tree, setting j to the left son of k */
  502. j <<= 1;
  503. }
  504. s.heap[k] = v;
  505. };
  506. // inlined manually
  507. // const SMALLEST = 1;
  508. /* ===========================================================================
  509. * Send the block data compressed using the given Huffman trees
  510. */
  511. var compress_block = function compress_block(s, ltree, dtree) {
  512. // deflate_state *s;
  513. // const ct_data *ltree; /* literal tree */
  514. // const ct_data *dtree; /* distance tree */
  515. var dist; /* distance of matched string */
  516. var lc; /* match length or unmatched char (if dist == 0) */
  517. var sx = 0; /* running index in sym_buf */
  518. var code; /* the code to send */
  519. var extra; /* number of extra bits to send */
  520. if (s.sym_next !== 0) {
  521. do {
  522. dist = s.pending_buf[s.sym_buf + sx++] & 0xff;
  523. dist += (s.pending_buf[s.sym_buf + sx++] & 0xff) << 8;
  524. lc = s.pending_buf[s.sym_buf + sx++];
  525. if (dist === 0) {
  526. send_code(s, lc, ltree); /* send a literal byte */
  527. //Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  528. } else {
  529. /* Here, lc is the match length - MIN_MATCH */
  530. code = _length_code[lc];
  531. send_code(s, code + LITERALS$1 + 1, ltree); /* send the length code */
  532. extra = extra_lbits[code];
  533. if (extra !== 0) {
  534. lc -= base_length[code];
  535. send_bits(s, lc, extra); /* send the extra length bits */
  536. }
  537. dist--; /* dist is now the match distance - 1 */
  538. code = d_code(dist);
  539. //Assert (code < D_CODES, "bad d_code");
  540. send_code(s, code, dtree); /* send the distance code */
  541. extra = extra_dbits[code];
  542. if (extra !== 0) {
  543. dist -= base_dist[code];
  544. send_bits(s, dist, extra); /* send the extra distance bits */
  545. }
  546. } /* literal or match pair ? */
  547. /* Check that the overlay between pending_buf and sym_buf is ok: */
  548. //Assert(s->pending < s->lit_bufsize + sx, "pendingBuf overflow");
  549. } while (sx < s.sym_next);
  550. }
  551. send_code(s, END_BLOCK, ltree);
  552. };
  553. /* ===========================================================================
  554. * Construct one Huffman tree and assigns the code bit strings and lengths.
  555. * Update the total bit length for the current block.
  556. * IN assertion: the field freq is set for all tree elements.
  557. * OUT assertions: the fields len and code are set to the optimal bit length
  558. * and corresponding code. The length opt_len is updated; static_len is
  559. * also updated if stree is not null. The field max_code is set.
  560. */
  561. var build_tree = function build_tree(s, desc) {
  562. // deflate_state *s;
  563. // tree_desc *desc; /* the tree descriptor */
  564. var tree = desc.dyn_tree;
  565. var stree = desc.stat_desc.static_tree;
  566. var has_stree = desc.stat_desc.has_stree;
  567. var elems = desc.stat_desc.elems;
  568. var n, m; /* iterate over heap elements */
  569. var max_code = -1; /* largest code with non zero frequency */
  570. var node; /* new node being created */
  571. /* Construct the initial heap, with least frequent element in
  572. * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
  573. * heap[0] is not used.
  574. */
  575. s.heap_len = 0;
  576. s.heap_max = HEAP_SIZE$1;
  577. for (n = 0; n < elems; n++) {
  578. if (tree[n * 2] /*.Freq*/ !== 0) {
  579. s.heap[++s.heap_len] = max_code = n;
  580. s.depth[n] = 0;
  581. } else {
  582. tree[n * 2 + 1] /*.Len*/ = 0;
  583. }
  584. }
  585. /* The pkzip format requires that at least one distance code exists,
  586. * and that at least one bit should be sent even if there is only one
  587. * possible code. So to avoid special checks later on we force at least
  588. * two codes of non zero frequency.
  589. */
  590. while (s.heap_len < 2) {
  591. node = s.heap[++s.heap_len] = max_code < 2 ? ++max_code : 0;
  592. tree[node * 2] /*.Freq*/ = 1;
  593. s.depth[node] = 0;
  594. s.opt_len--;
  595. if (has_stree) {
  596. s.static_len -= stree[node * 2 + 1] /*.Len*/;
  597. }
  598. /* node is 0 or 1 so it does not have extra bits */
  599. }
  600. desc.max_code = max_code;
  601. /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
  602. * establish sub-heaps of increasing lengths:
  603. */
  604. for (n = s.heap_len >> 1 /*int /2*/; n >= 1; n--) {
  605. pqdownheap(s, tree, n);
  606. }
  607. /* Construct the Huffman tree by repeatedly combining the least two
  608. * frequent nodes.
  609. */
  610. node = elems; /* next internal node of the tree */
  611. do {
  612. //pqremove(s, tree, n); /* n = node of least frequency */
  613. /*** pqremove ***/
  614. n = s.heap[1 /*SMALLEST*/];
  615. s.heap[1 /*SMALLEST*/] = s.heap[s.heap_len--];
  616. pqdownheap(s, tree, 1 /*SMALLEST*/);
  617. /***/
  618. m = s.heap[1 /*SMALLEST*/]; /* m = node of next least frequency */
  619. s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */
  620. s.heap[--s.heap_max] = m;
  621. /* Create a new node father of n and m */
  622. tree[node * 2] /*.Freq*/ = tree[n * 2] /*.Freq*/ + tree[m * 2] /*.Freq*/;
  623. s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;
  624. tree[n * 2 + 1] /*.Dad*/ = tree[m * 2 + 1] /*.Dad*/ = node;
  625. /* and insert the new node in the heap */
  626. s.heap[1 /*SMALLEST*/] = node++;
  627. pqdownheap(s, tree, 1 /*SMALLEST*/);
  628. } while (s.heap_len >= 2);
  629. s.heap[--s.heap_max] = s.heap[1 /*SMALLEST*/];
  630. /* At this point, the fields freq and dad are set. We can now
  631. * generate the bit lengths.
  632. */
  633. gen_bitlen(s, desc);
  634. /* The field len is now set, we can generate the bit codes */
  635. gen_codes(tree, max_code, s.bl_count);
  636. };
  637. /* ===========================================================================
  638. * Scan a literal or distance tree to determine the frequencies of the codes
  639. * in the bit length tree.
  640. */
  641. var scan_tree = function scan_tree(s, tree, max_code) {
  642. // deflate_state *s;
  643. // ct_data *tree; /* the tree to be scanned */
  644. // int max_code; /* and its largest code of non zero frequency */
  645. var n; /* iterates over all tree elements */
  646. var prevlen = -1; /* last emitted length */
  647. var curlen; /* length of current code */
  648. var nextlen = tree[0 * 2 + 1] /*.Len*/; /* length of next code */
  649. var count = 0; /* repeat count of the current code */
  650. var max_count = 7; /* max repeat count */
  651. var min_count = 4; /* min repeat count */
  652. if (nextlen === 0) {
  653. max_count = 138;
  654. min_count = 3;
  655. }
  656. tree[(max_code + 1) * 2 + 1] /*.Len*/ = 0xffff; /* guard */
  657. for (n = 0; n <= max_code; n++) {
  658. curlen = nextlen;
  659. nextlen = tree[(n + 1) * 2 + 1] /*.Len*/;
  660. if (++count < max_count && curlen === nextlen) {
  661. continue;
  662. } else if (count < min_count) {
  663. s.bl_tree[curlen * 2] /*.Freq*/ += count;
  664. } else if (curlen !== 0) {
  665. if (curlen !== prevlen) {
  666. s.bl_tree[curlen * 2] /*.Freq*/++;
  667. }
  668. s.bl_tree[REP_3_6 * 2] /*.Freq*/++;
  669. } else if (count <= 10) {
  670. s.bl_tree[REPZ_3_10 * 2] /*.Freq*/++;
  671. } else {
  672. s.bl_tree[REPZ_11_138 * 2] /*.Freq*/++;
  673. }
  674. count = 0;
  675. prevlen = curlen;
  676. if (nextlen === 0) {
  677. max_count = 138;
  678. min_count = 3;
  679. } else if (curlen === nextlen) {
  680. max_count = 6;
  681. min_count = 3;
  682. } else {
  683. max_count = 7;
  684. min_count = 4;
  685. }
  686. }
  687. };
  688. /* ===========================================================================
  689. * Send a literal or distance tree in compressed form, using the codes in
  690. * bl_tree.
  691. */
  692. var send_tree = function send_tree(s, tree, max_code) {
  693. // deflate_state *s;
  694. // ct_data *tree; /* the tree to be scanned */
  695. // int max_code; /* and its largest code of non zero frequency */
  696. var n; /* iterates over all tree elements */
  697. var prevlen = -1; /* last emitted length */
  698. var curlen; /* length of current code */
  699. var nextlen = tree[0 * 2 + 1] /*.Len*/; /* length of next code */
  700. var count = 0; /* repeat count of the current code */
  701. var max_count = 7; /* max repeat count */
  702. var min_count = 4; /* min repeat count */
  703. /* tree[max_code+1].Len = -1; */ /* guard already set */
  704. if (nextlen === 0) {
  705. max_count = 138;
  706. min_count = 3;
  707. }
  708. for (n = 0; n <= max_code; n++) {
  709. curlen = nextlen;
  710. nextlen = tree[(n + 1) * 2 + 1] /*.Len*/;
  711. if (++count < max_count && curlen === nextlen) {
  712. continue;
  713. } else if (count < min_count) {
  714. do {
  715. send_code(s, curlen, s.bl_tree);
  716. } while (--count !== 0);
  717. } else if (curlen !== 0) {
  718. if (curlen !== prevlen) {
  719. send_code(s, curlen, s.bl_tree);
  720. count--;
  721. }
  722. //Assert(count >= 3 && count <= 6, " 3_6?");
  723. send_code(s, REP_3_6, s.bl_tree);
  724. send_bits(s, count - 3, 2);
  725. } else if (count <= 10) {
  726. send_code(s, REPZ_3_10, s.bl_tree);
  727. send_bits(s, count - 3, 3);
  728. } else {
  729. send_code(s, REPZ_11_138, s.bl_tree);
  730. send_bits(s, count - 11, 7);
  731. }
  732. count = 0;
  733. prevlen = curlen;
  734. if (nextlen === 0) {
  735. max_count = 138;
  736. min_count = 3;
  737. } else if (curlen === nextlen) {
  738. max_count = 6;
  739. min_count = 3;
  740. } else {
  741. max_count = 7;
  742. min_count = 4;
  743. }
  744. }
  745. };
  746. /* ===========================================================================
  747. * Construct the Huffman tree for the bit lengths and return the index in
  748. * bl_order of the last bit length code to send.
  749. */
  750. var build_bl_tree = function build_bl_tree(s) {
  751. var max_blindex; /* index of last bit length code of non zero freq */
  752. /* Determine the bit length frequencies for literal and distance trees */
  753. scan_tree(s, s.dyn_ltree, s.l_desc.max_code);
  754. scan_tree(s, s.dyn_dtree, s.d_desc.max_code);
  755. /* Build the bit length tree: */
  756. build_tree(s, s.bl_desc);
  757. /* opt_len now includes the length of the tree representations, except
  758. * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
  759. */
  760. /* Determine the number of bit length codes to send. The pkzip format
  761. * requires that at least 4 bit length codes be sent. (appnote.txt says
  762. * 3 but the actual value used is 4.)
  763. */
  764. for (max_blindex = BL_CODES$1 - 1; max_blindex >= 3; max_blindex--) {
  765. if (s.bl_tree[bl_order[max_blindex] * 2 + 1] /*.Len*/ !== 0) {
  766. break;
  767. }
  768. }
  769. /* Update opt_len to include the bit length tree and counts */
  770. s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
  771. //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  772. // s->opt_len, s->static_len));
  773. return max_blindex;
  774. };
  775. /* ===========================================================================
  776. * Send the header for a block using dynamic Huffman trees: the counts, the
  777. * lengths of the bit length codes, the literal tree and the distance tree.
  778. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
  779. */
  780. var send_all_trees = function send_all_trees(s, lcodes, dcodes, blcodes) {
  781. // deflate_state *s;
  782. // int lcodes, dcodes, blcodes; /* number of codes for each tree */
  783. var rank; /* index in bl_order */
  784. //Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  785. //Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  786. // "too many codes");
  787. //Tracev((stderr, "\nbl counts: "));
  788. send_bits(s, lcodes - 257, 5); /* not +255 as stated in appnote.txt */
  789. send_bits(s, dcodes - 1, 5);
  790. send_bits(s, blcodes - 4, 4); /* not -3 as stated in appnote.txt */
  791. for (rank = 0; rank < blcodes; rank++) {
  792. //Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  793. send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1] /*.Len*/, 3);
  794. }
  795. //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  796. send_tree(s, s.dyn_ltree, lcodes - 1); /* literal tree */
  797. //Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  798. send_tree(s, s.dyn_dtree, dcodes - 1); /* distance tree */
  799. //Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  800. };
  801. /* ===========================================================================
  802. * Check if the data type is TEXT or BINARY, using the following algorithm:
  803. * - TEXT if the two conditions below are satisfied:
  804. * a) There are no non-portable control characters belonging to the
  805. * "block list" (0..6, 14..25, 28..31).
  806. * b) There is at least one printable character belonging to the
  807. * "allow list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
  808. * - BINARY otherwise.
  809. * - The following partially-portable control characters form a
  810. * "gray list" that is ignored in this detection algorithm:
  811. * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
  812. * IN assertion: the fields Freq of dyn_ltree are set.
  813. */
  814. var detect_data_type = function detect_data_type(s) {
  815. /* block_mask is the bit mask of block-listed bytes
  816. * set bits 0..6, 14..25, and 28..31
  817. * 0xf3ffc07f = binary 11110011111111111100000001111111
  818. */
  819. var block_mask = 0xf3ffc07f;
  820. var n;
  821. /* Check for non-textual ("block-listed") bytes. */
  822. for (n = 0; n <= 31; n++, block_mask >>>= 1) {
  823. if (block_mask & 1 && s.dyn_ltree[n * 2] /*.Freq*/ !== 0) {
  824. return Z_BINARY;
  825. }
  826. }
  827. /* Check for textual ("allow-listed") bytes. */
  828. if (s.dyn_ltree[9 * 2] /*.Freq*/ !== 0 || s.dyn_ltree[10 * 2] /*.Freq*/ !== 0 || s.dyn_ltree[13 * 2] /*.Freq*/ !== 0) {
  829. return Z_TEXT;
  830. }
  831. for (n = 32; n < LITERALS$1; n++) {
  832. if (s.dyn_ltree[n * 2] /*.Freq*/ !== 0) {
  833. return Z_TEXT;
  834. }
  835. }
  836. /* There are no "block-listed" or "allow-listed" bytes:
  837. * this stream either is empty or has tolerated ("gray-listed") bytes only.
  838. */
  839. return Z_BINARY;
  840. };
  841. var static_init_done = false;
  842. /* ===========================================================================
  843. * Initialize the tree data structures for a new zlib stream.
  844. */
  845. var _tr_init$1 = function _tr_init(s) {
  846. if (!static_init_done) {
  847. tr_static_init();
  848. static_init_done = true;
  849. }
  850. s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc);
  851. s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc);
  852. s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc);
  853. s.bi_buf = 0;
  854. s.bi_valid = 0;
  855. /* Initialize the first block of the first file: */
  856. init_block(s);
  857. };
  858. /* ===========================================================================
  859. * Send a stored block
  860. */
  861. var _tr_stored_block$1 = function _tr_stored_block(s, buf, stored_len, last) {
  862. //DeflateState *s;
  863. //charf *buf; /* input block */
  864. //ulg stored_len; /* length of input block */
  865. //int last; /* one if this is the last block for a file */
  866. send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3); /* send block type */
  867. bi_windup(s); /* align on byte boundary */
  868. put_short(s, stored_len);
  869. put_short(s, ~stored_len);
  870. if (stored_len) {
  871. s.pending_buf.set(s.window.subarray(buf, buf + stored_len), s.pending);
  872. }
  873. s.pending += stored_len;
  874. };
  875. /* ===========================================================================
  876. * Send one empty static block to give enough lookahead for inflate.
  877. * This takes 10 bits, of which 7 may remain in the bit buffer.
  878. */
  879. var _tr_align$1 = function _tr_align(s) {
  880. send_bits(s, STATIC_TREES << 1, 3);
  881. send_code(s, END_BLOCK, static_ltree);
  882. bi_flush(s);
  883. };
  884. /* ===========================================================================
  885. * Determine the best encoding for the current block: dynamic trees, static
  886. * trees or store, and write out the encoded block.
  887. */
  888. var _tr_flush_block$1 = function _tr_flush_block(s, buf, stored_len, last) {
  889. //DeflateState *s;
  890. //charf *buf; /* input block, or NULL if too old */
  891. //ulg stored_len; /* length of input block */
  892. //int last; /* one if this is the last block for a file */
  893. var opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  894. var max_blindex = 0; /* index of last bit length code of non zero freq */
  895. /* Build the Huffman trees unless a stored block is forced */
  896. if (s.level > 0) {
  897. /* Check if the file is binary or text */
  898. if (s.strm.data_type === Z_UNKNOWN$1) {
  899. s.strm.data_type = detect_data_type(s);
  900. }
  901. /* Construct the literal and distance trees */
  902. build_tree(s, s.l_desc);
  903. // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  904. // s->static_len));
  905. build_tree(s, s.d_desc);
  906. // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  907. // s->static_len));
  908. /* At this point, opt_len and static_len are the total bit lengths of
  909. * the compressed block data, excluding the tree representations.
  910. */
  911. /* Build the bit length tree for the above two trees, and get the index
  912. * in bl_order of the last bit length code to send.
  913. */
  914. max_blindex = build_bl_tree(s);
  915. /* Determine the best encoding. Compute the block lengths in bytes. */
  916. opt_lenb = s.opt_len + 3 + 7 >>> 3;
  917. static_lenb = s.static_len + 3 + 7 >>> 3;
  918. // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  919. // opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  920. // s->sym_next / 3));
  921. if (static_lenb <= opt_lenb) {
  922. opt_lenb = static_lenb;
  923. }
  924. } else {
  925. // Assert(buf != (char*)0, "lost buf");
  926. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  927. }
  928. if (stored_len + 4 <= opt_lenb && buf !== -1) {
  929. /* 4: two words for the lengths */
  930. /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
  931. * Otherwise we can't have processed more than WSIZE input bytes since
  932. * the last block flush, because compression would have been
  933. * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
  934. * transform a block into a stored block.
  935. */
  936. _tr_stored_block$1(s, buf, stored_len, last);
  937. } else if (s.strategy === Z_FIXED$1 || static_lenb === opt_lenb) {
  938. send_bits(s, (STATIC_TREES << 1) + (last ? 1 : 0), 3);
  939. compress_block(s, static_ltree, static_dtree);
  940. } else {
  941. send_bits(s, (DYN_TREES << 1) + (last ? 1 : 0), 3);
  942. send_all_trees(s, s.l_desc.max_code + 1, s.d_desc.max_code + 1, max_blindex + 1);
  943. compress_block(s, s.dyn_ltree, s.dyn_dtree);
  944. }
  945. // Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  946. /* The above check is made mod 2^32, for files larger than 512 MB
  947. * and uLong implemented on 32 bits.
  948. */
  949. init_block(s);
  950. if (last) {
  951. bi_windup(s);
  952. }
  953. // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  954. // s->compressed_len-7*last));
  955. };
  956. /* ===========================================================================
  957. * Save the match info and tally the frequency counts. Return true if
  958. * the current block must be flushed.
  959. */
  960. var _tr_tally$1 = function _tr_tally(s, dist, lc) {
  961. // deflate_state *s;
  962. // unsigned dist; /* distance of matched string */
  963. // unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
  964. s.pending_buf[s.sym_buf + s.sym_next++] = dist;
  965. s.pending_buf[s.sym_buf + s.sym_next++] = dist >> 8;
  966. s.pending_buf[s.sym_buf + s.sym_next++] = lc;
  967. if (dist === 0) {
  968. /* lc is the unmatched char */
  969. s.dyn_ltree[lc * 2] /*.Freq*/++;
  970. } else {
  971. s.matches++;
  972. /* Here, lc is the match length - MIN_MATCH */
  973. dist--; /* dist = match distance - 1 */
  974. //Assert((ush)dist < (ush)MAX_DIST(s) &&
  975. // (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  976. // (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  977. s.dyn_ltree[(_length_code[lc] + LITERALS$1 + 1) * 2] /*.Freq*/++;
  978. s.dyn_dtree[d_code(dist) * 2] /*.Freq*/++;
  979. }
  980. return s.sym_next === s.sym_end;
  981. };
  982. var _tr_init_1 = _tr_init$1;
  983. var _tr_stored_block_1 = _tr_stored_block$1;
  984. var _tr_flush_block_1 = _tr_flush_block$1;
  985. var _tr_tally_1 = _tr_tally$1;
  986. var _tr_align_1 = _tr_align$1;
  987. var trees = {
  988. _tr_init: _tr_init_1,
  989. _tr_stored_block: _tr_stored_block_1,
  990. _tr_flush_block: _tr_flush_block_1,
  991. _tr_tally: _tr_tally_1,
  992. _tr_align: _tr_align_1
  993. };
  994. // Note: adler32 takes 12% for level 0 and 2% for level 6.
  995. // It isn't worth it to make additional optimizations as in original.
  996. // Small size is preferable.
  997. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  998. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  999. //
  1000. // This software is provided 'as-is', without any express or implied
  1001. // warranty. In no event will the authors be held liable for any damages
  1002. // arising from the use of this software.
  1003. //
  1004. // Permission is granted to anyone to use this software for any purpose,
  1005. // including commercial applications, and to alter it and redistribute it
  1006. // freely, subject to the following restrictions:
  1007. //
  1008. // 1. The origin of this software must not be misrepresented; you must not
  1009. // claim that you wrote the original software. If you use this software
  1010. // in a product, an acknowledgment in the product documentation would be
  1011. // appreciated but is not required.
  1012. // 2. Altered source versions must be plainly marked as such, and must not be
  1013. // misrepresented as being the original software.
  1014. // 3. This notice may not be removed or altered from any source distribution.
  1015. var adler32 = function adler32(adler, buf, len, pos) {
  1016. var s1 = adler & 0xffff | 0,
  1017. s2 = adler >>> 16 & 0xffff | 0,
  1018. n = 0;
  1019. while (len !== 0) {
  1020. // Set limit ~ twice less than 5552, to keep
  1021. // s2 in 31-bits, because we force signed ints.
  1022. // in other case %= will fail.
  1023. n = len > 2000 ? 2000 : len;
  1024. len -= n;
  1025. do {
  1026. s1 = s1 + buf[pos++] | 0;
  1027. s2 = s2 + s1 | 0;
  1028. } while (--n);
  1029. s1 %= 65521;
  1030. s2 %= 65521;
  1031. }
  1032. return s1 | s2 << 16 | 0;
  1033. };
  1034. var adler32_1 = adler32;
  1035. // Note: we can't get significant speed boost here.
  1036. // So write code to minimize size - no pregenerated tables
  1037. // and array tools dependencies.
  1038. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  1039. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  1040. //
  1041. // This software is provided 'as-is', without any express or implied
  1042. // warranty. In no event will the authors be held liable for any damages
  1043. // arising from the use of this software.
  1044. //
  1045. // Permission is granted to anyone to use this software for any purpose,
  1046. // including commercial applications, and to alter it and redistribute it
  1047. // freely, subject to the following restrictions:
  1048. //
  1049. // 1. The origin of this software must not be misrepresented; you must not
  1050. // claim that you wrote the original software. If you use this software
  1051. // in a product, an acknowledgment in the product documentation would be
  1052. // appreciated but is not required.
  1053. // 2. Altered source versions must be plainly marked as such, and must not be
  1054. // misrepresented as being the original software.
  1055. // 3. This notice may not be removed or altered from any source distribution.
  1056. // Use ordinary array, since untyped makes no boost here
  1057. var makeTable = function makeTable() {
  1058. var c,
  1059. table = [];
  1060. for (var n = 0; n < 256; n++) {
  1061. c = n;
  1062. for (var k = 0; k < 8; k++) {
  1063. c = c & 1 ? 0xEDB88320 ^ c >>> 1 : c >>> 1;
  1064. }
  1065. table[n] = c;
  1066. }
  1067. return table;
  1068. };
  1069. // Create table on load. Just 255 signed longs. Not a problem.
  1070. var crcTable = new Uint32Array(makeTable());
  1071. var crc32 = function crc32(crc, buf, len, pos) {
  1072. var t = crcTable;
  1073. var end = pos + len;
  1074. crc ^= -1;
  1075. for (var i = pos; i < end; i++) {
  1076. crc = crc >>> 8 ^ t[(crc ^ buf[i]) & 0xFF];
  1077. }
  1078. return crc ^ -1; // >>> 0;
  1079. };
  1080. var crc32_1 = crc32;
  1081. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  1082. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  1083. //
  1084. // This software is provided 'as-is', without any express or implied
  1085. // warranty. In no event will the authors be held liable for any damages
  1086. // arising from the use of this software.
  1087. //
  1088. // Permission is granted to anyone to use this software for any purpose,
  1089. // including commercial applications, and to alter it and redistribute it
  1090. // freely, subject to the following restrictions:
  1091. //
  1092. // 1. The origin of this software must not be misrepresented; you must not
  1093. // claim that you wrote the original software. If you use this software
  1094. // in a product, an acknowledgment in the product documentation would be
  1095. // appreciated but is not required.
  1096. // 2. Altered source versions must be plainly marked as such, and must not be
  1097. // misrepresented as being the original software.
  1098. // 3. This notice may not be removed or altered from any source distribution.
  1099. var messages = {
  1100. 2: 'need dictionary',
  1101. /* Z_NEED_DICT 2 */
  1102. 1: 'stream end',
  1103. /* Z_STREAM_END 1 */
  1104. 0: '',
  1105. /* Z_OK 0 */
  1106. '-1': 'file error',
  1107. /* Z_ERRNO (-1) */
  1108. '-2': 'stream error',
  1109. /* Z_STREAM_ERROR (-2) */
  1110. '-3': 'data error',
  1111. /* Z_DATA_ERROR (-3) */
  1112. '-4': 'insufficient memory',
  1113. /* Z_MEM_ERROR (-4) */
  1114. '-5': 'buffer error',
  1115. /* Z_BUF_ERROR (-5) */
  1116. '-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */
  1117. };
  1118. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  1119. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  1120. //
  1121. // This software is provided 'as-is', without any express or implied
  1122. // warranty. In no event will the authors be held liable for any damages
  1123. // arising from the use of this software.
  1124. //
  1125. // Permission is granted to anyone to use this software for any purpose,
  1126. // including commercial applications, and to alter it and redistribute it
  1127. // freely, subject to the following restrictions:
  1128. //
  1129. // 1. The origin of this software must not be misrepresented; you must not
  1130. // claim that you wrote the original software. If you use this software
  1131. // in a product, an acknowledgment in the product documentation would be
  1132. // appreciated but is not required.
  1133. // 2. Altered source versions must be plainly marked as such, and must not be
  1134. // misrepresented as being the original software.
  1135. // 3. This notice may not be removed or altered from any source distribution.
  1136. var constants$2 = {
  1137. /* Allowed flush values; see deflate() and inflate() below for details */
  1138. Z_NO_FLUSH: 0,
  1139. Z_PARTIAL_FLUSH: 1,
  1140. Z_SYNC_FLUSH: 2,
  1141. Z_FULL_FLUSH: 3,
  1142. Z_FINISH: 4,
  1143. Z_BLOCK: 5,
  1144. Z_TREES: 6,
  1145. /* Return codes for the compression/decompression functions. Negative values
  1146. * are errors, positive values are used for special but normal events.
  1147. */
  1148. Z_OK: 0,
  1149. Z_STREAM_END: 1,
  1150. Z_NEED_DICT: 2,
  1151. Z_ERRNO: -1,
  1152. Z_STREAM_ERROR: -2,
  1153. Z_DATA_ERROR: -3,
  1154. Z_MEM_ERROR: -4,
  1155. Z_BUF_ERROR: -5,
  1156. //Z_VERSION_ERROR: -6,
  1157. /* compression levels */
  1158. Z_NO_COMPRESSION: 0,
  1159. Z_BEST_SPEED: 1,
  1160. Z_BEST_COMPRESSION: 9,
  1161. Z_DEFAULT_COMPRESSION: -1,
  1162. Z_FILTERED: 1,
  1163. Z_HUFFMAN_ONLY: 2,
  1164. Z_RLE: 3,
  1165. Z_FIXED: 4,
  1166. Z_DEFAULT_STRATEGY: 0,
  1167. /* Possible values of the data_type field (though see inflate()) */
  1168. Z_BINARY: 0,
  1169. Z_TEXT: 1,
  1170. //Z_ASCII: 1, // = Z_TEXT (deprecated)
  1171. Z_UNKNOWN: 2,
  1172. /* The deflate compression method */
  1173. Z_DEFLATED: 8
  1174. //Z_NULL: null // Use -1 or null inline, depending on var type
  1175. };
  1176. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  1177. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  1178. //
  1179. // This software is provided 'as-is', without any express or implied
  1180. // warranty. In no event will the authors be held liable for any damages
  1181. // arising from the use of this software.
  1182. //
  1183. // Permission is granted to anyone to use this software for any purpose,
  1184. // including commercial applications, and to alter it and redistribute it
  1185. // freely, subject to the following restrictions:
  1186. //
  1187. // 1. The origin of this software must not be misrepresented; you must not
  1188. // claim that you wrote the original software. If you use this software
  1189. // in a product, an acknowledgment in the product documentation would be
  1190. // appreciated but is not required.
  1191. // 2. Altered source versions must be plainly marked as such, and must not be
  1192. // misrepresented as being the original software.
  1193. // 3. This notice may not be removed or altered from any source distribution.
  1194. var _tr_init = trees._tr_init,
  1195. _tr_stored_block = trees._tr_stored_block,
  1196. _tr_flush_block = trees._tr_flush_block,
  1197. _tr_tally = trees._tr_tally,
  1198. _tr_align = trees._tr_align;
  1199. /* Public constants ==========================================================*/
  1200. /* ===========================================================================*/
  1201. var Z_NO_FLUSH$2 = constants$2.Z_NO_FLUSH,
  1202. Z_PARTIAL_FLUSH = constants$2.Z_PARTIAL_FLUSH,
  1203. Z_FULL_FLUSH$1 = constants$2.Z_FULL_FLUSH,
  1204. Z_FINISH$3 = constants$2.Z_FINISH,
  1205. Z_BLOCK$1 = constants$2.Z_BLOCK,
  1206. Z_OK$3 = constants$2.Z_OK,
  1207. Z_STREAM_END$3 = constants$2.Z_STREAM_END,
  1208. Z_STREAM_ERROR$2 = constants$2.Z_STREAM_ERROR,
  1209. Z_DATA_ERROR$2 = constants$2.Z_DATA_ERROR,
  1210. Z_BUF_ERROR$1 = constants$2.Z_BUF_ERROR,
  1211. Z_DEFAULT_COMPRESSION$1 = constants$2.Z_DEFAULT_COMPRESSION,
  1212. Z_FILTERED = constants$2.Z_FILTERED,
  1213. Z_HUFFMAN_ONLY = constants$2.Z_HUFFMAN_ONLY,
  1214. Z_RLE = constants$2.Z_RLE,
  1215. Z_FIXED = constants$2.Z_FIXED,
  1216. Z_DEFAULT_STRATEGY$1 = constants$2.Z_DEFAULT_STRATEGY,
  1217. Z_UNKNOWN = constants$2.Z_UNKNOWN,
  1218. Z_DEFLATED$2 = constants$2.Z_DEFLATED;
  1219. /*============================================================================*/
  1220. var MAX_MEM_LEVEL = 9;
  1221. /* Maximum value for memLevel in deflateInit2 */
  1222. var MAX_WBITS$1 = 15;
  1223. /* 32K LZ77 window */
  1224. var DEF_MEM_LEVEL = 8;
  1225. var LENGTH_CODES = 29;
  1226. /* number of length codes, not counting the special END_BLOCK code */
  1227. var LITERALS = 256;
  1228. /* number of literal bytes 0..255 */
  1229. var L_CODES = LITERALS + 1 + LENGTH_CODES;
  1230. /* number of Literal or Length codes, including the END_BLOCK code */
  1231. var D_CODES = 30;
  1232. /* number of distance codes */
  1233. var BL_CODES = 19;
  1234. /* number of codes used to transfer the bit lengths */
  1235. var HEAP_SIZE = 2 * L_CODES + 1;
  1236. /* maximum heap size */
  1237. var MAX_BITS = 15;
  1238. /* All codes must not exceed MAX_BITS bits */
  1239. var MIN_MATCH = 3;
  1240. var MAX_MATCH = 258;
  1241. var MIN_LOOKAHEAD = MAX_MATCH + MIN_MATCH + 1;
  1242. var PRESET_DICT = 0x20;
  1243. var INIT_STATE = 42; /* zlib header -> BUSY_STATE */
  1244. //#ifdef GZIP
  1245. var GZIP_STATE = 57; /* gzip header -> BUSY_STATE | EXTRA_STATE */
  1246. //#endif
  1247. var EXTRA_STATE = 69; /* gzip extra block -> NAME_STATE */
  1248. var NAME_STATE = 73; /* gzip file name -> COMMENT_STATE */
  1249. var COMMENT_STATE = 91; /* gzip comment -> HCRC_STATE */
  1250. var HCRC_STATE = 103; /* gzip header CRC -> BUSY_STATE */
  1251. var BUSY_STATE = 113; /* deflate -> FINISH_STATE */
  1252. var FINISH_STATE = 666; /* stream complete */
  1253. var BS_NEED_MORE = 1; /* block not completed, need more input or more output */
  1254. var BS_BLOCK_DONE = 2; /* block flush performed */
  1255. var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */
  1256. var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */
  1257. var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.
  1258. var err = function err(strm, errorCode) {
  1259. strm.msg = messages[errorCode];
  1260. return errorCode;
  1261. };
  1262. var rank = function rank(f) {
  1263. return f * 2 - (f > 4 ? 9 : 0);
  1264. };
  1265. var zero = function zero(buf) {
  1266. var len = buf.length;
  1267. while (--len >= 0) {
  1268. buf[len] = 0;
  1269. }
  1270. };
  1271. /* ===========================================================================
  1272. * Slide the hash table when sliding the window down (could be avoided with 32
  1273. * bit values at the expense of memory usage). We slide even when level == 0 to
  1274. * keep the hash table consistent if we switch back to level > 0 later.
  1275. */
  1276. var slide_hash = function slide_hash(s) {
  1277. var n, m;
  1278. var p;
  1279. var wsize = s.w_size;
  1280. n = s.hash_size;
  1281. p = n;
  1282. do {
  1283. m = s.head[--p];
  1284. s.head[p] = m >= wsize ? m - wsize : 0;
  1285. } while (--n);
  1286. n = wsize;
  1287. //#ifndef FASTEST
  1288. p = n;
  1289. do {
  1290. m = s.prev[--p];
  1291. s.prev[p] = m >= wsize ? m - wsize : 0;
  1292. /* If n is not on any hash chain, prev[n] is garbage but
  1293. * its value will never be used.
  1294. */
  1295. } while (--n);
  1296. //#endif
  1297. };
  1298. /* eslint-disable new-cap */
  1299. var HASH_ZLIB = function HASH_ZLIB(s, prev, data) {
  1300. return (prev << s.hash_shift ^ data) & s.hash_mask;
  1301. };
  1302. // This hash causes less collisions, https://github.com/nodeca/pako/issues/135
  1303. // But breaks binary compatibility
  1304. //let HASH_FAST = (s, prev, data) => ((prev << 8) + (prev >> 8) + (data << 4)) & s.hash_mask;
  1305. var HASH = HASH_ZLIB;
  1306. /* =========================================================================
  1307. * Flush as much pending output as possible. All deflate() output, except for
  1308. * some deflate_stored() output, goes through this function so some
  1309. * applications may wish to modify it to avoid allocating a large
  1310. * strm->next_out buffer and copying into it. (See also read_buf()).
  1311. */
  1312. var flush_pending = function flush_pending(strm) {
  1313. var s = strm.state;
  1314. //_tr_flush_bits(s);
  1315. var len = s.pending;
  1316. if (len > strm.avail_out) {
  1317. len = strm.avail_out;
  1318. }
  1319. if (len === 0) {
  1320. return;
  1321. }
  1322. strm.output.set(s.pending_buf.subarray(s.pending_out, s.pending_out + len), strm.next_out);
  1323. strm.next_out += len;
  1324. s.pending_out += len;
  1325. strm.total_out += len;
  1326. strm.avail_out -= len;
  1327. s.pending -= len;
  1328. if (s.pending === 0) {
  1329. s.pending_out = 0;
  1330. }
  1331. };
  1332. var flush_block_only = function flush_block_only(s, last) {
  1333. _tr_flush_block(s, s.block_start >= 0 ? s.block_start : -1, s.strstart - s.block_start, last);
  1334. s.block_start = s.strstart;
  1335. flush_pending(s.strm);
  1336. };
  1337. var put_byte = function put_byte(s, b) {
  1338. s.pending_buf[s.pending++] = b;
  1339. };
  1340. /* =========================================================================
  1341. * Put a short in the pending buffer. The 16-bit value is put in MSB order.
  1342. * IN assertion: the stream state is correct and there is enough room in
  1343. * pending_buf.
  1344. */
  1345. var putShortMSB = function putShortMSB(s, b) {
  1346. // put_byte(s, (Byte)(b >> 8));
  1347. // put_byte(s, (Byte)(b & 0xff));
  1348. s.pending_buf[s.pending++] = b >>> 8 & 0xff;
  1349. s.pending_buf[s.pending++] = b & 0xff;
  1350. };
  1351. /* ===========================================================================
  1352. * Read a new buffer from the current input stream, update the adler32
  1353. * and total number of bytes read. All deflate() input goes through
  1354. * this function so some applications may wish to modify it to avoid
  1355. * allocating a large strm->input buffer and copying from it.
  1356. * (See also flush_pending()).
  1357. */
  1358. var read_buf = function read_buf(strm, buf, start, size) {
  1359. var len = strm.avail_in;
  1360. if (len > size) {
  1361. len = size;
  1362. }
  1363. if (len === 0) {
  1364. return 0;
  1365. }
  1366. strm.avail_in -= len;
  1367. // zmemcpy(buf, strm->next_in, len);
  1368. buf.set(strm.input.subarray(strm.next_in, strm.next_in + len), start);
  1369. if (strm.state.wrap === 1) {
  1370. strm.adler = adler32_1(strm.adler, buf, len, start);
  1371. } else if (strm.state.wrap === 2) {
  1372. strm.adler = crc32_1(strm.adler, buf, len, start);
  1373. }
  1374. strm.next_in += len;
  1375. strm.total_in += len;
  1376. return len;
  1377. };
  1378. /* ===========================================================================
  1379. * Set match_start to the longest match starting at the given string and
  1380. * return its length. Matches shorter or equal to prev_length are discarded,
  1381. * in which case the result is equal to prev_length and match_start is
  1382. * garbage.
  1383. * IN assertions: cur_match is the head of the hash chain for the current
  1384. * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
  1385. * OUT assertion: the match length is not greater than s->lookahead.
  1386. */
  1387. var longest_match = function longest_match(s, cur_match) {
  1388. var chain_length = s.max_chain_length; /* max hash chain length */
  1389. var scan = s.strstart; /* current string */
  1390. var match; /* matched string */
  1391. var len; /* length of current match */
  1392. var best_len = s.prev_length; /* best match length so far */
  1393. var nice_match = s.nice_match; /* stop if match long enough */
  1394. var limit = s.strstart > s.w_size - MIN_LOOKAHEAD ? s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0 /*NIL*/;
  1395. var _win = s.window; // shortcut
  1396. var wmask = s.w_mask;
  1397. var prev = s.prev;
  1398. /* Stop when cur_match becomes <= limit. To simplify the code,
  1399. * we prevent matches with the string of window index 0.
  1400. */
  1401. var strend = s.strstart + MAX_MATCH;
  1402. var scan_end1 = _win[scan + best_len - 1];
  1403. var scan_end = _win[scan + best_len];
  1404. /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
  1405. * It is easy to get rid of this optimization if necessary.
  1406. */
  1407. // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  1408. /* Do not waste too much time if we already have a good match: */
  1409. if (s.prev_length >= s.good_match) {
  1410. chain_length >>= 2;
  1411. }
  1412. /* Do not look for matches beyond the end of the input. This is necessary
  1413. * to make deflate deterministic.
  1414. */
  1415. if (nice_match > s.lookahead) {
  1416. nice_match = s.lookahead;
  1417. }
  1418. // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  1419. do {
  1420. // Assert(cur_match < s->strstart, "no future");
  1421. match = cur_match;
  1422. /* Skip to next match if the match length cannot increase
  1423. * or if the match length is less than 2. Note that the checks below
  1424. * for insufficient lookahead only occur occasionally for performance
  1425. * reasons. Therefore uninitialized memory will be accessed, and
  1426. * conditional jumps will be made that depend on those values.
  1427. * However the length of the match is limited to the lookahead, so
  1428. * the output of deflate is not affected by the uninitialized values.
  1429. */
  1430. if (_win[match + best_len] !== scan_end || _win[match + best_len - 1] !== scan_end1 || _win[match] !== _win[scan] || _win[++match] !== _win[scan + 1]) {
  1431. continue;
  1432. }
  1433. /* The check at best_len-1 can be removed because it will be made
  1434. * again later. (This heuristic is not always a win.)
  1435. * It is not necessary to compare scan[2] and match[2] since they
  1436. * are always equal when the other bytes match, given that
  1437. * the hash keys are equal and that HASH_BITS >= 8.
  1438. */
  1439. scan += 2;
  1440. match++;
  1441. // Assert(*scan == *match, "match[2]?");
  1442. /* We check for insufficient lookahead only every 8th comparison;
  1443. * the 256th check will be made at strstart+258.
  1444. */
  1445. do {
  1446. /*jshint noempty:false*/
  1447. } while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && _win[++scan] === _win[++match] && scan < strend);
  1448. // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  1449. len = MAX_MATCH - (strend - scan);
  1450. scan = strend - MAX_MATCH;
  1451. if (len > best_len) {
  1452. s.match_start = cur_match;
  1453. best_len = len;
  1454. if (len >= nice_match) {
  1455. break;
  1456. }
  1457. scan_end1 = _win[scan + best_len - 1];
  1458. scan_end = _win[scan + best_len];
  1459. }
  1460. } while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0);
  1461. if (best_len <= s.lookahead) {
  1462. return best_len;
  1463. }
  1464. return s.lookahead;
  1465. };
  1466. /* ===========================================================================
  1467. * Fill the window when the lookahead becomes insufficient.
  1468. * Updates strstart and lookahead.
  1469. *
  1470. * IN assertion: lookahead < MIN_LOOKAHEAD
  1471. * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
  1472. * At least one byte has been read, or avail_in == 0; reads are
  1473. * performed for at least two bytes (required for the zip translate_eol
  1474. * option -- not supported here).
  1475. */
  1476. var fill_window = function fill_window(s) {
  1477. var _w_size = s.w_size;
  1478. var n, more, str;
  1479. //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
  1480. do {
  1481. more = s.window_size - s.lookahead - s.strstart;
  1482. // JS ints have 32 bit, block below not needed
  1483. /* Deal with !@#$% 64K limit: */
  1484. //if (sizeof(int) <= 2) {
  1485. // if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  1486. // more = wsize;
  1487. //
  1488. // } else if (more == (unsigned)(-1)) {
  1489. // /* Very unlikely, but possible on 16 bit machine if
  1490. // * strstart == 0 && lookahead == 1 (input done a byte at time)
  1491. // */
  1492. // more--;
  1493. // }
  1494. //}
  1495. /* If the window is almost full and there is insufficient lookahead,
  1496. * move the upper half to the lower one to make room in the upper half.
  1497. */
  1498. if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {
  1499. s.window.set(s.window.subarray(_w_size, _w_size + _w_size - more), 0);
  1500. s.match_start -= _w_size;
  1501. s.strstart -= _w_size;
  1502. /* we now have strstart >= MAX_DIST */
  1503. s.block_start -= _w_size;
  1504. if (s.insert > s.strstart) {
  1505. s.insert = s.strstart;
  1506. }
  1507. slide_hash(s);
  1508. more += _w_size;
  1509. }
  1510. if (s.strm.avail_in === 0) {
  1511. break;
  1512. }
  1513. /* If there was no sliding:
  1514. * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
  1515. * more == window_size - lookahead - strstart
  1516. * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
  1517. * => more >= window_size - 2*WSIZE + 2
  1518. * In the BIG_MEM or MMAP case (not yet supported),
  1519. * window_size == input_size + MIN_LOOKAHEAD &&
  1520. * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
  1521. * Otherwise, window_size == 2*WSIZE so more >= 2.
  1522. * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
  1523. */
  1524. //Assert(more >= 2, "more < 2");
  1525. n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);
  1526. s.lookahead += n;
  1527. /* Initialize the hash value now that we have some input: */
  1528. if (s.lookahead + s.insert >= MIN_MATCH) {
  1529. str = s.strstart - s.insert;
  1530. s.ins_h = s.window[str];
  1531. /* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */
  1532. s.ins_h = HASH(s, s.ins_h, s.window[str + 1]);
  1533. //#if MIN_MATCH != 3
  1534. // Call update_hash() MIN_MATCH-3 more times
  1535. //#endif
  1536. while (s.insert) {
  1537. /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
  1538. s.ins_h = HASH(s, s.ins_h, s.window[str + MIN_MATCH - 1]);
  1539. s.prev[str & s.w_mask] = s.head[s.ins_h];
  1540. s.head[s.ins_h] = str;
  1541. str++;
  1542. s.insert--;
  1543. if (s.lookahead + s.insert < MIN_MATCH) {
  1544. break;
  1545. }
  1546. }
  1547. }
  1548. /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
  1549. * but this is not important since only literal bytes will be emitted.
  1550. */
  1551. } while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0);
  1552. /* If the WIN_INIT bytes after the end of the current data have never been
  1553. * written, then zero those bytes in order to avoid memory check reports of
  1554. * the use of uninitialized (or uninitialised as Julian writes) bytes by
  1555. * the longest match routines. Update the high water mark for the next
  1556. * time through here. WIN_INIT is set to MAX_MATCH since the longest match
  1557. * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
  1558. */
  1559. // if (s.high_water < s.window_size) {
  1560. // const curr = s.strstart + s.lookahead;
  1561. // let init = 0;
  1562. //
  1563. // if (s.high_water < curr) {
  1564. // /* Previous high water mark below current data -- zero WIN_INIT
  1565. // * bytes or up to end of window, whichever is less.
  1566. // */
  1567. // init = s.window_size - curr;
  1568. // if (init > WIN_INIT)
  1569. // init = WIN_INIT;
  1570. // zmemzero(s->window + curr, (unsigned)init);
  1571. // s->high_water = curr + init;
  1572. // }
  1573. // else if (s->high_water < (ulg)curr + WIN_INIT) {
  1574. // /* High water mark at or above current data, but below current data
  1575. // * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
  1576. // * to end of window, whichever is less.
  1577. // */
  1578. // init = (ulg)curr + WIN_INIT - s->high_water;
  1579. // if (init > s->window_size - s->high_water)
  1580. // init = s->window_size - s->high_water;
  1581. // zmemzero(s->window + s->high_water, (unsigned)init);
  1582. // s->high_water += init;
  1583. // }
  1584. // }
  1585. //
  1586. // Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
  1587. // "not enough room for search");
  1588. };
  1589. /* ===========================================================================
  1590. * Copy without compression as much as possible from the input stream, return
  1591. * the current block state.
  1592. *
  1593. * In case deflateParams() is used to later switch to a non-zero compression
  1594. * level, s->matches (otherwise unused when storing) keeps track of the number
  1595. * of hash table slides to perform. If s->matches is 1, then one hash table
  1596. * slide will be done when switching. If s->matches is 2, the maximum value
  1597. * allowed here, then the hash table will be cleared, since two or more slides
  1598. * is the same as a clear.
  1599. *
  1600. * deflate_stored() is written to minimize the number of times an input byte is
  1601. * copied. It is most efficient with large input and output buffers, which
  1602. * maximizes the opportunites to have a single copy from next_in to next_out.
  1603. */
  1604. var deflate_stored = function deflate_stored(s, flush) {
  1605. /* Smallest worthy block size when not flushing or finishing. By default
  1606. * this is 32K. This can be as small as 507 bytes for memLevel == 1. For
  1607. * large input and output buffers, the stored block size will be larger.
  1608. */
  1609. var min_block = s.pending_buf_size - 5 > s.w_size ? s.w_size : s.pending_buf_size - 5;
  1610. /* Copy as many min_block or larger stored blocks directly to next_out as
  1611. * possible. If flushing, copy the remaining available input to next_out as
  1612. * stored blocks, if there is enough space.
  1613. */
  1614. var len,
  1615. left,
  1616. have,
  1617. last = 0;
  1618. var used = s.strm.avail_in;
  1619. do {
  1620. /* Set len to the maximum size block that we can copy directly with the
  1621. * available input data and output space. Set left to how much of that
  1622. * would be copied from what's left in the window.
  1623. */
  1624. len = 65535 /* MAX_STORED */; /* maximum deflate stored block length */
  1625. have = s.bi_valid + 42 >> 3; /* number of header bytes */
  1626. if (s.strm.avail_out < have) {
  1627. /* need room for header */
  1628. break;
  1629. }
  1630. /* maximum stored block length that will fit in avail_out: */
  1631. have = s.strm.avail_out - have;
  1632. left = s.strstart - s.block_start; /* bytes left in window */
  1633. if (len > left + s.strm.avail_in) {
  1634. len = left + s.strm.avail_in; /* limit len to the input */
  1635. }
  1636. if (len > have) {
  1637. len = have; /* limit len to the output */
  1638. }
  1639. /* If the stored block would be less than min_block in length, or if
  1640. * unable to copy all of the available input when flushing, then try
  1641. * copying to the window and the pending buffer instead. Also don't
  1642. * write an empty block when flushing -- deflate() does that.
  1643. */
  1644. if (len < min_block && (len === 0 && flush !== Z_FINISH$3 || flush === Z_NO_FLUSH$2 || len !== left + s.strm.avail_in)) {
  1645. break;
  1646. }
  1647. /* Make a dummy stored block in pending to get the header bytes,
  1648. * including any pending bits. This also updates the debugging counts.
  1649. */
  1650. last = flush === Z_FINISH$3 && len === left + s.strm.avail_in ? 1 : 0;
  1651. _tr_stored_block(s, 0, 0, last);
  1652. /* Replace the lengths in the dummy stored block with len. */
  1653. s.pending_buf[s.pending - 4] = len;
  1654. s.pending_buf[s.pending - 3] = len >> 8;
  1655. s.pending_buf[s.pending - 2] = ~len;
  1656. s.pending_buf[s.pending - 1] = ~len >> 8;
  1657. /* Write the stored block header bytes. */
  1658. flush_pending(s.strm);
  1659. //#ifdef ZLIB_DEBUG
  1660. // /* Update debugging counts for the data about to be copied. */
  1661. // s->compressed_len += len << 3;
  1662. // s->bits_sent += len << 3;
  1663. //#endif
  1664. /* Copy uncompressed bytes from the window to next_out. */
  1665. if (left) {
  1666. if (left > len) {
  1667. left = len;
  1668. }
  1669. //zmemcpy(s->strm->next_out, s->window + s->block_start, left);
  1670. s.strm.output.set(s.window.subarray(s.block_start, s.block_start + left), s.strm.next_out);
  1671. s.strm.next_out += left;
  1672. s.strm.avail_out -= left;
  1673. s.strm.total_out += left;
  1674. s.block_start += left;
  1675. len -= left;
  1676. }
  1677. /* Copy uncompressed bytes directly from next_in to next_out, updating
  1678. * the check value.
  1679. */
  1680. if (len) {
  1681. read_buf(s.strm, s.strm.output, s.strm.next_out, len);
  1682. s.strm.next_out += len;
  1683. s.strm.avail_out -= len;
  1684. s.strm.total_out += len;
  1685. }
  1686. } while (last === 0);
  1687. /* Update the sliding window with the last s->w_size bytes of the copied
  1688. * data, or append all of the copied data to the existing window if less
  1689. * than s->w_size bytes were copied. Also update the number of bytes to
  1690. * insert in the hash tables, in the event that deflateParams() switches to
  1691. * a non-zero compression level.
  1692. */
  1693. used -= s.strm.avail_in; /* number of input bytes directly copied */
  1694. if (used) {
  1695. /* If any input was used, then no unused input remains in the window,
  1696. * therefore s->block_start == s->strstart.
  1697. */
  1698. if (used >= s.w_size) {
  1699. /* supplant the previous history */
  1700. s.matches = 2; /* clear hash */
  1701. //zmemcpy(s->window, s->strm->next_in - s->w_size, s->w_size);
  1702. s.window.set(s.strm.input.subarray(s.strm.next_in - s.w_size, s.strm.next_in), 0);
  1703. s.strstart = s.w_size;
  1704. s.insert = s.strstart;
  1705. } else {
  1706. if (s.window_size - s.strstart <= used) {
  1707. /* Slide the window down. */
  1708. s.strstart -= s.w_size;
  1709. //zmemcpy(s->window, s->window + s->w_size, s->strstart);
  1710. s.window.set(s.window.subarray(s.w_size, s.w_size + s.strstart), 0);
  1711. if (s.matches < 2) {
  1712. s.matches++; /* add a pending slide_hash() */
  1713. }
  1714. if (s.insert > s.strstart) {
  1715. s.insert = s.strstart;
  1716. }
  1717. }
  1718. //zmemcpy(s->window + s->strstart, s->strm->next_in - used, used);
  1719. s.window.set(s.strm.input.subarray(s.strm.next_in - used, s.strm.next_in), s.strstart);
  1720. s.strstart += used;
  1721. s.insert += used > s.w_size - s.insert ? s.w_size - s.insert : used;
  1722. }
  1723. s.block_start = s.strstart;
  1724. }
  1725. if (s.high_water < s.strstart) {
  1726. s.high_water = s.strstart;
  1727. }
  1728. /* If the last block was written to next_out, then done. */
  1729. if (last) {
  1730. return BS_FINISH_DONE;
  1731. }
  1732. /* If flushing and all input has been consumed, then done. */
  1733. if (flush !== Z_NO_FLUSH$2 && flush !== Z_FINISH$3 && s.strm.avail_in === 0 && s.strstart === s.block_start) {
  1734. return BS_BLOCK_DONE;
  1735. }
  1736. /* Fill the window with any remaining input. */
  1737. have = s.window_size - s.strstart;
  1738. if (s.strm.avail_in > have && s.block_start >= s.w_size) {
  1739. /* Slide the window down. */
  1740. s.block_start -= s.w_size;
  1741. s.strstart -= s.w_size;
  1742. //zmemcpy(s->window, s->window + s->w_size, s->strstart);
  1743. s.window.set(s.window.subarray(s.w_size, s.w_size + s.strstart), 0);
  1744. if (s.matches < 2) {
  1745. s.matches++; /* add a pending slide_hash() */
  1746. }
  1747. have += s.w_size; /* more space now */
  1748. if (s.insert > s.strstart) {
  1749. s.insert = s.strstart;
  1750. }
  1751. }
  1752. if (have > s.strm.avail_in) {
  1753. have = s.strm.avail_in;
  1754. }
  1755. if (have) {
  1756. read_buf(s.strm, s.window, s.strstart, have);
  1757. s.strstart += have;
  1758. s.insert += have > s.w_size - s.insert ? s.w_size - s.insert : have;
  1759. }
  1760. if (s.high_water < s.strstart) {
  1761. s.high_water = s.strstart;
  1762. }
  1763. /* There was not enough avail_out to write a complete worthy or flushed
  1764. * stored block to next_out. Write a stored block to pending instead, if we
  1765. * have enough input for a worthy block, or if flushing and there is enough
  1766. * room for the remaining input as a stored block in the pending buffer.
  1767. */
  1768. have = s.bi_valid + 42 >> 3; /* number of header bytes */
  1769. /* maximum stored block length that will fit in pending: */
  1770. have = s.pending_buf_size - have > 65535 /* MAX_STORED */ ? 65535 /* MAX_STORED */ : s.pending_buf_size - have;
  1771. min_block = have > s.w_size ? s.w_size : have;
  1772. left = s.strstart - s.block_start;
  1773. if (left >= min_block || (left || flush === Z_FINISH$3) && flush !== Z_NO_FLUSH$2 && s.strm.avail_in === 0 && left <= have) {
  1774. len = left > have ? have : left;
  1775. last = flush === Z_FINISH$3 && s.strm.avail_in === 0 && len === left ? 1 : 0;
  1776. _tr_stored_block(s, s.block_start, len, last);
  1777. s.block_start += len;
  1778. flush_pending(s.strm);
  1779. }
  1780. /* We've done all we can with the available input and output. */
  1781. return last ? BS_FINISH_STARTED : BS_NEED_MORE;
  1782. };
  1783. /* ===========================================================================
  1784. * Compress as much as possible from the input stream, return the current
  1785. * block state.
  1786. * This function does not perform lazy evaluation of matches and inserts
  1787. * new strings in the dictionary only for unmatched strings or for short
  1788. * matches. It is used only for the fast compression options.
  1789. */
  1790. var deflate_fast = function deflate_fast(s, flush) {
  1791. var hash_head; /* head of the hash chain */
  1792. var bflush; /* set if current block must be flushed */
  1793. for (;;) {
  1794. /* Make sure that we always have enough lookahead, except
  1795. * at the end of the input file. We need MAX_MATCH bytes
  1796. * for the next match, plus MIN_MATCH bytes to insert the
  1797. * string following the next match.
  1798. */
  1799. if (s.lookahead < MIN_LOOKAHEAD) {
  1800. fill_window(s);
  1801. if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH$2) {
  1802. return BS_NEED_MORE;
  1803. }
  1804. if (s.lookahead === 0) {
  1805. break; /* flush the current block */
  1806. }
  1807. }
  1808. /* Insert the string window[strstart .. strstart+2] in the
  1809. * dictionary, and set hash_head to the head of the hash chain:
  1810. */
  1811. hash_head = 0 /*NIL*/;
  1812. if (s.lookahead >= MIN_MATCH) {
  1813. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  1814. s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + MIN_MATCH - 1]);
  1815. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  1816. s.head[s.ins_h] = s.strstart;
  1817. /***/
  1818. }
  1819. /* Find the longest match, discarding those <= prev_length.
  1820. * At this point we have always match_length < MIN_MATCH
  1821. */
  1822. if (hash_head !== 0 /*NIL*/ && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD) {
  1823. /* To simplify the code, we prevent matches with the string
  1824. * of window index 0 (in particular we have to avoid a match
  1825. * of the string with itself at the start of the input file).
  1826. */
  1827. s.match_length = longest_match(s, hash_head);
  1828. /* longest_match() sets match_start */
  1829. }
  1830. if (s.match_length >= MIN_MATCH) {
  1831. // check_match(s, s.strstart, s.match_start, s.match_length); // for debug only
  1832. /*** _tr_tally_dist(s, s.strstart - s.match_start,
  1833. s.match_length - MIN_MATCH, bflush); ***/
  1834. bflush = _tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);
  1835. s.lookahead -= s.match_length;
  1836. /* Insert new strings in the hash table only if the match length
  1837. * is not too large. This saves time but degrades compression.
  1838. */
  1839. if (s.match_length <= s.max_lazy_match /*max_insert_length*/ && s.lookahead >= MIN_MATCH) {
  1840. s.match_length--; /* string at strstart already in table */
  1841. do {
  1842. s.strstart++;
  1843. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  1844. s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + MIN_MATCH - 1]);
  1845. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  1846. s.head[s.ins_h] = s.strstart;
  1847. /***/
  1848. /* strstart never exceeds WSIZE-MAX_MATCH, so there are
  1849. * always MIN_MATCH bytes ahead.
  1850. */
  1851. } while (--s.match_length !== 0);
  1852. s.strstart++;
  1853. } else {
  1854. s.strstart += s.match_length;
  1855. s.match_length = 0;
  1856. s.ins_h = s.window[s.strstart];
  1857. /* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */
  1858. s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + 1]);
  1859. //#if MIN_MATCH != 3
  1860. // Call UPDATE_HASH() MIN_MATCH-3 more times
  1861. //#endif
  1862. /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
  1863. * matter since it will be recomputed at next deflate call.
  1864. */
  1865. }
  1866. } else {
  1867. /* No match, output a literal byte */
  1868. //Tracevv((stderr,"%c", s.window[s.strstart]));
  1869. /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  1870. bflush = _tr_tally(s, 0, s.window[s.strstart]);
  1871. s.lookahead--;
  1872. s.strstart++;
  1873. }
  1874. if (bflush) {
  1875. /*** FLUSH_BLOCK(s, 0); ***/
  1876. flush_block_only(s, false);
  1877. if (s.strm.avail_out === 0) {
  1878. return BS_NEED_MORE;
  1879. }
  1880. /***/
  1881. }
  1882. }
  1883. s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;
  1884. if (flush === Z_FINISH$3) {
  1885. /*** FLUSH_BLOCK(s, 1); ***/
  1886. flush_block_only(s, true);
  1887. if (s.strm.avail_out === 0) {
  1888. return BS_FINISH_STARTED;
  1889. }
  1890. /***/
  1891. return BS_FINISH_DONE;
  1892. }
  1893. if (s.sym_next) {
  1894. /*** FLUSH_BLOCK(s, 0); ***/
  1895. flush_block_only(s, false);
  1896. if (s.strm.avail_out === 0) {
  1897. return BS_NEED_MORE;
  1898. }
  1899. /***/
  1900. }
  1901. return BS_BLOCK_DONE;
  1902. };
  1903. /* ===========================================================================
  1904. * Same as above, but achieves better compression. We use a lazy
  1905. * evaluation for matches: a match is finally adopted only if there is
  1906. * no better match at the next window position.
  1907. */
  1908. var deflate_slow = function deflate_slow(s, flush) {
  1909. var hash_head; /* head of hash chain */
  1910. var bflush; /* set if current block must be flushed */
  1911. var max_insert;
  1912. /* Process the input block. */
  1913. for (;;) {
  1914. /* Make sure that we always have enough lookahead, except
  1915. * at the end of the input file. We need MAX_MATCH bytes
  1916. * for the next match, plus MIN_MATCH bytes to insert the
  1917. * string following the next match.
  1918. */
  1919. if (s.lookahead < MIN_LOOKAHEAD) {
  1920. fill_window(s);
  1921. if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH$2) {
  1922. return BS_NEED_MORE;
  1923. }
  1924. if (s.lookahead === 0) {
  1925. break;
  1926. } /* flush the current block */
  1927. }
  1928. /* Insert the string window[strstart .. strstart+2] in the
  1929. * dictionary, and set hash_head to the head of the hash chain:
  1930. */
  1931. hash_head = 0 /*NIL*/;
  1932. if (s.lookahead >= MIN_MATCH) {
  1933. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  1934. s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + MIN_MATCH - 1]);
  1935. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  1936. s.head[s.ins_h] = s.strstart;
  1937. /***/
  1938. }
  1939. /* Find the longest match, discarding those <= prev_length.
  1940. */
  1941. s.prev_length = s.match_length;
  1942. s.prev_match = s.match_start;
  1943. s.match_length = MIN_MATCH - 1;
  1944. if (hash_head !== 0 /*NIL*/ && s.prev_length < s.max_lazy_match && s.strstart - hash_head <= s.w_size - MIN_LOOKAHEAD /*MAX_DIST(s)*/) {
  1945. /* To simplify the code, we prevent matches with the string
  1946. * of window index 0 (in particular we have to avoid a match
  1947. * of the string with itself at the start of the input file).
  1948. */
  1949. s.match_length = longest_match(s, hash_head);
  1950. /* longest_match() sets match_start */
  1951. if (s.match_length <= 5 && (s.strategy === Z_FILTERED || s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096 /*TOO_FAR*/)) {
  1952. /* If prev_match is also MIN_MATCH, match_start is garbage
  1953. * but we will ignore the current match anyway.
  1954. */
  1955. s.match_length = MIN_MATCH - 1;
  1956. }
  1957. }
  1958. /* If there was a match at the previous step and the current
  1959. * match is not better, output the previous match:
  1960. */
  1961. if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) {
  1962. max_insert = s.strstart + s.lookahead - MIN_MATCH;
  1963. /* Do not insert strings in hash table beyond this. */
  1964. //check_match(s, s.strstart-1, s.prev_match, s.prev_length);
  1965. /***_tr_tally_dist(s, s.strstart - 1 - s.prev_match,
  1966. s.prev_length - MIN_MATCH, bflush);***/
  1967. bflush = _tr_tally(s, s.strstart - 1 - s.prev_match, s.prev_length - MIN_MATCH);
  1968. /* Insert in hash table all strings up to the end of the match.
  1969. * strstart-1 and strstart are already inserted. If there is not
  1970. * enough lookahead, the last two strings are not inserted in
  1971. * the hash table.
  1972. */
  1973. s.lookahead -= s.prev_length - 1;
  1974. s.prev_length -= 2;
  1975. do {
  1976. if (++s.strstart <= max_insert) {
  1977. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  1978. s.ins_h = HASH(s, s.ins_h, s.window[s.strstart + MIN_MATCH - 1]);
  1979. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  1980. s.head[s.ins_h] = s.strstart;
  1981. /***/
  1982. }
  1983. } while (--s.prev_length !== 0);
  1984. s.match_available = 0;
  1985. s.match_length = MIN_MATCH - 1;
  1986. s.strstart++;
  1987. if (bflush) {
  1988. /*** FLUSH_BLOCK(s, 0); ***/
  1989. flush_block_only(s, false);
  1990. if (s.strm.avail_out === 0) {
  1991. return BS_NEED_MORE;
  1992. }
  1993. /***/
  1994. }
  1995. } else if (s.match_available) {
  1996. /* If there was no match at the previous position, output a
  1997. * single literal. If there was a match but the current match
  1998. * is longer, truncate the previous match to a single literal.
  1999. */
  2000. //Tracevv((stderr,"%c", s->window[s->strstart-1]));
  2001. /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
  2002. bflush = _tr_tally(s, 0, s.window[s.strstart - 1]);
  2003. if (bflush) {
  2004. /*** FLUSH_BLOCK_ONLY(s, 0) ***/
  2005. flush_block_only(s, false);
  2006. /***/
  2007. }
  2008. s.strstart++;
  2009. s.lookahead--;
  2010. if (s.strm.avail_out === 0) {
  2011. return BS_NEED_MORE;
  2012. }
  2013. } else {
  2014. /* There is no previous match to compare with, wait for
  2015. * the next step to decide.
  2016. */
  2017. s.match_available = 1;
  2018. s.strstart++;
  2019. s.lookahead--;
  2020. }
  2021. }
  2022. //Assert (flush != Z_NO_FLUSH, "no flush?");
  2023. if (s.match_available) {
  2024. //Tracevv((stderr,"%c", s->window[s->strstart-1]));
  2025. /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
  2026. bflush = _tr_tally(s, 0, s.window[s.strstart - 1]);
  2027. s.match_available = 0;
  2028. }
  2029. s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;
  2030. if (flush === Z_FINISH$3) {
  2031. /*** FLUSH_BLOCK(s, 1); ***/
  2032. flush_block_only(s, true);
  2033. if (s.strm.avail_out === 0) {
  2034. return BS_FINISH_STARTED;
  2035. }
  2036. /***/
  2037. return BS_FINISH_DONE;
  2038. }
  2039. if (s.sym_next) {
  2040. /*** FLUSH_BLOCK(s, 0); ***/
  2041. flush_block_only(s, false);
  2042. if (s.strm.avail_out === 0) {
  2043. return BS_NEED_MORE;
  2044. }
  2045. /***/
  2046. }
  2047. return BS_BLOCK_DONE;
  2048. };
  2049. /* ===========================================================================
  2050. * For Z_RLE, simply look for runs of bytes, generate matches only of distance
  2051. * one. Do not maintain a hash table. (It will be regenerated if this run of
  2052. * deflate switches away from Z_RLE.)
  2053. */
  2054. var deflate_rle = function deflate_rle(s, flush) {
  2055. var bflush; /* set if current block must be flushed */
  2056. var prev; /* byte at distance one to match */
  2057. var scan, strend; /* scan goes up to strend for length of run */
  2058. var _win = s.window;
  2059. for (;;) {
  2060. /* Make sure that we always have enough lookahead, except
  2061. * at the end of the input file. We need MAX_MATCH bytes
  2062. * for the longest run, plus one for the unrolled loop.
  2063. */
  2064. if (s.lookahead <= MAX_MATCH) {
  2065. fill_window(s);
  2066. if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH$2) {
  2067. return BS_NEED_MORE;
  2068. }
  2069. if (s.lookahead === 0) {
  2070. break;
  2071. } /* flush the current block */
  2072. }
  2073. /* See how many times the previous byte repeats */
  2074. s.match_length = 0;
  2075. if (s.lookahead >= MIN_MATCH && s.strstart > 0) {
  2076. scan = s.strstart - 1;
  2077. prev = _win[scan];
  2078. if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) {
  2079. strend = s.strstart + MAX_MATCH;
  2080. do {
  2081. /*jshint noempty:false*/
  2082. } while (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan] && scan < strend);
  2083. s.match_length = MAX_MATCH - (strend - scan);
  2084. if (s.match_length > s.lookahead) {
  2085. s.match_length = s.lookahead;
  2086. }
  2087. }
  2088. //Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
  2089. }
  2090. /* Emit match if have run of MIN_MATCH or longer, else emit literal */
  2091. if (s.match_length >= MIN_MATCH) {
  2092. //check_match(s, s.strstart, s.strstart - 1, s.match_length);
  2093. /*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/
  2094. bflush = _tr_tally(s, 1, s.match_length - MIN_MATCH);
  2095. s.lookahead -= s.match_length;
  2096. s.strstart += s.match_length;
  2097. s.match_length = 0;
  2098. } else {
  2099. /* No match, output a literal byte */
  2100. //Tracevv((stderr,"%c", s->window[s->strstart]));
  2101. /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  2102. bflush = _tr_tally(s, 0, s.window[s.strstart]);
  2103. s.lookahead--;
  2104. s.strstart++;
  2105. }
  2106. if (bflush) {
  2107. /*** FLUSH_BLOCK(s, 0); ***/
  2108. flush_block_only(s, false);
  2109. if (s.strm.avail_out === 0) {
  2110. return BS_NEED_MORE;
  2111. }
  2112. /***/
  2113. }
  2114. }
  2115. s.insert = 0;
  2116. if (flush === Z_FINISH$3) {
  2117. /*** FLUSH_BLOCK(s, 1); ***/
  2118. flush_block_only(s, true);
  2119. if (s.strm.avail_out === 0) {
  2120. return BS_FINISH_STARTED;
  2121. }
  2122. /***/
  2123. return BS_FINISH_DONE;
  2124. }
  2125. if (s.sym_next) {
  2126. /*** FLUSH_BLOCK(s, 0); ***/
  2127. flush_block_only(s, false);
  2128. if (s.strm.avail_out === 0) {
  2129. return BS_NEED_MORE;
  2130. }
  2131. /***/
  2132. }
  2133. return BS_BLOCK_DONE;
  2134. };
  2135. /* ===========================================================================
  2136. * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
  2137. * (It will be regenerated if this run of deflate switches away from Huffman.)
  2138. */
  2139. var deflate_huff = function deflate_huff(s, flush) {
  2140. var bflush; /* set if current block must be flushed */
  2141. for (;;) {
  2142. /* Make sure that we have a literal to write. */
  2143. if (s.lookahead === 0) {
  2144. fill_window(s);
  2145. if (s.lookahead === 0) {
  2146. if (flush === Z_NO_FLUSH$2) {
  2147. return BS_NEED_MORE;
  2148. }
  2149. break; /* flush the current block */
  2150. }
  2151. }
  2152. /* Output a literal byte */
  2153. s.match_length = 0;
  2154. //Tracevv((stderr,"%c", s->window[s->strstart]));
  2155. /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  2156. bflush = _tr_tally(s, 0, s.window[s.strstart]);
  2157. s.lookahead--;
  2158. s.strstart++;
  2159. if (bflush) {
  2160. /*** FLUSH_BLOCK(s, 0); ***/
  2161. flush_block_only(s, false);
  2162. if (s.strm.avail_out === 0) {
  2163. return BS_NEED_MORE;
  2164. }
  2165. /***/
  2166. }
  2167. }
  2168. s.insert = 0;
  2169. if (flush === Z_FINISH$3) {
  2170. /*** FLUSH_BLOCK(s, 1); ***/
  2171. flush_block_only(s, true);
  2172. if (s.strm.avail_out === 0) {
  2173. return BS_FINISH_STARTED;
  2174. }
  2175. /***/
  2176. return BS_FINISH_DONE;
  2177. }
  2178. if (s.sym_next) {
  2179. /*** FLUSH_BLOCK(s, 0); ***/
  2180. flush_block_only(s, false);
  2181. if (s.strm.avail_out === 0) {
  2182. return BS_NEED_MORE;
  2183. }
  2184. /***/
  2185. }
  2186. return BS_BLOCK_DONE;
  2187. };
  2188. /* Values for max_lazy_match, good_match and max_chain_length, depending on
  2189. * the desired pack level (0..9). The values given below have been tuned to
  2190. * exclude worst case performance for pathological files. Better values may be
  2191. * found for specific files.
  2192. */
  2193. function Config(good_length, max_lazy, nice_length, max_chain, func) {
  2194. this.good_length = good_length;
  2195. this.max_lazy = max_lazy;
  2196. this.nice_length = nice_length;
  2197. this.max_chain = max_chain;
  2198. this.func = func;
  2199. }
  2200. var configuration_table = [/* good lazy nice chain */
  2201. new Config(0, 0, 0, 0, deflate_stored), /* 0 store only */
  2202. new Config(4, 4, 8, 4, deflate_fast), /* 1 max speed, no lazy matches */
  2203. new Config(4, 5, 16, 8, deflate_fast), /* 2 */
  2204. new Config(4, 6, 32, 32, deflate_fast), /* 3 */
  2205. new Config(4, 4, 16, 16, deflate_slow), /* 4 lazy matches */
  2206. new Config(8, 16, 32, 32, deflate_slow), /* 5 */
  2207. new Config(8, 16, 128, 128, deflate_slow), /* 6 */
  2208. new Config(8, 32, 128, 256, deflate_slow), /* 7 */
  2209. new Config(32, 128, 258, 1024, deflate_slow), /* 8 */
  2210. new Config(32, 258, 258, 4096, deflate_slow) /* 9 max compression */];
  2211. /* ===========================================================================
  2212. * Initialize the "longest match" routines for a new zlib stream
  2213. */
  2214. var lm_init = function lm_init(s) {
  2215. s.window_size = 2 * s.w_size;
  2216. /*** CLEAR_HASH(s); ***/
  2217. zero(s.head); // Fill with NIL (= 0);
  2218. /* Set the default configuration parameters:
  2219. */
  2220. s.max_lazy_match = configuration_table[s.level].max_lazy;
  2221. s.good_match = configuration_table[s.level].good_length;
  2222. s.nice_match = configuration_table[s.level].nice_length;
  2223. s.max_chain_length = configuration_table[s.level].max_chain;
  2224. s.strstart = 0;
  2225. s.block_start = 0;
  2226. s.lookahead = 0;
  2227. s.insert = 0;
  2228. s.match_length = s.prev_length = MIN_MATCH - 1;
  2229. s.match_available = 0;
  2230. s.ins_h = 0;
  2231. };
  2232. function DeflateState() {
  2233. this.strm = null; /* pointer back to this zlib stream */
  2234. this.status = 0; /* as the name implies */
  2235. this.pending_buf = null; /* output still pending */
  2236. this.pending_buf_size = 0; /* size of pending_buf */
  2237. this.pending_out = 0; /* next pending byte to output to the stream */
  2238. this.pending = 0; /* nb of bytes in the pending buffer */
  2239. this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */
  2240. this.gzhead = null; /* gzip header information to write */
  2241. this.gzindex = 0; /* where in extra, name, or comment */
  2242. this.method = Z_DEFLATED$2; /* can only be DEFLATED */
  2243. this.last_flush = -1; /* value of flush param for previous deflate call */
  2244. this.w_size = 0; /* LZ77 window size (32K by default) */
  2245. this.w_bits = 0; /* log2(w_size) (8..16) */
  2246. this.w_mask = 0; /* w_size - 1 */
  2247. this.window = null;
  2248. /* Sliding window. Input bytes are read into the second half of the window,
  2249. * and move to the first half later to keep a dictionary of at least wSize
  2250. * bytes. With this organization, matches are limited to a distance of
  2251. * wSize-MAX_MATCH bytes, but this ensures that IO is always
  2252. * performed with a length multiple of the block size.
  2253. */
  2254. this.window_size = 0;
  2255. /* Actual size of window: 2*wSize, except when the user input buffer
  2256. * is directly used as sliding window.
  2257. */
  2258. this.prev = null;
  2259. /* Link to older string with same hash index. To limit the size of this
  2260. * array to 64K, this link is maintained only for the last 32K strings.
  2261. * An index in this array is thus a window index modulo 32K.
  2262. */
  2263. this.head = null; /* Heads of the hash chains or NIL. */
  2264. this.ins_h = 0; /* hash index of string to be inserted */
  2265. this.hash_size = 0; /* number of elements in hash table */
  2266. this.hash_bits = 0; /* log2(hash_size) */
  2267. this.hash_mask = 0; /* hash_size-1 */
  2268. this.hash_shift = 0;
  2269. /* Number of bits by which ins_h must be shifted at each input
  2270. * step. It must be such that after MIN_MATCH steps, the oldest
  2271. * byte no longer takes part in the hash key, that is:
  2272. * hash_shift * MIN_MATCH >= hash_bits
  2273. */
  2274. this.block_start = 0;
  2275. /* Window position at the beginning of the current output block. Gets
  2276. * negative when the window is moved backwards.
  2277. */
  2278. this.match_length = 0; /* length of best match */
  2279. this.prev_match = 0; /* previous match */
  2280. this.match_available = 0; /* set if previous match exists */
  2281. this.strstart = 0; /* start of string to insert */
  2282. this.match_start = 0; /* start of matching string */
  2283. this.lookahead = 0; /* number of valid bytes ahead in window */
  2284. this.prev_length = 0;
  2285. /* Length of the best match at previous step. Matches not greater than this
  2286. * are discarded. This is used in the lazy match evaluation.
  2287. */
  2288. this.max_chain_length = 0;
  2289. /* To speed up deflation, hash chains are never searched beyond this
  2290. * length. A higher limit improves compression ratio but degrades the
  2291. * speed.
  2292. */
  2293. this.max_lazy_match = 0;
  2294. /* Attempt to find a better match only when the current match is strictly
  2295. * smaller than this value. This mechanism is used only for compression
  2296. * levels >= 4.
  2297. */
  2298. // That's alias to max_lazy_match, don't use directly
  2299. //this.max_insert_length = 0;
  2300. /* Insert new strings in the hash table only if the match length is not
  2301. * greater than this length. This saves time but degrades compression.
  2302. * max_insert_length is used only for compression levels <= 3.
  2303. */
  2304. this.level = 0; /* compression level (1..9) */
  2305. this.strategy = 0; /* favor or force Huffman coding*/
  2306. this.good_match = 0;
  2307. /* Use a faster search when the previous match is longer than this */
  2308. this.nice_match = 0; /* Stop searching when current match exceeds this */
  2309. /* used by trees.c: */
  2310. /* Didn't use ct_data typedef below to suppress compiler warning */
  2311. // struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  2312. // struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  2313. // struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  2314. // Use flat array of DOUBLE size, with interleaved fata,
  2315. // because JS does not support effective
  2316. this.dyn_ltree = new Uint16Array(HEAP_SIZE * 2);
  2317. this.dyn_dtree = new Uint16Array((2 * D_CODES + 1) * 2);
  2318. this.bl_tree = new Uint16Array((2 * BL_CODES + 1) * 2);
  2319. zero(this.dyn_ltree);
  2320. zero(this.dyn_dtree);
  2321. zero(this.bl_tree);
  2322. this.l_desc = null; /* desc. for literal tree */
  2323. this.d_desc = null; /* desc. for distance tree */
  2324. this.bl_desc = null; /* desc. for bit length tree */
  2325. //ush bl_count[MAX_BITS+1];
  2326. this.bl_count = new Uint16Array(MAX_BITS + 1);
  2327. /* number of codes at each bit length for an optimal tree */
  2328. //int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  2329. this.heap = new Uint16Array(2 * L_CODES + 1); /* heap used to build the Huffman trees */
  2330. zero(this.heap);
  2331. this.heap_len = 0; /* number of elements in the heap */
  2332. this.heap_max = 0; /* element of largest frequency */
  2333. /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
  2334. * The same heap array is used to build all trees.
  2335. */
  2336. this.depth = new Uint16Array(2 * L_CODES + 1); //uch depth[2*L_CODES+1];
  2337. zero(this.depth);
  2338. /* Depth of each subtree used as tie breaker for trees of equal frequency
  2339. */
  2340. this.sym_buf = 0; /* buffer for distances and literals/lengths */
  2341. this.lit_bufsize = 0;
  2342. /* Size of match buffer for literals/lengths. There are 4 reasons for
  2343. * limiting lit_bufsize to 64K:
  2344. * - frequencies can be kept in 16 bit counters
  2345. * - if compression is not successful for the first block, all input
  2346. * data is still in the window so we can still emit a stored block even
  2347. * when input comes from standard input. (This can also be done for
  2348. * all blocks if lit_bufsize is not greater than 32K.)
  2349. * - if compression is not successful for a file smaller than 64K, we can
  2350. * even emit a stored file instead of a stored block (saving 5 bytes).
  2351. * This is applicable only for zip (not gzip or zlib).
  2352. * - creating new Huffman trees less frequently may not provide fast
  2353. * adaptation to changes in the input data statistics. (Take for
  2354. * example a binary file with poorly compressible code followed by
  2355. * a highly compressible string table.) Smaller buffer sizes give
  2356. * fast adaptation but have of course the overhead of transmitting
  2357. * trees more frequently.
  2358. * - I can't count above 4
  2359. */
  2360. this.sym_next = 0; /* running index in sym_buf */
  2361. this.sym_end = 0; /* symbol table full when sym_next reaches this */
  2362. this.opt_len = 0; /* bit length of current block with optimal trees */
  2363. this.static_len = 0; /* bit length of current block with static trees */
  2364. this.matches = 0; /* number of string matches in current block */
  2365. this.insert = 0; /* bytes at end of window left to insert */
  2366. this.bi_buf = 0;
  2367. /* Output buffer. bits are inserted starting at the bottom (least
  2368. * significant bits).
  2369. */
  2370. this.bi_valid = 0;
  2371. /* Number of valid bits in bi_buf. All bits above the last valid bit
  2372. * are always zero.
  2373. */
  2374. // Used for window memory init. We safely ignore it for JS. That makes
  2375. // sense only for pointers and memory check tools.
  2376. //this.high_water = 0;
  2377. /* High water mark offset in window for initialized bytes -- bytes above
  2378. * this are set to zero in order to avoid memory check warnings when
  2379. * longest match routines access bytes past the input. This is then
  2380. * updated to the new high water mark.
  2381. */
  2382. }
  2383. /* =========================================================================
  2384. * Check for a valid deflate stream state. Return 0 if ok, 1 if not.
  2385. */
  2386. var deflateStateCheck = function deflateStateCheck(strm) {
  2387. if (!strm) {
  2388. return 1;
  2389. }
  2390. var s = strm.state;
  2391. if (!s || s.strm !== strm || s.status !== INIT_STATE &&
  2392. //#ifdef GZIP
  2393. s.status !== GZIP_STATE &&
  2394. //#endif
  2395. s.status !== EXTRA_STATE && s.status !== NAME_STATE && s.status !== COMMENT_STATE && s.status !== HCRC_STATE && s.status !== BUSY_STATE && s.status !== FINISH_STATE) {
  2396. return 1;
  2397. }
  2398. return 0;
  2399. };
  2400. var deflateResetKeep = function deflateResetKeep(strm) {
  2401. if (deflateStateCheck(strm)) {
  2402. return err(strm, Z_STREAM_ERROR$2);
  2403. }
  2404. strm.total_in = strm.total_out = 0;
  2405. strm.data_type = Z_UNKNOWN;
  2406. var s = strm.state;
  2407. s.pending = 0;
  2408. s.pending_out = 0;
  2409. if (s.wrap < 0) {
  2410. s.wrap = -s.wrap;
  2411. /* was made negative by deflate(..., Z_FINISH); */
  2412. }
  2413. s.status =
  2414. //#ifdef GZIP
  2415. s.wrap === 2 ? GZIP_STATE :
  2416. //#endif
  2417. s.wrap ? INIT_STATE : BUSY_STATE;
  2418. strm.adler = s.wrap === 2 ? 0 // crc32(0, Z_NULL, 0)
  2419. : 1; // adler32(0, Z_NULL, 0)
  2420. s.last_flush = -2;
  2421. _tr_init(s);
  2422. return Z_OK$3;
  2423. };
  2424. var deflateReset = function deflateReset(strm) {
  2425. var ret = deflateResetKeep(strm);
  2426. if (ret === Z_OK$3) {
  2427. lm_init(strm.state);
  2428. }
  2429. return ret;
  2430. };
  2431. var deflateSetHeader = function deflateSetHeader(strm, head) {
  2432. if (deflateStateCheck(strm) || strm.state.wrap !== 2) {
  2433. return Z_STREAM_ERROR$2;
  2434. }
  2435. strm.state.gzhead = head;
  2436. return Z_OK$3;
  2437. };
  2438. var deflateInit2 = function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
  2439. if (!strm) {
  2440. // === Z_NULL
  2441. return Z_STREAM_ERROR$2;
  2442. }
  2443. var wrap = 1;
  2444. if (level === Z_DEFAULT_COMPRESSION$1) {
  2445. level = 6;
  2446. }
  2447. if (windowBits < 0) {
  2448. /* suppress zlib wrapper */
  2449. wrap = 0;
  2450. windowBits = -windowBits;
  2451. } else if (windowBits > 15) {
  2452. wrap = 2; /* write gzip wrapper instead */
  2453. windowBits -= 16;
  2454. }
  2455. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED$2 || windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED || windowBits === 8 && wrap !== 1) {
  2456. return err(strm, Z_STREAM_ERROR$2);
  2457. }
  2458. if (windowBits === 8) {
  2459. windowBits = 9;
  2460. }
  2461. /* until 256-byte window bug fixed */
  2462. var s = new DeflateState();
  2463. strm.state = s;
  2464. s.strm = strm;
  2465. s.status = INIT_STATE; /* to pass state test in deflateReset() */
  2466. s.wrap = wrap;
  2467. s.gzhead = null;
  2468. s.w_bits = windowBits;
  2469. s.w_size = 1 << s.w_bits;
  2470. s.w_mask = s.w_size - 1;
  2471. s.hash_bits = memLevel + 7;
  2472. s.hash_size = 1 << s.hash_bits;
  2473. s.hash_mask = s.hash_size - 1;
  2474. s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH);
  2475. s.window = new Uint8Array(s.w_size * 2);
  2476. s.head = new Uint16Array(s.hash_size);
  2477. s.prev = new Uint16Array(s.w_size);
  2478. // Don't need mem init magic for JS.
  2479. //s.high_water = 0; /* nothing written to s->window yet */
  2480. s.lit_bufsize = 1 << memLevel + 6; /* 16K elements by default */
  2481. /* We overlay pending_buf and sym_buf. This works since the average size
  2482. * for length/distance pairs over any compressed block is assured to be 31
  2483. * bits or less.
  2484. *
  2485. * Analysis: The longest fixed codes are a length code of 8 bits plus 5
  2486. * extra bits, for lengths 131 to 257. The longest fixed distance codes are
  2487. * 5 bits plus 13 extra bits, for distances 16385 to 32768. The longest
  2488. * possible fixed-codes length/distance pair is then 31 bits total.
  2489. *
  2490. * sym_buf starts one-fourth of the way into pending_buf. So there are
  2491. * three bytes in sym_buf for every four bytes in pending_buf. Each symbol
  2492. * in sym_buf is three bytes -- two for the distance and one for the
  2493. * literal/length. As each symbol is consumed, the pointer to the next
  2494. * sym_buf value to read moves forward three bytes. From that symbol, up to
  2495. * 31 bits are written to pending_buf. The closest the written pending_buf
  2496. * bits gets to the next sym_buf symbol to read is just before the last
  2497. * code is written. At that time, 31*(n-2) bits have been written, just
  2498. * after 24*(n-2) bits have been consumed from sym_buf. sym_buf starts at
  2499. * 8*n bits into pending_buf. (Note that the symbol buffer fills when n-1
  2500. * symbols are written.) The closest the writing gets to what is unread is
  2501. * then n+14 bits. Here n is lit_bufsize, which is 16384 by default, and
  2502. * can range from 128 to 32768.
  2503. *
  2504. * Therefore, at a minimum, there are 142 bits of space between what is
  2505. * written and what is read in the overlain buffers, so the symbols cannot
  2506. * be overwritten by the compressed data. That space is actually 139 bits,
  2507. * due to the three-bit fixed-code block header.
  2508. *
  2509. * That covers the case where either Z_FIXED is specified, forcing fixed
  2510. * codes, or when the use of fixed codes is chosen, because that choice
  2511. * results in a smaller compressed block than dynamic codes. That latter
  2512. * condition then assures that the above analysis also covers all dynamic
  2513. * blocks. A dynamic-code block will only be chosen to be emitted if it has
  2514. * fewer bits than a fixed-code block would for the same set of symbols.
  2515. * Therefore its average symbol length is assured to be less than 31. So
  2516. * the compressed data for a dynamic block also cannot overwrite the
  2517. * symbols from which it is being constructed.
  2518. */
  2519. s.pending_buf_size = s.lit_bufsize * 4;
  2520. s.pending_buf = new Uint8Array(s.pending_buf_size);
  2521. // It is offset from `s.pending_buf` (size is `s.lit_bufsize * 2`)
  2522. //s->sym_buf = s->pending_buf + s->lit_bufsize;
  2523. s.sym_buf = s.lit_bufsize;
  2524. //s->sym_end = (s->lit_bufsize - 1) * 3;
  2525. s.sym_end = (s.lit_bufsize - 1) * 3;
  2526. /* We avoid equality with lit_bufsize*3 because of wraparound at 64K
  2527. * on 16 bit machines and because stored blocks are restricted to
  2528. * 64K-1 bytes.
  2529. */
  2530. s.level = level;
  2531. s.strategy = strategy;
  2532. s.method = method;
  2533. return deflateReset(strm);
  2534. };
  2535. var deflateInit = function deflateInit(strm, level) {
  2536. return deflateInit2(strm, level, Z_DEFLATED$2, MAX_WBITS$1, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY$1);
  2537. };
  2538. /* ========================================================================= */
  2539. var deflate$2 = function deflate(strm, flush) {
  2540. if (deflateStateCheck(strm) || flush > Z_BLOCK$1 || flush < 0) {
  2541. return strm ? err(strm, Z_STREAM_ERROR$2) : Z_STREAM_ERROR$2;
  2542. }
  2543. var s = strm.state;
  2544. if (!strm.output || strm.avail_in !== 0 && !strm.input || s.status === FINISH_STATE && flush !== Z_FINISH$3) {
  2545. return err(strm, strm.avail_out === 0 ? Z_BUF_ERROR$1 : Z_STREAM_ERROR$2);
  2546. }
  2547. var old_flush = s.last_flush;
  2548. s.last_flush = flush;
  2549. /* Flush as much pending output as possible */
  2550. if (s.pending !== 0) {
  2551. flush_pending(strm);
  2552. if (strm.avail_out === 0) {
  2553. /* Since avail_out is 0, deflate will be called again with
  2554. * more output space, but possibly with both pending and
  2555. * avail_in equal to zero. There won't be anything to do,
  2556. * but this is not an error situation so make sure we
  2557. * return OK instead of BUF_ERROR at next call of deflate:
  2558. */
  2559. s.last_flush = -1;
  2560. return Z_OK$3;
  2561. }
  2562. /* Make sure there is something to do and avoid duplicate consecutive
  2563. * flushes. For repeated and useless calls with Z_FINISH, we keep
  2564. * returning Z_STREAM_END instead of Z_BUF_ERROR.
  2565. */
  2566. } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) && flush !== Z_FINISH$3) {
  2567. return err(strm, Z_BUF_ERROR$1);
  2568. }
  2569. /* User must not provide more input after the first FINISH: */
  2570. if (s.status === FINISH_STATE && strm.avail_in !== 0) {
  2571. return err(strm, Z_BUF_ERROR$1);
  2572. }
  2573. /* Write the header */
  2574. if (s.status === INIT_STATE && s.wrap === 0) {
  2575. s.status = BUSY_STATE;
  2576. }
  2577. if (s.status === INIT_STATE) {
  2578. /* zlib header */
  2579. var header = Z_DEFLATED$2 + (s.w_bits - 8 << 4) << 8;
  2580. var level_flags = -1;
  2581. if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {
  2582. level_flags = 0;
  2583. } else if (s.level < 6) {
  2584. level_flags = 1;
  2585. } else if (s.level === 6) {
  2586. level_flags = 2;
  2587. } else {
  2588. level_flags = 3;
  2589. }
  2590. header |= level_flags << 6;
  2591. if (s.strstart !== 0) {
  2592. header |= PRESET_DICT;
  2593. }
  2594. header += 31 - header % 31;
  2595. putShortMSB(s, header);
  2596. /* Save the adler32 of the preset dictionary: */
  2597. if (s.strstart !== 0) {
  2598. putShortMSB(s, strm.adler >>> 16);
  2599. putShortMSB(s, strm.adler & 0xffff);
  2600. }
  2601. strm.adler = 1; // adler32(0L, Z_NULL, 0);
  2602. s.status = BUSY_STATE;
  2603. /* Compression must start with an empty pending buffer */
  2604. flush_pending(strm);
  2605. if (s.pending !== 0) {
  2606. s.last_flush = -1;
  2607. return Z_OK$3;
  2608. }
  2609. }
  2610. //#ifdef GZIP
  2611. if (s.status === GZIP_STATE) {
  2612. /* gzip header */
  2613. strm.adler = 0; //crc32(0L, Z_NULL, 0);
  2614. put_byte(s, 31);
  2615. put_byte(s, 139);
  2616. put_byte(s, 8);
  2617. if (!s.gzhead) {
  2618. // s->gzhead == Z_NULL
  2619. put_byte(s, 0);
  2620. put_byte(s, 0);
  2621. put_byte(s, 0);
  2622. put_byte(s, 0);
  2623. put_byte(s, 0);
  2624. put_byte(s, s.level === 9 ? 2 : s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? 4 : 0);
  2625. put_byte(s, OS_CODE);
  2626. s.status = BUSY_STATE;
  2627. /* Compression must start with an empty pending buffer */
  2628. flush_pending(strm);
  2629. if (s.pending !== 0) {
  2630. s.last_flush = -1;
  2631. return Z_OK$3;
  2632. }
  2633. } else {
  2634. put_byte(s, (s.gzhead.text ? 1 : 0) + (s.gzhead.hcrc ? 2 : 0) + (!s.gzhead.extra ? 0 : 4) + (!s.gzhead.name ? 0 : 8) + (!s.gzhead.comment ? 0 : 16));
  2635. put_byte(s, s.gzhead.time & 0xff);
  2636. put_byte(s, s.gzhead.time >> 8 & 0xff);
  2637. put_byte(s, s.gzhead.time >> 16 & 0xff);
  2638. put_byte(s, s.gzhead.time >> 24 & 0xff);
  2639. put_byte(s, s.level === 9 ? 2 : s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ? 4 : 0);
  2640. put_byte(s, s.gzhead.os & 0xff);
  2641. if (s.gzhead.extra && s.gzhead.extra.length) {
  2642. put_byte(s, s.gzhead.extra.length & 0xff);
  2643. put_byte(s, s.gzhead.extra.length >> 8 & 0xff);
  2644. }
  2645. if (s.gzhead.hcrc) {
  2646. strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending, 0);
  2647. }
  2648. s.gzindex = 0;
  2649. s.status = EXTRA_STATE;
  2650. }
  2651. }
  2652. if (s.status === EXTRA_STATE) {
  2653. if (s.gzhead.extra /* != Z_NULL*/) {
  2654. var beg = s.pending; /* start of bytes to update crc */
  2655. var left = (s.gzhead.extra.length & 0xffff) - s.gzindex;
  2656. while (s.pending + left > s.pending_buf_size) {
  2657. var copy = s.pending_buf_size - s.pending;
  2658. // zmemcpy(s.pending_buf + s.pending,
  2659. // s.gzhead.extra + s.gzindex, copy);
  2660. s.pending_buf.set(s.gzhead.extra.subarray(s.gzindex, s.gzindex + copy), s.pending);
  2661. s.pending = s.pending_buf_size;
  2662. //--- HCRC_UPDATE(beg) ---//
  2663. if (s.gzhead.hcrc && s.pending > beg) {
  2664. strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending - beg, beg);
  2665. }
  2666. //---//
  2667. s.gzindex += copy;
  2668. flush_pending(strm);
  2669. if (s.pending !== 0) {
  2670. s.last_flush = -1;
  2671. return Z_OK$3;
  2672. }
  2673. beg = 0;
  2674. left -= copy;
  2675. }
  2676. // JS specific: s.gzhead.extra may be TypedArray or Array for backward compatibility
  2677. // TypedArray.slice and TypedArray.from don't exist in IE10-IE11
  2678. var gzhead_extra = new Uint8Array(s.gzhead.extra);
  2679. // zmemcpy(s->pending_buf + s->pending,
  2680. // s->gzhead->extra + s->gzindex, left);
  2681. s.pending_buf.set(gzhead_extra.subarray(s.gzindex, s.gzindex + left), s.pending);
  2682. s.pending += left;
  2683. //--- HCRC_UPDATE(beg) ---//
  2684. if (s.gzhead.hcrc && s.pending > beg) {
  2685. strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending - beg, beg);
  2686. }
  2687. //---//
  2688. s.gzindex = 0;
  2689. }
  2690. s.status = NAME_STATE;
  2691. }
  2692. if (s.status === NAME_STATE) {
  2693. if (s.gzhead.name /* != Z_NULL*/) {
  2694. var _beg = s.pending; /* start of bytes to update crc */
  2695. var val;
  2696. do {
  2697. if (s.pending === s.pending_buf_size) {
  2698. //--- HCRC_UPDATE(beg) ---//
  2699. if (s.gzhead.hcrc && s.pending > _beg) {
  2700. strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending - _beg, _beg);
  2701. }
  2702. //---//
  2703. flush_pending(strm);
  2704. if (s.pending !== 0) {
  2705. s.last_flush = -1;
  2706. return Z_OK$3;
  2707. }
  2708. _beg = 0;
  2709. }
  2710. // JS specific: little magic to add zero terminator to end of string
  2711. if (s.gzindex < s.gzhead.name.length) {
  2712. val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff;
  2713. } else {
  2714. val = 0;
  2715. }
  2716. put_byte(s, val);
  2717. } while (val !== 0);
  2718. //--- HCRC_UPDATE(beg) ---//
  2719. if (s.gzhead.hcrc && s.pending > _beg) {
  2720. strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending - _beg, _beg);
  2721. }
  2722. //---//
  2723. s.gzindex = 0;
  2724. }
  2725. s.status = COMMENT_STATE;
  2726. }
  2727. if (s.status === COMMENT_STATE) {
  2728. if (s.gzhead.comment /* != Z_NULL*/) {
  2729. var _beg2 = s.pending; /* start of bytes to update crc */
  2730. var _val;
  2731. do {
  2732. if (s.pending === s.pending_buf_size) {
  2733. //--- HCRC_UPDATE(beg) ---//
  2734. if (s.gzhead.hcrc && s.pending > _beg2) {
  2735. strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending - _beg2, _beg2);
  2736. }
  2737. //---//
  2738. flush_pending(strm);
  2739. if (s.pending !== 0) {
  2740. s.last_flush = -1;
  2741. return Z_OK$3;
  2742. }
  2743. _beg2 = 0;
  2744. }
  2745. // JS specific: little magic to add zero terminator to end of string
  2746. if (s.gzindex < s.gzhead.comment.length) {
  2747. _val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff;
  2748. } else {
  2749. _val = 0;
  2750. }
  2751. put_byte(s, _val);
  2752. } while (_val !== 0);
  2753. //--- HCRC_UPDATE(beg) ---//
  2754. if (s.gzhead.hcrc && s.pending > _beg2) {
  2755. strm.adler = crc32_1(strm.adler, s.pending_buf, s.pending - _beg2, _beg2);
  2756. }
  2757. //---//
  2758. }
  2759. s.status = HCRC_STATE;
  2760. }
  2761. if (s.status === HCRC_STATE) {
  2762. if (s.gzhead.hcrc) {
  2763. if (s.pending + 2 > s.pending_buf_size) {
  2764. flush_pending(strm);
  2765. if (s.pending !== 0) {
  2766. s.last_flush = -1;
  2767. return Z_OK$3;
  2768. }
  2769. }
  2770. put_byte(s, strm.adler & 0xff);
  2771. put_byte(s, strm.adler >> 8 & 0xff);
  2772. strm.adler = 0; //crc32(0L, Z_NULL, 0);
  2773. }
  2774. s.status = BUSY_STATE;
  2775. /* Compression must start with an empty pending buffer */
  2776. flush_pending(strm);
  2777. if (s.pending !== 0) {
  2778. s.last_flush = -1;
  2779. return Z_OK$3;
  2780. }
  2781. }
  2782. //#endif
  2783. /* Start a new block or continue the current one.
  2784. */
  2785. if (strm.avail_in !== 0 || s.lookahead !== 0 || flush !== Z_NO_FLUSH$2 && s.status !== FINISH_STATE) {
  2786. var bstate = s.level === 0 ? deflate_stored(s, flush) : s.strategy === Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : s.strategy === Z_RLE ? deflate_rle(s, flush) : configuration_table[s.level].func(s, flush);
  2787. if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) {
  2788. s.status = FINISH_STATE;
  2789. }
  2790. if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) {
  2791. if (strm.avail_out === 0) {
  2792. s.last_flush = -1;
  2793. /* avoid BUF_ERROR next call, see above */
  2794. }
  2795. return Z_OK$3;
  2796. /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
  2797. * of deflate should use the same flush parameter to make sure
  2798. * that the flush is complete. So we don't have to output an
  2799. * empty block here, this will be done at next call. This also
  2800. * ensures that for a very small output buffer, we emit at most
  2801. * one empty block.
  2802. */
  2803. }
  2804. if (bstate === BS_BLOCK_DONE) {
  2805. if (flush === Z_PARTIAL_FLUSH) {
  2806. _tr_align(s);
  2807. } else if (flush !== Z_BLOCK$1) {
  2808. /* FULL_FLUSH or SYNC_FLUSH */
  2809. _tr_stored_block(s, 0, 0, false);
  2810. /* For a full flush, this empty block will be recognized
  2811. * as a special marker by inflate_sync().
  2812. */
  2813. if (flush === Z_FULL_FLUSH$1) {
  2814. /*** CLEAR_HASH(s); ***/ /* forget history */
  2815. zero(s.head); // Fill with NIL (= 0);
  2816. if (s.lookahead === 0) {
  2817. s.strstart = 0;
  2818. s.block_start = 0;
  2819. s.insert = 0;
  2820. }
  2821. }
  2822. }
  2823. flush_pending(strm);
  2824. if (strm.avail_out === 0) {
  2825. s.last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  2826. return Z_OK$3;
  2827. }
  2828. }
  2829. }
  2830. if (flush !== Z_FINISH$3) {
  2831. return Z_OK$3;
  2832. }
  2833. if (s.wrap <= 0) {
  2834. return Z_STREAM_END$3;
  2835. }
  2836. /* Write the trailer */
  2837. if (s.wrap === 2) {
  2838. put_byte(s, strm.adler & 0xff);
  2839. put_byte(s, strm.adler >> 8 & 0xff);
  2840. put_byte(s, strm.adler >> 16 & 0xff);
  2841. put_byte(s, strm.adler >> 24 & 0xff);
  2842. put_byte(s, strm.total_in & 0xff);
  2843. put_byte(s, strm.total_in >> 8 & 0xff);
  2844. put_byte(s, strm.total_in >> 16 & 0xff);
  2845. put_byte(s, strm.total_in >> 24 & 0xff);
  2846. } else {
  2847. putShortMSB(s, strm.adler >>> 16);
  2848. putShortMSB(s, strm.adler & 0xffff);
  2849. }
  2850. flush_pending(strm);
  2851. /* If avail_out is zero, the application will call deflate again
  2852. * to flush the rest.
  2853. */
  2854. if (s.wrap > 0) {
  2855. s.wrap = -s.wrap;
  2856. }
  2857. /* write the trailer only once! */
  2858. return s.pending !== 0 ? Z_OK$3 : Z_STREAM_END$3;
  2859. };
  2860. var deflateEnd = function deflateEnd(strm) {
  2861. if (deflateStateCheck(strm)) {
  2862. return Z_STREAM_ERROR$2;
  2863. }
  2864. var status = strm.state.status;
  2865. strm.state = null;
  2866. return status === BUSY_STATE ? err(strm, Z_DATA_ERROR$2) : Z_OK$3;
  2867. };
  2868. /* =========================================================================
  2869. * Initializes the compression dictionary from the given byte
  2870. * sequence without producing any compressed output.
  2871. */
  2872. var deflateSetDictionary = function deflateSetDictionary(strm, dictionary) {
  2873. var dictLength = dictionary.length;
  2874. if (deflateStateCheck(strm)) {
  2875. return Z_STREAM_ERROR$2;
  2876. }
  2877. var s = strm.state;
  2878. var wrap = s.wrap;
  2879. if (wrap === 2 || wrap === 1 && s.status !== INIT_STATE || s.lookahead) {
  2880. return Z_STREAM_ERROR$2;
  2881. }
  2882. /* when using zlib wrappers, compute Adler-32 for provided dictionary */
  2883. if (wrap === 1) {
  2884. /* adler32(strm->adler, dictionary, dictLength); */
  2885. strm.adler = adler32_1(strm.adler, dictionary, dictLength, 0);
  2886. }
  2887. s.wrap = 0; /* avoid computing Adler-32 in read_buf */
  2888. /* if dictionary would fill window, just replace the history */
  2889. if (dictLength >= s.w_size) {
  2890. if (wrap === 0) {
  2891. /* already empty otherwise */
  2892. /*** CLEAR_HASH(s); ***/
  2893. zero(s.head); // Fill with NIL (= 0);
  2894. s.strstart = 0;
  2895. s.block_start = 0;
  2896. s.insert = 0;
  2897. }
  2898. /* use the tail */
  2899. // dictionary = dictionary.slice(dictLength - s.w_size);
  2900. var tmpDict = new Uint8Array(s.w_size);
  2901. tmpDict.set(dictionary.subarray(dictLength - s.w_size, dictLength), 0);
  2902. dictionary = tmpDict;
  2903. dictLength = s.w_size;
  2904. }
  2905. /* insert dictionary into window and hash */
  2906. var avail = strm.avail_in;
  2907. var next = strm.next_in;
  2908. var input = strm.input;
  2909. strm.avail_in = dictLength;
  2910. strm.next_in = 0;
  2911. strm.input = dictionary;
  2912. fill_window(s);
  2913. while (s.lookahead >= MIN_MATCH) {
  2914. var str = s.strstart;
  2915. var n = s.lookahead - (MIN_MATCH - 1);
  2916. do {
  2917. /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
  2918. s.ins_h = HASH(s, s.ins_h, s.window[str + MIN_MATCH - 1]);
  2919. s.prev[str & s.w_mask] = s.head[s.ins_h];
  2920. s.head[s.ins_h] = str;
  2921. str++;
  2922. } while (--n);
  2923. s.strstart = str;
  2924. s.lookahead = MIN_MATCH - 1;
  2925. fill_window(s);
  2926. }
  2927. s.strstart += s.lookahead;
  2928. s.block_start = s.strstart;
  2929. s.insert = s.lookahead;
  2930. s.lookahead = 0;
  2931. s.match_length = s.prev_length = MIN_MATCH - 1;
  2932. s.match_available = 0;
  2933. strm.next_in = next;
  2934. strm.input = input;
  2935. strm.avail_in = avail;
  2936. s.wrap = wrap;
  2937. return Z_OK$3;
  2938. };
  2939. var deflateInit_1 = deflateInit;
  2940. var deflateInit2_1 = deflateInit2;
  2941. var deflateReset_1 = deflateReset;
  2942. var deflateResetKeep_1 = deflateResetKeep;
  2943. var deflateSetHeader_1 = deflateSetHeader;
  2944. var deflate_2$1 = deflate$2;
  2945. var deflateEnd_1 = deflateEnd;
  2946. var deflateSetDictionary_1 = deflateSetDictionary;
  2947. var deflateInfo = 'pako deflate (from Nodeca project)';
  2948. /* Not implemented
  2949. module.exports.deflateBound = deflateBound;
  2950. module.exports.deflateCopy = deflateCopy;
  2951. module.exports.deflateGetDictionary = deflateGetDictionary;
  2952. module.exports.deflateParams = deflateParams;
  2953. module.exports.deflatePending = deflatePending;
  2954. module.exports.deflatePrime = deflatePrime;
  2955. module.exports.deflateTune = deflateTune;
  2956. */
  2957. var deflate_1$2 = {
  2958. deflateInit: deflateInit_1,
  2959. deflateInit2: deflateInit2_1,
  2960. deflateReset: deflateReset_1,
  2961. deflateResetKeep: deflateResetKeep_1,
  2962. deflateSetHeader: deflateSetHeader_1,
  2963. deflate: deflate_2$1,
  2964. deflateEnd: deflateEnd_1,
  2965. deflateSetDictionary: deflateSetDictionary_1,
  2966. deflateInfo: deflateInfo
  2967. };
  2968. function _typeof(obj) {
  2969. "@babel/helpers - typeof";
  2970. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
  2971. return typeof obj;
  2972. } : function (obj) {
  2973. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  2974. }, _typeof(obj);
  2975. }
  2976. var _has = function _has(obj, key) {
  2977. return Object.prototype.hasOwnProperty.call(obj, key);
  2978. };
  2979. var assign = function assign(obj /*from1, from2, from3, ...*/) {
  2980. var sources = Array.prototype.slice.call(arguments, 1);
  2981. while (sources.length) {
  2982. var source = sources.shift();
  2983. if (!source) {
  2984. continue;
  2985. }
  2986. if (_typeof(source) !== 'object') {
  2987. throw new TypeError(source + 'must be non-object');
  2988. }
  2989. for (var p in source) {
  2990. if (_has(source, p)) {
  2991. obj[p] = source[p];
  2992. }
  2993. }
  2994. }
  2995. return obj;
  2996. };
  2997. // Join array of chunks to single array.
  2998. var flattenChunks = function flattenChunks(chunks) {
  2999. // calculate data length
  3000. var len = 0;
  3001. for (var i = 0, l = chunks.length; i < l; i++) {
  3002. len += chunks[i].length;
  3003. }
  3004. // join chunks
  3005. var result = new Uint8Array(len);
  3006. for (var _i = 0, pos = 0, _l = chunks.length; _i < _l; _i++) {
  3007. var chunk = chunks[_i];
  3008. result.set(chunk, pos);
  3009. pos += chunk.length;
  3010. }
  3011. return result;
  3012. };
  3013. var common = {
  3014. assign: assign,
  3015. flattenChunks: flattenChunks
  3016. };
  3017. // String encode/decode helpers
  3018. // Quick check if we can use fast array to bin string conversion
  3019. //
  3020. // - apply(Array) can fail on Android 2.2
  3021. // - apply(Uint8Array) can fail on iOS 5.1 Safari
  3022. //
  3023. var STR_APPLY_UIA_OK = true;
  3024. try {
  3025. String.fromCharCode.apply(null, new Uint8Array(1));
  3026. } catch (__) {
  3027. STR_APPLY_UIA_OK = false;
  3028. }
  3029. // Table with utf8 lengths (calculated by first byte of sequence)
  3030. // Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
  3031. // because max possible codepoint is 0x10ffff
  3032. var _utf8len = new Uint8Array(256);
  3033. for (var q = 0; q < 256; q++) {
  3034. _utf8len[q] = q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1;
  3035. }
  3036. _utf8len[254] = _utf8len[254] = 1; // Invalid sequence start
  3037. // convert string to array (typed, when possible)
  3038. var string2buf = function string2buf(str) {
  3039. if (typeof TextEncoder === 'function' && TextEncoder.prototype.encode) {
  3040. return new TextEncoder().encode(str);
  3041. }
  3042. var buf,
  3043. c,
  3044. c2,
  3045. m_pos,
  3046. i,
  3047. str_len = str.length,
  3048. buf_len = 0;
  3049. // count binary size
  3050. for (m_pos = 0; m_pos < str_len; m_pos++) {
  3051. c = str.charCodeAt(m_pos);
  3052. if ((c & 0xfc00) === 0xd800 && m_pos + 1 < str_len) {
  3053. c2 = str.charCodeAt(m_pos + 1);
  3054. if ((c2 & 0xfc00) === 0xdc00) {
  3055. c = 0x10000 + (c - 0xd800 << 10) + (c2 - 0xdc00);
  3056. m_pos++;
  3057. }
  3058. }
  3059. buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
  3060. }
  3061. // allocate buffer
  3062. buf = new Uint8Array(buf_len);
  3063. // convert
  3064. for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
  3065. c = str.charCodeAt(m_pos);
  3066. if ((c & 0xfc00) === 0xd800 && m_pos + 1 < str_len) {
  3067. c2 = str.charCodeAt(m_pos + 1);
  3068. if ((c2 & 0xfc00) === 0xdc00) {
  3069. c = 0x10000 + (c - 0xd800 << 10) + (c2 - 0xdc00);
  3070. m_pos++;
  3071. }
  3072. }
  3073. if (c < 0x80) {
  3074. /* one byte */
  3075. buf[i++] = c;
  3076. } else if (c < 0x800) {
  3077. /* two bytes */
  3078. buf[i++] = 0xC0 | c >>> 6;
  3079. buf[i++] = 0x80 | c & 0x3f;
  3080. } else if (c < 0x10000) {
  3081. /* three bytes */
  3082. buf[i++] = 0xE0 | c >>> 12;
  3083. buf[i++] = 0x80 | c >>> 6 & 0x3f;
  3084. buf[i++] = 0x80 | c & 0x3f;
  3085. } else {
  3086. /* four bytes */
  3087. buf[i++] = 0xf0 | c >>> 18;
  3088. buf[i++] = 0x80 | c >>> 12 & 0x3f;
  3089. buf[i++] = 0x80 | c >>> 6 & 0x3f;
  3090. buf[i++] = 0x80 | c & 0x3f;
  3091. }
  3092. }
  3093. return buf;
  3094. };
  3095. // Helper
  3096. var buf2binstring = function buf2binstring(buf, len) {
  3097. // On Chrome, the arguments in a function call that are allowed is `65534`.
  3098. // If the length of the buffer is smaller than that, we can use this optimization,
  3099. // otherwise we will take a slower path.
  3100. if (len < 65534) {
  3101. if (buf.subarray && STR_APPLY_UIA_OK) {
  3102. return String.fromCharCode.apply(null, buf.length === len ? buf : buf.subarray(0, len));
  3103. }
  3104. }
  3105. var result = '';
  3106. for (var i = 0; i < len; i++) {
  3107. result += String.fromCharCode(buf[i]);
  3108. }
  3109. return result;
  3110. };
  3111. // convert array to string
  3112. var buf2string = function buf2string(buf, max) {
  3113. var len = max || buf.length;
  3114. if (typeof TextDecoder === 'function' && TextDecoder.prototype.decode) {
  3115. return new TextDecoder().decode(buf.subarray(0, max));
  3116. }
  3117. var i, out;
  3118. // Reserve max possible length (2 words per char)
  3119. // NB: by unknown reasons, Array is significantly faster for
  3120. // String.fromCharCode.apply than Uint16Array.
  3121. var utf16buf = new Array(len * 2);
  3122. for (out = 0, i = 0; i < len;) {
  3123. var c = buf[i++];
  3124. // quick process ascii
  3125. if (c < 0x80) {
  3126. utf16buf[out++] = c;
  3127. continue;
  3128. }
  3129. var c_len = _utf8len[c];
  3130. // skip 5 & 6 byte codes
  3131. if (c_len > 4) {
  3132. utf16buf[out++] = 0xfffd;
  3133. i += c_len - 1;
  3134. continue;
  3135. }
  3136. // apply mask on first byte
  3137. c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
  3138. // join the rest
  3139. while (c_len > 1 && i < len) {
  3140. c = c << 6 | buf[i++] & 0x3f;
  3141. c_len--;
  3142. }
  3143. // terminated by end of string?
  3144. if (c_len > 1) {
  3145. utf16buf[out++] = 0xfffd;
  3146. continue;
  3147. }
  3148. if (c < 0x10000) {
  3149. utf16buf[out++] = c;
  3150. } else {
  3151. c -= 0x10000;
  3152. utf16buf[out++] = 0xd800 | c >> 10 & 0x3ff;
  3153. utf16buf[out++] = 0xdc00 | c & 0x3ff;
  3154. }
  3155. }
  3156. return buf2binstring(utf16buf, out);
  3157. };
  3158. // Calculate max possible position in utf8 buffer,
  3159. // that will not break sequence. If that's not possible
  3160. // - (very small limits) return max size as is.
  3161. //
  3162. // buf[] - utf8 bytes array
  3163. // max - length limit (mandatory);
  3164. var utf8border = function utf8border(buf, max) {
  3165. max = max || buf.length;
  3166. if (max > buf.length) {
  3167. max = buf.length;
  3168. }
  3169. // go back from last position, until start of sequence found
  3170. var pos = max - 1;
  3171. while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) {
  3172. pos--;
  3173. }
  3174. // Very small and broken sequence,
  3175. // return max, because we should return something anyway.
  3176. if (pos < 0) {
  3177. return max;
  3178. }
  3179. // If we came to start of buffer - that means buffer is too small,
  3180. // return max too.
  3181. if (pos === 0) {
  3182. return max;
  3183. }
  3184. return pos + _utf8len[buf[pos]] > max ? pos : max;
  3185. };
  3186. var strings = {
  3187. string2buf: string2buf,
  3188. buf2string: buf2string,
  3189. utf8border: utf8border
  3190. };
  3191. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  3192. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  3193. //
  3194. // This software is provided 'as-is', without any express or implied
  3195. // warranty. In no event will the authors be held liable for any damages
  3196. // arising from the use of this software.
  3197. //
  3198. // Permission is granted to anyone to use this software for any purpose,
  3199. // including commercial applications, and to alter it and redistribute it
  3200. // freely, subject to the following restrictions:
  3201. //
  3202. // 1. The origin of this software must not be misrepresented; you must not
  3203. // claim that you wrote the original software. If you use this software
  3204. // in a product, an acknowledgment in the product documentation would be
  3205. // appreciated but is not required.
  3206. // 2. Altered source versions must be plainly marked as such, and must not be
  3207. // misrepresented as being the original software.
  3208. // 3. This notice may not be removed or altered from any source distribution.
  3209. function ZStream() {
  3210. /* next input byte */
  3211. this.input = null; // JS specific, because we have no pointers
  3212. this.next_in = 0;
  3213. /* number of bytes available at input */
  3214. this.avail_in = 0;
  3215. /* total number of input bytes read so far */
  3216. this.total_in = 0;
  3217. /* next output byte should be put there */
  3218. this.output = null; // JS specific, because we have no pointers
  3219. this.next_out = 0;
  3220. /* remaining free space at output */
  3221. this.avail_out = 0;
  3222. /* total number of bytes output so far */
  3223. this.total_out = 0;
  3224. /* last error message, NULL if no error */
  3225. this.msg = '' /*Z_NULL*/;
  3226. /* not visible by applications */
  3227. this.state = null;
  3228. /* best guess about the data type: binary or text */
  3229. this.data_type = 2 /*Z_UNKNOWN*/;
  3230. /* adler32 value of the uncompressed data */
  3231. this.adler = 0;
  3232. }
  3233. var zstream = ZStream;
  3234. var toString$1 = Object.prototype.toString;
  3235. /* Public constants ==========================================================*/
  3236. /* ===========================================================================*/
  3237. var Z_NO_FLUSH$1 = constants$2.Z_NO_FLUSH,
  3238. Z_SYNC_FLUSH = constants$2.Z_SYNC_FLUSH,
  3239. Z_FULL_FLUSH = constants$2.Z_FULL_FLUSH,
  3240. Z_FINISH$2 = constants$2.Z_FINISH,
  3241. Z_OK$2 = constants$2.Z_OK,
  3242. Z_STREAM_END$2 = constants$2.Z_STREAM_END,
  3243. Z_DEFAULT_COMPRESSION = constants$2.Z_DEFAULT_COMPRESSION,
  3244. Z_DEFAULT_STRATEGY = constants$2.Z_DEFAULT_STRATEGY,
  3245. Z_DEFLATED$1 = constants$2.Z_DEFLATED;
  3246. /* ===========================================================================*/
  3247. /**
  3248. * class Deflate
  3249. *
  3250. * Generic JS-style wrapper for zlib calls. If you don't need
  3251. * streaming behaviour - use more simple functions: [[deflate]],
  3252. * [[deflateRaw]] and [[gzip]].
  3253. **/
  3254. /* internal
  3255. * Deflate.chunks -> Array
  3256. *
  3257. * Chunks of output data, if [[Deflate#onData]] not overridden.
  3258. **/
  3259. /**
  3260. * Deflate.result -> Uint8Array
  3261. *
  3262. * Compressed result, generated by default [[Deflate#onData]]
  3263. * and [[Deflate#onEnd]] handlers. Filled after you push last chunk
  3264. * (call [[Deflate#push]] with `Z_FINISH` / `true` param).
  3265. **/
  3266. /**
  3267. * Deflate.err -> Number
  3268. *
  3269. * Error code after deflate finished. 0 (Z_OK) on success.
  3270. * You will not need it in real life, because deflate errors
  3271. * are possible only on wrong options or bad `onData` / `onEnd`
  3272. * custom handlers.
  3273. **/
  3274. /**
  3275. * Deflate.msg -> String
  3276. *
  3277. * Error message, if [[Deflate.err]] != 0
  3278. **/
  3279. /**
  3280. * new Deflate(options)
  3281. * - options (Object): zlib deflate options.
  3282. *
  3283. * Creates new deflator instance with specified params. Throws exception
  3284. * on bad params. Supported options:
  3285. *
  3286. * - `level`
  3287. * - `windowBits`
  3288. * - `memLevel`
  3289. * - `strategy`
  3290. * - `dictionary`
  3291. *
  3292. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  3293. * for more information on these.
  3294. *
  3295. * Additional options, for internal needs:
  3296. *
  3297. * - `chunkSize` - size of generated data chunks (16K by default)
  3298. * - `raw` (Boolean) - do raw deflate
  3299. * - `gzip` (Boolean) - create gzip wrapper
  3300. * - `header` (Object) - custom header for gzip
  3301. * - `text` (Boolean) - true if compressed data believed to be text
  3302. * - `time` (Number) - modification time, unix timestamp
  3303. * - `os` (Number) - operation system code
  3304. * - `extra` (Array) - array of bytes with extra data (max 65536)
  3305. * - `name` (String) - file name (binary string)
  3306. * - `comment` (String) - comment (binary string)
  3307. * - `hcrc` (Boolean) - true if header crc should be added
  3308. *
  3309. * ##### Example:
  3310. *
  3311. * ```javascript
  3312. * const pako = require('pako')
  3313. * , chunk1 = new Uint8Array([1,2,3,4,5,6,7,8,9])
  3314. * , chunk2 = new Uint8Array([10,11,12,13,14,15,16,17,18,19]);
  3315. *
  3316. * const deflate = new pako.Deflate({ level: 3});
  3317. *
  3318. * deflate.push(chunk1, false);
  3319. * deflate.push(chunk2, true); // true -> last chunk
  3320. *
  3321. * if (deflate.err) { throw new Error(deflate.err); }
  3322. *
  3323. * console.log(deflate.result);
  3324. * ```
  3325. **/
  3326. function Deflate$1(options) {
  3327. this.options = common.assign({
  3328. level: Z_DEFAULT_COMPRESSION,
  3329. method: Z_DEFLATED$1,
  3330. chunkSize: 16384,
  3331. windowBits: 15,
  3332. memLevel: 8,
  3333. strategy: Z_DEFAULT_STRATEGY
  3334. }, options || {});
  3335. var opt = this.options;
  3336. if (opt.raw && opt.windowBits > 0) {
  3337. opt.windowBits = -opt.windowBits;
  3338. } else if (opt.gzip && opt.windowBits > 0 && opt.windowBits < 16) {
  3339. opt.windowBits += 16;
  3340. }
  3341. this.err = 0; // error code, if happens (0 = Z_OK)
  3342. this.msg = ''; // error message
  3343. this.ended = false; // used to avoid multiple onEnd() calls
  3344. this.chunks = []; // chunks of compressed data
  3345. this.strm = new zstream();
  3346. this.strm.avail_out = 0;
  3347. var status = deflate_1$2.deflateInit2(this.strm, opt.level, opt.method, opt.windowBits, opt.memLevel, opt.strategy);
  3348. if (status !== Z_OK$2) {
  3349. throw new Error(messages[status]);
  3350. }
  3351. if (opt.header) {
  3352. deflate_1$2.deflateSetHeader(this.strm, opt.header);
  3353. }
  3354. if (opt.dictionary) {
  3355. var dict;
  3356. // Convert data if needed
  3357. if (typeof opt.dictionary === 'string') {
  3358. // If we need to compress text, change encoding to utf8.
  3359. dict = strings.string2buf(opt.dictionary);
  3360. } else if (toString$1.call(opt.dictionary) === '[object ArrayBuffer]') {
  3361. dict = new Uint8Array(opt.dictionary);
  3362. } else {
  3363. dict = opt.dictionary;
  3364. }
  3365. status = deflate_1$2.deflateSetDictionary(this.strm, dict);
  3366. if (status !== Z_OK$2) {
  3367. throw new Error(messages[status]);
  3368. }
  3369. this._dict_set = true;
  3370. }
  3371. }
  3372. /**
  3373. * Deflate#push(data[, flush_mode]) -> Boolean
  3374. * - data (Uint8Array|ArrayBuffer|String): input data. Strings will be
  3375. * converted to utf8 byte sequence.
  3376. * - flush_mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
  3377. * See constants. Skipped or `false` means Z_NO_FLUSH, `true` means Z_FINISH.
  3378. *
  3379. * Sends input data to deflate pipe, generating [[Deflate#onData]] calls with
  3380. * new compressed chunks. Returns `true` on success. The last data block must
  3381. * have `flush_mode` Z_FINISH (or `true`). That will flush internal pending
  3382. * buffers and call [[Deflate#onEnd]].
  3383. *
  3384. * On fail call [[Deflate#onEnd]] with error code and return false.
  3385. *
  3386. * ##### Example
  3387. *
  3388. * ```javascript
  3389. * push(chunk, false); // push one of data chunks
  3390. * ...
  3391. * push(chunk, true); // push last chunk
  3392. * ```
  3393. **/
  3394. Deflate$1.prototype.push = function (data, flush_mode) {
  3395. var strm = this.strm;
  3396. var chunkSize = this.options.chunkSize;
  3397. var status, _flush_mode;
  3398. if (this.ended) {
  3399. return false;
  3400. }
  3401. if (flush_mode === ~~flush_mode) _flush_mode = flush_mode;else _flush_mode = flush_mode === true ? Z_FINISH$2 : Z_NO_FLUSH$1;
  3402. // Convert data if needed
  3403. if (typeof data === 'string') {
  3404. // If we need to compress text, change encoding to utf8.
  3405. strm.input = strings.string2buf(data);
  3406. } else if (toString$1.call(data) === '[object ArrayBuffer]') {
  3407. strm.input = new Uint8Array(data);
  3408. } else {
  3409. strm.input = data;
  3410. }
  3411. strm.next_in = 0;
  3412. strm.avail_in = strm.input.length;
  3413. for (;;) {
  3414. if (strm.avail_out === 0) {
  3415. strm.output = new Uint8Array(chunkSize);
  3416. strm.next_out = 0;
  3417. strm.avail_out = chunkSize;
  3418. }
  3419. // Make sure avail_out > 6 to avoid repeating markers
  3420. if ((_flush_mode === Z_SYNC_FLUSH || _flush_mode === Z_FULL_FLUSH) && strm.avail_out <= 6) {
  3421. this.onData(strm.output.subarray(0, strm.next_out));
  3422. strm.avail_out = 0;
  3423. continue;
  3424. }
  3425. status = deflate_1$2.deflate(strm, _flush_mode);
  3426. // Ended => flush and finish
  3427. if (status === Z_STREAM_END$2) {
  3428. if (strm.next_out > 0) {
  3429. this.onData(strm.output.subarray(0, strm.next_out));
  3430. }
  3431. status = deflate_1$2.deflateEnd(this.strm);
  3432. this.onEnd(status);
  3433. this.ended = true;
  3434. return status === Z_OK$2;
  3435. }
  3436. // Flush if out buffer full
  3437. if (strm.avail_out === 0) {
  3438. this.onData(strm.output);
  3439. continue;
  3440. }
  3441. // Flush if requested and has data
  3442. if (_flush_mode > 0 && strm.next_out > 0) {
  3443. this.onData(strm.output.subarray(0, strm.next_out));
  3444. strm.avail_out = 0;
  3445. continue;
  3446. }
  3447. if (strm.avail_in === 0) break;
  3448. }
  3449. return true;
  3450. };
  3451. /**
  3452. * Deflate#onData(chunk) -> Void
  3453. * - chunk (Uint8Array): output data.
  3454. *
  3455. * By default, stores data blocks in `chunks[]` property and glue
  3456. * those in `onEnd`. Override this handler, if you need another behaviour.
  3457. **/
  3458. Deflate$1.prototype.onData = function (chunk) {
  3459. this.chunks.push(chunk);
  3460. };
  3461. /**
  3462. * Deflate#onEnd(status) -> Void
  3463. * - status (Number): deflate status. 0 (Z_OK) on success,
  3464. * other if not.
  3465. *
  3466. * Called once after you tell deflate that the input stream is
  3467. * complete (Z_FINISH). By default - join collected chunks,
  3468. * free memory and fill `results` / `err` properties.
  3469. **/
  3470. Deflate$1.prototype.onEnd = function (status) {
  3471. // On success - join
  3472. if (status === Z_OK$2) {
  3473. this.result = common.flattenChunks(this.chunks);
  3474. }
  3475. this.chunks = [];
  3476. this.err = status;
  3477. this.msg = this.strm.msg;
  3478. };
  3479. /**
  3480. * deflate(data[, options]) -> Uint8Array
  3481. * - data (Uint8Array|ArrayBuffer|String): input data to compress.
  3482. * - options (Object): zlib deflate options.
  3483. *
  3484. * Compress `data` with deflate algorithm and `options`.
  3485. *
  3486. * Supported options are:
  3487. *
  3488. * - level
  3489. * - windowBits
  3490. * - memLevel
  3491. * - strategy
  3492. * - dictionary
  3493. *
  3494. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  3495. * for more information on these.
  3496. *
  3497. * Sugar (options):
  3498. *
  3499. * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
  3500. * negative windowBits implicitly.
  3501. *
  3502. * ##### Example:
  3503. *
  3504. * ```javascript
  3505. * const pako = require('pako')
  3506. * const data = new Uint8Array([1,2,3,4,5,6,7,8,9]);
  3507. *
  3508. * console.log(pako.deflate(data));
  3509. * ```
  3510. **/
  3511. function deflate$1(input, options) {
  3512. var deflator = new Deflate$1(options);
  3513. deflator.push(input, true);
  3514. // That will never happens, if you don't cheat with options :)
  3515. if (deflator.err) {
  3516. throw deflator.msg || messages[deflator.err];
  3517. }
  3518. return deflator.result;
  3519. }
  3520. /**
  3521. * deflateRaw(data[, options]) -> Uint8Array
  3522. * - data (Uint8Array|ArrayBuffer|String): input data to compress.
  3523. * - options (Object): zlib deflate options.
  3524. *
  3525. * The same as [[deflate]], but creates raw data, without wrapper
  3526. * (header and adler32 crc).
  3527. **/
  3528. function deflateRaw$1(input, options) {
  3529. options = options || {};
  3530. options.raw = true;
  3531. return deflate$1(input, options);
  3532. }
  3533. /**
  3534. * gzip(data[, options]) -> Uint8Array
  3535. * - data (Uint8Array|ArrayBuffer|String): input data to compress.
  3536. * - options (Object): zlib deflate options.
  3537. *
  3538. * The same as [[deflate]], but create gzip wrapper instead of
  3539. * deflate one.
  3540. **/
  3541. function gzip$1(input, options) {
  3542. options = options || {};
  3543. options.gzip = true;
  3544. return deflate$1(input, options);
  3545. }
  3546. var Deflate_1$1 = Deflate$1;
  3547. var deflate_2 = deflate$1;
  3548. var deflateRaw_1$1 = deflateRaw$1;
  3549. var gzip_1$1 = gzip$1;
  3550. var constants$1 = constants$2;
  3551. var deflate_1$1 = {
  3552. Deflate: Deflate_1$1,
  3553. deflate: deflate_2,
  3554. deflateRaw: deflateRaw_1$1,
  3555. gzip: gzip_1$1,
  3556. constants: constants$1
  3557. };
  3558. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  3559. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  3560. //
  3561. // This software is provided 'as-is', without any express or implied
  3562. // warranty. In no event will the authors be held liable for any damages
  3563. // arising from the use of this software.
  3564. //
  3565. // Permission is granted to anyone to use this software for any purpose,
  3566. // including commercial applications, and to alter it and redistribute it
  3567. // freely, subject to the following restrictions:
  3568. //
  3569. // 1. The origin of this software must not be misrepresented; you must not
  3570. // claim that you wrote the original software. If you use this software
  3571. // in a product, an acknowledgment in the product documentation would be
  3572. // appreciated but is not required.
  3573. // 2. Altered source versions must be plainly marked as such, and must not be
  3574. // misrepresented as being the original software.
  3575. // 3. This notice may not be removed or altered from any source distribution.
  3576. // See state defs from inflate.js
  3577. var BAD$1 = 16209; /* got a data error -- remain here until reset */
  3578. var TYPE$1 = 16191; /* i: waiting for type bits, including last-flag bit */
  3579. /*
  3580. Decode literal, length, and distance codes and write out the resulting
  3581. literal and match bytes until either not enough input or output is
  3582. available, an end-of-block is encountered, or a data error is encountered.
  3583. When large enough input and output buffers are supplied to inflate(), for
  3584. example, a 16K input buffer and a 64K output buffer, more than 95% of the
  3585. inflate execution time is spent in this routine.
  3586. Entry assumptions:
  3587. state.mode === LEN
  3588. strm.avail_in >= 6
  3589. strm.avail_out >= 258
  3590. start >= strm.avail_out
  3591. state.bits < 8
  3592. On return, state.mode is one of:
  3593. LEN -- ran out of enough output space or enough available input
  3594. TYPE -- reached end of block code, inflate() to interpret next block
  3595. BAD -- error in block data
  3596. Notes:
  3597. - The maximum input bits used by a length/distance pair is 15 bits for the
  3598. length code, 5 bits for the length extra, 15 bits for the distance code,
  3599. and 13 bits for the distance extra. This totals 48 bits, or six bytes.
  3600. Therefore if strm.avail_in >= 6, then there is enough input to avoid
  3601. checking for available input while decoding.
  3602. - The maximum bytes that a single length/distance pair can output is 258
  3603. bytes, which is the maximum length that can be coded. inflate_fast()
  3604. requires strm.avail_out >= 258 for each loop to avoid checking for
  3605. output space.
  3606. */
  3607. var inffast = function inflate_fast(strm, start) {
  3608. var _in; /* local strm.input */
  3609. var last; /* have enough input while in < last */
  3610. var _out; /* local strm.output */
  3611. var beg; /* inflate()'s initial strm.output */
  3612. var end; /* while out < end, enough space available */
  3613. //#ifdef INFLATE_STRICT
  3614. var dmax; /* maximum distance from zlib header */
  3615. //#endif
  3616. var wsize; /* window size or zero if not using window */
  3617. var whave; /* valid bytes in the window */
  3618. var wnext; /* window write index */
  3619. // Use `s_window` instead `window`, avoid conflict with instrumentation tools
  3620. var s_window; /* allocated sliding window, if wsize != 0 */
  3621. var hold; /* local strm.hold */
  3622. var bits; /* local strm.bits */
  3623. var lcode; /* local strm.lencode */
  3624. var dcode; /* local strm.distcode */
  3625. var lmask; /* mask for first level of length codes */
  3626. var dmask; /* mask for first level of distance codes */
  3627. var here; /* retrieved table entry */
  3628. var op; /* code bits, operation, extra bits, or */
  3629. /* window position, window bytes to copy */
  3630. var len; /* match length, unused bytes */
  3631. var dist; /* match distance */
  3632. var from; /* where to copy match from */
  3633. var from_source;
  3634. var input, output; // JS specific, because we have no pointers
  3635. /* copy state to local variables */
  3636. var state = strm.state;
  3637. //here = state.here;
  3638. _in = strm.next_in;
  3639. input = strm.input;
  3640. last = _in + (strm.avail_in - 5);
  3641. _out = strm.next_out;
  3642. output = strm.output;
  3643. beg = _out - (start - strm.avail_out);
  3644. end = _out + (strm.avail_out - 257);
  3645. //#ifdef INFLATE_STRICT
  3646. dmax = state.dmax;
  3647. //#endif
  3648. wsize = state.wsize;
  3649. whave = state.whave;
  3650. wnext = state.wnext;
  3651. s_window = state.window;
  3652. hold = state.hold;
  3653. bits = state.bits;
  3654. lcode = state.lencode;
  3655. dcode = state.distcode;
  3656. lmask = (1 << state.lenbits) - 1;
  3657. dmask = (1 << state.distbits) - 1;
  3658. /* decode literals and length/distances until end-of-block or not enough
  3659. input data or output space */
  3660. top: do {
  3661. if (bits < 15) {
  3662. hold += input[_in++] << bits;
  3663. bits += 8;
  3664. hold += input[_in++] << bits;
  3665. bits += 8;
  3666. }
  3667. here = lcode[hold & lmask];
  3668. dolen: for (;;) {
  3669. // Goto emulation
  3670. op = here >>> 24 /*here.bits*/;
  3671. hold >>>= op;
  3672. bits -= op;
  3673. op = here >>> 16 & 0xff /*here.op*/;
  3674. if (op === 0) {
  3675. /* literal */
  3676. //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
  3677. // "inflate: literal '%c'\n" :
  3678. // "inflate: literal 0x%02x\n", here.val));
  3679. output[_out++] = here & 0xffff /*here.val*/;
  3680. } else if (op & 16) {
  3681. /* length base */
  3682. len = here & 0xffff /*here.val*/;
  3683. op &= 15; /* number of extra bits */
  3684. if (op) {
  3685. if (bits < op) {
  3686. hold += input[_in++] << bits;
  3687. bits += 8;
  3688. }
  3689. len += hold & (1 << op) - 1;
  3690. hold >>>= op;
  3691. bits -= op;
  3692. }
  3693. //Tracevv((stderr, "inflate: length %u\n", len));
  3694. if (bits < 15) {
  3695. hold += input[_in++] << bits;
  3696. bits += 8;
  3697. hold += input[_in++] << bits;
  3698. bits += 8;
  3699. }
  3700. here = dcode[hold & dmask];
  3701. dodist: for (;;) {
  3702. // goto emulation
  3703. op = here >>> 24 /*here.bits*/;
  3704. hold >>>= op;
  3705. bits -= op;
  3706. op = here >>> 16 & 0xff /*here.op*/;
  3707. if (op & 16) {
  3708. /* distance base */
  3709. dist = here & 0xffff /*here.val*/;
  3710. op &= 15; /* number of extra bits */
  3711. if (bits < op) {
  3712. hold += input[_in++] << bits;
  3713. bits += 8;
  3714. if (bits < op) {
  3715. hold += input[_in++] << bits;
  3716. bits += 8;
  3717. }
  3718. }
  3719. dist += hold & (1 << op) - 1;
  3720. //#ifdef INFLATE_STRICT
  3721. if (dist > dmax) {
  3722. strm.msg = 'invalid distance too far back';
  3723. state.mode = BAD$1;
  3724. break top;
  3725. }
  3726. //#endif
  3727. hold >>>= op;
  3728. bits -= op;
  3729. //Tracevv((stderr, "inflate: distance %u\n", dist));
  3730. op = _out - beg; /* max distance in output */
  3731. if (dist > op) {
  3732. /* see if copy from window */
  3733. op = dist - op; /* distance back in window */
  3734. if (op > whave) {
  3735. if (state.sane) {
  3736. strm.msg = 'invalid distance too far back';
  3737. state.mode = BAD$1;
  3738. break top;
  3739. }
  3740. // (!) This block is disabled in zlib defaults,
  3741. // don't enable it for binary compatibility
  3742. //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
  3743. // if (len <= op - whave) {
  3744. // do {
  3745. // output[_out++] = 0;
  3746. // } while (--len);
  3747. // continue top;
  3748. // }
  3749. // len -= op - whave;
  3750. // do {
  3751. // output[_out++] = 0;
  3752. // } while (--op > whave);
  3753. // if (op === 0) {
  3754. // from = _out - dist;
  3755. // do {
  3756. // output[_out++] = output[from++];
  3757. // } while (--len);
  3758. // continue top;
  3759. // }
  3760. //#endif
  3761. }
  3762. from = 0; // window index
  3763. from_source = s_window;
  3764. if (wnext === 0) {
  3765. /* very common case */
  3766. from += wsize - op;
  3767. if (op < len) {
  3768. /* some from window */
  3769. len -= op;
  3770. do {
  3771. output[_out++] = s_window[from++];
  3772. } while (--op);
  3773. from = _out - dist; /* rest from output */
  3774. from_source = output;
  3775. }
  3776. } else if (wnext < op) {
  3777. /* wrap around window */
  3778. from += wsize + wnext - op;
  3779. op -= wnext;
  3780. if (op < len) {
  3781. /* some from end of window */
  3782. len -= op;
  3783. do {
  3784. output[_out++] = s_window[from++];
  3785. } while (--op);
  3786. from = 0;
  3787. if (wnext < len) {
  3788. /* some from start of window */
  3789. op = wnext;
  3790. len -= op;
  3791. do {
  3792. output[_out++] = s_window[from++];
  3793. } while (--op);
  3794. from = _out - dist; /* rest from output */
  3795. from_source = output;
  3796. }
  3797. }
  3798. } else {
  3799. /* contiguous in window */
  3800. from += wnext - op;
  3801. if (op < len) {
  3802. /* some from window */
  3803. len -= op;
  3804. do {
  3805. output[_out++] = s_window[from++];
  3806. } while (--op);
  3807. from = _out - dist; /* rest from output */
  3808. from_source = output;
  3809. }
  3810. }
  3811. while (len > 2) {
  3812. output[_out++] = from_source[from++];
  3813. output[_out++] = from_source[from++];
  3814. output[_out++] = from_source[from++];
  3815. len -= 3;
  3816. }
  3817. if (len) {
  3818. output[_out++] = from_source[from++];
  3819. if (len > 1) {
  3820. output[_out++] = from_source[from++];
  3821. }
  3822. }
  3823. } else {
  3824. from = _out - dist; /* copy direct from output */
  3825. do {
  3826. /* minimum length is three */
  3827. output[_out++] = output[from++];
  3828. output[_out++] = output[from++];
  3829. output[_out++] = output[from++];
  3830. len -= 3;
  3831. } while (len > 2);
  3832. if (len) {
  3833. output[_out++] = output[from++];
  3834. if (len > 1) {
  3835. output[_out++] = output[from++];
  3836. }
  3837. }
  3838. }
  3839. } else if ((op & 64) === 0) {
  3840. /* 2nd level distance code */
  3841. here = dcode[(here & 0xffff /*here.val*/) + (hold & (1 << op) - 1)];
  3842. continue dodist;
  3843. } else {
  3844. strm.msg = 'invalid distance code';
  3845. state.mode = BAD$1;
  3846. break top;
  3847. }
  3848. break; // need to emulate goto via "continue"
  3849. }
  3850. } else if ((op & 64) === 0) {
  3851. /* 2nd level length code */
  3852. here = lcode[(here & 0xffff /*here.val*/) + (hold & (1 << op) - 1)];
  3853. continue dolen;
  3854. } else if (op & 32) {
  3855. /* end-of-block */
  3856. //Tracevv((stderr, "inflate: end of block\n"));
  3857. state.mode = TYPE$1;
  3858. break top;
  3859. } else {
  3860. strm.msg = 'invalid literal/length code';
  3861. state.mode = BAD$1;
  3862. break top;
  3863. }
  3864. break; // need to emulate goto via "continue"
  3865. }
  3866. } while (_in < last && _out < end);
  3867. /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
  3868. len = bits >> 3;
  3869. _in -= len;
  3870. bits -= len << 3;
  3871. hold &= (1 << bits) - 1;
  3872. /* update state and return */
  3873. strm.next_in = _in;
  3874. strm.next_out = _out;
  3875. strm.avail_in = _in < last ? 5 + (last - _in) : 5 - (_in - last);
  3876. strm.avail_out = _out < end ? 257 + (end - _out) : 257 - (_out - end);
  3877. state.hold = hold;
  3878. state.bits = bits;
  3879. return;
  3880. };
  3881. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  3882. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  3883. //
  3884. // This software is provided 'as-is', without any express or implied
  3885. // warranty. In no event will the authors be held liable for any damages
  3886. // arising from the use of this software.
  3887. //
  3888. // Permission is granted to anyone to use this software for any purpose,
  3889. // including commercial applications, and to alter it and redistribute it
  3890. // freely, subject to the following restrictions:
  3891. //
  3892. // 1. The origin of this software must not be misrepresented; you must not
  3893. // claim that you wrote the original software. If you use this software
  3894. // in a product, an acknowledgment in the product documentation would be
  3895. // appreciated but is not required.
  3896. // 2. Altered source versions must be plainly marked as such, and must not be
  3897. // misrepresented as being the original software.
  3898. // 3. This notice may not be removed or altered from any source distribution.
  3899. var MAXBITS = 15;
  3900. var ENOUGH_LENS$1 = 852;
  3901. var ENOUGH_DISTS$1 = 592;
  3902. //const ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
  3903. var CODES$1 = 0;
  3904. var LENS$1 = 1;
  3905. var DISTS$1 = 2;
  3906. var lbase = new Uint16Array([/* Length codes 257..285 base */
  3907. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0]);
  3908. var lext = new Uint8Array([/* Length codes 257..285 extra */
  3909. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78]);
  3910. var dbase = new Uint16Array([/* Distance codes 0..29 base */
  3911. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0]);
  3912. var dext = new Uint8Array([/* Distance codes 0..29 extra */
  3913. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64]);
  3914. var inflate_table = function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts) {
  3915. var bits = opts.bits;
  3916. //here = opts.here; /* table entry for duplication */
  3917. var len = 0; /* a code's length in bits */
  3918. var sym = 0; /* index of code symbols */
  3919. var min = 0,
  3920. max = 0; /* minimum and maximum code lengths */
  3921. var root = 0; /* number of index bits for root table */
  3922. var curr = 0; /* number of index bits for current table */
  3923. var drop = 0; /* code bits to drop for sub-table */
  3924. var left = 0; /* number of prefix codes available */
  3925. var used = 0; /* code entries in table used */
  3926. var huff = 0; /* Huffman code */
  3927. var incr; /* for incrementing code, index */
  3928. var fill; /* index for replicating entries */
  3929. var low; /* low bits for current root entry */
  3930. var mask; /* mask for low root bits */
  3931. var next; /* next available space in table */
  3932. var base = null; /* base value table to use */
  3933. // let shoextra; /* extra bits table to use */
  3934. var match; /* use base and extra for symbol >= match */
  3935. var count = new Uint16Array(MAXBITS + 1); //[MAXBITS+1]; /* number of codes of each length */
  3936. var offs = new Uint16Array(MAXBITS + 1); //[MAXBITS+1]; /* offsets in table for each length */
  3937. var extra = null;
  3938. var here_bits, here_op, here_val;
  3939. /*
  3940. Process a set of code lengths to create a canonical Huffman code. The
  3941. code lengths are lens[0..codes-1]. Each length corresponds to the
  3942. symbols 0..codes-1. The Huffman code is generated by first sorting the
  3943. symbols by length from short to long, and retaining the symbol order
  3944. for codes with equal lengths. Then the code starts with all zero bits
  3945. for the first code of the shortest length, and the codes are integer
  3946. increments for the same length, and zeros are appended as the length
  3947. increases. For the deflate format, these bits are stored backwards
  3948. from their more natural integer increment ordering, and so when the
  3949. decoding tables are built in the large loop below, the integer codes
  3950. are incremented backwards.
  3951. This routine assumes, but does not check, that all of the entries in
  3952. lens[] are in the range 0..MAXBITS. The caller must assure this.
  3953. 1..MAXBITS is interpreted as that code length. zero means that that
  3954. symbol does not occur in this code.
  3955. The codes are sorted by computing a count of codes for each length,
  3956. creating from that a table of starting indices for each length in the
  3957. sorted table, and then entering the symbols in order in the sorted
  3958. table. The sorted table is work[], with that space being provided by
  3959. the caller.
  3960. The length counts are used for other purposes as well, i.e. finding
  3961. the minimum and maximum length codes, determining if there are any
  3962. codes at all, checking for a valid set of lengths, and looking ahead
  3963. at length counts to determine sub-table sizes when building the
  3964. decoding tables.
  3965. */
  3966. /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
  3967. for (len = 0; len <= MAXBITS; len++) {
  3968. count[len] = 0;
  3969. }
  3970. for (sym = 0; sym < codes; sym++) {
  3971. count[lens[lens_index + sym]]++;
  3972. }
  3973. /* bound code lengths, force root to be within code lengths */
  3974. root = bits;
  3975. for (max = MAXBITS; max >= 1; max--) {
  3976. if (count[max] !== 0) {
  3977. break;
  3978. }
  3979. }
  3980. if (root > max) {
  3981. root = max;
  3982. }
  3983. if (max === 0) {
  3984. /* no symbols to code at all */
  3985. //table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */
  3986. //table.bits[opts.table_index] = 1; //here.bits = (var char)1;
  3987. //table.val[opts.table_index++] = 0; //here.val = (var short)0;
  3988. table[table_index++] = 1 << 24 | 64 << 16 | 0;
  3989. //table.op[opts.table_index] = 64;
  3990. //table.bits[opts.table_index] = 1;
  3991. //table.val[opts.table_index++] = 0;
  3992. table[table_index++] = 1 << 24 | 64 << 16 | 0;
  3993. opts.bits = 1;
  3994. return 0; /* no symbols, but wait for decoding to report error */
  3995. }
  3996. for (min = 1; min < max; min++) {
  3997. if (count[min] !== 0) {
  3998. break;
  3999. }
  4000. }
  4001. if (root < min) {
  4002. root = min;
  4003. }
  4004. /* check for an over-subscribed or incomplete set of lengths */
  4005. left = 1;
  4006. for (len = 1; len <= MAXBITS; len++) {
  4007. left <<= 1;
  4008. left -= count[len];
  4009. if (left < 0) {
  4010. return -1;
  4011. } /* over-subscribed */
  4012. }
  4013. if (left > 0 && (type === CODES$1 || max !== 1)) {
  4014. return -1; /* incomplete set */
  4015. }
  4016. /* generate offsets into symbol table for each length for sorting */
  4017. offs[1] = 0;
  4018. for (len = 1; len < MAXBITS; len++) {
  4019. offs[len + 1] = offs[len] + count[len];
  4020. }
  4021. /* sort symbols by length, by symbol order within each length */
  4022. for (sym = 0; sym < codes; sym++) {
  4023. if (lens[lens_index + sym] !== 0) {
  4024. work[offs[lens[lens_index + sym]]++] = sym;
  4025. }
  4026. }
  4027. /*
  4028. Create and fill in decoding tables. In this loop, the table being
  4029. filled is at next and has curr index bits. The code being used is huff
  4030. with length len. That code is converted to an index by dropping drop
  4031. bits off of the bottom. For codes where len is less than drop + curr,
  4032. those top drop + curr - len bits are incremented through all values to
  4033. fill the table with replicated entries.
  4034. root is the number of index bits for the root table. When len exceeds
  4035. root, sub-tables are created pointed to by the root entry with an index
  4036. of the low root bits of huff. This is saved in low to check for when a
  4037. new sub-table should be started. drop is zero when the root table is
  4038. being filled, and drop is root when sub-tables are being filled.
  4039. When a new sub-table is needed, it is necessary to look ahead in the
  4040. code lengths to determine what size sub-table is needed. The length
  4041. counts are used for this, and so count[] is decremented as codes are
  4042. entered in the tables.
  4043. used keeps track of how many table entries have been allocated from the
  4044. provided *table space. It is checked for LENS and DIST tables against
  4045. the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
  4046. the initial root table size constants. See the comments in inftrees.h
  4047. for more information.
  4048. sym increments through all symbols, and the loop terminates when
  4049. all codes of length max, i.e. all codes, have been processed. This
  4050. routine permits incomplete codes, so another loop after this one fills
  4051. in the rest of the decoding tables with invalid code markers.
  4052. */
  4053. /* set up for code type */
  4054. // poor man optimization - use if-else instead of switch,
  4055. // to avoid deopts in old v8
  4056. if (type === CODES$1) {
  4057. base = extra = work; /* dummy value--not used */
  4058. match = 20;
  4059. } else if (type === LENS$1) {
  4060. base = lbase;
  4061. extra = lext;
  4062. match = 257;
  4063. } else {
  4064. /* DISTS */
  4065. base = dbase;
  4066. extra = dext;
  4067. match = 0;
  4068. }
  4069. /* initialize opts for loop */
  4070. huff = 0; /* starting code */
  4071. sym = 0; /* starting code symbol */
  4072. len = min; /* starting code length */
  4073. next = table_index; /* current table to fill in */
  4074. curr = root; /* current table index bits */
  4075. drop = 0; /* current bits to drop from code for index */
  4076. low = -1; /* trigger new sub-table when len > root */
  4077. used = 1 << root; /* use root table entries */
  4078. mask = used - 1; /* mask for comparing low */
  4079. /* check available table space */
  4080. if (type === LENS$1 && used > ENOUGH_LENS$1 || type === DISTS$1 && used > ENOUGH_DISTS$1) {
  4081. return 1;
  4082. }
  4083. /* process all codes and make table entries */
  4084. for (;;) {
  4085. /* create table entry */
  4086. here_bits = len - drop;
  4087. if (work[sym] + 1 < match) {
  4088. here_op = 0;
  4089. here_val = work[sym];
  4090. } else if (work[sym] >= match) {
  4091. here_op = extra[work[sym] - match];
  4092. here_val = base[work[sym] - match];
  4093. } else {
  4094. here_op = 32 + 64; /* end of block */
  4095. here_val = 0;
  4096. }
  4097. /* replicate for those indices with low len bits equal to huff */
  4098. incr = 1 << len - drop;
  4099. fill = 1 << curr;
  4100. min = fill; /* save offset to next table */
  4101. do {
  4102. fill -= incr;
  4103. table[next + (huff >> drop) + fill] = here_bits << 24 | here_op << 16 | here_val | 0;
  4104. } while (fill !== 0);
  4105. /* backwards increment the len-bit code huff */
  4106. incr = 1 << len - 1;
  4107. while (huff & incr) {
  4108. incr >>= 1;
  4109. }
  4110. if (incr !== 0) {
  4111. huff &= incr - 1;
  4112. huff += incr;
  4113. } else {
  4114. huff = 0;
  4115. }
  4116. /* go to next symbol, update count, len */
  4117. sym++;
  4118. if (--count[len] === 0) {
  4119. if (len === max) {
  4120. break;
  4121. }
  4122. len = lens[lens_index + work[sym]];
  4123. }
  4124. /* create new sub-table if needed */
  4125. if (len > root && (huff & mask) !== low) {
  4126. /* if first time, transition to sub-tables */
  4127. if (drop === 0) {
  4128. drop = root;
  4129. }
  4130. /* increment past last table */
  4131. next += min; /* here min is 1 << curr */
  4132. /* determine length of next table */
  4133. curr = len - drop;
  4134. left = 1 << curr;
  4135. while (curr + drop < max) {
  4136. left -= count[curr + drop];
  4137. if (left <= 0) {
  4138. break;
  4139. }
  4140. curr++;
  4141. left <<= 1;
  4142. }
  4143. /* check for enough space */
  4144. used += 1 << curr;
  4145. if (type === LENS$1 && used > ENOUGH_LENS$1 || type === DISTS$1 && used > ENOUGH_DISTS$1) {
  4146. return 1;
  4147. }
  4148. /* point entry in root table to sub-table */
  4149. low = huff & mask;
  4150. /*table.op[low] = curr;
  4151. table.bits[low] = root;
  4152. table.val[low] = next - opts.table_index;*/
  4153. table[low] = root << 24 | curr << 16 | next - table_index | 0;
  4154. }
  4155. }
  4156. /* fill in remaining table entry if code is incomplete (guaranteed to have
  4157. at most one remaining entry, since if the code is incomplete, the
  4158. maximum code length that was allowed to get this far is one bit) */
  4159. if (huff !== 0) {
  4160. //table.op[next + huff] = 64; /* invalid code marker */
  4161. //table.bits[next + huff] = len - drop;
  4162. //table.val[next + huff] = 0;
  4163. table[next + huff] = len - drop << 24 | 64 << 16 | 0;
  4164. }
  4165. /* set return parameters */
  4166. //opts.table_index += used;
  4167. opts.bits = root;
  4168. return 0;
  4169. };
  4170. var inftrees = inflate_table;
  4171. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  4172. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  4173. //
  4174. // This software is provided 'as-is', without any express or implied
  4175. // warranty. In no event will the authors be held liable for any damages
  4176. // arising from the use of this software.
  4177. //
  4178. // Permission is granted to anyone to use this software for any purpose,
  4179. // including commercial applications, and to alter it and redistribute it
  4180. // freely, subject to the following restrictions:
  4181. //
  4182. // 1. The origin of this software must not be misrepresented; you must not
  4183. // claim that you wrote the original software. If you use this software
  4184. // in a product, an acknowledgment in the product documentation would be
  4185. // appreciated but is not required.
  4186. // 2. Altered source versions must be plainly marked as such, and must not be
  4187. // misrepresented as being the original software.
  4188. // 3. This notice may not be removed or altered from any source distribution.
  4189. var CODES = 0;
  4190. var LENS = 1;
  4191. var DISTS = 2;
  4192. /* Public constants ==========================================================*/
  4193. /* ===========================================================================*/
  4194. var Z_FINISH$1 = constants$2.Z_FINISH,
  4195. Z_BLOCK = constants$2.Z_BLOCK,
  4196. Z_TREES = constants$2.Z_TREES,
  4197. Z_OK$1 = constants$2.Z_OK,
  4198. Z_STREAM_END$1 = constants$2.Z_STREAM_END,
  4199. Z_NEED_DICT$1 = constants$2.Z_NEED_DICT,
  4200. Z_STREAM_ERROR$1 = constants$2.Z_STREAM_ERROR,
  4201. Z_DATA_ERROR$1 = constants$2.Z_DATA_ERROR,
  4202. Z_MEM_ERROR$1 = constants$2.Z_MEM_ERROR,
  4203. Z_BUF_ERROR = constants$2.Z_BUF_ERROR,
  4204. Z_DEFLATED = constants$2.Z_DEFLATED;
  4205. /* STATES ====================================================================*/
  4206. /* ===========================================================================*/
  4207. var HEAD = 16180; /* i: waiting for magic header */
  4208. var FLAGS = 16181; /* i: waiting for method and flags (gzip) */
  4209. var TIME = 16182; /* i: waiting for modification time (gzip) */
  4210. var OS = 16183; /* i: waiting for extra flags and operating system (gzip) */
  4211. var EXLEN = 16184; /* i: waiting for extra length (gzip) */
  4212. var EXTRA = 16185; /* i: waiting for extra bytes (gzip) */
  4213. var NAME = 16186; /* i: waiting for end of file name (gzip) */
  4214. var COMMENT = 16187; /* i: waiting for end of comment (gzip) */
  4215. var HCRC = 16188; /* i: waiting for header crc (gzip) */
  4216. var DICTID = 16189; /* i: waiting for dictionary check value */
  4217. var DICT = 16190; /* waiting for inflateSetDictionary() call */
  4218. var TYPE = 16191; /* i: waiting for type bits, including last-flag bit */
  4219. var TYPEDO = 16192; /* i: same, but skip check to exit inflate on new block */
  4220. var STORED = 16193; /* i: waiting for stored size (length and complement) */
  4221. var COPY_ = 16194; /* i/o: same as COPY below, but only first time in */
  4222. var COPY = 16195; /* i/o: waiting for input or output to copy stored block */
  4223. var TABLE = 16196; /* i: waiting for dynamic block table lengths */
  4224. var LENLENS = 16197; /* i: waiting for code length code lengths */
  4225. var CODELENS = 16198; /* i: waiting for length/lit and distance code lengths */
  4226. var LEN_ = 16199; /* i: same as LEN below, but only first time in */
  4227. var LEN = 16200; /* i: waiting for length/lit/eob code */
  4228. var LENEXT = 16201; /* i: waiting for length extra bits */
  4229. var DIST = 16202; /* i: waiting for distance code */
  4230. var DISTEXT = 16203; /* i: waiting for distance extra bits */
  4231. var MATCH = 16204; /* o: waiting for output space to copy string */
  4232. var LIT = 16205; /* o: waiting for output space to write literal */
  4233. var CHECK = 16206; /* i: waiting for 32-bit check value */
  4234. var LENGTH = 16207; /* i: waiting for 32-bit length (gzip) */
  4235. var DONE = 16208; /* finished check, done -- remain here until reset */
  4236. var BAD = 16209; /* got a data error -- remain here until reset */
  4237. var MEM = 16210; /* got an inflate() memory error -- remain here until reset */
  4238. var SYNC = 16211; /* looking for synchronization bytes to restart inflate() */
  4239. /* ===========================================================================*/
  4240. var ENOUGH_LENS = 852;
  4241. var ENOUGH_DISTS = 592;
  4242. //const ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
  4243. var MAX_WBITS = 15;
  4244. /* 32K LZ77 window */
  4245. var DEF_WBITS = MAX_WBITS;
  4246. var zswap32 = function zswap32(q) {
  4247. return (q >>> 24 & 0xff) + (q >>> 8 & 0xff00) + ((q & 0xff00) << 8) + ((q & 0xff) << 24);
  4248. };
  4249. function InflateState() {
  4250. this.strm = null; /* pointer back to this zlib stream */
  4251. this.mode = 0; /* current inflate mode */
  4252. this.last = false; /* true if processing last block */
  4253. this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip,
  4254. bit 2 true to validate check value */
  4255. this.havedict = false; /* true if dictionary provided */
  4256. this.flags = 0; /* gzip header method and flags (0 if zlib), or
  4257. -1 if raw or no header yet */
  4258. this.dmax = 0; /* zlib header max distance (INFLATE_STRICT) */
  4259. this.check = 0; /* protected copy of check value */
  4260. this.total = 0; /* protected copy of output count */
  4261. // TODO: may be {}
  4262. this.head = null; /* where to save gzip header information */
  4263. /* sliding window */
  4264. this.wbits = 0; /* log base 2 of requested window size */
  4265. this.wsize = 0; /* window size or zero if not using window */
  4266. this.whave = 0; /* valid bytes in the window */
  4267. this.wnext = 0; /* window write index */
  4268. this.window = null; /* allocated sliding window, if needed */
  4269. /* bit accumulator */
  4270. this.hold = 0; /* input bit accumulator */
  4271. this.bits = 0; /* number of bits in "in" */
  4272. /* for string and stored block copying */
  4273. this.length = 0; /* literal or length of data to copy */
  4274. this.offset = 0; /* distance back to copy string from */
  4275. /* for table and code decoding */
  4276. this.extra = 0; /* extra bits needed */
  4277. /* fixed and dynamic code tables */
  4278. this.lencode = null; /* starting table for length/literal codes */
  4279. this.distcode = null; /* starting table for distance codes */
  4280. this.lenbits = 0; /* index bits for lencode */
  4281. this.distbits = 0; /* index bits for distcode */
  4282. /* dynamic table building */
  4283. this.ncode = 0; /* number of code length code lengths */
  4284. this.nlen = 0; /* number of length code lengths */
  4285. this.ndist = 0; /* number of distance code lengths */
  4286. this.have = 0; /* number of code lengths in lens[] */
  4287. this.next = null; /* next available space in codes[] */
  4288. this.lens = new Uint16Array(320); /* temporary storage for code lengths */
  4289. this.work = new Uint16Array(288); /* work area for code table building */
  4290. /*
  4291. because we don't have pointers in js, we use lencode and distcode directly
  4292. as buffers so we don't need codes
  4293. */
  4294. //this.codes = new Int32Array(ENOUGH); /* space for code tables */
  4295. this.lendyn = null; /* dynamic table for length/literal codes (JS specific) */
  4296. this.distdyn = null; /* dynamic table for distance codes (JS specific) */
  4297. this.sane = 0; /* if false, allow invalid distance too far */
  4298. this.back = 0; /* bits back of last unprocessed length/lit */
  4299. this.was = 0; /* initial length of match */
  4300. }
  4301. var inflateStateCheck = function inflateStateCheck(strm) {
  4302. if (!strm) {
  4303. return 1;
  4304. }
  4305. var state = strm.state;
  4306. if (!state || state.strm !== strm || state.mode < HEAD || state.mode > SYNC) {
  4307. return 1;
  4308. }
  4309. return 0;
  4310. };
  4311. var inflateResetKeep = function inflateResetKeep(strm) {
  4312. if (inflateStateCheck(strm)) {
  4313. return Z_STREAM_ERROR$1;
  4314. }
  4315. var state = strm.state;
  4316. strm.total_in = strm.total_out = state.total = 0;
  4317. strm.msg = ''; /*Z_NULL*/
  4318. if (state.wrap) {
  4319. /* to support ill-conceived Java test suite */
  4320. strm.adler = state.wrap & 1;
  4321. }
  4322. state.mode = HEAD;
  4323. state.last = 0;
  4324. state.havedict = 0;
  4325. state.flags = -1;
  4326. state.dmax = 32768;
  4327. state.head = null /*Z_NULL*/;
  4328. state.hold = 0;
  4329. state.bits = 0;
  4330. //state.lencode = state.distcode = state.next = state.codes;
  4331. state.lencode = state.lendyn = new Int32Array(ENOUGH_LENS);
  4332. state.distcode = state.distdyn = new Int32Array(ENOUGH_DISTS);
  4333. state.sane = 1;
  4334. state.back = -1;
  4335. //Tracev((stderr, "inflate: reset\n"));
  4336. return Z_OK$1;
  4337. };
  4338. var inflateReset = function inflateReset(strm) {
  4339. if (inflateStateCheck(strm)) {
  4340. return Z_STREAM_ERROR$1;
  4341. }
  4342. var state = strm.state;
  4343. state.wsize = 0;
  4344. state.whave = 0;
  4345. state.wnext = 0;
  4346. return inflateResetKeep(strm);
  4347. };
  4348. var inflateReset2 = function inflateReset2(strm, windowBits) {
  4349. var wrap;
  4350. /* get the state */
  4351. if (inflateStateCheck(strm)) {
  4352. return Z_STREAM_ERROR$1;
  4353. }
  4354. var state = strm.state;
  4355. /* extract wrap request from windowBits parameter */
  4356. if (windowBits < 0) {
  4357. wrap = 0;
  4358. windowBits = -windowBits;
  4359. } else {
  4360. wrap = (windowBits >> 4) + 5;
  4361. if (windowBits < 48) {
  4362. windowBits &= 15;
  4363. }
  4364. }
  4365. /* set number of window bits, free window if different */
  4366. if (windowBits && (windowBits < 8 || windowBits > 15)) {
  4367. return Z_STREAM_ERROR$1;
  4368. }
  4369. if (state.window !== null && state.wbits !== windowBits) {
  4370. state.window = null;
  4371. }
  4372. /* update state and reset the rest of it */
  4373. state.wrap = wrap;
  4374. state.wbits = windowBits;
  4375. return inflateReset(strm);
  4376. };
  4377. var inflateInit2 = function inflateInit2(strm, windowBits) {
  4378. if (!strm) {
  4379. return Z_STREAM_ERROR$1;
  4380. }
  4381. //strm.msg = Z_NULL; /* in case we return an error */
  4382. var state = new InflateState();
  4383. //if (state === Z_NULL) return Z_MEM_ERROR;
  4384. //Tracev((stderr, "inflate: allocated\n"));
  4385. strm.state = state;
  4386. state.strm = strm;
  4387. state.window = null /*Z_NULL*/;
  4388. state.mode = HEAD; /* to pass state test in inflateReset2() */
  4389. var ret = inflateReset2(strm, windowBits);
  4390. if (ret !== Z_OK$1) {
  4391. strm.state = null /*Z_NULL*/;
  4392. }
  4393. return ret;
  4394. };
  4395. var inflateInit = function inflateInit(strm) {
  4396. return inflateInit2(strm, DEF_WBITS);
  4397. };
  4398. /*
  4399. Return state with length and distance decoding tables and index sizes set to
  4400. fixed code decoding. Normally this returns fixed tables from inffixed.h.
  4401. If BUILDFIXED is defined, then instead this routine builds the tables the
  4402. first time it's called, and returns those tables the first time and
  4403. thereafter. This reduces the size of the code by about 2K bytes, in
  4404. exchange for a little execution time. However, BUILDFIXED should not be
  4405. used for threaded applications, since the rewriting of the tables and virgin
  4406. may not be thread-safe.
  4407. */
  4408. var virgin = true;
  4409. var lenfix, distfix; // We have no pointers in JS, so keep tables separate
  4410. var fixedtables = function fixedtables(state) {
  4411. /* build fixed huffman tables if first call (may not be thread safe) */
  4412. if (virgin) {
  4413. lenfix = new Int32Array(512);
  4414. distfix = new Int32Array(32);
  4415. /* literal/length table */
  4416. var sym = 0;
  4417. while (sym < 144) {
  4418. state.lens[sym++] = 8;
  4419. }
  4420. while (sym < 256) {
  4421. state.lens[sym++] = 9;
  4422. }
  4423. while (sym < 280) {
  4424. state.lens[sym++] = 7;
  4425. }
  4426. while (sym < 288) {
  4427. state.lens[sym++] = 8;
  4428. }
  4429. inftrees(LENS, state.lens, 0, 288, lenfix, 0, state.work, {
  4430. bits: 9
  4431. });
  4432. /* distance table */
  4433. sym = 0;
  4434. while (sym < 32) {
  4435. state.lens[sym++] = 5;
  4436. }
  4437. inftrees(DISTS, state.lens, 0, 32, distfix, 0, state.work, {
  4438. bits: 5
  4439. });
  4440. /* do this just once */
  4441. virgin = false;
  4442. }
  4443. state.lencode = lenfix;
  4444. state.lenbits = 9;
  4445. state.distcode = distfix;
  4446. state.distbits = 5;
  4447. };
  4448. /*
  4449. Update the window with the last wsize (normally 32K) bytes written before
  4450. returning. If window does not exist yet, create it. This is only called
  4451. when a window is already in use, or when output has been written during this
  4452. inflate call, but the end of the deflate stream has not been reached yet.
  4453. It is also called to create a window for dictionary data when a dictionary
  4454. is loaded.
  4455. Providing output buffers larger than 32K to inflate() should provide a speed
  4456. advantage, since only the last 32K of output is copied to the sliding window
  4457. upon return from inflate(), and since all distances after the first 32K of
  4458. output will fall in the output data, making match copies simpler and faster.
  4459. The advantage may be dependent on the size of the processor's data caches.
  4460. */
  4461. var updatewindow = function updatewindow(strm, src, end, copy) {
  4462. var dist;
  4463. var state = strm.state;
  4464. /* if it hasn't been done already, allocate space for the window */
  4465. if (state.window === null) {
  4466. state.wsize = 1 << state.wbits;
  4467. state.wnext = 0;
  4468. state.whave = 0;
  4469. state.window = new Uint8Array(state.wsize);
  4470. }
  4471. /* copy state->wsize or less output bytes into the circular window */
  4472. if (copy >= state.wsize) {
  4473. state.window.set(src.subarray(end - state.wsize, end), 0);
  4474. state.wnext = 0;
  4475. state.whave = state.wsize;
  4476. } else {
  4477. dist = state.wsize - state.wnext;
  4478. if (dist > copy) {
  4479. dist = copy;
  4480. }
  4481. //zmemcpy(state->window + state->wnext, end - copy, dist);
  4482. state.window.set(src.subarray(end - copy, end - copy + dist), state.wnext);
  4483. copy -= dist;
  4484. if (copy) {
  4485. //zmemcpy(state->window, end - copy, copy);
  4486. state.window.set(src.subarray(end - copy, end), 0);
  4487. state.wnext = copy;
  4488. state.whave = state.wsize;
  4489. } else {
  4490. state.wnext += dist;
  4491. if (state.wnext === state.wsize) {
  4492. state.wnext = 0;
  4493. }
  4494. if (state.whave < state.wsize) {
  4495. state.whave += dist;
  4496. }
  4497. }
  4498. }
  4499. return 0;
  4500. };
  4501. var inflate$2 = function inflate(strm, flush) {
  4502. var state;
  4503. var input, output; // input/output buffers
  4504. var next; /* next input INDEX */
  4505. var put; /* next output INDEX */
  4506. var have, left; /* available input and output */
  4507. var hold; /* bit buffer */
  4508. var bits; /* bits in bit buffer */
  4509. var _in, _out; /* save starting available input and output */
  4510. var copy; /* number of stored or match bytes to copy */
  4511. var from; /* where to copy match bytes from */
  4512. var from_source;
  4513. var here = 0; /* current decoding table entry */
  4514. var here_bits, here_op, here_val; // paked "here" denormalized (JS specific)
  4515. //let last; /* parent table entry */
  4516. var last_bits, last_op, last_val; // paked "last" denormalized (JS specific)
  4517. var len; /* length to copy for repeats, bits to drop */
  4518. var ret; /* return code */
  4519. var hbuf = new Uint8Array(4); /* buffer for gzip header crc calculation */
  4520. var opts;
  4521. var n; // temporary variable for NEED_BITS
  4522. var order = /* permutation of code lengths */
  4523. new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
  4524. if (inflateStateCheck(strm) || !strm.output || !strm.input && strm.avail_in !== 0) {
  4525. return Z_STREAM_ERROR$1;
  4526. }
  4527. state = strm.state;
  4528. if (state.mode === TYPE) {
  4529. state.mode = TYPEDO;
  4530. } /* skip check */
  4531. //--- LOAD() ---
  4532. put = strm.next_out;
  4533. output = strm.output;
  4534. left = strm.avail_out;
  4535. next = strm.next_in;
  4536. input = strm.input;
  4537. have = strm.avail_in;
  4538. hold = state.hold;
  4539. bits = state.bits;
  4540. //---
  4541. _in = have;
  4542. _out = left;
  4543. ret = Z_OK$1;
  4544. inf_leave:
  4545. // goto emulation
  4546. for (;;) {
  4547. switch (state.mode) {
  4548. case HEAD:
  4549. if (state.wrap === 0) {
  4550. state.mode = TYPEDO;
  4551. break;
  4552. }
  4553. //=== NEEDBITS(16);
  4554. while (bits < 16) {
  4555. if (have === 0) {
  4556. break inf_leave;
  4557. }
  4558. have--;
  4559. hold += input[next++] << bits;
  4560. bits += 8;
  4561. }
  4562. //===//
  4563. if (state.wrap & 2 && hold === 0x8b1f) {
  4564. /* gzip header */
  4565. if (state.wbits === 0) {
  4566. state.wbits = 15;
  4567. }
  4568. state.check = 0 /*crc32(0L, Z_NULL, 0)*/;
  4569. //=== CRC2(state.check, hold);
  4570. hbuf[0] = hold & 0xff;
  4571. hbuf[1] = hold >>> 8 & 0xff;
  4572. state.check = crc32_1(state.check, hbuf, 2, 0);
  4573. //===//
  4574. //=== INITBITS();
  4575. hold = 0;
  4576. bits = 0;
  4577. //===//
  4578. state.mode = FLAGS;
  4579. break;
  4580. }
  4581. if (state.head) {
  4582. state.head.done = false;
  4583. }
  4584. if (!(state.wrap & 1) || /* check if zlib header allowed */
  4585. (((hold & 0xff /*BITS(8)*/) << 8) + (hold >> 8)) % 31) {
  4586. strm.msg = 'incorrect header check';
  4587. state.mode = BAD;
  4588. break;
  4589. }
  4590. if ((hold & 0x0f /*BITS(4)*/) !== Z_DEFLATED) {
  4591. strm.msg = 'unknown compression method';
  4592. state.mode = BAD;
  4593. break;
  4594. }
  4595. //--- DROPBITS(4) ---//
  4596. hold >>>= 4;
  4597. bits -= 4;
  4598. //---//
  4599. len = (hold & 0x0f /*BITS(4)*/) + 8;
  4600. if (state.wbits === 0) {
  4601. state.wbits = len;
  4602. }
  4603. if (len > 15 || len > state.wbits) {
  4604. strm.msg = 'invalid window size';
  4605. state.mode = BAD;
  4606. break;
  4607. }
  4608. // !!! pako patch. Force use `options.windowBits` if passed.
  4609. // Required to always use max window size by default.
  4610. state.dmax = 1 << state.wbits;
  4611. //state.dmax = 1 << len;
  4612. state.flags = 0; /* indicate zlib header */
  4613. //Tracev((stderr, "inflate: zlib header ok\n"));
  4614. strm.adler = state.check = 1 /*adler32(0L, Z_NULL, 0)*/;
  4615. state.mode = hold & 0x200 ? DICTID : TYPE;
  4616. //=== INITBITS();
  4617. hold = 0;
  4618. bits = 0;
  4619. //===//
  4620. break;
  4621. case FLAGS:
  4622. //=== NEEDBITS(16); */
  4623. while (bits < 16) {
  4624. if (have === 0) {
  4625. break inf_leave;
  4626. }
  4627. have--;
  4628. hold += input[next++] << bits;
  4629. bits += 8;
  4630. }
  4631. //===//
  4632. state.flags = hold;
  4633. if ((state.flags & 0xff) !== Z_DEFLATED) {
  4634. strm.msg = 'unknown compression method';
  4635. state.mode = BAD;
  4636. break;
  4637. }
  4638. if (state.flags & 0xe000) {
  4639. strm.msg = 'unknown header flags set';
  4640. state.mode = BAD;
  4641. break;
  4642. }
  4643. if (state.head) {
  4644. state.head.text = hold >> 8 & 1;
  4645. }
  4646. if (state.flags & 0x0200 && state.wrap & 4) {
  4647. //=== CRC2(state.check, hold);
  4648. hbuf[0] = hold & 0xff;
  4649. hbuf[1] = hold >>> 8 & 0xff;
  4650. state.check = crc32_1(state.check, hbuf, 2, 0);
  4651. //===//
  4652. }
  4653. //=== INITBITS();
  4654. hold = 0;
  4655. bits = 0;
  4656. //===//
  4657. state.mode = TIME;
  4658. /* falls through */
  4659. case TIME:
  4660. //=== NEEDBITS(32); */
  4661. while (bits < 32) {
  4662. if (have === 0) {
  4663. break inf_leave;
  4664. }
  4665. have--;
  4666. hold += input[next++] << bits;
  4667. bits += 8;
  4668. }
  4669. //===//
  4670. if (state.head) {
  4671. state.head.time = hold;
  4672. }
  4673. if (state.flags & 0x0200 && state.wrap & 4) {
  4674. //=== CRC4(state.check, hold)
  4675. hbuf[0] = hold & 0xff;
  4676. hbuf[1] = hold >>> 8 & 0xff;
  4677. hbuf[2] = hold >>> 16 & 0xff;
  4678. hbuf[3] = hold >>> 24 & 0xff;
  4679. state.check = crc32_1(state.check, hbuf, 4, 0);
  4680. //===
  4681. }
  4682. //=== INITBITS();
  4683. hold = 0;
  4684. bits = 0;
  4685. //===//
  4686. state.mode = OS;
  4687. /* falls through */
  4688. case OS:
  4689. //=== NEEDBITS(16); */
  4690. while (bits < 16) {
  4691. if (have === 0) {
  4692. break inf_leave;
  4693. }
  4694. have--;
  4695. hold += input[next++] << bits;
  4696. bits += 8;
  4697. }
  4698. //===//
  4699. if (state.head) {
  4700. state.head.xflags = hold & 0xff;
  4701. state.head.os = hold >> 8;
  4702. }
  4703. if (state.flags & 0x0200 && state.wrap & 4) {
  4704. //=== CRC2(state.check, hold);
  4705. hbuf[0] = hold & 0xff;
  4706. hbuf[1] = hold >>> 8 & 0xff;
  4707. state.check = crc32_1(state.check, hbuf, 2, 0);
  4708. //===//
  4709. }
  4710. //=== INITBITS();
  4711. hold = 0;
  4712. bits = 0;
  4713. //===//
  4714. state.mode = EXLEN;
  4715. /* falls through */
  4716. case EXLEN:
  4717. if (state.flags & 0x0400) {
  4718. //=== NEEDBITS(16); */
  4719. while (bits < 16) {
  4720. if (have === 0) {
  4721. break inf_leave;
  4722. }
  4723. have--;
  4724. hold += input[next++] << bits;
  4725. bits += 8;
  4726. }
  4727. //===//
  4728. state.length = hold;
  4729. if (state.head) {
  4730. state.head.extra_len = hold;
  4731. }
  4732. if (state.flags & 0x0200 && state.wrap & 4) {
  4733. //=== CRC2(state.check, hold);
  4734. hbuf[0] = hold & 0xff;
  4735. hbuf[1] = hold >>> 8 & 0xff;
  4736. state.check = crc32_1(state.check, hbuf, 2, 0);
  4737. //===//
  4738. }
  4739. //=== INITBITS();
  4740. hold = 0;
  4741. bits = 0;
  4742. //===//
  4743. } else if (state.head) {
  4744. state.head.extra = null /*Z_NULL*/;
  4745. }
  4746. state.mode = EXTRA;
  4747. /* falls through */
  4748. case EXTRA:
  4749. if (state.flags & 0x0400) {
  4750. copy = state.length;
  4751. if (copy > have) {
  4752. copy = have;
  4753. }
  4754. if (copy) {
  4755. if (state.head) {
  4756. len = state.head.extra_len - state.length;
  4757. if (!state.head.extra) {
  4758. // Use untyped array for more convenient processing later
  4759. state.head.extra = new Uint8Array(state.head.extra_len);
  4760. }
  4761. state.head.extra.set(input.subarray(next,
  4762. // extra field is limited to 65536 bytes
  4763. // - no need for additional size check
  4764. next + copy), /*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
  4765. len);
  4766. //zmemcpy(state.head.extra + len, next,
  4767. // len + copy > state.head.extra_max ?
  4768. // state.head.extra_max - len : copy);
  4769. }
  4770. if (state.flags & 0x0200 && state.wrap & 4) {
  4771. state.check = crc32_1(state.check, input, copy, next);
  4772. }
  4773. have -= copy;
  4774. next += copy;
  4775. state.length -= copy;
  4776. }
  4777. if (state.length) {
  4778. break inf_leave;
  4779. }
  4780. }
  4781. state.length = 0;
  4782. state.mode = NAME;
  4783. /* falls through */
  4784. case NAME:
  4785. if (state.flags & 0x0800) {
  4786. if (have === 0) {
  4787. break inf_leave;
  4788. }
  4789. copy = 0;
  4790. do {
  4791. // TODO: 2 or 1 bytes?
  4792. len = input[next + copy++];
  4793. /* use constant limit because in js we should not preallocate memory */
  4794. if (state.head && len && state.length < 65536 /*state.head.name_max*/) {
  4795. state.head.name += String.fromCharCode(len);
  4796. }
  4797. } while (len && copy < have);
  4798. if (state.flags & 0x0200 && state.wrap & 4) {
  4799. state.check = crc32_1(state.check, input, copy, next);
  4800. }
  4801. have -= copy;
  4802. next += copy;
  4803. if (len) {
  4804. break inf_leave;
  4805. }
  4806. } else if (state.head) {
  4807. state.head.name = null;
  4808. }
  4809. state.length = 0;
  4810. state.mode = COMMENT;
  4811. /* falls through */
  4812. case COMMENT:
  4813. if (state.flags & 0x1000) {
  4814. if (have === 0) {
  4815. break inf_leave;
  4816. }
  4817. copy = 0;
  4818. do {
  4819. len = input[next + copy++];
  4820. /* use constant limit because in js we should not preallocate memory */
  4821. if (state.head && len && state.length < 65536 /*state.head.comm_max*/) {
  4822. state.head.comment += String.fromCharCode(len);
  4823. }
  4824. } while (len && copy < have);
  4825. if (state.flags & 0x0200 && state.wrap & 4) {
  4826. state.check = crc32_1(state.check, input, copy, next);
  4827. }
  4828. have -= copy;
  4829. next += copy;
  4830. if (len) {
  4831. break inf_leave;
  4832. }
  4833. } else if (state.head) {
  4834. state.head.comment = null;
  4835. }
  4836. state.mode = HCRC;
  4837. /* falls through */
  4838. case HCRC:
  4839. if (state.flags & 0x0200) {
  4840. //=== NEEDBITS(16); */
  4841. while (bits < 16) {
  4842. if (have === 0) {
  4843. break inf_leave;
  4844. }
  4845. have--;
  4846. hold += input[next++] << bits;
  4847. bits += 8;
  4848. }
  4849. //===//
  4850. if (state.wrap & 4 && hold !== (state.check & 0xffff)) {
  4851. strm.msg = 'header crc mismatch';
  4852. state.mode = BAD;
  4853. break;
  4854. }
  4855. //=== INITBITS();
  4856. hold = 0;
  4857. bits = 0;
  4858. //===//
  4859. }
  4860. if (state.head) {
  4861. state.head.hcrc = state.flags >> 9 & 1;
  4862. state.head.done = true;
  4863. }
  4864. strm.adler = state.check = 0;
  4865. state.mode = TYPE;
  4866. break;
  4867. case DICTID:
  4868. //=== NEEDBITS(32); */
  4869. while (bits < 32) {
  4870. if (have === 0) {
  4871. break inf_leave;
  4872. }
  4873. have--;
  4874. hold += input[next++] << bits;
  4875. bits += 8;
  4876. }
  4877. //===//
  4878. strm.adler = state.check = zswap32(hold);
  4879. //=== INITBITS();
  4880. hold = 0;
  4881. bits = 0;
  4882. //===//
  4883. state.mode = DICT;
  4884. /* falls through */
  4885. case DICT:
  4886. if (state.havedict === 0) {
  4887. //--- RESTORE() ---
  4888. strm.next_out = put;
  4889. strm.avail_out = left;
  4890. strm.next_in = next;
  4891. strm.avail_in = have;
  4892. state.hold = hold;
  4893. state.bits = bits;
  4894. //---
  4895. return Z_NEED_DICT$1;
  4896. }
  4897. strm.adler = state.check = 1 /*adler32(0L, Z_NULL, 0)*/;
  4898. state.mode = TYPE;
  4899. /* falls through */
  4900. case TYPE:
  4901. if (flush === Z_BLOCK || flush === Z_TREES) {
  4902. break inf_leave;
  4903. }
  4904. /* falls through */
  4905. case TYPEDO:
  4906. if (state.last) {
  4907. //--- BYTEBITS() ---//
  4908. hold >>>= bits & 7;
  4909. bits -= bits & 7;
  4910. //---//
  4911. state.mode = CHECK;
  4912. break;
  4913. }
  4914. //=== NEEDBITS(3); */
  4915. while (bits < 3) {
  4916. if (have === 0) {
  4917. break inf_leave;
  4918. }
  4919. have--;
  4920. hold += input[next++] << bits;
  4921. bits += 8;
  4922. }
  4923. //===//
  4924. state.last = hold & 0x01 /*BITS(1)*/;
  4925. //--- DROPBITS(1) ---//
  4926. hold >>>= 1;
  4927. bits -= 1;
  4928. //---//
  4929. switch (hold & 0x03 /*BITS(2)*/) {
  4930. case 0:
  4931. /* stored block */
  4932. //Tracev((stderr, "inflate: stored block%s\n",
  4933. // state.last ? " (last)" : ""));
  4934. state.mode = STORED;
  4935. break;
  4936. case 1:
  4937. /* fixed block */
  4938. fixedtables(state);
  4939. //Tracev((stderr, "inflate: fixed codes block%s\n",
  4940. // state.last ? " (last)" : ""));
  4941. state.mode = LEN_; /* decode codes */
  4942. if (flush === Z_TREES) {
  4943. //--- DROPBITS(2) ---//
  4944. hold >>>= 2;
  4945. bits -= 2;
  4946. //---//
  4947. break inf_leave;
  4948. }
  4949. break;
  4950. case 2:
  4951. /* dynamic block */
  4952. //Tracev((stderr, "inflate: dynamic codes block%s\n",
  4953. // state.last ? " (last)" : ""));
  4954. state.mode = TABLE;
  4955. break;
  4956. case 3:
  4957. strm.msg = 'invalid block type';
  4958. state.mode = BAD;
  4959. }
  4960. //--- DROPBITS(2) ---//
  4961. hold >>>= 2;
  4962. bits -= 2;
  4963. //---//
  4964. break;
  4965. case STORED:
  4966. //--- BYTEBITS() ---// /* go to byte boundary */
  4967. hold >>>= bits & 7;
  4968. bits -= bits & 7;
  4969. //---//
  4970. //=== NEEDBITS(32); */
  4971. while (bits < 32) {
  4972. if (have === 0) {
  4973. break inf_leave;
  4974. }
  4975. have--;
  4976. hold += input[next++] << bits;
  4977. bits += 8;
  4978. }
  4979. //===//
  4980. if ((hold & 0xffff) !== (hold >>> 16 ^ 0xffff)) {
  4981. strm.msg = 'invalid stored block lengths';
  4982. state.mode = BAD;
  4983. break;
  4984. }
  4985. state.length = hold & 0xffff;
  4986. //Tracev((stderr, "inflate: stored length %u\n",
  4987. // state.length));
  4988. //=== INITBITS();
  4989. hold = 0;
  4990. bits = 0;
  4991. //===//
  4992. state.mode = COPY_;
  4993. if (flush === Z_TREES) {
  4994. break inf_leave;
  4995. }
  4996. /* falls through */
  4997. case COPY_:
  4998. state.mode = COPY;
  4999. /* falls through */
  5000. case COPY:
  5001. copy = state.length;
  5002. if (copy) {
  5003. if (copy > have) {
  5004. copy = have;
  5005. }
  5006. if (copy > left) {
  5007. copy = left;
  5008. }
  5009. if (copy === 0) {
  5010. break inf_leave;
  5011. }
  5012. //--- zmemcpy(put, next, copy); ---
  5013. output.set(input.subarray(next, next + copy), put);
  5014. //---//
  5015. have -= copy;
  5016. next += copy;
  5017. left -= copy;
  5018. put += copy;
  5019. state.length -= copy;
  5020. break;
  5021. }
  5022. //Tracev((stderr, "inflate: stored end\n"));
  5023. state.mode = TYPE;
  5024. break;
  5025. case TABLE:
  5026. //=== NEEDBITS(14); */
  5027. while (bits < 14) {
  5028. if (have === 0) {
  5029. break inf_leave;
  5030. }
  5031. have--;
  5032. hold += input[next++] << bits;
  5033. bits += 8;
  5034. }
  5035. //===//
  5036. state.nlen = (hold & 0x1f /*BITS(5)*/) + 257;
  5037. //--- DROPBITS(5) ---//
  5038. hold >>>= 5;
  5039. bits -= 5;
  5040. //---//
  5041. state.ndist = (hold & 0x1f /*BITS(5)*/) + 1;
  5042. //--- DROPBITS(5) ---//
  5043. hold >>>= 5;
  5044. bits -= 5;
  5045. //---//
  5046. state.ncode = (hold & 0x0f /*BITS(4)*/) + 4;
  5047. //--- DROPBITS(4) ---//
  5048. hold >>>= 4;
  5049. bits -= 4;
  5050. //---//
  5051. //#ifndef PKZIP_BUG_WORKAROUND
  5052. if (state.nlen > 286 || state.ndist > 30) {
  5053. strm.msg = 'too many length or distance symbols';
  5054. state.mode = BAD;
  5055. break;
  5056. }
  5057. //#endif
  5058. //Tracev((stderr, "inflate: table sizes ok\n"));
  5059. state.have = 0;
  5060. state.mode = LENLENS;
  5061. /* falls through */
  5062. case LENLENS:
  5063. while (state.have < state.ncode) {
  5064. //=== NEEDBITS(3);
  5065. while (bits < 3) {
  5066. if (have === 0) {
  5067. break inf_leave;
  5068. }
  5069. have--;
  5070. hold += input[next++] << bits;
  5071. bits += 8;
  5072. }
  5073. //===//
  5074. state.lens[order[state.have++]] = hold & 0x07; //BITS(3);
  5075. //--- DROPBITS(3) ---//
  5076. hold >>>= 3;
  5077. bits -= 3;
  5078. //---//
  5079. }
  5080. while (state.have < 19) {
  5081. state.lens[order[state.have++]] = 0;
  5082. }
  5083. // We have separate tables & no pointers. 2 commented lines below not needed.
  5084. //state.next = state.codes;
  5085. //state.lencode = state.next;
  5086. // Switch to use dynamic table
  5087. state.lencode = state.lendyn;
  5088. state.lenbits = 7;
  5089. opts = {
  5090. bits: state.lenbits
  5091. };
  5092. ret = inftrees(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts);
  5093. state.lenbits = opts.bits;
  5094. if (ret) {
  5095. strm.msg = 'invalid code lengths set';
  5096. state.mode = BAD;
  5097. break;
  5098. }
  5099. //Tracev((stderr, "inflate: code lengths ok\n"));
  5100. state.have = 0;
  5101. state.mode = CODELENS;
  5102. /* falls through */
  5103. case CODELENS:
  5104. while (state.have < state.nlen + state.ndist) {
  5105. for (;;) {
  5106. here = state.lencode[hold & (1 << state.lenbits) - 1]; /*BITS(state.lenbits)*/
  5107. here_bits = here >>> 24;
  5108. here_op = here >>> 16 & 0xff;
  5109. here_val = here & 0xffff;
  5110. if (here_bits <= bits) {
  5111. break;
  5112. }
  5113. //--- PULLBYTE() ---//
  5114. if (have === 0) {
  5115. break inf_leave;
  5116. }
  5117. have--;
  5118. hold += input[next++] << bits;
  5119. bits += 8;
  5120. //---//
  5121. }
  5122. if (here_val < 16) {
  5123. //--- DROPBITS(here.bits) ---//
  5124. hold >>>= here_bits;
  5125. bits -= here_bits;
  5126. //---//
  5127. state.lens[state.have++] = here_val;
  5128. } else {
  5129. if (here_val === 16) {
  5130. //=== NEEDBITS(here.bits + 2);
  5131. n = here_bits + 2;
  5132. while (bits < n) {
  5133. if (have === 0) {
  5134. break inf_leave;
  5135. }
  5136. have--;
  5137. hold += input[next++] << bits;
  5138. bits += 8;
  5139. }
  5140. //===//
  5141. //--- DROPBITS(here.bits) ---//
  5142. hold >>>= here_bits;
  5143. bits -= here_bits;
  5144. //---//
  5145. if (state.have === 0) {
  5146. strm.msg = 'invalid bit length repeat';
  5147. state.mode = BAD;
  5148. break;
  5149. }
  5150. len = state.lens[state.have - 1];
  5151. copy = 3 + (hold & 0x03); //BITS(2);
  5152. //--- DROPBITS(2) ---//
  5153. hold >>>= 2;
  5154. bits -= 2;
  5155. //---//
  5156. } else if (here_val === 17) {
  5157. //=== NEEDBITS(here.bits + 3);
  5158. n = here_bits + 3;
  5159. while (bits < n) {
  5160. if (have === 0) {
  5161. break inf_leave;
  5162. }
  5163. have--;
  5164. hold += input[next++] << bits;
  5165. bits += 8;
  5166. }
  5167. //===//
  5168. //--- DROPBITS(here.bits) ---//
  5169. hold >>>= here_bits;
  5170. bits -= here_bits;
  5171. //---//
  5172. len = 0;
  5173. copy = 3 + (hold & 0x07); //BITS(3);
  5174. //--- DROPBITS(3) ---//
  5175. hold >>>= 3;
  5176. bits -= 3;
  5177. //---//
  5178. } else {
  5179. //=== NEEDBITS(here.bits + 7);
  5180. n = here_bits + 7;
  5181. while (bits < n) {
  5182. if (have === 0) {
  5183. break inf_leave;
  5184. }
  5185. have--;
  5186. hold += input[next++] << bits;
  5187. bits += 8;
  5188. }
  5189. //===//
  5190. //--- DROPBITS(here.bits) ---//
  5191. hold >>>= here_bits;
  5192. bits -= here_bits;
  5193. //---//
  5194. len = 0;
  5195. copy = 11 + (hold & 0x7f); //BITS(7);
  5196. //--- DROPBITS(7) ---//
  5197. hold >>>= 7;
  5198. bits -= 7;
  5199. //---//
  5200. }
  5201. if (state.have + copy > state.nlen + state.ndist) {
  5202. strm.msg = 'invalid bit length repeat';
  5203. state.mode = BAD;
  5204. break;
  5205. }
  5206. while (copy--) {
  5207. state.lens[state.have++] = len;
  5208. }
  5209. }
  5210. }
  5211. /* handle error breaks in while */
  5212. if (state.mode === BAD) {
  5213. break;
  5214. }
  5215. /* check for end-of-block code (better have one) */
  5216. if (state.lens[256] === 0) {
  5217. strm.msg = 'invalid code -- missing end-of-block';
  5218. state.mode = BAD;
  5219. break;
  5220. }
  5221. /* build code tables -- note: do not change the lenbits or distbits
  5222. values here (9 and 6) without reading the comments in inftrees.h
  5223. concerning the ENOUGH constants, which depend on those values */
  5224. state.lenbits = 9;
  5225. opts = {
  5226. bits: state.lenbits
  5227. };
  5228. ret = inftrees(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts);
  5229. // We have separate tables & no pointers. 2 commented lines below not needed.
  5230. // state.next_index = opts.table_index;
  5231. state.lenbits = opts.bits;
  5232. // state.lencode = state.next;
  5233. if (ret) {
  5234. strm.msg = 'invalid literal/lengths set';
  5235. state.mode = BAD;
  5236. break;
  5237. }
  5238. state.distbits = 6;
  5239. //state.distcode.copy(state.codes);
  5240. // Switch to use dynamic table
  5241. state.distcode = state.distdyn;
  5242. opts = {
  5243. bits: state.distbits
  5244. };
  5245. ret = inftrees(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);
  5246. // We have separate tables & no pointers. 2 commented lines below not needed.
  5247. // state.next_index = opts.table_index;
  5248. state.distbits = opts.bits;
  5249. // state.distcode = state.next;
  5250. if (ret) {
  5251. strm.msg = 'invalid distances set';
  5252. state.mode = BAD;
  5253. break;
  5254. }
  5255. //Tracev((stderr, 'inflate: codes ok\n'));
  5256. state.mode = LEN_;
  5257. if (flush === Z_TREES) {
  5258. break inf_leave;
  5259. }
  5260. /* falls through */
  5261. case LEN_:
  5262. state.mode = LEN;
  5263. /* falls through */
  5264. case LEN:
  5265. if (have >= 6 && left >= 258) {
  5266. //--- RESTORE() ---
  5267. strm.next_out = put;
  5268. strm.avail_out = left;
  5269. strm.next_in = next;
  5270. strm.avail_in = have;
  5271. state.hold = hold;
  5272. state.bits = bits;
  5273. //---
  5274. inffast(strm, _out);
  5275. //--- LOAD() ---
  5276. put = strm.next_out;
  5277. output = strm.output;
  5278. left = strm.avail_out;
  5279. next = strm.next_in;
  5280. input = strm.input;
  5281. have = strm.avail_in;
  5282. hold = state.hold;
  5283. bits = state.bits;
  5284. //---
  5285. if (state.mode === TYPE) {
  5286. state.back = -1;
  5287. }
  5288. break;
  5289. }
  5290. state.back = 0;
  5291. for (;;) {
  5292. here = state.lencode[hold & (1 << state.lenbits) - 1]; /*BITS(state.lenbits)*/
  5293. here_bits = here >>> 24;
  5294. here_op = here >>> 16 & 0xff;
  5295. here_val = here & 0xffff;
  5296. if (here_bits <= bits) {
  5297. break;
  5298. }
  5299. //--- PULLBYTE() ---//
  5300. if (have === 0) {
  5301. break inf_leave;
  5302. }
  5303. have--;
  5304. hold += input[next++] << bits;
  5305. bits += 8;
  5306. //---//
  5307. }
  5308. if (here_op && (here_op & 0xf0) === 0) {
  5309. last_bits = here_bits;
  5310. last_op = here_op;
  5311. last_val = here_val;
  5312. for (;;) {
  5313. here = state.lencode[last_val + ((hold & (1 << last_bits + last_op) - 1 /*BITS(last.bits + last.op)*/) >> last_bits)];
  5314. here_bits = here >>> 24;
  5315. here_op = here >>> 16 & 0xff;
  5316. here_val = here & 0xffff;
  5317. if (last_bits + here_bits <= bits) {
  5318. break;
  5319. }
  5320. //--- PULLBYTE() ---//
  5321. if (have === 0) {
  5322. break inf_leave;
  5323. }
  5324. have--;
  5325. hold += input[next++] << bits;
  5326. bits += 8;
  5327. //---//
  5328. }
  5329. //--- DROPBITS(last.bits) ---//
  5330. hold >>>= last_bits;
  5331. bits -= last_bits;
  5332. //---//
  5333. state.back += last_bits;
  5334. }
  5335. //--- DROPBITS(here.bits) ---//
  5336. hold >>>= here_bits;
  5337. bits -= here_bits;
  5338. //---//
  5339. state.back += here_bits;
  5340. state.length = here_val;
  5341. if (here_op === 0) {
  5342. //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
  5343. // "inflate: literal '%c'\n" :
  5344. // "inflate: literal 0x%02x\n", here.val));
  5345. state.mode = LIT;
  5346. break;
  5347. }
  5348. if (here_op & 32) {
  5349. //Tracevv((stderr, "inflate: end of block\n"));
  5350. state.back = -1;
  5351. state.mode = TYPE;
  5352. break;
  5353. }
  5354. if (here_op & 64) {
  5355. strm.msg = 'invalid literal/length code';
  5356. state.mode = BAD;
  5357. break;
  5358. }
  5359. state.extra = here_op & 15;
  5360. state.mode = LENEXT;
  5361. /* falls through */
  5362. case LENEXT:
  5363. if (state.extra) {
  5364. //=== NEEDBITS(state.extra);
  5365. n = state.extra;
  5366. while (bits < n) {
  5367. if (have === 0) {
  5368. break inf_leave;
  5369. }
  5370. have--;
  5371. hold += input[next++] << bits;
  5372. bits += 8;
  5373. }
  5374. //===//
  5375. state.length += hold & (1 << state.extra) - 1 /*BITS(state.extra)*/;
  5376. //--- DROPBITS(state.extra) ---//
  5377. hold >>>= state.extra;
  5378. bits -= state.extra;
  5379. //---//
  5380. state.back += state.extra;
  5381. }
  5382. //Tracevv((stderr, "inflate: length %u\n", state.length));
  5383. state.was = state.length;
  5384. state.mode = DIST;
  5385. /* falls through */
  5386. case DIST:
  5387. for (;;) {
  5388. here = state.distcode[hold & (1 << state.distbits) - 1]; /*BITS(state.distbits)*/
  5389. here_bits = here >>> 24;
  5390. here_op = here >>> 16 & 0xff;
  5391. here_val = here & 0xffff;
  5392. if (here_bits <= bits) {
  5393. break;
  5394. }
  5395. //--- PULLBYTE() ---//
  5396. if (have === 0) {
  5397. break inf_leave;
  5398. }
  5399. have--;
  5400. hold += input[next++] << bits;
  5401. bits += 8;
  5402. //---//
  5403. }
  5404. if ((here_op & 0xf0) === 0) {
  5405. last_bits = here_bits;
  5406. last_op = here_op;
  5407. last_val = here_val;
  5408. for (;;) {
  5409. here = state.distcode[last_val + ((hold & (1 << last_bits + last_op) - 1 /*BITS(last.bits + last.op)*/) >> last_bits)];
  5410. here_bits = here >>> 24;
  5411. here_op = here >>> 16 & 0xff;
  5412. here_val = here & 0xffff;
  5413. if (last_bits + here_bits <= bits) {
  5414. break;
  5415. }
  5416. //--- PULLBYTE() ---//
  5417. if (have === 0) {
  5418. break inf_leave;
  5419. }
  5420. have--;
  5421. hold += input[next++] << bits;
  5422. bits += 8;
  5423. //---//
  5424. }
  5425. //--- DROPBITS(last.bits) ---//
  5426. hold >>>= last_bits;
  5427. bits -= last_bits;
  5428. //---//
  5429. state.back += last_bits;
  5430. }
  5431. //--- DROPBITS(here.bits) ---//
  5432. hold >>>= here_bits;
  5433. bits -= here_bits;
  5434. //---//
  5435. state.back += here_bits;
  5436. if (here_op & 64) {
  5437. strm.msg = 'invalid distance code';
  5438. state.mode = BAD;
  5439. break;
  5440. }
  5441. state.offset = here_val;
  5442. state.extra = here_op & 15;
  5443. state.mode = DISTEXT;
  5444. /* falls through */
  5445. case DISTEXT:
  5446. if (state.extra) {
  5447. //=== NEEDBITS(state.extra);
  5448. n = state.extra;
  5449. while (bits < n) {
  5450. if (have === 0) {
  5451. break inf_leave;
  5452. }
  5453. have--;
  5454. hold += input[next++] << bits;
  5455. bits += 8;
  5456. }
  5457. //===//
  5458. state.offset += hold & (1 << state.extra) - 1 /*BITS(state.extra)*/;
  5459. //--- DROPBITS(state.extra) ---//
  5460. hold >>>= state.extra;
  5461. bits -= state.extra;
  5462. //---//
  5463. state.back += state.extra;
  5464. }
  5465. //#ifdef INFLATE_STRICT
  5466. if (state.offset > state.dmax) {
  5467. strm.msg = 'invalid distance too far back';
  5468. state.mode = BAD;
  5469. break;
  5470. }
  5471. //#endif
  5472. //Tracevv((stderr, "inflate: distance %u\n", state.offset));
  5473. state.mode = MATCH;
  5474. /* falls through */
  5475. case MATCH:
  5476. if (left === 0) {
  5477. break inf_leave;
  5478. }
  5479. copy = _out - left;
  5480. if (state.offset > copy) {
  5481. /* copy from window */
  5482. copy = state.offset - copy;
  5483. if (copy > state.whave) {
  5484. if (state.sane) {
  5485. strm.msg = 'invalid distance too far back';
  5486. state.mode = BAD;
  5487. break;
  5488. }
  5489. // (!) This block is disabled in zlib defaults,
  5490. // don't enable it for binary compatibility
  5491. //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
  5492. // Trace((stderr, "inflate.c too far\n"));
  5493. // copy -= state.whave;
  5494. // if (copy > state.length) { copy = state.length; }
  5495. // if (copy > left) { copy = left; }
  5496. // left -= copy;
  5497. // state.length -= copy;
  5498. // do {
  5499. // output[put++] = 0;
  5500. // } while (--copy);
  5501. // if (state.length === 0) { state.mode = LEN; }
  5502. // break;
  5503. //#endif
  5504. }
  5505. if (copy > state.wnext) {
  5506. copy -= state.wnext;
  5507. from = state.wsize - copy;
  5508. } else {
  5509. from = state.wnext - copy;
  5510. }
  5511. if (copy > state.length) {
  5512. copy = state.length;
  5513. }
  5514. from_source = state.window;
  5515. } else {
  5516. /* copy from output */
  5517. from_source = output;
  5518. from = put - state.offset;
  5519. copy = state.length;
  5520. }
  5521. if (copy > left) {
  5522. copy = left;
  5523. }
  5524. left -= copy;
  5525. state.length -= copy;
  5526. do {
  5527. output[put++] = from_source[from++];
  5528. } while (--copy);
  5529. if (state.length === 0) {
  5530. state.mode = LEN;
  5531. }
  5532. break;
  5533. case LIT:
  5534. if (left === 0) {
  5535. break inf_leave;
  5536. }
  5537. output[put++] = state.length;
  5538. left--;
  5539. state.mode = LEN;
  5540. break;
  5541. case CHECK:
  5542. if (state.wrap) {
  5543. //=== NEEDBITS(32);
  5544. while (bits < 32) {
  5545. if (have === 0) {
  5546. break inf_leave;
  5547. }
  5548. have--;
  5549. // Use '|' instead of '+' to make sure that result is signed
  5550. hold |= input[next++] << bits;
  5551. bits += 8;
  5552. }
  5553. //===//
  5554. _out -= left;
  5555. strm.total_out += _out;
  5556. state.total += _out;
  5557. if (state.wrap & 4 && _out) {
  5558. strm.adler = state.check = /*UPDATE_CHECK(state.check, put - _out, _out);*/
  5559. state.flags ? crc32_1(state.check, output, _out, put - _out) : adler32_1(state.check, output, _out, put - _out);
  5560. }
  5561. _out = left;
  5562. // NB: crc32 stored as signed 32-bit int, zswap32 returns signed too
  5563. if (state.wrap & 4 && (state.flags ? hold : zswap32(hold)) !== state.check) {
  5564. strm.msg = 'incorrect data check';
  5565. state.mode = BAD;
  5566. break;
  5567. }
  5568. //=== INITBITS();
  5569. hold = 0;
  5570. bits = 0;
  5571. //===//
  5572. //Tracev((stderr, "inflate: check matches trailer\n"));
  5573. }
  5574. state.mode = LENGTH;
  5575. /* falls through */
  5576. case LENGTH:
  5577. if (state.wrap && state.flags) {
  5578. //=== NEEDBITS(32);
  5579. while (bits < 32) {
  5580. if (have === 0) {
  5581. break inf_leave;
  5582. }
  5583. have--;
  5584. hold += input[next++] << bits;
  5585. bits += 8;
  5586. }
  5587. //===//
  5588. if (state.wrap & 4 && hold !== (state.total & 0xffffffff)) {
  5589. strm.msg = 'incorrect length check';
  5590. state.mode = BAD;
  5591. break;
  5592. }
  5593. //=== INITBITS();
  5594. hold = 0;
  5595. bits = 0;
  5596. //===//
  5597. //Tracev((stderr, "inflate: length matches trailer\n"));
  5598. }
  5599. state.mode = DONE;
  5600. /* falls through */
  5601. case DONE:
  5602. ret = Z_STREAM_END$1;
  5603. break inf_leave;
  5604. case BAD:
  5605. ret = Z_DATA_ERROR$1;
  5606. break inf_leave;
  5607. case MEM:
  5608. return Z_MEM_ERROR$1;
  5609. case SYNC:
  5610. /* falls through */
  5611. default:
  5612. return Z_STREAM_ERROR$1;
  5613. }
  5614. }
  5615. // inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave"
  5616. /*
  5617. Return from inflate(), updating the total counts and the check value.
  5618. If there was no progress during the inflate() call, return a buffer
  5619. error. Call updatewindow() to create and/or update the window state.
  5620. Note: a memory error from inflate() is non-recoverable.
  5621. */
  5622. //--- RESTORE() ---
  5623. strm.next_out = put;
  5624. strm.avail_out = left;
  5625. strm.next_in = next;
  5626. strm.avail_in = have;
  5627. state.hold = hold;
  5628. state.bits = bits;
  5629. //---
  5630. if (state.wsize || _out !== strm.avail_out && state.mode < BAD && (state.mode < CHECK || flush !== Z_FINISH$1)) {
  5631. if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) ;
  5632. }
  5633. _in -= strm.avail_in;
  5634. _out -= strm.avail_out;
  5635. strm.total_in += _in;
  5636. strm.total_out += _out;
  5637. state.total += _out;
  5638. if (state.wrap & 4 && _out) {
  5639. strm.adler = state.check = /*UPDATE_CHECK(state.check, strm.next_out - _out, _out);*/
  5640. state.flags ? crc32_1(state.check, output, _out, strm.next_out - _out) : adler32_1(state.check, output, _out, strm.next_out - _out);
  5641. }
  5642. strm.data_type = state.bits + (state.last ? 64 : 0) + (state.mode === TYPE ? 128 : 0) + (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);
  5643. if ((_in === 0 && _out === 0 || flush === Z_FINISH$1) && ret === Z_OK$1) {
  5644. ret = Z_BUF_ERROR;
  5645. }
  5646. return ret;
  5647. };
  5648. var inflateEnd = function inflateEnd(strm) {
  5649. if (inflateStateCheck(strm)) {
  5650. return Z_STREAM_ERROR$1;
  5651. }
  5652. var state = strm.state;
  5653. if (state.window) {
  5654. state.window = null;
  5655. }
  5656. strm.state = null;
  5657. return Z_OK$1;
  5658. };
  5659. var inflateGetHeader = function inflateGetHeader(strm, head) {
  5660. /* check state */
  5661. if (inflateStateCheck(strm)) {
  5662. return Z_STREAM_ERROR$1;
  5663. }
  5664. var state = strm.state;
  5665. if ((state.wrap & 2) === 0) {
  5666. return Z_STREAM_ERROR$1;
  5667. }
  5668. /* save header structure */
  5669. state.head = head;
  5670. head.done = false;
  5671. return Z_OK$1;
  5672. };
  5673. var inflateSetDictionary = function inflateSetDictionary(strm, dictionary) {
  5674. var dictLength = dictionary.length;
  5675. var state;
  5676. var dictid;
  5677. var ret;
  5678. /* check state */
  5679. if (inflateStateCheck(strm)) {
  5680. return Z_STREAM_ERROR$1;
  5681. }
  5682. state = strm.state;
  5683. if (state.wrap !== 0 && state.mode !== DICT) {
  5684. return Z_STREAM_ERROR$1;
  5685. }
  5686. /* check for correct dictionary identifier */
  5687. if (state.mode === DICT) {
  5688. dictid = 1; /* adler32(0, null, 0)*/
  5689. /* dictid = adler32(dictid, dictionary, dictLength); */
  5690. dictid = adler32_1(dictid, dictionary, dictLength, 0);
  5691. if (dictid !== state.check) {
  5692. return Z_DATA_ERROR$1;
  5693. }
  5694. }
  5695. /* copy dictionary to window using updatewindow(), which will amend the
  5696. existing dictionary if appropriate */
  5697. ret = updatewindow(strm, dictionary, dictLength, dictLength);
  5698. if (ret) {
  5699. state.mode = MEM;
  5700. return Z_MEM_ERROR$1;
  5701. }
  5702. state.havedict = 1;
  5703. // Tracev((stderr, "inflate: dictionary set\n"));
  5704. return Z_OK$1;
  5705. };
  5706. var inflateReset_1 = inflateReset;
  5707. var inflateReset2_1 = inflateReset2;
  5708. var inflateResetKeep_1 = inflateResetKeep;
  5709. var inflateInit_1 = inflateInit;
  5710. var inflateInit2_1 = inflateInit2;
  5711. var inflate_2$1 = inflate$2;
  5712. var inflateEnd_1 = inflateEnd;
  5713. var inflateGetHeader_1 = inflateGetHeader;
  5714. var inflateSetDictionary_1 = inflateSetDictionary;
  5715. var inflateInfo = 'pako inflate (from Nodeca project)';
  5716. /* Not implemented
  5717. module.exports.inflateCodesUsed = inflateCodesUsed;
  5718. module.exports.inflateCopy = inflateCopy;
  5719. module.exports.inflateGetDictionary = inflateGetDictionary;
  5720. module.exports.inflateMark = inflateMark;
  5721. module.exports.inflatePrime = inflatePrime;
  5722. module.exports.inflateSync = inflateSync;
  5723. module.exports.inflateSyncPoint = inflateSyncPoint;
  5724. module.exports.inflateUndermine = inflateUndermine;
  5725. module.exports.inflateValidate = inflateValidate;
  5726. */
  5727. var inflate_1$2 = {
  5728. inflateReset: inflateReset_1,
  5729. inflateReset2: inflateReset2_1,
  5730. inflateResetKeep: inflateResetKeep_1,
  5731. inflateInit: inflateInit_1,
  5732. inflateInit2: inflateInit2_1,
  5733. inflate: inflate_2$1,
  5734. inflateEnd: inflateEnd_1,
  5735. inflateGetHeader: inflateGetHeader_1,
  5736. inflateSetDictionary: inflateSetDictionary_1,
  5737. inflateInfo: inflateInfo
  5738. };
  5739. // (C) 1995-2013 Jean-loup Gailly and Mark Adler
  5740. // (C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
  5741. //
  5742. // This software is provided 'as-is', without any express or implied
  5743. // warranty. In no event will the authors be held liable for any damages
  5744. // arising from the use of this software.
  5745. //
  5746. // Permission is granted to anyone to use this software for any purpose,
  5747. // including commercial applications, and to alter it and redistribute it
  5748. // freely, subject to the following restrictions:
  5749. //
  5750. // 1. The origin of this software must not be misrepresented; you must not
  5751. // claim that you wrote the original software. If you use this software
  5752. // in a product, an acknowledgment in the product documentation would be
  5753. // appreciated but is not required.
  5754. // 2. Altered source versions must be plainly marked as such, and must not be
  5755. // misrepresented as being the original software.
  5756. // 3. This notice may not be removed or altered from any source distribution.
  5757. function GZheader() {
  5758. /* true if compressed data believed to be text */
  5759. this.text = 0;
  5760. /* modification time */
  5761. this.time = 0;
  5762. /* extra flags (not used when writing a gzip file) */
  5763. this.xflags = 0;
  5764. /* operating system */
  5765. this.os = 0;
  5766. /* pointer to extra field or Z_NULL if none */
  5767. this.extra = null;
  5768. /* extra field length (valid if extra != Z_NULL) */
  5769. this.extra_len = 0; // Actually, we don't need it in JS,
  5770. // but leave for few code modifications
  5771. //
  5772. // Setup limits is not necessary because in js we should not preallocate memory
  5773. // for inflate use constant limit in 65536 bytes
  5774. //
  5775. /* space at extra (only when reading header) */
  5776. // this.extra_max = 0;
  5777. /* pointer to zero-terminated file name or Z_NULL */
  5778. this.name = '';
  5779. /* space at name (only when reading header) */
  5780. // this.name_max = 0;
  5781. /* pointer to zero-terminated comment or Z_NULL */
  5782. this.comment = '';
  5783. /* space at comment (only when reading header) */
  5784. // this.comm_max = 0;
  5785. /* true if there was or will be a header crc */
  5786. this.hcrc = 0;
  5787. /* true when done reading gzip header (not used when writing a gzip file) */
  5788. this.done = false;
  5789. }
  5790. var gzheader = GZheader;
  5791. var toString = Object.prototype.toString;
  5792. /* Public constants ==========================================================*/
  5793. /* ===========================================================================*/
  5794. var Z_NO_FLUSH = constants$2.Z_NO_FLUSH,
  5795. Z_FINISH = constants$2.Z_FINISH,
  5796. Z_OK = constants$2.Z_OK,
  5797. Z_STREAM_END = constants$2.Z_STREAM_END,
  5798. Z_NEED_DICT = constants$2.Z_NEED_DICT,
  5799. Z_STREAM_ERROR = constants$2.Z_STREAM_ERROR,
  5800. Z_DATA_ERROR = constants$2.Z_DATA_ERROR,
  5801. Z_MEM_ERROR = constants$2.Z_MEM_ERROR;
  5802. /* ===========================================================================*/
  5803. /**
  5804. * class Inflate
  5805. *
  5806. * Generic JS-style wrapper for zlib calls. If you don't need
  5807. * streaming behaviour - use more simple functions: [[inflate]]
  5808. * and [[inflateRaw]].
  5809. **/
  5810. /* internal
  5811. * inflate.chunks -> Array
  5812. *
  5813. * Chunks of output data, if [[Inflate#onData]] not overridden.
  5814. **/
  5815. /**
  5816. * Inflate.result -> Uint8Array|String
  5817. *
  5818. * Uncompressed result, generated by default [[Inflate#onData]]
  5819. * and [[Inflate#onEnd]] handlers. Filled after you push last chunk
  5820. * (call [[Inflate#push]] with `Z_FINISH` / `true` param).
  5821. **/
  5822. /**
  5823. * Inflate.err -> Number
  5824. *
  5825. * Error code after inflate finished. 0 (Z_OK) on success.
  5826. * Should be checked if broken data possible.
  5827. **/
  5828. /**
  5829. * Inflate.msg -> String
  5830. *
  5831. * Error message, if [[Inflate.err]] != 0
  5832. **/
  5833. /**
  5834. * new Inflate(options)
  5835. * - options (Object): zlib inflate options.
  5836. *
  5837. * Creates new inflator instance with specified params. Throws exception
  5838. * on bad params. Supported options:
  5839. *
  5840. * - `windowBits`
  5841. * - `dictionary`
  5842. *
  5843. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  5844. * for more information on these.
  5845. *
  5846. * Additional options, for internal needs:
  5847. *
  5848. * - `chunkSize` - size of generated data chunks (16K by default)
  5849. * - `raw` (Boolean) - do raw inflate
  5850. * - `to` (String) - if equal to 'string', then result will be converted
  5851. * from utf8 to utf16 (javascript) string. When string output requested,
  5852. * chunk length can differ from `chunkSize`, depending on content.
  5853. *
  5854. * By default, when no options set, autodetect deflate/gzip data format via
  5855. * wrapper header.
  5856. *
  5857. * ##### Example:
  5858. *
  5859. * ```javascript
  5860. * const pako = require('pako')
  5861. * const chunk1 = new Uint8Array([1,2,3,4,5,6,7,8,9])
  5862. * const chunk2 = new Uint8Array([10,11,12,13,14,15,16,17,18,19]);
  5863. *
  5864. * const inflate = new pako.Inflate({ level: 3});
  5865. *
  5866. * inflate.push(chunk1, false);
  5867. * inflate.push(chunk2, true); // true -> last chunk
  5868. *
  5869. * if (inflate.err) { throw new Error(inflate.err); }
  5870. *
  5871. * console.log(inflate.result);
  5872. * ```
  5873. **/
  5874. function Inflate$1(options) {
  5875. this.options = common.assign({
  5876. chunkSize: 1024 * 64,
  5877. windowBits: 15,
  5878. to: ''
  5879. }, options || {});
  5880. var opt = this.options;
  5881. // Force window size for `raw` data, if not set directly,
  5882. // because we have no header for autodetect.
  5883. if (opt.raw && opt.windowBits >= 0 && opt.windowBits < 16) {
  5884. opt.windowBits = -opt.windowBits;
  5885. if (opt.windowBits === 0) {
  5886. opt.windowBits = -15;
  5887. }
  5888. }
  5889. // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
  5890. if (opt.windowBits >= 0 && opt.windowBits < 16 && !(options && options.windowBits)) {
  5891. opt.windowBits += 32;
  5892. }
  5893. // Gzip header has no info about windows size, we can do autodetect only
  5894. // for deflate. So, if window size not set, force it to max when gzip possible
  5895. if (opt.windowBits > 15 && opt.windowBits < 48) {
  5896. // bit 3 (16) -> gzipped data
  5897. // bit 4 (32) -> autodetect gzip/deflate
  5898. if ((opt.windowBits & 15) === 0) {
  5899. opt.windowBits |= 15;
  5900. }
  5901. }
  5902. this.err = 0; // error code, if happens (0 = Z_OK)
  5903. this.msg = ''; // error message
  5904. this.ended = false; // used to avoid multiple onEnd() calls
  5905. this.chunks = []; // chunks of compressed data
  5906. this.strm = new zstream();
  5907. this.strm.avail_out = 0;
  5908. var status = inflate_1$2.inflateInit2(this.strm, opt.windowBits);
  5909. if (status !== Z_OK) {
  5910. throw new Error(messages[status]);
  5911. }
  5912. this.header = new gzheader();
  5913. inflate_1$2.inflateGetHeader(this.strm, this.header);
  5914. // Setup dictionary
  5915. if (opt.dictionary) {
  5916. // Convert data if needed
  5917. if (typeof opt.dictionary === 'string') {
  5918. opt.dictionary = strings.string2buf(opt.dictionary);
  5919. } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
  5920. opt.dictionary = new Uint8Array(opt.dictionary);
  5921. }
  5922. if (opt.raw) {
  5923. //In raw mode we need to set the dictionary early
  5924. status = inflate_1$2.inflateSetDictionary(this.strm, opt.dictionary);
  5925. if (status !== Z_OK) {
  5926. throw new Error(messages[status]);
  5927. }
  5928. }
  5929. }
  5930. }
  5931. /**
  5932. * Inflate#push(data[, flush_mode]) -> Boolean
  5933. * - data (Uint8Array|ArrayBuffer): input data
  5934. * - flush_mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE
  5935. * flush modes. See constants. Skipped or `false` means Z_NO_FLUSH,
  5936. * `true` means Z_FINISH.
  5937. *
  5938. * Sends input data to inflate pipe, generating [[Inflate#onData]] calls with
  5939. * new output chunks. Returns `true` on success. If end of stream detected,
  5940. * [[Inflate#onEnd]] will be called.
  5941. *
  5942. * `flush_mode` is not needed for normal operation, because end of stream
  5943. * detected automatically. You may try to use it for advanced things, but
  5944. * this functionality was not tested.
  5945. *
  5946. * On fail call [[Inflate#onEnd]] with error code and return false.
  5947. *
  5948. * ##### Example
  5949. *
  5950. * ```javascript
  5951. * push(chunk, false); // push one of data chunks
  5952. * ...
  5953. * push(chunk, true); // push last chunk
  5954. * ```
  5955. **/
  5956. Inflate$1.prototype.push = function (data, flush_mode) {
  5957. var strm = this.strm;
  5958. var chunkSize = this.options.chunkSize;
  5959. var dictionary = this.options.dictionary;
  5960. var status, _flush_mode, last_avail_out;
  5961. if (this.ended) return false;
  5962. if (flush_mode === ~~flush_mode) _flush_mode = flush_mode;else _flush_mode = flush_mode === true ? Z_FINISH : Z_NO_FLUSH;
  5963. // Convert data if needed
  5964. if (toString.call(data) === '[object ArrayBuffer]') {
  5965. strm.input = new Uint8Array(data);
  5966. } else {
  5967. strm.input = data;
  5968. }
  5969. strm.next_in = 0;
  5970. strm.avail_in = strm.input.length;
  5971. for (;;) {
  5972. if (strm.avail_out === 0) {
  5973. strm.output = new Uint8Array(chunkSize);
  5974. strm.next_out = 0;
  5975. strm.avail_out = chunkSize;
  5976. }
  5977. status = inflate_1$2.inflate(strm, _flush_mode);
  5978. if (status === Z_NEED_DICT && dictionary) {
  5979. status = inflate_1$2.inflateSetDictionary(strm, dictionary);
  5980. if (status === Z_OK) {
  5981. status = inflate_1$2.inflate(strm, _flush_mode);
  5982. } else if (status === Z_DATA_ERROR) {
  5983. // Replace code with more verbose
  5984. status = Z_NEED_DICT;
  5985. }
  5986. }
  5987. // Skip snyc markers if more data follows and not raw mode
  5988. while (strm.avail_in > 0 && status === Z_STREAM_END && strm.state.wrap > 0 && data[strm.next_in] !== 0) {
  5989. inflate_1$2.inflateReset(strm);
  5990. status = inflate_1$2.inflate(strm, _flush_mode);
  5991. }
  5992. switch (status) {
  5993. case Z_STREAM_ERROR:
  5994. case Z_DATA_ERROR:
  5995. case Z_NEED_DICT:
  5996. case Z_MEM_ERROR:
  5997. this.onEnd(status);
  5998. this.ended = true;
  5999. return false;
  6000. }
  6001. // Remember real `avail_out` value, because we may patch out buffer content
  6002. // to align utf8 strings boundaries.
  6003. last_avail_out = strm.avail_out;
  6004. if (strm.next_out) {
  6005. if (strm.avail_out === 0 || status === Z_STREAM_END) {
  6006. if (this.options.to === 'string') {
  6007. var next_out_utf8 = strings.utf8border(strm.output, strm.next_out);
  6008. var tail = strm.next_out - next_out_utf8;
  6009. var utf8str = strings.buf2string(strm.output, next_out_utf8);
  6010. // move tail & realign counters
  6011. strm.next_out = tail;
  6012. strm.avail_out = chunkSize - tail;
  6013. if (tail) strm.output.set(strm.output.subarray(next_out_utf8, next_out_utf8 + tail), 0);
  6014. this.onData(utf8str);
  6015. } else {
  6016. this.onData(strm.output.length === strm.next_out ? strm.output : strm.output.subarray(0, strm.next_out));
  6017. }
  6018. }
  6019. }
  6020. // Must repeat iteration if out buffer is full
  6021. if (status === Z_OK && last_avail_out === 0) continue;
  6022. // Finalize if end of stream reached.
  6023. if (status === Z_STREAM_END) {
  6024. status = inflate_1$2.inflateEnd(this.strm);
  6025. this.onEnd(status);
  6026. this.ended = true;
  6027. return true;
  6028. }
  6029. if (strm.avail_in === 0) break;
  6030. }
  6031. return true;
  6032. };
  6033. /**
  6034. * Inflate#onData(chunk) -> Void
  6035. * - chunk (Uint8Array|String): output data. When string output requested,
  6036. * each chunk will be string.
  6037. *
  6038. * By default, stores data blocks in `chunks[]` property and glue
  6039. * those in `onEnd`. Override this handler, if you need another behaviour.
  6040. **/
  6041. Inflate$1.prototype.onData = function (chunk) {
  6042. this.chunks.push(chunk);
  6043. };
  6044. /**
  6045. * Inflate#onEnd(status) -> Void
  6046. * - status (Number): inflate status. 0 (Z_OK) on success,
  6047. * other if not.
  6048. *
  6049. * Called either after you tell inflate that the input stream is
  6050. * complete (Z_FINISH). By default - join collected chunks,
  6051. * free memory and fill `results` / `err` properties.
  6052. **/
  6053. Inflate$1.prototype.onEnd = function (status) {
  6054. // On success - join
  6055. if (status === Z_OK) {
  6056. if (this.options.to === 'string') {
  6057. this.result = this.chunks.join('');
  6058. } else {
  6059. this.result = common.flattenChunks(this.chunks);
  6060. }
  6061. }
  6062. this.chunks = [];
  6063. this.err = status;
  6064. this.msg = this.strm.msg;
  6065. };
  6066. /**
  6067. * inflate(data[, options]) -> Uint8Array|String
  6068. * - data (Uint8Array|ArrayBuffer): input data to decompress.
  6069. * - options (Object): zlib inflate options.
  6070. *
  6071. * Decompress `data` with inflate/ungzip and `options`. Autodetect
  6072. * format via wrapper header by default. That's why we don't provide
  6073. * separate `ungzip` method.
  6074. *
  6075. * Supported options are:
  6076. *
  6077. * - windowBits
  6078. *
  6079. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  6080. * for more information.
  6081. *
  6082. * Sugar (options):
  6083. *
  6084. * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
  6085. * negative windowBits implicitly.
  6086. * - `to` (String) - if equal to 'string', then result will be converted
  6087. * from utf8 to utf16 (javascript) string. When string output requested,
  6088. * chunk length can differ from `chunkSize`, depending on content.
  6089. *
  6090. *
  6091. * ##### Example:
  6092. *
  6093. * ```javascript
  6094. * const pako = require('pako');
  6095. * const input = pako.deflate(new Uint8Array([1,2,3,4,5,6,7,8,9]));
  6096. * let output;
  6097. *
  6098. * try {
  6099. * output = pako.inflate(input);
  6100. * } catch (err) {
  6101. * console.log(err);
  6102. * }
  6103. * ```
  6104. **/
  6105. function inflate$1(input, options) {
  6106. var inflator = new Inflate$1(options);
  6107. inflator.push(input);
  6108. // That will never happens, if you don't cheat with options :)
  6109. if (inflator.err) throw inflator.msg || messages[inflator.err];
  6110. return inflator.result;
  6111. }
  6112. /**
  6113. * inflateRaw(data[, options]) -> Uint8Array|String
  6114. * - data (Uint8Array|ArrayBuffer): input data to decompress.
  6115. * - options (Object): zlib inflate options.
  6116. *
  6117. * The same as [[inflate]], but creates raw data, without wrapper
  6118. * (header and adler32 crc).
  6119. **/
  6120. function inflateRaw$1(input, options) {
  6121. options = options || {};
  6122. options.raw = true;
  6123. return inflate$1(input, options);
  6124. }
  6125. /**
  6126. * ungzip(data[, options]) -> Uint8Array|String
  6127. * - data (Uint8Array|ArrayBuffer): input data to decompress.
  6128. * - options (Object): zlib inflate options.
  6129. *
  6130. * Just shortcut to [[inflate]], because it autodetects format
  6131. * by header.content. Done for convenience.
  6132. **/
  6133. var Inflate_1$1 = Inflate$1;
  6134. var inflate_2 = inflate$1;
  6135. var inflateRaw_1$1 = inflateRaw$1;
  6136. var ungzip$1 = inflate$1;
  6137. var constants = constants$2;
  6138. var inflate_1$1 = {
  6139. Inflate: Inflate_1$1,
  6140. inflate: inflate_2,
  6141. inflateRaw: inflateRaw_1$1,
  6142. ungzip: ungzip$1,
  6143. constants: constants
  6144. };
  6145. var Deflate = deflate_1$1.Deflate,
  6146. deflate = deflate_1$1.deflate,
  6147. deflateRaw = deflate_1$1.deflateRaw,
  6148. gzip = deflate_1$1.gzip;
  6149. var Inflate = inflate_1$1.Inflate,
  6150. inflate = inflate_1$1.inflate,
  6151. inflateRaw = inflate_1$1.inflateRaw,
  6152. ungzip = inflate_1$1.ungzip;
  6153. var Deflate_1 = Deflate;
  6154. var deflate_1 = deflate;
  6155. var deflateRaw_1 = deflateRaw;
  6156. var gzip_1 = gzip;
  6157. var Inflate_1 = Inflate;
  6158. var inflate_1 = inflate;
  6159. var inflateRaw_1 = inflateRaw;
  6160. var ungzip_1 = ungzip;
  6161. var constants_1 = constants$2;
  6162. var pako = {
  6163. Deflate: Deflate_1,
  6164. deflate: deflate_1,
  6165. deflateRaw: deflateRaw_1,
  6166. gzip: gzip_1,
  6167. Inflate: Inflate_1,
  6168. inflate: inflate_1,
  6169. inflateRaw: inflateRaw_1,
  6170. ungzip: ungzip_1,
  6171. constants: constants_1
  6172. };
  6173. exports.Deflate = Deflate_1;
  6174. exports.Inflate = Inflate_1;
  6175. exports.constants = constants_1;
  6176. exports["default"] = pako;
  6177. exports.deflate = deflate_1;
  6178. exports.deflateRaw = deflateRaw_1;
  6179. exports.gzip = gzip_1;
  6180. exports.inflate = inflate_1;
  6181. exports.inflateRaw = inflateRaw_1;
  6182. exports.ungzip = ungzip_1;
  6183. Object.defineProperty(exports, '__esModule', { value: true });
  6184. }));