zip-full.js 305 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.zip = {}));
  5. })(this, (function (exports) { 'use strict';
  6. const { Array, Object, String, BigInt, Math, Date, Map, URL, Error, Uint8Array, Uint16Array, Uint32Array, DataView, Blob, Promise, TextEncoder, TextDecoder, FileReader, document, crypto, btoa } = globalThis;
  7. /*
  8. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. 1. Redistributions of source code must retain the above copyright notice,
  12. this list of conditions and the following disclaimer.
  13. 2. Redistributions in binary form must reproduce the above copyright
  14. notice, this list of conditions and the following disclaimer in
  15. the documentation and/or other materials provided with the distribution.
  16. 3. The names of the authors may not be used to endorse or promote products
  17. derived from this software without specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  19. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  20. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  21. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  24. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  25. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  27. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. /*
  30. * This program is based on JZlib 1.0.2 ymnk, JCraft,Inc.
  31. * JZlib is based on zlib-1.1.3, so all credit should go authors
  32. * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  33. * and contributors of zlib.
  34. */
  35. // deno-lint-ignore-file no-this-alias prefer-const
  36. // Global
  37. const MAX_BITS$1 = 15;
  38. const D_CODES = 30;
  39. const BL_CODES = 19;
  40. const LENGTH_CODES = 29;
  41. const LITERALS = 256;
  42. const L_CODES = (LITERALS + 1 + LENGTH_CODES);
  43. const HEAP_SIZE = (2 * L_CODES + 1);
  44. const END_BLOCK = 256;
  45. // Bit length codes must not exceed MAX_BL_BITS bits
  46. const MAX_BL_BITS = 7;
  47. // repeat previous bit length 3-6 times (2 bits of repeat count)
  48. const REP_3_6 = 16;
  49. // repeat a zero length 3-10 times (3 bits of repeat count)
  50. const REPZ_3_10 = 17;
  51. // repeat a zero length 11-138 times (7 bits of repeat count)
  52. const REPZ_11_138 = 18;
  53. // The lengths of the bit length codes are sent in order of decreasing
  54. // probability, to avoid transmitting the lengths for unused bit
  55. // length codes.
  56. const Buf_size = 8 * 2;
  57. // JZlib version : "1.0.2"
  58. const Z_DEFAULT_COMPRESSION = -1;
  59. // compression strategy
  60. const Z_FILTERED = 1;
  61. const Z_HUFFMAN_ONLY = 2;
  62. const Z_DEFAULT_STRATEGY = 0;
  63. const Z_NO_FLUSH$1 = 0;
  64. const Z_PARTIAL_FLUSH = 1;
  65. const Z_FULL_FLUSH = 3;
  66. const Z_FINISH$1 = 4;
  67. const Z_OK$1 = 0;
  68. const Z_STREAM_END$1 = 1;
  69. const Z_NEED_DICT$1 = 2;
  70. const Z_STREAM_ERROR$1 = -2;
  71. const Z_DATA_ERROR$1 = -3;
  72. const Z_BUF_ERROR$1 = -5;
  73. // Tree
  74. function extractArray(array) {
  75. return flatArray(array.map(([length, value]) => (new Array(length)).fill(value, 0, length)));
  76. }
  77. function flatArray(array) {
  78. return array.reduce((a, b) => a.concat(Array.isArray(b) ? flatArray(b) : b), []);
  79. }
  80. // see definition of array dist_code below
  81. const _dist_code = [0, 1, 2, 3].concat(...extractArray([
  82. [2, 4], [2, 5], [4, 6], [4, 7], [8, 8], [8, 9], [16, 10], [16, 11], [32, 12], [32, 13], [64, 14], [64, 15], [2, 0], [1, 16],
  83. [1, 17], [2, 18], [2, 19], [4, 20], [4, 21], [8, 22], [8, 23], [16, 24], [16, 25], [32, 26], [32, 27], [64, 28], [64, 29]
  84. ]));
  85. function Tree() {
  86. const that = this;
  87. // dyn_tree; // the dynamic tree
  88. // max_code; // largest code with non zero frequency
  89. // stat_desc; // the corresponding static tree
  90. // Compute the optimal bit lengths for a tree and update the total bit
  91. // length
  92. // for the current block.
  93. // IN assertion: the fields freq and dad are set, heap[heap_max] and
  94. // above are the tree nodes sorted by increasing frequency.
  95. // OUT assertions: the field len is set to the optimal bit length, the
  96. // array bl_count contains the frequencies for each bit length.
  97. // The length opt_len is updated; static_len is also updated if stree is
  98. // not null.
  99. function gen_bitlen(s) {
  100. const tree = that.dyn_tree;
  101. const stree = that.stat_desc.static_tree;
  102. const extra = that.stat_desc.extra_bits;
  103. const base = that.stat_desc.extra_base;
  104. const max_length = that.stat_desc.max_length;
  105. let h; // heap index
  106. let n, m; // iterate over the tree elements
  107. let bits; // bit length
  108. let xbits; // extra bits
  109. let f; // frequency
  110. let overflow = 0; // number of elements with bit length too large
  111. for (bits = 0; bits <= MAX_BITS$1; bits++)
  112. s.bl_count[bits] = 0;
  113. // In a first pass, compute the optimal bit lengths (which may
  114. // overflow in the case of the bit length tree).
  115. tree[s.heap[s.heap_max] * 2 + 1] = 0; // root of the heap
  116. for (h = s.heap_max + 1; h < HEAP_SIZE; h++) {
  117. n = s.heap[h];
  118. bits = tree[tree[n * 2 + 1] * 2 + 1] + 1;
  119. if (bits > max_length) {
  120. bits = max_length;
  121. overflow++;
  122. }
  123. tree[n * 2 + 1] = bits;
  124. // We overwrite tree[n*2+1] which is no longer needed
  125. if (n > that.max_code)
  126. continue; // not a leaf node
  127. s.bl_count[bits]++;
  128. xbits = 0;
  129. if (n >= base)
  130. xbits = extra[n - base];
  131. f = tree[n * 2];
  132. s.opt_len += f * (bits + xbits);
  133. if (stree)
  134. s.static_len += f * (stree[n * 2 + 1] + xbits);
  135. }
  136. if (overflow === 0)
  137. return;
  138. // This happens for example on obj2 and pic of the Calgary corpus
  139. // Find the first bit length which could increase:
  140. do {
  141. bits = max_length - 1;
  142. while (s.bl_count[bits] === 0)
  143. bits--;
  144. s.bl_count[bits]--; // move one leaf down the tree
  145. s.bl_count[bits + 1] += 2; // move one overflow item as its brother
  146. s.bl_count[max_length]--;
  147. // The brother of the overflow item also moves one step up,
  148. // but this does not affect bl_count[max_length]
  149. overflow -= 2;
  150. } while (overflow > 0);
  151. for (bits = max_length; bits !== 0; bits--) {
  152. n = s.bl_count[bits];
  153. while (n !== 0) {
  154. m = s.heap[--h];
  155. if (m > that.max_code)
  156. continue;
  157. if (tree[m * 2 + 1] != bits) {
  158. s.opt_len += (bits - tree[m * 2 + 1]) * tree[m * 2];
  159. tree[m * 2 + 1] = bits;
  160. }
  161. n--;
  162. }
  163. }
  164. }
  165. // Reverse the first len bits of a code, using straightforward code (a
  166. // faster
  167. // method would use a table)
  168. // IN assertion: 1 <= len <= 15
  169. function bi_reverse(code, // the value to invert
  170. len // its bit length
  171. ) {
  172. let res = 0;
  173. do {
  174. res |= code & 1;
  175. code >>>= 1;
  176. res <<= 1;
  177. } while (--len > 0);
  178. return res >>> 1;
  179. }
  180. // Generate the codes for a given tree and bit counts (which need not be
  181. // optimal).
  182. // IN assertion: the array bl_count contains the bit length statistics for
  183. // the given tree and the field len is set for all tree elements.
  184. // OUT assertion: the field code is set for all tree elements of non
  185. // zero code length.
  186. function gen_codes(tree, // the tree to decorate
  187. max_code, // largest code with non zero frequency
  188. bl_count // number of codes at each bit length
  189. ) {
  190. const next_code = []; // next code value for each
  191. // bit length
  192. let code = 0; // running code value
  193. let bits; // bit index
  194. let n; // code index
  195. let len;
  196. // The distribution counts are first used to generate the code values
  197. // without bit reversal.
  198. for (bits = 1; bits <= MAX_BITS$1; bits++) {
  199. next_code[bits] = code = ((code + bl_count[bits - 1]) << 1);
  200. }
  201. // Check that the bit counts in bl_count are consistent. The last code
  202. // must be all ones.
  203. // Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  204. // "inconsistent bit counts");
  205. // Tracev((stderr,"gen_codes: max_code %d ", max_code));
  206. for (n = 0; n <= max_code; n++) {
  207. len = tree[n * 2 + 1];
  208. if (len === 0)
  209. continue;
  210. // Now reverse the bits
  211. tree[n * 2] = bi_reverse(next_code[len]++, len);
  212. }
  213. }
  214. // Construct one Huffman tree and assigns the code bit strings and lengths.
  215. // Update the total bit length for the current block.
  216. // IN assertion: the field freq is set for all tree elements.
  217. // OUT assertions: the fields len and code are set to the optimal bit length
  218. // and corresponding code. The length opt_len is updated; static_len is
  219. // also updated if stree is not null. The field max_code is set.
  220. that.build_tree = function (s) {
  221. const tree = that.dyn_tree;
  222. const stree = that.stat_desc.static_tree;
  223. const elems = that.stat_desc.elems;
  224. let n, m; // iterate over heap elements
  225. let max_code = -1; // largest code with non zero frequency
  226. let node; // new node being created
  227. // Construct the initial heap, with least frequent element in
  228. // heap[1]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
  229. // heap[0] is not used.
  230. s.heap_len = 0;
  231. s.heap_max = HEAP_SIZE;
  232. for (n = 0; n < elems; n++) {
  233. if (tree[n * 2] !== 0) {
  234. s.heap[++s.heap_len] = max_code = n;
  235. s.depth[n] = 0;
  236. } else {
  237. tree[n * 2 + 1] = 0;
  238. }
  239. }
  240. // The pkzip format requires that at least one distance code exists,
  241. // and that at least one bit should be sent even if there is only one
  242. // possible code. So to avoid special checks later on we force at least
  243. // two codes of non zero frequency.
  244. while (s.heap_len < 2) {
  245. node = s.heap[++s.heap_len] = max_code < 2 ? ++max_code : 0;
  246. tree[node * 2] = 1;
  247. s.depth[node] = 0;
  248. s.opt_len--;
  249. if (stree)
  250. s.static_len -= stree[node * 2 + 1];
  251. // node is 0 or 1 so it does not have extra bits
  252. }
  253. that.max_code = max_code;
  254. // The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
  255. // establish sub-heaps of increasing lengths:
  256. for (n = Math.floor(s.heap_len / 2); n >= 1; n--)
  257. s.pqdownheap(tree, n);
  258. // Construct the Huffman tree by repeatedly combining the least two
  259. // frequent nodes.
  260. node = elems; // next internal node of the tree
  261. do {
  262. // n = node of least frequency
  263. n = s.heap[1];
  264. s.heap[1] = s.heap[s.heap_len--];
  265. s.pqdownheap(tree, 1);
  266. m = s.heap[1]; // m = node of next least frequency
  267. s.heap[--s.heap_max] = n; // keep the nodes sorted by frequency
  268. s.heap[--s.heap_max] = m;
  269. // Create a new node father of n and m
  270. tree[node * 2] = (tree[n * 2] + tree[m * 2]);
  271. s.depth[node] = Math.max(s.depth[n], s.depth[m]) + 1;
  272. tree[n * 2 + 1] = tree[m * 2 + 1] = node;
  273. // and insert the new node in the heap
  274. s.heap[1] = node++;
  275. s.pqdownheap(tree, 1);
  276. } while (s.heap_len >= 2);
  277. s.heap[--s.heap_max] = s.heap[1];
  278. // At this point, the fields freq and dad are set. We can now
  279. // generate the bit lengths.
  280. gen_bitlen(s);
  281. // The field len is now set, we can generate the bit codes
  282. gen_codes(tree, that.max_code, s.bl_count);
  283. };
  284. }
  285. Tree._length_code = [0, 1, 2, 3, 4, 5, 6, 7].concat(...extractArray([
  286. [2, 8], [2, 9], [2, 10], [2, 11], [4, 12], [4, 13], [4, 14], [4, 15], [8, 16], [8, 17], [8, 18], [8, 19],
  287. [16, 20], [16, 21], [16, 22], [16, 23], [32, 24], [32, 25], [32, 26], [31, 27], [1, 28]]));
  288. Tree.base_length = [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 0];
  289. Tree.base_dist = [0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384,
  290. 24576];
  291. // Mapping from a distance to a distance code. dist is the distance - 1 and
  292. // must not have side effects. _dist_code[256] and _dist_code[257] are never
  293. // used.
  294. Tree.d_code = function (dist) {
  295. return ((dist) < 256 ? _dist_code[dist] : _dist_code[256 + ((dist) >>> 7)]);
  296. };
  297. // extra bits for each length code
  298. Tree.extra_lbits = [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];
  299. // extra bits for each distance code
  300. Tree.extra_dbits = [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];
  301. // extra bits for each bit length code
  302. Tree.extra_blbits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7];
  303. Tree.bl_order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
  304. // StaticTree
  305. function StaticTree(static_tree, extra_bits, extra_base, elems, max_length) {
  306. const that = this;
  307. that.static_tree = static_tree;
  308. that.extra_bits = extra_bits;
  309. that.extra_base = extra_base;
  310. that.elems = elems;
  311. that.max_length = max_length;
  312. }
  313. const static_ltree2_first_part = [12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252, 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82,
  314. 210, 50, 178, 114, 242, 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86,
  315. 214, 54, 182, 118, 246, 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254, 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81,
  316. 209, 49, 177, 113, 241, 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85,
  317. 213, 53, 181, 117, 245, 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, 19, 275, 147, 403, 83, 339, 211, 467, 51, 307,
  318. 179, 435, 115, 371, 243, 499, 11, 267, 139, 395, 75, 331, 203, 459, 43, 299, 171, 427, 107, 363, 235, 491, 27, 283, 155, 411, 91, 347, 219, 475,
  319. 59, 315, 187, 443, 123, 379, 251, 507, 7, 263, 135, 391, 71, 327, 199, 455, 39, 295, 167, 423, 103, 359, 231, 487, 23, 279, 151, 407, 87, 343, 215,
  320. 471, 55, 311, 183, 439, 119, 375, 247, 503, 15, 271, 143, 399, 79, 335, 207, 463, 47, 303, 175, 431, 111, 367, 239, 495, 31, 287, 159, 415, 95,
  321. 351, 223, 479, 63, 319, 191, 447, 127, 383, 255, 511, 0, 64, 32, 96, 16, 80, 48, 112, 8, 72, 40, 104, 24, 88, 56, 120, 4, 68, 36, 100, 20, 84, 52,
  322. 116, 3, 131, 67, 195, 35, 163, 99, 227];
  323. const static_ltree2_second_part = extractArray([[144, 8], [112, 9], [24, 7], [8, 8]]);
  324. StaticTree.static_ltree = flatArray(static_ltree2_first_part.map((value, index) => [value, static_ltree2_second_part[index]]));
  325. const static_dtree_first_part = [0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14, 30, 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23];
  326. const static_dtree_second_part = extractArray([[30, 5]]);
  327. StaticTree.static_dtree = flatArray(static_dtree_first_part.map((value, index) => [value, static_dtree_second_part[index]]));
  328. StaticTree.static_l_desc = new StaticTree(StaticTree.static_ltree, Tree.extra_lbits, LITERALS + 1, L_CODES, MAX_BITS$1);
  329. StaticTree.static_d_desc = new StaticTree(StaticTree.static_dtree, Tree.extra_dbits, 0, D_CODES, MAX_BITS$1);
  330. StaticTree.static_bl_desc = new StaticTree(null, Tree.extra_blbits, 0, BL_CODES, MAX_BL_BITS);
  331. // Deflate
  332. const MAX_MEM_LEVEL = 9;
  333. const DEF_MEM_LEVEL = 8;
  334. function Config(good_length, max_lazy, nice_length, max_chain, func) {
  335. const that = this;
  336. that.good_length = good_length;
  337. that.max_lazy = max_lazy;
  338. that.nice_length = nice_length;
  339. that.max_chain = max_chain;
  340. that.func = func;
  341. }
  342. const STORED$1 = 0;
  343. const FAST = 1;
  344. const SLOW = 2;
  345. const config_table = [
  346. new Config(0, 0, 0, 0, STORED$1),
  347. new Config(4, 4, 8, 4, FAST),
  348. new Config(4, 5, 16, 8, FAST),
  349. new Config(4, 6, 32, 32, FAST),
  350. new Config(4, 4, 16, 16, SLOW),
  351. new Config(8, 16, 32, 32, SLOW),
  352. new Config(8, 16, 128, 128, SLOW),
  353. new Config(8, 32, 128, 256, SLOW),
  354. new Config(32, 128, 258, 1024, SLOW),
  355. new Config(32, 258, 258, 4096, SLOW)
  356. ];
  357. const z_errmsg = ["need dictionary", // Z_NEED_DICT
  358. // 2
  359. "stream end", // Z_STREAM_END 1
  360. "", // Z_OK 0
  361. "", // Z_ERRNO (-1)
  362. "stream error", // Z_STREAM_ERROR (-2)
  363. "data error", // Z_DATA_ERROR (-3)
  364. "", // Z_MEM_ERROR (-4)
  365. "buffer error", // Z_BUF_ERROR (-5)
  366. "",// Z_VERSION_ERROR (-6)
  367. ""];
  368. // block not completed, need more input or more output
  369. const NeedMore = 0;
  370. // block flush performed
  371. const BlockDone = 1;
  372. // finish started, need only more output at next deflate
  373. const FinishStarted = 2;
  374. // finish done, accept no more input or output
  375. const FinishDone = 3;
  376. // preset dictionary flag in zlib header
  377. const PRESET_DICT$1 = 0x20;
  378. const INIT_STATE = 42;
  379. const BUSY_STATE = 113;
  380. const FINISH_STATE = 666;
  381. // The deflate compression method
  382. const Z_DEFLATED$1 = 8;
  383. const STORED_BLOCK = 0;
  384. const STATIC_TREES = 1;
  385. const DYN_TREES = 2;
  386. const MIN_MATCH = 3;
  387. const MAX_MATCH = 258;
  388. const MIN_LOOKAHEAD = (MAX_MATCH + MIN_MATCH + 1);
  389. function smaller(tree, n, m, depth) {
  390. const tn2 = tree[n * 2];
  391. const tm2 = tree[m * 2];
  392. return (tn2 < tm2 || (tn2 == tm2 && depth[n] <= depth[m]));
  393. }
  394. function Deflate$1() {
  395. const that = this;
  396. let strm; // pointer back to this zlib stream
  397. let status; // as the name implies
  398. // pending_buf; // output still pending
  399. let pending_buf_size; // size of pending_buf
  400. // pending_out; // next pending byte to output to the stream
  401. // pending; // nb of bytes in the pending buffer
  402. // dist_buf; // buffer for distances
  403. // lc_buf; // buffer for literals or lengths
  404. // To simplify the code, dist_buf and lc_buf have the same number of elements.
  405. // To use different lengths, an extra flag array would be necessary.
  406. let last_flush; // value of flush param for previous deflate call
  407. let w_size; // LZ77 win size (32K by default)
  408. let w_bits; // log2(w_size) (8..16)
  409. let w_mask; // w_size - 1
  410. let win;
  411. // Sliding win. Input bytes are read into the second half of the win,
  412. // and move to the first half later to keep a dictionary of at least wSize
  413. // bytes. With this organization, matches are limited to a distance of
  414. // wSize-MAX_MATCH bytes, but this ensures that IO is always
  415. // performed with a length multiple of the block size. Also, it limits
  416. // the win size to 64K, which is quite useful on MSDOS.
  417. // To do: use the user input buffer as sliding win.
  418. let window_size;
  419. // Actual size of win: 2*wSize, except when the user input buffer
  420. // is directly used as sliding win.
  421. let prev;
  422. // Link to older string with same hash index. To limit the size of this
  423. // array to 64K, this link is maintained only for the last 32K strings.
  424. // An index in this array is thus a win index modulo 32K.
  425. let head; // Heads of the hash chains or NIL.
  426. let ins_h; // hash index of string to be inserted
  427. let hash_size; // number of elements in hash table
  428. let hash_bits; // log2(hash_size)
  429. let hash_mask; // hash_size-1
  430. // Number of bits by which ins_h must be shifted at each input
  431. // step. It must be such that after MIN_MATCH steps, the oldest
  432. // byte no longer takes part in the hash key, that is:
  433. // hash_shift * MIN_MATCH >= hash_bits
  434. let hash_shift;
  435. // Window position at the beginning of the current output block. Gets
  436. // negative when the win is moved backwards.
  437. let block_start;
  438. let match_length; // length of best match
  439. let prev_match; // previous match
  440. let match_available; // set if previous match exists
  441. let strstart; // start of string to insert
  442. let match_start; // start of matching string
  443. let lookahead; // number of valid bytes ahead in win
  444. // Length of the best match at previous step. Matches not greater than this
  445. // are discarded. This is used in the lazy match evaluation.
  446. let prev_length;
  447. // To speed up deflation, hash chains are never searched beyond this
  448. // length. A higher limit improves compression ratio but degrades the speed.
  449. let max_chain_length;
  450. // Attempt to find a better match only when the current match is strictly
  451. // smaller than this value. This mechanism is used only for compression
  452. // levels >= 4.
  453. let max_lazy_match;
  454. // Insert new strings in the hash table only if the match length is not
  455. // greater than this length. This saves time but degrades compression.
  456. // max_insert_length is used only for compression levels <= 3.
  457. let level; // compression level (1..9)
  458. let strategy; // favor or force Huffman coding
  459. // Use a faster search when the previous match is longer than this
  460. let good_match;
  461. // Stop searching when current match exceeds this
  462. let nice_match;
  463. let dyn_ltree; // literal and length tree
  464. let dyn_dtree; // distance tree
  465. let bl_tree; // Huffman tree for bit lengths
  466. const l_desc = new Tree(); // desc for literal tree
  467. const d_desc = new Tree(); // desc for distance tree
  468. const bl_desc = new Tree(); // desc for bit length tree
  469. // that.heap_len; // number of elements in the heap
  470. // that.heap_max; // element of largest frequency
  471. // The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
  472. // The same heap array is used to build all trees.
  473. // Depth of each subtree used as tie breaker for trees of equal frequency
  474. that.depth = [];
  475. // Size of match buffer for literals/lengths. There are 4 reasons for
  476. // limiting lit_bufsize to 64K:
  477. // - frequencies can be kept in 16 bit counters
  478. // - if compression is not successful for the first block, all input
  479. // data is still in the win so we can still emit a stored block even
  480. // when input comes from standard input. (This can also be done for
  481. // all blocks if lit_bufsize is not greater than 32K.)
  482. // - if compression is not successful for a file smaller than 64K, we can
  483. // even emit a stored file instead of a stored block (saving 5 bytes).
  484. // This is applicable only for zip (not gzip or zlib).
  485. // - creating new Huffman trees less frequently may not provide fast
  486. // adaptation to changes in the input data statistics. (Take for
  487. // example a binary file with poorly compressible code followed by
  488. // a highly compressible string table.) Smaller buffer sizes give
  489. // fast adaptation but have of course the overhead of transmitting
  490. // trees more frequently.
  491. // - I can't count above 4
  492. let lit_bufsize;
  493. let last_lit; // running index in dist_buf and lc_buf
  494. // that.opt_len; // bit length of current block with optimal trees
  495. // that.static_len; // bit length of current block with static trees
  496. let matches; // number of string matches in current block
  497. let last_eob_len; // bit length of EOB code for last block
  498. // Output buffer. bits are inserted starting at the bottom (least
  499. // significant bits).
  500. let bi_buf;
  501. // Number of valid bits in bi_buf. All bits above the last valid bit
  502. // are always zero.
  503. let bi_valid;
  504. // number of codes at each bit length for an optimal tree
  505. that.bl_count = [];
  506. // heap used to build the Huffman trees
  507. that.heap = [];
  508. dyn_ltree = [];
  509. dyn_dtree = [];
  510. bl_tree = [];
  511. function lm_init() {
  512. window_size = 2 * w_size;
  513. head[hash_size - 1] = 0;
  514. for (let i = 0; i < hash_size - 1; i++) {
  515. head[i] = 0;
  516. }
  517. // Set the default configuration parameters:
  518. max_lazy_match = config_table[level].max_lazy;
  519. good_match = config_table[level].good_length;
  520. nice_match = config_table[level].nice_length;
  521. max_chain_length = config_table[level].max_chain;
  522. strstart = 0;
  523. block_start = 0;
  524. lookahead = 0;
  525. match_length = prev_length = MIN_MATCH - 1;
  526. match_available = 0;
  527. ins_h = 0;
  528. }
  529. function init_block() {
  530. let i;
  531. // Initialize the trees.
  532. for (i = 0; i < L_CODES; i++)
  533. dyn_ltree[i * 2] = 0;
  534. for (i = 0; i < D_CODES; i++)
  535. dyn_dtree[i * 2] = 0;
  536. for (i = 0; i < BL_CODES; i++)
  537. bl_tree[i * 2] = 0;
  538. dyn_ltree[END_BLOCK * 2] = 1;
  539. that.opt_len = that.static_len = 0;
  540. last_lit = matches = 0;
  541. }
  542. // Initialize the tree data structures for a new zlib stream.
  543. function tr_init() {
  544. l_desc.dyn_tree = dyn_ltree;
  545. l_desc.stat_desc = StaticTree.static_l_desc;
  546. d_desc.dyn_tree = dyn_dtree;
  547. d_desc.stat_desc = StaticTree.static_d_desc;
  548. bl_desc.dyn_tree = bl_tree;
  549. bl_desc.stat_desc = StaticTree.static_bl_desc;
  550. bi_buf = 0;
  551. bi_valid = 0;
  552. last_eob_len = 8; // enough lookahead for inflate
  553. // Initialize the first block of the first file:
  554. init_block();
  555. }
  556. // Restore the heap property by moving down the tree starting at node k,
  557. // exchanging a node with the smallest of its two sons if necessary,
  558. // stopping
  559. // when the heap property is re-established (each father smaller than its
  560. // two sons).
  561. that.pqdownheap = function (tree, // the tree to restore
  562. k // node to move down
  563. ) {
  564. const heap = that.heap;
  565. const v = heap[k];
  566. let j = k << 1; // left son of k
  567. while (j <= that.heap_len) {
  568. // Set j to the smallest of the two sons:
  569. if (j < that.heap_len && smaller(tree, heap[j + 1], heap[j], that.depth)) {
  570. j++;
  571. }
  572. // Exit if v is smaller than both sons
  573. if (smaller(tree, v, heap[j], that.depth))
  574. break;
  575. // Exchange v with the smallest son
  576. heap[k] = heap[j];
  577. k = j;
  578. // And continue down the tree, setting j to the left son of k
  579. j <<= 1;
  580. }
  581. heap[k] = v;
  582. };
  583. // Scan a literal or distance tree to determine the frequencies of the codes
  584. // in the bit length tree.
  585. function scan_tree(tree,// the tree to be scanned
  586. max_code // and its largest code of non zero frequency
  587. ) {
  588. let prevlen = -1; // last emitted length
  589. let curlen; // length of current code
  590. let nextlen = tree[0 * 2 + 1]; // length of next code
  591. let count = 0; // repeat count of the current code
  592. let max_count = 7; // max repeat count
  593. let min_count = 4; // min repeat count
  594. if (nextlen === 0) {
  595. max_count = 138;
  596. min_count = 3;
  597. }
  598. tree[(max_code + 1) * 2 + 1] = 0xffff; // guard
  599. for (let n = 0; n <= max_code; n++) {
  600. curlen = nextlen;
  601. nextlen = tree[(n + 1) * 2 + 1];
  602. if (++count < max_count && curlen == nextlen) {
  603. continue;
  604. } else if (count < min_count) {
  605. bl_tree[curlen * 2] += count;
  606. } else if (curlen !== 0) {
  607. if (curlen != prevlen)
  608. bl_tree[curlen * 2]++;
  609. bl_tree[REP_3_6 * 2]++;
  610. } else if (count <= 10) {
  611. bl_tree[REPZ_3_10 * 2]++;
  612. } else {
  613. bl_tree[REPZ_11_138 * 2]++;
  614. }
  615. count = 0;
  616. prevlen = curlen;
  617. if (nextlen === 0) {
  618. max_count = 138;
  619. min_count = 3;
  620. } else if (curlen == nextlen) {
  621. max_count = 6;
  622. min_count = 3;
  623. } else {
  624. max_count = 7;
  625. min_count = 4;
  626. }
  627. }
  628. }
  629. // Construct the Huffman tree for the bit lengths and return the index in
  630. // bl_order of the last bit length code to send.
  631. function build_bl_tree() {
  632. let max_blindex; // index of last bit length code of non zero freq
  633. // Determine the bit length frequencies for literal and distance trees
  634. scan_tree(dyn_ltree, l_desc.max_code);
  635. scan_tree(dyn_dtree, d_desc.max_code);
  636. // Build the bit length tree:
  637. bl_desc.build_tree(that);
  638. // opt_len now includes the length of the tree representations, except
  639. // the lengths of the bit lengths codes and the 5+5+4 bits for the
  640. // counts.
  641. // Determine the number of bit length codes to send. The pkzip format
  642. // requires that at least 4 bit length codes be sent. (appnote.txt says
  643. // 3 but the actual value used is 4.)
  644. for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {
  645. if (bl_tree[Tree.bl_order[max_blindex] * 2 + 1] !== 0)
  646. break;
  647. }
  648. // Update opt_len to include the bit length tree and counts
  649. that.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
  650. return max_blindex;
  651. }
  652. // Output a byte on the stream.
  653. // IN assertion: there is enough room in pending_buf.
  654. function put_byte(p) {
  655. that.pending_buf[that.pending++] = p;
  656. }
  657. function put_short(w) {
  658. put_byte(w & 0xff);
  659. put_byte((w >>> 8) & 0xff);
  660. }
  661. function putShortMSB(b) {
  662. put_byte((b >> 8) & 0xff);
  663. put_byte((b & 0xff) & 0xff);
  664. }
  665. function send_bits(value, length) {
  666. let val;
  667. const len = length;
  668. if (bi_valid > Buf_size - len) {
  669. val = value;
  670. // bi_buf |= (val << bi_valid);
  671. bi_buf |= ((val << bi_valid) & 0xffff);
  672. put_short(bi_buf);
  673. bi_buf = val >>> (Buf_size - bi_valid);
  674. bi_valid += len - Buf_size;
  675. } else {
  676. // bi_buf |= (value) << bi_valid;
  677. bi_buf |= (((value) << bi_valid) & 0xffff);
  678. bi_valid += len;
  679. }
  680. }
  681. function send_code(c, tree) {
  682. const c2 = c * 2;
  683. send_bits(tree[c2] & 0xffff, tree[c2 + 1] & 0xffff);
  684. }
  685. // Send a literal or distance tree in compressed form, using the codes in
  686. // bl_tree.
  687. function send_tree(tree,// the tree to be sent
  688. max_code // and its largest code of non zero frequency
  689. ) {
  690. let n; // iterates over all tree elements
  691. let prevlen = -1; // last emitted length
  692. let curlen; // length of current code
  693. let nextlen = tree[0 * 2 + 1]; // length of next code
  694. let count = 0; // repeat count of the current code
  695. let max_count = 7; // max repeat count
  696. let min_count = 4; // min repeat count
  697. if (nextlen === 0) {
  698. max_count = 138;
  699. min_count = 3;
  700. }
  701. for (n = 0; n <= max_code; n++) {
  702. curlen = nextlen;
  703. nextlen = tree[(n + 1) * 2 + 1];
  704. if (++count < max_count && curlen == nextlen) {
  705. continue;
  706. } else if (count < min_count) {
  707. do {
  708. send_code(curlen, bl_tree);
  709. } while (--count !== 0);
  710. } else if (curlen !== 0) {
  711. if (curlen != prevlen) {
  712. send_code(curlen, bl_tree);
  713. count--;
  714. }
  715. send_code(REP_3_6, bl_tree);
  716. send_bits(count - 3, 2);
  717. } else if (count <= 10) {
  718. send_code(REPZ_3_10, bl_tree);
  719. send_bits(count - 3, 3);
  720. } else {
  721. send_code(REPZ_11_138, bl_tree);
  722. send_bits(count - 11, 7);
  723. }
  724. count = 0;
  725. prevlen = curlen;
  726. if (nextlen === 0) {
  727. max_count = 138;
  728. min_count = 3;
  729. } else if (curlen == nextlen) {
  730. max_count = 6;
  731. min_count = 3;
  732. } else {
  733. max_count = 7;
  734. min_count = 4;
  735. }
  736. }
  737. }
  738. // Send the header for a block using dynamic Huffman trees: the counts, the
  739. // lengths of the bit length codes, the literal tree and the distance tree.
  740. // IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
  741. function send_all_trees(lcodes, dcodes, blcodes) {
  742. let rank; // index in bl_order
  743. send_bits(lcodes - 257, 5); // not +255 as stated in appnote.txt
  744. send_bits(dcodes - 1, 5);
  745. send_bits(blcodes - 4, 4); // not -3 as stated in appnote.txt
  746. for (rank = 0; rank < blcodes; rank++) {
  747. send_bits(bl_tree[Tree.bl_order[rank] * 2 + 1], 3);
  748. }
  749. send_tree(dyn_ltree, lcodes - 1); // literal tree
  750. send_tree(dyn_dtree, dcodes - 1); // distance tree
  751. }
  752. // Flush the bit buffer, keeping at most 7 bits in it.
  753. function bi_flush() {
  754. if (bi_valid == 16) {
  755. put_short(bi_buf);
  756. bi_buf = 0;
  757. bi_valid = 0;
  758. } else if (bi_valid >= 8) {
  759. put_byte(bi_buf & 0xff);
  760. bi_buf >>>= 8;
  761. bi_valid -= 8;
  762. }
  763. }
  764. // Send one empty static block to give enough lookahead for inflate.
  765. // This takes 10 bits, of which 7 may remain in the bit buffer.
  766. // The current inflate code requires 9 bits of lookahead. If the
  767. // last two codes for the previous block (real code plus EOB) were coded
  768. // on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
  769. // the last real code. In this case we send two empty static blocks instead
  770. // of one. (There are no problems if the previous block is stored or fixed.)
  771. // To simplify the code, we assume the worst case of last real code encoded
  772. // on one bit only.
  773. function _tr_align() {
  774. send_bits(STATIC_TREES << 1, 3);
  775. send_code(END_BLOCK, StaticTree.static_ltree);
  776. bi_flush();
  777. // Of the 10 bits for the empty block, we have already sent
  778. // (10 - bi_valid) bits. The lookahead for the last real code (before
  779. // the EOB of the previous block) was thus at least one plus the length
  780. // of the EOB plus what we have just sent of the empty static block.
  781. if (1 + last_eob_len + 10 - bi_valid < 9) {
  782. send_bits(STATIC_TREES << 1, 3);
  783. send_code(END_BLOCK, StaticTree.static_ltree);
  784. bi_flush();
  785. }
  786. last_eob_len = 7;
  787. }
  788. // Save the match info and tally the frequency counts. Return true if
  789. // the current block must be flushed.
  790. function _tr_tally(dist, // distance of matched string
  791. lc // match length-MIN_MATCH or unmatched char (if dist==0)
  792. ) {
  793. let out_length, in_length, dcode;
  794. that.dist_buf[last_lit] = dist;
  795. that.lc_buf[last_lit] = lc & 0xff;
  796. last_lit++;
  797. if (dist === 0) {
  798. // lc is the unmatched char
  799. dyn_ltree[lc * 2]++;
  800. } else {
  801. matches++;
  802. // Here, lc is the match length - MIN_MATCH
  803. dist--; // dist = match distance - 1
  804. dyn_ltree[(Tree._length_code[lc] + LITERALS + 1) * 2]++;
  805. dyn_dtree[Tree.d_code(dist) * 2]++;
  806. }
  807. if ((last_lit & 0x1fff) === 0 && level > 2) {
  808. // Compute an upper bound for the compressed length
  809. out_length = last_lit * 8;
  810. in_length = strstart - block_start;
  811. for (dcode = 0; dcode < D_CODES; dcode++) {
  812. out_length += dyn_dtree[dcode * 2] * (5 + Tree.extra_dbits[dcode]);
  813. }
  814. out_length >>>= 3;
  815. if ((matches < Math.floor(last_lit / 2)) && out_length < Math.floor(in_length / 2))
  816. return true;
  817. }
  818. return (last_lit == lit_bufsize - 1);
  819. // We avoid equality with lit_bufsize because of wraparound at 64K
  820. // on 16 bit machines and because stored blocks are restricted to
  821. // 64K-1 bytes.
  822. }
  823. // Send the block data compressed using the given Huffman trees
  824. function compress_block(ltree, dtree) {
  825. let dist; // distance of matched string
  826. let lc; // match length or unmatched char (if dist === 0)
  827. let lx = 0; // running index in dist_buf and lc_buf
  828. let code; // the code to send
  829. let extra; // number of extra bits to send
  830. if (last_lit !== 0) {
  831. do {
  832. dist = that.dist_buf[lx];
  833. lc = that.lc_buf[lx];
  834. lx++;
  835. if (dist === 0) {
  836. send_code(lc, ltree); // send a literal byte
  837. } else {
  838. // Here, lc is the match length - MIN_MATCH
  839. code = Tree._length_code[lc];
  840. send_code(code + LITERALS + 1, ltree); // send the length
  841. // code
  842. extra = Tree.extra_lbits[code];
  843. if (extra !== 0) {
  844. lc -= Tree.base_length[code];
  845. send_bits(lc, extra); // send the extra length bits
  846. }
  847. dist--; // dist is now the match distance - 1
  848. code = Tree.d_code(dist);
  849. send_code(code, dtree); // send the distance code
  850. extra = Tree.extra_dbits[code];
  851. if (extra !== 0) {
  852. dist -= Tree.base_dist[code];
  853. send_bits(dist, extra); // send the extra distance bits
  854. }
  855. } // literal or match pair ?
  856. } while (lx < last_lit);
  857. }
  858. send_code(END_BLOCK, ltree);
  859. last_eob_len = ltree[END_BLOCK * 2 + 1];
  860. }
  861. // Flush the bit buffer and align the output on a byte boundary
  862. function bi_windup() {
  863. if (bi_valid > 8) {
  864. put_short(bi_buf);
  865. } else if (bi_valid > 0) {
  866. put_byte(bi_buf & 0xff);
  867. }
  868. bi_buf = 0;
  869. bi_valid = 0;
  870. }
  871. // Copy a stored block, storing first the length and its
  872. // one's complement if requested.
  873. function copy_block(buf, // the input data
  874. len, // its length
  875. header // true if block header must be written
  876. ) {
  877. bi_windup(); // align on byte boundary
  878. last_eob_len = 8; // enough lookahead for inflate
  879. if (header) {
  880. put_short(len);
  881. put_short(~len);
  882. }
  883. that.pending_buf.set(win.subarray(buf, buf + len), that.pending);
  884. that.pending += len;
  885. }
  886. // Send a stored block
  887. function _tr_stored_block(buf, // input block
  888. stored_len, // length of input block
  889. eof // true if this is the last block for a file
  890. ) {
  891. send_bits((STORED_BLOCK << 1) + (eof ? 1 : 0), 3); // send block type
  892. copy_block(buf, stored_len, true); // with header
  893. }
  894. // Determine the best encoding for the current block: dynamic trees, static
  895. // trees or store, and output the encoded block to the zip file.
  896. function _tr_flush_block(buf, // input block, or NULL if too old
  897. stored_len, // length of input block
  898. eof // true if this is the last block for a file
  899. ) {
  900. let opt_lenb, static_lenb;// opt_len and static_len in bytes
  901. let max_blindex = 0; // index of last bit length code of non zero freq
  902. // Build the Huffman trees unless a stored block is forced
  903. if (level > 0) {
  904. // Construct the literal and distance trees
  905. l_desc.build_tree(that);
  906. d_desc.build_tree(that);
  907. // At this point, opt_len and static_len are the total bit lengths
  908. // of
  909. // the compressed block data, excluding the tree representations.
  910. // Build the bit length tree for the above two trees, and get the
  911. // index
  912. // in bl_order of the last bit length code to send.
  913. max_blindex = build_bl_tree();
  914. // Determine the best encoding. Compute first the block length in
  915. // bytes
  916. opt_lenb = (that.opt_len + 3 + 7) >>> 3;
  917. static_lenb = (that.static_len + 3 + 7) >>> 3;
  918. if (static_lenb <= opt_lenb)
  919. opt_lenb = static_lenb;
  920. } else {
  921. opt_lenb = static_lenb = stored_len + 5; // force a stored block
  922. }
  923. if ((stored_len + 4 <= opt_lenb) && buf != -1) {
  924. // 4: two words for the lengths
  925. // The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
  926. // Otherwise we can't have processed more than WSIZE input bytes
  927. // since
  928. // the last block flush, because compression would have been
  929. // successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
  930. // transform a block into a stored block.
  931. _tr_stored_block(buf, stored_len, eof);
  932. } else if (static_lenb == opt_lenb) {
  933. send_bits((STATIC_TREES << 1) + (eof ? 1 : 0), 3);
  934. compress_block(StaticTree.static_ltree, StaticTree.static_dtree);
  935. } else {
  936. send_bits((DYN_TREES << 1) + (eof ? 1 : 0), 3);
  937. send_all_trees(l_desc.max_code + 1, d_desc.max_code + 1, max_blindex + 1);
  938. compress_block(dyn_ltree, dyn_dtree);
  939. }
  940. // The above check is made mod 2^32, for files larger than 512 MB
  941. // and uLong implemented on 32 bits.
  942. init_block();
  943. if (eof) {
  944. bi_windup();
  945. }
  946. }
  947. function flush_block_only(eof) {
  948. _tr_flush_block(block_start >= 0 ? block_start : -1, strstart - block_start, eof);
  949. block_start = strstart;
  950. strm.flush_pending();
  951. }
  952. // Fill the win when the lookahead becomes insufficient.
  953. // Updates strstart and lookahead.
  954. //
  955. // IN assertion: lookahead < MIN_LOOKAHEAD
  956. // OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
  957. // At least one byte has been read, or avail_in === 0; reads are
  958. // performed for at least two bytes (required for the zip translate_eol
  959. // option -- not supported here).
  960. function fill_window() {
  961. let n, m;
  962. let p;
  963. let more; // Amount of free space at the end of the win.
  964. do {
  965. more = (window_size - lookahead - strstart);
  966. // Deal with !@#$% 64K limit:
  967. if (more === 0 && strstart === 0 && lookahead === 0) {
  968. more = w_size;
  969. } else if (more == -1) {
  970. // Very unlikely, but possible on 16 bit machine if strstart ==
  971. // 0
  972. // and lookahead == 1 (input done one byte at time)
  973. more--;
  974. // If the win is almost full and there is insufficient
  975. // lookahead,
  976. // move the upper half to the lower one to make room in the
  977. // upper half.
  978. } else if (strstart >= w_size + w_size - MIN_LOOKAHEAD) {
  979. win.set(win.subarray(w_size, w_size + w_size), 0);
  980. match_start -= w_size;
  981. strstart -= w_size; // we now have strstart >= MAX_DIST
  982. block_start -= w_size;
  983. // Slide the hash table (could be avoided with 32 bit values
  984. // at the expense of memory usage). We slide even when level ==
  985. // 0
  986. // to keep the hash table consistent if we switch back to level
  987. // > 0
  988. // later. (Using level 0 permanently is not an optimal usage of
  989. // zlib, so we don't care about this pathological case.)
  990. n = hash_size;
  991. p = n;
  992. do {
  993. m = (head[--p] & 0xffff);
  994. head[p] = (m >= w_size ? m - w_size : 0);
  995. } while (--n !== 0);
  996. n = w_size;
  997. p = n;
  998. do {
  999. m = (prev[--p] & 0xffff);
  1000. prev[p] = (m >= w_size ? m - w_size : 0);
  1001. // If n is not on any hash chain, prev[n] is garbage but
  1002. // its value will never be used.
  1003. } while (--n !== 0);
  1004. more += w_size;
  1005. }
  1006. if (strm.avail_in === 0)
  1007. return;
  1008. // If there was no sliding:
  1009. // strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
  1010. // more == window_size - lookahead - strstart
  1011. // => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
  1012. // => more >= window_size - 2*WSIZE + 2
  1013. // In the BIG_MEM or MMAP case (not yet supported),
  1014. // window_size == input_size + MIN_LOOKAHEAD &&
  1015. // strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
  1016. // Otherwise, window_size == 2*WSIZE so more >= 2.
  1017. // If there was sliding, more >= WSIZE. So in all cases, more >= 2.
  1018. n = strm.read_buf(win, strstart + lookahead, more);
  1019. lookahead += n;
  1020. // Initialize the hash value now that we have some input:
  1021. if (lookahead >= MIN_MATCH) {
  1022. ins_h = win[strstart] & 0xff;
  1023. ins_h = (((ins_h) << hash_shift) ^ (win[strstart + 1] & 0xff)) & hash_mask;
  1024. }
  1025. // If the whole input has less than MIN_MATCH bytes, ins_h is
  1026. // garbage,
  1027. // but this is not important since only literal bytes will be
  1028. // emitted.
  1029. } while (lookahead < MIN_LOOKAHEAD && strm.avail_in !== 0);
  1030. }
  1031. // Copy without compression as much as possible from the input stream,
  1032. // return
  1033. // the current block state.
  1034. // This function does not insert new strings in the dictionary since
  1035. // uncompressible data is probably not useful. This function is used
  1036. // only for the level=0 compression option.
  1037. // NOTE: this function should be optimized to avoid extra copying from
  1038. // win to pending_buf.
  1039. function deflate_stored(flush) {
  1040. // Stored blocks are limited to 0xffff bytes, pending_buf is limited
  1041. // to pending_buf_size, and each stored block has a 5 byte header:
  1042. let max_block_size = 0xffff;
  1043. let max_start;
  1044. if (max_block_size > pending_buf_size - 5) {
  1045. max_block_size = pending_buf_size - 5;
  1046. }
  1047. // Copy as much as possible from input to output:
  1048. // eslint-disable-next-line no-constant-condition
  1049. while (true) {
  1050. // Fill the win as much as possible:
  1051. if (lookahead <= 1) {
  1052. fill_window();
  1053. if (lookahead === 0 && flush == Z_NO_FLUSH$1)
  1054. return NeedMore;
  1055. if (lookahead === 0)
  1056. break; // flush the current block
  1057. }
  1058. strstart += lookahead;
  1059. lookahead = 0;
  1060. // Emit a stored block if pending_buf will be full:
  1061. max_start = block_start + max_block_size;
  1062. if (strstart === 0 || strstart >= max_start) {
  1063. // strstart === 0 is possible when wraparound on 16-bit machine
  1064. lookahead = (strstart - max_start);
  1065. strstart = max_start;
  1066. flush_block_only(false);
  1067. if (strm.avail_out === 0)
  1068. return NeedMore;
  1069. }
  1070. // Flush if we may have to slide, otherwise block_start may become
  1071. // negative and the data will be gone:
  1072. if (strstart - block_start >= w_size - MIN_LOOKAHEAD) {
  1073. flush_block_only(false);
  1074. if (strm.avail_out === 0)
  1075. return NeedMore;
  1076. }
  1077. }
  1078. flush_block_only(flush == Z_FINISH$1);
  1079. if (strm.avail_out === 0)
  1080. return (flush == Z_FINISH$1) ? FinishStarted : NeedMore;
  1081. return flush == Z_FINISH$1 ? FinishDone : BlockDone;
  1082. }
  1083. function longest_match(cur_match) {
  1084. let chain_length = max_chain_length; // max hash chain length
  1085. let scan = strstart; // current string
  1086. let match; // matched string
  1087. let len; // length of current match
  1088. let best_len = prev_length; // best match length so far
  1089. const limit = strstart > (w_size - MIN_LOOKAHEAD) ? strstart - (w_size - MIN_LOOKAHEAD) : 0;
  1090. let _nice_match = nice_match;
  1091. // Stop when cur_match becomes <= limit. To simplify the code,
  1092. // we prevent matches with the string of win index 0.
  1093. const wmask = w_mask;
  1094. const strend = strstart + MAX_MATCH;
  1095. let scan_end1 = win[scan + best_len - 1];
  1096. let scan_end = win[scan + best_len];
  1097. // The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of
  1098. // 16.
  1099. // It is easy to get rid of this optimization if necessary.
  1100. // Do not waste too much time if we already have a good match:
  1101. if (prev_length >= good_match) {
  1102. chain_length >>= 2;
  1103. }
  1104. // Do not look for matches beyond the end of the input. This is
  1105. // necessary
  1106. // to make deflate deterministic.
  1107. if (_nice_match > lookahead)
  1108. _nice_match = lookahead;
  1109. do {
  1110. match = cur_match;
  1111. // Skip to next match if the match length cannot increase
  1112. // or if the match length is less than 2:
  1113. if (win[match + best_len] != scan_end || win[match + best_len - 1] != scan_end1 || win[match] != win[scan]
  1114. || win[++match] != win[scan + 1])
  1115. continue;
  1116. // The check at best_len-1 can be removed because it will be made
  1117. // again later. (This heuristic is not always a win.)
  1118. // It is not necessary to compare scan[2] and match[2] since they
  1119. // are always equal when the other bytes match, given that
  1120. // the hash keys are equal and that HASH_BITS >= 8.
  1121. scan += 2;
  1122. match++;
  1123. // We check for insufficient lookahead only every 8th comparison;
  1124. // the 256th check will be made at strstart+258.
  1125. // eslint-disable-next-line no-empty
  1126. do {
  1127. // empty block
  1128. } while (win[++scan] == win[++match] && win[++scan] == win[++match] && win[++scan] == win[++match]
  1129. && win[++scan] == win[++match] && win[++scan] == win[++match] && win[++scan] == win[++match]
  1130. && win[++scan] == win[++match] && win[++scan] == win[++match] && scan < strend);
  1131. len = MAX_MATCH - (strend - scan);
  1132. scan = strend - MAX_MATCH;
  1133. if (len > best_len) {
  1134. match_start = cur_match;
  1135. best_len = len;
  1136. if (len >= _nice_match)
  1137. break;
  1138. scan_end1 = win[scan + best_len - 1];
  1139. scan_end = win[scan + best_len];
  1140. }
  1141. } while ((cur_match = (prev[cur_match & wmask] & 0xffff)) > limit && --chain_length !== 0);
  1142. if (best_len <= lookahead)
  1143. return best_len;
  1144. return lookahead;
  1145. }
  1146. // Compress as much as possible from the input stream, return the current
  1147. // block state.
  1148. // This function does not perform lazy evaluation of matches and inserts
  1149. // new strings in the dictionary only for unmatched strings or for short
  1150. // matches. It is used only for the fast compression options.
  1151. function deflate_fast(flush) {
  1152. // short hash_head = 0; // head of the hash chain
  1153. let hash_head = 0; // head of the hash chain
  1154. let bflush; // set if current block must be flushed
  1155. // eslint-disable-next-line no-constant-condition
  1156. while (true) {
  1157. // Make sure that we always have enough lookahead, except
  1158. // at the end of the input file. We need MAX_MATCH bytes
  1159. // for the next match, plus MIN_MATCH bytes to insert the
  1160. // string following the next match.
  1161. if (lookahead < MIN_LOOKAHEAD) {
  1162. fill_window();
  1163. if (lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH$1) {
  1164. return NeedMore;
  1165. }
  1166. if (lookahead === 0)
  1167. break; // flush the current block
  1168. }
  1169. // Insert the string win[strstart .. strstart+2] in the
  1170. // dictionary, and set hash_head to the head of the hash chain:
  1171. if (lookahead >= MIN_MATCH) {
  1172. ins_h = (((ins_h) << hash_shift) ^ (win[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
  1173. // prev[strstart&w_mask]=hash_head=head[ins_h];
  1174. hash_head = (head[ins_h] & 0xffff);
  1175. prev[strstart & w_mask] = head[ins_h];
  1176. head[ins_h] = strstart;
  1177. }
  1178. // Find the longest match, discarding those <= prev_length.
  1179. // At this point we have always match_length < MIN_MATCH
  1180. if (hash_head !== 0 && ((strstart - hash_head) & 0xffff) <= w_size - MIN_LOOKAHEAD) {
  1181. // To simplify the code, we prevent matches with the string
  1182. // of win index 0 (in particular we have to avoid a match
  1183. // of the string with itself at the start of the input file).
  1184. if (strategy != Z_HUFFMAN_ONLY) {
  1185. match_length = longest_match(hash_head);
  1186. }
  1187. // longest_match() sets match_start
  1188. }
  1189. if (match_length >= MIN_MATCH) {
  1190. // check_match(strstart, match_start, match_length);
  1191. bflush = _tr_tally(strstart - match_start, match_length - MIN_MATCH);
  1192. lookahead -= match_length;
  1193. // Insert new strings in the hash table only if the match length
  1194. // is not too large. This saves time but degrades compression.
  1195. if (match_length <= max_lazy_match && lookahead >= MIN_MATCH) {
  1196. match_length--; // string at strstart already in hash table
  1197. do {
  1198. strstart++;
  1199. ins_h = ((ins_h << hash_shift) ^ (win[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
  1200. // prev[strstart&w_mask]=hash_head=head[ins_h];
  1201. hash_head = (head[ins_h] & 0xffff);
  1202. prev[strstart & w_mask] = head[ins_h];
  1203. head[ins_h] = strstart;
  1204. // strstart never exceeds WSIZE-MAX_MATCH, so there are
  1205. // always MIN_MATCH bytes ahead.
  1206. } while (--match_length !== 0);
  1207. strstart++;
  1208. } else {
  1209. strstart += match_length;
  1210. match_length = 0;
  1211. ins_h = win[strstart] & 0xff;
  1212. ins_h = (((ins_h) << hash_shift) ^ (win[strstart + 1] & 0xff)) & hash_mask;
  1213. // If lookahead < MIN_MATCH, ins_h is garbage, but it does
  1214. // not
  1215. // matter since it will be recomputed at next deflate call.
  1216. }
  1217. } else {
  1218. // No match, output a literal byte
  1219. bflush = _tr_tally(0, win[strstart] & 0xff);
  1220. lookahead--;
  1221. strstart++;
  1222. }
  1223. if (bflush) {
  1224. flush_block_only(false);
  1225. if (strm.avail_out === 0)
  1226. return NeedMore;
  1227. }
  1228. }
  1229. flush_block_only(flush == Z_FINISH$1);
  1230. if (strm.avail_out === 0) {
  1231. if (flush == Z_FINISH$1)
  1232. return FinishStarted;
  1233. else
  1234. return NeedMore;
  1235. }
  1236. return flush == Z_FINISH$1 ? FinishDone : BlockDone;
  1237. }
  1238. // Same as above, but achieves better compression. We use a lazy
  1239. // evaluation for matches: a match is finally adopted only if there is
  1240. // no better match at the next win position.
  1241. function deflate_slow(flush) {
  1242. // short hash_head = 0; // head of hash chain
  1243. let hash_head = 0; // head of hash chain
  1244. let bflush; // set if current block must be flushed
  1245. let max_insert;
  1246. // Process the input block.
  1247. // eslint-disable-next-line no-constant-condition
  1248. while (true) {
  1249. // Make sure that we always have enough lookahead, except
  1250. // at the end of the input file. We need MAX_MATCH bytes
  1251. // for the next match, plus MIN_MATCH bytes to insert the
  1252. // string following the next match.
  1253. if (lookahead < MIN_LOOKAHEAD) {
  1254. fill_window();
  1255. if (lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH$1) {
  1256. return NeedMore;
  1257. }
  1258. if (lookahead === 0)
  1259. break; // flush the current block
  1260. }
  1261. // Insert the string win[strstart .. strstart+2] in the
  1262. // dictionary, and set hash_head to the head of the hash chain:
  1263. if (lookahead >= MIN_MATCH) {
  1264. ins_h = (((ins_h) << hash_shift) ^ (win[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
  1265. // prev[strstart&w_mask]=hash_head=head[ins_h];
  1266. hash_head = (head[ins_h] & 0xffff);
  1267. prev[strstart & w_mask] = head[ins_h];
  1268. head[ins_h] = strstart;
  1269. }
  1270. // Find the longest match, discarding those <= prev_length.
  1271. prev_length = match_length;
  1272. prev_match = match_start;
  1273. match_length = MIN_MATCH - 1;
  1274. if (hash_head !== 0 && prev_length < max_lazy_match && ((strstart - hash_head) & 0xffff) <= w_size - MIN_LOOKAHEAD) {
  1275. // To simplify the code, we prevent matches with the string
  1276. // of win index 0 (in particular we have to avoid a match
  1277. // of the string with itself at the start of the input file).
  1278. if (strategy != Z_HUFFMAN_ONLY) {
  1279. match_length = longest_match(hash_head);
  1280. }
  1281. // longest_match() sets match_start
  1282. if (match_length <= 5 && (strategy == Z_FILTERED || (match_length == MIN_MATCH && strstart - match_start > 4096))) {
  1283. // If prev_match is also MIN_MATCH, match_start is garbage
  1284. // but we will ignore the current match anyway.
  1285. match_length = MIN_MATCH - 1;
  1286. }
  1287. }
  1288. // If there was a match at the previous step and the current
  1289. // match is not better, output the previous match:
  1290. if (prev_length >= MIN_MATCH && match_length <= prev_length) {
  1291. max_insert = strstart + lookahead - MIN_MATCH;
  1292. // Do not insert strings in hash table beyond this.
  1293. // check_match(strstart-1, prev_match, prev_length);
  1294. bflush = _tr_tally(strstart - 1 - prev_match, prev_length - MIN_MATCH);
  1295. // Insert in hash table all strings up to the end of the match.
  1296. // strstart-1 and strstart are already inserted. If there is not
  1297. // enough lookahead, the last two strings are not inserted in
  1298. // the hash table.
  1299. lookahead -= prev_length - 1;
  1300. prev_length -= 2;
  1301. do {
  1302. if (++strstart <= max_insert) {
  1303. ins_h = (((ins_h) << hash_shift) ^ (win[(strstart) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
  1304. // prev[strstart&w_mask]=hash_head=head[ins_h];
  1305. hash_head = (head[ins_h] & 0xffff);
  1306. prev[strstart & w_mask] = head[ins_h];
  1307. head[ins_h] = strstart;
  1308. }
  1309. } while (--prev_length !== 0);
  1310. match_available = 0;
  1311. match_length = MIN_MATCH - 1;
  1312. strstart++;
  1313. if (bflush) {
  1314. flush_block_only(false);
  1315. if (strm.avail_out === 0)
  1316. return NeedMore;
  1317. }
  1318. } else if (match_available !== 0) {
  1319. // If there was no match at the previous position, output a
  1320. // single literal. If there was a match but the current match
  1321. // is longer, truncate the previous match to a single literal.
  1322. bflush = _tr_tally(0, win[strstart - 1] & 0xff);
  1323. if (bflush) {
  1324. flush_block_only(false);
  1325. }
  1326. strstart++;
  1327. lookahead--;
  1328. if (strm.avail_out === 0)
  1329. return NeedMore;
  1330. } else {
  1331. // There is no previous match to compare with, wait for
  1332. // the next step to decide.
  1333. match_available = 1;
  1334. strstart++;
  1335. lookahead--;
  1336. }
  1337. }
  1338. if (match_available !== 0) {
  1339. bflush = _tr_tally(0, win[strstart - 1] & 0xff);
  1340. match_available = 0;
  1341. }
  1342. flush_block_only(flush == Z_FINISH$1);
  1343. if (strm.avail_out === 0) {
  1344. if (flush == Z_FINISH$1)
  1345. return FinishStarted;
  1346. else
  1347. return NeedMore;
  1348. }
  1349. return flush == Z_FINISH$1 ? FinishDone : BlockDone;
  1350. }
  1351. function deflateReset(strm) {
  1352. strm.total_in = strm.total_out = 0;
  1353. strm.msg = null; //
  1354. that.pending = 0;
  1355. that.pending_out = 0;
  1356. status = BUSY_STATE;
  1357. last_flush = Z_NO_FLUSH$1;
  1358. tr_init();
  1359. lm_init();
  1360. return Z_OK$1;
  1361. }
  1362. that.deflateInit = function (strm, _level, bits, _method, memLevel, _strategy) {
  1363. if (!_method)
  1364. _method = Z_DEFLATED$1;
  1365. if (!memLevel)
  1366. memLevel = DEF_MEM_LEVEL;
  1367. if (!_strategy)
  1368. _strategy = Z_DEFAULT_STRATEGY;
  1369. // byte[] my_version=ZLIB_VERSION;
  1370. //
  1371. // if (!version || version[0] != my_version[0]
  1372. // || stream_size != sizeof(z_stream)) {
  1373. // return Z_VERSION_ERROR;
  1374. // }
  1375. strm.msg = null;
  1376. if (_level == Z_DEFAULT_COMPRESSION)
  1377. _level = 6;
  1378. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || _method != Z_DEFLATED$1 || bits < 9 || bits > 15 || _level < 0 || _level > 9 || _strategy < 0
  1379. || _strategy > Z_HUFFMAN_ONLY) {
  1380. return Z_STREAM_ERROR$1;
  1381. }
  1382. strm.dstate = that;
  1383. w_bits = bits;
  1384. w_size = 1 << w_bits;
  1385. w_mask = w_size - 1;
  1386. hash_bits = memLevel + 7;
  1387. hash_size = 1 << hash_bits;
  1388. hash_mask = hash_size - 1;
  1389. hash_shift = Math.floor((hash_bits + MIN_MATCH - 1) / MIN_MATCH);
  1390. win = new Uint8Array(w_size * 2);
  1391. prev = [];
  1392. head = [];
  1393. lit_bufsize = 1 << (memLevel + 6); // 16K elements by default
  1394. that.pending_buf = new Uint8Array(lit_bufsize * 4);
  1395. pending_buf_size = lit_bufsize * 4;
  1396. that.dist_buf = new Uint16Array(lit_bufsize);
  1397. that.lc_buf = new Uint8Array(lit_bufsize);
  1398. level = _level;
  1399. strategy = _strategy;
  1400. return deflateReset(strm);
  1401. };
  1402. that.deflateEnd = function () {
  1403. if (status != INIT_STATE && status != BUSY_STATE && status != FINISH_STATE) {
  1404. return Z_STREAM_ERROR$1;
  1405. }
  1406. // Deallocate in reverse order of allocations:
  1407. that.lc_buf = null;
  1408. that.dist_buf = null;
  1409. that.pending_buf = null;
  1410. head = null;
  1411. prev = null;
  1412. win = null;
  1413. // free
  1414. that.dstate = null;
  1415. return status == BUSY_STATE ? Z_DATA_ERROR$1 : Z_OK$1;
  1416. };
  1417. that.deflateParams = function (strm, _level, _strategy) {
  1418. let err = Z_OK$1;
  1419. if (_level == Z_DEFAULT_COMPRESSION) {
  1420. _level = 6;
  1421. }
  1422. if (_level < 0 || _level > 9 || _strategy < 0 || _strategy > Z_HUFFMAN_ONLY) {
  1423. return Z_STREAM_ERROR$1;
  1424. }
  1425. if (config_table[level].func != config_table[_level].func && strm.total_in !== 0) {
  1426. // Flush the last buffer:
  1427. err = strm.deflate(Z_PARTIAL_FLUSH);
  1428. }
  1429. if (level != _level) {
  1430. level = _level;
  1431. max_lazy_match = config_table[level].max_lazy;
  1432. good_match = config_table[level].good_length;
  1433. nice_match = config_table[level].nice_length;
  1434. max_chain_length = config_table[level].max_chain;
  1435. }
  1436. strategy = _strategy;
  1437. return err;
  1438. };
  1439. that.deflateSetDictionary = function (_strm, dictionary, dictLength) {
  1440. let length = dictLength;
  1441. let n, index = 0;
  1442. if (!dictionary || status != INIT_STATE)
  1443. return Z_STREAM_ERROR$1;
  1444. if (length < MIN_MATCH)
  1445. return Z_OK$1;
  1446. if (length > w_size - MIN_LOOKAHEAD) {
  1447. length = w_size - MIN_LOOKAHEAD;
  1448. index = dictLength - length; // use the tail of the dictionary
  1449. }
  1450. win.set(dictionary.subarray(index, index + length), 0);
  1451. strstart = length;
  1452. block_start = length;
  1453. // Insert all strings in the hash table (except for the last two bytes).
  1454. // s->lookahead stays null, so s->ins_h will be recomputed at the next
  1455. // call of fill_window.
  1456. ins_h = win[0] & 0xff;
  1457. ins_h = (((ins_h) << hash_shift) ^ (win[1] & 0xff)) & hash_mask;
  1458. for (n = 0; n <= length - MIN_MATCH; n++) {
  1459. ins_h = (((ins_h) << hash_shift) ^ (win[(n) + (MIN_MATCH - 1)] & 0xff)) & hash_mask;
  1460. prev[n & w_mask] = head[ins_h];
  1461. head[ins_h] = n;
  1462. }
  1463. return Z_OK$1;
  1464. };
  1465. that.deflate = function (_strm, flush) {
  1466. let i, header, level_flags, old_flush, bstate;
  1467. if (flush > Z_FINISH$1 || flush < 0) {
  1468. return Z_STREAM_ERROR$1;
  1469. }
  1470. if (!_strm.next_out || (!_strm.next_in && _strm.avail_in !== 0) || (status == FINISH_STATE && flush != Z_FINISH$1)) {
  1471. _strm.msg = z_errmsg[Z_NEED_DICT$1 - (Z_STREAM_ERROR$1)];
  1472. return Z_STREAM_ERROR$1;
  1473. }
  1474. if (_strm.avail_out === 0) {
  1475. _strm.msg = z_errmsg[Z_NEED_DICT$1 - (Z_BUF_ERROR$1)];
  1476. return Z_BUF_ERROR$1;
  1477. }
  1478. strm = _strm; // just in case
  1479. old_flush = last_flush;
  1480. last_flush = flush;
  1481. // Write the zlib header
  1482. if (status == INIT_STATE) {
  1483. header = (Z_DEFLATED$1 + ((w_bits - 8) << 4)) << 8;
  1484. level_flags = ((level - 1) & 0xff) >> 1;
  1485. if (level_flags > 3)
  1486. level_flags = 3;
  1487. header |= (level_flags << 6);
  1488. if (strstart !== 0)
  1489. header |= PRESET_DICT$1;
  1490. header += 31 - (header % 31);
  1491. status = BUSY_STATE;
  1492. putShortMSB(header);
  1493. }
  1494. // Flush as much pending output as possible
  1495. if (that.pending !== 0) {
  1496. strm.flush_pending();
  1497. if (strm.avail_out === 0) {
  1498. // console.log(" avail_out==0");
  1499. // Since avail_out is 0, deflate will be called again with
  1500. // more output space, but possibly with both pending and
  1501. // avail_in equal to zero. There won't be anything to do,
  1502. // but this is not an error situation so make sure we
  1503. // return OK instead of BUF_ERROR at next call of deflate:
  1504. last_flush = -1;
  1505. return Z_OK$1;
  1506. }
  1507. // Make sure there is something to do and avoid duplicate
  1508. // consecutive
  1509. // flushes. For repeated and useless calls with Z_FINISH, we keep
  1510. // returning Z_STREAM_END instead of Z_BUFF_ERROR.
  1511. } else if (strm.avail_in === 0 && flush <= old_flush && flush != Z_FINISH$1) {
  1512. strm.msg = z_errmsg[Z_NEED_DICT$1 - (Z_BUF_ERROR$1)];
  1513. return Z_BUF_ERROR$1;
  1514. }
  1515. // User must not provide more input after the first FINISH:
  1516. if (status == FINISH_STATE && strm.avail_in !== 0) {
  1517. _strm.msg = z_errmsg[Z_NEED_DICT$1 - (Z_BUF_ERROR$1)];
  1518. return Z_BUF_ERROR$1;
  1519. }
  1520. // Start a new block or continue the current one.
  1521. if (strm.avail_in !== 0 || lookahead !== 0 || (flush != Z_NO_FLUSH$1 && status != FINISH_STATE)) {
  1522. bstate = -1;
  1523. switch (config_table[level].func) {
  1524. case STORED$1:
  1525. bstate = deflate_stored(flush);
  1526. break;
  1527. case FAST:
  1528. bstate = deflate_fast(flush);
  1529. break;
  1530. case SLOW:
  1531. bstate = deflate_slow(flush);
  1532. break;
  1533. }
  1534. if (bstate == FinishStarted || bstate == FinishDone) {
  1535. status = FINISH_STATE;
  1536. }
  1537. if (bstate == NeedMore || bstate == FinishStarted) {
  1538. if (strm.avail_out === 0) {
  1539. last_flush = -1; // avoid BUF_ERROR next call, see above
  1540. }
  1541. return Z_OK$1;
  1542. // If flush != Z_NO_FLUSH && avail_out === 0, the next call
  1543. // of deflate should use the same flush parameter to make sure
  1544. // that the flush is complete. So we don't have to output an
  1545. // empty block here, this will be done at next call. This also
  1546. // ensures that for a very small output buffer, we emit at most
  1547. // one empty block.
  1548. }
  1549. if (bstate == BlockDone) {
  1550. if (flush == Z_PARTIAL_FLUSH) {
  1551. _tr_align();
  1552. } else { // FULL_FLUSH or SYNC_FLUSH
  1553. _tr_stored_block(0, 0, false);
  1554. // For a full flush, this empty block will be recognized
  1555. // as a special marker by inflate_sync().
  1556. if (flush == Z_FULL_FLUSH) {
  1557. // state.head[s.hash_size-1]=0;
  1558. for (i = 0; i < hash_size/*-1*/; i++)
  1559. // forget history
  1560. head[i] = 0;
  1561. }
  1562. }
  1563. strm.flush_pending();
  1564. if (strm.avail_out === 0) {
  1565. last_flush = -1; // avoid BUF_ERROR at next call, see above
  1566. return Z_OK$1;
  1567. }
  1568. }
  1569. }
  1570. if (flush != Z_FINISH$1)
  1571. return Z_OK$1;
  1572. return Z_STREAM_END$1;
  1573. };
  1574. }
  1575. // ZStream
  1576. function ZStream$1() {
  1577. const that = this;
  1578. that.next_in_index = 0;
  1579. that.next_out_index = 0;
  1580. // that.next_in; // next input byte
  1581. that.avail_in = 0; // number of bytes available at next_in
  1582. that.total_in = 0; // total nb of input bytes read so far
  1583. // that.next_out; // next output byte should be put there
  1584. that.avail_out = 0; // remaining free space at next_out
  1585. that.total_out = 0; // total nb of bytes output so far
  1586. // that.msg;
  1587. // that.dstate;
  1588. }
  1589. ZStream$1.prototype = {
  1590. deflateInit: function (level, bits) {
  1591. const that = this;
  1592. that.dstate = new Deflate$1();
  1593. if (!bits)
  1594. bits = MAX_BITS$1;
  1595. return that.dstate.deflateInit(that, level, bits);
  1596. },
  1597. deflate: function (flush) {
  1598. const that = this;
  1599. if (!that.dstate) {
  1600. return Z_STREAM_ERROR$1;
  1601. }
  1602. return that.dstate.deflate(that, flush);
  1603. },
  1604. deflateEnd: function () {
  1605. const that = this;
  1606. if (!that.dstate)
  1607. return Z_STREAM_ERROR$1;
  1608. const ret = that.dstate.deflateEnd();
  1609. that.dstate = null;
  1610. return ret;
  1611. },
  1612. deflateParams: function (level, strategy) {
  1613. const that = this;
  1614. if (!that.dstate)
  1615. return Z_STREAM_ERROR$1;
  1616. return that.dstate.deflateParams(that, level, strategy);
  1617. },
  1618. deflateSetDictionary: function (dictionary, dictLength) {
  1619. const that = this;
  1620. if (!that.dstate)
  1621. return Z_STREAM_ERROR$1;
  1622. return that.dstate.deflateSetDictionary(that, dictionary, dictLength);
  1623. },
  1624. // Read a new buffer from the current input stream, update the
  1625. // total number of bytes read. All deflate() input goes through
  1626. // this function so some applications may wish to modify it to avoid
  1627. // allocating a large strm->next_in buffer and copying from it.
  1628. // (See also flush_pending()).
  1629. read_buf: function (buf, start, size) {
  1630. const that = this;
  1631. let len = that.avail_in;
  1632. if (len > size)
  1633. len = size;
  1634. if (len === 0)
  1635. return 0;
  1636. that.avail_in -= len;
  1637. buf.set(that.next_in.subarray(that.next_in_index, that.next_in_index + len), start);
  1638. that.next_in_index += len;
  1639. that.total_in += len;
  1640. return len;
  1641. },
  1642. // Flush as much pending output as possible. All deflate() output goes
  1643. // through this function so some applications may wish to modify it
  1644. // to avoid allocating a large strm->next_out buffer and copying into it.
  1645. // (See also read_buf()).
  1646. flush_pending: function () {
  1647. const that = this;
  1648. let len = that.dstate.pending;
  1649. if (len > that.avail_out)
  1650. len = that.avail_out;
  1651. if (len === 0)
  1652. return;
  1653. // if (that.dstate.pending_buf.length <= that.dstate.pending_out || that.next_out.length <= that.next_out_index
  1654. // || that.dstate.pending_buf.length < (that.dstate.pending_out + len) || that.next_out.length < (that.next_out_index +
  1655. // len)) {
  1656. // console.log(that.dstate.pending_buf.length + ", " + that.dstate.pending_out + ", " + that.next_out.length + ", " +
  1657. // that.next_out_index + ", " + len);
  1658. // console.log("avail_out=" + that.avail_out);
  1659. // }
  1660. that.next_out.set(that.dstate.pending_buf.subarray(that.dstate.pending_out, that.dstate.pending_out + len), that.next_out_index);
  1661. that.next_out_index += len;
  1662. that.dstate.pending_out += len;
  1663. that.total_out += len;
  1664. that.avail_out -= len;
  1665. that.dstate.pending -= len;
  1666. if (that.dstate.pending === 0) {
  1667. that.dstate.pending_out = 0;
  1668. }
  1669. }
  1670. };
  1671. // Deflate
  1672. function ZipDeflate(options) {
  1673. const that = this;
  1674. const z = new ZStream$1();
  1675. const bufsize = getMaximumCompressedSize$1(options && options.chunkSize ? options.chunkSize : 64 * 1024);
  1676. const flush = Z_NO_FLUSH$1;
  1677. const buf = new Uint8Array(bufsize);
  1678. let level = options ? options.level : Z_DEFAULT_COMPRESSION;
  1679. if (typeof level == "undefined")
  1680. level = Z_DEFAULT_COMPRESSION;
  1681. z.deflateInit(level);
  1682. z.next_out = buf;
  1683. that.append = function (data, onprogress) {
  1684. let err, array, lastIndex = 0, bufferIndex = 0, bufferSize = 0;
  1685. const buffers = [];
  1686. if (!data.length)
  1687. return;
  1688. z.next_in_index = 0;
  1689. z.next_in = data;
  1690. z.avail_in = data.length;
  1691. do {
  1692. z.next_out_index = 0;
  1693. z.avail_out = bufsize;
  1694. err = z.deflate(flush);
  1695. if (err != Z_OK$1)
  1696. throw new Error("deflating: " + z.msg);
  1697. if (z.next_out_index)
  1698. if (z.next_out_index == bufsize)
  1699. buffers.push(new Uint8Array(buf));
  1700. else
  1701. buffers.push(buf.slice(0, z.next_out_index));
  1702. bufferSize += z.next_out_index;
  1703. if (onprogress && z.next_in_index > 0 && z.next_in_index != lastIndex) {
  1704. onprogress(z.next_in_index);
  1705. lastIndex = z.next_in_index;
  1706. }
  1707. } while (z.avail_in > 0 || z.avail_out === 0);
  1708. if (buffers.length > 1) {
  1709. array = new Uint8Array(bufferSize);
  1710. buffers.forEach(function (chunk) {
  1711. array.set(chunk, bufferIndex);
  1712. bufferIndex += chunk.length;
  1713. });
  1714. } else {
  1715. array = buffers[0] || new Uint8Array(0);
  1716. }
  1717. return array;
  1718. };
  1719. that.flush = function () {
  1720. let err, array, bufferIndex = 0, bufferSize = 0;
  1721. const buffers = [];
  1722. do {
  1723. z.next_out_index = 0;
  1724. z.avail_out = bufsize;
  1725. err = z.deflate(Z_FINISH$1);
  1726. if (err != Z_STREAM_END$1 && err != Z_OK$1)
  1727. throw new Error("deflating: " + z.msg);
  1728. if (bufsize - z.avail_out > 0)
  1729. buffers.push(buf.slice(0, z.next_out_index));
  1730. bufferSize += z.next_out_index;
  1731. } while (z.avail_in > 0 || z.avail_out === 0);
  1732. z.deflateEnd();
  1733. array = new Uint8Array(bufferSize);
  1734. buffers.forEach(function (chunk) {
  1735. array.set(chunk, bufferIndex);
  1736. bufferIndex += chunk.length;
  1737. });
  1738. return array;
  1739. };
  1740. }
  1741. function getMaximumCompressedSize$1(uncompressedSize) {
  1742. return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
  1743. }
  1744. /*
  1745. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  1746. Redistribution and use in source and binary forms, with or without
  1747. modification, are permitted provided that the following conditions are met:
  1748. 1. Redistributions of source code must retain the above copyright notice,
  1749. this list of conditions and the following disclaimer.
  1750. 2. Redistributions in binary form must reproduce the above copyright
  1751. notice, this list of conditions and the following disclaimer in
  1752. the documentation and/or other materials provided with the distribution.
  1753. 3. The names of the authors may not be used to endorse or promote products
  1754. derived from this software without specific prior written permission.
  1755. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  1756. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1757. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  1758. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  1759. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1760. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  1761. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1762. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1763. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1764. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1765. */
  1766. /*
  1767. * This program is based on JZlib 1.0.2 ymnk, JCraft,Inc.
  1768. * JZlib is based on zlib-1.1.3, so all credit should go authors
  1769. * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
  1770. * and contributors of zlib.
  1771. */
  1772. // deno-lint-ignore-file no-this-alias prefer-const
  1773. // Global
  1774. const MAX_BITS = 15;
  1775. const Z_OK = 0;
  1776. const Z_STREAM_END = 1;
  1777. const Z_NEED_DICT = 2;
  1778. const Z_STREAM_ERROR = -2;
  1779. const Z_DATA_ERROR = -3;
  1780. const Z_MEM_ERROR = -4;
  1781. const Z_BUF_ERROR = -5;
  1782. const inflate_mask = [0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff, 0x000003ff,
  1783. 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff];
  1784. const MANY = 1440;
  1785. // JZlib version : "1.0.2"
  1786. const Z_NO_FLUSH = 0;
  1787. const Z_FINISH = 4;
  1788. // InfTree
  1789. const fixed_bl = 9;
  1790. const fixed_bd = 5;
  1791. const fixed_tl = [96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9, 192, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 160, 0, 8, 0,
  1792. 0, 8, 128, 0, 8, 64, 0, 9, 224, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 144, 83, 7, 59, 0, 8, 120, 0, 8, 56, 0, 9, 208, 81, 7, 17, 0, 8, 104, 0, 8, 40,
  1793. 0, 9, 176, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 240, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8, 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 200, 81, 7, 13,
  1794. 0, 8, 100, 0, 8, 36, 0, 9, 168, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 232, 80, 7, 8, 0, 8, 92, 0, 8, 28, 0, 9, 152, 84, 7, 83, 0, 8, 124, 0, 8, 60,
  1795. 0, 9, 216, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 184, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9, 248, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7,
  1796. 35, 0, 8, 114, 0, 8, 50, 0, 9, 196, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 164, 0, 8, 2, 0, 8, 130, 0, 8, 66, 0, 9, 228, 80, 7, 7, 0, 8, 90, 0, 8,
  1797. 26, 0, 9, 148, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 212, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9, 180, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 244, 80,
  1798. 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 204, 81, 7, 15, 0, 8, 102, 0, 8, 38, 0, 9, 172, 0, 8, 6, 0, 8, 134, 0,
  1799. 8, 70, 0, 9, 236, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 156, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9, 220, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 188, 0,
  1800. 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 252, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0, 8, 113, 0, 8, 49, 0, 9, 194, 80, 7, 10, 0, 8, 97,
  1801. 0, 8, 33, 0, 9, 162, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 226, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9, 146, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 210,
  1802. 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 178, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 242, 80, 7, 4, 0, 8, 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117,
  1803. 0, 8, 53, 0, 9, 202, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 170, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9, 234, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 154,
  1804. 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 218, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 186, 0, 8, 13, 0, 8, 141, 0, 8, 77, 0, 9, 250, 80, 7, 3, 0, 8, 83,
  1805. 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 198, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9, 166, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 230,
  1806. 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 150, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 214, 82, 7, 19, 0, 8, 107, 0, 8, 43, 0, 9, 182, 0, 8, 11, 0, 8, 139,
  1807. 0, 8, 75, 0, 9, 246, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9, 206, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 174,
  1808. 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 238, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 158, 84, 7, 99, 0, 8, 127, 0, 8, 63, 0, 9, 222, 82, 7, 27, 0, 8, 111,
  1809. 0, 8, 47, 0, 9, 190, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 254, 96, 7, 256, 0, 8, 80, 0, 8, 16, 84, 8, 115, 82, 7, 31, 0, 8, 112, 0, 8, 48, 0, 9,
  1810. 193, 80, 7, 10, 0, 8, 96, 0, 8, 32, 0, 9, 161, 0, 8, 0, 0, 8, 128, 0, 8, 64, 0, 9, 225, 80, 7, 6, 0, 8, 88, 0, 8, 24, 0, 9, 145, 83, 7, 59, 0, 8,
  1811. 120, 0, 8, 56, 0, 9, 209, 81, 7, 17, 0, 8, 104, 0, 8, 40, 0, 9, 177, 0, 8, 8, 0, 8, 136, 0, 8, 72, 0, 9, 241, 80, 7, 4, 0, 8, 84, 0, 8, 20, 85, 8,
  1812. 227, 83, 7, 43, 0, 8, 116, 0, 8, 52, 0, 9, 201, 81, 7, 13, 0, 8, 100, 0, 8, 36, 0, 9, 169, 0, 8, 4, 0, 8, 132, 0, 8, 68, 0, 9, 233, 80, 7, 8, 0, 8,
  1813. 92, 0, 8, 28, 0, 9, 153, 84, 7, 83, 0, 8, 124, 0, 8, 60, 0, 9, 217, 82, 7, 23, 0, 8, 108, 0, 8, 44, 0, 9, 185, 0, 8, 12, 0, 8, 140, 0, 8, 76, 0, 9,
  1814. 249, 80, 7, 3, 0, 8, 82, 0, 8, 18, 85, 8, 163, 83, 7, 35, 0, 8, 114, 0, 8, 50, 0, 9, 197, 81, 7, 11, 0, 8, 98, 0, 8, 34, 0, 9, 165, 0, 8, 2, 0, 8,
  1815. 130, 0, 8, 66, 0, 9, 229, 80, 7, 7, 0, 8, 90, 0, 8, 26, 0, 9, 149, 84, 7, 67, 0, 8, 122, 0, 8, 58, 0, 9, 213, 82, 7, 19, 0, 8, 106, 0, 8, 42, 0, 9,
  1816. 181, 0, 8, 10, 0, 8, 138, 0, 8, 74, 0, 9, 245, 80, 7, 5, 0, 8, 86, 0, 8, 22, 192, 8, 0, 83, 7, 51, 0, 8, 118, 0, 8, 54, 0, 9, 205, 81, 7, 15, 0, 8,
  1817. 102, 0, 8, 38, 0, 9, 173, 0, 8, 6, 0, 8, 134, 0, 8, 70, 0, 9, 237, 80, 7, 9, 0, 8, 94, 0, 8, 30, 0, 9, 157, 84, 7, 99, 0, 8, 126, 0, 8, 62, 0, 9,
  1818. 221, 82, 7, 27, 0, 8, 110, 0, 8, 46, 0, 9, 189, 0, 8, 14, 0, 8, 142, 0, 8, 78, 0, 9, 253, 96, 7, 256, 0, 8, 81, 0, 8, 17, 85, 8, 131, 82, 7, 31, 0,
  1819. 8, 113, 0, 8, 49, 0, 9, 195, 80, 7, 10, 0, 8, 97, 0, 8, 33, 0, 9, 163, 0, 8, 1, 0, 8, 129, 0, 8, 65, 0, 9, 227, 80, 7, 6, 0, 8, 89, 0, 8, 25, 0, 9,
  1820. 147, 83, 7, 59, 0, 8, 121, 0, 8, 57, 0, 9, 211, 81, 7, 17, 0, 8, 105, 0, 8, 41, 0, 9, 179, 0, 8, 9, 0, 8, 137, 0, 8, 73, 0, 9, 243, 80, 7, 4, 0, 8,
  1821. 85, 0, 8, 21, 80, 8, 258, 83, 7, 43, 0, 8, 117, 0, 8, 53, 0, 9, 203, 81, 7, 13, 0, 8, 101, 0, 8, 37, 0, 9, 171, 0, 8, 5, 0, 8, 133, 0, 8, 69, 0, 9,
  1822. 235, 80, 7, 8, 0, 8, 93, 0, 8, 29, 0, 9, 155, 84, 7, 83, 0, 8, 125, 0, 8, 61, 0, 9, 219, 82, 7, 23, 0, 8, 109, 0, 8, 45, 0, 9, 187, 0, 8, 13, 0, 8,
  1823. 141, 0, 8, 77, 0, 9, 251, 80, 7, 3, 0, 8, 83, 0, 8, 19, 85, 8, 195, 83, 7, 35, 0, 8, 115, 0, 8, 51, 0, 9, 199, 81, 7, 11, 0, 8, 99, 0, 8, 35, 0, 9,
  1824. 167, 0, 8, 3, 0, 8, 131, 0, 8, 67, 0, 9, 231, 80, 7, 7, 0, 8, 91, 0, 8, 27, 0, 9, 151, 84, 7, 67, 0, 8, 123, 0, 8, 59, 0, 9, 215, 82, 7, 19, 0, 8,
  1825. 107, 0, 8, 43, 0, 9, 183, 0, 8, 11, 0, 8, 139, 0, 8, 75, 0, 9, 247, 80, 7, 5, 0, 8, 87, 0, 8, 23, 192, 8, 0, 83, 7, 51, 0, 8, 119, 0, 8, 55, 0, 9,
  1826. 207, 81, 7, 15, 0, 8, 103, 0, 8, 39, 0, 9, 175, 0, 8, 7, 0, 8, 135, 0, 8, 71, 0, 9, 239, 80, 7, 9, 0, 8, 95, 0, 8, 31, 0, 9, 159, 84, 7, 99, 0, 8,
  1827. 127, 0, 8, 63, 0, 9, 223, 82, 7, 27, 0, 8, 111, 0, 8, 47, 0, 9, 191, 0, 8, 15, 0, 8, 143, 0, 8, 79, 0, 9, 255];
  1828. const fixed_td = [80, 5, 1, 87, 5, 257, 83, 5, 17, 91, 5, 4097, 81, 5, 5, 89, 5, 1025, 85, 5, 65, 93, 5, 16385, 80, 5, 3, 88, 5, 513, 84, 5, 33, 92, 5,
  1829. 8193, 82, 5, 9, 90, 5, 2049, 86, 5, 129, 192, 5, 24577, 80, 5, 2, 87, 5, 385, 83, 5, 25, 91, 5, 6145, 81, 5, 7, 89, 5, 1537, 85, 5, 97, 93, 5,
  1830. 24577, 80, 5, 4, 88, 5, 769, 84, 5, 49, 92, 5, 12289, 82, 5, 13, 90, 5, 3073, 86, 5, 193, 192, 5, 24577];
  1831. // Tables for deflate from PKZIP's appnote.txt.
  1832. const cplens = [ // Copy lengths for literal codes 257..285
  1833. 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];
  1834. // see note #13 above about 258
  1835. const cplext = [ // Extra bits for literal codes 257..285
  1836. 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, 112, 112 // 112==invalid
  1837. ];
  1838. const cpdist = [ // Copy offsets for distance codes 0..29
  1839. 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];
  1840. const cpdext = [ // Extra bits for distance codes
  1841. 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];
  1842. // If BMAX needs to be larger than 16, then h and x[] should be uLong.
  1843. const BMAX = 15; // maximum bit length of any code
  1844. function InfTree() {
  1845. const that = this;
  1846. let hn; // hufts used in space
  1847. let v; // work area for huft_build
  1848. let c; // bit length count table
  1849. let r; // table entry for structure assignment
  1850. let u; // table stack
  1851. let x; // bit offsets, then code stack
  1852. function huft_build(b, // code lengths in bits (all assumed <=
  1853. // BMAX)
  1854. bindex, n, // number of codes (assumed <= 288)
  1855. s, // number of simple-valued codes (0..s-1)
  1856. d, // list of base values for non-simple codes
  1857. e, // list of extra bits for non-simple codes
  1858. t, // result: starting table
  1859. m, // maximum lookup bits, returns actual
  1860. hp,// space for trees
  1861. hn,// hufts used in space
  1862. v // working area: values in order of bit length
  1863. ) {
  1864. // Given a list of code lengths and a maximum table size, make a set of
  1865. // tables to decode that set of codes. Return Z_OK on success,
  1866. // Z_BUF_ERROR
  1867. // if the given code set is incomplete (the tables are still built in
  1868. // this
  1869. // case), Z_DATA_ERROR if the input is invalid (an over-subscribed set
  1870. // of
  1871. // lengths), or Z_MEM_ERROR if not enough memory.
  1872. let a; // counter for codes of length k
  1873. let f; // i repeats in table every f entries
  1874. let g; // maximum code length
  1875. let h; // table level
  1876. let i; // counter, current code
  1877. let j; // counter
  1878. let k; // number of bits in current code
  1879. let l; // bits per table (returned in m)
  1880. let mask; // (1 << w) - 1, to avoid cc -O bug on HP
  1881. let p; // pointer into c[], b[], or v[]
  1882. let q; // points to current table
  1883. let w; // bits before this table == (l * h)
  1884. let xp; // pointer into x
  1885. let y; // number of dummy codes added
  1886. let z; // number of entries in current table
  1887. // Generate counts for each bit length
  1888. p = 0;
  1889. i = n;
  1890. do {
  1891. c[b[bindex + p]]++;
  1892. p++;
  1893. i--; // assume all entries <= BMAX
  1894. } while (i !== 0);
  1895. if (c[0] == n) { // null input--all zero length codes
  1896. t[0] = -1;
  1897. m[0] = 0;
  1898. return Z_OK;
  1899. }
  1900. // Find minimum and maximum length, bound *m by those
  1901. l = m[0];
  1902. for (j = 1; j <= BMAX; j++)
  1903. if (c[j] !== 0)
  1904. break;
  1905. k = j; // minimum code length
  1906. if (l < j) {
  1907. l = j;
  1908. }
  1909. for (i = BMAX; i !== 0; i--) {
  1910. if (c[i] !== 0)
  1911. break;
  1912. }
  1913. g = i; // maximum code length
  1914. if (l > i) {
  1915. l = i;
  1916. }
  1917. m[0] = l;
  1918. // Adjust last length count to fill out codes, if needed
  1919. for (y = 1 << j; j < i; j++, y <<= 1) {
  1920. if ((y -= c[j]) < 0) {
  1921. return Z_DATA_ERROR;
  1922. }
  1923. }
  1924. if ((y -= c[i]) < 0) {
  1925. return Z_DATA_ERROR;
  1926. }
  1927. c[i] += y;
  1928. // Generate starting offsets into the value table for each length
  1929. x[1] = j = 0;
  1930. p = 1;
  1931. xp = 2;
  1932. while (--i !== 0) { // note that i == g from above
  1933. x[xp] = (j += c[p]);
  1934. xp++;
  1935. p++;
  1936. }
  1937. // Make a table of values in order of bit lengths
  1938. i = 0;
  1939. p = 0;
  1940. do {
  1941. if ((j = b[bindex + p]) !== 0) {
  1942. v[x[j]++] = i;
  1943. }
  1944. p++;
  1945. } while (++i < n);
  1946. n = x[g]; // set n to length of v
  1947. // Generate the Huffman codes and for each, make the table entries
  1948. x[0] = i = 0; // first Huffman code is zero
  1949. p = 0; // grab values in bit order
  1950. h = -1; // no tables yet--level -1
  1951. w = -l; // bits decoded == (l * h)
  1952. u[0] = 0; // just to keep compilers happy
  1953. q = 0; // ditto
  1954. z = 0; // ditto
  1955. // go through the bit lengths (k already is bits in shortest code)
  1956. for (; k <= g; k++) {
  1957. a = c[k];
  1958. while (a-- !== 0) {
  1959. // here i is the Huffman code of length k bits for value *p
  1960. // make tables up to required level
  1961. while (k > w + l) {
  1962. h++;
  1963. w += l; // previous table always l bits
  1964. // compute minimum size table less than or equal to l bits
  1965. z = g - w;
  1966. z = (z > l) ? l : z; // table size upper limit
  1967. if ((f = 1 << (j = k - w)) > a + 1) { // try a k-w bit table
  1968. // too few codes for
  1969. // k-w bit table
  1970. f -= a + 1; // deduct codes from patterns left
  1971. xp = k;
  1972. if (j < z) {
  1973. while (++j < z) { // try smaller tables up to z bits
  1974. if ((f <<= 1) <= c[++xp])
  1975. break; // enough codes to use up j bits
  1976. f -= c[xp]; // else deduct codes from patterns
  1977. }
  1978. }
  1979. }
  1980. z = 1 << j; // table entries for j-bit table
  1981. // allocate new table
  1982. if (hn[0] + z > MANY) { // (note: doesn't matter for fixed)
  1983. return Z_DATA_ERROR; // overflow of MANY
  1984. }
  1985. u[h] = q = /* hp+ */hn[0]; // DEBUG
  1986. hn[0] += z;
  1987. // connect to last table, if there is one
  1988. if (h !== 0) {
  1989. x[h] = i; // save pattern for backing up
  1990. r[0] = /* (byte) */j; // bits in this table
  1991. r[1] = /* (byte) */l; // bits to dump before this table
  1992. j = i >>> (w - l);
  1993. r[2] = /* (int) */(q - u[h - 1] - j); // offset to this table
  1994. hp.set(r, (u[h - 1] + j) * 3);
  1995. // to
  1996. // last
  1997. // table
  1998. } else {
  1999. t[0] = q; // first table is returned result
  2000. }
  2001. }
  2002. // set up table entry in r
  2003. r[1] = /* (byte) */(k - w);
  2004. if (p >= n) {
  2005. r[0] = 128 + 64; // out of values--invalid code
  2006. } else if (v[p] < s) {
  2007. r[0] = /* (byte) */(v[p] < 256 ? 0 : 32 + 64); // 256 is
  2008. // end-of-block
  2009. r[2] = v[p++]; // simple code is just the value
  2010. } else {
  2011. r[0] = /* (byte) */(e[v[p] - s] + 16 + 64); // non-simple--look
  2012. // up in lists
  2013. r[2] = d[v[p++] - s];
  2014. }
  2015. // fill code-like entries with r
  2016. f = 1 << (k - w);
  2017. for (j = i >>> w; j < z; j += f) {
  2018. hp.set(r, (q + j) * 3);
  2019. }
  2020. // backwards increment the k-bit code i
  2021. for (j = 1 << (k - 1); (i & j) !== 0; j >>>= 1) {
  2022. i ^= j;
  2023. }
  2024. i ^= j;
  2025. // backup over finished tables
  2026. mask = (1 << w) - 1; // needed on HP, cc -O bug
  2027. while ((i & mask) != x[h]) {
  2028. h--; // don't need to update q
  2029. w -= l;
  2030. mask = (1 << w) - 1;
  2031. }
  2032. }
  2033. }
  2034. // Return Z_BUF_ERROR if we were given an incomplete table
  2035. return y !== 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
  2036. }
  2037. function initWorkArea(vsize) {
  2038. let i;
  2039. if (!hn) {
  2040. hn = []; // []; //new Array(1);
  2041. v = []; // new Array(vsize);
  2042. c = new Int32Array(BMAX + 1); // new Array(BMAX + 1);
  2043. r = []; // new Array(3);
  2044. u = new Int32Array(BMAX); // new Array(BMAX);
  2045. x = new Int32Array(BMAX + 1); // new Array(BMAX + 1);
  2046. }
  2047. if (v.length < vsize) {
  2048. v = []; // new Array(vsize);
  2049. }
  2050. for (i = 0; i < vsize; i++) {
  2051. v[i] = 0;
  2052. }
  2053. for (i = 0; i < BMAX + 1; i++) {
  2054. c[i] = 0;
  2055. }
  2056. for (i = 0; i < 3; i++) {
  2057. r[i] = 0;
  2058. }
  2059. // for(int i=0; i<BMAX; i++){u[i]=0;}
  2060. u.set(c.subarray(0, BMAX), 0);
  2061. // for(int i=0; i<BMAX+1; i++){x[i]=0;}
  2062. x.set(c.subarray(0, BMAX + 1), 0);
  2063. }
  2064. that.inflate_trees_bits = function (c, // 19 code lengths
  2065. bb, // bits tree desired/actual depth
  2066. tb, // bits tree result
  2067. hp, // space for trees
  2068. z // for messages
  2069. ) {
  2070. let result;
  2071. initWorkArea(19);
  2072. hn[0] = 0;
  2073. result = huft_build(c, 0, 19, 19, null, null, tb, bb, hp, hn, v);
  2074. if (result == Z_DATA_ERROR) {
  2075. z.msg = "oversubscribed dynamic bit lengths tree";
  2076. } else if (result == Z_BUF_ERROR || bb[0] === 0) {
  2077. z.msg = "incomplete dynamic bit lengths tree";
  2078. result = Z_DATA_ERROR;
  2079. }
  2080. return result;
  2081. };
  2082. that.inflate_trees_dynamic = function (nl, // number of literal/length codes
  2083. nd, // number of distance codes
  2084. c, // that many (total) code lengths
  2085. bl, // literal desired/actual bit depth
  2086. bd, // distance desired/actual bit depth
  2087. tl, // literal/length tree result
  2088. td, // distance tree result
  2089. hp, // space for trees
  2090. z // for messages
  2091. ) {
  2092. let result;
  2093. // build literal/length tree
  2094. initWorkArea(288);
  2095. hn[0] = 0;
  2096. result = huft_build(c, 0, nl, 257, cplens, cplext, tl, bl, hp, hn, v);
  2097. if (result != Z_OK || bl[0] === 0) {
  2098. if (result == Z_DATA_ERROR) {
  2099. z.msg = "oversubscribed literal/length tree";
  2100. } else if (result != Z_MEM_ERROR) {
  2101. z.msg = "incomplete literal/length tree";
  2102. result = Z_DATA_ERROR;
  2103. }
  2104. return result;
  2105. }
  2106. // build distance tree
  2107. initWorkArea(288);
  2108. result = huft_build(c, nl, nd, 0, cpdist, cpdext, td, bd, hp, hn, v);
  2109. if (result != Z_OK || (bd[0] === 0 && nl > 257)) {
  2110. if (result == Z_DATA_ERROR) {
  2111. z.msg = "oversubscribed distance tree";
  2112. } else if (result == Z_BUF_ERROR) {
  2113. z.msg = "incomplete distance tree";
  2114. result = Z_DATA_ERROR;
  2115. } else if (result != Z_MEM_ERROR) {
  2116. z.msg = "empty distance tree with lengths";
  2117. result = Z_DATA_ERROR;
  2118. }
  2119. return result;
  2120. }
  2121. return Z_OK;
  2122. };
  2123. }
  2124. InfTree.inflate_trees_fixed = function (bl, // literal desired/actual bit depth
  2125. bd, // distance desired/actual bit depth
  2126. tl,// literal/length tree result
  2127. td// distance tree result
  2128. ) {
  2129. bl[0] = fixed_bl;
  2130. bd[0] = fixed_bd;
  2131. tl[0] = fixed_tl;
  2132. td[0] = fixed_td;
  2133. return Z_OK;
  2134. };
  2135. // InfCodes
  2136. // waiting for "i:"=input,
  2137. // "o:"=output,
  2138. // "x:"=nothing
  2139. const START = 0; // x: set up for LEN
  2140. const LEN = 1; // i: get length/literal/eob next
  2141. const LENEXT = 2; // i: getting length extra (have base)
  2142. const DIST = 3; // i: get distance next
  2143. const DISTEXT = 4;// i: getting distance extra
  2144. const COPY = 5; // o: copying bytes in win, waiting
  2145. // for space
  2146. const LIT = 6; // o: got literal, waiting for output
  2147. // space
  2148. const WASH = 7; // o: got eob, possibly still output
  2149. // waiting
  2150. const END = 8; // x: got eob and all data flushed
  2151. const BADCODE = 9;// x: got error
  2152. function InfCodes() {
  2153. const that = this;
  2154. let mode; // current inflate_codes mode
  2155. // mode dependent information
  2156. let len = 0;
  2157. let tree; // pointer into tree
  2158. let tree_index = 0;
  2159. let need = 0; // bits needed
  2160. let lit = 0;
  2161. // if EXT or COPY, where and how much
  2162. let get = 0; // bits to get for extra
  2163. let dist = 0; // distance back to copy from
  2164. let lbits = 0; // ltree bits decoded per branch
  2165. let dbits = 0; // dtree bits decoder per branch
  2166. let ltree; // literal/length/eob tree
  2167. let ltree_index = 0; // literal/length/eob tree
  2168. let dtree; // distance tree
  2169. let dtree_index = 0; // distance tree
  2170. // Called with number of bytes left to write in win at least 258
  2171. // (the maximum string length) and number of input bytes available
  2172. // at least ten. The ten bytes are six bytes for the longest length/
  2173. // distance pair plus four bytes for overloading the bit buffer.
  2174. function inflate_fast(bl, bd, tl, tl_index, td, td_index, s, z) {
  2175. let t; // temporary pointer
  2176. let tp; // temporary pointer
  2177. let tp_index; // temporary pointer
  2178. let e; // extra bits or operation
  2179. let b; // bit buffer
  2180. let k; // bits in bit buffer
  2181. let p; // input data pointer
  2182. let n; // bytes available there
  2183. let q; // output win write pointer
  2184. let m; // bytes to end of win or read pointer
  2185. let ml; // mask for literal/length tree
  2186. let md; // mask for distance tree
  2187. let c; // bytes to copy
  2188. let d; // distance back to copy from
  2189. let r; // copy source pointer
  2190. let tp_index_t_3; // (tp_index+t)*3
  2191. // load input, output, bit values
  2192. p = z.next_in_index;
  2193. n = z.avail_in;
  2194. b = s.bitb;
  2195. k = s.bitk;
  2196. q = s.write;
  2197. m = q < s.read ? s.read - q - 1 : s.end - q;
  2198. // initialize masks
  2199. ml = inflate_mask[bl];
  2200. md = inflate_mask[bd];
  2201. // do until not enough input or output space for fast loop
  2202. do { // assume called with m >= 258 && n >= 10
  2203. // get literal/length code
  2204. while (k < (20)) { // max bits for literal/length code
  2205. n--;
  2206. b |= (z.read_byte(p++) & 0xff) << k;
  2207. k += 8;
  2208. }
  2209. t = b & ml;
  2210. tp = tl;
  2211. tp_index = tl_index;
  2212. tp_index_t_3 = (tp_index + t) * 3;
  2213. if ((e = tp[tp_index_t_3]) === 0) {
  2214. b >>= (tp[tp_index_t_3 + 1]);
  2215. k -= (tp[tp_index_t_3 + 1]);
  2216. s.win[q++] = /* (byte) */tp[tp_index_t_3 + 2];
  2217. m--;
  2218. continue;
  2219. }
  2220. do {
  2221. b >>= (tp[tp_index_t_3 + 1]);
  2222. k -= (tp[tp_index_t_3 + 1]);
  2223. if ((e & 16) !== 0) {
  2224. e &= 15;
  2225. c = tp[tp_index_t_3 + 2] + (/* (int) */b & inflate_mask[e]);
  2226. b >>= e;
  2227. k -= e;
  2228. // decode distance base of block to copy
  2229. while (k < (15)) { // max bits for distance code
  2230. n--;
  2231. b |= (z.read_byte(p++) & 0xff) << k;
  2232. k += 8;
  2233. }
  2234. t = b & md;
  2235. tp = td;
  2236. tp_index = td_index;
  2237. tp_index_t_3 = (tp_index + t) * 3;
  2238. e = tp[tp_index_t_3];
  2239. do {
  2240. b >>= (tp[tp_index_t_3 + 1]);
  2241. k -= (tp[tp_index_t_3 + 1]);
  2242. if ((e & 16) !== 0) {
  2243. // get extra bits to add to distance base
  2244. e &= 15;
  2245. while (k < (e)) { // get extra bits (up to 13)
  2246. n--;
  2247. b |= (z.read_byte(p++) & 0xff) << k;
  2248. k += 8;
  2249. }
  2250. d = tp[tp_index_t_3 + 2] + (b & inflate_mask[e]);
  2251. b >>= (e);
  2252. k -= (e);
  2253. // do the copy
  2254. m -= c;
  2255. if (q >= d) { // offset before dest
  2256. // just copy
  2257. r = q - d;
  2258. if (q - r > 0 && 2 > (q - r)) {
  2259. s.win[q++] = s.win[r++]; // minimum
  2260. // count is
  2261. // three,
  2262. s.win[q++] = s.win[r++]; // so unroll
  2263. // loop a
  2264. // little
  2265. c -= 2;
  2266. } else {
  2267. s.win.set(s.win.subarray(r, r + 2), q);
  2268. q += 2;
  2269. r += 2;
  2270. c -= 2;
  2271. }
  2272. } else { // else offset after destination
  2273. r = q - d;
  2274. do {
  2275. r += s.end; // force pointer in win
  2276. } while (r < 0); // covers invalid distances
  2277. e = s.end - r;
  2278. if (c > e) { // if source crosses,
  2279. c -= e; // wrapped copy
  2280. if (q - r > 0 && e > (q - r)) {
  2281. do {
  2282. s.win[q++] = s.win[r++];
  2283. } while (--e !== 0);
  2284. } else {
  2285. s.win.set(s.win.subarray(r, r + e), q);
  2286. q += e;
  2287. r += e;
  2288. e = 0;
  2289. }
  2290. r = 0; // copy rest from start of win
  2291. }
  2292. }
  2293. // copy all or what's left
  2294. if (q - r > 0 && c > (q - r)) {
  2295. do {
  2296. s.win[q++] = s.win[r++];
  2297. } while (--c !== 0);
  2298. } else {
  2299. s.win.set(s.win.subarray(r, r + c), q);
  2300. q += c;
  2301. r += c;
  2302. c = 0;
  2303. }
  2304. break;
  2305. } else if ((e & 64) === 0) {
  2306. t += tp[tp_index_t_3 + 2];
  2307. t += (b & inflate_mask[e]);
  2308. tp_index_t_3 = (tp_index + t) * 3;
  2309. e = tp[tp_index_t_3];
  2310. } else {
  2311. z.msg = "invalid distance code";
  2312. c = z.avail_in - n;
  2313. c = (k >> 3) < c ? k >> 3 : c;
  2314. n += c;
  2315. p -= c;
  2316. k -= c << 3;
  2317. s.bitb = b;
  2318. s.bitk = k;
  2319. z.avail_in = n;
  2320. z.total_in += p - z.next_in_index;
  2321. z.next_in_index = p;
  2322. s.write = q;
  2323. return Z_DATA_ERROR;
  2324. }
  2325. // eslint-disable-next-line no-constant-condition
  2326. } while (true);
  2327. break;
  2328. }
  2329. if ((e & 64) === 0) {
  2330. t += tp[tp_index_t_3 + 2];
  2331. t += (b & inflate_mask[e]);
  2332. tp_index_t_3 = (tp_index + t) * 3;
  2333. if ((e = tp[tp_index_t_3]) === 0) {
  2334. b >>= (tp[tp_index_t_3 + 1]);
  2335. k -= (tp[tp_index_t_3 + 1]);
  2336. s.win[q++] = /* (byte) */tp[tp_index_t_3 + 2];
  2337. m--;
  2338. break;
  2339. }
  2340. } else if ((e & 32) !== 0) {
  2341. c = z.avail_in - n;
  2342. c = (k >> 3) < c ? k >> 3 : c;
  2343. n += c;
  2344. p -= c;
  2345. k -= c << 3;
  2346. s.bitb = b;
  2347. s.bitk = k;
  2348. z.avail_in = n;
  2349. z.total_in += p - z.next_in_index;
  2350. z.next_in_index = p;
  2351. s.write = q;
  2352. return Z_STREAM_END;
  2353. } else {
  2354. z.msg = "invalid literal/length code";
  2355. c = z.avail_in - n;
  2356. c = (k >> 3) < c ? k >> 3 : c;
  2357. n += c;
  2358. p -= c;
  2359. k -= c << 3;
  2360. s.bitb = b;
  2361. s.bitk = k;
  2362. z.avail_in = n;
  2363. z.total_in += p - z.next_in_index;
  2364. z.next_in_index = p;
  2365. s.write = q;
  2366. return Z_DATA_ERROR;
  2367. }
  2368. // eslint-disable-next-line no-constant-condition
  2369. } while (true);
  2370. } while (m >= 258 && n >= 10);
  2371. // not enough input or output--restore pointers and return
  2372. c = z.avail_in - n;
  2373. c = (k >> 3) < c ? k >> 3 : c;
  2374. n += c;
  2375. p -= c;
  2376. k -= c << 3;
  2377. s.bitb = b;
  2378. s.bitk = k;
  2379. z.avail_in = n;
  2380. z.total_in += p - z.next_in_index;
  2381. z.next_in_index = p;
  2382. s.write = q;
  2383. return Z_OK;
  2384. }
  2385. that.init = function (bl, bd, tl, tl_index, td, td_index) {
  2386. mode = START;
  2387. lbits = /* (byte) */bl;
  2388. dbits = /* (byte) */bd;
  2389. ltree = tl;
  2390. ltree_index = tl_index;
  2391. dtree = td;
  2392. dtree_index = td_index;
  2393. tree = null;
  2394. };
  2395. that.proc = function (s, z, r) {
  2396. let j; // temporary storage
  2397. let tindex; // temporary pointer
  2398. let e; // extra bits or operation
  2399. let b = 0; // bit buffer
  2400. let k = 0; // bits in bit buffer
  2401. let p = 0; // input data pointer
  2402. let n; // bytes available there
  2403. let q; // output win write pointer
  2404. let m; // bytes to end of win or read pointer
  2405. let f; // pointer to copy strings from
  2406. // copy input/output information to locals (UPDATE macro restores)
  2407. p = z.next_in_index;
  2408. n = z.avail_in;
  2409. b = s.bitb;
  2410. k = s.bitk;
  2411. q = s.write;
  2412. m = q < s.read ? s.read - q - 1 : s.end - q;
  2413. // process input and output based on current state
  2414. // eslint-disable-next-line no-constant-condition
  2415. while (true) {
  2416. switch (mode) {
  2417. // waiting for "i:"=input, "o:"=output, "x:"=nothing
  2418. case START: // x: set up for LEN
  2419. if (m >= 258 && n >= 10) {
  2420. s.bitb = b;
  2421. s.bitk = k;
  2422. z.avail_in = n;
  2423. z.total_in += p - z.next_in_index;
  2424. z.next_in_index = p;
  2425. s.write = q;
  2426. r = inflate_fast(lbits, dbits, ltree, ltree_index, dtree, dtree_index, s, z);
  2427. p = z.next_in_index;
  2428. n = z.avail_in;
  2429. b = s.bitb;
  2430. k = s.bitk;
  2431. q = s.write;
  2432. m = q < s.read ? s.read - q - 1 : s.end - q;
  2433. if (r != Z_OK) {
  2434. mode = r == Z_STREAM_END ? WASH : BADCODE;
  2435. break;
  2436. }
  2437. }
  2438. need = lbits;
  2439. tree = ltree;
  2440. tree_index = ltree_index;
  2441. mode = LEN;
  2442. /* falls through */
  2443. case LEN: // i: get length/literal/eob next
  2444. j = need;
  2445. while (k < (j)) {
  2446. if (n !== 0)
  2447. r = Z_OK;
  2448. else {
  2449. s.bitb = b;
  2450. s.bitk = k;
  2451. z.avail_in = n;
  2452. z.total_in += p - z.next_in_index;
  2453. z.next_in_index = p;
  2454. s.write = q;
  2455. return s.inflate_flush(z, r);
  2456. }
  2457. n--;
  2458. b |= (z.read_byte(p++) & 0xff) << k;
  2459. k += 8;
  2460. }
  2461. tindex = (tree_index + (b & inflate_mask[j])) * 3;
  2462. b >>>= (tree[tindex + 1]);
  2463. k -= (tree[tindex + 1]);
  2464. e = tree[tindex];
  2465. if (e === 0) { // literal
  2466. lit = tree[tindex + 2];
  2467. mode = LIT;
  2468. break;
  2469. }
  2470. if ((e & 16) !== 0) { // length
  2471. get = e & 15;
  2472. len = tree[tindex + 2];
  2473. mode = LENEXT;
  2474. break;
  2475. }
  2476. if ((e & 64) === 0) { // next table
  2477. need = e;
  2478. tree_index = tindex / 3 + tree[tindex + 2];
  2479. break;
  2480. }
  2481. if ((e & 32) !== 0) { // end of block
  2482. mode = WASH;
  2483. break;
  2484. }
  2485. mode = BADCODE; // invalid code
  2486. z.msg = "invalid literal/length code";
  2487. r = Z_DATA_ERROR;
  2488. s.bitb = b;
  2489. s.bitk = k;
  2490. z.avail_in = n;
  2491. z.total_in += p - z.next_in_index;
  2492. z.next_in_index = p;
  2493. s.write = q;
  2494. return s.inflate_flush(z, r);
  2495. case LENEXT: // i: getting length extra (have base)
  2496. j = get;
  2497. while (k < (j)) {
  2498. if (n !== 0)
  2499. r = Z_OK;
  2500. else {
  2501. s.bitb = b;
  2502. s.bitk = k;
  2503. z.avail_in = n;
  2504. z.total_in += p - z.next_in_index;
  2505. z.next_in_index = p;
  2506. s.write = q;
  2507. return s.inflate_flush(z, r);
  2508. }
  2509. n--;
  2510. b |= (z.read_byte(p++) & 0xff) << k;
  2511. k += 8;
  2512. }
  2513. len += (b & inflate_mask[j]);
  2514. b >>= j;
  2515. k -= j;
  2516. need = dbits;
  2517. tree = dtree;
  2518. tree_index = dtree_index;
  2519. mode = DIST;
  2520. /* falls through */
  2521. case DIST: // i: get distance next
  2522. j = need;
  2523. while (k < (j)) {
  2524. if (n !== 0)
  2525. r = Z_OK;
  2526. else {
  2527. s.bitb = b;
  2528. s.bitk = k;
  2529. z.avail_in = n;
  2530. z.total_in += p - z.next_in_index;
  2531. z.next_in_index = p;
  2532. s.write = q;
  2533. return s.inflate_flush(z, r);
  2534. }
  2535. n--;
  2536. b |= (z.read_byte(p++) & 0xff) << k;
  2537. k += 8;
  2538. }
  2539. tindex = (tree_index + (b & inflate_mask[j])) * 3;
  2540. b >>= tree[tindex + 1];
  2541. k -= tree[tindex + 1];
  2542. e = (tree[tindex]);
  2543. if ((e & 16) !== 0) { // distance
  2544. get = e & 15;
  2545. dist = tree[tindex + 2];
  2546. mode = DISTEXT;
  2547. break;
  2548. }
  2549. if ((e & 64) === 0) { // next table
  2550. need = e;
  2551. tree_index = tindex / 3 + tree[tindex + 2];
  2552. break;
  2553. }
  2554. mode = BADCODE; // invalid code
  2555. z.msg = "invalid distance code";
  2556. r = Z_DATA_ERROR;
  2557. s.bitb = b;
  2558. s.bitk = k;
  2559. z.avail_in = n;
  2560. z.total_in += p - z.next_in_index;
  2561. z.next_in_index = p;
  2562. s.write = q;
  2563. return s.inflate_flush(z, r);
  2564. case DISTEXT: // i: getting distance extra
  2565. j = get;
  2566. while (k < (j)) {
  2567. if (n !== 0)
  2568. r = Z_OK;
  2569. else {
  2570. s.bitb = b;
  2571. s.bitk = k;
  2572. z.avail_in = n;
  2573. z.total_in += p - z.next_in_index;
  2574. z.next_in_index = p;
  2575. s.write = q;
  2576. return s.inflate_flush(z, r);
  2577. }
  2578. n--;
  2579. b |= (z.read_byte(p++) & 0xff) << k;
  2580. k += 8;
  2581. }
  2582. dist += (b & inflate_mask[j]);
  2583. b >>= j;
  2584. k -= j;
  2585. mode = COPY;
  2586. /* falls through */
  2587. case COPY: // o: copying bytes in win, waiting for space
  2588. f = q - dist;
  2589. while (f < 0) { // modulo win size-"while" instead
  2590. f += s.end; // of "if" handles invalid distances
  2591. }
  2592. while (len !== 0) {
  2593. if (m === 0) {
  2594. if (q == s.end && s.read !== 0) {
  2595. q = 0;
  2596. m = q < s.read ? s.read - q - 1 : s.end - q;
  2597. }
  2598. if (m === 0) {
  2599. s.write = q;
  2600. r = s.inflate_flush(z, r);
  2601. q = s.write;
  2602. m = q < s.read ? s.read - q - 1 : s.end - q;
  2603. if (q == s.end && s.read !== 0) {
  2604. q = 0;
  2605. m = q < s.read ? s.read - q - 1 : s.end - q;
  2606. }
  2607. if (m === 0) {
  2608. s.bitb = b;
  2609. s.bitk = k;
  2610. z.avail_in = n;
  2611. z.total_in += p - z.next_in_index;
  2612. z.next_in_index = p;
  2613. s.write = q;
  2614. return s.inflate_flush(z, r);
  2615. }
  2616. }
  2617. }
  2618. s.win[q++] = s.win[f++];
  2619. m--;
  2620. if (f == s.end)
  2621. f = 0;
  2622. len--;
  2623. }
  2624. mode = START;
  2625. break;
  2626. case LIT: // o: got literal, waiting for output space
  2627. if (m === 0) {
  2628. if (q == s.end && s.read !== 0) {
  2629. q = 0;
  2630. m = q < s.read ? s.read - q - 1 : s.end - q;
  2631. }
  2632. if (m === 0) {
  2633. s.write = q;
  2634. r = s.inflate_flush(z, r);
  2635. q = s.write;
  2636. m = q < s.read ? s.read - q - 1 : s.end - q;
  2637. if (q == s.end && s.read !== 0) {
  2638. q = 0;
  2639. m = q < s.read ? s.read - q - 1 : s.end - q;
  2640. }
  2641. if (m === 0) {
  2642. s.bitb = b;
  2643. s.bitk = k;
  2644. z.avail_in = n;
  2645. z.total_in += p - z.next_in_index;
  2646. z.next_in_index = p;
  2647. s.write = q;
  2648. return s.inflate_flush(z, r);
  2649. }
  2650. }
  2651. }
  2652. r = Z_OK;
  2653. s.win[q++] = /* (byte) */lit;
  2654. m--;
  2655. mode = START;
  2656. break;
  2657. case WASH: // o: got eob, possibly more output
  2658. if (k > 7) { // return unused byte, if any
  2659. k -= 8;
  2660. n++;
  2661. p--; // can always return one
  2662. }
  2663. s.write = q;
  2664. r = s.inflate_flush(z, r);
  2665. q = s.write;
  2666. m = q < s.read ? s.read - q - 1 : s.end - q;
  2667. if (s.read != s.write) {
  2668. s.bitb = b;
  2669. s.bitk = k;
  2670. z.avail_in = n;
  2671. z.total_in += p - z.next_in_index;
  2672. z.next_in_index = p;
  2673. s.write = q;
  2674. return s.inflate_flush(z, r);
  2675. }
  2676. mode = END;
  2677. /* falls through */
  2678. case END:
  2679. r = Z_STREAM_END;
  2680. s.bitb = b;
  2681. s.bitk = k;
  2682. z.avail_in = n;
  2683. z.total_in += p - z.next_in_index;
  2684. z.next_in_index = p;
  2685. s.write = q;
  2686. return s.inflate_flush(z, r);
  2687. case BADCODE: // x: got error
  2688. r = Z_DATA_ERROR;
  2689. s.bitb = b;
  2690. s.bitk = k;
  2691. z.avail_in = n;
  2692. z.total_in += p - z.next_in_index;
  2693. z.next_in_index = p;
  2694. s.write = q;
  2695. return s.inflate_flush(z, r);
  2696. default:
  2697. r = Z_STREAM_ERROR;
  2698. s.bitb = b;
  2699. s.bitk = k;
  2700. z.avail_in = n;
  2701. z.total_in += p - z.next_in_index;
  2702. z.next_in_index = p;
  2703. s.write = q;
  2704. return s.inflate_flush(z, r);
  2705. }
  2706. }
  2707. };
  2708. that.free = function () {
  2709. // ZFREE(z, c);
  2710. };
  2711. }
  2712. // InfBlocks
  2713. // Table for deflate from PKZIP's appnote.txt.
  2714. const border = [ // Order of the bit length code lengths
  2715. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
  2716. const TYPE = 0; // get type bits (3, including end bit)
  2717. const LENS = 1; // get lengths for stored
  2718. const STORED = 2;// processing stored block
  2719. const TABLE = 3; // get table lengths
  2720. const BTREE = 4; // get bit lengths tree for a dynamic
  2721. // block
  2722. const DTREE = 5; // get length, distance trees for a
  2723. // dynamic block
  2724. const CODES = 6; // processing fixed or dynamic block
  2725. const DRY = 7; // output remaining win bytes
  2726. const DONELOCKS = 8; // finished last block, done
  2727. const BADBLOCKS = 9; // ot a data error--stuck here
  2728. function InfBlocks(z, w) {
  2729. const that = this;
  2730. let mode = TYPE; // current inflate_block mode
  2731. let left = 0; // if STORED, bytes left to copy
  2732. let table = 0; // table lengths (14 bits)
  2733. let index = 0; // index into blens (or border)
  2734. let blens; // bit lengths of codes
  2735. const bb = [0]; // bit length tree depth
  2736. const tb = [0]; // bit length decoding tree
  2737. const codes = new InfCodes(); // if CODES, current state
  2738. let last = 0; // true if this block is the last block
  2739. let hufts = new Int32Array(MANY * 3); // single malloc for tree space
  2740. const check = 0; // check on output
  2741. const inftree = new InfTree();
  2742. that.bitk = 0; // bits in bit buffer
  2743. that.bitb = 0; // bit buffer
  2744. that.win = new Uint8Array(w); // sliding win
  2745. that.end = w; // one byte after sliding win
  2746. that.read = 0; // win read pointer
  2747. that.write = 0; // win write pointer
  2748. that.reset = function (z, c) {
  2749. if (c)
  2750. c[0] = check;
  2751. // if (mode == BTREE || mode == DTREE) {
  2752. // }
  2753. if (mode == CODES) {
  2754. codes.free(z);
  2755. }
  2756. mode = TYPE;
  2757. that.bitk = 0;
  2758. that.bitb = 0;
  2759. that.read = that.write = 0;
  2760. };
  2761. that.reset(z, null);
  2762. // copy as much as possible from the sliding win to the output area
  2763. that.inflate_flush = function (z, r) {
  2764. let n;
  2765. let p;
  2766. let q;
  2767. // local copies of source and destination pointers
  2768. p = z.next_out_index;
  2769. q = that.read;
  2770. // compute number of bytes to copy as far as end of win
  2771. n = /* (int) */((q <= that.write ? that.write : that.end) - q);
  2772. if (n > z.avail_out)
  2773. n = z.avail_out;
  2774. if (n !== 0 && r == Z_BUF_ERROR)
  2775. r = Z_OK;
  2776. // update counters
  2777. z.avail_out -= n;
  2778. z.total_out += n;
  2779. // copy as far as end of win
  2780. z.next_out.set(that.win.subarray(q, q + n), p);
  2781. p += n;
  2782. q += n;
  2783. // see if more to copy at beginning of win
  2784. if (q == that.end) {
  2785. // wrap pointers
  2786. q = 0;
  2787. if (that.write == that.end)
  2788. that.write = 0;
  2789. // compute bytes to copy
  2790. n = that.write - q;
  2791. if (n > z.avail_out)
  2792. n = z.avail_out;
  2793. if (n !== 0 && r == Z_BUF_ERROR)
  2794. r = Z_OK;
  2795. // update counters
  2796. z.avail_out -= n;
  2797. z.total_out += n;
  2798. // copy
  2799. z.next_out.set(that.win.subarray(q, q + n), p);
  2800. p += n;
  2801. q += n;
  2802. }
  2803. // update pointers
  2804. z.next_out_index = p;
  2805. that.read = q;
  2806. // done
  2807. return r;
  2808. };
  2809. that.proc = function (z, r) {
  2810. let t; // temporary storage
  2811. let b; // bit buffer
  2812. let k; // bits in bit buffer
  2813. let p; // input data pointer
  2814. let n; // bytes available there
  2815. let q; // output win write pointer
  2816. let m; // bytes to end of win or read pointer
  2817. let i;
  2818. // copy input/output information to locals (UPDATE macro restores)
  2819. // {
  2820. p = z.next_in_index;
  2821. n = z.avail_in;
  2822. b = that.bitb;
  2823. k = that.bitk;
  2824. // }
  2825. // {
  2826. q = that.write;
  2827. m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
  2828. // }
  2829. // process input based on current state
  2830. // DEBUG dtree
  2831. // eslint-disable-next-line no-constant-condition
  2832. while (true) {
  2833. let bl, bd, tl, td, bl_, bd_, tl_, td_;
  2834. switch (mode) {
  2835. case TYPE:
  2836. while (k < (3)) {
  2837. if (n !== 0) {
  2838. r = Z_OK;
  2839. } else {
  2840. that.bitb = b;
  2841. that.bitk = k;
  2842. z.avail_in = n;
  2843. z.total_in += p - z.next_in_index;
  2844. z.next_in_index = p;
  2845. that.write = q;
  2846. return that.inflate_flush(z, r);
  2847. }
  2848. n--;
  2849. b |= (z.read_byte(p++) & 0xff) << k;
  2850. k += 8;
  2851. }
  2852. t = /* (int) */(b & 7);
  2853. last = t & 1;
  2854. switch (t >>> 1) {
  2855. case 0: // stored
  2856. // {
  2857. b >>>= (3);
  2858. k -= (3);
  2859. // }
  2860. t = k & 7; // go to byte boundary
  2861. // {
  2862. b >>>= (t);
  2863. k -= (t);
  2864. // }
  2865. mode = LENS; // get length of stored block
  2866. break;
  2867. case 1: // fixed
  2868. // {
  2869. bl = []; // new Array(1);
  2870. bd = []; // new Array(1);
  2871. tl = [[]]; // new Array(1);
  2872. td = [[]]; // new Array(1);
  2873. InfTree.inflate_trees_fixed(bl, bd, tl, td);
  2874. codes.init(bl[0], bd[0], tl[0], 0, td[0], 0);
  2875. // }
  2876. // {
  2877. b >>>= (3);
  2878. k -= (3);
  2879. // }
  2880. mode = CODES;
  2881. break;
  2882. case 2: // dynamic
  2883. // {
  2884. b >>>= (3);
  2885. k -= (3);
  2886. // }
  2887. mode = TABLE;
  2888. break;
  2889. case 3: // illegal
  2890. // {
  2891. b >>>= (3);
  2892. k -= (3);
  2893. // }
  2894. mode = BADBLOCKS;
  2895. z.msg = "invalid block type";
  2896. r = Z_DATA_ERROR;
  2897. that.bitb = b;
  2898. that.bitk = k;
  2899. z.avail_in = n;
  2900. z.total_in += p - z.next_in_index;
  2901. z.next_in_index = p;
  2902. that.write = q;
  2903. return that.inflate_flush(z, r);
  2904. }
  2905. break;
  2906. case LENS:
  2907. while (k < (32)) {
  2908. if (n !== 0) {
  2909. r = Z_OK;
  2910. } else {
  2911. that.bitb = b;
  2912. that.bitk = k;
  2913. z.avail_in = n;
  2914. z.total_in += p - z.next_in_index;
  2915. z.next_in_index = p;
  2916. that.write = q;
  2917. return that.inflate_flush(z, r);
  2918. }
  2919. n--;
  2920. b |= (z.read_byte(p++) & 0xff) << k;
  2921. k += 8;
  2922. }
  2923. if ((((~b) >>> 16) & 0xffff) != (b & 0xffff)) {
  2924. mode = BADBLOCKS;
  2925. z.msg = "invalid stored block lengths";
  2926. r = Z_DATA_ERROR;
  2927. that.bitb = b;
  2928. that.bitk = k;
  2929. z.avail_in = n;
  2930. z.total_in += p - z.next_in_index;
  2931. z.next_in_index = p;
  2932. that.write = q;
  2933. return that.inflate_flush(z, r);
  2934. }
  2935. left = (b & 0xffff);
  2936. b = k = 0; // dump bits
  2937. mode = left !== 0 ? STORED : (last !== 0 ? DRY : TYPE);
  2938. break;
  2939. case STORED:
  2940. if (n === 0) {
  2941. that.bitb = b;
  2942. that.bitk = k;
  2943. z.avail_in = n;
  2944. z.total_in += p - z.next_in_index;
  2945. z.next_in_index = p;
  2946. that.write = q;
  2947. return that.inflate_flush(z, r);
  2948. }
  2949. if (m === 0) {
  2950. if (q == that.end && that.read !== 0) {
  2951. q = 0;
  2952. m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
  2953. }
  2954. if (m === 0) {
  2955. that.write = q;
  2956. r = that.inflate_flush(z, r);
  2957. q = that.write;
  2958. m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
  2959. if (q == that.end && that.read !== 0) {
  2960. q = 0;
  2961. m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
  2962. }
  2963. if (m === 0) {
  2964. that.bitb = b;
  2965. that.bitk = k;
  2966. z.avail_in = n;
  2967. z.total_in += p - z.next_in_index;
  2968. z.next_in_index = p;
  2969. that.write = q;
  2970. return that.inflate_flush(z, r);
  2971. }
  2972. }
  2973. }
  2974. r = Z_OK;
  2975. t = left;
  2976. if (t > n)
  2977. t = n;
  2978. if (t > m)
  2979. t = m;
  2980. that.win.set(z.read_buf(p, t), q);
  2981. p += t;
  2982. n -= t;
  2983. q += t;
  2984. m -= t;
  2985. if ((left -= t) !== 0)
  2986. break;
  2987. mode = last !== 0 ? DRY : TYPE;
  2988. break;
  2989. case TABLE:
  2990. while (k < (14)) {
  2991. if (n !== 0) {
  2992. r = Z_OK;
  2993. } else {
  2994. that.bitb = b;
  2995. that.bitk = k;
  2996. z.avail_in = n;
  2997. z.total_in += p - z.next_in_index;
  2998. z.next_in_index = p;
  2999. that.write = q;
  3000. return that.inflate_flush(z, r);
  3001. }
  3002. n--;
  3003. b |= (z.read_byte(p++) & 0xff) << k;
  3004. k += 8;
  3005. }
  3006. table = t = (b & 0x3fff);
  3007. if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29) {
  3008. mode = BADBLOCKS;
  3009. z.msg = "too many length or distance symbols";
  3010. r = Z_DATA_ERROR;
  3011. that.bitb = b;
  3012. that.bitk = k;
  3013. z.avail_in = n;
  3014. z.total_in += p - z.next_in_index;
  3015. z.next_in_index = p;
  3016. that.write = q;
  3017. return that.inflate_flush(z, r);
  3018. }
  3019. t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
  3020. if (!blens || blens.length < t) {
  3021. blens = []; // new Array(t);
  3022. } else {
  3023. for (i = 0; i < t; i++) {
  3024. blens[i] = 0;
  3025. }
  3026. }
  3027. // {
  3028. b >>>= (14);
  3029. k -= (14);
  3030. // }
  3031. index = 0;
  3032. mode = BTREE;
  3033. /* falls through */
  3034. case BTREE:
  3035. while (index < 4 + (table >>> 10)) {
  3036. while (k < (3)) {
  3037. if (n !== 0) {
  3038. r = Z_OK;
  3039. } else {
  3040. that.bitb = b;
  3041. that.bitk = k;
  3042. z.avail_in = n;
  3043. z.total_in += p - z.next_in_index;
  3044. z.next_in_index = p;
  3045. that.write = q;
  3046. return that.inflate_flush(z, r);
  3047. }
  3048. n--;
  3049. b |= (z.read_byte(p++) & 0xff) << k;
  3050. k += 8;
  3051. }
  3052. blens[border[index++]] = b & 7;
  3053. // {
  3054. b >>>= (3);
  3055. k -= (3);
  3056. // }
  3057. }
  3058. while (index < 19) {
  3059. blens[border[index++]] = 0;
  3060. }
  3061. bb[0] = 7;
  3062. t = inftree.inflate_trees_bits(blens, bb, tb, hufts, z);
  3063. if (t != Z_OK) {
  3064. r = t;
  3065. if (r == Z_DATA_ERROR) {
  3066. blens = null;
  3067. mode = BADBLOCKS;
  3068. }
  3069. that.bitb = b;
  3070. that.bitk = k;
  3071. z.avail_in = n;
  3072. z.total_in += p - z.next_in_index;
  3073. z.next_in_index = p;
  3074. that.write = q;
  3075. return that.inflate_flush(z, r);
  3076. }
  3077. index = 0;
  3078. mode = DTREE;
  3079. /* falls through */
  3080. case DTREE:
  3081. // eslint-disable-next-line no-constant-condition
  3082. while (true) {
  3083. t = table;
  3084. if (index >= 258 + (t & 0x1f) + ((t >> 5) & 0x1f)) {
  3085. break;
  3086. }
  3087. let j, c;
  3088. t = bb[0];
  3089. while (k < (t)) {
  3090. if (n !== 0) {
  3091. r = Z_OK;
  3092. } else {
  3093. that.bitb = b;
  3094. that.bitk = k;
  3095. z.avail_in = n;
  3096. z.total_in += p - z.next_in_index;
  3097. z.next_in_index = p;
  3098. that.write = q;
  3099. return that.inflate_flush(z, r);
  3100. }
  3101. n--;
  3102. b |= (z.read_byte(p++) & 0xff) << k;
  3103. k += 8;
  3104. }
  3105. // if (tb[0] == -1) {
  3106. // System.err.println("null...");
  3107. // }
  3108. t = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 1];
  3109. c = hufts[(tb[0] + (b & inflate_mask[t])) * 3 + 2];
  3110. if (c < 16) {
  3111. b >>>= (t);
  3112. k -= (t);
  3113. blens[index++] = c;
  3114. } else { // c == 16..18
  3115. i = c == 18 ? 7 : c - 14;
  3116. j = c == 18 ? 11 : 3;
  3117. while (k < (t + i)) {
  3118. if (n !== 0) {
  3119. r = Z_OK;
  3120. } else {
  3121. that.bitb = b;
  3122. that.bitk = k;
  3123. z.avail_in = n;
  3124. z.total_in += p - z.next_in_index;
  3125. z.next_in_index = p;
  3126. that.write = q;
  3127. return that.inflate_flush(z, r);
  3128. }
  3129. n--;
  3130. b |= (z.read_byte(p++) & 0xff) << k;
  3131. k += 8;
  3132. }
  3133. b >>>= (t);
  3134. k -= (t);
  3135. j += (b & inflate_mask[i]);
  3136. b >>>= (i);
  3137. k -= (i);
  3138. i = index;
  3139. t = table;
  3140. if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) || (c == 16 && i < 1)) {
  3141. blens = null;
  3142. mode = BADBLOCKS;
  3143. z.msg = "invalid bit length repeat";
  3144. r = Z_DATA_ERROR;
  3145. that.bitb = b;
  3146. that.bitk = k;
  3147. z.avail_in = n;
  3148. z.total_in += p - z.next_in_index;
  3149. z.next_in_index = p;
  3150. that.write = q;
  3151. return that.inflate_flush(z, r);
  3152. }
  3153. c = c == 16 ? blens[i - 1] : 0;
  3154. do {
  3155. blens[i++] = c;
  3156. } while (--j !== 0);
  3157. index = i;
  3158. }
  3159. }
  3160. tb[0] = -1;
  3161. // {
  3162. bl_ = []; // new Array(1);
  3163. bd_ = []; // new Array(1);
  3164. tl_ = []; // new Array(1);
  3165. td_ = []; // new Array(1);
  3166. bl_[0] = 9; // must be <= 9 for lookahead assumptions
  3167. bd_[0] = 6; // must be <= 9 for lookahead assumptions
  3168. t = table;
  3169. t = inftree.inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f), blens, bl_, bd_, tl_, td_, hufts, z);
  3170. if (t != Z_OK) {
  3171. if (t == Z_DATA_ERROR) {
  3172. blens = null;
  3173. mode = BADBLOCKS;
  3174. }
  3175. r = t;
  3176. that.bitb = b;
  3177. that.bitk = k;
  3178. z.avail_in = n;
  3179. z.total_in += p - z.next_in_index;
  3180. z.next_in_index = p;
  3181. that.write = q;
  3182. return that.inflate_flush(z, r);
  3183. }
  3184. codes.init(bl_[0], bd_[0], hufts, tl_[0], hufts, td_[0]);
  3185. // }
  3186. mode = CODES;
  3187. /* falls through */
  3188. case CODES:
  3189. that.bitb = b;
  3190. that.bitk = k;
  3191. z.avail_in = n;
  3192. z.total_in += p - z.next_in_index;
  3193. z.next_in_index = p;
  3194. that.write = q;
  3195. if ((r = codes.proc(that, z, r)) != Z_STREAM_END) {
  3196. return that.inflate_flush(z, r);
  3197. }
  3198. r = Z_OK;
  3199. codes.free(z);
  3200. p = z.next_in_index;
  3201. n = z.avail_in;
  3202. b = that.bitb;
  3203. k = that.bitk;
  3204. q = that.write;
  3205. m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
  3206. if (last === 0) {
  3207. mode = TYPE;
  3208. break;
  3209. }
  3210. mode = DRY;
  3211. /* falls through */
  3212. case DRY:
  3213. that.write = q;
  3214. r = that.inflate_flush(z, r);
  3215. q = that.write;
  3216. m = /* (int) */(q < that.read ? that.read - q - 1 : that.end - q);
  3217. if (that.read != that.write) {
  3218. that.bitb = b;
  3219. that.bitk = k;
  3220. z.avail_in = n;
  3221. z.total_in += p - z.next_in_index;
  3222. z.next_in_index = p;
  3223. that.write = q;
  3224. return that.inflate_flush(z, r);
  3225. }
  3226. mode = DONELOCKS;
  3227. /* falls through */
  3228. case DONELOCKS:
  3229. r = Z_STREAM_END;
  3230. that.bitb = b;
  3231. that.bitk = k;
  3232. z.avail_in = n;
  3233. z.total_in += p - z.next_in_index;
  3234. z.next_in_index = p;
  3235. that.write = q;
  3236. return that.inflate_flush(z, r);
  3237. case BADBLOCKS:
  3238. r = Z_DATA_ERROR;
  3239. that.bitb = b;
  3240. that.bitk = k;
  3241. z.avail_in = n;
  3242. z.total_in += p - z.next_in_index;
  3243. z.next_in_index = p;
  3244. that.write = q;
  3245. return that.inflate_flush(z, r);
  3246. default:
  3247. r = Z_STREAM_ERROR;
  3248. that.bitb = b;
  3249. that.bitk = k;
  3250. z.avail_in = n;
  3251. z.total_in += p - z.next_in_index;
  3252. z.next_in_index = p;
  3253. that.write = q;
  3254. return that.inflate_flush(z, r);
  3255. }
  3256. }
  3257. };
  3258. that.free = function (z) {
  3259. that.reset(z, null);
  3260. that.win = null;
  3261. hufts = null;
  3262. // ZFREE(z, s);
  3263. };
  3264. that.set_dictionary = function (d, start, n) {
  3265. that.win.set(d.subarray(start, start + n), 0);
  3266. that.read = that.write = n;
  3267. };
  3268. // Returns true if inflate is currently at the end of a block generated
  3269. // by Z_SYNC_FLUSH or Z_FULL_FLUSH.
  3270. that.sync_point = function () {
  3271. return mode == LENS ? 1 : 0;
  3272. };
  3273. }
  3274. // Inflate
  3275. // preset dictionary flag in zlib header
  3276. const PRESET_DICT = 0x20;
  3277. const Z_DEFLATED = 8;
  3278. const METHOD = 0; // waiting for method byte
  3279. const FLAG = 1; // waiting for flag byte
  3280. const DICT4 = 2; // four dictionary check bytes to go
  3281. const DICT3 = 3; // three dictionary check bytes to go
  3282. const DICT2 = 4; // two dictionary check bytes to go
  3283. const DICT1 = 5; // one dictionary check byte to go
  3284. const DICT0 = 6; // waiting for inflateSetDictionary
  3285. const BLOCKS = 7; // decompressing blocks
  3286. const DONE = 12; // finished check, done
  3287. const BAD = 13; // got an error--stay here
  3288. const mark = [0, 0, 0xff, 0xff];
  3289. function Inflate$1() {
  3290. const that = this;
  3291. that.mode = 0; // current inflate mode
  3292. // mode dependent information
  3293. that.method = 0; // if FLAGS, method byte
  3294. // if CHECK, check values to compare
  3295. that.was = [0]; // new Array(1); // computed check value
  3296. that.need = 0; // stream check value
  3297. // if BAD, inflateSync's marker bytes count
  3298. that.marker = 0;
  3299. // mode independent information
  3300. that.wbits = 0; // log2(win size) (8..15, defaults to 15)
  3301. // this.blocks; // current inflate_blocks state
  3302. function inflateReset(z) {
  3303. if (!z || !z.istate)
  3304. return Z_STREAM_ERROR;
  3305. z.total_in = z.total_out = 0;
  3306. z.msg = null;
  3307. z.istate.mode = BLOCKS;
  3308. z.istate.blocks.reset(z, null);
  3309. return Z_OK;
  3310. }
  3311. that.inflateEnd = function (z) {
  3312. if (that.blocks)
  3313. that.blocks.free(z);
  3314. that.blocks = null;
  3315. // ZFREE(z, z->state);
  3316. return Z_OK;
  3317. };
  3318. that.inflateInit = function (z, w) {
  3319. z.msg = null;
  3320. that.blocks = null;
  3321. // set win size
  3322. if (w < 8 || w > 15) {
  3323. that.inflateEnd(z);
  3324. return Z_STREAM_ERROR;
  3325. }
  3326. that.wbits = w;
  3327. z.istate.blocks = new InfBlocks(z, 1 << w);
  3328. // reset state
  3329. inflateReset(z);
  3330. return Z_OK;
  3331. };
  3332. that.inflate = function (z, f) {
  3333. let r;
  3334. let b;
  3335. if (!z || !z.istate || !z.next_in)
  3336. return Z_STREAM_ERROR;
  3337. const istate = z.istate;
  3338. f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
  3339. r = Z_BUF_ERROR;
  3340. // eslint-disable-next-line no-constant-condition
  3341. while (true) {
  3342. switch (istate.mode) {
  3343. case METHOD:
  3344. if (z.avail_in === 0)
  3345. return r;
  3346. r = f;
  3347. z.avail_in--;
  3348. z.total_in++;
  3349. if (((istate.method = z.read_byte(z.next_in_index++)) & 0xf) != Z_DEFLATED) {
  3350. istate.mode = BAD;
  3351. z.msg = "unknown compression method";
  3352. istate.marker = 5; // can't try inflateSync
  3353. break;
  3354. }
  3355. if ((istate.method >> 4) + 8 > istate.wbits) {
  3356. istate.mode = BAD;
  3357. z.msg = "invalid win size";
  3358. istate.marker = 5; // can't try inflateSync
  3359. break;
  3360. }
  3361. istate.mode = FLAG;
  3362. /* falls through */
  3363. case FLAG:
  3364. if (z.avail_in === 0)
  3365. return r;
  3366. r = f;
  3367. z.avail_in--;
  3368. z.total_in++;
  3369. b = (z.read_byte(z.next_in_index++)) & 0xff;
  3370. if ((((istate.method << 8) + b) % 31) !== 0) {
  3371. istate.mode = BAD;
  3372. z.msg = "incorrect header check";
  3373. istate.marker = 5; // can't try inflateSync
  3374. break;
  3375. }
  3376. if ((b & PRESET_DICT) === 0) {
  3377. istate.mode = BLOCKS;
  3378. break;
  3379. }
  3380. istate.mode = DICT4;
  3381. /* falls through */
  3382. case DICT4:
  3383. if (z.avail_in === 0)
  3384. return r;
  3385. r = f;
  3386. z.avail_in--;
  3387. z.total_in++;
  3388. istate.need = ((z.read_byte(z.next_in_index++) & 0xff) << 24) & 0xff000000;
  3389. istate.mode = DICT3;
  3390. /* falls through */
  3391. case DICT3:
  3392. if (z.avail_in === 0)
  3393. return r;
  3394. r = f;
  3395. z.avail_in--;
  3396. z.total_in++;
  3397. istate.need += ((z.read_byte(z.next_in_index++) & 0xff) << 16) & 0xff0000;
  3398. istate.mode = DICT2;
  3399. /* falls through */
  3400. case DICT2:
  3401. if (z.avail_in === 0)
  3402. return r;
  3403. r = f;
  3404. z.avail_in--;
  3405. z.total_in++;
  3406. istate.need += ((z.read_byte(z.next_in_index++) & 0xff) << 8) & 0xff00;
  3407. istate.mode = DICT1;
  3408. /* falls through */
  3409. case DICT1:
  3410. if (z.avail_in === 0)
  3411. return r;
  3412. r = f;
  3413. z.avail_in--;
  3414. z.total_in++;
  3415. istate.need += (z.read_byte(z.next_in_index++) & 0xff);
  3416. istate.mode = DICT0;
  3417. return Z_NEED_DICT;
  3418. case DICT0:
  3419. istate.mode = BAD;
  3420. z.msg = "need dictionary";
  3421. istate.marker = 0; // can try inflateSync
  3422. return Z_STREAM_ERROR;
  3423. case BLOCKS:
  3424. r = istate.blocks.proc(z, r);
  3425. if (r == Z_DATA_ERROR) {
  3426. istate.mode = BAD;
  3427. istate.marker = 0; // can try inflateSync
  3428. break;
  3429. }
  3430. if (r == Z_OK) {
  3431. r = f;
  3432. }
  3433. if (r != Z_STREAM_END) {
  3434. return r;
  3435. }
  3436. r = f;
  3437. istate.blocks.reset(z, istate.was);
  3438. istate.mode = DONE;
  3439. /* falls through */
  3440. case DONE:
  3441. z.avail_in = 0;
  3442. return Z_STREAM_END;
  3443. case BAD:
  3444. return Z_DATA_ERROR;
  3445. default:
  3446. return Z_STREAM_ERROR;
  3447. }
  3448. }
  3449. };
  3450. that.inflateSetDictionary = function (z, dictionary, dictLength) {
  3451. let index = 0, length = dictLength;
  3452. if (!z || !z.istate || z.istate.mode != DICT0)
  3453. return Z_STREAM_ERROR;
  3454. const istate = z.istate;
  3455. if (length >= (1 << istate.wbits)) {
  3456. length = (1 << istate.wbits) - 1;
  3457. index = dictLength - length;
  3458. }
  3459. istate.blocks.set_dictionary(dictionary, index, length);
  3460. istate.mode = BLOCKS;
  3461. return Z_OK;
  3462. };
  3463. that.inflateSync = function (z) {
  3464. let n; // number of bytes to look at
  3465. let p; // pointer to bytes
  3466. let m; // number of marker bytes found in a row
  3467. let r, w; // temporaries to save total_in and total_out
  3468. // set up
  3469. if (!z || !z.istate)
  3470. return Z_STREAM_ERROR;
  3471. const istate = z.istate;
  3472. if (istate.mode != BAD) {
  3473. istate.mode = BAD;
  3474. istate.marker = 0;
  3475. }
  3476. if ((n = z.avail_in) === 0)
  3477. return Z_BUF_ERROR;
  3478. p = z.next_in_index;
  3479. m = istate.marker;
  3480. // search
  3481. while (n !== 0 && m < 4) {
  3482. if (z.read_byte(p) == mark[m]) {
  3483. m++;
  3484. } else if (z.read_byte(p) !== 0) {
  3485. m = 0;
  3486. } else {
  3487. m = 4 - m;
  3488. }
  3489. p++;
  3490. n--;
  3491. }
  3492. // restore
  3493. z.total_in += p - z.next_in_index;
  3494. z.next_in_index = p;
  3495. z.avail_in = n;
  3496. istate.marker = m;
  3497. // return no joy or set up to restart on a new block
  3498. if (m != 4) {
  3499. return Z_DATA_ERROR;
  3500. }
  3501. r = z.total_in;
  3502. w = z.total_out;
  3503. inflateReset(z);
  3504. z.total_in = r;
  3505. z.total_out = w;
  3506. istate.mode = BLOCKS;
  3507. return Z_OK;
  3508. };
  3509. // Returns true if inflate is currently at the end of a block generated
  3510. // by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
  3511. // implementation to provide an additional safety check. PPP uses
  3512. // Z_SYNC_FLUSH
  3513. // but removes the length bytes of the resulting empty stored block. When
  3514. // decompressing, PPP checks that at the end of input packet, inflate is
  3515. // waiting for these length bytes.
  3516. that.inflateSyncPoint = function (z) {
  3517. if (!z || !z.istate || !z.istate.blocks)
  3518. return Z_STREAM_ERROR;
  3519. return z.istate.blocks.sync_point();
  3520. };
  3521. }
  3522. // ZStream
  3523. function ZStream() {
  3524. }
  3525. ZStream.prototype = {
  3526. inflateInit: function (bits) {
  3527. const that = this;
  3528. that.istate = new Inflate$1();
  3529. if (!bits)
  3530. bits = MAX_BITS;
  3531. return that.istate.inflateInit(that, bits);
  3532. },
  3533. inflate: function (f) {
  3534. const that = this;
  3535. if (!that.istate)
  3536. return Z_STREAM_ERROR;
  3537. return that.istate.inflate(that, f);
  3538. },
  3539. inflateEnd: function () {
  3540. const that = this;
  3541. if (!that.istate)
  3542. return Z_STREAM_ERROR;
  3543. const ret = that.istate.inflateEnd(that);
  3544. that.istate = null;
  3545. return ret;
  3546. },
  3547. inflateSync: function () {
  3548. const that = this;
  3549. if (!that.istate)
  3550. return Z_STREAM_ERROR;
  3551. return that.istate.inflateSync(that);
  3552. },
  3553. inflateSetDictionary: function (dictionary, dictLength) {
  3554. const that = this;
  3555. if (!that.istate)
  3556. return Z_STREAM_ERROR;
  3557. return that.istate.inflateSetDictionary(that, dictionary, dictLength);
  3558. },
  3559. read_byte: function (start) {
  3560. const that = this;
  3561. return that.next_in[start];
  3562. },
  3563. read_buf: function (start, size) {
  3564. const that = this;
  3565. return that.next_in.subarray(start, start + size);
  3566. }
  3567. };
  3568. // Inflater
  3569. function ZipInflate(options) {
  3570. const that = this;
  3571. const z = new ZStream();
  3572. const bufsize = options && options.chunkSize ? Math.floor(options.chunkSize * 2) : 128 * 1024;
  3573. const flush = Z_NO_FLUSH;
  3574. const buf = new Uint8Array(bufsize);
  3575. let nomoreinput = false;
  3576. z.inflateInit();
  3577. z.next_out = buf;
  3578. that.append = function (data, onprogress) {
  3579. const buffers = [];
  3580. let err, array, lastIndex = 0, bufferIndex = 0, bufferSize = 0;
  3581. if (data.length === 0)
  3582. return;
  3583. z.next_in_index = 0;
  3584. z.next_in = data;
  3585. z.avail_in = data.length;
  3586. do {
  3587. z.next_out_index = 0;
  3588. z.avail_out = bufsize;
  3589. if ((z.avail_in === 0) && (!nomoreinput)) { // if buffer is empty and more input is available, refill it
  3590. z.next_in_index = 0;
  3591. nomoreinput = true;
  3592. }
  3593. err = z.inflate(flush);
  3594. if (nomoreinput && (err === Z_BUF_ERROR)) {
  3595. if (z.avail_in !== 0)
  3596. throw new Error("inflating: bad input");
  3597. } else if (err !== Z_OK && err !== Z_STREAM_END)
  3598. throw new Error("inflating: " + z.msg);
  3599. if ((nomoreinput || err === Z_STREAM_END) && (z.avail_in === data.length))
  3600. throw new Error("inflating: bad input");
  3601. if (z.next_out_index)
  3602. if (z.next_out_index === bufsize)
  3603. buffers.push(new Uint8Array(buf));
  3604. else
  3605. buffers.push(buf.slice(0, z.next_out_index));
  3606. bufferSize += z.next_out_index;
  3607. if (onprogress && z.next_in_index > 0 && z.next_in_index != lastIndex) {
  3608. onprogress(z.next_in_index);
  3609. lastIndex = z.next_in_index;
  3610. }
  3611. } while (z.avail_in > 0 || z.avail_out === 0);
  3612. if (buffers.length > 1) {
  3613. array = new Uint8Array(bufferSize);
  3614. buffers.forEach(function (chunk) {
  3615. array.set(chunk, bufferIndex);
  3616. bufferIndex += chunk.length;
  3617. });
  3618. } else {
  3619. array = buffers[0] || new Uint8Array(0);
  3620. }
  3621. return array;
  3622. };
  3623. that.flush = function () {
  3624. z.inflateEnd();
  3625. };
  3626. }
  3627. /*
  3628. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  3629. Redistribution and use in source and binary forms, with or without
  3630. modification, are permitted provided that the following conditions are met:
  3631. 1. Redistributions of source code must retain the above copyright notice,
  3632. this list of conditions and the following disclaimer.
  3633. 2. Redistributions in binary form must reproduce the above copyright
  3634. notice, this list of conditions and the following disclaimer in
  3635. the documentation and/or other materials provided with the distribution.
  3636. 3. The names of the authors may not be used to endorse or promote products
  3637. derived from this software without specific prior written permission.
  3638. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  3639. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  3640. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  3641. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  3642. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3643. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  3644. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3645. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3646. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3647. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3648. */
  3649. /* global navigator */
  3650. const DEFAULT_CONFIGURATION = {
  3651. chunkSize: 512 * 1024,
  3652. maxWorkers: (typeof navigator != "undefined" && navigator.hardwareConcurrency) || 2,
  3653. terminateWorkerTimeout: 5000,
  3654. useWebWorkers: true,
  3655. workerScripts: undefined
  3656. };
  3657. const config = Object.assign({}, DEFAULT_CONFIGURATION);
  3658. function getConfiguration() {
  3659. return config;
  3660. }
  3661. function configure(configuration) {
  3662. if (configuration.baseURL !== undefined) {
  3663. config.baseURL = configuration.baseURL;
  3664. }
  3665. if (configuration.chunkSize !== undefined) {
  3666. config.chunkSize = configuration.chunkSize;
  3667. }
  3668. if (configuration.maxWorkers !== undefined) {
  3669. config.maxWorkers = configuration.maxWorkers;
  3670. }
  3671. if (configuration.terminateWorkerTimeout !== undefined) {
  3672. config.terminateWorkerTimeout = configuration.terminateWorkerTimeout;
  3673. }
  3674. if (configuration.useWebWorkers !== undefined) {
  3675. config.useWebWorkers = configuration.useWebWorkers;
  3676. }
  3677. if (configuration.Deflate !== undefined) {
  3678. config.Deflate = configuration.Deflate;
  3679. }
  3680. if (configuration.Inflate !== undefined) {
  3681. config.Inflate = configuration.Inflate;
  3682. }
  3683. if (configuration.workerScripts !== undefined) {
  3684. if (configuration.workerScripts.deflate) {
  3685. if (!Array.isArray(configuration.workerScripts.deflate)) {
  3686. throw new Error("workerScripts.deflate must be an array");
  3687. }
  3688. if (!config.workerScripts) {
  3689. config.workerScripts = {};
  3690. }
  3691. config.workerScripts.deflate = configuration.workerScripts.deflate;
  3692. }
  3693. if (configuration.workerScripts.inflate) {
  3694. if (!Array.isArray(configuration.workerScripts.inflate)) {
  3695. throw new Error("workerScripts.inflate must be an array");
  3696. }
  3697. if (!config.workerScripts) {
  3698. config.workerScripts = {};
  3699. }
  3700. config.workerScripts.inflate = configuration.workerScripts.inflate;
  3701. }
  3702. }
  3703. }
  3704. var t=t=>{if("function"==typeof URL.createObjectURL){const e=()=>URL.createObjectURL(new Blob(['const{Array:t,Object:e,Math:n,Error:r,Uint8Array:i,Uint16Array:o,Uint32Array:s,Int32Array:f,DataView:c,TextEncoder:l,crypto:u,postMessage:a}=globalThis,w=[];for(let t=0;256>t;t++){let e=t;for(let t=0;8>t;t++)1&e?e=e>>>1^3988292384:e>>>=1;w[t]=e}class h{constructor(t){this.t=t||-1}append(t){let e=0|this.t;for(let n=0,r=0|t.length;r>n;n++)e=e>>>8^w[255&(e^t[n])];this.t=e}get(){return~this.t}}const d={concat(t,e){if(0===t.length||0===e.length)return t.concat(e);const n=t[t.length-1],r=d.i(n);return 32===r?t.concat(e):d.o(e,r,0|n,t.slice(0,t.length-1))},l(t){const e=t.length;if(0===e)return 0;const n=t[e-1];return 32*(e-1)+d.i(n)},u(t,e){if(32*t.length<e)return t;const r=(t=t.slice(0,n.ceil(e/32))).length;return e&=31,r>0&&e&&(t[r-1]=d.h(e,t[r-1]&2147483648>>e-1,1)),t},h:(t,e,n)=>32===t?e:(n?0|e:e<<32-t)+1099511627776*t,i:t=>n.round(t/1099511627776)||32,o(t,e,n,r){for(void 0===r&&(r=[]);e>=32;e-=32)r.push(n),n=0;if(0===e)return r.concat(t);for(let i=0;i<t.length;i++)r.push(n|t[i]>>>e),n=t[i]<<32-e;const i=t.length?t[t.length-1]:0,o=d.i(i);return r.push(d.h(e+o&31,e+o>32?n:r.pop(),1)),r}},p={p:{k(t){const e=d.l(t)/8,n=new i(e);let r;for(let i=0;e>i;i++)0==(3&i)&&(r=t[i/4]),n[i]=r>>>24,r<<=8;return n},g(t){const e=[];let n,r=0;for(n=0;n<t.length;n++)r=r<<8|t[n],3==(3&n)&&(e.push(r),r=0);return 3&n&&e.push(d.h(8*(3&n),r)),e}}},y={v:function(t){t?(this.m=t.m.slice(0),this.S=t.S.slice(0),this._=t._):this.reset()}};y.v.prototype={blockSize:512,reset:function(){const t=this;return t.m=this.I.slice(0),t.S=[],t._=0,t},update:function(t){const e=this;"string"==typeof t&&(t=p.A.g(t));const n=e.S=d.concat(e.S,t),i=e._,o=e._=i+d.l(t);if(o>9007199254740991)throw new r("Cannot hash more than 2^53 - 1 bits");const f=new s(n);let c=0;for(let t=e.blockSize+i-(e.blockSize+i&e.blockSize-1);o>=t;t+=e.blockSize)e.C(f.subarray(16*c,16*(c+1))),c+=1;return n.splice(0,16*c),e},V:function(){const t=this;let e=t.S;const r=t.m;e=d.concat(e,[d.h(1,1)]);for(let t=e.length+2;15&t;t++)e.push(0);for(e.push(n.floor(t._/4294967296)),e.push(0|t._);e.length;)t.C(e.splice(0,16));return t.reset(),r},I:[1732584193,4023233417,2562383102,271733878,3285377520],B:[1518500249,1859775393,2400959708,3395469782],D:(t,e,n,r)=>t>19?t>39?t>59?t>79?void 0:e^n^r:e&n|e&r|n&r:e^n^r:e&n|~e&r,U:(t,e)=>e<<t|e>>>32-t,C:function(e){const r=this,i=r.m,o=t(80);for(let t=0;16>t;t++)o[t]=e[t];let s=i[0],f=i[1],c=i[2],l=i[3],u=i[4];for(let t=0;79>=t;t++){16>t||(o[t]=r.U(1,o[t-3]^o[t-8]^o[t-14]^o[t-16]));const e=r.U(5,s)+r.D(t,f,c,l)+u+o[t]+r.B[n.floor(t/20)]|0;u=l,l=c,c=r.U(30,f),f=s,s=e}i[0]=i[0]+s|0,i[1]=i[1]+f|0,i[2]=i[2]+c|0,i[3]=i[3]+l|0,i[4]=i[4]+u|0}};const b={getRandomValues(t){const e=new s(t.buffer),r=t=>{let e=987654321;const r=4294967295;return()=>(e=36969*(65535&e)+(e>>16)&r,(((e<<16)+(t=18e3*(65535&t)+(t>>16)&r)&r)/4294967296+.5)*(n.random()>.5?1:-1))};for(let i,o=0;o<t.length;o+=4){const t=r(4294967296*(i||n.random()));i=987654071*t(),e[o/4]=4294967296*t()|0}return t}},k={importKey:t=>new k.M(p.p.g(t)),P(t,e,n,i){if(n=n||1e4,0>i||0>n)throw new r("invalid params to pbkdf2");const o=1+(i>>5)<<2;let s,f,l,u,a;const w=new ArrayBuffer(o),h=new c(w);let y=0;const b=d;for(e=p.p.g(e),a=1;(o||1)>y;a++){for(s=f=t.encrypt(b.concat(e,[a])),l=1;n>l;l++)for(f=t.encrypt(f),u=0;u<f.length;u++)s[u]^=f[u];for(l=0;(o||1)>y&&l<s.length;l++)h.setInt32(y,s[l]),y+=4}return w.slice(0,i/8)},M:class{constructor(t){const e=this,n=e.R=y.v,r=[[],[]],i=n.prototype.blockSize/32;e.H=[new n,new n],t.length>i&&(t=n.hash(t));for(let e=0;i>e;e++)r[0][e]=909522486^t[e],r[1][e]=1549556828^t[e];e.H[0].update(r[0]),e.H[1].update(r[1]),e.K=new n(e.H[0])}reset(){const t=this;t.K=new t.R(t.H[0]),t.L=!1}update(t){this.L=!0,this.K.update(t)}digest(){const t=this,e=t.K.V(),n=new t.R(t.H[1]).update(e).V();return t.reset(),n}encrypt(t){if(this.L)throw new r("encrypt on already updated hmac called!");return this.update(t),this.digest(t)}}},g={name:"PBKDF2"},v=e.assign({hash:{name:"HMAC"}},g),m=e.assign({iterations:1e3,hash:{name:"SHA-1"}},g),S=["deriveBits"],z=[8,12,16],_=[16,24,32],I=[0,0,0,0],A=void 0!==u,C=A&&void 0!==u.subtle,V=p.p,B=class{constructor(t){const e=this;e.T=[[[],[],[],[],[]],[[],[],[],[],[]]],e.T[0][0][0]||e.j();const n=e.T[0][4],i=e.T[1],o=t.length;let s,f,c,l=1;if(4!==o&&6!==o&&8!==o)throw new r("invalid aes key size");for(e.B=[f=t.slice(0),c=[]],s=o;4*o+28>s;s++){let t=f[s-1];(s%o==0||8===o&&s%o==4)&&(t=n[t>>>24]<<24^n[t>>16&255]<<16^n[t>>8&255]<<8^n[255&t],s%o==0&&(t=t<<8^t>>>24^l<<24,l=l<<1^283*(l>>7))),f[s]=f[s-o]^t}for(let t=0;s;t++,s--){const e=f[3&t?s:s-4];c[t]=4>=s||4>t?e:i[0][n[e>>>24]]^i[1][n[e>>16&255]]^i[2][n[e>>8&255]]^i[3][n[255&e]]}}encrypt(t){return this.F(t,0)}decrypt(t){return this.F(t,1)}j(){const t=this.T[0],e=this.T[1],n=t[4],r=e[4],i=[],o=[];let s,f,c,l;for(let t=0;256>t;t++)o[(i[t]=t<<1^283*(t>>7))^t]=t;for(let u=s=0;!n[u];u^=f||1,s=o[s]||1){let o=s^s<<1^s<<2^s<<3^s<<4;o=o>>8^255&o^99,n[u]=o,r[o]=u,l=i[c=i[f=i[u]]];let a=16843009*l^65537*c^257*f^16843008*u,w=257*i[o]^16843008*o;for(let n=0;4>n;n++)t[n][u]=w=w<<24^w>>>8,e[n][o]=a=a<<24^a>>>8}for(let n=0;5>n;n++)t[n]=t[n].slice(0),e[n]=e[n].slice(0)}F(t,e){if(4!==t.length)throw new r("invalid aes block size");const n=this.B[e],i=n.length/4-2,o=[0,0,0,0],s=this.T[e],f=s[0],c=s[1],l=s[2],u=s[3],a=s[4];let w,h,d,p=t[0]^n[0],y=t[e?3:1]^n[1],b=t[2]^n[2],k=t[e?1:3]^n[3],g=4;for(let t=0;i>t;t++)w=f[p>>>24]^c[y>>16&255]^l[b>>8&255]^u[255&k]^n[g],h=f[y>>>24]^c[b>>16&255]^l[k>>8&255]^u[255&p]^n[g+1],d=f[b>>>24]^c[k>>16&255]^l[p>>8&255]^u[255&y]^n[g+2],k=f[k>>>24]^c[p>>16&255]^l[y>>8&255]^u[255&b]^n[g+3],g+=4,p=w,y=h,b=d;for(let t=0;4>t;t++)o[e?3&-t:t]=a[p>>>24]<<24^a[y>>16&255]<<16^a[b>>8&255]<<8^a[255&k]^n[g++],w=p,p=y,y=b,b=k,k=w;return o}},E=class{constructor(t,e){this.O=t,this.W=e,this.q=e}reset(){this.q=this.W}update(t){return this.G(this.O,t,this.q)}J(t){if(255==(t>>24&255)){let e=t>>16&255,n=t>>8&255,r=255&t;255===e?(e=0,255===n?(n=0,255===r?r=0:++r):++n):++e,t=0,t+=e<<16,t+=n<<8,t+=r}else t+=1<<24;return t}N(t){0===(t[0]=this.J(t[0]))&&(t[1]=this.J(t[1]))}G(t,e,n){let r;if(!(r=e.length))return[];const i=d.l(e);for(let i=0;r>i;i+=4){this.N(n);const r=t.encrypt(n);e[i]^=r[0],e[i+1]^=r[1],e[i+2]^=r[2],e[i+3]^=r[3]}return d.u(e,i)}},D=k.M;class U{constructor(t,n,r){e.assign(this,{password:t,signed:n,X:r-1,Y:new i(0)})}async append(e){const n=this;if(n.password){const i=K(e,0,z[n.X]+2);await(async(t,e,n)=>{await R(t,n,K(e,0,z[t.X]));const i=K(e,z[t.X]),o=t.keys.passwordVerification;if(o[0]!=i[0]||o[1]!=i[1])throw new r("Invalid pasword")})(n,i,n.password),n.password=null,n.Z=new E(new B(n.keys.key),t.from(I)),n.$=new D(n.keys.tt),e=K(e,z[n.X]+2)}return P(n,e,new i(e.length-10-(e.length-10)%16),0,10,!0)}flush(){const t=this,e=t.Y,n=K(e,0,e.length-10),r=K(e,e.length-10);let o=new i(0);if(n.length){const e=V.g(n);t.$.update(e);const r=t.Z.update(e);o=V.k(r)}let s=!0;if(t.signed){const e=K(V.k(t.$.digest()),0,10);for(let t=0;10>t;t++)e[t]!=r[t]&&(s=!1)}return{valid:s,data:o}}}class M{constructor(t,n){e.assign(this,{password:t,X:n-1,Y:new i(0)})}async append(e){const n=this;let r=new i(0);n.password&&(r=await(async(t,e)=>{const n=(r=new i(z[t.X]),A&&"function"==typeof u.getRandomValues?u.getRandomValues(r):b.getRandomValues(r));var r;return await R(t,e,n),H(n,t.keys.passwordVerification)})(n,n.password),n.password=null,n.Z=new E(new B(n.keys.key),t.from(I)),n.$=new D(n.keys.tt));const o=new i(r.length+e.length-e.length%16);return o.set(r,0),P(n,e,o,r.length,0)}flush(){const t=this;let e=new i(0);if(t.Y.length){const n=t.Z.update(V.g(t.Y));t.$.update(n),e=V.k(n)}const n=K(V.k(t.$.digest()),0,10);return{data:H(e,n),signature:n}}}function P(t,e,n,r,o,s){const f=e.length-o;let c;for(t.Y.length&&(e=H(t.Y,e),n=((t,e)=>{if(e&&e>t.length){const n=t;(t=new i(e)).set(n,0)}return t})(n,f-f%16)),c=0;f-16>=c;c+=16){const i=V.g(K(e,c,c+16));s&&t.$.update(i);const o=t.Z.update(i);s||t.$.update(o),n.set(V.k(o),c+r)}return t.Y=K(e,c),n}async function R(t,n,r){const o=(t=>{if(void 0===l){const e=new i((t=unescape(encodeURIComponent(t))).length);for(let n=0;n<e.length;n++)e[n]=t.charCodeAt(n);return e}return(new l).encode(t)})(n),s=await((t,e,n,r,i)=>A&&C&&"function"==typeof u.subtle.importKey?u.subtle.importKey("raw",e,n,!1,i):k.importKey(e))(0,o,v,0,S),f=await(async(t,e,n)=>A&&C&&"function"==typeof u.subtle.deriveBits?await u.subtle.deriveBits(t,e,n):k.P(e,t.salt,m.iterations,n))(e.assign({salt:r},m),s,8*(2*_[t.X]+2)),c=new i(f);t.keys={key:V.g(K(c,0,_[t.X])),tt:V.g(K(c,_[t.X],2*_[t.X])),passwordVerification:K(c,2*_[t.X])}}function H(t,e){let n=t;return t.length+e.length&&(n=new i(t.length+e.length),n.set(t,0),n.set(e,t.length)),n}function K(t,e,n){return t.subarray(e,n)}class L{constructor(t,n){e.assign(this,{password:t,passwordVerification:n}),F(this,t)}append(t){const e=this;if(e.password){const n=j(e,t.subarray(0,12));if(e.password=null,n[11]!=e.passwordVerification)throw new r("Invalid pasword");t=t.subarray(12)}return j(e,t)}flush(){return{valid:!0,data:new i(0)}}}class T{constructor(t,n){e.assign(this,{password:t,passwordVerification:n}),F(this,t)}append(t){const e=this;let n,r;if(e.password){e.password=null;const o=u.getRandomValues(new i(12));o[11]=e.passwordVerification,n=new i(t.length+o.length),n.set(x(e,o),0),r=12}else n=new i(t.length),r=0;return n.set(x(e,t),r),n}flush(){return{data:new i(0)}}}function j(t,e){const n=new i(e.length);for(let r=0;r<e.length;r++)n[r]=W(t)^e[r],O(t,n[r]);return n}function x(t,e){const n=new i(e.length);for(let r=0;r<e.length;r++)n[r]=W(t)^e[r],O(t,e[r]);return n}function F(t,e){t.keys=[305419896,591751049,878082192],t.et=new h(t.keys[0]),t.nt=new h(t.keys[2]);for(let n=0;n<e.length;n++)O(t,e.charCodeAt(n))}function O(t,e){t.et.append([e]),t.keys[0]=~t.et.get(),t.keys[1]=G(t.keys[1]+q(t.keys[0])),t.keys[1]=G(n.imul(t.keys[1],134775813)+1),t.nt.append([t.keys[1]>>>24]),t.keys[2]=~t.nt.get()}function W(t){const e=2|t.keys[2];return q(n.imul(e,1^e)>>>8)}function q(t){return 255&t}function G(t){return 4294967295&t}class J{constructor(t,{signature:n,password:r,signed:i,compressed:o,zipCrypto:s,passwordVerification:f,encryptionStrength:c},{rt:l}){const u=!!r;e.assign(this,{signature:n,encrypted:u,signed:i,compressed:o,it:o&&new t({rt:l}),ot:i&&new h,zipCrypto:s,decrypt:u&&s?new L(r,f):new U(r,i,c)})}async append(t){const e=this;return e.encrypted&&t.length&&(t=await e.decrypt.append(t)),e.compressed&&t.length&&(t=await e.it.append(t)),(!e.encrypted||e.zipCrypto)&&e.signed&&t.length&&e.ot.append(t),t}async flush(){const t=this;let e,n=new i(0);if(t.encrypted){const e=t.decrypt.flush();if(!e.valid)throw new r("Invalid signature");n=e.data}if((!t.encrypted||t.zipCrypto)&&t.signed){const n=new c(new i(4).buffer);if(e=t.ot.get(),n.setUint32(0,e),t.signature!=n.getUint32(0,!1))throw new r("Invalid signature")}return t.compressed&&(n=await t.it.append(n)||new i(0),await t.it.flush()),{data:n,signature:e}}}class N{constructor(t,{encrypted:n,signed:r,compressed:i,level:o,zipCrypto:s,password:f,passwordVerification:c,encryptionStrength:l},{rt:u}){e.assign(this,{encrypted:n,signed:r,compressed:i,st:i&&new t({level:o||5,rt:u}),ot:r&&new h,zipCrypto:s,encrypt:n&&s?new T(f,c):new M(f,l)})}async append(t){const e=this;let n=t;return e.compressed&&t.length&&(n=await e.st.append(t)),e.encrypted&&n.length&&(n=await e.encrypt.append(n)),(!e.encrypted||e.zipCrypto)&&e.signed&&t.length&&e.ot.append(t),n}async flush(){const t=this;let e,n=new i(0);if(t.compressed&&(n=await t.st.flush()||new i(0)),t.encrypted){n=await t.encrypt.append(n);const r=t.encrypt.flush();e=r.signature;const o=new i(n.length+r.data.length);o.set(n,0),o.set(r.data,n.length),n=o}return t.encrypted&&!t.zipCrypto||!t.signed||(e=t.ot.get()),{data:n,signature:e}}}const Q={init(t){t.scripts&&t.scripts.length&&importScripts.apply(void 0,t.scripts);const e=t.options;let n;self.initCodec&&self.initCodec(),e.codecType.startsWith("deflate")?n=self.Deflate:e.codecType.startsWith("inflate")&&(n=self.Inflate),X=((t,e,n)=>e.codecType.startsWith("deflate")?new N(t,e,n):e.codecType.startsWith("inflate")?new J(t,e,n):void 0)(n,e,t.config)},append:async t=>({data:await X.append(t.data)}),flush:()=>X.flush()};let X;function Y(e){return Z(e.map((([e,n])=>new t(e).fill(n,0,e))))}function Z(e){return e.reduce(((e,n)=>e.concat(t.isArray(n)?Z(n):n)),[])}addEventListener("message",(async t=>{const e=t.data,n=e.type,r=Q[n];if(r)try{e.data&&(e.data=new i(e.data));const t=await r(e)||{};if(t.type=n,t.data)try{t.data=t.data.buffer,a(t,[t.data])}catch(e){a(t)}else a(t)}catch(t){a({type:n,error:{message:t.message,stack:t.stack}})}}));const $=[0,1,2,3].concat(...Y([[2,4],[2,5],[4,6],[4,7],[8,8],[8,9],[16,10],[16,11],[32,12],[32,13],[64,14],[64,15],[2,0],[1,16],[1,17],[2,18],[2,19],[4,20],[4,21],[8,22],[8,23],[16,24],[16,25],[32,26],[32,27],[64,28],[64,29]]));function tt(){const t=this;function e(t,e){let n=0;do{n|=1&t,t>>>=1,n<<=1}while(--e>0);return n>>>1}t.ft=r=>{const i=t.ct,o=t.ut.lt,s=t.ut.wt;let f,c,l,u=-1;for(r.ht=0,r.dt=573,f=0;s>f;f++)0!==i[2*f]?(r.yt[++r.ht]=u=f,r.bt[f]=0):i[2*f+1]=0;for(;2>r.ht;)l=r.yt[++r.ht]=2>u?++u:0,i[2*l]=1,r.bt[l]=0,r.kt--,o&&(r.gt-=o[2*l+1]);for(t.vt=u,f=n.floor(r.ht/2);f>=1;f--)r.St(i,f);l=s;do{f=r.yt[1],r.yt[1]=r.yt[r.ht--],r.St(i,1),c=r.yt[1],r.yt[--r.dt]=f,r.yt[--r.dt]=c,i[2*l]=i[2*f]+i[2*c],r.bt[l]=n.max(r.bt[f],r.bt[c])+1,i[2*f+1]=i[2*c+1]=l,r.yt[1]=l++,r.St(i,1)}while(r.ht>=2);r.yt[--r.dt]=r.yt[1],(e=>{const n=t.ct,r=t.ut.lt,i=t.ut.zt,o=t.ut._t,s=t.ut.It;let f,c,l,u,a,w,h=0;for(u=0;15>=u;u++)e.At[u]=0;for(n[2*e.yt[e.dt]+1]=0,f=e.dt+1;573>f;f++)c=e.yt[f],u=n[2*n[2*c+1]+1]+1,u>s&&(u=s,h++),n[2*c+1]=u,c>t.vt||(e.At[u]++,a=0,o>c||(a=i[c-o]),w=n[2*c],e.kt+=w*(u+a),r&&(e.gt+=w*(r[2*c+1]+a)));if(0!==h){do{for(u=s-1;0===e.At[u];)u--;e.At[u]--,e.At[u+1]+=2,e.At[s]--,h-=2}while(h>0);for(u=s;0!==u;u--)for(c=e.At[u];0!==c;)l=e.yt[--f],l>t.vt||(n[2*l+1]!=u&&(e.kt+=(u-n[2*l+1])*n[2*l],n[2*l+1]=u),c--)}})(r),((t,n,r)=>{const i=[];let o,s,f,c=0;for(o=1;15>=o;o++)i[o]=c=c+r[o-1]<<1;for(s=0;n>=s;s++)f=t[2*s+1],0!==f&&(t[2*s]=e(i[f]++,f))})(i,t.vt,r.At)}}function et(t,e,n,r,i){const o=this;o.lt=t,o.zt=e,o._t=n,o.wt=r,o.It=i}tt.Ct=[0,1,2,3,4,5,6,7].concat(...Y([[2,8],[2,9],[2,10],[2,11],[4,12],[4,13],[4,14],[4,15],[8,16],[8,17],[8,18],[8,19],[16,20],[16,21],[16,22],[16,23],[32,24],[32,25],[32,26],[31,27],[1,28]])),tt.Vt=[0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224,0],tt.Bt=[0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,1024,1536,2048,3072,4096,6144,8192,12288,16384,24576],tt.Et=t=>256>t?$[t]:$[256+(t>>>7)],tt.Dt=[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],tt.Ut=[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],tt.Mt=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],tt.Pt=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];const nt=Y([[144,8],[112,9],[24,7],[8,8]]);et.Rt=Z([12,140,76,204,44,172,108,236,28,156,92,220,60,188,124,252,2,130,66,194,34,162,98,226,18,146,82,210,50,178,114,242,10,138,74,202,42,170,106,234,26,154,90,218,58,186,122,250,6,134,70,198,38,166,102,230,22,150,86,214,54,182,118,246,14,142,78,206,46,174,110,238,30,158,94,222,62,190,126,254,1,129,65,193,33,161,97,225,17,145,81,209,49,177,113,241,9,137,73,201,41,169,105,233,25,153,89,217,57,185,121,249,5,133,69,197,37,165,101,229,21,149,85,213,53,181,117,245,13,141,77,205,45,173,109,237,29,157,93,221,61,189,125,253,19,275,147,403,83,339,211,467,51,307,179,435,115,371,243,499,11,267,139,395,75,331,203,459,43,299,171,427,107,363,235,491,27,283,155,411,91,347,219,475,59,315,187,443,123,379,251,507,7,263,135,391,71,327,199,455,39,295,167,423,103,359,231,487,23,279,151,407,87,343,215,471,55,311,183,439,119,375,247,503,15,271,143,399,79,335,207,463,47,303,175,431,111,367,239,495,31,287,159,415,95,351,223,479,63,319,191,447,127,383,255,511,0,64,32,96,16,80,48,112,8,72,40,104,24,88,56,120,4,68,36,100,20,84,52,116,3,131,67,195,35,163,99,227].map(((t,e)=>[t,nt[e]])));const rt=Y([[30,5]]);function it(t,e,n,r,i){const o=this;o.Ht=t,o.Kt=e,o.Lt=n,o.Tt=r,o.jt=i}et.xt=Z([0,16,8,24,4,20,12,28,2,18,10,26,6,22,14,30,1,17,9,25,5,21,13,29,3,19,11,27,7,23].map(((t,e)=>[t,rt[e]]))),et.Ft=new et(et.Rt,tt.Dt,257,286,15),et.Ot=new et(et.xt,tt.Ut,0,30,15),et.Wt=new et(null,tt.Mt,0,19,7);const ot=[new it(0,0,0,0,0),new it(4,4,8,4,1),new it(4,5,16,8,1),new it(4,6,32,32,1),new it(4,4,16,16,2),new it(8,16,32,32,2),new it(8,16,128,128,2),new it(8,32,128,256,2),new it(32,128,258,1024,2),new it(32,258,258,4096,2)],st=["need dictionary","stream end","","","stream error","data error","","buffer error","",""];function ft(t,e,n,r){const i=t[2*e],o=t[2*n];return o>i||i==o&&r[e]<=r[n]}function ct(){const t=this;let e,r,s,f,c,l,u,a,w,h,d,p,y,b,k,g,v,m,S,z,_,I,A,C,V,B,E,D,U,M,P,R,H;const K=new tt,L=new tt,T=new tt;let j,x,F,O,W,q;function G(){let e;for(e=0;286>e;e++)P[2*e]=0;for(e=0;30>e;e++)R[2*e]=0;for(e=0;19>e;e++)H[2*e]=0;P[512]=1,t.kt=t.gt=0,x=F=0}function J(t,e){let n,r=-1,i=t[1],o=0,s=7,f=4;0===i&&(s=138,f=3),t[2*(e+1)+1]=65535;for(let c=0;e>=c;c++)n=i,i=t[2*(c+1)+1],++o<s&&n==i||(f>o?H[2*n]+=o:0!==n?(n!=r&&H[2*n]++,H[32]++):o>10?H[36]++:H[34]++,o=0,r=n,0===i?(s=138,f=3):n==i?(s=6,f=3):(s=7,f=4))}function N(e){t.qt[t.pending++]=e}function Q(t){N(255&t),N(t>>>8&255)}function X(t,e){let n;const r=e;q>16-r?(n=t,W|=n<<q&65535,Q(W),W=n>>>16-q,q+=r-16):(W|=t<<q&65535,q+=r)}function Y(t,e){const n=2*t;X(65535&e[n],65535&e[n+1])}function Z(t,e){let n,r,i=-1,o=t[1],s=0,f=7,c=4;for(0===o&&(f=138,c=3),n=0;e>=n;n++)if(r=o,o=t[2*(n+1)+1],++s>=f||r!=o){if(c>s)do{Y(r,H)}while(0!=--s);else 0!==r?(r!=i&&(Y(r,H),s--),Y(16,H),X(s-3,2)):s>10?(Y(18,H),X(s-11,7)):(Y(17,H),X(s-3,3));s=0,i=r,0===o?(f=138,c=3):r==o?(f=6,c=3):(f=7,c=4)}}function $(){16==q?(Q(W),W=0,q=0):8>q||(N(255&W),W>>>=8,q-=8)}function nt(e,r){let i,o,s;if(t.Gt[x]=e,t.Jt[x]=255&r,x++,0===e?P[2*r]++:(F++,e--,P[2*(tt.Ct[r]+256+1)]++,R[2*tt.Et(e)]++),0==(8191&x)&&E>2){for(i=8*x,o=_-v,s=0;30>s;s++)i+=R[2*s]*(5+tt.Ut[s]);if(i>>>=3,F<n.floor(x/2)&&i<n.floor(o/2))return!0}return x==j-1}function rt(e,n){let r,i,o,s,f=0;if(0!==x)do{r=t.Gt[f],i=t.Jt[f],f++,0===r?Y(i,e):(o=tt.Ct[i],Y(o+256+1,e),s=tt.Dt[o],0!==s&&(i-=tt.Vt[o],X(i,s)),r--,o=tt.Et(r),Y(o,n),s=tt.Ut[o],0!==s&&(r-=tt.Bt[o],X(r,s)))}while(x>f);Y(256,e),O=e[513]}function it(){q>8?Q(W):q>0&&N(255&W),W=0,q=0}function ct(e,n,r){X(0+(r?1:0),3),((e,n)=>{it(),O=8,Q(n),Q(~n),t.qt.set(a.subarray(e,e+n),t.pending),t.pending+=n})(e,n)}function lt(n){((e,n,r)=>{let i,o,s=0;E>0?(K.ft(t),L.ft(t),s=(()=>{let e;for(J(P,K.vt),J(R,L.vt),T.ft(t),e=18;e>=3&&0===H[2*tt.Pt[e]+1];e--);return t.kt+=14+3*(e+1),e})(),i=t.kt+3+7>>>3,o=t.gt+3+7>>>3,o>i||(i=o)):i=o=n+5,n+4>i||-1==e?o==i?(X(2+(r?1:0),3),rt(et.Rt,et.xt)):(X(4+(r?1:0),3),((t,e,n)=>{let r;for(X(t-257,5),X(e-1,5),X(n-4,4),r=0;n>r;r++)X(H[2*tt.Pt[r]+1],3);Z(P,t-1),Z(R,e-1)})(K.vt+1,L.vt+1,s+1),rt(P,R)):ct(e,n,r),G(),r&&it()})(0>v?-1:v,_-v,n),v=_,e.Nt()}function ut(){let t,n,r,i;do{if(i=w-A-_,0===i&&0===_&&0===A)i=c;else if(-1==i)i--;else if(_>=c+c-262){a.set(a.subarray(c,c+c),0),I-=c,_-=c,v-=c,t=y,r=t;do{n=65535&d[--r],d[r]=c>n?0:n-c}while(0!=--t);t=c,r=t;do{n=65535&h[--r],h[r]=c>n?0:n-c}while(0!=--t);i+=c}if(0===e.Qt)return;t=e.Xt(a,_+A,i),A+=t,3>A||(p=255&a[_],p=(p<<g^255&a[_+1])&k)}while(262>A&&0!==e.Qt)}function at(t){let e,n,r=V,i=_,o=C;const s=_>c-262?_-(c-262):0;let f=M;const l=u,w=_+258;let d=a[i+o-1],p=a[i+o];U>C||(r>>=2),f>A&&(f=A);do{if(e=t,a[e+o]==p&&a[e+o-1]==d&&a[e]==a[i]&&a[++e]==a[i+1]){i+=2,e++;do{}while(a[++i]==a[++e]&&a[++i]==a[++e]&&a[++i]==a[++e]&&a[++i]==a[++e]&&a[++i]==a[++e]&&a[++i]==a[++e]&&a[++i]==a[++e]&&a[++i]==a[++e]&&w>i);if(n=258-(w-i),i=w-258,n>o){if(I=t,o=n,n>=f)break;d=a[i+o-1],p=a[i+o]}}}while((t=65535&h[t&l])>s&&0!=--r);return o>A?A:o}t.bt=[],t.At=[],t.yt=[],P=[],R=[],H=[],t.St=(e,n)=>{const r=t.yt,i=r[n];let o=n<<1;for(;o<=t.ht&&(o<t.ht&&ft(e,r[o+1],r[o],t.bt)&&o++,!ft(e,i,r[o],t.bt));)r[n]=r[o],n=o,o<<=1;r[n]=i},t.Yt=(e,S,I,x,F,J)=>(x||(x=8),F||(F=8),J||(J=0),e.Zt=null,-1==S&&(S=6),1>F||F>9||8!=x||9>I||I>15||0>S||S>9||0>J||J>2?-2:(e.$t=t,l=I,c=1<<l,u=c-1,b=F+7,y=1<<b,k=y-1,g=n.floor((b+3-1)/3),a=new i(2*c),h=[],d=[],j=1<<F+6,t.qt=new i(4*j),s=4*j,t.Gt=new o(j),t.Jt=new i(j),E=S,D=J,(e=>(e.te=e.ee=0,e.Zt=null,t.pending=0,t.ne=0,r=113,f=0,K.ct=P,K.ut=et.Ft,L.ct=R,L.ut=et.Ot,T.ct=H,T.ut=et.Wt,W=0,q=0,O=8,G(),(()=>{w=2*c,d[y-1]=0;for(let t=0;y-1>t;t++)d[t]=0;B=ot[E].Kt,U=ot[E].Ht,M=ot[E].Lt,V=ot[E].Tt,_=0,v=0,A=0,m=C=2,z=0,p=0})(),0))(e))),t.re=()=>42!=r&&113!=r&&666!=r?-2:(t.Jt=null,t.Gt=null,t.qt=null,d=null,h=null,a=null,t.$t=null,113==r?-3:0),t.ie=(t,e,n)=>{let r=0;return-1==e&&(e=6),0>e||e>9||0>n||n>2?-2:(ot[E].jt!=ot[e].jt&&0!==t.te&&(r=t.st(1)),E!=e&&(E=e,B=ot[E].Kt,U=ot[E].Ht,M=ot[E].Lt,V=ot[E].Tt),D=n,r)},t.oe=(t,e,n)=>{let i,o=n,s=0;if(!e||42!=r)return-2;if(3>o)return 0;for(o>c-262&&(o=c-262,s=n-o),a.set(e.subarray(s,s+o),0),_=o,v=o,p=255&a[0],p=(p<<g^255&a[1])&k,i=0;o-3>=i;i++)p=(p<<g^255&a[i+2])&k,h[i&u]=d[p],d[p]=i;return 0},t.st=(n,i)=>{let o,w,b,V,U;if(i>4||0>i)return-2;if(!n.se||!n.fe&&0!==n.Qt||666==r&&4!=i)return n.Zt=st[4],-2;if(0===n.ce)return n.Zt=st[7],-5;var M;if(e=n,V=f,f=i,42==r&&(w=8+(l-8<<4)<<8,b=(E-1&255)>>1,b>3&&(b=3),w|=b<<6,0!==_&&(w|=32),w+=31-w%31,r=113,N((M=w)>>8&255),N(255&M)),0!==t.pending){if(e.Nt(),0===e.ce)return f=-1,0}else if(0===e.Qt&&V>=i&&4!=i)return e.Zt=st[7],-5;if(666==r&&0!==e.Qt)return n.Zt=st[7],-5;if(0!==e.Qt||0!==A||0!=i&&666!=r){switch(U=-1,ot[E].jt){case 0:U=(t=>{let n,r=65535;for(r>s-5&&(r=s-5);;){if(1>=A){if(ut(),0===A&&0==t)return 0;if(0===A)break}if(_+=A,A=0,n=v+r,(0===_||_>=n)&&(A=_-n,_=n,lt(!1),0===e.ce))return 0;if(_-v>=c-262&&(lt(!1),0===e.ce))return 0}return lt(4==t),0===e.ce?4==t?2:0:4==t?3:1})(i);break;case 1:U=(t=>{let n,r=0;for(;;){if(262>A){if(ut(),262>A&&0==t)return 0;if(0===A)break}if(3>A||(p=(p<<g^255&a[_+2])&k,r=65535&d[p],h[_&u]=d[p],d[p]=_),0===r||(_-r&65535)>c-262||2!=D&&(m=at(r)),3>m)n=nt(0,255&a[_]),A--,_++;else if(n=nt(_-I,m-3),A-=m,m>B||3>A)_+=m,m=0,p=255&a[_],p=(p<<g^255&a[_+1])&k;else{m--;do{_++,p=(p<<g^255&a[_+2])&k,r=65535&d[p],h[_&u]=d[p],d[p]=_}while(0!=--m);_++}if(n&&(lt(!1),0===e.ce))return 0}return lt(4==t),0===e.ce?4==t?2:0:4==t?3:1})(i);break;case 2:U=(t=>{let n,r,i=0;for(;;){if(262>A){if(ut(),262>A&&0==t)return 0;if(0===A)break}if(3>A||(p=(p<<g^255&a[_+2])&k,i=65535&d[p],h[_&u]=d[p],d[p]=_),C=m,S=I,m=2,0!==i&&B>C&&c-262>=(_-i&65535)&&(2!=D&&(m=at(i)),5>=m&&(1==D||3==m&&_-I>4096)&&(m=2)),3>C||m>C)if(0!==z){if(n=nt(0,255&a[_-1]),n&&lt(!1),_++,A--,0===e.ce)return 0}else z=1,_++,A--;else{r=_+A-3,n=nt(_-1-S,C-3),A-=C-1,C-=2;do{++_>r||(p=(p<<g^255&a[_+2])&k,i=65535&d[p],h[_&u]=d[p],d[p]=_)}while(0!=--C);if(z=0,m=2,_++,n&&(lt(!1),0===e.ce))return 0}}return 0!==z&&(n=nt(0,255&a[_-1]),z=0),lt(4==t),0===e.ce?4==t?2:0:4==t?3:1})(i)}if(2!=U&&3!=U||(r=666),0==U||2==U)return 0===e.ce&&(f=-1),0;if(1==U){if(1==i)X(2,3),Y(256,et.Rt),$(),9>1+O+10-q&&(X(2,3),Y(256,et.Rt),$()),O=7;else if(ct(0,0,!1),3==i)for(o=0;y>o;o++)d[o]=0;if(e.Nt(),0===e.ce)return f=-1,0}}return 4!=i?0:1}}function lt(){const t=this;t.le=0,t.ue=0,t.Qt=0,t.te=0,t.ce=0,t.ee=0}function ut(t){const e=new lt,o=(s=t&&t.rt?t.rt:65536)+5*(n.floor(s/16383)+1);var s;const f=new i(o);let c=t?t.level:-1;void 0===c&&(c=-1),e.Yt(c),e.se=f,this.append=(t,n)=>{let s,c,l=0,u=0,a=0;const w=[];if(t.length){e.le=0,e.fe=t,e.Qt=t.length;do{if(e.ue=0,e.ce=o,s=e.st(0),0!=s)throw new r("deflating: "+e.Zt);e.ue&&(e.ue==o?w.push(new i(f)):w.push(f.slice(0,e.ue))),a+=e.ue,n&&e.le>0&&e.le!=l&&(n(e.le),l=e.le)}while(e.Qt>0||0===e.ce);return w.length>1?(c=new i(a),w.forEach((t=>{c.set(t,u),u+=t.length}))):c=w[0]||new i(0),c}},this.flush=()=>{let t,n,s=0,c=0;const l=[];do{if(e.ue=0,e.ce=o,t=e.st(4),1!=t&&0!=t)throw new r("deflating: "+e.Zt);o-e.ce>0&&l.push(f.slice(0,e.ue)),c+=e.ue}while(e.Qt>0||0===e.ce);return e.re(),n=new i(c),l.forEach((t=>{n.set(t,s),s+=t.length})),n}}lt.prototype={Yt:function(t,e){const n=this;return n.$t=new ct,e||(e=15),n.$t.Yt(n,t,e)},st:function(t){const e=this;return e.$t?e.$t.st(e,t):-2},re:function(){const t=this;if(!t.$t)return-2;const e=t.$t.re();return t.$t=null,e},ie:function(t,e){const n=this;return n.$t?n.$t.ie(n,t,e):-2},oe:function(t,e){const n=this;return n.$t?n.$t.oe(n,t,e):-2},Xt:function(t,e,n){const r=this;let i=r.Qt;return i>n&&(i=n),0===i?0:(r.Qt-=i,t.set(r.fe.subarray(r.le,r.le+i),e),r.le+=i,r.te+=i,i)},Nt:function(){const t=this;let e=t.$t.pending;e>t.ce&&(e=t.ce),0!==e&&(t.se.set(t.$t.qt.subarray(t.$t.ne,t.$t.ne+e),t.ue),t.ue+=e,t.$t.ne+=e,t.ee+=e,t.ce-=e,t.$t.pending-=e,0===t.$t.pending&&(t.$t.ne=0))}};const at=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],wt=[96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,192,80,7,10,0,8,96,0,8,32,0,9,160,0,8,0,0,8,128,0,8,64,0,9,224,80,7,6,0,8,88,0,8,24,0,9,144,83,7,59,0,8,120,0,8,56,0,9,208,81,7,17,0,8,104,0,8,40,0,9,176,0,8,8,0,8,136,0,8,72,0,9,240,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,200,81,7,13,0,8,100,0,8,36,0,9,168,0,8,4,0,8,132,0,8,68,0,9,232,80,7,8,0,8,92,0,8,28,0,9,152,84,7,83,0,8,124,0,8,60,0,9,216,82,7,23,0,8,108,0,8,44,0,9,184,0,8,12,0,8,140,0,8,76,0,9,248,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,196,81,7,11,0,8,98,0,8,34,0,9,164,0,8,2,0,8,130,0,8,66,0,9,228,80,7,7,0,8,90,0,8,26,0,9,148,84,7,67,0,8,122,0,8,58,0,9,212,82,7,19,0,8,106,0,8,42,0,9,180,0,8,10,0,8,138,0,8,74,0,9,244,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,204,81,7,15,0,8,102,0,8,38,0,9,172,0,8,6,0,8,134,0,8,70,0,9,236,80,7,9,0,8,94,0,8,30,0,9,156,84,7,99,0,8,126,0,8,62,0,9,220,82,7,27,0,8,110,0,8,46,0,9,188,0,8,14,0,8,142,0,8,78,0,9,252,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,194,80,7,10,0,8,97,0,8,33,0,9,162,0,8,1,0,8,129,0,8,65,0,9,226,80,7,6,0,8,89,0,8,25,0,9,146,83,7,59,0,8,121,0,8,57,0,9,210,81,7,17,0,8,105,0,8,41,0,9,178,0,8,9,0,8,137,0,8,73,0,9,242,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,202,81,7,13,0,8,101,0,8,37,0,9,170,0,8,5,0,8,133,0,8,69,0,9,234,80,7,8,0,8,93,0,8,29,0,9,154,84,7,83,0,8,125,0,8,61,0,9,218,82,7,23,0,8,109,0,8,45,0,9,186,0,8,13,0,8,141,0,8,77,0,9,250,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,198,81,7,11,0,8,99,0,8,35,0,9,166,0,8,3,0,8,131,0,8,67,0,9,230,80,7,7,0,8,91,0,8,27,0,9,150,84,7,67,0,8,123,0,8,59,0,9,214,82,7,19,0,8,107,0,8,43,0,9,182,0,8,11,0,8,139,0,8,75,0,9,246,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,206,81,7,15,0,8,103,0,8,39,0,9,174,0,8,7,0,8,135,0,8,71,0,9,238,80,7,9,0,8,95,0,8,31,0,9,158,84,7,99,0,8,127,0,8,63,0,9,222,82,7,27,0,8,111,0,8,47,0,9,190,0,8,15,0,8,143,0,8,79,0,9,254,96,7,256,0,8,80,0,8,16,84,8,115,82,7,31,0,8,112,0,8,48,0,9,193,80,7,10,0,8,96,0,8,32,0,9,161,0,8,0,0,8,128,0,8,64,0,9,225,80,7,6,0,8,88,0,8,24,0,9,145,83,7,59,0,8,120,0,8,56,0,9,209,81,7,17,0,8,104,0,8,40,0,9,177,0,8,8,0,8,136,0,8,72,0,9,241,80,7,4,0,8,84,0,8,20,85,8,227,83,7,43,0,8,116,0,8,52,0,9,201,81,7,13,0,8,100,0,8,36,0,9,169,0,8,4,0,8,132,0,8,68,0,9,233,80,7,8,0,8,92,0,8,28,0,9,153,84,7,83,0,8,124,0,8,60,0,9,217,82,7,23,0,8,108,0,8,44,0,9,185,0,8,12,0,8,140,0,8,76,0,9,249,80,7,3,0,8,82,0,8,18,85,8,163,83,7,35,0,8,114,0,8,50,0,9,197,81,7,11,0,8,98,0,8,34,0,9,165,0,8,2,0,8,130,0,8,66,0,9,229,80,7,7,0,8,90,0,8,26,0,9,149,84,7,67,0,8,122,0,8,58,0,9,213,82,7,19,0,8,106,0,8,42,0,9,181,0,8,10,0,8,138,0,8,74,0,9,245,80,7,5,0,8,86,0,8,22,192,8,0,83,7,51,0,8,118,0,8,54,0,9,205,81,7,15,0,8,102,0,8,38,0,9,173,0,8,6,0,8,134,0,8,70,0,9,237,80,7,9,0,8,94,0,8,30,0,9,157,84,7,99,0,8,126,0,8,62,0,9,221,82,7,27,0,8,110,0,8,46,0,9,189,0,8,14,0,8,142,0,8,78,0,9,253,96,7,256,0,8,81,0,8,17,85,8,131,82,7,31,0,8,113,0,8,49,0,9,195,80,7,10,0,8,97,0,8,33,0,9,163,0,8,1,0,8,129,0,8,65,0,9,227,80,7,6,0,8,89,0,8,25,0,9,147,83,7,59,0,8,121,0,8,57,0,9,211,81,7,17,0,8,105,0,8,41,0,9,179,0,8,9,0,8,137,0,8,73,0,9,243,80,7,4,0,8,85,0,8,21,80,8,258,83,7,43,0,8,117,0,8,53,0,9,203,81,7,13,0,8,101,0,8,37,0,9,171,0,8,5,0,8,133,0,8,69,0,9,235,80,7,8,0,8,93,0,8,29,0,9,155,84,7,83,0,8,125,0,8,61,0,9,219,82,7,23,0,8,109,0,8,45,0,9,187,0,8,13,0,8,141,0,8,77,0,9,251,80,7,3,0,8,83,0,8,19,85,8,195,83,7,35,0,8,115,0,8,51,0,9,199,81,7,11,0,8,99,0,8,35,0,9,167,0,8,3,0,8,131,0,8,67,0,9,231,80,7,7,0,8,91,0,8,27,0,9,151,84,7,67,0,8,123,0,8,59,0,9,215,82,7,19,0,8,107,0,8,43,0,9,183,0,8,11,0,8,139,0,8,75,0,9,247,80,7,5,0,8,87,0,8,23,192,8,0,83,7,51,0,8,119,0,8,55,0,9,207,81,7,15,0,8,103,0,8,39,0,9,175,0,8,7,0,8,135,0,8,71,0,9,239,80,7,9,0,8,95,0,8,31,0,9,159,84,7,99,0,8,127,0,8,63,0,9,223,82,7,27,0,8,111,0,8,47,0,9,191,0,8,15,0,8,143,0,8,79,0,9,255],ht=[80,5,1,87,5,257,83,5,17,91,5,4097,81,5,5,89,5,1025,85,5,65,93,5,16385,80,5,3,88,5,513,84,5,33,92,5,8193,82,5,9,90,5,2049,86,5,129,192,5,24577,80,5,2,87,5,385,83,5,25,91,5,6145,81,5,7,89,5,1537,85,5,97,93,5,24577,80,5,4,88,5,769,84,5,49,92,5,12289,82,5,13,90,5,3073,86,5,193,192,5,24577],dt=[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],pt=[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,112,112],yt=[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],bt=[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];function kt(){let t,e,n,r,i,o;function s(t,e,s,f,c,l,u,a,w,h,d){let p,y,b,k,g,v,m,S,z,_,I,A,C,V,B;_=0,g=s;do{n[t[e+_]]++,_++,g--}while(0!==g);if(n[0]==s)return u[0]=-1,a[0]=0,0;for(S=a[0],v=1;15>=v&&0===n[v];v++);for(m=v,v>S&&(S=v),g=15;0!==g&&0===n[g];g--);for(b=g,S>g&&(S=g),a[0]=S,V=1<<v;g>v;v++,V<<=1)if(0>(V-=n[v]))return-3;if(0>(V-=n[g]))return-3;for(n[g]+=V,o[1]=v=0,_=1,C=2;0!=--g;)o[C]=v+=n[_],C++,_++;g=0,_=0;do{0!==(v=t[e+_])&&(d[o[v]++]=g),_++}while(++g<s);for(s=o[b],o[0]=g=0,_=0,k=-1,A=-S,i[0]=0,I=0,B=0;b>=m;m++)for(p=n[m];0!=p--;){for(;m>A+S;){if(k++,A+=S,B=b-A,B=B>S?S:B,(y=1<<(v=m-A))>p+1&&(y-=p+1,C=m,B>v))for(;++v<B&&(y<<=1)>n[++C];)y-=n[C];if(B=1<<v,h[0]+B>1440)return-3;i[k]=I=h[0],h[0]+=B,0!==k?(o[k]=g,r[0]=v,r[1]=S,v=g>>>A-S,r[2]=I-i[k-1]-v,w.set(r,3*(i[k-1]+v))):u[0]=I}for(r[1]=m-A,s>_?d[_]<f?(r[0]=256>d[_]?0:96,r[2]=d[_++]):(r[0]=l[d[_]-f]+16+64,r[2]=c[d[_++]-f]):r[0]=192,y=1<<m-A,v=g>>>A;B>v;v+=y)w.set(r,3*(I+v));for(v=1<<m-1;0!=(g&v);v>>>=1)g^=v;for(g^=v,z=(1<<A)-1;(g&z)!=o[k];)k--,A-=S,z=(1<<A)-1}return 0!==V&&1!=b?-5:0}function c(s){let c;for(t||(t=[],e=[],n=new f(16),r=[],i=new f(15),o=new f(16)),e.length<s&&(e=[]),c=0;s>c;c++)e[c]=0;for(c=0;16>c;c++)n[c]=0;for(c=0;3>c;c++)r[c]=0;i.set(n.subarray(0,15),0),o.set(n.subarray(0,16),0)}this.ae=(n,r,i,o,f)=>{let l;return c(19),t[0]=0,l=s(n,0,19,19,null,null,i,r,o,t,e),-3==l?f.Zt="oversubscribed dynamic bit lengths tree":-5!=l&&0!==r[0]||(f.Zt="incomplete dynamic bit lengths tree",l=-3),l},this.we=(n,r,i,o,f,l,u,a,w)=>{let h;return c(288),t[0]=0,h=s(i,0,n,257,dt,pt,l,o,a,t,e),0!=h||0===o[0]?(-3==h?w.Zt="oversubscribed literal/length tree":-4!=h&&(w.Zt="incomplete literal/length tree",h=-3),h):(c(288),h=s(i,n,r,0,yt,bt,u,f,a,t,e),0!=h||0===f[0]&&n>257?(-3==h?w.Zt="oversubscribed distance tree":-5==h?(w.Zt="incomplete distance tree",h=-3):-4!=h&&(w.Zt="empty distance tree with lengths",h=-3),h):0)}}function gt(){const t=this;let e,n,r,i,o=0,s=0,f=0,c=0,l=0,u=0,a=0,w=0,h=0,d=0;function p(t,e,n,r,i,o,s,f){let c,l,u,a,w,h,d,p,y,b,k,g,v,m,S,z;d=f.le,p=f.Qt,w=s.he,h=s.de,y=s.write,b=y<s.read?s.read-y-1:s.end-y,k=at[t],g=at[e];do{for(;20>h;)p--,w|=(255&f.pe(d++))<<h,h+=8;if(c=w&k,l=n,u=r,z=3*(u+c),0!==(a=l[z]))for(;;){if(w>>=l[z+1],h-=l[z+1],0!=(16&a)){for(a&=15,v=l[z+2]+(w&at[a]),w>>=a,h-=a;15>h;)p--,w|=(255&f.pe(d++))<<h,h+=8;for(c=w&g,l=i,u=o,z=3*(u+c),a=l[z];;){if(w>>=l[z+1],h-=l[z+1],0!=(16&a)){for(a&=15;a>h;)p--,w|=(255&f.pe(d++))<<h,h+=8;if(m=l[z+2]+(w&at[a]),w>>=a,h-=a,b-=v,m>y){S=y-m;do{S+=s.end}while(0>S);if(a=s.end-S,v>a){if(v-=a,y-S>0&&a>y-S)do{s.ye[y++]=s.ye[S++]}while(0!=--a);else s.ye.set(s.ye.subarray(S,S+a),y),y+=a,S+=a,a=0;S=0}}else S=y-m,y-S>0&&2>y-S?(s.ye[y++]=s.ye[S++],s.ye[y++]=s.ye[S++],v-=2):(s.ye.set(s.ye.subarray(S,S+2),y),y+=2,S+=2,v-=2);if(y-S>0&&v>y-S)do{s.ye[y++]=s.ye[S++]}while(0!=--v);else s.ye.set(s.ye.subarray(S,S+v),y),y+=v,S+=v,v=0;break}if(0!=(64&a))return f.Zt="invalid distance code",v=f.Qt-p,v=v>h>>3?h>>3:v,p+=v,d-=v,h-=v<<3,s.he=w,s.de=h,f.Qt=p,f.te+=d-f.le,f.le=d,s.write=y,-3;c+=l[z+2],c+=w&at[a],z=3*(u+c),a=l[z]}break}if(0!=(64&a))return 0!=(32&a)?(v=f.Qt-p,v=v>h>>3?h>>3:v,p+=v,d-=v,h-=v<<3,s.he=w,s.de=h,f.Qt=p,f.te+=d-f.le,f.le=d,s.write=y,1):(f.Zt="invalid literal/length code",v=f.Qt-p,v=v>h>>3?h>>3:v,p+=v,d-=v,h-=v<<3,s.he=w,s.de=h,f.Qt=p,f.te+=d-f.le,f.le=d,s.write=y,-3);if(c+=l[z+2],c+=w&at[a],z=3*(u+c),0===(a=l[z])){w>>=l[z+1],h-=l[z+1],s.ye[y++]=l[z+2],b--;break}}else w>>=l[z+1],h-=l[z+1],s.ye[y++]=l[z+2],b--}while(b>=258&&p>=10);return v=f.Qt-p,v=v>h>>3?h>>3:v,p+=v,d-=v,h-=v<<3,s.he=w,s.de=h,f.Qt=p,f.te+=d-f.le,f.le=d,s.write=y,0}t.init=(t,o,s,f,c,l)=>{e=0,a=t,w=o,r=s,h=f,i=c,d=l,n=null},t.be=(t,y,b)=>{let k,g,v,m,S,z,_,I=0,A=0,C=0;for(C=y.le,m=y.Qt,I=t.he,A=t.de,S=t.write,z=S<t.read?t.read-S-1:t.end-S;;)switch(e){case 0:if(z>=258&&m>=10&&(t.he=I,t.de=A,y.Qt=m,y.te+=C-y.le,y.le=C,t.write=S,b=p(a,w,r,h,i,d,t,y),C=y.le,m=y.Qt,I=t.he,A=t.de,S=t.write,z=S<t.read?t.read-S-1:t.end-S,0!=b)){e=1==b?7:9;break}f=a,n=r,s=h,e=1;case 1:for(k=f;k>A;){if(0===m)return t.he=I,t.de=A,y.Qt=m,y.te+=C-y.le,y.le=C,t.write=S,t.ke(y,b);b=0,m--,I|=(255&y.pe(C++))<<A,A+=8}if(g=3*(s+(I&at[k])),I>>>=n[g+1],A-=n[g+1],v=n[g],0===v){c=n[g+2],e=6;break}if(0!=(16&v)){l=15&v,o=n[g+2],e=2;break}if(0==(64&v)){f=v,s=g/3+n[g+2];break}if(0!=(32&v)){e=7;break}return e=9,y.Zt="invalid literal/length code",b=-3,t.he=I,t.de=A,y.Qt=m,y.te+=C-y.le,y.le=C,t.write=S,t.ke(y,b);case 2:for(k=l;k>A;){if(0===m)return t.he=I,t.de=A,y.Qt=m,y.te+=C-y.le,y.le=C,t.write=S,t.ke(y,b);b=0,m--,I|=(255&y.pe(C++))<<A,A+=8}o+=I&at[k],I>>=k,A-=k,f=w,n=i,s=d,e=3;case 3:for(k=f;k>A;){if(0===m)return t.he=I,t.de=A,y.Qt=m,y.te+=C-y.le,y.le=C,t.write=S,t.ke(y,b);b=0,m--,I|=(255&y.pe(C++))<<A,A+=8}if(g=3*(s+(I&at[k])),I>>=n[g+1],A-=n[g+1],v=n[g],0!=(16&v)){l=15&v,u=n[g+2],e=4;break}if(0==(64&v)){f=v,s=g/3+n[g+2];break}return e=9,y.Zt="invalid distance code",b=-3,t.he=I,t.de=A,y.Qt=m,y.te+=C-y.le,y.le=C,t.write=S,t.ke(y,b);case 4:for(k=l;k>A;){if(0===m)return t.he=I,t.de=A,y.Qt=m,y.te+=C-y.le,y.le=C,t.write=S,t.ke(y,b);b=0,m--,I|=(255&y.pe(C++))<<A,A+=8}u+=I&at[k],I>>=k,A-=k,e=5;case 5:for(_=S-u;0>_;)_+=t.end;for(;0!==o;){if(0===z&&(S==t.end&&0!==t.read&&(S=0,z=S<t.read?t.read-S-1:t.end-S),0===z&&(t.write=S,b=t.ke(y,b),S=t.write,z=S<t.read?t.read-S-1:t.end-S,S==t.end&&0!==t.read&&(S=0,z=S<t.read?t.read-S-1:t.end-S),0===z)))return t.he=I,t.de=A,y.Qt=m,y.te+=C-y.le,y.le=C,t.write=S,t.ke(y,b);t.ye[S++]=t.ye[_++],z--,_==t.end&&(_=0),o--}e=0;break;case 6:if(0===z&&(S==t.end&&0!==t.read&&(S=0,z=S<t.read?t.read-S-1:t.end-S),0===z&&(t.write=S,b=t.ke(y,b),S=t.write,z=S<t.read?t.read-S-1:t.end-S,S==t.end&&0!==t.read&&(S=0,z=S<t.read?t.read-S-1:t.end-S),0===z)))return t.he=I,t.de=A,y.Qt=m,y.te+=C-y.le,y.le=C,t.write=S,t.ke(y,b);b=0,t.ye[S++]=c,z--,e=0;break;case 7:if(A>7&&(A-=8,m++,C--),t.write=S,b=t.ke(y,b),S=t.write,z=S<t.read?t.read-S-1:t.end-S,t.read!=t.write)return t.he=I,t.de=A,y.Qt=m,y.te+=C-y.le,y.le=C,t.write=S,t.ke(y,b);e=8;case 8:return b=1,t.he=I,t.de=A,y.Qt=m,y.te+=C-y.le,y.le=C,t.write=S,t.ke(y,b);case 9:return b=-3,t.he=I,t.de=A,y.Qt=m,y.te+=C-y.le,y.le=C,t.write=S,t.ke(y,b);default:return b=-2,t.he=I,t.de=A,y.Qt=m,y.te+=C-y.le,y.le=C,t.write=S,t.ke(y,b)}},t.ge=()=>{}}kt.ve=(t,e,n,r)=>(t[0]=9,e[0]=5,n[0]=wt,r[0]=ht,0);const vt=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];function mt(t,e){const n=this;let r,o=0,s=0,c=0,l=0;const u=[0],a=[0],w=new gt;let h=0,d=new f(4320);const p=new kt;n.de=0,n.he=0,n.ye=new i(e),n.end=e,n.read=0,n.write=0,n.reset=(t,e)=>{e&&(e[0]=0),6==o&&w.ge(t),o=0,n.de=0,n.he=0,n.read=n.write=0},n.reset(t,null),n.ke=(t,e)=>{let r,i,o;return i=t.ue,o=n.read,r=(o>n.write?n.end:n.write)-o,r>t.ce&&(r=t.ce),0!==r&&-5==e&&(e=0),t.ce-=r,t.ee+=r,t.se.set(n.ye.subarray(o,o+r),i),i+=r,o+=r,o==n.end&&(o=0,n.write==n.end&&(n.write=0),r=n.write-o,r>t.ce&&(r=t.ce),0!==r&&-5==e&&(e=0),t.ce-=r,t.ee+=r,t.se.set(n.ye.subarray(o,o+r),i),i+=r,o+=r),t.ue=i,n.read=o,e},n.be=(t,e)=>{let i,f,y,b,k,g,v,m;for(b=t.le,k=t.Qt,f=n.he,y=n.de,g=n.write,v=g<n.read?n.read-g-1:n.end-g;;){let S,z,_,I,A,C,V,B;switch(o){case 0:for(;3>y;){if(0===k)return n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);e=0,k--,f|=(255&t.pe(b++))<<y,y+=8}switch(i=7&f,h=1&i,i>>>1){case 0:f>>>=3,y-=3,i=7&y,f>>>=i,y-=i,o=1;break;case 1:S=[],z=[],_=[[]],I=[[]],kt.ve(S,z,_,I),w.init(S[0],z[0],_[0],0,I[0],0),f>>>=3,y-=3,o=6;break;case 2:f>>>=3,y-=3,o=3;break;case 3:return f>>>=3,y-=3,o=9,t.Zt="invalid block type",e=-3,n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e)}break;case 1:for(;32>y;){if(0===k)return n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);e=0,k--,f|=(255&t.pe(b++))<<y,y+=8}if((~f>>>16&65535)!=(65535&f))return o=9,t.Zt="invalid stored block lengths",e=-3,n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);s=65535&f,f=y=0,o=0!==s?2:0!==h?7:0;break;case 2:if(0===k)return n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);if(0===v&&(g==n.end&&0!==n.read&&(g=0,v=g<n.read?n.read-g-1:n.end-g),0===v&&(n.write=g,e=n.ke(t,e),g=n.write,v=g<n.read?n.read-g-1:n.end-g,g==n.end&&0!==n.read&&(g=0,v=g<n.read?n.read-g-1:n.end-g),0===v)))return n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);if(e=0,i=s,i>k&&(i=k),i>v&&(i=v),n.ye.set(t.Xt(b,i),g),b+=i,k-=i,g+=i,v-=i,0!=(s-=i))break;o=0!==h?7:0;break;case 3:for(;14>y;){if(0===k)return n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);e=0,k--,f|=(255&t.pe(b++))<<y,y+=8}if(c=i=16383&f,(31&i)>29||(i>>5&31)>29)return o=9,t.Zt="too many length or distance symbols",e=-3,n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);if(i=258+(31&i)+(i>>5&31),!r||r.length<i)r=[];else for(m=0;i>m;m++)r[m]=0;f>>>=14,y-=14,l=0,o=4;case 4:for(;4+(c>>>10)>l;){for(;3>y;){if(0===k)return n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);e=0,k--,f|=(255&t.pe(b++))<<y,y+=8}r[vt[l++]]=7&f,f>>>=3,y-=3}for(;19>l;)r[vt[l++]]=0;if(u[0]=7,i=p.ae(r,u,a,d,t),0!=i)return-3==(e=i)&&(r=null,o=9),n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);l=0,o=5;case 5:for(;i=c,258+(31&i)+(i>>5&31)>l;){let s,w;for(i=u[0];i>y;){if(0===k)return n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);e=0,k--,f|=(255&t.pe(b++))<<y,y+=8}if(i=d[3*(a[0]+(f&at[i]))+1],w=d[3*(a[0]+(f&at[i]))+2],16>w)f>>>=i,y-=i,r[l++]=w;else{for(m=18==w?7:w-14,s=18==w?11:3;i+m>y;){if(0===k)return n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);e=0,k--,f|=(255&t.pe(b++))<<y,y+=8}if(f>>>=i,y-=i,s+=f&at[m],f>>>=m,y-=m,m=l,i=c,m+s>258+(31&i)+(i>>5&31)||16==w&&1>m)return r=null,o=9,t.Zt="invalid bit length repeat",e=-3,n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);w=16==w?r[m-1]:0;do{r[m++]=w}while(0!=--s);l=m}}if(a[0]=-1,A=[],C=[],V=[],B=[],A[0]=9,C[0]=6,i=c,i=p.we(257+(31&i),1+(i>>5&31),r,A,C,V,B,d,t),0!=i)return-3==i&&(r=null,o=9),e=i,n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);w.init(A[0],C[0],d,V[0],d,B[0]),o=6;case 6:if(n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,1!=(e=w.be(n,t,e)))return n.ke(t,e);if(e=0,w.ge(t),b=t.le,k=t.Qt,f=n.he,y=n.de,g=n.write,v=g<n.read?n.read-g-1:n.end-g,0===h){o=0;break}o=7;case 7:if(n.write=g,e=n.ke(t,e),g=n.write,v=g<n.read?n.read-g-1:n.end-g,n.read!=n.write)return n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);o=8;case 8:return e=1,n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);case 9:return e=-3,n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e);default:return e=-2,n.he=f,n.de=y,t.Qt=k,t.te+=b-t.le,t.le=b,n.write=g,n.ke(t,e)}}},n.ge=t=>{n.reset(t,null),n.ye=null,d=null},n.me=(t,e,r)=>{n.ye.set(t.subarray(e,e+r),0),n.read=n.write=r},n.Se=()=>1==o?1:0}const St=[0,0,255,255];function zt(){const t=this;function e(t){return t&&t.ze?(t.te=t.ee=0,t.Zt=null,t.ze.mode=7,t.ze._e.reset(t,null),0):-2}t.mode=0,t.method=0,t.Ie=[0],t.Ae=0,t.marker=0,t.Ce=0,t.Ve=e=>(t._e&&t._e.ge(e),t._e=null,0),t.Be=(n,r)=>(n.Zt=null,t._e=null,8>r||r>15?(t.Ve(n),-2):(t.Ce=r,n.ze._e=new mt(n,1<<r),e(n),0)),t.it=(t,e)=>{let n,r;if(!t||!t.ze||!t.fe)return-2;const i=t.ze;for(e=4==e?-5:0,n=-5;;)switch(i.mode){case 0:if(0===t.Qt)return n;if(n=e,t.Qt--,t.te++,8!=(15&(i.method=t.pe(t.le++)))){i.mode=13,t.Zt="unknown compression method",i.marker=5;break}if(8+(i.method>>4)>i.Ce){i.mode=13,t.Zt="invalid win size",i.marker=5;break}i.mode=1;case 1:if(0===t.Qt)return n;if(n=e,t.Qt--,t.te++,r=255&t.pe(t.le++),((i.method<<8)+r)%31!=0){i.mode=13,t.Zt="incorrect header check",i.marker=5;break}if(0==(32&r)){i.mode=7;break}i.mode=2;case 2:if(0===t.Qt)return n;n=e,t.Qt--,t.te++,i.Ae=(255&t.pe(t.le++))<<24&4278190080,i.mode=3;case 3:if(0===t.Qt)return n;n=e,t.Qt--,t.te++,i.Ae+=(255&t.pe(t.le++))<<16&16711680,i.mode=4;case 4:if(0===t.Qt)return n;n=e,t.Qt--,t.te++,i.Ae+=(255&t.pe(t.le++))<<8&65280,i.mode=5;case 5:return 0===t.Qt?n:(n=e,t.Qt--,t.te++,i.Ae+=255&t.pe(t.le++),i.mode=6,2);case 6:return i.mode=13,t.Zt="need dictionary",i.marker=0,-2;case 7:if(n=i._e.be(t,n),-3==n){i.mode=13,i.marker=0;break}if(0==n&&(n=e),1!=n)return n;n=e,i._e.reset(t,i.Ie),i.mode=12;case 12:return t.Qt=0,1;case 13:return-3;default:return-2}},t.Ee=(t,e,n)=>{let r=0,i=n;if(!t||!t.ze||6!=t.ze.mode)return-2;const o=t.ze;return i<1<<o.Ce||(i=(1<<o.Ce)-1,r=n-i),o._e.me(e,r,i),o.mode=7,0},t.De=t=>{let n,r,i,o,s;if(!t||!t.ze)return-2;const f=t.ze;if(13!=f.mode&&(f.mode=13,f.marker=0),0===(n=t.Qt))return-5;for(r=t.le,i=f.marker;0!==n&&4>i;)t.pe(r)==St[i]?i++:i=0!==t.pe(r)?0:4-i,r++,n--;return t.te+=r-t.le,t.le=r,t.Qt=n,f.marker=i,4!=i?-3:(o=t.te,s=t.ee,e(t),t.te=o,t.ee=s,f.mode=7,0)},t.Ue=t=>t&&t.ze&&t.ze._e?t.ze._e.Se():-2}function _t(){}function It(t){const e=new _t,o=t&&t.rt?n.floor(2*t.rt):131072,s=new i(o);let f=!1;e.Be(),e.se=s,this.append=(t,n)=>{const c=[];let l,u,a=0,w=0,h=0;if(0!==t.length){e.le=0,e.fe=t,e.Qt=t.length;do{if(e.ue=0,e.ce=o,0!==e.Qt||f||(e.le=0,f=!0),l=e.it(0),f&&-5===l){if(0!==e.Qt)throw new r("inflating: bad input")}else if(0!==l&&1!==l)throw new r("inflating: "+e.Zt);if((f||1===l)&&e.Qt===t.length)throw new r("inflating: bad input");e.ue&&(e.ue===o?c.push(new i(s)):c.push(s.slice(0,e.ue))),h+=e.ue,n&&e.le>0&&e.le!=a&&(n(e.le),a=e.le)}while(e.Qt>0||0===e.ce);return c.length>1?(u=new i(h),c.forEach((t=>{u.set(t,w),w+=t.length}))):u=c[0]||new i(0),u}},this.flush=()=>{e.Ve()}}_t.prototype={Be:function(t){const e=this;return e.ze=new zt,t||(t=15),e.ze.Be(e,t)},it:function(t){const e=this;return e.ze?e.ze.it(e,t):-2},Ve:function(){const t=this;if(!t.ze)return-2;const e=t.ze.Ve(t);return t.ze=null,e},De:function(){const t=this;return t.ze?t.ze.De(t):-2},Ee:function(t,e){const n=this;return n.ze?n.ze.Ee(n,t,e):-2},pe:function(t){return this.fe[t]},Xt:function(t,e){return this.fe.subarray(t,t+e)}},self.initCodec=()=>{self.Deflate=ut,self.Inflate=It};\n'],{type:"text/javascript"}));t({workerScripts:{inflate:[e],deflate:[e]}});}};
  3705. /*
  3706. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  3707. Redistribution and use in source and binary forms, with or without
  3708. modification, are permitted provided that the following conditions are met:
  3709. 1. Redistributions of source code must retain the above copyright notice,
  3710. this list of conditions and the following disclaimer.
  3711. 2. Redistributions in binary form must reproduce the above copyright
  3712. notice, this list of conditions and the following disclaimer in
  3713. the documentation and/or other materials provided with the distribution.
  3714. 3. The names of the authors may not be used to endorse or promote products
  3715. derived from this software without specific prior written permission.
  3716. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  3717. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  3718. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  3719. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  3720. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3721. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  3722. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3723. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3724. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3725. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3726. */
  3727. function getMimeType() {
  3728. return "application/octet-stream";
  3729. }
  3730. /*
  3731. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  3732. Redistribution and use in source and binary forms, with or without
  3733. modification, are permitted provided that the following conditions are met:
  3734. 1. Redistributions of source code must retain the above copyright notice,
  3735. this list of conditions and the following disclaimer.
  3736. 2. Redistributions in binary form must reproduce the above copyright
  3737. notice, this list of conditions and the following disclaimer in
  3738. the documentation and/or other materials provided with the distribution.
  3739. 3. The names of the authors may not be used to endorse or promote products
  3740. derived from this software without specific prior written permission.
  3741. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  3742. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  3743. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  3744. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  3745. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3746. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  3747. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3748. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3749. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3750. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3751. */
  3752. var streamCodecShim = (library, options = {}, registerDataHandler) => {
  3753. return {
  3754. Deflate: createCodecClass(library.Deflate, options.deflate, registerDataHandler),
  3755. Inflate: createCodecClass(library.Inflate, options.inflate, registerDataHandler)
  3756. };
  3757. };
  3758. function createCodecClass(constructor, constructorOptions, registerDataHandler) {
  3759. return class {
  3760. constructor(options) {
  3761. const codecAdapter = this;
  3762. const onData = data => {
  3763. if (codecAdapter.pendingData) {
  3764. const pendingData = codecAdapter.pendingData;
  3765. codecAdapter.pendingData = new Uint8Array(pendingData.length + data.length);
  3766. codecAdapter.pendingData.set(pendingData, 0);
  3767. codecAdapter.pendingData.set(data, pendingData.length);
  3768. } else {
  3769. codecAdapter.pendingData = new Uint8Array(data);
  3770. }
  3771. };
  3772. codecAdapter.codec = new constructor(Object.assign({}, constructorOptions, options));
  3773. registerDataHandler(codecAdapter.codec, onData);
  3774. }
  3775. append(data) {
  3776. this.codec.push(data);
  3777. return getResponse(this);
  3778. }
  3779. flush() {
  3780. this.codec.push(new Uint8Array(0), true);
  3781. return getResponse(this);
  3782. }
  3783. };
  3784. function getResponse(codec) {
  3785. if (codec.pendingData) {
  3786. const output = codec.pendingData;
  3787. codec.pendingData = null;
  3788. return output;
  3789. } else {
  3790. return new Uint8Array(0);
  3791. }
  3792. }
  3793. }
  3794. /*
  3795. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  3796. Redistribution and use in source and binary forms, with or without
  3797. modification, are permitted provided that the following conditions are met:
  3798. 1. Redistributions of source code must retain the above copyright notice,
  3799. this list of conditions and the following disclaimer.
  3800. 2. Redistributions in binary form must reproduce the above copyright
  3801. notice, this list of conditions and the following disclaimer in
  3802. the documentation and/or other materials provided with the distribution.
  3803. 3. The names of the authors may not be used to endorse or promote products
  3804. derived from this software without specific prior written permission.
  3805. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  3806. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  3807. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  3808. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  3809. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3810. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  3811. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3812. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3813. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3814. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3815. */
  3816. const table = [];
  3817. for (let i = 0; i < 256; i++) {
  3818. let t = i;
  3819. for (let j = 0; j < 8; j++) {
  3820. if (t & 1) {
  3821. t = (t >>> 1) ^ 0xEDB88320;
  3822. } else {
  3823. t = t >>> 1;
  3824. }
  3825. }
  3826. table[i] = t;
  3827. }
  3828. class Crc32 {
  3829. constructor(crc) {
  3830. this.crc = crc || -1;
  3831. }
  3832. append(data) {
  3833. let crc = this.crc | 0;
  3834. for (let offset = 0, length = data.length | 0; offset < length; offset++) {
  3835. crc = (crc >>> 8) ^ table[(crc ^ data[offset]) & 0xFF];
  3836. }
  3837. this.crc = crc;
  3838. }
  3839. get() {
  3840. return ~this.crc;
  3841. }
  3842. }
  3843. /*
  3844. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  3845. Redistribution and use in source and binary forms, with or without
  3846. modification, are permitted provided that the following conditions are met:
  3847. 1. Redistributions of source code must retain the above copyright notice,
  3848. this list of conditions and the following disclaimer.
  3849. 2. Redistributions in binary form must reproduce the above copyright
  3850. notice, this list of conditions and the following disclaimer in
  3851. the documentation and/or other materials provided with the distribution.
  3852. 3. The names of the authors may not be used to endorse or promote products
  3853. derived from this software without specific prior written permission.
  3854. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  3855. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  3856. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  3857. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  3858. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3859. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  3860. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3861. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3862. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3863. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3864. */
  3865. function encodeText(value) {
  3866. if (typeof TextEncoder == "undefined") {
  3867. value = unescape(encodeURIComponent(value));
  3868. const result = new Uint8Array(value.length);
  3869. for (let i = 0; i < result.length; i++) {
  3870. result[i] = value.charCodeAt(i);
  3871. }
  3872. return result;
  3873. } else {
  3874. return new TextEncoder().encode(value);
  3875. }
  3876. }
  3877. // Derived from https://github.com/xqdoo00o/jszip/blob/master/lib/sjcl.js and https://github.com/bitwiseshiftleft/sjcl
  3878. /*// deno-lint-ignore-file no-this-alias *
  3879. /*
  3880. * SJCL is open. You can use, modify and redistribute it under a BSD
  3881. * license or under the GNU GPL, version 2.0.
  3882. */
  3883. /** @fileOverview Javascript cryptography implementation.
  3884. *
  3885. * Crush to remove comments, shorten variable names and
  3886. * generally reduce transmission size.
  3887. *
  3888. * @author Emily Stark
  3889. * @author Mike Hamburg
  3890. * @author Dan Boneh
  3891. */
  3892. /*jslint indent: 2, bitwise: false, nomen: false, plusplus: false, white: false, regexp: false */
  3893. /** @fileOverview Arrays of bits, encoded as arrays of Numbers.
  3894. *
  3895. * @author Emily Stark
  3896. * @author Mike Hamburg
  3897. * @author Dan Boneh
  3898. */
  3899. /**
  3900. * Arrays of bits, encoded as arrays of Numbers.
  3901. * @namespace
  3902. * @description
  3903. * <p>
  3904. * These objects are the currency accepted by SJCL's crypto functions.
  3905. * </p>
  3906. *
  3907. * <p>
  3908. * Most of our crypto primitives operate on arrays of 4-byte words internally,
  3909. * but many of them can take arguments that are not a multiple of 4 bytes.
  3910. * This library encodes arrays of bits (whose size need not be a multiple of 8
  3911. * bits) as arrays of 32-bit words. The bits are packed, big-endian, into an
  3912. * array of words, 32 bits at a time. Since the words are double-precision
  3913. * floating point numbers, they fit some extra data. We use this (in a private,
  3914. * possibly-changing manner) to encode the number of bits actually present
  3915. * in the last word of the array.
  3916. * </p>
  3917. *
  3918. * <p>
  3919. * Because bitwise ops clear this out-of-band data, these arrays can be passed
  3920. * to ciphers like AES which want arrays of words.
  3921. * </p>
  3922. */
  3923. const bitArray = {
  3924. /**
  3925. * Concatenate two bit arrays.
  3926. * @param {bitArray} a1 The first array.
  3927. * @param {bitArray} a2 The second array.
  3928. * @return {bitArray} The concatenation of a1 and a2.
  3929. */
  3930. concat(a1, a2) {
  3931. if (a1.length === 0 || a2.length === 0) {
  3932. return a1.concat(a2);
  3933. }
  3934. const last = a1[a1.length - 1], shift = bitArray.getPartial(last);
  3935. if (shift === 32) {
  3936. return a1.concat(a2);
  3937. } else {
  3938. return bitArray._shiftRight(a2, shift, last | 0, a1.slice(0, a1.length - 1));
  3939. }
  3940. },
  3941. /**
  3942. * Find the length of an array of bits.
  3943. * @param {bitArray} a The array.
  3944. * @return {Number} The length of a, in bits.
  3945. */
  3946. bitLength(a) {
  3947. const l = a.length;
  3948. if (l === 0) {
  3949. return 0;
  3950. }
  3951. const x = a[l - 1];
  3952. return (l - 1) * 32 + bitArray.getPartial(x);
  3953. },
  3954. /**
  3955. * Truncate an array.
  3956. * @param {bitArray} a The array.
  3957. * @param {Number} len The length to truncate to, in bits.
  3958. * @return {bitArray} A new array, truncated to len bits.
  3959. */
  3960. clamp(a, len) {
  3961. if (a.length * 32 < len) {
  3962. return a;
  3963. }
  3964. a = a.slice(0, Math.ceil(len / 32));
  3965. const l = a.length;
  3966. len = len & 31;
  3967. if (l > 0 && len) {
  3968. a[l - 1] = bitArray.partial(len, a[l - 1] & 0x80000000 >> (len - 1), 1);
  3969. }
  3970. return a;
  3971. },
  3972. /**
  3973. * Make a partial word for a bit array.
  3974. * @param {Number} len The number of bits in the word.
  3975. * @param {Number} x The bits.
  3976. * @param {Number} [_end=0] Pass 1 if x has already been shifted to the high side.
  3977. * @return {Number} The partial word.
  3978. */
  3979. partial(len, x, _end) {
  3980. if (len === 32) {
  3981. return x;
  3982. }
  3983. return (_end ? x | 0 : x << (32 - len)) + len * 0x10000000000;
  3984. },
  3985. /**
  3986. * Get the number of bits used by a partial word.
  3987. * @param {Number} x The partial word.
  3988. * @return {Number} The number of bits used by the partial word.
  3989. */
  3990. getPartial(x) {
  3991. return Math.round(x / 0x10000000000) || 32;
  3992. },
  3993. /** Shift an array right.
  3994. * @param {bitArray} a The array to shift.
  3995. * @param {Number} shift The number of bits to shift.
  3996. * @param {Number} [carry=0] A byte to carry in
  3997. * @param {bitArray} [out=[]] An array to prepend to the output.
  3998. * @private
  3999. */
  4000. _shiftRight(a, shift, carry, out) {
  4001. if (out === undefined) {
  4002. out = [];
  4003. }
  4004. for (; shift >= 32; shift -= 32) {
  4005. out.push(carry);
  4006. carry = 0;
  4007. }
  4008. if (shift === 0) {
  4009. return out.concat(a);
  4010. }
  4011. for (let i = 0; i < a.length; i++) {
  4012. out.push(carry | a[i] >>> shift);
  4013. carry = a[i] << (32 - shift);
  4014. }
  4015. const last2 = a.length ? a[a.length - 1] : 0;
  4016. const shift2 = bitArray.getPartial(last2);
  4017. out.push(bitArray.partial(shift + shift2 & 31, (shift + shift2 > 32) ? carry : out.pop(), 1));
  4018. return out;
  4019. }
  4020. };
  4021. /** @fileOverview Bit array codec implementations.
  4022. *
  4023. * @author Emily Stark
  4024. * @author Mike Hamburg
  4025. * @author Dan Boneh
  4026. */
  4027. /**
  4028. * Arrays of bytes
  4029. * @namespace
  4030. */
  4031. const codec = {
  4032. bytes: {
  4033. /** Convert from a bitArray to an array of bytes. */
  4034. fromBits(arr) {
  4035. const bl = bitArray.bitLength(arr);
  4036. const byteLength = bl / 8;
  4037. const out = new Uint8Array(byteLength);
  4038. let tmp;
  4039. for (let i = 0; i < byteLength; i++) {
  4040. if ((i & 3) === 0) {
  4041. tmp = arr[i / 4];
  4042. }
  4043. out[i] = tmp >>> 24;
  4044. tmp <<= 8;
  4045. }
  4046. return out;
  4047. },
  4048. /** Convert from an array of bytes to a bitArray. */
  4049. toBits(bytes) {
  4050. const out = [];
  4051. let i;
  4052. let tmp = 0;
  4053. for (i = 0; i < bytes.length; i++) {
  4054. tmp = tmp << 8 | bytes[i];
  4055. if ((i & 3) === 3) {
  4056. out.push(tmp);
  4057. tmp = 0;
  4058. }
  4059. }
  4060. if (i & 3) {
  4061. out.push(bitArray.partial(8 * (i & 3), tmp));
  4062. }
  4063. return out;
  4064. }
  4065. }
  4066. };
  4067. const hash = {};
  4068. /**
  4069. * Context for a SHA-1 operation in progress.
  4070. * @constructor
  4071. */
  4072. hash.sha1 = function (hash) {
  4073. if (hash) {
  4074. this._h = hash._h.slice(0);
  4075. this._buffer = hash._buffer.slice(0);
  4076. this._length = hash._length;
  4077. } else {
  4078. this.reset();
  4079. }
  4080. };
  4081. hash.sha1.prototype = {
  4082. /**
  4083. * The hash's block size, in bits.
  4084. * @constant
  4085. */
  4086. blockSize: 512,
  4087. /**
  4088. * Reset the hash state.
  4089. * @return this
  4090. */
  4091. reset: function () {
  4092. const sha1 = this;
  4093. sha1._h = this._init.slice(0);
  4094. sha1._buffer = [];
  4095. sha1._length = 0;
  4096. return sha1;
  4097. },
  4098. /**
  4099. * Input several words to the hash.
  4100. * @param {bitArray|String} data the data to hash.
  4101. * @return this
  4102. */
  4103. update: function (data) {
  4104. const sha1 = this;
  4105. if (typeof data === "string") {
  4106. data = codec.utf8String.toBits(data);
  4107. }
  4108. const b = sha1._buffer = bitArray.concat(sha1._buffer, data);
  4109. const ol = sha1._length;
  4110. const nl = sha1._length = ol + bitArray.bitLength(data);
  4111. if (nl > 9007199254740991) {
  4112. throw new Error("Cannot hash more than 2^53 - 1 bits");
  4113. }
  4114. const c = new Uint32Array(b);
  4115. let j = 0;
  4116. for (let i = sha1.blockSize + ol - ((sha1.blockSize + ol) & (sha1.blockSize - 1)); i <= nl;
  4117. i += sha1.blockSize) {
  4118. sha1._block(c.subarray(16 * j, 16 * (j + 1)));
  4119. j += 1;
  4120. }
  4121. b.splice(0, 16 * j);
  4122. return sha1;
  4123. },
  4124. /**
  4125. * Complete hashing and output the hash value.
  4126. * @return {bitArray} The hash value, an array of 5 big-endian words. TODO
  4127. */
  4128. finalize: function () {
  4129. const sha1 = this;
  4130. let b = sha1._buffer;
  4131. const h = sha1._h;
  4132. // Round out and push the buffer
  4133. b = bitArray.concat(b, [bitArray.partial(1, 1)]);
  4134. // Round out the buffer to a multiple of 16 words, less the 2 length words.
  4135. for (let i = b.length + 2; i & 15; i++) {
  4136. b.push(0);
  4137. }
  4138. // append the length
  4139. b.push(Math.floor(sha1._length / 0x100000000));
  4140. b.push(sha1._length | 0);
  4141. while (b.length) {
  4142. sha1._block(b.splice(0, 16));
  4143. }
  4144. sha1.reset();
  4145. return h;
  4146. },
  4147. /**
  4148. * The SHA-1 initialization vector.
  4149. * @private
  4150. */
  4151. _init: [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0],
  4152. /**
  4153. * The SHA-1 hash key.
  4154. * @private
  4155. */
  4156. _key: [0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6],
  4157. /**
  4158. * The SHA-1 logical functions f(0), f(1), ..., f(79).
  4159. * @private
  4160. */
  4161. _f: function (t, b, c, d) {
  4162. if (t <= 19) {
  4163. return (b & c) | (~b & d);
  4164. } else if (t <= 39) {
  4165. return b ^ c ^ d;
  4166. } else if (t <= 59) {
  4167. return (b & c) | (b & d) | (c & d);
  4168. } else if (t <= 79) {
  4169. return b ^ c ^ d;
  4170. }
  4171. },
  4172. /**
  4173. * Circular left-shift operator.
  4174. * @private
  4175. */
  4176. _S: function (n, x) {
  4177. return (x << n) | (x >>> 32 - n);
  4178. },
  4179. /**
  4180. * Perform one cycle of SHA-1.
  4181. * @param {Uint32Array|bitArray} words one block of words.
  4182. * @private
  4183. */
  4184. _block: function (words) {
  4185. const sha1 = this;
  4186. const h = sha1._h;
  4187. // When words is passed to _block, it has 16 elements. SHA1 _block
  4188. // function extends words with new elements (at the end there are 80 elements).
  4189. // The problem is that if we use Uint32Array instead of Array,
  4190. // the length of Uint32Array cannot be changed. Thus, we replace words with a
  4191. // normal Array here.
  4192. const w = Array(80); // do not use Uint32Array here as the instantiation is slower
  4193. for (let j = 0; j < 16; j++) {
  4194. w[j] = words[j];
  4195. }
  4196. let a = h[0];
  4197. let b = h[1];
  4198. let c = h[2];
  4199. let d = h[3];
  4200. let e = h[4];
  4201. for (let t = 0; t <= 79; t++) {
  4202. if (t >= 16) {
  4203. w[t] = sha1._S(1, w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16]);
  4204. }
  4205. const tmp = (sha1._S(5, a) + sha1._f(t, b, c, d) + e + w[t] +
  4206. sha1._key[Math.floor(t / 20)]) | 0;
  4207. e = d;
  4208. d = c;
  4209. c = sha1._S(30, b);
  4210. b = a;
  4211. a = tmp;
  4212. }
  4213. h[0] = (h[0] + a) | 0;
  4214. h[1] = (h[1] + b) | 0;
  4215. h[2] = (h[2] + c) | 0;
  4216. h[3] = (h[3] + d) | 0;
  4217. h[4] = (h[4] + e) | 0;
  4218. }
  4219. };
  4220. /** @fileOverview Low-level AES implementation.
  4221. *
  4222. * This file contains a low-level implementation of AES, optimized for
  4223. * size and for efficiency on several browsers. It is based on
  4224. * OpenSSL's aes_core.c, a public-domain implementation by Vincent
  4225. * Rijmen, Antoon Bosselaers and Paulo Barreto.
  4226. *
  4227. * An older version of this implementation is available in the public
  4228. * domain, but this one is (c) Emily Stark, Mike Hamburg, Dan Boneh,
  4229. * Stanford University 2008-2010 and BSD-licensed for liability
  4230. * reasons.
  4231. *
  4232. * @author Emily Stark
  4233. * @author Mike Hamburg
  4234. * @author Dan Boneh
  4235. */
  4236. const cipher = {};
  4237. /**
  4238. * Schedule out an AES key for both encryption and decryption. This
  4239. * is a low-level class. Use a cipher mode to do bulk encryption.
  4240. *
  4241. * @constructor
  4242. * @param {Array} key The key as an array of 4, 6 or 8 words.
  4243. */
  4244. cipher.aes = class {
  4245. constructor(key) {
  4246. /**
  4247. * The expanded S-box and inverse S-box tables. These will be computed
  4248. * on the client so that we don't have to send them down the wire.
  4249. *
  4250. * There are two tables, _tables[0] is for encryption and
  4251. * _tables[1] is for decryption.
  4252. *
  4253. * The first 4 sub-tables are the expanded S-box with MixColumns. The
  4254. * last (_tables[01][4]) is the S-box itself.
  4255. *
  4256. * @private
  4257. */
  4258. const aes = this;
  4259. aes._tables = [[[], [], [], [], []], [[], [], [], [], []]];
  4260. if (!aes._tables[0][0][0]) {
  4261. aes._precompute();
  4262. }
  4263. const sbox = aes._tables[0][4];
  4264. const decTable = aes._tables[1];
  4265. const keyLen = key.length;
  4266. let i, encKey, decKey, rcon = 1;
  4267. if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {
  4268. throw new Error("invalid aes key size");
  4269. }
  4270. aes._key = [encKey = key.slice(0), decKey = []];
  4271. // schedule encryption keys
  4272. for (i = keyLen; i < 4 * keyLen + 28; i++) {
  4273. let tmp = encKey[i - 1];
  4274. // apply sbox
  4275. if (i % keyLen === 0 || (keyLen === 8 && i % keyLen === 4)) {
  4276. tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
  4277. // shift rows and add rcon
  4278. if (i % keyLen === 0) {
  4279. tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
  4280. rcon = rcon << 1 ^ (rcon >> 7) * 283;
  4281. }
  4282. }
  4283. encKey[i] = encKey[i - keyLen] ^ tmp;
  4284. }
  4285. // schedule decryption keys
  4286. for (let j = 0; i; j++, i--) {
  4287. const tmp = encKey[j & 3 ? i : i - 4];
  4288. if (i <= 4 || j < 4) {
  4289. decKey[j] = tmp;
  4290. } else {
  4291. decKey[j] = decTable[0][sbox[tmp >>> 24]] ^
  4292. decTable[1][sbox[tmp >> 16 & 255]] ^
  4293. decTable[2][sbox[tmp >> 8 & 255]] ^
  4294. decTable[3][sbox[tmp & 255]];
  4295. }
  4296. }
  4297. }
  4298. // public
  4299. /* Something like this might appear here eventually
  4300. name: "AES",
  4301. blockSize: 4,
  4302. keySizes: [4,6,8],
  4303. */
  4304. /**
  4305. * Encrypt an array of 4 big-endian words.
  4306. * @param {Array} data The plaintext.
  4307. * @return {Array} The ciphertext.
  4308. */
  4309. encrypt(data) {
  4310. return this._crypt(data, 0);
  4311. }
  4312. /**
  4313. * Decrypt an array of 4 big-endian words.
  4314. * @param {Array} data The ciphertext.
  4315. * @return {Array} The plaintext.
  4316. */
  4317. decrypt(data) {
  4318. return this._crypt(data, 1);
  4319. }
  4320. /**
  4321. * Expand the S-box tables.
  4322. *
  4323. * @private
  4324. */
  4325. _precompute() {
  4326. const encTable = this._tables[0];
  4327. const decTable = this._tables[1];
  4328. const sbox = encTable[4];
  4329. const sboxInv = decTable[4];
  4330. const d = [];
  4331. const th = [];
  4332. let xInv, x2, x4, x8;
  4333. // Compute double and third tables
  4334. for (let i = 0; i < 256; i++) {
  4335. th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
  4336. }
  4337. for (let x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
  4338. // Compute sbox
  4339. let s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
  4340. s = s >> 8 ^ s & 255 ^ 99;
  4341. sbox[x] = s;
  4342. sboxInv[s] = x;
  4343. // Compute MixColumns
  4344. x8 = d[x4 = d[x2 = d[x]]];
  4345. let tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
  4346. let tEnc = d[s] * 0x101 ^ s * 0x1010100;
  4347. for (let i = 0; i < 4; i++) {
  4348. encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
  4349. decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
  4350. }
  4351. }
  4352. // Compactify. Considerable speedup on Firefox.
  4353. for (let i = 0; i < 5; i++) {
  4354. encTable[i] = encTable[i].slice(0);
  4355. decTable[i] = decTable[i].slice(0);
  4356. }
  4357. }
  4358. /**
  4359. * Encryption and decryption core.
  4360. * @param {Array} input Four words to be encrypted or decrypted.
  4361. * @param dir The direction, 0 for encrypt and 1 for decrypt.
  4362. * @return {Array} The four encrypted or decrypted words.
  4363. * @private
  4364. */
  4365. _crypt(input, dir) {
  4366. if (input.length !== 4) {
  4367. throw new Error("invalid aes block size");
  4368. }
  4369. const key = this._key[dir];
  4370. const nInnerRounds = key.length / 4 - 2;
  4371. const out = [0, 0, 0, 0];
  4372. const table = this._tables[dir];
  4373. // load up the tables
  4374. const t0 = table[0];
  4375. const t1 = table[1];
  4376. const t2 = table[2];
  4377. const t3 = table[3];
  4378. const sbox = table[4];
  4379. // state variables a,b,c,d are loaded with pre-whitened data
  4380. let a = input[0] ^ key[0];
  4381. let b = input[dir ? 3 : 1] ^ key[1];
  4382. let c = input[2] ^ key[2];
  4383. let d = input[dir ? 1 : 3] ^ key[3];
  4384. let kIndex = 4;
  4385. let a2, b2, c2;
  4386. // Inner rounds. Cribbed from OpenSSL.
  4387. for (let i = 0; i < nInnerRounds; i++) {
  4388. a2 = t0[a >>> 24] ^ t1[b >> 16 & 255] ^ t2[c >> 8 & 255] ^ t3[d & 255] ^ key[kIndex];
  4389. b2 = t0[b >>> 24] ^ t1[c >> 16 & 255] ^ t2[d >> 8 & 255] ^ t3[a & 255] ^ key[kIndex + 1];
  4390. c2 = t0[c >>> 24] ^ t1[d >> 16 & 255] ^ t2[a >> 8 & 255] ^ t3[b & 255] ^ key[kIndex + 2];
  4391. d = t0[d >>> 24] ^ t1[a >> 16 & 255] ^ t2[b >> 8 & 255] ^ t3[c & 255] ^ key[kIndex + 3];
  4392. kIndex += 4;
  4393. a = a2; b = b2; c = c2;
  4394. }
  4395. // Last round.
  4396. for (let i = 0; i < 4; i++) {
  4397. out[dir ? 3 & -i : i] =
  4398. sbox[a >>> 24] << 24 ^
  4399. sbox[b >> 16 & 255] << 16 ^
  4400. sbox[c >> 8 & 255] << 8 ^
  4401. sbox[d & 255] ^
  4402. key[kIndex++];
  4403. a2 = a; a = b; b = c; c = d; d = a2;
  4404. }
  4405. return out;
  4406. }
  4407. };
  4408. /**
  4409. * Random values
  4410. * @namespace
  4411. */
  4412. const random = {
  4413. /**
  4414. * Generate random words with pure js, cryptographically not as strong & safe as native implementation.
  4415. * @param {TypedArray} typedArray The array to fill.
  4416. * @return {TypedArray} The random values.
  4417. */
  4418. getRandomValues(typedArray) {
  4419. const words = new Uint32Array(typedArray.buffer);
  4420. const r = (m_w) => {
  4421. let m_z = 0x3ade68b1;
  4422. const mask = 0xffffffff;
  4423. return function () {
  4424. m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
  4425. m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
  4426. const result = ((((m_z << 0x10) + m_w) & mask) / 0x100000000) + .5;
  4427. return result * (Math.random() > .5 ? 1 : -1);
  4428. };
  4429. };
  4430. for (let i = 0, rcache; i < typedArray.length; i += 4) {
  4431. const _r = r((rcache || Math.random()) * 0x100000000);
  4432. rcache = _r() * 0x3ade67b7;
  4433. words[i / 4] = (_r() * 0x100000000) | 0;
  4434. }
  4435. return typedArray;
  4436. }
  4437. };
  4438. /** @fileOverview CTR mode implementation.
  4439. *
  4440. * Special thanks to Roy Nicholson for pointing out a bug in our
  4441. * implementation.
  4442. *
  4443. * @author Emily Stark
  4444. * @author Mike Hamburg
  4445. * @author Dan Boneh
  4446. */
  4447. /** Brian Gladman's CTR Mode.
  4448. * @constructor
  4449. * @param {Object} _prf The aes instance to generate key.
  4450. * @param {bitArray} _iv The iv for ctr mode, it must be 128 bits.
  4451. */
  4452. const mode = {};
  4453. /**
  4454. * Brian Gladman's CTR Mode.
  4455. * @namespace
  4456. */
  4457. mode.ctrGladman = class {
  4458. constructor(prf, iv) {
  4459. this._prf = prf;
  4460. this._initIv = iv;
  4461. this._iv = iv;
  4462. }
  4463. reset() {
  4464. this._iv = this._initIv;
  4465. }
  4466. /** Input some data to calculate.
  4467. * @param {bitArray} data the data to process, it must be intergral multiple of 128 bits unless it's the last.
  4468. */
  4469. update(data) {
  4470. return this.calculate(this._prf, data, this._iv);
  4471. }
  4472. incWord(word) {
  4473. if (((word >> 24) & 0xff) === 0xff) { //overflow
  4474. let b1 = (word >> 16) & 0xff;
  4475. let b2 = (word >> 8) & 0xff;
  4476. let b3 = word & 0xff;
  4477. if (b1 === 0xff) { // overflow b1
  4478. b1 = 0;
  4479. if (b2 === 0xff) {
  4480. b2 = 0;
  4481. if (b3 === 0xff) {
  4482. b3 = 0;
  4483. } else {
  4484. ++b3;
  4485. }
  4486. } else {
  4487. ++b2;
  4488. }
  4489. } else {
  4490. ++b1;
  4491. }
  4492. word = 0;
  4493. word += (b1 << 16);
  4494. word += (b2 << 8);
  4495. word += b3;
  4496. } else {
  4497. word += (0x01 << 24);
  4498. }
  4499. return word;
  4500. }
  4501. incCounter(counter) {
  4502. if ((counter[0] = this.incWord(counter[0])) === 0) {
  4503. // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
  4504. counter[1] = this.incWord(counter[1]);
  4505. }
  4506. }
  4507. calculate(prf, data, iv) {
  4508. let l;
  4509. if (!(l = data.length)) {
  4510. return [];
  4511. }
  4512. const bl = bitArray.bitLength(data);
  4513. for (let i = 0; i < l; i += 4) {
  4514. this.incCounter(iv);
  4515. const e = prf.encrypt(iv);
  4516. data[i] ^= e[0];
  4517. data[i + 1] ^= e[1];
  4518. data[i + 2] ^= e[2];
  4519. data[i + 3] ^= e[3];
  4520. }
  4521. return bitArray.clamp(data, bl);
  4522. }
  4523. };
  4524. const misc = {
  4525. importKey(password) {
  4526. return new misc.hmacSha1(codec.bytes.toBits(password));
  4527. },
  4528. pbkdf2(prf, salt, count, length) {
  4529. count = count || 10000;
  4530. if (length < 0 || count < 0) {
  4531. throw new Error("invalid params to pbkdf2");
  4532. }
  4533. const byteLength = ((length >> 5) + 1) << 2;
  4534. let u, ui, i, j, k;
  4535. const arrayBuffer = new ArrayBuffer(byteLength);
  4536. const out = new DataView(arrayBuffer);
  4537. let outLength = 0;
  4538. const b = bitArray;
  4539. salt = codec.bytes.toBits(salt);
  4540. for (k = 1; outLength < (byteLength || 1); k++) {
  4541. u = ui = prf.encrypt(b.concat(salt, [k]));
  4542. for (i = 1; i < count; i++) {
  4543. ui = prf.encrypt(ui);
  4544. for (j = 0; j < ui.length; j++) {
  4545. u[j] ^= ui[j];
  4546. }
  4547. }
  4548. for (i = 0; outLength < (byteLength || 1) && i < u.length; i++) {
  4549. out.setInt32(outLength, u[i]);
  4550. outLength += 4;
  4551. }
  4552. }
  4553. return arrayBuffer.slice(0, length / 8);
  4554. }
  4555. };
  4556. /** @fileOverview HMAC implementation.
  4557. *
  4558. * @author Emily Stark
  4559. * @author Mike Hamburg
  4560. * @author Dan Boneh
  4561. */
  4562. /** HMAC with the specified hash function.
  4563. * @constructor
  4564. * @param {bitArray} key the key for HMAC.
  4565. * @param {Object} [Hash=hash.sha1] The hash function to use.
  4566. */
  4567. misc.hmacSha1 = class {
  4568. constructor(key) {
  4569. const hmac = this;
  4570. const Hash = hmac._hash = hash.sha1;
  4571. const exKey = [[], []];
  4572. const bs = Hash.prototype.blockSize / 32;
  4573. hmac._baseHash = [new Hash(), new Hash()];
  4574. if (key.length > bs) {
  4575. key = Hash.hash(key);
  4576. }
  4577. for (let i = 0; i < bs; i++) {
  4578. exKey[0][i] = key[i] ^ 0x36363636;
  4579. exKey[1][i] = key[i] ^ 0x5C5C5C5C;
  4580. }
  4581. hmac._baseHash[0].update(exKey[0]);
  4582. hmac._baseHash[1].update(exKey[1]);
  4583. hmac._resultHash = new Hash(hmac._baseHash[0]);
  4584. }
  4585. reset() {
  4586. const hmac = this;
  4587. hmac._resultHash = new hmac._hash(hmac._baseHash[0]);
  4588. hmac._updated = false;
  4589. }
  4590. update(data) {
  4591. const hmac = this;
  4592. hmac._updated = true;
  4593. hmac._resultHash.update(data);
  4594. }
  4595. digest() {
  4596. const hmac = this;
  4597. const w = hmac._resultHash.finalize();
  4598. const result = new (hmac._hash)(hmac._baseHash[1]).update(w).finalize();
  4599. hmac.reset();
  4600. return result;
  4601. }
  4602. encrypt(data) {
  4603. if (!this._updated) {
  4604. this.update(data);
  4605. return this.digest(data);
  4606. } else {
  4607. throw new Error("encrypt on already updated hmac called!");
  4608. }
  4609. }
  4610. };
  4611. /*
  4612. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  4613. Redistribution and use in source and binary forms, with or without
  4614. modification, are permitted provided that the following conditions are met:
  4615. 1. Redistributions of source code must retain the above copyright notice,
  4616. this list of conditions and the following disclaimer.
  4617. 2. Redistributions in binary form must reproduce the above copyright
  4618. notice, this list of conditions and the following disclaimer in
  4619. the documentation and/or other materials provided with the distribution.
  4620. 3. The names of the authors may not be used to endorse or promote products
  4621. derived from this software without specific prior written permission.
  4622. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  4623. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  4624. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  4625. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  4626. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4627. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  4628. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4629. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4630. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4631. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4632. */
  4633. const ERR_INVALID_PASSWORD = "Invalid pasword";
  4634. const BLOCK_LENGTH = 16;
  4635. const RAW_FORMAT = "raw";
  4636. const PBKDF2_ALGORITHM = { name: "PBKDF2" };
  4637. const HASH_ALGORITHM = { name: "HMAC" };
  4638. const HASH_FUNCTION = "SHA-1";
  4639. const BASE_KEY_ALGORITHM = Object.assign({ hash: HASH_ALGORITHM }, PBKDF2_ALGORITHM);
  4640. const DERIVED_BITS_ALGORITHM = Object.assign({ iterations: 1000, hash: { name: HASH_FUNCTION } }, PBKDF2_ALGORITHM);
  4641. const DERIVED_BITS_USAGE = ["deriveBits"];
  4642. const SALT_LENGTH = [8, 12, 16];
  4643. const KEY_LENGTH = [16, 24, 32];
  4644. const SIGNATURE_LENGTH = 10;
  4645. const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];
  4646. const CRYPTO_API_SUPPORTED = typeof crypto != "undefined";
  4647. const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof crypto.subtle != "undefined";
  4648. const codecBytes = codec.bytes;
  4649. const Aes = cipher.aes;
  4650. const CtrGladman = mode.ctrGladman;
  4651. const HmacSha1 = misc.hmacSha1;
  4652. class AESDecrypt {
  4653. constructor(password, signed, strength) {
  4654. Object.assign(this, {
  4655. password,
  4656. signed,
  4657. strength: strength - 1,
  4658. pendingInput: new Uint8Array(0)
  4659. });
  4660. }
  4661. async append(input) {
  4662. const aesCrypto = this;
  4663. if (aesCrypto.password) {
  4664. const preamble = subarray(input, 0, SALT_LENGTH[aesCrypto.strength] + 2);
  4665. await createDecryptionKeys(aesCrypto, preamble, aesCrypto.password);
  4666. aesCrypto.password = null;
  4667. aesCrypto.aesCtrGladman = new CtrGladman(new Aes(aesCrypto.keys.key), Array.from(COUNTER_DEFAULT_VALUE));
  4668. aesCrypto.hmac = new HmacSha1(aesCrypto.keys.authentication);
  4669. input = subarray(input, SALT_LENGTH[aesCrypto.strength] + 2);
  4670. }
  4671. const output = new Uint8Array(input.length - SIGNATURE_LENGTH - ((input.length - SIGNATURE_LENGTH) % BLOCK_LENGTH));
  4672. return append(aesCrypto, input, output, 0, SIGNATURE_LENGTH, true);
  4673. }
  4674. flush() {
  4675. const aesCrypto = this;
  4676. const pendingInput = aesCrypto.pendingInput;
  4677. const chunkToDecrypt = subarray(pendingInput, 0, pendingInput.length - SIGNATURE_LENGTH);
  4678. const originalSignature = subarray(pendingInput, pendingInput.length - SIGNATURE_LENGTH);
  4679. let decryptedChunkArray = new Uint8Array(0);
  4680. if (chunkToDecrypt.length) {
  4681. const encryptedChunk = codecBytes.toBits(chunkToDecrypt);
  4682. aesCrypto.hmac.update(encryptedChunk);
  4683. const decryptedChunk = aesCrypto.aesCtrGladman.update(encryptedChunk);
  4684. decryptedChunkArray = codecBytes.fromBits(decryptedChunk);
  4685. }
  4686. let valid = true;
  4687. if (aesCrypto.signed) {
  4688. const signature = subarray(codecBytes.fromBits(aesCrypto.hmac.digest()), 0, SIGNATURE_LENGTH);
  4689. for (let indexSignature = 0; indexSignature < SIGNATURE_LENGTH; indexSignature++) {
  4690. if (signature[indexSignature] != originalSignature[indexSignature]) {
  4691. valid = false;
  4692. }
  4693. }
  4694. }
  4695. return {
  4696. valid,
  4697. data: decryptedChunkArray
  4698. };
  4699. }
  4700. }
  4701. class AESEncrypt {
  4702. constructor(password, strength) {
  4703. Object.assign(this, {
  4704. password,
  4705. strength: strength - 1,
  4706. pendingInput: new Uint8Array(0)
  4707. });
  4708. }
  4709. async append(input) {
  4710. const aesCrypto = this;
  4711. let preamble = new Uint8Array(0);
  4712. if (aesCrypto.password) {
  4713. preamble = await createEncryptionKeys(aesCrypto, aesCrypto.password);
  4714. aesCrypto.password = null;
  4715. aesCrypto.aesCtrGladman = new CtrGladman(new Aes(aesCrypto.keys.key), Array.from(COUNTER_DEFAULT_VALUE));
  4716. aesCrypto.hmac = new HmacSha1(aesCrypto.keys.authentication);
  4717. }
  4718. const output = new Uint8Array(preamble.length + input.length - (input.length % BLOCK_LENGTH));
  4719. output.set(preamble, 0);
  4720. return append(aesCrypto, input, output, preamble.length, 0);
  4721. }
  4722. flush() {
  4723. const aesCrypto = this;
  4724. let encryptedChunkArray = new Uint8Array(0);
  4725. if (aesCrypto.pendingInput.length) {
  4726. const encryptedChunk = aesCrypto.aesCtrGladman.update(codecBytes.toBits(aesCrypto.pendingInput));
  4727. aesCrypto.hmac.update(encryptedChunk);
  4728. encryptedChunkArray = codecBytes.fromBits(encryptedChunk);
  4729. }
  4730. const signature = subarray(codecBytes.fromBits(aesCrypto.hmac.digest()), 0, SIGNATURE_LENGTH);
  4731. return {
  4732. data: concat(encryptedChunkArray, signature),
  4733. signature
  4734. };
  4735. }
  4736. }
  4737. function append(aesCrypto, input, output, paddingStart, paddingEnd, verifySignature) {
  4738. const inputLength = input.length - paddingEnd;
  4739. if (aesCrypto.pendingInput.length) {
  4740. input = concat(aesCrypto.pendingInput, input);
  4741. output = expand(output, inputLength - (inputLength % BLOCK_LENGTH));
  4742. }
  4743. let offset;
  4744. for (offset = 0; offset <= inputLength - BLOCK_LENGTH; offset += BLOCK_LENGTH) {
  4745. const inputChunk = codecBytes.toBits(subarray(input, offset, offset + BLOCK_LENGTH));
  4746. if (verifySignature) {
  4747. aesCrypto.hmac.update(inputChunk);
  4748. }
  4749. const outputChunk = aesCrypto.aesCtrGladman.update(inputChunk);
  4750. if (!verifySignature) {
  4751. aesCrypto.hmac.update(outputChunk);
  4752. }
  4753. output.set(codecBytes.fromBits(outputChunk), offset + paddingStart);
  4754. }
  4755. aesCrypto.pendingInput = subarray(input, offset);
  4756. return output;
  4757. }
  4758. async function createDecryptionKeys(decrypt, preambleArray, password) {
  4759. await createKeys$1(decrypt, password, subarray(preambleArray, 0, SALT_LENGTH[decrypt.strength]));
  4760. const passwordVerification = subarray(preambleArray, SALT_LENGTH[decrypt.strength]);
  4761. const passwordVerificationKey = decrypt.keys.passwordVerification;
  4762. if (passwordVerificationKey[0] != passwordVerification[0] || passwordVerificationKey[1] != passwordVerification[1]) {
  4763. throw new Error(ERR_INVALID_PASSWORD);
  4764. }
  4765. }
  4766. async function createEncryptionKeys(encrypt, password) {
  4767. const salt = getRandomValues(new Uint8Array(SALT_LENGTH[encrypt.strength]));
  4768. await createKeys$1(encrypt, password, salt);
  4769. return concat(salt, encrypt.keys.passwordVerification);
  4770. }
  4771. async function createKeys$1(target, password, salt) {
  4772. const encodedPassword = encodeText(password);
  4773. const basekey = await importKey(RAW_FORMAT, encodedPassword, BASE_KEY_ALGORITHM, false, DERIVED_BITS_USAGE);
  4774. const derivedBits = await deriveBits(Object.assign({ salt }, DERIVED_BITS_ALGORITHM), basekey, 8 * ((KEY_LENGTH[target.strength] * 2) + 2));
  4775. const compositeKey = new Uint8Array(derivedBits);
  4776. target.keys = {
  4777. key: codecBytes.toBits(subarray(compositeKey, 0, KEY_LENGTH[target.strength])),
  4778. authentication: codecBytes.toBits(subarray(compositeKey, KEY_LENGTH[target.strength], KEY_LENGTH[target.strength] * 2)),
  4779. passwordVerification: subarray(compositeKey, KEY_LENGTH[target.strength] * 2)
  4780. };
  4781. }
  4782. function getRandomValues(array) {
  4783. if (CRYPTO_API_SUPPORTED && typeof crypto.getRandomValues == "function") {
  4784. return crypto.getRandomValues(array);
  4785. } else {
  4786. return random.getRandomValues(array);
  4787. }
  4788. }
  4789. function importKey(format, password, algorithm, extractable, keyUsages) {
  4790. if (CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof crypto.subtle.importKey == "function") {
  4791. return crypto.subtle.importKey(format, password, algorithm, extractable, keyUsages);
  4792. } else {
  4793. return misc.importKey(password);
  4794. }
  4795. }
  4796. async function deriveBits(algorithm, baseKey, length) {
  4797. if (CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof crypto.subtle.deriveBits == "function") {
  4798. return await crypto.subtle.deriveBits(algorithm, baseKey, length);
  4799. } else {
  4800. return misc.pbkdf2(baseKey, algorithm.salt, DERIVED_BITS_ALGORITHM.iterations, length);
  4801. }
  4802. }
  4803. function concat(leftArray, rightArray) {
  4804. let array = leftArray;
  4805. if (leftArray.length + rightArray.length) {
  4806. array = new Uint8Array(leftArray.length + rightArray.length);
  4807. array.set(leftArray, 0);
  4808. array.set(rightArray, leftArray.length);
  4809. }
  4810. return array;
  4811. }
  4812. function expand(inputArray, length) {
  4813. if (length && length > inputArray.length) {
  4814. const array = inputArray;
  4815. inputArray = new Uint8Array(length);
  4816. inputArray.set(array, 0);
  4817. }
  4818. return inputArray;
  4819. }
  4820. function subarray(array, begin, end) {
  4821. return array.subarray(begin, end);
  4822. }
  4823. /*
  4824. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  4825. Redistribution and use in source and binary forms, with or without
  4826. modification, are permitted provided that the following conditions are met:
  4827. 1. Redistributions of source code must retain the above copyright notice,
  4828. this list of conditions and the following disclaimer.
  4829. 2. Redistributions in binary form must reproduce the above copyright
  4830. notice, this list of conditions and the following disclaimer in
  4831. the documentation and/or other materials provided with the distribution.
  4832. 3. The names of the authors may not be used to endorse or promote products
  4833. derived from this software without specific prior written permission.
  4834. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  4835. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  4836. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  4837. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  4838. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4839. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  4840. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4841. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4842. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4843. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4844. */
  4845. const HEADER_LENGTH = 12;
  4846. class ZipCryptoDecrypt {
  4847. constructor(password, passwordVerification) {
  4848. const zipCrypto = this;
  4849. Object.assign(zipCrypto, {
  4850. password,
  4851. passwordVerification
  4852. });
  4853. createKeys(zipCrypto, password);
  4854. }
  4855. append(input) {
  4856. const zipCrypto = this;
  4857. if (zipCrypto.password) {
  4858. const decryptedHeader = decrypt(zipCrypto, input.subarray(0, HEADER_LENGTH));
  4859. zipCrypto.password = null;
  4860. if (decryptedHeader[HEADER_LENGTH - 1] != zipCrypto.passwordVerification) {
  4861. throw new Error(ERR_INVALID_PASSWORD);
  4862. }
  4863. input = input.subarray(HEADER_LENGTH);
  4864. }
  4865. return decrypt(zipCrypto, input);
  4866. }
  4867. flush() {
  4868. return {
  4869. valid: true,
  4870. data: new Uint8Array(0)
  4871. };
  4872. }
  4873. }
  4874. class ZipCryptoEncrypt {
  4875. constructor(password, passwordVerification) {
  4876. const zipCrypto = this;
  4877. Object.assign(zipCrypto, {
  4878. password,
  4879. passwordVerification
  4880. });
  4881. createKeys(zipCrypto, password);
  4882. }
  4883. append(input) {
  4884. const zipCrypto = this;
  4885. let output;
  4886. let offset;
  4887. if (zipCrypto.password) {
  4888. zipCrypto.password = null;
  4889. const header = crypto.getRandomValues(new Uint8Array(HEADER_LENGTH));
  4890. header[HEADER_LENGTH - 1] = zipCrypto.passwordVerification;
  4891. output = new Uint8Array(input.length + header.length);
  4892. output.set(encrypt(zipCrypto, header), 0);
  4893. offset = HEADER_LENGTH;
  4894. } else {
  4895. output = new Uint8Array(input.length);
  4896. offset = 0;
  4897. }
  4898. output.set(encrypt(zipCrypto, input), offset);
  4899. return output;
  4900. }
  4901. flush() {
  4902. return {
  4903. data: new Uint8Array(0)
  4904. };
  4905. }
  4906. }
  4907. function decrypt(target, input) {
  4908. const output = new Uint8Array(input.length);
  4909. for (let index = 0; index < input.length; index++) {
  4910. output[index] = getByte(target) ^ input[index];
  4911. updateKeys(target, output[index]);
  4912. }
  4913. return output;
  4914. }
  4915. function encrypt(target, input) {
  4916. const output = new Uint8Array(input.length);
  4917. for (let index = 0; index < input.length; index++) {
  4918. output[index] = getByte(target) ^ input[index];
  4919. updateKeys(target, input[index]);
  4920. }
  4921. return output;
  4922. }
  4923. function createKeys(target, password) {
  4924. target.keys = [0x12345678, 0x23456789, 0x34567890];
  4925. target.crcKey0 = new Crc32(target.keys[0]);
  4926. target.crcKey2 = new Crc32(target.keys[2]);
  4927. for (let index = 0; index < password.length; index++) {
  4928. updateKeys(target, password.charCodeAt(index));
  4929. }
  4930. }
  4931. function updateKeys(target, byte) {
  4932. target.crcKey0.append([byte]);
  4933. target.keys[0] = ~target.crcKey0.get();
  4934. target.keys[1] = getInt32(target.keys[1] + getInt8(target.keys[0]));
  4935. target.keys[1] = getInt32(Math.imul(target.keys[1], 134775813) + 1);
  4936. target.crcKey2.append([target.keys[1] >>> 24]);
  4937. target.keys[2] = ~target.crcKey2.get();
  4938. }
  4939. function getByte(target) {
  4940. const temp = target.keys[2] | 2;
  4941. return getInt8(Math.imul(temp, (temp ^ 1)) >>> 8);
  4942. }
  4943. function getInt8(number) {
  4944. return number & 0xFF;
  4945. }
  4946. function getInt32(number) {
  4947. return number & 0xFFFFFFFF;
  4948. }
  4949. /*
  4950. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  4951. Redistribution and use in source and binary forms, with or without
  4952. modification, are permitted provided that the following conditions are met:
  4953. 1. Redistributions of source code must retain the above copyright notice,
  4954. this list of conditions and the following disclaimer.
  4955. 2. Redistributions in binary form must reproduce the above copyright
  4956. notice, this list of conditions and the following disclaimer in
  4957. the documentation and/or other materials provided with the distribution.
  4958. 3. The names of the authors may not be used to endorse or promote products
  4959. derived from this software without specific prior written permission.
  4960. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  4961. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  4962. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  4963. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  4964. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4965. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  4966. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4967. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4968. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4969. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4970. */
  4971. const CODEC_DEFLATE = "deflate";
  4972. const CODEC_INFLATE = "inflate";
  4973. const ERR_INVALID_SIGNATURE = "Invalid signature";
  4974. class Inflate {
  4975. constructor(codecConstructor, {
  4976. signature,
  4977. password,
  4978. signed,
  4979. compressed,
  4980. zipCrypto,
  4981. passwordVerification,
  4982. encryptionStrength
  4983. }, { chunkSize }) {
  4984. const encrypted = Boolean(password);
  4985. Object.assign(this, {
  4986. signature,
  4987. encrypted,
  4988. signed,
  4989. compressed,
  4990. inflate: compressed && new codecConstructor({ chunkSize }),
  4991. crc32: signed && new Crc32(),
  4992. zipCrypto,
  4993. decrypt: encrypted && zipCrypto ?
  4994. new ZipCryptoDecrypt(password, passwordVerification) :
  4995. new AESDecrypt(password, signed, encryptionStrength)
  4996. });
  4997. }
  4998. async append(data) {
  4999. const codec = this;
  5000. if (codec.encrypted && data.length) {
  5001. data = await codec.decrypt.append(data);
  5002. }
  5003. if (codec.compressed && data.length) {
  5004. data = await codec.inflate.append(data);
  5005. }
  5006. if ((!codec.encrypted || codec.zipCrypto) && codec.signed && data.length) {
  5007. codec.crc32.append(data);
  5008. }
  5009. return data;
  5010. }
  5011. async flush() {
  5012. const codec = this;
  5013. let signature;
  5014. let data = new Uint8Array(0);
  5015. if (codec.encrypted) {
  5016. const result = codec.decrypt.flush();
  5017. if (!result.valid) {
  5018. throw new Error(ERR_INVALID_SIGNATURE);
  5019. }
  5020. data = result.data;
  5021. }
  5022. if ((!codec.encrypted || codec.zipCrypto) && codec.signed) {
  5023. const dataViewSignature = new DataView(new Uint8Array(4).buffer);
  5024. signature = codec.crc32.get();
  5025. dataViewSignature.setUint32(0, signature);
  5026. if (codec.signature != dataViewSignature.getUint32(0, false)) {
  5027. throw new Error(ERR_INVALID_SIGNATURE);
  5028. }
  5029. }
  5030. if (codec.compressed) {
  5031. data = (await codec.inflate.append(data)) || new Uint8Array(0);
  5032. await codec.inflate.flush();
  5033. }
  5034. return { data, signature };
  5035. }
  5036. }
  5037. class Deflate {
  5038. constructor(codecConstructor, {
  5039. encrypted,
  5040. signed,
  5041. compressed,
  5042. level,
  5043. zipCrypto,
  5044. password,
  5045. passwordVerification,
  5046. encryptionStrength
  5047. }, { chunkSize }) {
  5048. Object.assign(this, {
  5049. encrypted,
  5050. signed,
  5051. compressed,
  5052. deflate: compressed && new codecConstructor({ level: level || 5, chunkSize }),
  5053. crc32: signed && new Crc32(),
  5054. zipCrypto,
  5055. encrypt: encrypted && zipCrypto ?
  5056. new ZipCryptoEncrypt(password, passwordVerification) :
  5057. new AESEncrypt(password, encryptionStrength)
  5058. });
  5059. }
  5060. async append(inputData) {
  5061. const codec = this;
  5062. let data = inputData;
  5063. if (codec.compressed && inputData.length) {
  5064. data = await codec.deflate.append(inputData);
  5065. }
  5066. if (codec.encrypted && data.length) {
  5067. data = await codec.encrypt.append(data);
  5068. }
  5069. if ((!codec.encrypted || codec.zipCrypto) && codec.signed && inputData.length) {
  5070. codec.crc32.append(inputData);
  5071. }
  5072. return data;
  5073. }
  5074. async flush() {
  5075. const codec = this;
  5076. let signature;
  5077. let data = new Uint8Array(0);
  5078. if (codec.compressed) {
  5079. data = (await codec.deflate.flush()) || new Uint8Array(0);
  5080. }
  5081. if (codec.encrypted) {
  5082. data = await codec.encrypt.append(data);
  5083. const result = codec.encrypt.flush();
  5084. signature = result.signature;
  5085. const newData = new Uint8Array(data.length + result.data.length);
  5086. newData.set(data, 0);
  5087. newData.set(result.data, data.length);
  5088. data = newData;
  5089. }
  5090. if ((!codec.encrypted || codec.zipCrypto) && codec.signed) {
  5091. signature = codec.crc32.get();
  5092. }
  5093. return { data, signature };
  5094. }
  5095. }
  5096. function createCodec$1(codecConstructor, options, config) {
  5097. if (options.codecType.startsWith(CODEC_DEFLATE)) {
  5098. return new Deflate(codecConstructor, options, config);
  5099. } else if (options.codecType.startsWith(CODEC_INFLATE)) {
  5100. return new Inflate(codecConstructor, options, config);
  5101. }
  5102. }
  5103. /*
  5104. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  5105. Redistribution and use in source and binary forms, with or without
  5106. modification, are permitted provided that the following conditions are met:
  5107. 1. Redistributions of source code must retain the above copyright notice,
  5108. this list of conditions and the following disclaimer.
  5109. 2. Redistributions in binary form must reproduce the above copyright
  5110. notice, this list of conditions and the following disclaimer in
  5111. the documentation and/or other materials provided with the distribution.
  5112. 3. The names of the authors may not be used to endorse or promote products
  5113. derived from this software without specific prior written permission.
  5114. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  5115. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  5116. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  5117. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  5118. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5119. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  5120. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5121. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5122. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5123. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5124. */
  5125. const MESSAGE_INIT = "init";
  5126. const MESSAGE_APPEND = "append";
  5127. const MESSAGE_FLUSH = "flush";
  5128. const MESSAGE_EVENT_TYPE = "message";
  5129. let classicWorkersSupported = true;
  5130. var getWorker = (workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts) => {
  5131. Object.assign(workerData, {
  5132. busy: true,
  5133. codecConstructor,
  5134. options: Object.assign({}, options),
  5135. scripts,
  5136. terminate() {
  5137. if (workerData.worker && !workerData.busy) {
  5138. workerData.worker.terminate();
  5139. workerData.interface = null;
  5140. }
  5141. },
  5142. onTaskFinished() {
  5143. workerData.busy = false;
  5144. onTaskFinished(workerData);
  5145. }
  5146. });
  5147. return webWorker ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);
  5148. };
  5149. function createWorkerInterface(workerData, config) {
  5150. const interfaceCodec = createCodec$1(workerData.codecConstructor, workerData.options, config);
  5151. return {
  5152. async append(data) {
  5153. try {
  5154. return await interfaceCodec.append(data);
  5155. } catch (error) {
  5156. workerData.onTaskFinished();
  5157. throw error;
  5158. }
  5159. },
  5160. async flush() {
  5161. try {
  5162. return await interfaceCodec.flush();
  5163. } finally {
  5164. workerData.onTaskFinished();
  5165. }
  5166. },
  5167. abort() {
  5168. workerData.onTaskFinished();
  5169. }
  5170. };
  5171. }
  5172. function createWebWorkerInterface(workerData, config) {
  5173. let messageTask;
  5174. const workerOptions = { type: "module" };
  5175. if (!workerData.interface) {
  5176. if (!classicWorkersSupported) {
  5177. workerData.worker = getWorker(workerOptions, config.baseURL);
  5178. } else {
  5179. try {
  5180. workerData.worker = getWorker({}, config.baseURL);
  5181. } catch (_error) {
  5182. classicWorkersSupported = false;
  5183. workerData.worker = getWorker(workerOptions, config.baseURL);
  5184. }
  5185. }
  5186. workerData.worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false);
  5187. workerData.interface = {
  5188. append(data) {
  5189. return initAndSendMessage({ type: MESSAGE_APPEND, data });
  5190. },
  5191. flush() {
  5192. return initAndSendMessage({ type: MESSAGE_FLUSH });
  5193. },
  5194. abort() {
  5195. workerData.onTaskFinished();
  5196. }
  5197. };
  5198. }
  5199. return workerData.interface;
  5200. function getWorker(options, baseURL) {
  5201. let url, scriptUrl;
  5202. url = workerData.scripts[0];
  5203. if (typeof url == "function") {
  5204. url = url();
  5205. }
  5206. try {
  5207. scriptUrl = new URL(url, baseURL);
  5208. } catch (_error) {
  5209. scriptUrl = url;
  5210. }
  5211. return new Worker(scriptUrl, options);
  5212. }
  5213. async function initAndSendMessage(message) {
  5214. if (!messageTask) {
  5215. const options = workerData.options;
  5216. const scripts = workerData.scripts.slice(1);
  5217. await sendMessage({ scripts, type: MESSAGE_INIT, options, config: { chunkSize: config.chunkSize } });
  5218. }
  5219. return sendMessage(message);
  5220. }
  5221. function sendMessage(message) {
  5222. const worker = workerData.worker;
  5223. const result = new Promise((resolve, reject) => messageTask = { resolve, reject });
  5224. try {
  5225. if (message.data) {
  5226. try {
  5227. message.data = message.data.buffer;
  5228. worker.postMessage(message, [message.data]);
  5229. } catch (_error) {
  5230. worker.postMessage(message);
  5231. }
  5232. } else {
  5233. worker.postMessage(message);
  5234. }
  5235. } catch (error) {
  5236. messageTask.reject(error);
  5237. messageTask = null;
  5238. workerData.onTaskFinished();
  5239. }
  5240. return result;
  5241. }
  5242. function onMessage(event) {
  5243. const message = event.data;
  5244. if (messageTask) {
  5245. const reponseError = message.error;
  5246. const type = message.type;
  5247. if (reponseError) {
  5248. const error = new Error(reponseError.message);
  5249. error.stack = reponseError.stack;
  5250. messageTask.reject(error);
  5251. messageTask = null;
  5252. workerData.onTaskFinished();
  5253. } else if (type == MESSAGE_INIT || type == MESSAGE_FLUSH || type == MESSAGE_APPEND) {
  5254. const data = message.data;
  5255. if (type == MESSAGE_FLUSH) {
  5256. messageTask.resolve({ data: new Uint8Array(data), signature: message.signature });
  5257. messageTask = null;
  5258. workerData.onTaskFinished();
  5259. } else {
  5260. messageTask.resolve(data && new Uint8Array(data));
  5261. }
  5262. }
  5263. }
  5264. }
  5265. }
  5266. /*
  5267. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  5268. Redistribution and use in source and binary forms, with or without
  5269. modification, are permitted provided that the following conditions are met:
  5270. 1. Redistributions of source code must retain the above copyright notice,
  5271. this list of conditions and the following disclaimer.
  5272. 2. Redistributions in binary form must reproduce the above copyright
  5273. notice, this list of conditions and the following disclaimer in
  5274. the documentation and/or other materials provided with the distribution.
  5275. 3. The names of the authors may not be used to endorse or promote products
  5276. derived from this software without specific prior written permission.
  5277. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  5278. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  5279. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  5280. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  5281. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5282. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  5283. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5284. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5285. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5286. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5287. */
  5288. let pool = [];
  5289. const pendingRequests = [];
  5290. function createCodec(codecConstructor, options, config) {
  5291. const streamCopy = !options.compressed && !options.signed && !options.encrypted;
  5292. const webWorker = !streamCopy && (options.useWebWorkers || (options.useWebWorkers === undefined && config.useWebWorkers));
  5293. const scripts = webWorker && config.workerScripts ? config.workerScripts[options.codecType] : [];
  5294. if (pool.length < config.maxWorkers) {
  5295. const workerData = {};
  5296. pool.push(workerData);
  5297. return getWorker(workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts);
  5298. } else {
  5299. const workerData = pool.find(workerData => !workerData.busy);
  5300. if (workerData) {
  5301. clearTerminateTimeout(workerData);
  5302. return getWorker(workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts);
  5303. } else {
  5304. return new Promise(resolve => pendingRequests.push({ resolve, codecConstructor, options, webWorker, scripts }));
  5305. }
  5306. }
  5307. function onTaskFinished(workerData) {
  5308. if (pendingRequests.length) {
  5309. const [{ resolve, codecConstructor, options, webWorker, scripts }] = pendingRequests.splice(0, 1);
  5310. resolve(getWorker(workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts));
  5311. } else if (workerData.worker) {
  5312. clearTerminateTimeout(workerData);
  5313. if (Number.isFinite(config.terminateWorkerTimeout) && config.terminateWorkerTimeout >= 0) {
  5314. workerData.terminateTimeout = setTimeout(() => {
  5315. pool = pool.filter(data => data != workerData);
  5316. workerData.terminate();
  5317. }, config.terminateWorkerTimeout);
  5318. }
  5319. } else {
  5320. pool = pool.filter(data => data != workerData);
  5321. }
  5322. }
  5323. }
  5324. function clearTerminateTimeout(workerData) {
  5325. if (workerData.terminateTimeout) {
  5326. clearTimeout(workerData.terminateTimeout);
  5327. workerData.terminateTimeout = null;
  5328. }
  5329. }
  5330. function terminateWorkers() {
  5331. pool.forEach(workerData => {
  5332. clearTerminateTimeout(workerData);
  5333. workerData.terminate();
  5334. });
  5335. }
  5336. /*
  5337. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  5338. Redistribution and use in source and binary forms, with or without
  5339. modification, are permitted provided that the following conditions are met:
  5340. 1. Redistributions of source code must retain the above copyright notice,
  5341. this list of conditions and the following disclaimer.
  5342. 2. Redistributions in binary form must reproduce the above copyright
  5343. notice, this list of conditions and the following disclaimer in
  5344. the documentation and/or other materials provided with the distribution.
  5345. 3. The names of the authors may not be used to endorse or promote products
  5346. derived from this software without specific prior written permission.
  5347. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  5348. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  5349. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  5350. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  5351. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5352. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  5353. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5354. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5355. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5356. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5357. */
  5358. const MINIMUM_CHUNK_SIZE = 64;
  5359. const ERR_ABORT = "Abort error";
  5360. async function processData(codec, reader, writer, offset, inputLengthGetter, config, options) {
  5361. const chunkSize = Math.max(config.chunkSize, MINIMUM_CHUNK_SIZE);
  5362. return processChunk();
  5363. async function processChunk(chunkOffset = 0, outputLength = 0) {
  5364. const signal = options.signal;
  5365. const inputLength = inputLengthGetter();
  5366. if (chunkOffset < inputLength) {
  5367. testAborted(signal, codec);
  5368. const inputData = await reader.readUint8Array(chunkOffset + offset, Math.min(chunkSize, inputLength - chunkOffset));
  5369. const chunkLength = inputData.length;
  5370. testAborted(signal, codec);
  5371. const data = await codec.append(inputData);
  5372. testAborted(signal, codec);
  5373. outputLength += await writeData(writer, data);
  5374. if (options.onprogress) {
  5375. try {
  5376. options.onprogress(chunkOffset + chunkLength, inputLength);
  5377. } catch (error) {
  5378. // ignored
  5379. }
  5380. }
  5381. return processChunk(chunkOffset + chunkSize, outputLength);
  5382. } else {
  5383. const result = await codec.flush();
  5384. outputLength += await writeData(writer, result.data);
  5385. return { signature: result.signature, length: outputLength };
  5386. }
  5387. }
  5388. }
  5389. function testAborted(signal, codec) {
  5390. if (signal && signal.aborted) {
  5391. codec.abort();
  5392. throw new Error(ERR_ABORT);
  5393. }
  5394. }
  5395. async function writeData(writer, data) {
  5396. if (data.length) {
  5397. await writer.writeUint8Array(data);
  5398. }
  5399. return data.length;
  5400. }
  5401. /*
  5402. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  5403. Redistribution and use in source and binary forms, with or without
  5404. modification, are permitted provided that the following conditions are met:
  5405. 1. Redistributions of source code must retain the above copyright notice,
  5406. this list of conditions and the following disclaimer.
  5407. 2. Redistributions in binary form must reproduce the above copyright
  5408. notice, this list of conditions and the following disclaimer in
  5409. the documentation and/or other materials provided with the distribution.
  5410. 3. The names of the authors may not be used to endorse or promote products
  5411. derived from this software without specific prior written permission.
  5412. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  5413. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  5414. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  5415. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  5416. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5417. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  5418. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5419. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5420. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5421. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5422. */
  5423. /* global Blob, FileReader, atob, btoa, XMLHttpRequest, document, fetch */
  5424. const ERR_HTTP_STATUS = "HTTP error ";
  5425. const ERR_HTTP_RANGE = "HTTP Range not supported";
  5426. const ERR_NOT_SEEKABLE_READER = "Reader is not seekable";
  5427. const CONTENT_TYPE_TEXT_PLAIN = "text/plain";
  5428. const HTTP_HEADER_CONTENT_LENGTH = "Content-Length";
  5429. const HTTP_HEADER_CONTENT_RANGE = "Content-Range";
  5430. const HTTP_HEADER_ACCEPT_RANGES = "Accept-Ranges";
  5431. const HTTP_HEADER_RANGE = "Range";
  5432. const HTTP_METHOD_HEAD = "HEAD";
  5433. const HTTP_METHOD_GET = "GET";
  5434. const HTTP_RANGE_UNIT = "bytes";
  5435. class Stream {
  5436. constructor() {
  5437. this.size = 0;
  5438. }
  5439. init() {
  5440. this.initialized = true;
  5441. }
  5442. }
  5443. class Reader extends Stream {
  5444. }
  5445. class Writer extends Stream {
  5446. writeUint8Array(array) {
  5447. this.size += array.length;
  5448. }
  5449. }
  5450. class TextReader extends Reader {
  5451. constructor(text) {
  5452. super();
  5453. this.blobReader = new BlobReader(new Blob([text], { type: CONTENT_TYPE_TEXT_PLAIN }));
  5454. }
  5455. init() {
  5456. super.init();
  5457. this.blobReader.init();
  5458. this.size = this.blobReader.size;
  5459. }
  5460. readUint8Array(offset, length) {
  5461. return this.blobReader.readUint8Array(offset, length);
  5462. }
  5463. }
  5464. class TextWriter extends Writer {
  5465. constructor(encoding) {
  5466. super();
  5467. this.encoding = encoding;
  5468. this.blob = new Blob([], { type: CONTENT_TYPE_TEXT_PLAIN });
  5469. }
  5470. writeUint8Array(array) {
  5471. super.writeUint8Array(array);
  5472. this.blob = new Blob([this.blob, array.buffer], { type: CONTENT_TYPE_TEXT_PLAIN });
  5473. }
  5474. getData() {
  5475. if (this.blob.text) {
  5476. return this.blob.text();
  5477. } else {
  5478. const reader = new FileReader();
  5479. return new Promise((resolve, reject) => {
  5480. reader.onload = event => resolve(event.target.result);
  5481. reader.onerror = () => reject(reader.error);
  5482. reader.readAsText(this.blob, this.encoding);
  5483. });
  5484. }
  5485. }
  5486. }
  5487. class Data64URIReader extends Reader {
  5488. constructor(dataURI) {
  5489. super();
  5490. this.dataURI = dataURI;
  5491. let dataEnd = dataURI.length;
  5492. while (dataURI.charAt(dataEnd - 1) == "=") {
  5493. dataEnd--;
  5494. }
  5495. this.dataStart = dataURI.indexOf(",") + 1;
  5496. this.size = Math.floor((dataEnd - this.dataStart) * 0.75);
  5497. }
  5498. readUint8Array(offset, length) {
  5499. const dataArray = new Uint8Array(length);
  5500. const start = Math.floor(offset / 3) * 4;
  5501. const bytes = atob(this.dataURI.substring(start + this.dataStart, Math.ceil((offset + length) / 3) * 4 + this.dataStart));
  5502. const delta = offset - Math.floor(start / 4) * 3;
  5503. for (let indexByte = delta; indexByte < delta + length; indexByte++) {
  5504. dataArray[indexByte - delta] = bytes.charCodeAt(indexByte);
  5505. }
  5506. return dataArray;
  5507. }
  5508. }
  5509. class Data64URIWriter extends Writer {
  5510. constructor(contentType) {
  5511. super();
  5512. this.data = "data:" + (contentType || "") + ";base64,";
  5513. this.pending = [];
  5514. }
  5515. writeUint8Array(array) {
  5516. super.writeUint8Array(array);
  5517. let indexArray = 0;
  5518. let dataString = this.pending;
  5519. const delta = this.pending.length;
  5520. this.pending = "";
  5521. for (indexArray = 0; indexArray < (Math.floor((delta + array.length) / 3) * 3) - delta; indexArray++) {
  5522. dataString += String.fromCharCode(array[indexArray]);
  5523. }
  5524. for (; indexArray < array.length; indexArray++) {
  5525. this.pending += String.fromCharCode(array[indexArray]);
  5526. }
  5527. if (dataString.length > 2) {
  5528. this.data += btoa(dataString);
  5529. } else {
  5530. this.pending = dataString;
  5531. }
  5532. }
  5533. getData() {
  5534. return this.data + btoa(this.pending);
  5535. }
  5536. }
  5537. class BlobReader extends Reader {
  5538. constructor(blob) {
  5539. super();
  5540. this.blob = blob;
  5541. this.size = blob.size;
  5542. }
  5543. async readUint8Array(offset, length) {
  5544. if (this.blob.arrayBuffer) {
  5545. return new Uint8Array(await this.blob.slice(offset, offset + length).arrayBuffer());
  5546. } else {
  5547. const reader = new FileReader();
  5548. return new Promise((resolve, reject) => {
  5549. reader.onload = event => resolve(new Uint8Array(event.target.result));
  5550. reader.onerror = () => reject(reader.error);
  5551. reader.readAsArrayBuffer(this.blob.slice(offset, offset + length));
  5552. });
  5553. }
  5554. }
  5555. }
  5556. class BlobWriter extends Writer {
  5557. constructor(contentType) {
  5558. super();
  5559. this.contentType = contentType;
  5560. this.arrayBuffersMaxlength = 8;
  5561. initArrayBuffers(this);
  5562. }
  5563. writeUint8Array(array) {
  5564. super.writeUint8Array(array);
  5565. if (this.arrayBuffers.length == this.arrayBuffersMaxlength) {
  5566. flushArrayBuffers(this);
  5567. }
  5568. this.arrayBuffers.push(array.buffer);
  5569. }
  5570. getData() {
  5571. if (!this.blob) {
  5572. if (this.arrayBuffers.length) {
  5573. flushArrayBuffers(this);
  5574. }
  5575. this.blob = this.pendingBlob;
  5576. initArrayBuffers(this);
  5577. }
  5578. return this.blob;
  5579. }
  5580. }
  5581. function initArrayBuffers(blobWriter) {
  5582. blobWriter.pendingBlob = new Blob([], { type: blobWriter.contentType });
  5583. blobWriter.arrayBuffers = [];
  5584. }
  5585. function flushArrayBuffers(blobWriter) {
  5586. blobWriter.pendingBlob = new Blob([blobWriter.pendingBlob, ...blobWriter.arrayBuffers], { type: blobWriter.contentType });
  5587. blobWriter.arrayBuffers = [];
  5588. }
  5589. class ReadableStreamReader {
  5590. constructor(readableStream) {
  5591. this.readableStream = readableStream;
  5592. this.reader = readableStream.getReader();
  5593. this.size = Infinity;
  5594. this.index = 0;
  5595. this.currentSize = 0;
  5596. this.pendingValue = new Uint8Array();
  5597. }
  5598. init() {
  5599. this.initialized = true;
  5600. }
  5601. async readUint8Array(index, length) {
  5602. if (this.index != index) {
  5603. throw new Error(ERR_NOT_SEEKABLE_READER);
  5604. }
  5605. let data = new Uint8Array(length);
  5606. let size = 0, done;
  5607. do {
  5608. const result = await this.reader.read();
  5609. let { value } = result;
  5610. done = result.done;
  5611. if (value) {
  5612. this.currentSize += value.length;
  5613. } else {
  5614. value = this.pendingValue;
  5615. this.pendingValue = new Uint8Array();
  5616. }
  5617. if (this.pendingValue.length) {
  5618. const newValue = new Uint8Array(this.pendingValue.length + value.length);
  5619. newValue.set(this.pendingValue);
  5620. newValue.set(value, this.pendingValue.length);
  5621. this.pendingValue = new Uint8Array();
  5622. value = newValue;
  5623. }
  5624. if (size + value.length > length) {
  5625. data.set(value.subarray(0, length), size);
  5626. this.pendingValue = value.subarray(length);
  5627. size += length;
  5628. } else {
  5629. data.set(value, size);
  5630. size += value.length;
  5631. }
  5632. } while (size < length && !done);
  5633. if (done && this.size == Infinity) {
  5634. this.size = this.currentSize;
  5635. }
  5636. if (this.size < length) {
  5637. data = data.slice(0, this.size);
  5638. length = this.size;
  5639. }
  5640. this.index += length;
  5641. return data;
  5642. }
  5643. }
  5644. class WritableStreamWriter extends Writer {
  5645. constructor(writableStream) {
  5646. super();
  5647. this.writableStream = writableStream;
  5648. this.writer = writableStream.getWriter();
  5649. }
  5650. async writeUint8Array(array) {
  5651. await this.writer.ready;
  5652. return this.writer.write(array);
  5653. }
  5654. async getData() {
  5655. await this.writer.ready;
  5656. await this.writer.close();
  5657. return this.writableStream;
  5658. }
  5659. }
  5660. class FetchReader extends Reader {
  5661. constructor(url, options) {
  5662. super();
  5663. this.url = url;
  5664. this.preventHeadRequest = options.preventHeadRequest;
  5665. this.useRangeHeader = options.useRangeHeader;
  5666. this.forceRangeRequests = options.forceRangeRequests;
  5667. this.options = Object.assign({}, options);
  5668. delete this.options.preventHeadRequest;
  5669. delete this.options.useRangeHeader;
  5670. delete this.options.forceRangeRequests;
  5671. delete this.options.useXHR;
  5672. }
  5673. async init() {
  5674. super.init();
  5675. await initHttpReader(this, sendFetchRequest, getFetchRequestData);
  5676. }
  5677. readUint8Array(index, length) {
  5678. return readUint8ArrayHttpReader(this, index, length, sendFetchRequest, getFetchRequestData);
  5679. }
  5680. }
  5681. class XHRReader extends Reader {
  5682. constructor(url, options) {
  5683. super();
  5684. this.url = url;
  5685. this.preventHeadRequest = options.preventHeadRequest;
  5686. this.useRangeHeader = options.useRangeHeader;
  5687. this.forceRangeRequests = options.forceRangeRequests;
  5688. this.options = options;
  5689. }
  5690. async init() {
  5691. super.init();
  5692. await initHttpReader(this, sendXMLHttpRequest, getXMLHttpRequestData);
  5693. }
  5694. readUint8Array(index, length) {
  5695. return readUint8ArrayHttpReader(this, index, length, sendXMLHttpRequest, getXMLHttpRequestData);
  5696. }
  5697. }
  5698. async function initHttpReader(httpReader, sendRequest, getRequestData) {
  5699. if (isHttpFamily(httpReader.url) && (httpReader.useRangeHeader || httpReader.forceRangeRequests)) {
  5700. const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
  5701. if (!httpReader.forceRangeRequests && response.headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
  5702. throw new Error(ERR_HTTP_RANGE);
  5703. } else {
  5704. let contentSize;
  5705. const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
  5706. if (contentRangeHeader) {
  5707. const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
  5708. if (splitHeader.length) {
  5709. const headerValue = splitHeader[1];
  5710. if (headerValue && headerValue != "*") {
  5711. contentSize = Number(headerValue);
  5712. }
  5713. }
  5714. }
  5715. if (contentSize === undefined) {
  5716. await getContentLength(httpReader, sendRequest, getRequestData);
  5717. } else {
  5718. httpReader.size = contentSize;
  5719. }
  5720. }
  5721. } else {
  5722. await getContentLength(httpReader, sendRequest, getRequestData);
  5723. }
  5724. }
  5725. async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest, getRequestData) {
  5726. if (httpReader.useRangeHeader || httpReader.forceRangeRequests) {
  5727. const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
  5728. if (response.status != 206) {
  5729. throw new Error(ERR_HTTP_RANGE);
  5730. }
  5731. return new Uint8Array(await response.arrayBuffer());
  5732. } else {
  5733. if (!httpReader.data) {
  5734. await getRequestData(httpReader, httpReader.options);
  5735. }
  5736. return new Uint8Array(httpReader.data.subarray(index, index + length));
  5737. }
  5738. }
  5739. function getRangeHeaders(httpReader, index = 0, length = 1) {
  5740. return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
  5741. }
  5742. function getHeaders(httpReader) {
  5743. const headers = httpReader.options.headers;
  5744. if (headers) {
  5745. if (Symbol.iterator in headers) {
  5746. return Object.fromEntries(headers);
  5747. } else {
  5748. return headers;
  5749. }
  5750. }
  5751. }
  5752. async function getFetchRequestData(httpReader) {
  5753. await getRequestData(httpReader, sendFetchRequest);
  5754. }
  5755. async function getXMLHttpRequestData(httpReader) {
  5756. await getRequestData(httpReader, sendXMLHttpRequest);
  5757. }
  5758. async function getRequestData(httpReader, sendRequest) {
  5759. const response = await sendRequest(HTTP_METHOD_GET, httpReader, getHeaders(httpReader));
  5760. httpReader.data = new Uint8Array(await response.arrayBuffer());
  5761. if (!httpReader.size) {
  5762. httpReader.size = httpReader.data.length;
  5763. }
  5764. }
  5765. async function getContentLength(httpReader, sendRequest, getRequestData) {
  5766. if (httpReader.preventHeadRequest) {
  5767. await getRequestData(httpReader, httpReader.options);
  5768. } else {
  5769. const response = await sendRequest(HTTP_METHOD_HEAD, httpReader, getHeaders(httpReader));
  5770. const contentLength = response.headers.get(HTTP_HEADER_CONTENT_LENGTH);
  5771. if (contentLength) {
  5772. httpReader.size = Number(contentLength);
  5773. } else {
  5774. await getRequestData(httpReader, httpReader.options);
  5775. }
  5776. }
  5777. }
  5778. async function sendFetchRequest(method, { options, url }, headers) {
  5779. const response = await fetch(url, Object.assign({}, options, { method, headers }));
  5780. if (response.status < 400) {
  5781. return response;
  5782. } else {
  5783. throw new Error(ERR_HTTP_STATUS + (response.statusText || response.status));
  5784. }
  5785. }
  5786. function sendXMLHttpRequest(method, { url }, headers) {
  5787. return new Promise((resolve, reject) => {
  5788. const request = new XMLHttpRequest();
  5789. request.addEventListener("load", () => {
  5790. if (request.status < 400) {
  5791. const headers = [];
  5792. request.getAllResponseHeaders().trim().split(/[\r\n]+/).forEach(header => {
  5793. const splitHeader = header.trim().split(/\s*:\s*/);
  5794. splitHeader[0] = splitHeader[0].trim().replace(/^[a-z]|-[a-z]/g, value => value.toUpperCase());
  5795. headers.push(splitHeader);
  5796. });
  5797. resolve({
  5798. status: request.status,
  5799. arrayBuffer: () => request.response,
  5800. headers: new Map(headers)
  5801. });
  5802. } else {
  5803. reject(new Error(ERR_HTTP_STATUS + (request.statusText || request.status)));
  5804. }
  5805. }, false);
  5806. request.addEventListener("error", event => reject(event.detail.error), false);
  5807. request.open(method, url);
  5808. if (headers) {
  5809. for (const entry of Object.entries(headers)) {
  5810. request.setRequestHeader(entry[0], entry[1]);
  5811. }
  5812. }
  5813. request.responseType = "arraybuffer";
  5814. request.send();
  5815. });
  5816. }
  5817. class HttpReader extends Reader {
  5818. constructor(url, options = {}) {
  5819. super();
  5820. this.url = url;
  5821. if (options.useXHR) {
  5822. this.reader = new XHRReader(url, options);
  5823. } else {
  5824. this.reader = new FetchReader(url, options);
  5825. }
  5826. }
  5827. set size(value) {
  5828. // ignored
  5829. }
  5830. get size() {
  5831. return this.reader.size;
  5832. }
  5833. async init() {
  5834. super.init();
  5835. await this.reader.init();
  5836. }
  5837. readUint8Array(index, length) {
  5838. return this.reader.readUint8Array(index, length);
  5839. }
  5840. }
  5841. class HttpRangeReader extends HttpReader {
  5842. constructor(url, options = {}) {
  5843. options.useRangeHeader = true;
  5844. super(url, options);
  5845. }
  5846. }
  5847. class Uint8ArrayReader extends Reader {
  5848. constructor(array) {
  5849. super();
  5850. this.array = array;
  5851. this.size = array.length;
  5852. }
  5853. readUint8Array(index, length) {
  5854. return this.array.slice(index, index + length);
  5855. }
  5856. }
  5857. class Uint8ArrayWriter extends Writer {
  5858. constructor() {
  5859. super();
  5860. this.array = new Uint8Array(0);
  5861. }
  5862. writeUint8Array(array) {
  5863. super.writeUint8Array(array);
  5864. const previousArray = this.array;
  5865. this.array = new Uint8Array(previousArray.length + array.length);
  5866. this.array.set(previousArray);
  5867. this.array.set(array, previousArray.length);
  5868. }
  5869. getData() {
  5870. return this.array;
  5871. }
  5872. }
  5873. function isHttpFamily(url) {
  5874. if (typeof document != "undefined") {
  5875. const anchor = document.createElement("a");
  5876. anchor.href = url;
  5877. return anchor.protocol == "http:" || anchor.protocol == "https:";
  5878. } else {
  5879. return /^https?:\/\//i.test(url);
  5880. }
  5881. }
  5882. /*
  5883. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  5884. Redistribution and use in source and binary forms, with or without
  5885. modification, are permitted provided that the following conditions are met:
  5886. 1. Redistributions of source code must retain the above copyright notice,
  5887. this list of conditions and the following disclaimer.
  5888. 2. Redistributions in binary form must reproduce the above copyright
  5889. notice, this list of conditions and the following disclaimer in
  5890. the documentation and/or other materials provided with the distribution.
  5891. 3. The names of the authors may not be used to endorse or promote products
  5892. derived from this software without specific prior written permission.
  5893. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  5894. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  5895. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  5896. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  5897. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5898. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  5899. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5900. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5901. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5902. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5903. */
  5904. const MAX_32_BITS = 0xffffffff;
  5905. const MAX_16_BITS = 0xffff;
  5906. const COMPRESSION_METHOD_DEFLATE = 0x08;
  5907. const COMPRESSION_METHOD_STORE = 0x00;
  5908. const COMPRESSION_METHOD_AES = 0x63;
  5909. const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
  5910. const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50;
  5911. const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
  5912. const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
  5913. const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
  5914. const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
  5915. const END_OF_CENTRAL_DIR_LENGTH = 22;
  5916. const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
  5917. const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
  5918. const ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH = END_OF_CENTRAL_DIR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LENGTH;
  5919. const ZIP64_TOTAL_NUMBER_OF_DISKS = 1;
  5920. const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
  5921. const EXTRAFIELD_TYPE_AES = 0x9901;
  5922. const EXTRAFIELD_TYPE_NTFS = 0x000a;
  5923. const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
  5924. const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
  5925. const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
  5926. const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
  5927. const BITFLAG_ENCRYPTED = 0x01;
  5928. const BITFLAG_LEVEL = 0x06;
  5929. const BITFLAG_DATA_DESCRIPTOR = 0x0008;
  5930. const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
  5931. const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
  5932. const VERSION_DEFLATE = 0x14;
  5933. const VERSION_ZIP64 = 0x2D;
  5934. const VERSION_AES = 0x33;
  5935. const DIRECTORY_SIGNATURE = "/";
  5936. const MAX_DATE = new Date(2107, 11, 31);
  5937. const MIN_DATE = new Date(1980, 0, 1);
  5938. /*
  5939. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  5940. Redistribution and use in source and binary forms, with or without
  5941. modification, are permitted provided that the following conditions are met:
  5942. 1. Redistributions of source code must retain the above copyright notice,
  5943. this list of conditions and the following disclaimer.
  5944. 2. Redistributions in binary form must reproduce the above copyright
  5945. notice, this list of conditions and the following disclaimer in
  5946. the documentation and/or other materials provided with the distribution.
  5947. 3. The names of the authors may not be used to endorse or promote products
  5948. derived from this software without specific prior written permission.
  5949. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  5950. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  5951. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  5952. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  5953. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5954. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  5955. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5956. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5957. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5958. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5959. */
  5960. const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
  5961. var decodeCP437 = stringValue => {
  5962. let result = "";
  5963. for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
  5964. result += CP437[stringValue[indexCharacter]];
  5965. }
  5966. return result;
  5967. };
  5968. /*
  5969. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  5970. Redistribution and use in source and binary forms, with or without
  5971. modification, are permitted provided that the following conditions are met:
  5972. 1. Redistributions of source code must retain the above copyright notice,
  5973. this list of conditions and the following disclaimer.
  5974. 2. Redistributions in binary form must reproduce the above copyright
  5975. notice, this list of conditions and the following disclaimer in
  5976. the documentation and/or other materials provided with the distribution.
  5977. 3. The names of the authors may not be used to endorse or promote products
  5978. derived from this software without specific prior written permission.
  5979. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  5980. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  5981. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  5982. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  5983. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5984. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  5985. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5986. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5987. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5988. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5989. */
  5990. function decodeText(value, encoding) {
  5991. if (encoding && encoding.trim().toLowerCase() == "cp437") {
  5992. return decodeCP437(value);
  5993. } else if (typeof TextDecoder == "undefined") {
  5994. const fileReader = new FileReader();
  5995. return new Promise((resolve, reject) => {
  5996. fileReader.onload = event => resolve(event.target.result);
  5997. fileReader.onerror = () => reject(fileReader.error);
  5998. fileReader.readAsText(new Blob([value]));
  5999. });
  6000. } else {
  6001. return new TextDecoder(encoding).decode(value);
  6002. }
  6003. }
  6004. /*
  6005. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  6006. Redistribution and use in source and binary forms, with or without
  6007. modification, are permitted provided that the following conditions are met:
  6008. 1. Redistributions of source code must retain the above copyright notice,
  6009. this list of conditions and the following disclaimer.
  6010. 2. Redistributions in binary form must reproduce the above copyright
  6011. notice, this list of conditions and the following disclaimer in
  6012. the documentation and/or other materials provided with the distribution.
  6013. 3. The names of the authors may not be used to endorse or promote products
  6014. derived from this software without specific prior written permission.
  6015. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  6016. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  6017. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  6018. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  6019. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6020. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  6021. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6022. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6023. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6024. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6025. */
  6026. const PROPERTY_NAMES = [
  6027. "filename", "rawFilename", "directory", "encrypted", "compressedSize", "uncompressedSize",
  6028. "lastModDate", "rawLastModDate", "comment", "rawComment", "signature", "extraField",
  6029. "rawExtraField", "bitFlag", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment",
  6030. "extraFieldAES", "filenameUTF8", "commentUTF8", "offset", "zip64", "compressionMethod",
  6031. "extraFieldNTFS", "lastAccessDate", "creationDate", "extraFieldExtendedTimestamp",
  6032. "version", "versionMadeBy", "msDosCompatible", "internalFileAttribute", "externalFileAttribute"];
  6033. class Entry {
  6034. constructor(data) {
  6035. PROPERTY_NAMES.forEach(name => this[name] = data[name]);
  6036. }
  6037. }
  6038. /*
  6039. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  6040. Redistribution and use in source and binary forms, with or without
  6041. modification, are permitted provided that the following conditions are met:
  6042. 1. Redistributions of source code must retain the above copyright notice,
  6043. this list of conditions and the following disclaimer.
  6044. 2. Redistributions in binary form must reproduce the above copyright
  6045. notice, this list of conditions and the following disclaimer in
  6046. the documentation and/or other materials provided with the distribution.
  6047. 3. The names of the authors may not be used to endorse or promote products
  6048. derived from this software without specific prior written permission.
  6049. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  6050. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  6051. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  6052. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  6053. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6054. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  6055. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6056. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6057. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6058. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6059. */
  6060. const ERR_BAD_FORMAT = "File format is not recognized";
  6061. const ERR_EOCDR_NOT_FOUND = "End of central directory not found";
  6062. const ERR_EOCDR_ZIP64_NOT_FOUND = "End of Zip64 central directory not found";
  6063. const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = "End of Zip64 central directory locator not found";
  6064. const ERR_CENTRAL_DIRECTORY_NOT_FOUND = "Central directory header not found";
  6065. const ERR_LOCAL_FILE_HEADER_NOT_FOUND = "Local file header not found";
  6066. const ERR_EXTRAFIELD_ZIP64_NOT_FOUND = "Zip64 extra field not found";
  6067. const ERR_ENCRYPTED = "File contains encrypted entry";
  6068. const ERR_UNSUPPORTED_ENCRYPTION = "Encryption method not supported";
  6069. const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
  6070. const CHARSET_UTF8 = "utf-8";
  6071. const CHARSET_CP437 = "cp437";
  6072. const ZIP64_PROPERTIES = ["uncompressedSize", "compressedSize", "offset"];
  6073. class ZipReader {
  6074. constructor(reader, options = {}) {
  6075. Object.assign(this, {
  6076. reader,
  6077. options,
  6078. config: getConfiguration()
  6079. });
  6080. }
  6081. async* getEntriesGenerator(options = {}) {
  6082. const zipReader = this;
  6083. const reader = zipReader.reader;
  6084. if (!reader.initialized) {
  6085. await reader.init();
  6086. }
  6087. if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
  6088. throw new Error(ERR_BAD_FORMAT);
  6089. }
  6090. const endOfDirectoryInfo = await seekSignature(reader, END_OF_CENTRAL_DIR_SIGNATURE, reader.size, END_OF_CENTRAL_DIR_LENGTH, MAX_16_BITS * 16);
  6091. if (!endOfDirectoryInfo) {
  6092. throw new Error(ERR_EOCDR_NOT_FOUND);
  6093. }
  6094. const endOfDirectoryView = getDataView$1(endOfDirectoryInfo);
  6095. let directoryDataLength = getUint32(endOfDirectoryView, 12);
  6096. let directoryDataOffset = getUint32(endOfDirectoryView, 16);
  6097. let filesLength = getUint16(endOfDirectoryView, 8);
  6098. let prependedDataLength = 0;
  6099. if (directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS) {
  6100. const endOfDirectoryLocatorArray = await readUint8Array(reader, endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH);
  6101. const endOfDirectoryLocatorView = getDataView$1(endOfDirectoryLocatorArray);
  6102. if (getUint32(endOfDirectoryLocatorView, 0) != ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
  6103. throw new Error(ERR_EOCDR_ZIP64_NOT_FOUND);
  6104. }
  6105. directoryDataOffset = getBigUint64(endOfDirectoryLocatorView, 8);
  6106. let endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
  6107. let endOfDirectoryView = getDataView$1(endOfDirectoryArray);
  6108. const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH - ZIP64_END_OF_CENTRAL_DIR_LENGTH;
  6109. if (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE && directoryDataOffset != expectedDirectoryDataOffset) {
  6110. const originalDirectoryDataOffset = directoryDataOffset;
  6111. directoryDataOffset = expectedDirectoryDataOffset;
  6112. prependedDataLength = directoryDataOffset - originalDirectoryDataOffset;
  6113. endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
  6114. endOfDirectoryView = getDataView$1(endOfDirectoryArray);
  6115. }
  6116. if (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
  6117. throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
  6118. }
  6119. filesLength = getBigUint64(endOfDirectoryView, 32);
  6120. directoryDataLength = getBigUint64(endOfDirectoryView, 40);
  6121. directoryDataOffset -= directoryDataLength;
  6122. }
  6123. if (directoryDataOffset < 0 || directoryDataOffset >= reader.size) {
  6124. throw new Error(ERR_BAD_FORMAT);
  6125. }
  6126. let offset = 0;
  6127. let directoryArray = await readUint8Array(reader, directoryDataOffset, directoryDataLength);
  6128. let directoryView = getDataView$1(directoryArray);
  6129. if (directoryDataLength) {
  6130. const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - directoryDataLength;
  6131. if (getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE && directoryDataOffset != expectedDirectoryDataOffset) {
  6132. const originalDirectoryDataOffset = directoryDataOffset;
  6133. directoryDataOffset = expectedDirectoryDataOffset;
  6134. prependedDataLength = directoryDataOffset - originalDirectoryDataOffset;
  6135. directoryArray = await readUint8Array(reader, directoryDataOffset, directoryDataLength);
  6136. directoryView = getDataView$1(directoryArray);
  6137. }
  6138. }
  6139. if (directoryDataOffset < 0 || directoryDataOffset >= reader.size) {
  6140. throw new Error(ERR_BAD_FORMAT);
  6141. }
  6142. for (let indexFile = 0; indexFile < filesLength; indexFile++) {
  6143. const fileEntry = new ZipEntry(reader, zipReader.config, zipReader.options);
  6144. if (getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
  6145. throw new Error(ERR_CENTRAL_DIRECTORY_NOT_FOUND);
  6146. }
  6147. readCommonHeader(fileEntry, directoryView, offset + 6);
  6148. const languageEncodingFlag = Boolean(fileEntry.bitFlag.languageEncodingFlag);
  6149. const filenameOffset = offset + 46;
  6150. const extraFieldOffset = filenameOffset + fileEntry.filenameLength;
  6151. const commentOffset = extraFieldOffset + fileEntry.extraFieldLength;
  6152. const versionMadeBy = getUint16(directoryView, offset + 4);
  6153. const msDosCompatible = (versionMadeBy & 0) == 0;
  6154. Object.assign(fileEntry, {
  6155. versionMadeBy,
  6156. msDosCompatible,
  6157. compressedSize: 0,
  6158. uncompressedSize: 0,
  6159. commentLength: getUint16(directoryView, offset + 32),
  6160. directory: msDosCompatible && ((getUint8(directoryView, offset + 38) & FILE_ATTR_MSDOS_DIR_MASK) == FILE_ATTR_MSDOS_DIR_MASK),
  6161. offset: getUint32(directoryView, offset + 42) + prependedDataLength,
  6162. internalFileAttribute: getUint32(directoryView, offset + 34),
  6163. externalFileAttribute: getUint32(directoryView, offset + 38),
  6164. rawFilename: directoryArray.subarray(filenameOffset, extraFieldOffset),
  6165. filenameUTF8: languageEncodingFlag,
  6166. commentUTF8: languageEncodingFlag,
  6167. rawExtraField: directoryArray.subarray(extraFieldOffset, commentOffset)
  6168. });
  6169. const endOffset = commentOffset + fileEntry.commentLength;
  6170. fileEntry.rawComment = directoryArray.subarray(commentOffset, endOffset);
  6171. const filenameEncoding = getOptionValue$1(zipReader, options, "filenameEncoding");
  6172. const commentEncoding = getOptionValue$1(zipReader, options, "commentEncoding");
  6173. const [filename, comment] = await Promise.all([
  6174. decodeText(fileEntry.rawFilename, fileEntry.filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437),
  6175. decodeText(fileEntry.rawComment, fileEntry.commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437)
  6176. ]);
  6177. fileEntry.filename = filename;
  6178. fileEntry.comment = comment;
  6179. if (!fileEntry.directory && fileEntry.filename.endsWith(DIRECTORY_SIGNATURE)) {
  6180. fileEntry.directory = true;
  6181. }
  6182. await readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6);
  6183. const entry = new Entry(fileEntry);
  6184. entry.getData = (writer, options) => fileEntry.getData(writer, entry, options);
  6185. offset = endOffset;
  6186. if (options.onprogress) {
  6187. try {
  6188. options.onprogress(indexFile + 1, filesLength, new Entry(fileEntry));
  6189. } catch (_error) {
  6190. // ignored
  6191. }
  6192. }
  6193. yield entry;
  6194. }
  6195. return true;
  6196. }
  6197. async getEntries(options = {}) {
  6198. const entries = [];
  6199. const iter = this.getEntriesGenerator(options);
  6200. let curr = iter.next();
  6201. while(!(await curr).done) {
  6202. entries.push((await curr).value);
  6203. curr = iter.next();
  6204. }
  6205. return entries;
  6206. }
  6207. async close() {
  6208. }
  6209. }
  6210. class ZipEntry {
  6211. constructor(reader, config, options) {
  6212. Object.assign(this, {
  6213. reader,
  6214. config,
  6215. options
  6216. });
  6217. }
  6218. async getData(writer, fileEntry, options = {}) {
  6219. const zipEntry = this;
  6220. const {
  6221. reader,
  6222. offset,
  6223. extraFieldAES,
  6224. compressionMethod,
  6225. config,
  6226. bitFlag,
  6227. signature,
  6228. rawLastModDate,
  6229. compressedSize
  6230. } = zipEntry;
  6231. const localDirectory = zipEntry.localDirectory = {};
  6232. if (!reader.initialized) {
  6233. await reader.init();
  6234. }
  6235. let dataArray = await readUint8Array(reader, offset, 30);
  6236. const dataView = getDataView$1(dataArray);
  6237. let password = getOptionValue$1(zipEntry, options, "password");
  6238. password = password && password.length && password;
  6239. if (extraFieldAES) {
  6240. if (extraFieldAES.originalCompressionMethod != COMPRESSION_METHOD_AES) {
  6241. throw new Error(ERR_UNSUPPORTED_COMPRESSION);
  6242. }
  6243. }
  6244. if (compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE) {
  6245. throw new Error(ERR_UNSUPPORTED_COMPRESSION);
  6246. }
  6247. if (getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
  6248. throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
  6249. }
  6250. readCommonHeader(localDirectory, dataView, 4);
  6251. dataArray = await readUint8Array(reader, offset, 30 + localDirectory.filenameLength + localDirectory.extraFieldLength);
  6252. localDirectory.rawExtraField = dataArray.subarray(30 + localDirectory.filenameLength);
  6253. await readCommonFooter(zipEntry, localDirectory, dataView, 4);
  6254. fileEntry.lastAccessDate = localDirectory.lastAccessDate;
  6255. fileEntry.creationDate = localDirectory.creationDate;
  6256. const encrypted = zipEntry.encrypted && localDirectory.encrypted;
  6257. const zipCrypto = encrypted && !extraFieldAES;
  6258. if (encrypted) {
  6259. if (!zipCrypto && extraFieldAES.strength === undefined) {
  6260. throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
  6261. } else if (!password) {
  6262. throw new Error(ERR_ENCRYPTED);
  6263. }
  6264. }
  6265. const codec = await createCodec(config.Inflate, {
  6266. codecType: CODEC_INFLATE,
  6267. password,
  6268. zipCrypto,
  6269. encryptionStrength: extraFieldAES && extraFieldAES.strength,
  6270. signed: getOptionValue$1(zipEntry, options, "checkSignature"),
  6271. passwordVerification: zipCrypto && (bitFlag.dataDescriptor ? ((rawLastModDate >>> 8) & 0xFF) : ((signature >>> 24) & 0xFF)),
  6272. signature,
  6273. compressed: compressionMethod != 0,
  6274. encrypted,
  6275. useWebWorkers: getOptionValue$1(zipEntry, options, "useWebWorkers")
  6276. }, config);
  6277. if (!writer.initialized) {
  6278. await writer.init();
  6279. }
  6280. const signal = getOptionValue$1(zipEntry, options, "signal");
  6281. const dataOffset = offset + 30 + localDirectory.filenameLength + localDirectory.extraFieldLength;
  6282. await processData(codec, reader, writer, dataOffset, () => compressedSize, config, { onprogress: options.onprogress, signal });
  6283. return writer.getData();
  6284. }
  6285. }
  6286. function readCommonHeader(directory, dataView, offset) {
  6287. const rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2);
  6288. const encrypted = (rawBitFlag & BITFLAG_ENCRYPTED) == BITFLAG_ENCRYPTED;
  6289. const rawLastModDate = getUint32(dataView, offset + 6);
  6290. Object.assign(directory, {
  6291. encrypted,
  6292. version: getUint16(dataView, offset),
  6293. bitFlag: {
  6294. level: (rawBitFlag & BITFLAG_LEVEL) >> 1,
  6295. dataDescriptor: (rawBitFlag & BITFLAG_DATA_DESCRIPTOR) == BITFLAG_DATA_DESCRIPTOR,
  6296. languageEncodingFlag: (rawBitFlag & BITFLAG_LANG_ENCODING_FLAG) == BITFLAG_LANG_ENCODING_FLAG
  6297. },
  6298. rawLastModDate,
  6299. lastModDate: getDate(rawLastModDate),
  6300. filenameLength: getUint16(dataView, offset + 22),
  6301. extraFieldLength: getUint16(dataView, offset + 24)
  6302. });
  6303. }
  6304. async function readCommonFooter(fileEntry, directory, dataView, offset) {
  6305. const rawExtraField = directory.rawExtraField;
  6306. const extraField = directory.extraField = new Map();
  6307. const rawExtraFieldView = getDataView$1(new Uint8Array(rawExtraField));
  6308. let offsetExtraField = 0;
  6309. try {
  6310. while (offsetExtraField < rawExtraField.length) {
  6311. const type = getUint16(rawExtraFieldView, offsetExtraField);
  6312. const size = getUint16(rawExtraFieldView, offsetExtraField + 2);
  6313. extraField.set(type, {
  6314. type,
  6315. data: rawExtraField.slice(offsetExtraField + 4, offsetExtraField + 4 + size)
  6316. });
  6317. offsetExtraField += 4 + size;
  6318. }
  6319. } catch (_error) {
  6320. // ignored
  6321. }
  6322. const compressionMethod = getUint16(dataView, offset + 4);
  6323. directory.signature = getUint32(dataView, offset + 10);
  6324. directory.uncompressedSize = getUint32(dataView, offset + 18);
  6325. directory.compressedSize = getUint32(dataView, offset + 14);
  6326. const extraFieldZip64 = extraField.get(EXTRAFIELD_TYPE_ZIP64);
  6327. if (extraFieldZip64) {
  6328. readExtraFieldZip64(extraFieldZip64, directory);
  6329. directory.extraFieldZip64 = extraFieldZip64;
  6330. }
  6331. const extraFieldUnicodePath = extraField.get(EXTRAFIELD_TYPE_UNICODE_PATH);
  6332. if (extraFieldUnicodePath) {
  6333. await readExtraFieldUnicode(extraFieldUnicodePath, "filename", "rawFilename", directory, fileEntry);
  6334. directory.extraFieldUnicodePath = extraFieldUnicodePath;
  6335. }
  6336. const extraFieldUnicodeComment = extraField.get(EXTRAFIELD_TYPE_UNICODE_COMMENT);
  6337. if (extraFieldUnicodeComment) {
  6338. await readExtraFieldUnicode(extraFieldUnicodeComment, "comment", "rawComment", directory, fileEntry);
  6339. directory.extraFieldUnicodeComment = extraFieldUnicodeComment;
  6340. }
  6341. const extraFieldAES = extraField.get(EXTRAFIELD_TYPE_AES);
  6342. if (extraFieldAES) {
  6343. readExtraFieldAES(extraFieldAES, directory, compressionMethod);
  6344. directory.extraFieldAES = extraFieldAES;
  6345. } else {
  6346. directory.compressionMethod = compressionMethod;
  6347. }
  6348. const extraFieldNTFS = extraField.get(EXTRAFIELD_TYPE_NTFS);
  6349. if (extraFieldNTFS) {
  6350. readExtraFieldNTFS(extraFieldNTFS, directory);
  6351. directory.extraFieldNTFS = extraFieldNTFS;
  6352. }
  6353. const extraFieldExtendedTimestamp = extraField.get(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
  6354. if (extraFieldExtendedTimestamp) {
  6355. readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory);
  6356. directory.extraFieldExtendedTimestamp = extraFieldExtendedTimestamp;
  6357. }
  6358. }
  6359. function readExtraFieldZip64(extraFieldZip64, directory) {
  6360. directory.zip64 = true;
  6361. const extraFieldView = getDataView$1(extraFieldZip64.data);
  6362. extraFieldZip64.values = [];
  6363. for (let indexValue = 0; indexValue < Math.floor(extraFieldZip64.data.length / 8); indexValue++) {
  6364. extraFieldZip64.values.push(getBigUint64(extraFieldView, 0 + indexValue * 8));
  6365. }
  6366. const missingProperties = ZIP64_PROPERTIES.filter(propertyName => directory[propertyName] == MAX_32_BITS);
  6367. for (let indexMissingProperty = 0; indexMissingProperty < missingProperties.length; indexMissingProperty++) {
  6368. extraFieldZip64[missingProperties[indexMissingProperty]] = extraFieldZip64.values[indexMissingProperty];
  6369. }
  6370. ZIP64_PROPERTIES.forEach(propertyName => {
  6371. if (directory[propertyName] == MAX_32_BITS) {
  6372. if (extraFieldZip64[propertyName] !== undefined) {
  6373. directory[propertyName] = extraFieldZip64[propertyName];
  6374. } else {
  6375. throw new Error(ERR_EXTRAFIELD_ZIP64_NOT_FOUND);
  6376. }
  6377. }
  6378. });
  6379. }
  6380. async function readExtraFieldUnicode(extraFieldUnicode, propertyName, rawPropertyName, directory, fileEntry) {
  6381. const extraFieldView = getDataView$1(extraFieldUnicode.data);
  6382. extraFieldUnicode.version = getUint8(extraFieldView, 0);
  6383. extraFieldUnicode.signature = getUint32(extraFieldView, 1);
  6384. const crc32 = new Crc32();
  6385. crc32.append(fileEntry[rawPropertyName]);
  6386. const dataViewSignature = getDataView$1(new Uint8Array(4));
  6387. dataViewSignature.setUint32(0, crc32.get(), true);
  6388. extraFieldUnicode[propertyName] = await decodeText(extraFieldUnicode.data.subarray(5));
  6389. extraFieldUnicode.valid = !fileEntry.bitFlag.languageEncodingFlag && extraFieldUnicode.signature == getUint32(dataViewSignature, 0);
  6390. if (extraFieldUnicode.valid) {
  6391. directory[propertyName] = extraFieldUnicode[propertyName];
  6392. directory[propertyName + "UTF8"] = true;
  6393. }
  6394. }
  6395. function readExtraFieldAES(extraFieldAES, directory, compressionMethod) {
  6396. const extraFieldView = getDataView$1(extraFieldAES.data);
  6397. extraFieldAES.vendorVersion = getUint8(extraFieldView, 0);
  6398. extraFieldAES.vendorId = getUint8(extraFieldView, 2);
  6399. const strength = getUint8(extraFieldView, 4);
  6400. extraFieldAES.strength = strength;
  6401. extraFieldAES.originalCompressionMethod = compressionMethod;
  6402. directory.compressionMethod = extraFieldAES.compressionMethod = getUint16(extraFieldView, 5);
  6403. }
  6404. function readExtraFieldNTFS(extraFieldNTFS, directory) {
  6405. const extraFieldView = getDataView$1(extraFieldNTFS.data);
  6406. let offsetExtraField = 4;
  6407. let tag1Data;
  6408. try {
  6409. while (offsetExtraField < extraFieldNTFS.data.length && !tag1Data) {
  6410. const tagValue = getUint16(extraFieldView, offsetExtraField);
  6411. const attributeSize = getUint16(extraFieldView, offsetExtraField + 2);
  6412. if (tagValue == EXTRAFIELD_TYPE_NTFS_TAG1) {
  6413. tag1Data = extraFieldNTFS.data.slice(offsetExtraField + 4, offsetExtraField + 4 + attributeSize);
  6414. }
  6415. offsetExtraField += 4 + attributeSize;
  6416. }
  6417. } catch (_error) {
  6418. // ignored
  6419. }
  6420. try {
  6421. if (tag1Data && tag1Data.length == 24) {
  6422. const tag1View = getDataView$1(tag1Data);
  6423. const rawLastModDate = tag1View.getBigUint64(0, true);
  6424. const rawLastAccessDate = tag1View.getBigUint64(8, true);
  6425. const rawCreationDate = tag1View.getBigUint64(16, true);
  6426. Object.assign(extraFieldNTFS, {
  6427. rawLastModDate,
  6428. rawLastAccessDate,
  6429. rawCreationDate
  6430. });
  6431. const lastModDate = getDateNTFS(rawLastModDate);
  6432. const lastAccessDate = getDateNTFS(rawLastAccessDate);
  6433. const creationDate = getDateNTFS(rawCreationDate);
  6434. const extraFieldData = { lastModDate, lastAccessDate, creationDate };
  6435. Object.assign(extraFieldNTFS, extraFieldData);
  6436. Object.assign(directory, extraFieldData);
  6437. }
  6438. } catch (_error) {
  6439. // ignored
  6440. }
  6441. }
  6442. function readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory) {
  6443. const extraFieldView = getDataView$1(extraFieldExtendedTimestamp.data);
  6444. const flags = getUint8(extraFieldView, 0);
  6445. const timeProperties = [];
  6446. const timeRawProperties = [];
  6447. if ((flags & 0x1) == 0x1) {
  6448. timeProperties.push("lastModDate");
  6449. timeRawProperties.push("rawLastModDate");
  6450. }
  6451. if ((flags & 0x2) == 0x2) {
  6452. timeProperties.push("lastAccessDate");
  6453. timeRawProperties.push("rawLastAccessDate");
  6454. }
  6455. if ((flags & 0x4) == 0x4) {
  6456. timeProperties.push("creationDate");
  6457. timeRawProperties.push("rawCreationDate");
  6458. }
  6459. let offset = 1;
  6460. timeProperties.forEach((propertyName, indexProperty) => {
  6461. if (extraFieldExtendedTimestamp.data.length >= offset + 4) {
  6462. const time = getUint32(extraFieldView, offset);
  6463. directory[propertyName] = extraFieldExtendedTimestamp[propertyName] = new Date(time * 1000);
  6464. const rawPropertyName = timeRawProperties[indexProperty];
  6465. extraFieldExtendedTimestamp[rawPropertyName] = time;
  6466. }
  6467. offset += 4;
  6468. });
  6469. }
  6470. async function seekSignature(reader, signature, startOffset, minimumBytes, maximumLength) {
  6471. const signatureArray = new Uint8Array(4);
  6472. const signatureView = getDataView$1(signatureArray);
  6473. setUint32$1(signatureView, 0, signature);
  6474. const maximumBytes = minimumBytes + maximumLength;
  6475. return (await seek(minimumBytes)) || await seek(Math.min(maximumBytes, startOffset));
  6476. async function seek(length) {
  6477. const offset = startOffset - length;
  6478. const bytes = await readUint8Array(reader, offset, length);
  6479. for (let indexByte = bytes.length - minimumBytes; indexByte >= 0; indexByte--) {
  6480. if (bytes[indexByte] == signatureArray[0] && bytes[indexByte + 1] == signatureArray[1] &&
  6481. bytes[indexByte + 2] == signatureArray[2] && bytes[indexByte + 3] == signatureArray[3]) {
  6482. return {
  6483. offset: offset + indexByte,
  6484. buffer: bytes.slice(indexByte, indexByte + minimumBytes).buffer
  6485. };
  6486. }
  6487. }
  6488. }
  6489. }
  6490. function getOptionValue$1(zipReader, options, name) {
  6491. return options[name] === undefined ? zipReader.options[name] : options[name];
  6492. }
  6493. function getDate(timeRaw) {
  6494. const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & 0x0000ffff;
  6495. try {
  6496. return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
  6497. } catch (_error) {
  6498. // ignored
  6499. }
  6500. }
  6501. function getDateNTFS(timeRaw) {
  6502. return new Date((Number((timeRaw / BigInt(10000)) - BigInt(11644473600000))));
  6503. }
  6504. function getUint8(view, offset) {
  6505. return view.getUint8(offset);
  6506. }
  6507. function getUint16(view, offset) {
  6508. return view.getUint16(offset, true);
  6509. }
  6510. function getUint32(view, offset) {
  6511. return view.getUint32(offset, true);
  6512. }
  6513. function getBigUint64(view, offset) {
  6514. return Number(view.getBigUint64(offset, true));
  6515. }
  6516. function setUint32$1(view, offset, value) {
  6517. view.setUint32(offset, value, true);
  6518. }
  6519. function getDataView$1(array) {
  6520. return new DataView(array.buffer);
  6521. }
  6522. function readUint8Array(reader, offset, size) {
  6523. return reader.readUint8Array(offset, size);
  6524. }
  6525. /*
  6526. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  6527. Redistribution and use in source and binary forms, with or without
  6528. modification, are permitted provided that the following conditions are met:
  6529. 1. Redistributions of source code must retain the above copyright notice,
  6530. this list of conditions and the following disclaimer.
  6531. 2. Redistributions in binary form must reproduce the above copyright
  6532. notice, this list of conditions and the following disclaimer in
  6533. the documentation and/or other materials provided with the distribution.
  6534. 3. The names of the authors may not be used to endorse or promote products
  6535. derived from this software without specific prior written permission.
  6536. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  6537. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  6538. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  6539. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  6540. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6541. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  6542. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6543. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6544. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6545. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6546. */
  6547. const ERR_DUPLICATED_NAME = "File already exists";
  6548. const ERR_INVALID_COMMENT = "Zip file comment exceeds 64KB";
  6549. const ERR_INVALID_ENTRY_COMMENT = "File entry comment exceeds 64KB";
  6550. const ERR_INVALID_ENTRY_NAME = "File entry name exceeds 64KB";
  6551. const ERR_INVALID_VERSION = "Version exceeds 65535";
  6552. const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
  6553. const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
  6554. const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
  6555. const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported";
  6556. const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
  6557. const EXTRAFIELD_LENGTH_ZIP64 = 24;
  6558. let workers = 0;
  6559. class ZipWriter {
  6560. constructor(writer, options = {}) {
  6561. Object.assign(this, {
  6562. writer,
  6563. options,
  6564. config: getConfiguration(),
  6565. files: new Map(),
  6566. offset: writer.size,
  6567. pendingCompressedSize: 0,
  6568. pendingEntries: [],
  6569. pendingAddFileCalls: new Set()
  6570. });
  6571. }
  6572. async add(name = "", reader, options = {}) {
  6573. const zipWriter = this;
  6574. if (workers < zipWriter.config.maxWorkers) {
  6575. workers++;
  6576. let promiseAddFile;
  6577. try {
  6578. promiseAddFile = addFile(zipWriter, name, reader, options);
  6579. this.pendingAddFileCalls.add(promiseAddFile);
  6580. return await promiseAddFile;
  6581. } finally {
  6582. this.pendingAddFileCalls.delete(promiseAddFile);
  6583. workers--;
  6584. const pendingEntry = zipWriter.pendingEntries.shift();
  6585. if (pendingEntry) {
  6586. zipWriter.add(pendingEntry.name, pendingEntry.reader, pendingEntry.options)
  6587. .then(pendingEntry.resolve)
  6588. .catch(pendingEntry.reject);
  6589. }
  6590. }
  6591. } else {
  6592. return new Promise((resolve, reject) => zipWriter.pendingEntries.push({ name, reader, options, resolve, reject }));
  6593. }
  6594. }
  6595. async close(comment = new Uint8Array(0), options = {}) {
  6596. while (this.pendingAddFileCalls.size) {
  6597. await Promise.all(Array.from(this.pendingAddFileCalls));
  6598. }
  6599. await closeFile(this, comment, options);
  6600. return this.writer.getData();
  6601. }
  6602. }
  6603. async function addFile(zipWriter, name, reader, options) {
  6604. name = name.trim();
  6605. if (options.directory && (!name.endsWith(DIRECTORY_SIGNATURE))) {
  6606. name += DIRECTORY_SIGNATURE;
  6607. } else {
  6608. options.directory = name.endsWith(DIRECTORY_SIGNATURE);
  6609. }
  6610. if (zipWriter.files.has(name)) {
  6611. throw new Error(ERR_DUPLICATED_NAME);
  6612. }
  6613. const rawFilename = encodeText(name);
  6614. if (rawFilename.length > MAX_16_BITS) {
  6615. throw new Error(ERR_INVALID_ENTRY_NAME);
  6616. }
  6617. const comment = options.comment || "";
  6618. const rawComment = encodeText(comment);
  6619. if (rawComment.length > MAX_16_BITS) {
  6620. throw new Error(ERR_INVALID_ENTRY_COMMENT);
  6621. }
  6622. const version = zipWriter.options.version || options.version || 0;
  6623. if (version > MAX_16_BITS) {
  6624. throw new Error(ERR_INVALID_VERSION);
  6625. }
  6626. const versionMadeBy = zipWriter.options.versionMadeBy || options.versionMadeBy || 20;
  6627. if (versionMadeBy > MAX_16_BITS) {
  6628. throw new Error(ERR_INVALID_VERSION);
  6629. }
  6630. const lastModDate = getOptionValue(zipWriter, options, "lastModDate") || new Date();
  6631. const lastAccessDate = getOptionValue(zipWriter, options, "lastAccessDate");
  6632. const creationDate = getOptionValue(zipWriter, options, "creationDate");
  6633. const password = getOptionValue(zipWriter, options, "password");
  6634. const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
  6635. const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
  6636. if (password !== undefined && encryptionStrength !== undefined && (encryptionStrength < 1 || encryptionStrength > 3)) {
  6637. throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
  6638. }
  6639. let rawExtraField = new Uint8Array(0);
  6640. const extraField = options.extraField;
  6641. if (extraField) {
  6642. let extraFieldSize = 0;
  6643. let offset = 0;
  6644. extraField.forEach(data => extraFieldSize += 4 + data.length);
  6645. rawExtraField = new Uint8Array(extraFieldSize);
  6646. extraField.forEach((data, type) => {
  6647. if (type > MAX_16_BITS) {
  6648. throw new Error(ERR_INVALID_EXTRAFIELD_TYPE);
  6649. }
  6650. if (data.length > MAX_16_BITS) {
  6651. throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
  6652. }
  6653. arraySet(rawExtraField, new Uint16Array([type]), offset);
  6654. arraySet(rawExtraField, new Uint16Array([data.length]), offset + 2);
  6655. arraySet(rawExtraField, data, offset + 4);
  6656. offset += 4 + data.length;
  6657. });
  6658. }
  6659. let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
  6660. if (extendedTimestamp === undefined) {
  6661. extendedTimestamp = true;
  6662. }
  6663. let maximumCompressedSize = 0;
  6664. let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
  6665. if (keepOrder === undefined) {
  6666. keepOrder = true;
  6667. }
  6668. let uncompressedSize = 0;
  6669. let msDosCompatible = getOptionValue(zipWriter, options, "msDosCompatible");
  6670. if (msDosCompatible === undefined) {
  6671. msDosCompatible = true;
  6672. }
  6673. const internalFileAttribute = getOptionValue(zipWriter, options, "internalFileAttribute") || 0;
  6674. const externalFileAttribute = getOptionValue(zipWriter, options, "externalFileAttribute") || 0;
  6675. if (reader) {
  6676. if (!reader.initialized) {
  6677. await reader.init();
  6678. }
  6679. uncompressedSize = reader.size;
  6680. maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
  6681. }
  6682. let zip64 = options.zip64 || zipWriter.options.zip64 || false;
  6683. if (zipWriter.offset + zipWriter.pendingCompressedSize >= MAX_32_BITS ||
  6684. uncompressedSize >= MAX_32_BITS ||
  6685. maximumCompressedSize >= MAX_32_BITS) {
  6686. if (options.zip64 === false || zipWriter.options.zip64 === false || !keepOrder) {
  6687. throw new Error(ERR_UNSUPPORTED_FORMAT);
  6688. } else {
  6689. zip64 = true;
  6690. }
  6691. }
  6692. zipWriter.pendingCompressedSize += maximumCompressedSize;
  6693. await Promise.resolve();
  6694. const level = getOptionValue(zipWriter, options, "level");
  6695. const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
  6696. const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
  6697. let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor");
  6698. let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
  6699. const signal = getOptionValue(zipWriter, options, "signal");
  6700. if (dataDescriptor === undefined) {
  6701. dataDescriptor = true;
  6702. }
  6703. if (dataDescriptor && dataDescriptorSignature === undefined) {
  6704. dataDescriptorSignature = false;
  6705. }
  6706. const fileEntry = await getFileEntry(zipWriter, name, reader, Object.assign({}, options, {
  6707. rawFilename,
  6708. rawComment,
  6709. version,
  6710. versionMadeBy,
  6711. lastModDate,
  6712. lastAccessDate,
  6713. creationDate,
  6714. rawExtraField,
  6715. zip64,
  6716. password,
  6717. level,
  6718. useWebWorkers,
  6719. encryptionStrength,
  6720. extendedTimestamp,
  6721. zipCrypto,
  6722. bufferedWrite,
  6723. keepOrder,
  6724. dataDescriptor,
  6725. dataDescriptorSignature,
  6726. signal,
  6727. msDosCompatible,
  6728. internalFileAttribute,
  6729. externalFileAttribute
  6730. }));
  6731. if (maximumCompressedSize) {
  6732. zipWriter.pendingCompressedSize -= maximumCompressedSize;
  6733. }
  6734. Object.assign(fileEntry, { name, comment, extraField });
  6735. return new Entry(fileEntry);
  6736. }
  6737. async function getFileEntry(zipWriter, name, reader, options) {
  6738. const files = zipWriter.files;
  6739. const writer = zipWriter.writer;
  6740. const previousFileEntry = Array.from(files.values()).pop();
  6741. let fileEntry = {};
  6742. let bufferedWrite;
  6743. let resolveLockUnbufferedWrite;
  6744. let resolveLockCurrentFileEntry;
  6745. files.set(name, fileEntry);
  6746. try {
  6747. let lockPreviousFileEntry;
  6748. let fileWriter;
  6749. let lockCurrentFileEntry;
  6750. if (options.keepOrder) {
  6751. lockPreviousFileEntry = previousFileEntry && previousFileEntry.lock;
  6752. }
  6753. fileEntry.lock = lockCurrentFileEntry = new Promise(resolve => resolveLockCurrentFileEntry = resolve);
  6754. if (options.bufferedWrite || zipWriter.lockWrite || !options.dataDescriptor) {
  6755. fileWriter = new BlobWriter();
  6756. fileWriter.init();
  6757. bufferedWrite = true;
  6758. } else {
  6759. zipWriter.lockWrite = new Promise(resolve => resolveLockUnbufferedWrite = resolve);
  6760. if (!writer.initialized) {
  6761. await writer.init();
  6762. }
  6763. fileWriter = writer;
  6764. }
  6765. fileEntry = await createFileEntry(reader, fileWriter, zipWriter.config, options);
  6766. fileEntry.lock = lockCurrentFileEntry;
  6767. files.set(name, fileEntry);
  6768. fileEntry.filename = name;
  6769. if (bufferedWrite) {
  6770. let indexWrittenData = 0;
  6771. const blob = fileWriter.getData();
  6772. await Promise.all([zipWriter.lockWrite, lockPreviousFileEntry]);
  6773. let pendingFileEntry;
  6774. do {
  6775. pendingFileEntry = Array.from(files.values()).find(fileEntry => fileEntry.writingBufferedData);
  6776. if (pendingFileEntry) {
  6777. await pendingFileEntry.lock;
  6778. }
  6779. } while (pendingFileEntry && pendingFileEntry.lock);
  6780. fileEntry.writingBufferedData = true;
  6781. if (!options.dataDescriptor) {
  6782. const headerLength = 26;
  6783. const arrayBuffer = await sliceAsArrayBuffer(blob, 0, headerLength);
  6784. const arrayBufferView = new DataView(arrayBuffer);
  6785. if (!fileEntry.encrypted || options.zipCrypto) {
  6786. setUint32(arrayBufferView, 14, fileEntry.signature);
  6787. }
  6788. if (fileEntry.zip64) {
  6789. setUint32(arrayBufferView, 18, MAX_32_BITS);
  6790. setUint32(arrayBufferView, 22, MAX_32_BITS);
  6791. } else {
  6792. setUint32(arrayBufferView, 18, fileEntry.compressedSize);
  6793. setUint32(arrayBufferView, 22, fileEntry.uncompressedSize);
  6794. }
  6795. await writer.writeUint8Array(new Uint8Array(arrayBuffer));
  6796. indexWrittenData = headerLength;
  6797. }
  6798. await writeBlob(writer, blob, indexWrittenData);
  6799. delete fileEntry.writingBufferedData;
  6800. }
  6801. fileEntry.offset = zipWriter.offset;
  6802. if (fileEntry.zip64) {
  6803. const rawExtraFieldZip64View = getDataView(fileEntry.rawExtraFieldZip64);
  6804. setBigUint64(rawExtraFieldZip64View, 20, BigInt(fileEntry.offset));
  6805. } else if (fileEntry.offset >= MAX_32_BITS) {
  6806. throw new Error(ERR_UNSUPPORTED_FORMAT);
  6807. }
  6808. zipWriter.offset += fileEntry.length;
  6809. return fileEntry;
  6810. } catch (error) {
  6811. if ((bufferedWrite && fileEntry.writingBufferedData) || (!bufferedWrite && fileEntry.dataWritten)) {
  6812. error.corruptedEntry = zipWriter.hasCorruptedEntries = true;
  6813. if (fileEntry.uncompressedSize) {
  6814. zipWriter.offset += fileEntry.uncompressedSize;
  6815. }
  6816. }
  6817. files.delete(name);
  6818. throw error;
  6819. } finally {
  6820. resolveLockCurrentFileEntry();
  6821. if (resolveLockUnbufferedWrite) {
  6822. resolveLockUnbufferedWrite();
  6823. }
  6824. }
  6825. }
  6826. async function createFileEntry(reader, writer, config, options) {
  6827. const {
  6828. rawFilename,
  6829. lastAccessDate,
  6830. creationDate,
  6831. password,
  6832. level,
  6833. zip64,
  6834. zipCrypto,
  6835. dataDescriptor,
  6836. dataDescriptorSignature,
  6837. directory,
  6838. version,
  6839. versionMadeBy,
  6840. rawComment,
  6841. rawExtraField,
  6842. useWebWorkers,
  6843. onprogress,
  6844. signal,
  6845. encryptionStrength,
  6846. extendedTimestamp,
  6847. msDosCompatible,
  6848. internalFileAttribute,
  6849. externalFileAttribute
  6850. } = options;
  6851. const encrypted = Boolean(password && password.length);
  6852. const compressed = level !== 0 && !directory;
  6853. let rawExtraFieldAES;
  6854. if (encrypted && !zipCrypto) {
  6855. rawExtraFieldAES = new Uint8Array(EXTRAFIELD_DATA_AES.length + 2);
  6856. const extraFieldAESView = getDataView(rawExtraFieldAES);
  6857. setUint16(extraFieldAESView, 0, EXTRAFIELD_TYPE_AES);
  6858. arraySet(rawExtraFieldAES, EXTRAFIELD_DATA_AES, 2);
  6859. setUint8(extraFieldAESView, 8, encryptionStrength);
  6860. } else {
  6861. rawExtraFieldAES = new Uint8Array(0);
  6862. }
  6863. let rawExtraFieldNTFS;
  6864. let rawExtraFieldExtendedTimestamp;
  6865. if (extendedTimestamp) {
  6866. rawExtraFieldExtendedTimestamp = new Uint8Array(9 + (lastAccessDate ? 4 : 0) + (creationDate ? 4 : 0));
  6867. const extraFieldExtendedTimestampView = getDataView(rawExtraFieldExtendedTimestamp);
  6868. setUint16(extraFieldExtendedTimestampView, 0, EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
  6869. setUint16(extraFieldExtendedTimestampView, 2, rawExtraFieldExtendedTimestamp.length - 4);
  6870. const extraFieldExtendedTimestampFlag = 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0);
  6871. setUint8(extraFieldExtendedTimestampView, 4, extraFieldExtendedTimestampFlag);
  6872. setUint32(extraFieldExtendedTimestampView, 5, Math.floor(options.lastModDate.getTime() / 1000));
  6873. if (lastAccessDate) {
  6874. setUint32(extraFieldExtendedTimestampView, 9, Math.floor(lastAccessDate.getTime() / 1000));
  6875. }
  6876. if (creationDate) {
  6877. setUint32(extraFieldExtendedTimestampView, 13, Math.floor(creationDate.getTime() / 1000));
  6878. }
  6879. try {
  6880. rawExtraFieldNTFS = new Uint8Array(36);
  6881. const extraFieldNTFSView = getDataView(rawExtraFieldNTFS);
  6882. const lastModTimeNTFS = getTimeNTFS(options.lastModDate);
  6883. setUint16(extraFieldNTFSView, 0, EXTRAFIELD_TYPE_NTFS);
  6884. setUint16(extraFieldNTFSView, 2, 32);
  6885. setUint16(extraFieldNTFSView, 8, EXTRAFIELD_TYPE_NTFS_TAG1);
  6886. setUint16(extraFieldNTFSView, 10, 24);
  6887. setBigUint64(extraFieldNTFSView, 12, lastModTimeNTFS);
  6888. setBigUint64(extraFieldNTFSView, 20, getTimeNTFS(lastAccessDate) || lastModTimeNTFS);
  6889. setBigUint64(extraFieldNTFSView, 28, getTimeNTFS(creationDate) || lastModTimeNTFS);
  6890. } catch (_error) {
  6891. rawExtraFieldNTFS = new Uint8Array(0);
  6892. }
  6893. } else {
  6894. rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array(0);
  6895. }
  6896. const fileEntry = {
  6897. version: version || VERSION_DEFLATE,
  6898. versionMadeBy,
  6899. zip64,
  6900. directory: Boolean(directory),
  6901. filenameUTF8: true,
  6902. rawFilename,
  6903. commentUTF8: true,
  6904. rawComment,
  6905. rawExtraFieldZip64: zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array(0),
  6906. rawExtraFieldExtendedTimestamp,
  6907. rawExtraFieldNTFS,
  6908. rawExtraFieldAES,
  6909. rawExtraField,
  6910. extendedTimestamp,
  6911. msDosCompatible,
  6912. internalFileAttribute,
  6913. externalFileAttribute
  6914. };
  6915. let uncompressedSize = fileEntry.uncompressedSize = 0;
  6916. let bitFlag = BITFLAG_LANG_ENCODING_FLAG;
  6917. if (dataDescriptor) {
  6918. bitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;
  6919. }
  6920. let compressionMethod = COMPRESSION_METHOD_STORE;
  6921. if (compressed) {
  6922. compressionMethod = COMPRESSION_METHOD_DEFLATE;
  6923. }
  6924. if (zip64) {
  6925. fileEntry.version = fileEntry.version > VERSION_ZIP64 ? fileEntry.version : VERSION_ZIP64;
  6926. }
  6927. if (encrypted) {
  6928. bitFlag = bitFlag | BITFLAG_ENCRYPTED;
  6929. if (!zipCrypto) {
  6930. fileEntry.version = fileEntry.version > VERSION_AES ? fileEntry.version : VERSION_AES;
  6931. compressionMethod = COMPRESSION_METHOD_AES;
  6932. if (compressed) {
  6933. fileEntry.rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
  6934. }
  6935. }
  6936. }
  6937. fileEntry.compressionMethod = compressionMethod;
  6938. const headerArray = fileEntry.headerArray = new Uint8Array(26);
  6939. const headerView = getDataView(headerArray);
  6940. setUint16(headerView, 0, fileEntry.version);
  6941. setUint16(headerView, 2, bitFlag);
  6942. setUint16(headerView, 4, compressionMethod);
  6943. const dateArray = new Uint32Array(1);
  6944. const dateView = getDataView(dateArray);
  6945. let lastModDate;
  6946. if (options.lastModDate < MIN_DATE) {
  6947. lastModDate = MIN_DATE;
  6948. } else if (options.lastModDate > MAX_DATE) {
  6949. lastModDate = MAX_DATE;
  6950. } else {
  6951. lastModDate = options.lastModDate;
  6952. }
  6953. setUint16(dateView, 0, (((lastModDate.getHours() << 6) | lastModDate.getMinutes()) << 5) | lastModDate.getSeconds() / 2);
  6954. setUint16(dateView, 2, ((((lastModDate.getFullYear() - 1980) << 4) | (lastModDate.getMonth() + 1)) << 5) | lastModDate.getDate());
  6955. const rawLastModDate = dateArray[0];
  6956. setUint32(headerView, 6, rawLastModDate);
  6957. setUint16(headerView, 22, rawFilename.length);
  6958. const extraFieldLength = rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length + fileEntry.rawExtraField.length;
  6959. setUint16(headerView, 24, extraFieldLength);
  6960. const localHeaderArray = new Uint8Array(30 + rawFilename.length + extraFieldLength);
  6961. const localHeaderView = getDataView(localHeaderArray);
  6962. setUint32(localHeaderView, 0, LOCAL_FILE_HEADER_SIGNATURE);
  6963. arraySet(localHeaderArray, headerArray, 4);
  6964. arraySet(localHeaderArray, rawFilename, 30);
  6965. arraySet(localHeaderArray, rawExtraFieldAES, 30 + rawFilename.length);
  6966. arraySet(localHeaderArray, rawExtraFieldExtendedTimestamp, 30 + rawFilename.length + rawExtraFieldAES.length);
  6967. arraySet(localHeaderArray, rawExtraFieldNTFS, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length);
  6968. arraySet(localHeaderArray, fileEntry.rawExtraField, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length);
  6969. let result;
  6970. let compressedSize = 0;
  6971. if (reader) {
  6972. const codec = await createCodec(config.Deflate, {
  6973. codecType: CODEC_DEFLATE,
  6974. level,
  6975. password,
  6976. encryptionStrength,
  6977. zipCrypto: encrypted && zipCrypto,
  6978. passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
  6979. signed: true,
  6980. compressed,
  6981. encrypted,
  6982. useWebWorkers
  6983. }, config);
  6984. await writer.writeUint8Array(localHeaderArray);
  6985. fileEntry.dataWritten = true;
  6986. result = await processData(codec, reader, writer, 0, () => reader.size, config, { onprogress, signal });
  6987. uncompressedSize = fileEntry.uncompressedSize = reader.size;
  6988. compressedSize = result.length;
  6989. } else {
  6990. await writer.writeUint8Array(localHeaderArray);
  6991. fileEntry.dataWritten = true;
  6992. }
  6993. let dataDescriptorArray = new Uint8Array(0);
  6994. let dataDescriptorView, dataDescriptorOffset = 0;
  6995. if (dataDescriptor) {
  6996. dataDescriptorArray = new Uint8Array(zip64 ? (dataDescriptorSignature ? 24 : 20) : (dataDescriptorSignature ? 16 : 12));
  6997. dataDescriptorView = getDataView(dataDescriptorArray);
  6998. if (dataDescriptorSignature) {
  6999. dataDescriptorOffset = 4;
  7000. setUint32(dataDescriptorView, 0, DATA_DESCRIPTOR_RECORD_SIGNATURE);
  7001. }
  7002. }
  7003. if (reader) {
  7004. const signature = result.signature;
  7005. if ((!encrypted || zipCrypto) && signature !== undefined) {
  7006. setUint32(headerView, 10, signature);
  7007. fileEntry.signature = signature;
  7008. if (dataDescriptor) {
  7009. setUint32(dataDescriptorView, dataDescriptorOffset, signature);
  7010. }
  7011. }
  7012. if (zip64) {
  7013. const rawExtraFieldZip64View = getDataView(fileEntry.rawExtraFieldZip64);
  7014. setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
  7015. setUint16(rawExtraFieldZip64View, 2, EXTRAFIELD_LENGTH_ZIP64);
  7016. setUint32(headerView, 14, MAX_32_BITS);
  7017. setBigUint64(rawExtraFieldZip64View, 12, BigInt(compressedSize));
  7018. setUint32(headerView, 18, MAX_32_BITS);
  7019. setBigUint64(rawExtraFieldZip64View, 4, BigInt(uncompressedSize));
  7020. if (dataDescriptor) {
  7021. setBigUint64(dataDescriptorView, dataDescriptorOffset + 4, BigInt(compressedSize));
  7022. setBigUint64(dataDescriptorView, dataDescriptorOffset + 12, BigInt(uncompressedSize));
  7023. }
  7024. } else {
  7025. setUint32(headerView, 14, compressedSize);
  7026. setUint32(headerView, 18, uncompressedSize);
  7027. if (dataDescriptor) {
  7028. setUint32(dataDescriptorView, dataDescriptorOffset + 4, compressedSize);
  7029. setUint32(dataDescriptorView, dataDescriptorOffset + 8, uncompressedSize);
  7030. }
  7031. }
  7032. }
  7033. if (dataDescriptor) {
  7034. await writer.writeUint8Array(dataDescriptorArray);
  7035. }
  7036. const length = localHeaderArray.length + compressedSize + dataDescriptorArray.length;
  7037. Object.assign(fileEntry, { compressedSize, lastModDate, rawLastModDate, creationDate, lastAccessDate, encrypted, length });
  7038. return fileEntry;
  7039. }
  7040. async function closeFile(zipWriter, comment, options) {
  7041. const writer = zipWriter.writer;
  7042. const files = zipWriter.files;
  7043. let offset = 0;
  7044. let directoryDataLength = 0;
  7045. let directoryOffset = zipWriter.offset;
  7046. let filesLength = files.size;
  7047. for (const [, fileEntry] of files) {
  7048. directoryDataLength += 46 +
  7049. fileEntry.rawFilename.length +
  7050. fileEntry.rawComment.length +
  7051. fileEntry.rawExtraFieldZip64.length +
  7052. fileEntry.rawExtraFieldAES.length +
  7053. fileEntry.rawExtraFieldExtendedTimestamp.length +
  7054. fileEntry.rawExtraFieldNTFS.length +
  7055. fileEntry.rawExtraField.length;
  7056. }
  7057. let zip64 = options.zip64 || zipWriter.options.zip64 || false;
  7058. if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) {
  7059. if (options.zip64 === false || zipWriter.options.zip64 === false) {
  7060. throw new Error(ERR_UNSUPPORTED_FORMAT);
  7061. } else {
  7062. zip64 = true;
  7063. }
  7064. }
  7065. const directoryArray = new Uint8Array(directoryDataLength + (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH));
  7066. const directoryView = getDataView(directoryArray);
  7067. if (comment && comment.length) {
  7068. if (comment.length <= MAX_16_BITS) {
  7069. setUint16(directoryView, offset + 20, comment.length);
  7070. } else {
  7071. throw new Error(ERR_INVALID_COMMENT);
  7072. }
  7073. }
  7074. for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
  7075. const {
  7076. rawFilename,
  7077. rawExtraFieldZip64,
  7078. rawExtraFieldAES,
  7079. rawExtraField,
  7080. rawComment,
  7081. versionMadeBy,
  7082. headerArray,
  7083. directory,
  7084. zip64,
  7085. msDosCompatible,
  7086. internalFileAttribute,
  7087. externalFileAttribute
  7088. } = fileEntry;
  7089. let rawExtraFieldExtendedTimestamp;
  7090. let rawExtraFieldNTFS;
  7091. if (fileEntry.extendedTimestamp) {
  7092. rawExtraFieldNTFS = fileEntry.rawExtraFieldNTFS;
  7093. rawExtraFieldExtendedTimestamp = new Uint8Array(9);
  7094. const extraFieldExtendedTimestampView = getDataView(rawExtraFieldExtendedTimestamp);
  7095. setUint16(extraFieldExtendedTimestampView, 0, EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
  7096. setUint16(extraFieldExtendedTimestampView, 2, rawExtraFieldExtendedTimestamp.length - 4);
  7097. setUint8(extraFieldExtendedTimestampView, 4, 0x1);
  7098. setUint32(extraFieldExtendedTimestampView, 5, Math.floor(fileEntry.lastModDate.getTime() / 1000));
  7099. } else {
  7100. rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array(0);
  7101. }
  7102. const extraFieldLength = rawExtraFieldZip64.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length + rawExtraField.length;
  7103. setUint32(directoryView, offset, CENTRAL_FILE_HEADER_SIGNATURE);
  7104. setUint16(directoryView, offset + 4, versionMadeBy);
  7105. arraySet(directoryArray, headerArray, offset + 6);
  7106. setUint16(directoryView, offset + 30, extraFieldLength);
  7107. setUint16(directoryView, offset + 32, rawComment.length);
  7108. setUint32(directoryView, offset + 34, internalFileAttribute);
  7109. if (externalFileAttribute) {
  7110. setUint32(directoryView, offset + 38, externalFileAttribute);
  7111. } else if (directory && msDosCompatible) {
  7112. setUint8(directoryView, offset + 38, FILE_ATTR_MSDOS_DIR_MASK);
  7113. }
  7114. if (zip64) {
  7115. setUint32(directoryView, offset + 42, MAX_32_BITS);
  7116. } else {
  7117. setUint32(directoryView, offset + 42, fileEntry.offset);
  7118. }
  7119. arraySet(directoryArray, rawFilename, offset + 46);
  7120. arraySet(directoryArray, rawExtraFieldZip64, offset + 46 + rawFilename.length);
  7121. arraySet(directoryArray, rawExtraFieldAES, offset + 46 + rawFilename.length + rawExtraFieldZip64.length);
  7122. arraySet(directoryArray, rawExtraFieldExtendedTimestamp, offset + 46 + rawFilename.length + rawExtraFieldZip64.length + rawExtraFieldAES.length);
  7123. arraySet(directoryArray, rawExtraFieldNTFS, offset + 46 + rawFilename.length + rawExtraFieldZip64.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length);
  7124. arraySet(directoryArray, rawExtraField, offset + 46 + rawFilename.length + rawExtraFieldZip64.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length);
  7125. arraySet(directoryArray, rawComment, offset + 46 + rawFilename.length + extraFieldLength);
  7126. offset += 46 + rawFilename.length + extraFieldLength + rawComment.length;
  7127. if (options.onprogress) {
  7128. try {
  7129. options.onprogress(indexFileEntry + 1, files.size, new Entry(fileEntry));
  7130. } catch (_error) {
  7131. // ignored
  7132. }
  7133. }
  7134. }
  7135. if (zip64) {
  7136. setUint32(directoryView, offset, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
  7137. setBigUint64(directoryView, offset + 4, BigInt(44));
  7138. setUint16(directoryView, offset + 12, 45);
  7139. setUint16(directoryView, offset + 14, 45);
  7140. setBigUint64(directoryView, offset + 24, BigInt(filesLength));
  7141. setBigUint64(directoryView, offset + 32, BigInt(filesLength));
  7142. setBigUint64(directoryView, offset + 40, BigInt(directoryDataLength));
  7143. setBigUint64(directoryView, offset + 48, BigInt(directoryOffset));
  7144. setUint32(directoryView, offset + 56, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
  7145. setBigUint64(directoryView, offset + 64, BigInt(directoryOffset) + BigInt(directoryDataLength));
  7146. setUint32(directoryView, offset + 72, ZIP64_TOTAL_NUMBER_OF_DISKS);
  7147. filesLength = MAX_16_BITS;
  7148. directoryOffset = MAX_32_BITS;
  7149. directoryDataLength = MAX_32_BITS;
  7150. offset += 76;
  7151. }
  7152. setUint32(directoryView, offset, END_OF_CENTRAL_DIR_SIGNATURE);
  7153. setUint16(directoryView, offset + 8, filesLength);
  7154. setUint16(directoryView, offset + 10, filesLength);
  7155. setUint32(directoryView, offset + 12, directoryDataLength);
  7156. setUint32(directoryView, offset + 16, directoryOffset);
  7157. await writer.writeUint8Array(directoryArray);
  7158. if (comment && comment.length) {
  7159. await writer.writeUint8Array(comment);
  7160. }
  7161. }
  7162. function sliceAsArrayBuffer(blob, start, end) {
  7163. if (blob.arrayBuffer) {
  7164. if (start || end) {
  7165. return blob.slice(start, end).arrayBuffer();
  7166. } else {
  7167. return blob.arrayBuffer();
  7168. }
  7169. } else {
  7170. const fileReader = new FileReader();
  7171. return new Promise((resolve, reject) => {
  7172. fileReader.onload = event => resolve(event.target.result);
  7173. fileReader.onerror = () => reject(fileReader.error);
  7174. fileReader.readAsArrayBuffer(start || end ? blob.slice(start, end) : blob);
  7175. });
  7176. }
  7177. }
  7178. async function writeBlob(writer, blob, start = 0) {
  7179. const blockSize = 512 * 1024 * 1024;
  7180. await writeSlice();
  7181. async function writeSlice() {
  7182. if (start < blob.size) {
  7183. const arrayBuffer = await sliceAsArrayBuffer(blob, start, start + blockSize);
  7184. await writer.writeUint8Array(new Uint8Array(arrayBuffer));
  7185. start += blockSize;
  7186. await writeSlice();
  7187. }
  7188. }
  7189. }
  7190. function getTimeNTFS(date) {
  7191. if (date) {
  7192. return ((BigInt(date.getTime()) + BigInt(11644473600000)) * BigInt(10000));
  7193. }
  7194. }
  7195. function getOptionValue(zipWriter, options, name) {
  7196. return options[name] === undefined ? zipWriter.options[name] : options[name];
  7197. }
  7198. function getMaximumCompressedSize(uncompressedSize) {
  7199. return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
  7200. }
  7201. function setUint8(view, offset, value) {
  7202. view.setUint8(offset, value);
  7203. }
  7204. function setUint16(view, offset, value) {
  7205. view.setUint16(offset, value, true);
  7206. }
  7207. function setUint32(view, offset, value) {
  7208. view.setUint32(offset, value, true);
  7209. }
  7210. function setBigUint64(view, offset, value) {
  7211. view.setBigUint64(offset, value, true);
  7212. }
  7213. function arraySet(array, typedArray, offset) {
  7214. array.set(typedArray, offset);
  7215. }
  7216. function getDataView(array) {
  7217. return new DataView(array.buffer);
  7218. }
  7219. /*
  7220. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  7221. Redistribution and use in source and binary forms, with or without
  7222. modification, are permitted provided that the following conditions are met:
  7223. 1. Redistributions of source code must retain the above copyright notice,
  7224. this list of conditions and the following disclaimer.
  7225. 2. Redistributions in binary form must reproduce the above copyright
  7226. notice, this list of conditions and the following disclaimer in
  7227. the documentation and/or other materials provided with the distribution.
  7228. 3. The names of the authors may not be used to endorse or promote products
  7229. derived from this software without specific prior written permission.
  7230. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  7231. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  7232. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  7233. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  7234. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  7235. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  7236. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  7237. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  7238. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  7239. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7240. */
  7241. let baseURL;
  7242. try {
  7243. baseURL = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('zip-full.js', document.baseURI).href));
  7244. } catch (_error) {
  7245. // ignored
  7246. }
  7247. t(configure);
  7248. configure({ Deflate: ZipDeflate, Inflate: ZipInflate, baseURL });
  7249. exports.BlobReader = BlobReader;
  7250. exports.BlobWriter = BlobWriter;
  7251. exports.Data64URIReader = Data64URIReader;
  7252. exports.Data64URIWriter = Data64URIWriter;
  7253. exports.ERR_ABORT = ERR_ABORT;
  7254. exports.ERR_BAD_FORMAT = ERR_BAD_FORMAT;
  7255. exports.ERR_CENTRAL_DIRECTORY_NOT_FOUND = ERR_CENTRAL_DIRECTORY_NOT_FOUND;
  7256. exports.ERR_DUPLICATED_NAME = ERR_DUPLICATED_NAME;
  7257. exports.ERR_ENCRYPTED = ERR_ENCRYPTED;
  7258. exports.ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND;
  7259. exports.ERR_EOCDR_NOT_FOUND = ERR_EOCDR_NOT_FOUND;
  7260. exports.ERR_EOCDR_ZIP64_NOT_FOUND = ERR_EOCDR_ZIP64_NOT_FOUND;
  7261. exports.ERR_EXTRAFIELD_ZIP64_NOT_FOUND = ERR_EXTRAFIELD_ZIP64_NOT_FOUND;
  7262. exports.ERR_HTTP_RANGE = ERR_HTTP_RANGE;
  7263. exports.ERR_INVALID_COMMENT = ERR_INVALID_COMMENT;
  7264. exports.ERR_INVALID_ENCRYPTION_STRENGTH = ERR_INVALID_ENCRYPTION_STRENGTH;
  7265. exports.ERR_INVALID_ENTRY_COMMENT = ERR_INVALID_ENTRY_COMMENT;
  7266. exports.ERR_INVALID_ENTRY_NAME = ERR_INVALID_ENTRY_NAME;
  7267. exports.ERR_INVALID_EXTRAFIELD_DATA = ERR_INVALID_EXTRAFIELD_DATA;
  7268. exports.ERR_INVALID_EXTRAFIELD_TYPE = ERR_INVALID_EXTRAFIELD_TYPE;
  7269. exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
  7270. exports.ERR_INVALID_SIGNATURE = ERR_INVALID_SIGNATURE;
  7271. exports.ERR_INVALID_VERSION = ERR_INVALID_VERSION;
  7272. exports.ERR_LOCAL_FILE_HEADER_NOT_FOUND = ERR_LOCAL_FILE_HEADER_NOT_FOUND;
  7273. exports.ERR_NOT_SEEKABLE_READER = ERR_NOT_SEEKABLE_READER;
  7274. exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION;
  7275. exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
  7276. exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
  7277. exports.HttpRangeReader = HttpRangeReader;
  7278. exports.HttpReader = HttpReader;
  7279. exports.ReadableStreamReader = ReadableStreamReader;
  7280. exports.Reader = Reader;
  7281. exports.TextReader = TextReader;
  7282. exports.TextWriter = TextWriter;
  7283. exports.Uint8ArrayReader = Uint8ArrayReader;
  7284. exports.Uint8ArrayWriter = Uint8ArrayWriter;
  7285. exports.WritableStreamWriter = WritableStreamWriter;
  7286. exports.Writer = Writer;
  7287. exports.ZipReader = ZipReader;
  7288. exports.ZipWriter = ZipWriter;
  7289. exports.configure = configure;
  7290. exports.getMimeType = getMimeType;
  7291. exports.initShimAsyncCodec = streamCodecShim;
  7292. exports.terminateWorkers = terminateWorkers;
  7293. Object.defineProperty(exports, '__esModule', { value: true });
  7294. }));