zip-fs-full.js 350 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913
  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. /*
  3705. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  3706. Redistribution and use in source and binary forms, with or without
  3707. modification, are permitted provided that the following conditions are met:
  3708. 1. Redistributions of source code must retain the above copyright notice,
  3709. this list of conditions and the following disclaimer.
  3710. 2. Redistributions in binary form must reproduce the above copyright
  3711. notice, this list of conditions and the following disclaimer in
  3712. the documentation and/or other materials provided with the distribution.
  3713. 3. The names of the authors may not be used to endorse or promote products
  3714. derived from this software without specific prior written permission.
  3715. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  3716. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  3717. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  3718. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  3719. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3720. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  3721. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3722. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3723. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3724. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3725. */
  3726. function getMimeType$1() {
  3727. return "application/octet-stream";
  3728. }
  3729. /*
  3730. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  3731. Redistribution and use in source and binary forms, with or without
  3732. modification, are permitted provided that the following conditions are met:
  3733. 1. Redistributions of source code must retain the above copyright notice,
  3734. this list of conditions and the following disclaimer.
  3735. 2. Redistributions in binary form must reproduce the above copyright
  3736. notice, this list of conditions and the following disclaimer in
  3737. the documentation and/or other materials provided with the distribution.
  3738. 3. The names of the authors may not be used to endorse or promote products
  3739. derived from this software without specific prior written permission.
  3740. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  3741. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  3742. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  3743. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  3744. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3745. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  3746. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3747. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3748. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3749. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3750. */
  3751. const table$1 = {
  3752. "application": {
  3753. "andrew-inset": "ez",
  3754. "annodex": "anx",
  3755. "atom+xml": "atom",
  3756. "atomcat+xml": "atomcat",
  3757. "atomserv+xml": "atomsrv",
  3758. "bbolin": "lin",
  3759. "cap": ["cap", "pcap"],
  3760. "cu-seeme": "cu",
  3761. "davmount+xml": "davmount",
  3762. "dsptype": "tsp",
  3763. "ecmascript": ["es", "ecma"],
  3764. "futuresplash": "spl",
  3765. "hta": "hta",
  3766. "java-archive": "jar",
  3767. "java-serialized-object": "ser",
  3768. "java-vm": "class",
  3769. "javascript": "js",
  3770. "m3g": "m3g",
  3771. "mac-binhex40": "hqx",
  3772. "mathematica": ["nb", "ma", "mb"],
  3773. "msaccess": "mdb",
  3774. "msword": ["doc", "dot"],
  3775. "mxf": "mxf",
  3776. "oda": "oda",
  3777. "ogg": "ogx",
  3778. "pdf": "pdf",
  3779. "pgp-keys": "key",
  3780. "pgp-signature": ["asc", "sig"],
  3781. "pics-rules": "prf",
  3782. "postscript": ["ps", "ai", "eps", "epsi", "epsf", "eps2", "eps3"],
  3783. "rar": "rar",
  3784. "rdf+xml": "rdf",
  3785. "rss+xml": "rss",
  3786. "rtf": "rtf",
  3787. "smil": ["smi", "smil"],
  3788. "xhtml+xml": ["xhtml", "xht"],
  3789. "xml": ["xml", "xsl", "xsd"],
  3790. "xspf+xml": "xspf",
  3791. "zip": "zip",
  3792. "vnd.android.package-archive": "apk",
  3793. "vnd.cinderella": "cdy",
  3794. "vnd.google-earth.kml+xml": "kml",
  3795. "vnd.google-earth.kmz": "kmz",
  3796. "vnd.mozilla.xul+xml": "xul",
  3797. "vnd.ms-excel": ["xls", "xlb", "xlt", "xlm", "xla", "xlc", "xlw"],
  3798. "vnd.ms-pki.seccat": "cat",
  3799. "vnd.ms-pki.stl": "stl",
  3800. "vnd.ms-powerpoint": ["ppt", "pps", "pot"],
  3801. "vnd.oasis.opendocument.chart": "odc",
  3802. "vnd.oasis.opendocument.database": "odb",
  3803. "vnd.oasis.opendocument.formula": "odf",
  3804. "vnd.oasis.opendocument.graphics": "odg",
  3805. "vnd.oasis.opendocument.graphics-template": "otg",
  3806. "vnd.oasis.opendocument.image": "odi",
  3807. "vnd.oasis.opendocument.presentation": "odp",
  3808. "vnd.oasis.opendocument.presentation-template": "otp",
  3809. "vnd.oasis.opendocument.spreadsheet": "ods",
  3810. "vnd.oasis.opendocument.spreadsheet-template": "ots",
  3811. "vnd.oasis.opendocument.text": "odt",
  3812. "vnd.oasis.opendocument.text-master": "odm",
  3813. "vnd.oasis.opendocument.text-template": "ott",
  3814. "vnd.oasis.opendocument.text-web": "oth",
  3815. "vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
  3816. "vnd.openxmlformats-officedocument.spreadsheetml.template": "xltx",
  3817. "vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
  3818. "vnd.openxmlformats-officedocument.presentationml.slideshow": "ppsx",
  3819. "vnd.openxmlformats-officedocument.presentationml.template": "potx",
  3820. "vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
  3821. "vnd.openxmlformats-officedocument.wordprocessingml.template": "dotx",
  3822. "vnd.smaf": "mmf",
  3823. "vnd.stardivision.calc": "sdc",
  3824. "vnd.stardivision.chart": "sds",
  3825. "vnd.stardivision.draw": "sda",
  3826. "vnd.stardivision.impress": "sdd",
  3827. "vnd.stardivision.math": ["sdf", "smf"],
  3828. "vnd.stardivision.writer": ["sdw", "vor"],
  3829. "vnd.stardivision.writer-global": "sgl",
  3830. "vnd.sun.xml.calc": "sxc",
  3831. "vnd.sun.xml.calc.template": "stc",
  3832. "vnd.sun.xml.draw": "sxd",
  3833. "vnd.sun.xml.draw.template": "std",
  3834. "vnd.sun.xml.impress": "sxi",
  3835. "vnd.sun.xml.impress.template": "sti",
  3836. "vnd.sun.xml.math": "sxm",
  3837. "vnd.sun.xml.writer": "sxw",
  3838. "vnd.sun.xml.writer.global": "sxg",
  3839. "vnd.sun.xml.writer.template": "stw",
  3840. "vnd.symbian.install": ["sis", "sisx"],
  3841. "vnd.visio": ["vsd", "vst", "vss", "vsw"],
  3842. "vnd.wap.wbxml": "wbxml",
  3843. "vnd.wap.wmlc": "wmlc",
  3844. "vnd.wap.wmlscriptc": "wmlsc",
  3845. "vnd.wordperfect": "wpd",
  3846. "vnd.wordperfect5.1": "wp5",
  3847. "x-123": "wk",
  3848. "x-7z-compressed": "7z",
  3849. "x-abiword": "abw",
  3850. "x-apple-diskimage": "dmg",
  3851. "x-bcpio": "bcpio",
  3852. "x-bittorrent": "torrent",
  3853. "x-cbr": ["cbr", "cba", "cbt", "cb7"],
  3854. "x-cbz": "cbz",
  3855. "x-cdf": ["cdf", "cda"],
  3856. "x-cdlink": "vcd",
  3857. "x-chess-pgn": "pgn",
  3858. "x-cpio": "cpio",
  3859. "x-csh": "csh",
  3860. "x-debian-package": ["deb", "udeb"],
  3861. "x-director": ["dcr", "dir", "dxr", "cst", "cct", "cxt", "w3d", "fgd", "swa"],
  3862. "x-dms": "dms",
  3863. "x-doom": "wad",
  3864. "x-dvi": "dvi",
  3865. "x-httpd-eruby": "rhtml",
  3866. "x-font": "pcf.Z",
  3867. "x-freemind": "mm",
  3868. "x-gnumeric": "gnumeric",
  3869. "x-go-sgf": "sgf",
  3870. "x-graphing-calculator": "gcf",
  3871. "x-gtar": ["gtar", "taz"],
  3872. "x-hdf": "hdf",
  3873. "x-httpd-php": ["phtml", "pht", "php"],
  3874. "x-httpd-php-source": "phps",
  3875. "x-httpd-php3": "php3",
  3876. "x-httpd-php3-preprocessed": "php3p",
  3877. "x-httpd-php4": "php4",
  3878. "x-httpd-php5": "php5",
  3879. "x-ica": "ica",
  3880. "x-info": "info",
  3881. "x-internet-signup": ["ins", "isp"],
  3882. "x-iphone": "iii",
  3883. "x-iso9660-image": "iso",
  3884. "x-java-jnlp-file": "jnlp",
  3885. "x-jmol": "jmz",
  3886. "x-killustrator": "kil",
  3887. "x-koan": ["skp", "skd", "skt", "skm"],
  3888. "x-kpresenter": ["kpr", "kpt"],
  3889. "x-kword": ["kwd", "kwt"],
  3890. "x-latex": "latex",
  3891. "x-lha": "lha",
  3892. "x-lyx": "lyx",
  3893. "x-lzh": "lzh",
  3894. "x-lzx": "lzx",
  3895. "x-maker": ["frm", "maker", "frame", "fm", "fb", "book", "fbdoc"],
  3896. "x-ms-wmd": "wmd",
  3897. "x-ms-wmz": "wmz",
  3898. "x-msdos-program": ["com", "exe", "bat", "dll"],
  3899. "x-msi": "msi",
  3900. "x-netcdf": ["nc", "cdf"],
  3901. "x-ns-proxy-autoconfig": ["pac", "dat"],
  3902. "x-nwc": "nwc",
  3903. "x-object": "o",
  3904. "x-oz-application": "oza",
  3905. "x-pkcs7-certreqresp": "p7r",
  3906. "x-python-code": ["pyc", "pyo"],
  3907. "x-qgis": ["qgs", "shp", "shx"],
  3908. "x-quicktimeplayer": "qtl",
  3909. "x-redhat-package-manager": "rpm",
  3910. "x-ruby": "rb",
  3911. "x-sh": "sh",
  3912. "x-shar": "shar",
  3913. "x-shockwave-flash": ["swf", "swfl"],
  3914. "x-silverlight": "scr",
  3915. "x-stuffit": "sit",
  3916. "x-sv4cpio": "sv4cpio",
  3917. "x-sv4crc": "sv4crc",
  3918. "x-tar": "tar",
  3919. "x-tcl": "tcl",
  3920. "x-tex-gf": "gf",
  3921. "x-tex-pk": "pk",
  3922. "x-texinfo": ["texinfo", "texi"],
  3923. "x-trash": ["~", "%", "bak", "old", "sik"],
  3924. "x-troff": ["t", "tr", "roff"],
  3925. "x-troff-man": "man",
  3926. "x-troff-me": "me",
  3927. "x-troff-ms": "ms",
  3928. "x-ustar": "ustar",
  3929. "x-wais-source": "src",
  3930. "x-wingz": "wz",
  3931. "x-x509-ca-cert": ["crt", "der", "cer"],
  3932. "x-xcf": "xcf",
  3933. "x-xfig": "fig",
  3934. "x-xpinstall": "xpi",
  3935. "applixware": "aw",
  3936. "atomsvc+xml": "atomsvc",
  3937. "ccxml+xml": "ccxml",
  3938. "cdmi-capability": "cdmia",
  3939. "cdmi-container": "cdmic",
  3940. "cdmi-domain": "cdmid",
  3941. "cdmi-object": "cdmio",
  3942. "cdmi-queue": "cdmiq",
  3943. "docbook+xml": "dbk",
  3944. "dssc+der": "dssc",
  3945. "dssc+xml": "xdssc",
  3946. "emma+xml": "emma",
  3947. "epub+zip": "epub",
  3948. "exi": "exi",
  3949. "font-tdpfr": "pfr",
  3950. "gml+xml": "gml",
  3951. "gpx+xml": "gpx",
  3952. "gxf": "gxf",
  3953. "hyperstudio": "stk",
  3954. "inkml+xml": ["ink", "inkml"],
  3955. "ipfix": "ipfix",
  3956. "json": "json",
  3957. "jsonml+json": "jsonml",
  3958. "lost+xml": "lostxml",
  3959. "mads+xml": "mads",
  3960. "marc": "mrc",
  3961. "marcxml+xml": "mrcx",
  3962. "mathml+xml": "mathml",
  3963. "mbox": "mbox",
  3964. "mediaservercontrol+xml": "mscml",
  3965. "metalink+xml": "metalink",
  3966. "metalink4+xml": "meta4",
  3967. "mets+xml": "mets",
  3968. "mods+xml": "mods",
  3969. "mp21": ["m21", "mp21"],
  3970. "mp4": "mp4s",
  3971. "oebps-package+xml": "opf",
  3972. "omdoc+xml": "omdoc",
  3973. "onenote": ["onetoc", "onetoc2", "onetmp", "onepkg"],
  3974. "oxps": "oxps",
  3975. "patch-ops-error+xml": "xer",
  3976. "pgp-encrypted": "pgp",
  3977. "pkcs10": "p10",
  3978. "pkcs7-mime": ["p7m", "p7c"],
  3979. "pkcs7-signature": "p7s",
  3980. "pkcs8": "p8",
  3981. "pkix-attr-cert": "ac",
  3982. "pkix-crl": "crl",
  3983. "pkix-pkipath": "pkipath",
  3984. "pkixcmp": "pki",
  3985. "pls+xml": "pls",
  3986. "prs.cww": "cww",
  3987. "pskc+xml": "pskcxml",
  3988. "reginfo+xml": "rif",
  3989. "relax-ng-compact-syntax": "rnc",
  3990. "resource-lists+xml": "rl",
  3991. "resource-lists-diff+xml": "rld",
  3992. "rls-services+xml": "rs",
  3993. "rpki-ghostbusters": "gbr",
  3994. "rpki-manifest": "mft",
  3995. "rpki-roa": "roa",
  3996. "rsd+xml": "rsd",
  3997. "sbml+xml": "sbml",
  3998. "scvp-cv-request": "scq",
  3999. "scvp-cv-response": "scs",
  4000. "scvp-vp-request": "spq",
  4001. "scvp-vp-response": "spp",
  4002. "sdp": "sdp",
  4003. "set-payment-initiation": "setpay",
  4004. "set-registration-initiation": "setreg",
  4005. "shf+xml": "shf",
  4006. "sparql-query": "rq",
  4007. "sparql-results+xml": "srx",
  4008. "srgs": "gram",
  4009. "srgs+xml": "grxml",
  4010. "sru+xml": "sru",
  4011. "ssdl+xml": "ssdl",
  4012. "ssml+xml": "ssml",
  4013. "tei+xml": ["tei", "teicorpus"],
  4014. "thraud+xml": "tfi",
  4015. "timestamped-data": "tsd",
  4016. "vnd.3gpp.pic-bw-large": "plb",
  4017. "vnd.3gpp.pic-bw-small": "psb",
  4018. "vnd.3gpp.pic-bw-var": "pvb",
  4019. "vnd.3gpp2.tcap": "tcap",
  4020. "vnd.3m.post-it-notes": "pwn",
  4021. "vnd.accpac.simply.aso": "aso",
  4022. "vnd.accpac.simply.imp": "imp",
  4023. "vnd.acucobol": "acu",
  4024. "vnd.acucorp": ["atc", "acutc"],
  4025. "vnd.adobe.air-application-installer-package+zip": "air",
  4026. "vnd.adobe.formscentral.fcdt": "fcdt",
  4027. "vnd.adobe.fxp": ["fxp", "fxpl"],
  4028. "vnd.adobe.xdp+xml": "xdp",
  4029. "vnd.adobe.xfdf": "xfdf",
  4030. "vnd.ahead.space": "ahead",
  4031. "vnd.airzip.filesecure.azf": "azf",
  4032. "vnd.airzip.filesecure.azs": "azs",
  4033. "vnd.amazon.ebook": "azw",
  4034. "vnd.americandynamics.acc": "acc",
  4035. "vnd.amiga.ami": "ami",
  4036. "vnd.anser-web-certificate-issue-initiation": "cii",
  4037. "vnd.anser-web-funds-transfer-initiation": "fti",
  4038. "vnd.antix.game-component": "atx",
  4039. "vnd.apple.installer+xml": "mpkg",
  4040. "vnd.apple.mpegurl": "m3u8",
  4041. "vnd.aristanetworks.swi": "swi",
  4042. "vnd.astraea-software.iota": "iota",
  4043. "vnd.audiograph": "aep",
  4044. "vnd.blueice.multipass": "mpm",
  4045. "vnd.bmi": "bmi",
  4046. "vnd.businessobjects": "rep",
  4047. "vnd.chemdraw+xml": "cdxml",
  4048. "vnd.chipnuts.karaoke-mmd": "mmd",
  4049. "vnd.claymore": "cla",
  4050. "vnd.cloanto.rp9": "rp9",
  4051. "vnd.clonk.c4group": ["c4g", "c4d", "c4f", "c4p", "c4u"],
  4052. "vnd.cluetrust.cartomobile-config": "c11amc",
  4053. "vnd.cluetrust.cartomobile-config-pkg": "c11amz",
  4054. "vnd.commonspace": "csp",
  4055. "vnd.contact.cmsg": "cdbcmsg",
  4056. "vnd.cosmocaller": "cmc",
  4057. "vnd.crick.clicker": "clkx",
  4058. "vnd.crick.clicker.keyboard": "clkk",
  4059. "vnd.crick.clicker.palette": "clkp",
  4060. "vnd.crick.clicker.template": "clkt",
  4061. "vnd.crick.clicker.wordbank": "clkw",
  4062. "vnd.criticaltools.wbs+xml": "wbs",
  4063. "vnd.ctc-posml": "pml",
  4064. "vnd.cups-ppd": "ppd",
  4065. "vnd.curl.car": "car",
  4066. "vnd.curl.pcurl": "pcurl",
  4067. "vnd.dart": "dart",
  4068. "vnd.data-vision.rdz": "rdz",
  4069. "vnd.dece.data": ["uvf", "uvvf", "uvd", "uvvd"],
  4070. "vnd.dece.ttml+xml": ["uvt", "uvvt"],
  4071. "vnd.dece.unspecified": ["uvx", "uvvx"],
  4072. "vnd.dece.zip": ["uvz", "uvvz"],
  4073. "vnd.denovo.fcselayout-link": "fe_launch",
  4074. "vnd.dna": "dna",
  4075. "vnd.dolby.mlp": "mlp",
  4076. "vnd.dpgraph": "dpg",
  4077. "vnd.dreamfactory": "dfac",
  4078. "vnd.ds-keypoint": "kpxx",
  4079. "vnd.dvb.ait": "ait",
  4080. "vnd.dvb.service": "svc",
  4081. "vnd.dynageo": "geo",
  4082. "vnd.ecowin.chart": "mag",
  4083. "vnd.enliven": "nml",
  4084. "vnd.epson.esf": "esf",
  4085. "vnd.epson.msf": "msf",
  4086. "vnd.epson.quickanime": "qam",
  4087. "vnd.epson.salt": "slt",
  4088. "vnd.epson.ssf": "ssf",
  4089. "vnd.eszigno3+xml": ["es3", "et3"],
  4090. "vnd.ezpix-album": "ez2",
  4091. "vnd.ezpix-package": "ez3",
  4092. "vnd.fdf": "fdf",
  4093. "vnd.fdsn.mseed": "mseed",
  4094. "vnd.fdsn.seed": ["seed", "dataless"],
  4095. "vnd.flographit": "gph",
  4096. "vnd.fluxtime.clip": "ftc",
  4097. "vnd.framemaker": ["fm", "frame", "maker", "book"],
  4098. "vnd.frogans.fnc": "fnc",
  4099. "vnd.frogans.ltf": "ltf",
  4100. "vnd.fsc.weblaunch": "fsc",
  4101. "vnd.fujitsu.oasys": "oas",
  4102. "vnd.fujitsu.oasys2": "oa2",
  4103. "vnd.fujitsu.oasys3": "oa3",
  4104. "vnd.fujitsu.oasysgp": "fg5",
  4105. "vnd.fujitsu.oasysprs": "bh2",
  4106. "vnd.fujixerox.ddd": "ddd",
  4107. "vnd.fujixerox.docuworks": "xdw",
  4108. "vnd.fujixerox.docuworks.binder": "xbd",
  4109. "vnd.fuzzysheet": "fzs",
  4110. "vnd.genomatix.tuxedo": "txd",
  4111. "vnd.geogebra.file": "ggb",
  4112. "vnd.geogebra.tool": "ggt",
  4113. "vnd.geometry-explorer": ["gex", "gre"],
  4114. "vnd.geonext": "gxt",
  4115. "vnd.geoplan": "g2w",
  4116. "vnd.geospace": "g3w",
  4117. "vnd.gmx": "gmx",
  4118. "vnd.grafeq": ["gqf", "gqs"],
  4119. "vnd.groove-account": "gac",
  4120. "vnd.groove-help": "ghf",
  4121. "vnd.groove-identity-message": "gim",
  4122. "vnd.groove-injector": "grv",
  4123. "vnd.groove-tool-message": "gtm",
  4124. "vnd.groove-tool-template": "tpl",
  4125. "vnd.groove-vcard": "vcg",
  4126. "vnd.hal+xml": "hal",
  4127. "vnd.handheld-entertainment+xml": "zmm",
  4128. "vnd.hbci": "hbci",
  4129. "vnd.hhe.lesson-player": "les",
  4130. "vnd.hp-hpgl": "hpgl",
  4131. "vnd.hp-hpid": "hpid",
  4132. "vnd.hp-hps": "hps",
  4133. "vnd.hp-jlyt": "jlt",
  4134. "vnd.hp-pcl": "pcl",
  4135. "vnd.hp-pclxl": "pclxl",
  4136. "vnd.hydrostatix.sof-data": "sfd-hdstx",
  4137. "vnd.ibm.minipay": "mpy",
  4138. "vnd.ibm.modcap": ["afp", "listafp", "list3820"],
  4139. "vnd.ibm.rights-management": "irm",
  4140. "vnd.ibm.secure-container": "sc",
  4141. "vnd.iccprofile": ["icc", "icm"],
  4142. "vnd.igloader": "igl",
  4143. "vnd.immervision-ivp": "ivp",
  4144. "vnd.immervision-ivu": "ivu",
  4145. "vnd.insors.igm": "igm",
  4146. "vnd.intercon.formnet": ["xpw", "xpx"],
  4147. "vnd.intergeo": "i2g",
  4148. "vnd.intu.qbo": "qbo",
  4149. "vnd.intu.qfx": "qfx",
  4150. "vnd.ipunplugged.rcprofile": "rcprofile",
  4151. "vnd.irepository.package+xml": "irp",
  4152. "vnd.is-xpr": "xpr",
  4153. "vnd.isac.fcs": "fcs",
  4154. "vnd.jam": "jam",
  4155. "vnd.jcp.javame.midlet-rms": "rms",
  4156. "vnd.jisp": "jisp",
  4157. "vnd.joost.joda-archive": "joda",
  4158. "vnd.kahootz": ["ktz", "ktr"],
  4159. "vnd.kde.karbon": "karbon",
  4160. "vnd.kde.kchart": "chrt",
  4161. "vnd.kde.kformula": "kfo",
  4162. "vnd.kde.kivio": "flw",
  4163. "vnd.kde.kontour": "kon",
  4164. "vnd.kde.kpresenter": ["kpr", "kpt"],
  4165. "vnd.kde.kspread": "ksp",
  4166. "vnd.kde.kword": ["kwd", "kwt"],
  4167. "vnd.kenameaapp": "htke",
  4168. "vnd.kidspiration": "kia",
  4169. "vnd.kinar": ["kne", "knp"],
  4170. "vnd.koan": ["skp", "skd", "skt", "skm"],
  4171. "vnd.kodak-descriptor": "sse",
  4172. "vnd.las.las+xml": "lasxml",
  4173. "vnd.llamagraphics.life-balance.desktop": "lbd",
  4174. "vnd.llamagraphics.life-balance.exchange+xml": "lbe",
  4175. "vnd.lotus-1-2-3": "123",
  4176. "vnd.lotus-approach": "apr",
  4177. "vnd.lotus-freelance": "pre",
  4178. "vnd.lotus-notes": "nsf",
  4179. "vnd.lotus-organizer": "org",
  4180. "vnd.lotus-screencam": "scm",
  4181. "vnd.lotus-wordpro": "lwp",
  4182. "vnd.macports.portpkg": "portpkg",
  4183. "vnd.mcd": "mcd",
  4184. "vnd.medcalcdata": "mc1",
  4185. "vnd.mediastation.cdkey": "cdkey",
  4186. "vnd.mfer": "mwf",
  4187. "vnd.mfmp": "mfm",
  4188. "vnd.micrografx.flo": "flo",
  4189. "vnd.micrografx.igx": "igx",
  4190. "vnd.mif": "mif",
  4191. "vnd.mobius.daf": "daf",
  4192. "vnd.mobius.dis": "dis",
  4193. "vnd.mobius.mbk": "mbk",
  4194. "vnd.mobius.mqy": "mqy",
  4195. "vnd.mobius.msl": "msl",
  4196. "vnd.mobius.plc": "plc",
  4197. "vnd.mobius.txf": "txf",
  4198. "vnd.mophun.application": "mpn",
  4199. "vnd.mophun.certificate": "mpc",
  4200. "vnd.ms-artgalry": "cil",
  4201. "vnd.ms-cab-compressed": "cab",
  4202. "vnd.ms-excel.addin.macroenabled.12": "xlam",
  4203. "vnd.ms-excel.sheet.binary.macroenabled.12": "xlsb",
  4204. "vnd.ms-excel.sheet.macroenabled.12": "xlsm",
  4205. "vnd.ms-excel.template.macroenabled.12": "xltm",
  4206. "vnd.ms-fontobject": "eot",
  4207. "vnd.ms-htmlhelp": "chm",
  4208. "vnd.ms-ims": "ims",
  4209. "vnd.ms-lrm": "lrm",
  4210. "vnd.ms-officetheme": "thmx",
  4211. "vnd.ms-powerpoint.addin.macroenabled.12": "ppam",
  4212. "vnd.ms-powerpoint.presentation.macroenabled.12": "pptm",
  4213. "vnd.ms-powerpoint.slide.macroenabled.12": "sldm",
  4214. "vnd.ms-powerpoint.slideshow.macroenabled.12": "ppsm",
  4215. "vnd.ms-powerpoint.template.macroenabled.12": "potm",
  4216. "vnd.ms-project": ["mpp", "mpt"],
  4217. "vnd.ms-word.document.macroenabled.12": "docm",
  4218. "vnd.ms-word.template.macroenabled.12": "dotm",
  4219. "vnd.ms-works": ["wps", "wks", "wcm", "wdb"],
  4220. "vnd.ms-wpl": "wpl",
  4221. "vnd.ms-xpsdocument": "xps",
  4222. "vnd.mseq": "mseq",
  4223. "vnd.musician": "mus",
  4224. "vnd.muvee.style": "msty",
  4225. "vnd.mynfc": "taglet",
  4226. "vnd.neurolanguage.nlu": "nlu",
  4227. "vnd.nitf": ["ntf", "nitf"],
  4228. "vnd.noblenet-directory": "nnd",
  4229. "vnd.noblenet-sealer": "nns",
  4230. "vnd.noblenet-web": "nnw",
  4231. "vnd.nokia.n-gage.data": "ngdat",
  4232. "vnd.nokia.n-gage.symbian.install": "n-gage",
  4233. "vnd.nokia.radio-preset": "rpst",
  4234. "vnd.nokia.radio-presets": "rpss",
  4235. "vnd.novadigm.edm": "edm",
  4236. "vnd.novadigm.edx": "edx",
  4237. "vnd.novadigm.ext": "ext",
  4238. "vnd.oasis.opendocument.chart-template": "otc",
  4239. "vnd.oasis.opendocument.formula-template": "odft",
  4240. "vnd.oasis.opendocument.image-template": "oti",
  4241. "vnd.olpc-sugar": "xo",
  4242. "vnd.oma.dd2+xml": "dd2",
  4243. "vnd.openofficeorg.extension": "oxt",
  4244. "vnd.openxmlformats-officedocument.presentationml.slide": "sldx",
  4245. "vnd.osgeo.mapguide.package": "mgp",
  4246. "vnd.osgi.dp": "dp",
  4247. "vnd.osgi.subsystem": "esa",
  4248. "vnd.palm": ["pdb", "pqa", "oprc"],
  4249. "vnd.pawaafile": "paw",
  4250. "vnd.pg.format": "str",
  4251. "vnd.pg.osasli": "ei6",
  4252. "vnd.picsel": "efif",
  4253. "vnd.pmi.widget": "wg",
  4254. "vnd.pocketlearn": "plf",
  4255. "vnd.powerbuilder6": "pbd",
  4256. "vnd.previewsystems.box": "box",
  4257. "vnd.proteus.magazine": "mgz",
  4258. "vnd.publishare-delta-tree": "qps",
  4259. "vnd.pvi.ptid1": "ptid",
  4260. "vnd.quark.quarkxpress": ["qxd", "qxt", "qwd", "qwt", "qxl", "qxb"],
  4261. "vnd.realvnc.bed": "bed",
  4262. "vnd.recordare.musicxml": "mxl",
  4263. "vnd.recordare.musicxml+xml": "musicxml",
  4264. "vnd.rig.cryptonote": "cryptonote",
  4265. "vnd.rn-realmedia": "rm",
  4266. "vnd.rn-realmedia-vbr": "rmvb",
  4267. "vnd.route66.link66+xml": "link66",
  4268. "vnd.sailingtracker.track": "st",
  4269. "vnd.seemail": "see",
  4270. "vnd.sema": "sema",
  4271. "vnd.semd": "semd",
  4272. "vnd.semf": "semf",
  4273. "vnd.shana.informed.formdata": "ifm",
  4274. "vnd.shana.informed.formtemplate": "itp",
  4275. "vnd.shana.informed.interchange": "iif",
  4276. "vnd.shana.informed.package": "ipk",
  4277. "vnd.simtech-mindmapper": ["twd", "twds"],
  4278. "vnd.smart.teacher": "teacher",
  4279. "vnd.solent.sdkm+xml": ["sdkm", "sdkd"],
  4280. "vnd.spotfire.dxp": "dxp",
  4281. "vnd.spotfire.sfs": "sfs",
  4282. "vnd.stepmania.package": "smzip",
  4283. "vnd.stepmania.stepchart": "sm",
  4284. "vnd.sus-calendar": ["sus", "susp"],
  4285. "vnd.svd": "svd",
  4286. "vnd.syncml+xml": "xsm",
  4287. "vnd.syncml.dm+wbxml": "bdm",
  4288. "vnd.syncml.dm+xml": "xdm",
  4289. "vnd.tao.intent-module-archive": "tao",
  4290. "vnd.tcpdump.pcap": ["pcap", "cap", "dmp"],
  4291. "vnd.tmobile-livetv": "tmo",
  4292. "vnd.trid.tpt": "tpt",
  4293. "vnd.triscape.mxs": "mxs",
  4294. "vnd.trueapp": "tra",
  4295. "vnd.ufdl": ["ufd", "ufdl"],
  4296. "vnd.uiq.theme": "utz",
  4297. "vnd.umajin": "umj",
  4298. "vnd.unity": "unityweb",
  4299. "vnd.uoml+xml": "uoml",
  4300. "vnd.vcx": "vcx",
  4301. "vnd.visionary": "vis",
  4302. "vnd.vsf": "vsf",
  4303. "vnd.webturbo": "wtb",
  4304. "vnd.wolfram.player": "nbp",
  4305. "vnd.wqd": "wqd",
  4306. "vnd.wt.stf": "stf",
  4307. "vnd.xara": "xar",
  4308. "vnd.xfdl": "xfdl",
  4309. "vnd.yamaha.hv-dic": "hvd",
  4310. "vnd.yamaha.hv-script": "hvs",
  4311. "vnd.yamaha.hv-voice": "hvp",
  4312. "vnd.yamaha.openscoreformat": "osf",
  4313. "vnd.yamaha.openscoreformat.osfpvg+xml": "osfpvg",
  4314. "vnd.yamaha.smaf-audio": "saf",
  4315. "vnd.yamaha.smaf-phrase": "spf",
  4316. "vnd.yellowriver-custom-menu": "cmp",
  4317. "vnd.zul": ["zir", "zirz"],
  4318. "vnd.zzazz.deck+xml": "zaz",
  4319. "voicexml+xml": "vxml",
  4320. "widget": "wgt",
  4321. "winhlp": "hlp",
  4322. "wsdl+xml": "wsdl",
  4323. "wspolicy+xml": "wspolicy",
  4324. "x-ace-compressed": "ace",
  4325. "x-authorware-bin": ["aab", "x32", "u32", "vox"],
  4326. "x-authorware-map": "aam",
  4327. "x-authorware-seg": "aas",
  4328. "x-blorb": ["blb", "blorb"],
  4329. "x-bzip": "bz",
  4330. "x-bzip2": ["bz2", "boz"],
  4331. "x-cfs-compressed": "cfs",
  4332. "x-chat": "chat",
  4333. "x-conference": "nsc",
  4334. "x-dgc-compressed": "dgc",
  4335. "x-dtbncx+xml": "ncx",
  4336. "x-dtbook+xml": "dtb",
  4337. "x-dtbresource+xml": "res",
  4338. "x-eva": "eva",
  4339. "x-font-bdf": "bdf",
  4340. "x-font-ghostscript": "gsf",
  4341. "x-font-linux-psf": "psf",
  4342. "x-font-otf": "otf",
  4343. "x-font-pcf": "pcf",
  4344. "x-font-snf": "snf",
  4345. "x-font-ttf": ["ttf", "ttc"],
  4346. "x-font-type1": ["pfa", "pfb", "pfm", "afm"],
  4347. "x-font-woff": "woff",
  4348. "x-freearc": "arc",
  4349. "x-gca-compressed": "gca",
  4350. "x-glulx": "ulx",
  4351. "x-gramps-xml": "gramps",
  4352. "x-install-instructions": "install",
  4353. "x-lzh-compressed": ["lzh", "lha"],
  4354. "x-mie": "mie",
  4355. "x-mobipocket-ebook": ["prc", "mobi"],
  4356. "x-ms-application": "application",
  4357. "x-ms-shortcut": "lnk",
  4358. "x-ms-xbap": "xbap",
  4359. "x-msbinder": "obd",
  4360. "x-mscardfile": "crd",
  4361. "x-msclip": "clp",
  4362. "x-msdownload": ["exe", "dll", "com", "bat", "msi"],
  4363. "x-msmediaview": ["mvb", "m13", "m14"],
  4364. "x-msmetafile": ["wmf", "wmz", "emf", "emz"],
  4365. "x-msmoney": "mny",
  4366. "x-mspublisher": "pub",
  4367. "x-msschedule": "scd",
  4368. "x-msterminal": "trm",
  4369. "x-mswrite": "wri",
  4370. "x-nzb": "nzb",
  4371. "x-pkcs12": ["p12", "pfx"],
  4372. "x-pkcs7-certificates": ["p7b", "spc"],
  4373. "x-research-info-systems": "ris",
  4374. "x-silverlight-app": "xap",
  4375. "x-sql": "sql",
  4376. "x-stuffitx": "sitx",
  4377. "x-subrip": "srt",
  4378. "x-t3vm-image": "t3",
  4379. "x-tads": "gam",
  4380. "x-tex": "tex",
  4381. "x-tex-tfm": "tfm",
  4382. "x-tgif": "obj",
  4383. "x-xliff+xml": "xlf",
  4384. "x-xz": "xz",
  4385. "x-zmachine": ["z1", "z2", "z3", "z4", "z5", "z6", "z7", "z8"],
  4386. "xaml+xml": "xaml",
  4387. "xcap-diff+xml": "xdf",
  4388. "xenc+xml": "xenc",
  4389. "xml-dtd": "dtd",
  4390. "xop+xml": "xop",
  4391. "xproc+xml": "xpl",
  4392. "xslt+xml": "xslt",
  4393. "xv+xml": ["mxml", "xhvml", "xvml", "xvm"],
  4394. "yang": "yang",
  4395. "yin+xml": "yin",
  4396. "envoy": "evy",
  4397. "fractals": "fif",
  4398. "internet-property-stream": "acx",
  4399. "olescript": "axs",
  4400. "vnd.ms-outlook": "msg",
  4401. "vnd.ms-pkicertstore": "sst",
  4402. "x-compress": "z",
  4403. "x-compressed": "tgz",
  4404. "x-gzip": "gz",
  4405. "x-perfmon": ["pma", "pmc", "pml", "pmr", "pmw"],
  4406. "x-pkcs7-mime": ["p7c", "p7m"],
  4407. "ynd.ms-pkipko": "pko"
  4408. },
  4409. "audio": {
  4410. "amr": "amr",
  4411. "amr-wb": "awb",
  4412. "annodex": "axa",
  4413. "basic": ["au", "snd"],
  4414. "flac": "flac",
  4415. "midi": ["mid", "midi", "kar", "rmi"],
  4416. "mpeg": ["mpga", "mpega", "mp2", "mp3", "m4a", "mp2a", "m2a", "m3a"],
  4417. "mpegurl": "m3u",
  4418. "ogg": ["oga", "ogg", "spx"],
  4419. "prs.sid": "sid",
  4420. "x-aiff": ["aif", "aiff", "aifc"],
  4421. "x-gsm": "gsm",
  4422. "x-ms-wma": "wma",
  4423. "x-ms-wax": "wax",
  4424. "x-pn-realaudio": "ram",
  4425. "x-realaudio": "ra",
  4426. "x-sd2": "sd2",
  4427. "x-wav": "wav",
  4428. "adpcm": "adp",
  4429. "mp4": "mp4a",
  4430. "s3m": "s3m",
  4431. "silk": "sil",
  4432. "vnd.dece.audio": ["uva", "uvva"],
  4433. "vnd.digital-winds": "eol",
  4434. "vnd.dra": "dra",
  4435. "vnd.dts": "dts",
  4436. "vnd.dts.hd": "dtshd",
  4437. "vnd.lucent.voice": "lvp",
  4438. "vnd.ms-playready.media.pya": "pya",
  4439. "vnd.nuera.ecelp4800": "ecelp4800",
  4440. "vnd.nuera.ecelp7470": "ecelp7470",
  4441. "vnd.nuera.ecelp9600": "ecelp9600",
  4442. "vnd.rip": "rip",
  4443. "webm": "weba",
  4444. "x-aac": "aac",
  4445. "x-caf": "caf",
  4446. "x-matroska": "mka",
  4447. "x-pn-realaudio-plugin": "rmp",
  4448. "xm": "xm",
  4449. "mid": ["mid", "rmi"]
  4450. },
  4451. "chemical": {
  4452. "x-alchemy": "alc",
  4453. "x-cache": ["cac", "cache"],
  4454. "x-cache-csf": "csf",
  4455. "x-cactvs-binary": ["cbin", "cascii", "ctab"],
  4456. "x-cdx": "cdx",
  4457. "x-chem3d": "c3d",
  4458. "x-cif": "cif",
  4459. "x-cmdf": "cmdf",
  4460. "x-cml": "cml",
  4461. "x-compass": "cpa",
  4462. "x-crossfire": "bsd",
  4463. "x-csml": ["csml", "csm"],
  4464. "x-ctx": "ctx",
  4465. "x-cxf": ["cxf", "cef"],
  4466. "x-embl-dl-nucleotide": ["emb", "embl"],
  4467. "x-gamess-input": ["inp", "gam", "gamin"],
  4468. "x-gaussian-checkpoint": ["fch", "fchk"],
  4469. "x-gaussian-cube": "cub",
  4470. "x-gaussian-input": ["gau", "gjc", "gjf"],
  4471. "x-gaussian-log": "gal",
  4472. "x-gcg8-sequence": "gcg",
  4473. "x-genbank": "gen",
  4474. "x-hin": "hin",
  4475. "x-isostar": ["istr", "ist"],
  4476. "x-jcamp-dx": ["jdx", "dx"],
  4477. "x-kinemage": "kin",
  4478. "x-macmolecule": "mcm",
  4479. "x-macromodel-input": ["mmd", "mmod"],
  4480. "x-mdl-molfile": "mol",
  4481. "x-mdl-rdfile": "rd",
  4482. "x-mdl-rxnfile": "rxn",
  4483. "x-mdl-sdfile": ["sd", "sdf"],
  4484. "x-mdl-tgf": "tgf",
  4485. "x-mmcif": "mcif",
  4486. "x-mol2": "mol2",
  4487. "x-molconn-Z": "b",
  4488. "x-mopac-graph": "gpt",
  4489. "x-mopac-input": ["mop", "mopcrt", "mpc", "zmt"],
  4490. "x-mopac-out": "moo",
  4491. "x-ncbi-asn1": "asn",
  4492. "x-ncbi-asn1-ascii": ["prt", "ent"],
  4493. "x-ncbi-asn1-binary": ["val", "aso"],
  4494. "x-pdb": ["pdb", "ent"],
  4495. "x-rosdal": "ros",
  4496. "x-swissprot": "sw",
  4497. "x-vamas-iso14976": "vms",
  4498. "x-vmd": "vmd",
  4499. "x-xtel": "xtel",
  4500. "x-xyz": "xyz"
  4501. },
  4502. "image": {
  4503. "gif": "gif",
  4504. "ief": "ief",
  4505. "jpeg": ["jpeg", "jpg", "jpe"],
  4506. "pcx": "pcx",
  4507. "png": "png",
  4508. "svg+xml": ["svg", "svgz"],
  4509. "tiff": ["tiff", "tif"],
  4510. "vnd.djvu": ["djvu", "djv"],
  4511. "vnd.wap.wbmp": "wbmp",
  4512. "x-canon-cr2": "cr2",
  4513. "x-canon-crw": "crw",
  4514. "x-cmu-raster": "ras",
  4515. "x-coreldraw": "cdr",
  4516. "x-coreldrawpattern": "pat",
  4517. "x-coreldrawtemplate": "cdt",
  4518. "x-corelphotopaint": "cpt",
  4519. "x-epson-erf": "erf",
  4520. "x-icon": "ico",
  4521. "x-jg": "art",
  4522. "x-jng": "jng",
  4523. "x-nikon-nef": "nef",
  4524. "x-olympus-orf": "orf",
  4525. "x-photoshop": "psd",
  4526. "x-portable-anymap": "pnm",
  4527. "x-portable-bitmap": "pbm",
  4528. "x-portable-graymap": "pgm",
  4529. "x-portable-pixmap": "ppm",
  4530. "x-rgb": "rgb",
  4531. "x-xbitmap": "xbm",
  4532. "x-xpixmap": "xpm",
  4533. "x-xwindowdump": "xwd",
  4534. "bmp": "bmp",
  4535. "cgm": "cgm",
  4536. "g3fax": "g3",
  4537. "ktx": "ktx",
  4538. "prs.btif": "btif",
  4539. "sgi": "sgi",
  4540. "vnd.dece.graphic": ["uvi", "uvvi", "uvg", "uvvg"],
  4541. "vnd.dwg": "dwg",
  4542. "vnd.dxf": "dxf",
  4543. "vnd.fastbidsheet": "fbs",
  4544. "vnd.fpx": "fpx",
  4545. "vnd.fst": "fst",
  4546. "vnd.fujixerox.edmics-mmr": "mmr",
  4547. "vnd.fujixerox.edmics-rlc": "rlc",
  4548. "vnd.ms-modi": "mdi",
  4549. "vnd.ms-photo": "wdp",
  4550. "vnd.net-fpx": "npx",
  4551. "vnd.xiff": "xif",
  4552. "webp": "webp",
  4553. "x-3ds": "3ds",
  4554. "x-cmx": "cmx",
  4555. "x-freehand": ["fh", "fhc", "fh4", "fh5", "fh7"],
  4556. "x-pict": ["pic", "pct"],
  4557. "x-tga": "tga",
  4558. "cis-cod": "cod",
  4559. "pipeg": "jfif"
  4560. },
  4561. "message": {
  4562. "rfc822": ["eml", "mime", "mht", "mhtml", "nws"]
  4563. },
  4564. "model": {
  4565. "iges": ["igs", "iges"],
  4566. "mesh": ["msh", "mesh", "silo"],
  4567. "vrml": ["wrl", "vrml"],
  4568. "x3d+vrml": ["x3dv", "x3dvz"],
  4569. "x3d+xml": ["x3d", "x3dz"],
  4570. "x3d+binary": ["x3db", "x3dbz"],
  4571. "vnd.collada+xml": "dae",
  4572. "vnd.dwf": "dwf",
  4573. "vnd.gdl": "gdl",
  4574. "vnd.gtw": "gtw",
  4575. "vnd.mts": "mts",
  4576. "vnd.vtu": "vtu"
  4577. },
  4578. "text": {
  4579. "cache-manifest": ["manifest", "appcache"],
  4580. "calendar": ["ics", "icz", "ifb"],
  4581. "css": "css",
  4582. "csv": "csv",
  4583. "h323": "323",
  4584. "html": ["html", "htm", "shtml", "stm"],
  4585. "iuls": "uls",
  4586. "mathml": "mml",
  4587. "plain": ["txt", "text", "brf", "conf", "def", "list", "log", "in", "bas"],
  4588. "richtext": "rtx",
  4589. "scriptlet": ["sct", "wsc"],
  4590. "texmacs": ["tm", "ts"],
  4591. "tab-separated-values": "tsv",
  4592. "vnd.sun.j2me.app-descriptor": "jad",
  4593. "vnd.wap.wml": "wml",
  4594. "vnd.wap.wmlscript": "wmls",
  4595. "x-bibtex": "bib",
  4596. "x-boo": "boo",
  4597. "x-c++hdr": ["h++", "hpp", "hxx", "hh"],
  4598. "x-c++src": ["c++", "cpp", "cxx", "cc"],
  4599. "x-component": "htc",
  4600. "x-dsrc": "d",
  4601. "x-diff": ["diff", "patch"],
  4602. "x-haskell": "hs",
  4603. "x-java": "java",
  4604. "x-literate-haskell": "lhs",
  4605. "x-moc": "moc",
  4606. "x-pascal": ["p", "pas"],
  4607. "x-pcs-gcd": "gcd",
  4608. "x-perl": ["pl", "pm"],
  4609. "x-python": "py",
  4610. "x-scala": "scala",
  4611. "x-setext": "etx",
  4612. "x-tcl": ["tcl", "tk"],
  4613. "x-tex": ["tex", "ltx", "sty", "cls"],
  4614. "x-vcalendar": "vcs",
  4615. "x-vcard": "vcf",
  4616. "n3": "n3",
  4617. "prs.lines.tag": "dsc",
  4618. "sgml": ["sgml", "sgm"],
  4619. "troff": ["t", "tr", "roff", "man", "me", "ms"],
  4620. "turtle": "ttl",
  4621. "uri-list": ["uri", "uris", "urls"],
  4622. "vcard": "vcard",
  4623. "vnd.curl": "curl",
  4624. "vnd.curl.dcurl": "dcurl",
  4625. "vnd.curl.scurl": "scurl",
  4626. "vnd.curl.mcurl": "mcurl",
  4627. "vnd.dvb.subtitle": "sub",
  4628. "vnd.fly": "fly",
  4629. "vnd.fmi.flexstor": "flx",
  4630. "vnd.graphviz": "gv",
  4631. "vnd.in3d.3dml": "3dml",
  4632. "vnd.in3d.spot": "spot",
  4633. "x-asm": ["s", "asm"],
  4634. "x-c": ["c", "cc", "cxx", "cpp", "h", "hh", "dic"],
  4635. "x-fortran": ["f", "for", "f77", "f90"],
  4636. "x-opml": "opml",
  4637. "x-nfo": "nfo",
  4638. "x-sfv": "sfv",
  4639. "x-uuencode": "uu",
  4640. "webviewhtml": "htt"
  4641. },
  4642. "video": {
  4643. "avif": ".avif",
  4644. "3gpp": "3gp",
  4645. "annodex": "axv",
  4646. "dl": "dl",
  4647. "dv": ["dif", "dv"],
  4648. "fli": "fli",
  4649. "gl": "gl",
  4650. "mpeg": ["mpeg", "mpg", "mpe", "m1v", "m2v", "mp2", "mpa", "mpv2"],
  4651. "mp4": ["mp4", "mp4v", "mpg4"],
  4652. "quicktime": ["qt", "mov"],
  4653. "ogg": "ogv",
  4654. "vnd.mpegurl": ["mxu", "m4u"],
  4655. "x-flv": "flv",
  4656. "x-la-asf": ["lsf", "lsx"],
  4657. "x-mng": "mng",
  4658. "x-ms-asf": ["asf", "asx", "asr"],
  4659. "x-ms-wm": "wm",
  4660. "x-ms-wmv": "wmv",
  4661. "x-ms-wmx": "wmx",
  4662. "x-ms-wvx": "wvx",
  4663. "x-msvideo": "avi",
  4664. "x-sgi-movie": "movie",
  4665. "x-matroska": ["mpv", "mkv", "mk3d", "mks"],
  4666. "3gpp2": "3g2",
  4667. "h261": "h261",
  4668. "h263": "h263",
  4669. "h264": "h264",
  4670. "jpeg": "jpgv",
  4671. "jpm": ["jpm", "jpgm"],
  4672. "mj2": ["mj2", "mjp2"],
  4673. "vnd.dece.hd": ["uvh", "uvvh"],
  4674. "vnd.dece.mobile": ["uvm", "uvvm"],
  4675. "vnd.dece.pd": ["uvp", "uvvp"],
  4676. "vnd.dece.sd": ["uvs", "uvvs"],
  4677. "vnd.dece.video": ["uvv", "uvvv"],
  4678. "vnd.dvb.file": "dvb",
  4679. "vnd.fvt": "fvt",
  4680. "vnd.ms-playready.media.pyv": "pyv",
  4681. "vnd.uvvu.mp4": ["uvu", "uvvu"],
  4682. "vnd.vivo": "viv",
  4683. "webm": "webm",
  4684. "x-f4v": "f4v",
  4685. "x-m4v": "m4v",
  4686. "x-ms-vob": "vob",
  4687. "x-smv": "smv"
  4688. },
  4689. "x-conference": {
  4690. "x-cooltalk": "ice"
  4691. },
  4692. "x-world": {
  4693. "x-vrml": ["vrm", "vrml", "wrl", "flr", "wrz", "xaf", "xof"]
  4694. }
  4695. };
  4696. const mimeTypes = (() => {
  4697. const mimeTypes = {};
  4698. for (const type in table$1) {
  4699. // eslint-disable-next-line no-prototype-builtins
  4700. if (table$1.hasOwnProperty(type)) {
  4701. for (const subtype in table$1[type]) {
  4702. // eslint-disable-next-line no-prototype-builtins
  4703. if (table$1[type].hasOwnProperty(subtype)) {
  4704. const value = table$1[type][subtype];
  4705. if (typeof value == "string") {
  4706. mimeTypes[value] = type + "/" + subtype;
  4707. } else {
  4708. for (let indexMimeType = 0; indexMimeType < value.length; indexMimeType++) {
  4709. mimeTypes[value[indexMimeType]] = type + "/" + subtype;
  4710. }
  4711. }
  4712. }
  4713. }
  4714. }
  4715. }
  4716. return mimeTypes;
  4717. })();
  4718. function getMimeType(filename) {
  4719. return filename && mimeTypes[filename.split(".").pop().toLowerCase()] || getMimeType$1();
  4720. }
  4721. /*
  4722. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  4723. Redistribution and use in source and binary forms, with or without
  4724. modification, are permitted provided that the following conditions are met:
  4725. 1. Redistributions of source code must retain the above copyright notice,
  4726. this list of conditions and the following disclaimer.
  4727. 2. Redistributions in binary form must reproduce the above copyright
  4728. notice, this list of conditions and the following disclaimer in
  4729. the documentation and/or other materials provided with the distribution.
  4730. 3. The names of the authors may not be used to endorse or promote products
  4731. derived from this software without specific prior written permission.
  4732. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  4733. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  4734. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  4735. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  4736. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4737. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  4738. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4739. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4740. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4741. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4742. */
  4743. const table = [];
  4744. for (let i = 0; i < 256; i++) {
  4745. let t = i;
  4746. for (let j = 0; j < 8; j++) {
  4747. if (t & 1) {
  4748. t = (t >>> 1) ^ 0xEDB88320;
  4749. } else {
  4750. t = t >>> 1;
  4751. }
  4752. }
  4753. table[i] = t;
  4754. }
  4755. class Crc32 {
  4756. constructor(crc) {
  4757. this.crc = crc || -1;
  4758. }
  4759. append(data) {
  4760. let crc = this.crc | 0;
  4761. for (let offset = 0, length = data.length | 0; offset < length; offset++) {
  4762. crc = (crc >>> 8) ^ table[(crc ^ data[offset]) & 0xFF];
  4763. }
  4764. this.crc = crc;
  4765. }
  4766. get() {
  4767. return ~this.crc;
  4768. }
  4769. }
  4770. /*
  4771. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  4772. Redistribution and use in source and binary forms, with or without
  4773. modification, are permitted provided that the following conditions are met:
  4774. 1. Redistributions of source code must retain the above copyright notice,
  4775. this list of conditions and the following disclaimer.
  4776. 2. Redistributions in binary form must reproduce the above copyright
  4777. notice, this list of conditions and the following disclaimer in
  4778. the documentation and/or other materials provided with the distribution.
  4779. 3. The names of the authors may not be used to endorse or promote products
  4780. derived from this software without specific prior written permission.
  4781. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  4782. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  4783. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  4784. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  4785. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4786. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  4787. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4788. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4789. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4790. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4791. */
  4792. function encodeText(value) {
  4793. if (typeof TextEncoder == "undefined") {
  4794. value = unescape(encodeURIComponent(value));
  4795. const result = new Uint8Array(value.length);
  4796. for (let i = 0; i < result.length; i++) {
  4797. result[i] = value.charCodeAt(i);
  4798. }
  4799. return result;
  4800. } else {
  4801. return new TextEncoder().encode(value);
  4802. }
  4803. }
  4804. // Derived from https://github.com/xqdoo00o/jszip/blob/master/lib/sjcl.js and https://github.com/bitwiseshiftleft/sjcl
  4805. /*// deno-lint-ignore-file no-this-alias *
  4806. /*
  4807. * SJCL is open. You can use, modify and redistribute it under a BSD
  4808. * license or under the GNU GPL, version 2.0.
  4809. */
  4810. /** @fileOverview Javascript cryptography implementation.
  4811. *
  4812. * Crush to remove comments, shorten variable names and
  4813. * generally reduce transmission size.
  4814. *
  4815. * @author Emily Stark
  4816. * @author Mike Hamburg
  4817. * @author Dan Boneh
  4818. */
  4819. /*jslint indent: 2, bitwise: false, nomen: false, plusplus: false, white: false, regexp: false */
  4820. /** @fileOverview Arrays of bits, encoded as arrays of Numbers.
  4821. *
  4822. * @author Emily Stark
  4823. * @author Mike Hamburg
  4824. * @author Dan Boneh
  4825. */
  4826. /**
  4827. * Arrays of bits, encoded as arrays of Numbers.
  4828. * @namespace
  4829. * @description
  4830. * <p>
  4831. * These objects are the currency accepted by SJCL's crypto functions.
  4832. * </p>
  4833. *
  4834. * <p>
  4835. * Most of our crypto primitives operate on arrays of 4-byte words internally,
  4836. * but many of them can take arguments that are not a multiple of 4 bytes.
  4837. * This library encodes arrays of bits (whose size need not be a multiple of 8
  4838. * bits) as arrays of 32-bit words. The bits are packed, big-endian, into an
  4839. * array of words, 32 bits at a time. Since the words are double-precision
  4840. * floating point numbers, they fit some extra data. We use this (in a private,
  4841. * possibly-changing manner) to encode the number of bits actually present
  4842. * in the last word of the array.
  4843. * </p>
  4844. *
  4845. * <p>
  4846. * Because bitwise ops clear this out-of-band data, these arrays can be passed
  4847. * to ciphers like AES which want arrays of words.
  4848. * </p>
  4849. */
  4850. const bitArray = {
  4851. /**
  4852. * Concatenate two bit arrays.
  4853. * @param {bitArray} a1 The first array.
  4854. * @param {bitArray} a2 The second array.
  4855. * @return {bitArray} The concatenation of a1 and a2.
  4856. */
  4857. concat(a1, a2) {
  4858. if (a1.length === 0 || a2.length === 0) {
  4859. return a1.concat(a2);
  4860. }
  4861. const last = a1[a1.length - 1], shift = bitArray.getPartial(last);
  4862. if (shift === 32) {
  4863. return a1.concat(a2);
  4864. } else {
  4865. return bitArray._shiftRight(a2, shift, last | 0, a1.slice(0, a1.length - 1));
  4866. }
  4867. },
  4868. /**
  4869. * Find the length of an array of bits.
  4870. * @param {bitArray} a The array.
  4871. * @return {Number} The length of a, in bits.
  4872. */
  4873. bitLength(a) {
  4874. const l = a.length;
  4875. if (l === 0) {
  4876. return 0;
  4877. }
  4878. const x = a[l - 1];
  4879. return (l - 1) * 32 + bitArray.getPartial(x);
  4880. },
  4881. /**
  4882. * Truncate an array.
  4883. * @param {bitArray} a The array.
  4884. * @param {Number} len The length to truncate to, in bits.
  4885. * @return {bitArray} A new array, truncated to len bits.
  4886. */
  4887. clamp(a, len) {
  4888. if (a.length * 32 < len) {
  4889. return a;
  4890. }
  4891. a = a.slice(0, Math.ceil(len / 32));
  4892. const l = a.length;
  4893. len = len & 31;
  4894. if (l > 0 && len) {
  4895. a[l - 1] = bitArray.partial(len, a[l - 1] & 0x80000000 >> (len - 1), 1);
  4896. }
  4897. return a;
  4898. },
  4899. /**
  4900. * Make a partial word for a bit array.
  4901. * @param {Number} len The number of bits in the word.
  4902. * @param {Number} x The bits.
  4903. * @param {Number} [_end=0] Pass 1 if x has already been shifted to the high side.
  4904. * @return {Number} The partial word.
  4905. */
  4906. partial(len, x, _end) {
  4907. if (len === 32) {
  4908. return x;
  4909. }
  4910. return (_end ? x | 0 : x << (32 - len)) + len * 0x10000000000;
  4911. },
  4912. /**
  4913. * Get the number of bits used by a partial word.
  4914. * @param {Number} x The partial word.
  4915. * @return {Number} The number of bits used by the partial word.
  4916. */
  4917. getPartial(x) {
  4918. return Math.round(x / 0x10000000000) || 32;
  4919. },
  4920. /** Shift an array right.
  4921. * @param {bitArray} a The array to shift.
  4922. * @param {Number} shift The number of bits to shift.
  4923. * @param {Number} [carry=0] A byte to carry in
  4924. * @param {bitArray} [out=[]] An array to prepend to the output.
  4925. * @private
  4926. */
  4927. _shiftRight(a, shift, carry, out) {
  4928. if (out === undefined) {
  4929. out = [];
  4930. }
  4931. for (; shift >= 32; shift -= 32) {
  4932. out.push(carry);
  4933. carry = 0;
  4934. }
  4935. if (shift === 0) {
  4936. return out.concat(a);
  4937. }
  4938. for (let i = 0; i < a.length; i++) {
  4939. out.push(carry | a[i] >>> shift);
  4940. carry = a[i] << (32 - shift);
  4941. }
  4942. const last2 = a.length ? a[a.length - 1] : 0;
  4943. const shift2 = bitArray.getPartial(last2);
  4944. out.push(bitArray.partial(shift + shift2 & 31, (shift + shift2 > 32) ? carry : out.pop(), 1));
  4945. return out;
  4946. }
  4947. };
  4948. /** @fileOverview Bit array codec implementations.
  4949. *
  4950. * @author Emily Stark
  4951. * @author Mike Hamburg
  4952. * @author Dan Boneh
  4953. */
  4954. /**
  4955. * Arrays of bytes
  4956. * @namespace
  4957. */
  4958. const codec = {
  4959. bytes: {
  4960. /** Convert from a bitArray to an array of bytes. */
  4961. fromBits(arr) {
  4962. const bl = bitArray.bitLength(arr);
  4963. const byteLength = bl / 8;
  4964. const out = new Uint8Array(byteLength);
  4965. let tmp;
  4966. for (let i = 0; i < byteLength; i++) {
  4967. if ((i & 3) === 0) {
  4968. tmp = arr[i / 4];
  4969. }
  4970. out[i] = tmp >>> 24;
  4971. tmp <<= 8;
  4972. }
  4973. return out;
  4974. },
  4975. /** Convert from an array of bytes to a bitArray. */
  4976. toBits(bytes) {
  4977. const out = [];
  4978. let i;
  4979. let tmp = 0;
  4980. for (i = 0; i < bytes.length; i++) {
  4981. tmp = tmp << 8 | bytes[i];
  4982. if ((i & 3) === 3) {
  4983. out.push(tmp);
  4984. tmp = 0;
  4985. }
  4986. }
  4987. if (i & 3) {
  4988. out.push(bitArray.partial(8 * (i & 3), tmp));
  4989. }
  4990. return out;
  4991. }
  4992. }
  4993. };
  4994. const hash = {};
  4995. /**
  4996. * Context for a SHA-1 operation in progress.
  4997. * @constructor
  4998. */
  4999. hash.sha1 = function (hash) {
  5000. if (hash) {
  5001. this._h = hash._h.slice(0);
  5002. this._buffer = hash._buffer.slice(0);
  5003. this._length = hash._length;
  5004. } else {
  5005. this.reset();
  5006. }
  5007. };
  5008. hash.sha1.prototype = {
  5009. /**
  5010. * The hash's block size, in bits.
  5011. * @constant
  5012. */
  5013. blockSize: 512,
  5014. /**
  5015. * Reset the hash state.
  5016. * @return this
  5017. */
  5018. reset: function () {
  5019. const sha1 = this;
  5020. sha1._h = this._init.slice(0);
  5021. sha1._buffer = [];
  5022. sha1._length = 0;
  5023. return sha1;
  5024. },
  5025. /**
  5026. * Input several words to the hash.
  5027. * @param {bitArray|String} data the data to hash.
  5028. * @return this
  5029. */
  5030. update: function (data) {
  5031. const sha1 = this;
  5032. if (typeof data === "string") {
  5033. data = codec.utf8String.toBits(data);
  5034. }
  5035. const b = sha1._buffer = bitArray.concat(sha1._buffer, data);
  5036. const ol = sha1._length;
  5037. const nl = sha1._length = ol + bitArray.bitLength(data);
  5038. if (nl > 9007199254740991) {
  5039. throw new Error("Cannot hash more than 2^53 - 1 bits");
  5040. }
  5041. const c = new Uint32Array(b);
  5042. let j = 0;
  5043. for (let i = sha1.blockSize + ol - ((sha1.blockSize + ol) & (sha1.blockSize - 1)); i <= nl;
  5044. i += sha1.blockSize) {
  5045. sha1._block(c.subarray(16 * j, 16 * (j + 1)));
  5046. j += 1;
  5047. }
  5048. b.splice(0, 16 * j);
  5049. return sha1;
  5050. },
  5051. /**
  5052. * Complete hashing and output the hash value.
  5053. * @return {bitArray} The hash value, an array of 5 big-endian words. TODO
  5054. */
  5055. finalize: function () {
  5056. const sha1 = this;
  5057. let b = sha1._buffer;
  5058. const h = sha1._h;
  5059. // Round out and push the buffer
  5060. b = bitArray.concat(b, [bitArray.partial(1, 1)]);
  5061. // Round out the buffer to a multiple of 16 words, less the 2 length words.
  5062. for (let i = b.length + 2; i & 15; i++) {
  5063. b.push(0);
  5064. }
  5065. // append the length
  5066. b.push(Math.floor(sha1._length / 0x100000000));
  5067. b.push(sha1._length | 0);
  5068. while (b.length) {
  5069. sha1._block(b.splice(0, 16));
  5070. }
  5071. sha1.reset();
  5072. return h;
  5073. },
  5074. /**
  5075. * The SHA-1 initialization vector.
  5076. * @private
  5077. */
  5078. _init: [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0],
  5079. /**
  5080. * The SHA-1 hash key.
  5081. * @private
  5082. */
  5083. _key: [0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6],
  5084. /**
  5085. * The SHA-1 logical functions f(0), f(1), ..., f(79).
  5086. * @private
  5087. */
  5088. _f: function (t, b, c, d) {
  5089. if (t <= 19) {
  5090. return (b & c) | (~b & d);
  5091. } else if (t <= 39) {
  5092. return b ^ c ^ d;
  5093. } else if (t <= 59) {
  5094. return (b & c) | (b & d) | (c & d);
  5095. } else if (t <= 79) {
  5096. return b ^ c ^ d;
  5097. }
  5098. },
  5099. /**
  5100. * Circular left-shift operator.
  5101. * @private
  5102. */
  5103. _S: function (n, x) {
  5104. return (x << n) | (x >>> 32 - n);
  5105. },
  5106. /**
  5107. * Perform one cycle of SHA-1.
  5108. * @param {Uint32Array|bitArray} words one block of words.
  5109. * @private
  5110. */
  5111. _block: function (words) {
  5112. const sha1 = this;
  5113. const h = sha1._h;
  5114. // When words is passed to _block, it has 16 elements. SHA1 _block
  5115. // function extends words with new elements (at the end there are 80 elements).
  5116. // The problem is that if we use Uint32Array instead of Array,
  5117. // the length of Uint32Array cannot be changed. Thus, we replace words with a
  5118. // normal Array here.
  5119. const w = Array(80); // do not use Uint32Array here as the instantiation is slower
  5120. for (let j = 0; j < 16; j++) {
  5121. w[j] = words[j];
  5122. }
  5123. let a = h[0];
  5124. let b = h[1];
  5125. let c = h[2];
  5126. let d = h[3];
  5127. let e = h[4];
  5128. for (let t = 0; t <= 79; t++) {
  5129. if (t >= 16) {
  5130. w[t] = sha1._S(1, w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16]);
  5131. }
  5132. const tmp = (sha1._S(5, a) + sha1._f(t, b, c, d) + e + w[t] +
  5133. sha1._key[Math.floor(t / 20)]) | 0;
  5134. e = d;
  5135. d = c;
  5136. c = sha1._S(30, b);
  5137. b = a;
  5138. a = tmp;
  5139. }
  5140. h[0] = (h[0] + a) | 0;
  5141. h[1] = (h[1] + b) | 0;
  5142. h[2] = (h[2] + c) | 0;
  5143. h[3] = (h[3] + d) | 0;
  5144. h[4] = (h[4] + e) | 0;
  5145. }
  5146. };
  5147. /** @fileOverview Low-level AES implementation.
  5148. *
  5149. * This file contains a low-level implementation of AES, optimized for
  5150. * size and for efficiency on several browsers. It is based on
  5151. * OpenSSL's aes_core.c, a public-domain implementation by Vincent
  5152. * Rijmen, Antoon Bosselaers and Paulo Barreto.
  5153. *
  5154. * An older version of this implementation is available in the public
  5155. * domain, but this one is (c) Emily Stark, Mike Hamburg, Dan Boneh,
  5156. * Stanford University 2008-2010 and BSD-licensed for liability
  5157. * reasons.
  5158. *
  5159. * @author Emily Stark
  5160. * @author Mike Hamburg
  5161. * @author Dan Boneh
  5162. */
  5163. const cipher = {};
  5164. /**
  5165. * Schedule out an AES key for both encryption and decryption. This
  5166. * is a low-level class. Use a cipher mode to do bulk encryption.
  5167. *
  5168. * @constructor
  5169. * @param {Array} key The key as an array of 4, 6 or 8 words.
  5170. */
  5171. cipher.aes = class {
  5172. constructor(key) {
  5173. /**
  5174. * The expanded S-box and inverse S-box tables. These will be computed
  5175. * on the client so that we don't have to send them down the wire.
  5176. *
  5177. * There are two tables, _tables[0] is for encryption and
  5178. * _tables[1] is for decryption.
  5179. *
  5180. * The first 4 sub-tables are the expanded S-box with MixColumns. The
  5181. * last (_tables[01][4]) is the S-box itself.
  5182. *
  5183. * @private
  5184. */
  5185. const aes = this;
  5186. aes._tables = [[[], [], [], [], []], [[], [], [], [], []]];
  5187. if (!aes._tables[0][0][0]) {
  5188. aes._precompute();
  5189. }
  5190. const sbox = aes._tables[0][4];
  5191. const decTable = aes._tables[1];
  5192. const keyLen = key.length;
  5193. let i, encKey, decKey, rcon = 1;
  5194. if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {
  5195. throw new Error("invalid aes key size");
  5196. }
  5197. aes._key = [encKey = key.slice(0), decKey = []];
  5198. // schedule encryption keys
  5199. for (i = keyLen; i < 4 * keyLen + 28; i++) {
  5200. let tmp = encKey[i - 1];
  5201. // apply sbox
  5202. if (i % keyLen === 0 || (keyLen === 8 && i % keyLen === 4)) {
  5203. tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
  5204. // shift rows and add rcon
  5205. if (i % keyLen === 0) {
  5206. tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
  5207. rcon = rcon << 1 ^ (rcon >> 7) * 283;
  5208. }
  5209. }
  5210. encKey[i] = encKey[i - keyLen] ^ tmp;
  5211. }
  5212. // schedule decryption keys
  5213. for (let j = 0; i; j++, i--) {
  5214. const tmp = encKey[j & 3 ? i : i - 4];
  5215. if (i <= 4 || j < 4) {
  5216. decKey[j] = tmp;
  5217. } else {
  5218. decKey[j] = decTable[0][sbox[tmp >>> 24]] ^
  5219. decTable[1][sbox[tmp >> 16 & 255]] ^
  5220. decTable[2][sbox[tmp >> 8 & 255]] ^
  5221. decTable[3][sbox[tmp & 255]];
  5222. }
  5223. }
  5224. }
  5225. // public
  5226. /* Something like this might appear here eventually
  5227. name: "AES",
  5228. blockSize: 4,
  5229. keySizes: [4,6,8],
  5230. */
  5231. /**
  5232. * Encrypt an array of 4 big-endian words.
  5233. * @param {Array} data The plaintext.
  5234. * @return {Array} The ciphertext.
  5235. */
  5236. encrypt(data) {
  5237. return this._crypt(data, 0);
  5238. }
  5239. /**
  5240. * Decrypt an array of 4 big-endian words.
  5241. * @param {Array} data The ciphertext.
  5242. * @return {Array} The plaintext.
  5243. */
  5244. decrypt(data) {
  5245. return this._crypt(data, 1);
  5246. }
  5247. /**
  5248. * Expand the S-box tables.
  5249. *
  5250. * @private
  5251. */
  5252. _precompute() {
  5253. const encTable = this._tables[0];
  5254. const decTable = this._tables[1];
  5255. const sbox = encTable[4];
  5256. const sboxInv = decTable[4];
  5257. const d = [];
  5258. const th = [];
  5259. let xInv, x2, x4, x8;
  5260. // Compute double and third tables
  5261. for (let i = 0; i < 256; i++) {
  5262. th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
  5263. }
  5264. for (let x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
  5265. // Compute sbox
  5266. let s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
  5267. s = s >> 8 ^ s & 255 ^ 99;
  5268. sbox[x] = s;
  5269. sboxInv[s] = x;
  5270. // Compute MixColumns
  5271. x8 = d[x4 = d[x2 = d[x]]];
  5272. let tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
  5273. let tEnc = d[s] * 0x101 ^ s * 0x1010100;
  5274. for (let i = 0; i < 4; i++) {
  5275. encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
  5276. decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
  5277. }
  5278. }
  5279. // Compactify. Considerable speedup on Firefox.
  5280. for (let i = 0; i < 5; i++) {
  5281. encTable[i] = encTable[i].slice(0);
  5282. decTable[i] = decTable[i].slice(0);
  5283. }
  5284. }
  5285. /**
  5286. * Encryption and decryption core.
  5287. * @param {Array} input Four words to be encrypted or decrypted.
  5288. * @param dir The direction, 0 for encrypt and 1 for decrypt.
  5289. * @return {Array} The four encrypted or decrypted words.
  5290. * @private
  5291. */
  5292. _crypt(input, dir) {
  5293. if (input.length !== 4) {
  5294. throw new Error("invalid aes block size");
  5295. }
  5296. const key = this._key[dir];
  5297. const nInnerRounds = key.length / 4 - 2;
  5298. const out = [0, 0, 0, 0];
  5299. const table = this._tables[dir];
  5300. // load up the tables
  5301. const t0 = table[0];
  5302. const t1 = table[1];
  5303. const t2 = table[2];
  5304. const t3 = table[3];
  5305. const sbox = table[4];
  5306. // state variables a,b,c,d are loaded with pre-whitened data
  5307. let a = input[0] ^ key[0];
  5308. let b = input[dir ? 3 : 1] ^ key[1];
  5309. let c = input[2] ^ key[2];
  5310. let d = input[dir ? 1 : 3] ^ key[3];
  5311. let kIndex = 4;
  5312. let a2, b2, c2;
  5313. // Inner rounds. Cribbed from OpenSSL.
  5314. for (let i = 0; i < nInnerRounds; i++) {
  5315. a2 = t0[a >>> 24] ^ t1[b >> 16 & 255] ^ t2[c >> 8 & 255] ^ t3[d & 255] ^ key[kIndex];
  5316. b2 = t0[b >>> 24] ^ t1[c >> 16 & 255] ^ t2[d >> 8 & 255] ^ t3[a & 255] ^ key[kIndex + 1];
  5317. c2 = t0[c >>> 24] ^ t1[d >> 16 & 255] ^ t2[a >> 8 & 255] ^ t3[b & 255] ^ key[kIndex + 2];
  5318. d = t0[d >>> 24] ^ t1[a >> 16 & 255] ^ t2[b >> 8 & 255] ^ t3[c & 255] ^ key[kIndex + 3];
  5319. kIndex += 4;
  5320. a = a2; b = b2; c = c2;
  5321. }
  5322. // Last round.
  5323. for (let i = 0; i < 4; i++) {
  5324. out[dir ? 3 & -i : i] =
  5325. sbox[a >>> 24] << 24 ^
  5326. sbox[b >> 16 & 255] << 16 ^
  5327. sbox[c >> 8 & 255] << 8 ^
  5328. sbox[d & 255] ^
  5329. key[kIndex++];
  5330. a2 = a; a = b; b = c; c = d; d = a2;
  5331. }
  5332. return out;
  5333. }
  5334. };
  5335. /**
  5336. * Random values
  5337. * @namespace
  5338. */
  5339. const random = {
  5340. /**
  5341. * Generate random words with pure js, cryptographically not as strong & safe as native implementation.
  5342. * @param {TypedArray} typedArray The array to fill.
  5343. * @return {TypedArray} The random values.
  5344. */
  5345. getRandomValues(typedArray) {
  5346. const words = new Uint32Array(typedArray.buffer);
  5347. const r = (m_w) => {
  5348. let m_z = 0x3ade68b1;
  5349. const mask = 0xffffffff;
  5350. return function () {
  5351. m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
  5352. m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
  5353. const result = ((((m_z << 0x10) + m_w) & mask) / 0x100000000) + .5;
  5354. return result * (Math.random() > .5 ? 1 : -1);
  5355. };
  5356. };
  5357. for (let i = 0, rcache; i < typedArray.length; i += 4) {
  5358. const _r = r((rcache || Math.random()) * 0x100000000);
  5359. rcache = _r() * 0x3ade67b7;
  5360. words[i / 4] = (_r() * 0x100000000) | 0;
  5361. }
  5362. return typedArray;
  5363. }
  5364. };
  5365. /** @fileOverview CTR mode implementation.
  5366. *
  5367. * Special thanks to Roy Nicholson for pointing out a bug in our
  5368. * implementation.
  5369. *
  5370. * @author Emily Stark
  5371. * @author Mike Hamburg
  5372. * @author Dan Boneh
  5373. */
  5374. /** Brian Gladman's CTR Mode.
  5375. * @constructor
  5376. * @param {Object} _prf The aes instance to generate key.
  5377. * @param {bitArray} _iv The iv for ctr mode, it must be 128 bits.
  5378. */
  5379. const mode = {};
  5380. /**
  5381. * Brian Gladman's CTR Mode.
  5382. * @namespace
  5383. */
  5384. mode.ctrGladman = class {
  5385. constructor(prf, iv) {
  5386. this._prf = prf;
  5387. this._initIv = iv;
  5388. this._iv = iv;
  5389. }
  5390. reset() {
  5391. this._iv = this._initIv;
  5392. }
  5393. /** Input some data to calculate.
  5394. * @param {bitArray} data the data to process, it must be intergral multiple of 128 bits unless it's the last.
  5395. */
  5396. update(data) {
  5397. return this.calculate(this._prf, data, this._iv);
  5398. }
  5399. incWord(word) {
  5400. if (((word >> 24) & 0xff) === 0xff) { //overflow
  5401. let b1 = (word >> 16) & 0xff;
  5402. let b2 = (word >> 8) & 0xff;
  5403. let b3 = word & 0xff;
  5404. if (b1 === 0xff) { // overflow b1
  5405. b1 = 0;
  5406. if (b2 === 0xff) {
  5407. b2 = 0;
  5408. if (b3 === 0xff) {
  5409. b3 = 0;
  5410. } else {
  5411. ++b3;
  5412. }
  5413. } else {
  5414. ++b2;
  5415. }
  5416. } else {
  5417. ++b1;
  5418. }
  5419. word = 0;
  5420. word += (b1 << 16);
  5421. word += (b2 << 8);
  5422. word += b3;
  5423. } else {
  5424. word += (0x01 << 24);
  5425. }
  5426. return word;
  5427. }
  5428. incCounter(counter) {
  5429. if ((counter[0] = this.incWord(counter[0])) === 0) {
  5430. // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
  5431. counter[1] = this.incWord(counter[1]);
  5432. }
  5433. }
  5434. calculate(prf, data, iv) {
  5435. let l;
  5436. if (!(l = data.length)) {
  5437. return [];
  5438. }
  5439. const bl = bitArray.bitLength(data);
  5440. for (let i = 0; i < l; i += 4) {
  5441. this.incCounter(iv);
  5442. const e = prf.encrypt(iv);
  5443. data[i] ^= e[0];
  5444. data[i + 1] ^= e[1];
  5445. data[i + 2] ^= e[2];
  5446. data[i + 3] ^= e[3];
  5447. }
  5448. return bitArray.clamp(data, bl);
  5449. }
  5450. };
  5451. const misc = {
  5452. importKey(password) {
  5453. return new misc.hmacSha1(codec.bytes.toBits(password));
  5454. },
  5455. pbkdf2(prf, salt, count, length) {
  5456. count = count || 10000;
  5457. if (length < 0 || count < 0) {
  5458. throw new Error("invalid params to pbkdf2");
  5459. }
  5460. const byteLength = ((length >> 5) + 1) << 2;
  5461. let u, ui, i, j, k;
  5462. const arrayBuffer = new ArrayBuffer(byteLength);
  5463. const out = new DataView(arrayBuffer);
  5464. let outLength = 0;
  5465. const b = bitArray;
  5466. salt = codec.bytes.toBits(salt);
  5467. for (k = 1; outLength < (byteLength || 1); k++) {
  5468. u = ui = prf.encrypt(b.concat(salt, [k]));
  5469. for (i = 1; i < count; i++) {
  5470. ui = prf.encrypt(ui);
  5471. for (j = 0; j < ui.length; j++) {
  5472. u[j] ^= ui[j];
  5473. }
  5474. }
  5475. for (i = 0; outLength < (byteLength || 1) && i < u.length; i++) {
  5476. out.setInt32(outLength, u[i]);
  5477. outLength += 4;
  5478. }
  5479. }
  5480. return arrayBuffer.slice(0, length / 8);
  5481. }
  5482. };
  5483. /** @fileOverview HMAC implementation.
  5484. *
  5485. * @author Emily Stark
  5486. * @author Mike Hamburg
  5487. * @author Dan Boneh
  5488. */
  5489. /** HMAC with the specified hash function.
  5490. * @constructor
  5491. * @param {bitArray} key the key for HMAC.
  5492. * @param {Object} [Hash=hash.sha1] The hash function to use.
  5493. */
  5494. misc.hmacSha1 = class {
  5495. constructor(key) {
  5496. const hmac = this;
  5497. const Hash = hmac._hash = hash.sha1;
  5498. const exKey = [[], []];
  5499. const bs = Hash.prototype.blockSize / 32;
  5500. hmac._baseHash = [new Hash(), new Hash()];
  5501. if (key.length > bs) {
  5502. key = Hash.hash(key);
  5503. }
  5504. for (let i = 0; i < bs; i++) {
  5505. exKey[0][i] = key[i] ^ 0x36363636;
  5506. exKey[1][i] = key[i] ^ 0x5C5C5C5C;
  5507. }
  5508. hmac._baseHash[0].update(exKey[0]);
  5509. hmac._baseHash[1].update(exKey[1]);
  5510. hmac._resultHash = new Hash(hmac._baseHash[0]);
  5511. }
  5512. reset() {
  5513. const hmac = this;
  5514. hmac._resultHash = new hmac._hash(hmac._baseHash[0]);
  5515. hmac._updated = false;
  5516. }
  5517. update(data) {
  5518. const hmac = this;
  5519. hmac._updated = true;
  5520. hmac._resultHash.update(data);
  5521. }
  5522. digest() {
  5523. const hmac = this;
  5524. const w = hmac._resultHash.finalize();
  5525. const result = new (hmac._hash)(hmac._baseHash[1]).update(w).finalize();
  5526. hmac.reset();
  5527. return result;
  5528. }
  5529. encrypt(data) {
  5530. if (!this._updated) {
  5531. this.update(data);
  5532. return this.digest(data);
  5533. } else {
  5534. throw new Error("encrypt on already updated hmac called!");
  5535. }
  5536. }
  5537. };
  5538. /*
  5539. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  5540. Redistribution and use in source and binary forms, with or without
  5541. modification, are permitted provided that the following conditions are met:
  5542. 1. Redistributions of source code must retain the above copyright notice,
  5543. this list of conditions and the following disclaimer.
  5544. 2. Redistributions in binary form must reproduce the above copyright
  5545. notice, this list of conditions and the following disclaimer in
  5546. the documentation and/or other materials provided with the distribution.
  5547. 3. The names of the authors may not be used to endorse or promote products
  5548. derived from this software without specific prior written permission.
  5549. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  5550. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  5551. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  5552. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  5553. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5554. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  5555. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5556. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5557. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5558. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5559. */
  5560. const ERR_INVALID_PASSWORD = "Invalid pasword";
  5561. const BLOCK_LENGTH = 16;
  5562. const RAW_FORMAT = "raw";
  5563. const PBKDF2_ALGORITHM = { name: "PBKDF2" };
  5564. const HASH_ALGORITHM = { name: "HMAC" };
  5565. const HASH_FUNCTION = "SHA-1";
  5566. const BASE_KEY_ALGORITHM = Object.assign({ hash: HASH_ALGORITHM }, PBKDF2_ALGORITHM);
  5567. const DERIVED_BITS_ALGORITHM = Object.assign({ iterations: 1000, hash: { name: HASH_FUNCTION } }, PBKDF2_ALGORITHM);
  5568. const DERIVED_BITS_USAGE = ["deriveBits"];
  5569. const SALT_LENGTH = [8, 12, 16];
  5570. const KEY_LENGTH = [16, 24, 32];
  5571. const SIGNATURE_LENGTH = 10;
  5572. const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];
  5573. const CRYPTO_API_SUPPORTED = typeof crypto != "undefined";
  5574. const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof crypto.subtle != "undefined";
  5575. const codecBytes = codec.bytes;
  5576. const Aes = cipher.aes;
  5577. const CtrGladman = mode.ctrGladman;
  5578. const HmacSha1 = misc.hmacSha1;
  5579. class AESDecrypt {
  5580. constructor(password, signed, strength) {
  5581. Object.assign(this, {
  5582. password,
  5583. signed,
  5584. strength: strength - 1,
  5585. pendingInput: new Uint8Array(0)
  5586. });
  5587. }
  5588. async append(input) {
  5589. const aesCrypto = this;
  5590. if (aesCrypto.password) {
  5591. const preamble = subarray(input, 0, SALT_LENGTH[aesCrypto.strength] + 2);
  5592. await createDecryptionKeys(aesCrypto, preamble, aesCrypto.password);
  5593. aesCrypto.password = null;
  5594. aesCrypto.aesCtrGladman = new CtrGladman(new Aes(aesCrypto.keys.key), Array.from(COUNTER_DEFAULT_VALUE));
  5595. aesCrypto.hmac = new HmacSha1(aesCrypto.keys.authentication);
  5596. input = subarray(input, SALT_LENGTH[aesCrypto.strength] + 2);
  5597. }
  5598. const output = new Uint8Array(input.length - SIGNATURE_LENGTH - ((input.length - SIGNATURE_LENGTH) % BLOCK_LENGTH));
  5599. return append(aesCrypto, input, output, 0, SIGNATURE_LENGTH, true);
  5600. }
  5601. flush() {
  5602. const aesCrypto = this;
  5603. const pendingInput = aesCrypto.pendingInput;
  5604. const chunkToDecrypt = subarray(pendingInput, 0, pendingInput.length - SIGNATURE_LENGTH);
  5605. const originalSignature = subarray(pendingInput, pendingInput.length - SIGNATURE_LENGTH);
  5606. let decryptedChunkArray = new Uint8Array(0);
  5607. if (chunkToDecrypt.length) {
  5608. const encryptedChunk = codecBytes.toBits(chunkToDecrypt);
  5609. aesCrypto.hmac.update(encryptedChunk);
  5610. const decryptedChunk = aesCrypto.aesCtrGladman.update(encryptedChunk);
  5611. decryptedChunkArray = codecBytes.fromBits(decryptedChunk);
  5612. }
  5613. let valid = true;
  5614. if (aesCrypto.signed) {
  5615. const signature = subarray(codecBytes.fromBits(aesCrypto.hmac.digest()), 0, SIGNATURE_LENGTH);
  5616. for (let indexSignature = 0; indexSignature < SIGNATURE_LENGTH; indexSignature++) {
  5617. if (signature[indexSignature] != originalSignature[indexSignature]) {
  5618. valid = false;
  5619. }
  5620. }
  5621. }
  5622. return {
  5623. valid,
  5624. data: decryptedChunkArray
  5625. };
  5626. }
  5627. }
  5628. class AESEncrypt {
  5629. constructor(password, strength) {
  5630. Object.assign(this, {
  5631. password,
  5632. strength: strength - 1,
  5633. pendingInput: new Uint8Array(0)
  5634. });
  5635. }
  5636. async append(input) {
  5637. const aesCrypto = this;
  5638. let preamble = new Uint8Array(0);
  5639. if (aesCrypto.password) {
  5640. preamble = await createEncryptionKeys(aesCrypto, aesCrypto.password);
  5641. aesCrypto.password = null;
  5642. aesCrypto.aesCtrGladman = new CtrGladman(new Aes(aesCrypto.keys.key), Array.from(COUNTER_DEFAULT_VALUE));
  5643. aesCrypto.hmac = new HmacSha1(aesCrypto.keys.authentication);
  5644. }
  5645. const output = new Uint8Array(preamble.length + input.length - (input.length % BLOCK_LENGTH));
  5646. output.set(preamble, 0);
  5647. return append(aesCrypto, input, output, preamble.length, 0);
  5648. }
  5649. flush() {
  5650. const aesCrypto = this;
  5651. let encryptedChunkArray = new Uint8Array(0);
  5652. if (aesCrypto.pendingInput.length) {
  5653. const encryptedChunk = aesCrypto.aesCtrGladman.update(codecBytes.toBits(aesCrypto.pendingInput));
  5654. aesCrypto.hmac.update(encryptedChunk);
  5655. encryptedChunkArray = codecBytes.fromBits(encryptedChunk);
  5656. }
  5657. const signature = subarray(codecBytes.fromBits(aesCrypto.hmac.digest()), 0, SIGNATURE_LENGTH);
  5658. return {
  5659. data: concat(encryptedChunkArray, signature),
  5660. signature
  5661. };
  5662. }
  5663. }
  5664. function append(aesCrypto, input, output, paddingStart, paddingEnd, verifySignature) {
  5665. const inputLength = input.length - paddingEnd;
  5666. if (aesCrypto.pendingInput.length) {
  5667. input = concat(aesCrypto.pendingInput, input);
  5668. output = expand(output, inputLength - (inputLength % BLOCK_LENGTH));
  5669. }
  5670. let offset;
  5671. for (offset = 0; offset <= inputLength - BLOCK_LENGTH; offset += BLOCK_LENGTH) {
  5672. const inputChunk = codecBytes.toBits(subarray(input, offset, offset + BLOCK_LENGTH));
  5673. if (verifySignature) {
  5674. aesCrypto.hmac.update(inputChunk);
  5675. }
  5676. const outputChunk = aesCrypto.aesCtrGladman.update(inputChunk);
  5677. if (!verifySignature) {
  5678. aesCrypto.hmac.update(outputChunk);
  5679. }
  5680. output.set(codecBytes.fromBits(outputChunk), offset + paddingStart);
  5681. }
  5682. aesCrypto.pendingInput = subarray(input, offset);
  5683. return output;
  5684. }
  5685. async function createDecryptionKeys(decrypt, preambleArray, password) {
  5686. await createKeys$1(decrypt, password, subarray(preambleArray, 0, SALT_LENGTH[decrypt.strength]));
  5687. const passwordVerification = subarray(preambleArray, SALT_LENGTH[decrypt.strength]);
  5688. const passwordVerificationKey = decrypt.keys.passwordVerification;
  5689. if (passwordVerificationKey[0] != passwordVerification[0] || passwordVerificationKey[1] != passwordVerification[1]) {
  5690. throw new Error(ERR_INVALID_PASSWORD);
  5691. }
  5692. }
  5693. async function createEncryptionKeys(encrypt, password) {
  5694. const salt = getRandomValues(new Uint8Array(SALT_LENGTH[encrypt.strength]));
  5695. await createKeys$1(encrypt, password, salt);
  5696. return concat(salt, encrypt.keys.passwordVerification);
  5697. }
  5698. async function createKeys$1(target, password, salt) {
  5699. const encodedPassword = encodeText(password);
  5700. const basekey = await importKey(RAW_FORMAT, encodedPassword, BASE_KEY_ALGORITHM, false, DERIVED_BITS_USAGE);
  5701. const derivedBits = await deriveBits(Object.assign({ salt }, DERIVED_BITS_ALGORITHM), basekey, 8 * ((KEY_LENGTH[target.strength] * 2) + 2));
  5702. const compositeKey = new Uint8Array(derivedBits);
  5703. target.keys = {
  5704. key: codecBytes.toBits(subarray(compositeKey, 0, KEY_LENGTH[target.strength])),
  5705. authentication: codecBytes.toBits(subarray(compositeKey, KEY_LENGTH[target.strength], KEY_LENGTH[target.strength] * 2)),
  5706. passwordVerification: subarray(compositeKey, KEY_LENGTH[target.strength] * 2)
  5707. };
  5708. }
  5709. function getRandomValues(array) {
  5710. if (CRYPTO_API_SUPPORTED && typeof crypto.getRandomValues == "function") {
  5711. return crypto.getRandomValues(array);
  5712. } else {
  5713. return random.getRandomValues(array);
  5714. }
  5715. }
  5716. function importKey(format, password, algorithm, extractable, keyUsages) {
  5717. if (CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof crypto.subtle.importKey == "function") {
  5718. return crypto.subtle.importKey(format, password, algorithm, extractable, keyUsages);
  5719. } else {
  5720. return misc.importKey(password);
  5721. }
  5722. }
  5723. async function deriveBits(algorithm, baseKey, length) {
  5724. if (CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof crypto.subtle.deriveBits == "function") {
  5725. return await crypto.subtle.deriveBits(algorithm, baseKey, length);
  5726. } else {
  5727. return misc.pbkdf2(baseKey, algorithm.salt, DERIVED_BITS_ALGORITHM.iterations, length);
  5728. }
  5729. }
  5730. function concat(leftArray, rightArray) {
  5731. let array = leftArray;
  5732. if (leftArray.length + rightArray.length) {
  5733. array = new Uint8Array(leftArray.length + rightArray.length);
  5734. array.set(leftArray, 0);
  5735. array.set(rightArray, leftArray.length);
  5736. }
  5737. return array;
  5738. }
  5739. function expand(inputArray, length) {
  5740. if (length && length > inputArray.length) {
  5741. const array = inputArray;
  5742. inputArray = new Uint8Array(length);
  5743. inputArray.set(array, 0);
  5744. }
  5745. return inputArray;
  5746. }
  5747. function subarray(array, begin, end) {
  5748. return array.subarray(begin, end);
  5749. }
  5750. /*
  5751. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  5752. Redistribution and use in source and binary forms, with or without
  5753. modification, are permitted provided that the following conditions are met:
  5754. 1. Redistributions of source code must retain the above copyright notice,
  5755. this list of conditions and the following disclaimer.
  5756. 2. Redistributions in binary form must reproduce the above copyright
  5757. notice, this list of conditions and the following disclaimer in
  5758. the documentation and/or other materials provided with the distribution.
  5759. 3. The names of the authors may not be used to endorse or promote products
  5760. derived from this software without specific prior written permission.
  5761. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  5762. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  5763. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  5764. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  5765. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5766. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  5767. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5768. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5769. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5770. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5771. */
  5772. const HEADER_LENGTH = 12;
  5773. class ZipCryptoDecrypt {
  5774. constructor(password, passwordVerification) {
  5775. const zipCrypto = this;
  5776. Object.assign(zipCrypto, {
  5777. password,
  5778. passwordVerification
  5779. });
  5780. createKeys(zipCrypto, password);
  5781. }
  5782. append(input) {
  5783. const zipCrypto = this;
  5784. if (zipCrypto.password) {
  5785. const decryptedHeader = decrypt(zipCrypto, input.subarray(0, HEADER_LENGTH));
  5786. zipCrypto.password = null;
  5787. if (decryptedHeader[HEADER_LENGTH - 1] != zipCrypto.passwordVerification) {
  5788. throw new Error(ERR_INVALID_PASSWORD);
  5789. }
  5790. input = input.subarray(HEADER_LENGTH);
  5791. }
  5792. return decrypt(zipCrypto, input);
  5793. }
  5794. flush() {
  5795. return {
  5796. valid: true,
  5797. data: new Uint8Array(0)
  5798. };
  5799. }
  5800. }
  5801. class ZipCryptoEncrypt {
  5802. constructor(password, passwordVerification) {
  5803. const zipCrypto = this;
  5804. Object.assign(zipCrypto, {
  5805. password,
  5806. passwordVerification
  5807. });
  5808. createKeys(zipCrypto, password);
  5809. }
  5810. append(input) {
  5811. const zipCrypto = this;
  5812. let output;
  5813. let offset;
  5814. if (zipCrypto.password) {
  5815. zipCrypto.password = null;
  5816. const header = crypto.getRandomValues(new Uint8Array(HEADER_LENGTH));
  5817. header[HEADER_LENGTH - 1] = zipCrypto.passwordVerification;
  5818. output = new Uint8Array(input.length + header.length);
  5819. output.set(encrypt(zipCrypto, header), 0);
  5820. offset = HEADER_LENGTH;
  5821. } else {
  5822. output = new Uint8Array(input.length);
  5823. offset = 0;
  5824. }
  5825. output.set(encrypt(zipCrypto, input), offset);
  5826. return output;
  5827. }
  5828. flush() {
  5829. return {
  5830. data: new Uint8Array(0)
  5831. };
  5832. }
  5833. }
  5834. function decrypt(target, input) {
  5835. const output = new Uint8Array(input.length);
  5836. for (let index = 0; index < input.length; index++) {
  5837. output[index] = getByte(target) ^ input[index];
  5838. updateKeys(target, output[index]);
  5839. }
  5840. return output;
  5841. }
  5842. function encrypt(target, input) {
  5843. const output = new Uint8Array(input.length);
  5844. for (let index = 0; index < input.length; index++) {
  5845. output[index] = getByte(target) ^ input[index];
  5846. updateKeys(target, input[index]);
  5847. }
  5848. return output;
  5849. }
  5850. function createKeys(target, password) {
  5851. target.keys = [0x12345678, 0x23456789, 0x34567890];
  5852. target.crcKey0 = new Crc32(target.keys[0]);
  5853. target.crcKey2 = new Crc32(target.keys[2]);
  5854. for (let index = 0; index < password.length; index++) {
  5855. updateKeys(target, password.charCodeAt(index));
  5856. }
  5857. }
  5858. function updateKeys(target, byte) {
  5859. target.crcKey0.append([byte]);
  5860. target.keys[0] = ~target.crcKey0.get();
  5861. target.keys[1] = getInt32(target.keys[1] + getInt8(target.keys[0]));
  5862. target.keys[1] = getInt32(Math.imul(target.keys[1], 134775813) + 1);
  5863. target.crcKey2.append([target.keys[1] >>> 24]);
  5864. target.keys[2] = ~target.crcKey2.get();
  5865. }
  5866. function getByte(target) {
  5867. const temp = target.keys[2] | 2;
  5868. return getInt8(Math.imul(temp, (temp ^ 1)) >>> 8);
  5869. }
  5870. function getInt8(number) {
  5871. return number & 0xFF;
  5872. }
  5873. function getInt32(number) {
  5874. return number & 0xFFFFFFFF;
  5875. }
  5876. /*
  5877. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  5878. Redistribution and use in source and binary forms, with or without
  5879. modification, are permitted provided that the following conditions are met:
  5880. 1. Redistributions of source code must retain the above copyright notice,
  5881. this list of conditions and the following disclaimer.
  5882. 2. Redistributions in binary form must reproduce the above copyright
  5883. notice, this list of conditions and the following disclaimer in
  5884. the documentation and/or other materials provided with the distribution.
  5885. 3. The names of the authors may not be used to endorse or promote products
  5886. derived from this software without specific prior written permission.
  5887. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  5888. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  5889. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  5890. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  5891. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  5892. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  5893. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  5894. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  5895. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  5896. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5897. */
  5898. const CODEC_DEFLATE = "deflate";
  5899. const CODEC_INFLATE = "inflate";
  5900. const ERR_INVALID_SIGNATURE = "Invalid signature";
  5901. class Inflate {
  5902. constructor(codecConstructor, {
  5903. signature,
  5904. password,
  5905. signed,
  5906. compressed,
  5907. zipCrypto,
  5908. passwordVerification,
  5909. encryptionStrength
  5910. }, { chunkSize }) {
  5911. const encrypted = Boolean(password);
  5912. Object.assign(this, {
  5913. signature,
  5914. encrypted,
  5915. signed,
  5916. compressed,
  5917. inflate: compressed && new codecConstructor({ chunkSize }),
  5918. crc32: signed && new Crc32(),
  5919. zipCrypto,
  5920. decrypt: encrypted && zipCrypto ?
  5921. new ZipCryptoDecrypt(password, passwordVerification) :
  5922. new AESDecrypt(password, signed, encryptionStrength)
  5923. });
  5924. }
  5925. async append(data) {
  5926. const codec = this;
  5927. if (codec.encrypted && data.length) {
  5928. data = await codec.decrypt.append(data);
  5929. }
  5930. if (codec.compressed && data.length) {
  5931. data = await codec.inflate.append(data);
  5932. }
  5933. if ((!codec.encrypted || codec.zipCrypto) && codec.signed && data.length) {
  5934. codec.crc32.append(data);
  5935. }
  5936. return data;
  5937. }
  5938. async flush() {
  5939. const codec = this;
  5940. let signature;
  5941. let data = new Uint8Array(0);
  5942. if (codec.encrypted) {
  5943. const result = codec.decrypt.flush();
  5944. if (!result.valid) {
  5945. throw new Error(ERR_INVALID_SIGNATURE);
  5946. }
  5947. data = result.data;
  5948. }
  5949. if ((!codec.encrypted || codec.zipCrypto) && codec.signed) {
  5950. const dataViewSignature = new DataView(new Uint8Array(4).buffer);
  5951. signature = codec.crc32.get();
  5952. dataViewSignature.setUint32(0, signature);
  5953. if (codec.signature != dataViewSignature.getUint32(0, false)) {
  5954. throw new Error(ERR_INVALID_SIGNATURE);
  5955. }
  5956. }
  5957. if (codec.compressed) {
  5958. data = (await codec.inflate.append(data)) || new Uint8Array(0);
  5959. await codec.inflate.flush();
  5960. }
  5961. return { data, signature };
  5962. }
  5963. }
  5964. class Deflate {
  5965. constructor(codecConstructor, {
  5966. encrypted,
  5967. signed,
  5968. compressed,
  5969. level,
  5970. zipCrypto,
  5971. password,
  5972. passwordVerification,
  5973. encryptionStrength
  5974. }, { chunkSize }) {
  5975. Object.assign(this, {
  5976. encrypted,
  5977. signed,
  5978. compressed,
  5979. deflate: compressed && new codecConstructor({ level: level || 5, chunkSize }),
  5980. crc32: signed && new Crc32(),
  5981. zipCrypto,
  5982. encrypt: encrypted && zipCrypto ?
  5983. new ZipCryptoEncrypt(password, passwordVerification) :
  5984. new AESEncrypt(password, encryptionStrength)
  5985. });
  5986. }
  5987. async append(inputData) {
  5988. const codec = this;
  5989. let data = inputData;
  5990. if (codec.compressed && inputData.length) {
  5991. data = await codec.deflate.append(inputData);
  5992. }
  5993. if (codec.encrypted && data.length) {
  5994. data = await codec.encrypt.append(data);
  5995. }
  5996. if ((!codec.encrypted || codec.zipCrypto) && codec.signed && inputData.length) {
  5997. codec.crc32.append(inputData);
  5998. }
  5999. return data;
  6000. }
  6001. async flush() {
  6002. const codec = this;
  6003. let signature;
  6004. let data = new Uint8Array(0);
  6005. if (codec.compressed) {
  6006. data = (await codec.deflate.flush()) || new Uint8Array(0);
  6007. }
  6008. if (codec.encrypted) {
  6009. data = await codec.encrypt.append(data);
  6010. const result = codec.encrypt.flush();
  6011. signature = result.signature;
  6012. const newData = new Uint8Array(data.length + result.data.length);
  6013. newData.set(data, 0);
  6014. newData.set(result.data, data.length);
  6015. data = newData;
  6016. }
  6017. if ((!codec.encrypted || codec.zipCrypto) && codec.signed) {
  6018. signature = codec.crc32.get();
  6019. }
  6020. return { data, signature };
  6021. }
  6022. }
  6023. function createCodec$1(codecConstructor, options, config) {
  6024. if (options.codecType.startsWith(CODEC_DEFLATE)) {
  6025. return new Deflate(codecConstructor, options, config);
  6026. } else if (options.codecType.startsWith(CODEC_INFLATE)) {
  6027. return new Inflate(codecConstructor, options, config);
  6028. }
  6029. }
  6030. /*
  6031. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  6032. Redistribution and use in source and binary forms, with or without
  6033. modification, are permitted provided that the following conditions are met:
  6034. 1. Redistributions of source code must retain the above copyright notice,
  6035. this list of conditions and the following disclaimer.
  6036. 2. Redistributions in binary form must reproduce the above copyright
  6037. notice, this list of conditions and the following disclaimer in
  6038. the documentation and/or other materials provided with the distribution.
  6039. 3. The names of the authors may not be used to endorse or promote products
  6040. derived from this software without specific prior written permission.
  6041. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  6042. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  6043. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  6044. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  6045. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6046. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  6047. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6048. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6049. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6050. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6051. */
  6052. const MESSAGE_INIT = "init";
  6053. const MESSAGE_APPEND = "append";
  6054. const MESSAGE_FLUSH = "flush";
  6055. const MESSAGE_EVENT_TYPE = "message";
  6056. let classicWorkersSupported = true;
  6057. var getWorker = (workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts) => {
  6058. Object.assign(workerData, {
  6059. busy: true,
  6060. codecConstructor,
  6061. options: Object.assign({}, options),
  6062. scripts,
  6063. terminate() {
  6064. if (workerData.worker && !workerData.busy) {
  6065. workerData.worker.terminate();
  6066. workerData.interface = null;
  6067. }
  6068. },
  6069. onTaskFinished() {
  6070. workerData.busy = false;
  6071. onTaskFinished(workerData);
  6072. }
  6073. });
  6074. return webWorker ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);
  6075. };
  6076. function createWorkerInterface(workerData, config) {
  6077. const interfaceCodec = createCodec$1(workerData.codecConstructor, workerData.options, config);
  6078. return {
  6079. async append(data) {
  6080. try {
  6081. return await interfaceCodec.append(data);
  6082. } catch (error) {
  6083. workerData.onTaskFinished();
  6084. throw error;
  6085. }
  6086. },
  6087. async flush() {
  6088. try {
  6089. return await interfaceCodec.flush();
  6090. } finally {
  6091. workerData.onTaskFinished();
  6092. }
  6093. },
  6094. abort() {
  6095. workerData.onTaskFinished();
  6096. }
  6097. };
  6098. }
  6099. function createWebWorkerInterface(workerData, config) {
  6100. let messageTask;
  6101. const workerOptions = { type: "module" };
  6102. if (!workerData.interface) {
  6103. if (!classicWorkersSupported) {
  6104. workerData.worker = getWorker(workerOptions, config.baseURL);
  6105. } else {
  6106. try {
  6107. workerData.worker = getWorker({}, config.baseURL);
  6108. } catch (_error) {
  6109. classicWorkersSupported = false;
  6110. workerData.worker = getWorker(workerOptions, config.baseURL);
  6111. }
  6112. }
  6113. workerData.worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false);
  6114. workerData.interface = {
  6115. append(data) {
  6116. return initAndSendMessage({ type: MESSAGE_APPEND, data });
  6117. },
  6118. flush() {
  6119. return initAndSendMessage({ type: MESSAGE_FLUSH });
  6120. },
  6121. abort() {
  6122. workerData.onTaskFinished();
  6123. }
  6124. };
  6125. }
  6126. return workerData.interface;
  6127. function getWorker(options, baseURL) {
  6128. let url, scriptUrl;
  6129. url = workerData.scripts[0];
  6130. if (typeof url == "function") {
  6131. url = url();
  6132. }
  6133. try {
  6134. scriptUrl = new URL(url, baseURL);
  6135. } catch (_error) {
  6136. scriptUrl = url;
  6137. }
  6138. return new Worker(scriptUrl, options);
  6139. }
  6140. async function initAndSendMessage(message) {
  6141. if (!messageTask) {
  6142. const options = workerData.options;
  6143. const scripts = workerData.scripts.slice(1);
  6144. await sendMessage({ scripts, type: MESSAGE_INIT, options, config: { chunkSize: config.chunkSize } });
  6145. }
  6146. return sendMessage(message);
  6147. }
  6148. function sendMessage(message) {
  6149. const worker = workerData.worker;
  6150. const result = new Promise((resolve, reject) => messageTask = { resolve, reject });
  6151. try {
  6152. if (message.data) {
  6153. try {
  6154. message.data = message.data.buffer;
  6155. worker.postMessage(message, [message.data]);
  6156. } catch (_error) {
  6157. worker.postMessage(message);
  6158. }
  6159. } else {
  6160. worker.postMessage(message);
  6161. }
  6162. } catch (error) {
  6163. messageTask.reject(error);
  6164. messageTask = null;
  6165. workerData.onTaskFinished();
  6166. }
  6167. return result;
  6168. }
  6169. function onMessage(event) {
  6170. const message = event.data;
  6171. if (messageTask) {
  6172. const reponseError = message.error;
  6173. const type = message.type;
  6174. if (reponseError) {
  6175. const error = new Error(reponseError.message);
  6176. error.stack = reponseError.stack;
  6177. messageTask.reject(error);
  6178. messageTask = null;
  6179. workerData.onTaskFinished();
  6180. } else if (type == MESSAGE_INIT || type == MESSAGE_FLUSH || type == MESSAGE_APPEND) {
  6181. const data = message.data;
  6182. if (type == MESSAGE_FLUSH) {
  6183. messageTask.resolve({ data: new Uint8Array(data), signature: message.signature });
  6184. messageTask = null;
  6185. workerData.onTaskFinished();
  6186. } else {
  6187. messageTask.resolve(data && new Uint8Array(data));
  6188. }
  6189. }
  6190. }
  6191. }
  6192. }
  6193. /*
  6194. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  6195. Redistribution and use in source and binary forms, with or without
  6196. modification, are permitted provided that the following conditions are met:
  6197. 1. Redistributions of source code must retain the above copyright notice,
  6198. this list of conditions and the following disclaimer.
  6199. 2. Redistributions in binary form must reproduce the above copyright
  6200. notice, this list of conditions and the following disclaimer in
  6201. the documentation and/or other materials provided with the distribution.
  6202. 3. The names of the authors may not be used to endorse or promote products
  6203. derived from this software without specific prior written permission.
  6204. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  6205. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  6206. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  6207. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  6208. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6209. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  6210. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6211. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6212. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6213. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6214. */
  6215. let pool = [];
  6216. const pendingRequests = [];
  6217. function createCodec(codecConstructor, options, config) {
  6218. const streamCopy = !options.compressed && !options.signed && !options.encrypted;
  6219. const webWorker = !streamCopy && (options.useWebWorkers || (options.useWebWorkers === undefined && config.useWebWorkers));
  6220. const scripts = webWorker && config.workerScripts ? config.workerScripts[options.codecType] : [];
  6221. if (pool.length < config.maxWorkers) {
  6222. const workerData = {};
  6223. pool.push(workerData);
  6224. return getWorker(workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts);
  6225. } else {
  6226. const workerData = pool.find(workerData => !workerData.busy);
  6227. if (workerData) {
  6228. clearTerminateTimeout(workerData);
  6229. return getWorker(workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts);
  6230. } else {
  6231. return new Promise(resolve => pendingRequests.push({ resolve, codecConstructor, options, webWorker, scripts }));
  6232. }
  6233. }
  6234. function onTaskFinished(workerData) {
  6235. if (pendingRequests.length) {
  6236. const [{ resolve, codecConstructor, options, webWorker, scripts }] = pendingRequests.splice(0, 1);
  6237. resolve(getWorker(workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts));
  6238. } else if (workerData.worker) {
  6239. clearTerminateTimeout(workerData);
  6240. if (Number.isFinite(config.terminateWorkerTimeout) && config.terminateWorkerTimeout >= 0) {
  6241. workerData.terminateTimeout = setTimeout(() => {
  6242. pool = pool.filter(data => data != workerData);
  6243. workerData.terminate();
  6244. }, config.terminateWorkerTimeout);
  6245. }
  6246. } else {
  6247. pool = pool.filter(data => data != workerData);
  6248. }
  6249. }
  6250. }
  6251. function clearTerminateTimeout(workerData) {
  6252. if (workerData.terminateTimeout) {
  6253. clearTimeout(workerData.terminateTimeout);
  6254. workerData.terminateTimeout = null;
  6255. }
  6256. }
  6257. function terminateWorkers() {
  6258. pool.forEach(workerData => {
  6259. clearTerminateTimeout(workerData);
  6260. workerData.terminate();
  6261. });
  6262. }
  6263. 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]}});}};
  6264. /*
  6265. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  6266. Redistribution and use in source and binary forms, with or without
  6267. modification, are permitted provided that the following conditions are met:
  6268. 1. Redistributions of source code must retain the above copyright notice,
  6269. this list of conditions and the following disclaimer.
  6270. 2. Redistributions in binary form must reproduce the above copyright
  6271. notice, this list of conditions and the following disclaimer in
  6272. the documentation and/or other materials provided with the distribution.
  6273. 3. The names of the authors may not be used to endorse or promote products
  6274. derived from this software without specific prior written permission.
  6275. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  6276. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  6277. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  6278. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  6279. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6280. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  6281. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6282. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6283. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6284. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6285. */
  6286. var streamCodecShim = (library, options = {}, registerDataHandler) => {
  6287. return {
  6288. Deflate: createCodecClass(library.Deflate, options.deflate, registerDataHandler),
  6289. Inflate: createCodecClass(library.Inflate, options.inflate, registerDataHandler)
  6290. };
  6291. };
  6292. function createCodecClass(constructor, constructorOptions, registerDataHandler) {
  6293. return class {
  6294. constructor(options) {
  6295. const codecAdapter = this;
  6296. const onData = data => {
  6297. if (codecAdapter.pendingData) {
  6298. const pendingData = codecAdapter.pendingData;
  6299. codecAdapter.pendingData = new Uint8Array(pendingData.length + data.length);
  6300. codecAdapter.pendingData.set(pendingData, 0);
  6301. codecAdapter.pendingData.set(data, pendingData.length);
  6302. } else {
  6303. codecAdapter.pendingData = new Uint8Array(data);
  6304. }
  6305. };
  6306. codecAdapter.codec = new constructor(Object.assign({}, constructorOptions, options));
  6307. registerDataHandler(codecAdapter.codec, onData);
  6308. }
  6309. append(data) {
  6310. this.codec.push(data);
  6311. return getResponse(this);
  6312. }
  6313. flush() {
  6314. this.codec.push(new Uint8Array(0), true);
  6315. return getResponse(this);
  6316. }
  6317. };
  6318. function getResponse(codec) {
  6319. if (codec.pendingData) {
  6320. const output = codec.pendingData;
  6321. codec.pendingData = null;
  6322. return output;
  6323. } else {
  6324. return new Uint8Array(0);
  6325. }
  6326. }
  6327. }
  6328. /*
  6329. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  6330. Redistribution and use in source and binary forms, with or without
  6331. modification, are permitted provided that the following conditions are met:
  6332. 1. Redistributions of source code must retain the above copyright notice,
  6333. this list of conditions and the following disclaimer.
  6334. 2. Redistributions in binary form must reproduce the above copyright
  6335. notice, this list of conditions and the following disclaimer in
  6336. the documentation and/or other materials provided with the distribution.
  6337. 3. The names of the authors may not be used to endorse or promote products
  6338. derived from this software without specific prior written permission.
  6339. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  6340. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  6341. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  6342. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  6343. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6344. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  6345. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6346. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6347. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6348. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6349. */
  6350. /* global Blob, FileReader, atob, btoa, XMLHttpRequest, document, fetch */
  6351. const ERR_HTTP_STATUS = "HTTP error ";
  6352. const ERR_HTTP_RANGE = "HTTP Range not supported";
  6353. const ERR_NOT_SEEKABLE_READER = "Reader is not seekable";
  6354. const CONTENT_TYPE_TEXT_PLAIN = "text/plain";
  6355. const HTTP_HEADER_CONTENT_LENGTH = "Content-Length";
  6356. const HTTP_HEADER_CONTENT_RANGE = "Content-Range";
  6357. const HTTP_HEADER_ACCEPT_RANGES = "Accept-Ranges";
  6358. const HTTP_HEADER_RANGE = "Range";
  6359. const HTTP_METHOD_HEAD = "HEAD";
  6360. const HTTP_METHOD_GET = "GET";
  6361. const HTTP_RANGE_UNIT = "bytes";
  6362. class Stream {
  6363. constructor() {
  6364. this.size = 0;
  6365. }
  6366. init() {
  6367. this.initialized = true;
  6368. }
  6369. }
  6370. class Reader extends Stream {
  6371. }
  6372. class Writer extends Stream {
  6373. writeUint8Array(array) {
  6374. this.size += array.length;
  6375. }
  6376. }
  6377. class TextReader extends Reader {
  6378. constructor(text) {
  6379. super();
  6380. this.blobReader = new BlobReader(new Blob([text], { type: CONTENT_TYPE_TEXT_PLAIN }));
  6381. }
  6382. init() {
  6383. super.init();
  6384. this.blobReader.init();
  6385. this.size = this.blobReader.size;
  6386. }
  6387. readUint8Array(offset, length) {
  6388. return this.blobReader.readUint8Array(offset, length);
  6389. }
  6390. }
  6391. class TextWriter extends Writer {
  6392. constructor(encoding) {
  6393. super();
  6394. this.encoding = encoding;
  6395. this.blob = new Blob([], { type: CONTENT_TYPE_TEXT_PLAIN });
  6396. }
  6397. writeUint8Array(array) {
  6398. super.writeUint8Array(array);
  6399. this.blob = new Blob([this.blob, array.buffer], { type: CONTENT_TYPE_TEXT_PLAIN });
  6400. }
  6401. getData() {
  6402. if (this.blob.text) {
  6403. return this.blob.text();
  6404. } else {
  6405. const reader = new FileReader();
  6406. return new Promise((resolve, reject) => {
  6407. reader.onload = event => resolve(event.target.result);
  6408. reader.onerror = () => reject(reader.error);
  6409. reader.readAsText(this.blob, this.encoding);
  6410. });
  6411. }
  6412. }
  6413. }
  6414. class Data64URIReader extends Reader {
  6415. constructor(dataURI) {
  6416. super();
  6417. this.dataURI = dataURI;
  6418. let dataEnd = dataURI.length;
  6419. while (dataURI.charAt(dataEnd - 1) == "=") {
  6420. dataEnd--;
  6421. }
  6422. this.dataStart = dataURI.indexOf(",") + 1;
  6423. this.size = Math.floor((dataEnd - this.dataStart) * 0.75);
  6424. }
  6425. readUint8Array(offset, length) {
  6426. const dataArray = new Uint8Array(length);
  6427. const start = Math.floor(offset / 3) * 4;
  6428. const bytes = atob(this.dataURI.substring(start + this.dataStart, Math.ceil((offset + length) / 3) * 4 + this.dataStart));
  6429. const delta = offset - Math.floor(start / 4) * 3;
  6430. for (let indexByte = delta; indexByte < delta + length; indexByte++) {
  6431. dataArray[indexByte - delta] = bytes.charCodeAt(indexByte);
  6432. }
  6433. return dataArray;
  6434. }
  6435. }
  6436. class Data64URIWriter extends Writer {
  6437. constructor(contentType) {
  6438. super();
  6439. this.data = "data:" + (contentType || "") + ";base64,";
  6440. this.pending = [];
  6441. }
  6442. writeUint8Array(array) {
  6443. super.writeUint8Array(array);
  6444. let indexArray = 0;
  6445. let dataString = this.pending;
  6446. const delta = this.pending.length;
  6447. this.pending = "";
  6448. for (indexArray = 0; indexArray < (Math.floor((delta + array.length) / 3) * 3) - delta; indexArray++) {
  6449. dataString += String.fromCharCode(array[indexArray]);
  6450. }
  6451. for (; indexArray < array.length; indexArray++) {
  6452. this.pending += String.fromCharCode(array[indexArray]);
  6453. }
  6454. if (dataString.length > 2) {
  6455. this.data += btoa(dataString);
  6456. } else {
  6457. this.pending = dataString;
  6458. }
  6459. }
  6460. getData() {
  6461. return this.data + btoa(this.pending);
  6462. }
  6463. }
  6464. class BlobReader extends Reader {
  6465. constructor(blob) {
  6466. super();
  6467. this.blob = blob;
  6468. this.size = blob.size;
  6469. }
  6470. async readUint8Array(offset, length) {
  6471. if (this.blob.arrayBuffer) {
  6472. return new Uint8Array(await this.blob.slice(offset, offset + length).arrayBuffer());
  6473. } else {
  6474. const reader = new FileReader();
  6475. return new Promise((resolve, reject) => {
  6476. reader.onload = event => resolve(new Uint8Array(event.target.result));
  6477. reader.onerror = () => reject(reader.error);
  6478. reader.readAsArrayBuffer(this.blob.slice(offset, offset + length));
  6479. });
  6480. }
  6481. }
  6482. }
  6483. class BlobWriter extends Writer {
  6484. constructor(contentType) {
  6485. super();
  6486. this.contentType = contentType;
  6487. this.arrayBuffersMaxlength = 8;
  6488. initArrayBuffers(this);
  6489. }
  6490. writeUint8Array(array) {
  6491. super.writeUint8Array(array);
  6492. if (this.arrayBuffers.length == this.arrayBuffersMaxlength) {
  6493. flushArrayBuffers(this);
  6494. }
  6495. this.arrayBuffers.push(array.buffer);
  6496. }
  6497. getData() {
  6498. if (!this.blob) {
  6499. if (this.arrayBuffers.length) {
  6500. flushArrayBuffers(this);
  6501. }
  6502. this.blob = this.pendingBlob;
  6503. initArrayBuffers(this);
  6504. }
  6505. return this.blob;
  6506. }
  6507. }
  6508. function initArrayBuffers(blobWriter) {
  6509. blobWriter.pendingBlob = new Blob([], { type: blobWriter.contentType });
  6510. blobWriter.arrayBuffers = [];
  6511. }
  6512. function flushArrayBuffers(blobWriter) {
  6513. blobWriter.pendingBlob = new Blob([blobWriter.pendingBlob, ...blobWriter.arrayBuffers], { type: blobWriter.contentType });
  6514. blobWriter.arrayBuffers = [];
  6515. }
  6516. class ReadableStreamReader {
  6517. constructor(readableStream) {
  6518. this.readableStream = readableStream;
  6519. this.reader = readableStream.getReader();
  6520. this.size = Infinity;
  6521. this.index = 0;
  6522. this.currentSize = 0;
  6523. this.pendingValue = new Uint8Array();
  6524. }
  6525. init() {
  6526. this.initialized = true;
  6527. }
  6528. async readUint8Array(index, length) {
  6529. if (this.index != index) {
  6530. throw new Error(ERR_NOT_SEEKABLE_READER);
  6531. }
  6532. let data = new Uint8Array(length);
  6533. let size = 0, done;
  6534. do {
  6535. const result = await this.reader.read();
  6536. let { value } = result;
  6537. done = result.done;
  6538. if (value) {
  6539. this.currentSize += value.length;
  6540. } else {
  6541. value = this.pendingValue;
  6542. this.pendingValue = new Uint8Array();
  6543. }
  6544. if (this.pendingValue.length) {
  6545. const newValue = new Uint8Array(this.pendingValue.length + value.length);
  6546. newValue.set(this.pendingValue);
  6547. newValue.set(value, this.pendingValue.length);
  6548. this.pendingValue = new Uint8Array();
  6549. value = newValue;
  6550. }
  6551. if (size + value.length > length) {
  6552. data.set(value.subarray(0, length), size);
  6553. this.pendingValue = value.subarray(length);
  6554. size += length;
  6555. } else {
  6556. data.set(value, size);
  6557. size += value.length;
  6558. }
  6559. } while (size < length && !done);
  6560. if (done && this.size == Infinity) {
  6561. this.size = this.currentSize;
  6562. }
  6563. if (this.size < length) {
  6564. data = data.slice(0, this.size);
  6565. length = this.size;
  6566. }
  6567. this.index += length;
  6568. return data;
  6569. }
  6570. }
  6571. class WritableStreamWriter extends Writer {
  6572. constructor(writableStream) {
  6573. super();
  6574. this.writableStream = writableStream;
  6575. this.writer = writableStream.getWriter();
  6576. }
  6577. async writeUint8Array(array) {
  6578. await this.writer.ready;
  6579. return this.writer.write(array);
  6580. }
  6581. async getData() {
  6582. await this.writer.ready;
  6583. await this.writer.close();
  6584. return this.writableStream;
  6585. }
  6586. }
  6587. class FetchReader extends Reader {
  6588. constructor(url, options) {
  6589. super();
  6590. this.url = url;
  6591. this.preventHeadRequest = options.preventHeadRequest;
  6592. this.useRangeHeader = options.useRangeHeader;
  6593. this.forceRangeRequests = options.forceRangeRequests;
  6594. this.options = Object.assign({}, options);
  6595. delete this.options.preventHeadRequest;
  6596. delete this.options.useRangeHeader;
  6597. delete this.options.forceRangeRequests;
  6598. delete this.options.useXHR;
  6599. }
  6600. async init() {
  6601. super.init();
  6602. await initHttpReader(this, sendFetchRequest, getFetchRequestData);
  6603. }
  6604. readUint8Array(index, length) {
  6605. return readUint8ArrayHttpReader(this, index, length, sendFetchRequest, getFetchRequestData);
  6606. }
  6607. }
  6608. class XHRReader extends Reader {
  6609. constructor(url, options) {
  6610. super();
  6611. this.url = url;
  6612. this.preventHeadRequest = options.preventHeadRequest;
  6613. this.useRangeHeader = options.useRangeHeader;
  6614. this.forceRangeRequests = options.forceRangeRequests;
  6615. this.options = options;
  6616. }
  6617. async init() {
  6618. super.init();
  6619. await initHttpReader(this, sendXMLHttpRequest, getXMLHttpRequestData);
  6620. }
  6621. readUint8Array(index, length) {
  6622. return readUint8ArrayHttpReader(this, index, length, sendXMLHttpRequest, getXMLHttpRequestData);
  6623. }
  6624. }
  6625. async function initHttpReader(httpReader, sendRequest, getRequestData) {
  6626. if (isHttpFamily(httpReader.url) && (httpReader.useRangeHeader || httpReader.forceRangeRequests)) {
  6627. const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
  6628. if (!httpReader.forceRangeRequests && response.headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
  6629. throw new Error(ERR_HTTP_RANGE);
  6630. } else {
  6631. let contentSize;
  6632. const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
  6633. if (contentRangeHeader) {
  6634. const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
  6635. if (splitHeader.length) {
  6636. const headerValue = splitHeader[1];
  6637. if (headerValue && headerValue != "*") {
  6638. contentSize = Number(headerValue);
  6639. }
  6640. }
  6641. }
  6642. if (contentSize === undefined) {
  6643. await getContentLength(httpReader, sendRequest, getRequestData);
  6644. } else {
  6645. httpReader.size = contentSize;
  6646. }
  6647. }
  6648. } else {
  6649. await getContentLength(httpReader, sendRequest, getRequestData);
  6650. }
  6651. }
  6652. async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest, getRequestData) {
  6653. if (httpReader.useRangeHeader || httpReader.forceRangeRequests) {
  6654. const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
  6655. if (response.status != 206) {
  6656. throw new Error(ERR_HTTP_RANGE);
  6657. }
  6658. return new Uint8Array(await response.arrayBuffer());
  6659. } else {
  6660. if (!httpReader.data) {
  6661. await getRequestData(httpReader, httpReader.options);
  6662. }
  6663. return new Uint8Array(httpReader.data.subarray(index, index + length));
  6664. }
  6665. }
  6666. function getRangeHeaders(httpReader, index = 0, length = 1) {
  6667. return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
  6668. }
  6669. function getHeaders(httpReader) {
  6670. const headers = httpReader.options.headers;
  6671. if (headers) {
  6672. if (Symbol.iterator in headers) {
  6673. return Object.fromEntries(headers);
  6674. } else {
  6675. return headers;
  6676. }
  6677. }
  6678. }
  6679. async function getFetchRequestData(httpReader) {
  6680. await getRequestData(httpReader, sendFetchRequest);
  6681. }
  6682. async function getXMLHttpRequestData(httpReader) {
  6683. await getRequestData(httpReader, sendXMLHttpRequest);
  6684. }
  6685. async function getRequestData(httpReader, sendRequest) {
  6686. const response = await sendRequest(HTTP_METHOD_GET, httpReader, getHeaders(httpReader));
  6687. httpReader.data = new Uint8Array(await response.arrayBuffer());
  6688. if (!httpReader.size) {
  6689. httpReader.size = httpReader.data.length;
  6690. }
  6691. }
  6692. async function getContentLength(httpReader, sendRequest, getRequestData) {
  6693. if (httpReader.preventHeadRequest) {
  6694. await getRequestData(httpReader, httpReader.options);
  6695. } else {
  6696. const response = await sendRequest(HTTP_METHOD_HEAD, httpReader, getHeaders(httpReader));
  6697. const contentLength = response.headers.get(HTTP_HEADER_CONTENT_LENGTH);
  6698. if (contentLength) {
  6699. httpReader.size = Number(contentLength);
  6700. } else {
  6701. await getRequestData(httpReader, httpReader.options);
  6702. }
  6703. }
  6704. }
  6705. async function sendFetchRequest(method, { options, url }, headers) {
  6706. const response = await fetch(url, Object.assign({}, options, { method, headers }));
  6707. if (response.status < 400) {
  6708. return response;
  6709. } else {
  6710. throw new Error(ERR_HTTP_STATUS + (response.statusText || response.status));
  6711. }
  6712. }
  6713. function sendXMLHttpRequest(method, { url }, headers) {
  6714. return new Promise((resolve, reject) => {
  6715. const request = new XMLHttpRequest();
  6716. request.addEventListener("load", () => {
  6717. if (request.status < 400) {
  6718. const headers = [];
  6719. request.getAllResponseHeaders().trim().split(/[\r\n]+/).forEach(header => {
  6720. const splitHeader = header.trim().split(/\s*:\s*/);
  6721. splitHeader[0] = splitHeader[0].trim().replace(/^[a-z]|-[a-z]/g, value => value.toUpperCase());
  6722. headers.push(splitHeader);
  6723. });
  6724. resolve({
  6725. status: request.status,
  6726. arrayBuffer: () => request.response,
  6727. headers: new Map(headers)
  6728. });
  6729. } else {
  6730. reject(new Error(ERR_HTTP_STATUS + (request.statusText || request.status)));
  6731. }
  6732. }, false);
  6733. request.addEventListener("error", event => reject(event.detail.error), false);
  6734. request.open(method, url);
  6735. if (headers) {
  6736. for (const entry of Object.entries(headers)) {
  6737. request.setRequestHeader(entry[0], entry[1]);
  6738. }
  6739. }
  6740. request.responseType = "arraybuffer";
  6741. request.send();
  6742. });
  6743. }
  6744. class HttpReader extends Reader {
  6745. constructor(url, options = {}) {
  6746. super();
  6747. this.url = url;
  6748. if (options.useXHR) {
  6749. this.reader = new XHRReader(url, options);
  6750. } else {
  6751. this.reader = new FetchReader(url, options);
  6752. }
  6753. }
  6754. set size(value) {
  6755. // ignored
  6756. }
  6757. get size() {
  6758. return this.reader.size;
  6759. }
  6760. async init() {
  6761. super.init();
  6762. await this.reader.init();
  6763. }
  6764. readUint8Array(index, length) {
  6765. return this.reader.readUint8Array(index, length);
  6766. }
  6767. }
  6768. class HttpRangeReader extends HttpReader {
  6769. constructor(url, options = {}) {
  6770. options.useRangeHeader = true;
  6771. super(url, options);
  6772. }
  6773. }
  6774. class Uint8ArrayReader extends Reader {
  6775. constructor(array) {
  6776. super();
  6777. this.array = array;
  6778. this.size = array.length;
  6779. }
  6780. readUint8Array(index, length) {
  6781. return this.array.slice(index, index + length);
  6782. }
  6783. }
  6784. class Uint8ArrayWriter extends Writer {
  6785. constructor() {
  6786. super();
  6787. this.array = new Uint8Array(0);
  6788. }
  6789. writeUint8Array(array) {
  6790. super.writeUint8Array(array);
  6791. const previousArray = this.array;
  6792. this.array = new Uint8Array(previousArray.length + array.length);
  6793. this.array.set(previousArray);
  6794. this.array.set(array, previousArray.length);
  6795. }
  6796. getData() {
  6797. return this.array;
  6798. }
  6799. }
  6800. function isHttpFamily(url) {
  6801. if (typeof document != "undefined") {
  6802. const anchor = document.createElement("a");
  6803. anchor.href = url;
  6804. return anchor.protocol == "http:" || anchor.protocol == "https:";
  6805. } else {
  6806. return /^https?:\/\//i.test(url);
  6807. }
  6808. }
  6809. /*
  6810. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  6811. Redistribution and use in source and binary forms, with or without
  6812. modification, are permitted provided that the following conditions are met:
  6813. 1. Redistributions of source code must retain the above copyright notice,
  6814. this list of conditions and the following disclaimer.
  6815. 2. Redistributions in binary form must reproduce the above copyright
  6816. notice, this list of conditions and the following disclaimer in
  6817. the documentation and/or other materials provided with the distribution.
  6818. 3. The names of the authors may not be used to endorse or promote products
  6819. derived from this software without specific prior written permission.
  6820. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  6821. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  6822. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  6823. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  6824. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6825. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  6826. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6827. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6828. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6829. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6830. */
  6831. const MAX_32_BITS = 0xffffffff;
  6832. const MAX_16_BITS = 0xffff;
  6833. const COMPRESSION_METHOD_DEFLATE = 0x08;
  6834. const COMPRESSION_METHOD_STORE = 0x00;
  6835. const COMPRESSION_METHOD_AES = 0x63;
  6836. const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
  6837. const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50;
  6838. const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
  6839. const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
  6840. const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
  6841. const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
  6842. const END_OF_CENTRAL_DIR_LENGTH = 22;
  6843. const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
  6844. const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
  6845. 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;
  6846. const ZIP64_TOTAL_NUMBER_OF_DISKS = 1;
  6847. const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
  6848. const EXTRAFIELD_TYPE_AES = 0x9901;
  6849. const EXTRAFIELD_TYPE_NTFS = 0x000a;
  6850. const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
  6851. const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
  6852. const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
  6853. const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
  6854. const BITFLAG_ENCRYPTED = 0x01;
  6855. const BITFLAG_LEVEL = 0x06;
  6856. const BITFLAG_DATA_DESCRIPTOR = 0x0008;
  6857. const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
  6858. const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
  6859. const VERSION_DEFLATE = 0x14;
  6860. const VERSION_ZIP64 = 0x2D;
  6861. const VERSION_AES = 0x33;
  6862. const DIRECTORY_SIGNATURE = "/";
  6863. const MAX_DATE = new Date(2107, 11, 31);
  6864. const MIN_DATE = new Date(1980, 0, 1);
  6865. /*
  6866. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  6867. Redistribution and use in source and binary forms, with or without
  6868. modification, are permitted provided that the following conditions are met:
  6869. 1. Redistributions of source code must retain the above copyright notice,
  6870. this list of conditions and the following disclaimer.
  6871. 2. Redistributions in binary form must reproduce the above copyright
  6872. notice, this list of conditions and the following disclaimer in
  6873. the documentation and/or other materials provided with the distribution.
  6874. 3. The names of the authors may not be used to endorse or promote products
  6875. derived from this software without specific prior written permission.
  6876. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  6877. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  6878. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  6879. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  6880. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6881. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  6882. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6883. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6884. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6885. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6886. */
  6887. const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
  6888. var decodeCP437 = stringValue => {
  6889. let result = "";
  6890. for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
  6891. result += CP437[stringValue[indexCharacter]];
  6892. }
  6893. return result;
  6894. };
  6895. /*
  6896. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  6897. Redistribution and use in source and binary forms, with or without
  6898. modification, are permitted provided that the following conditions are met:
  6899. 1. Redistributions of source code must retain the above copyright notice,
  6900. this list of conditions and the following disclaimer.
  6901. 2. Redistributions in binary form must reproduce the above copyright
  6902. notice, this list of conditions and the following disclaimer in
  6903. the documentation and/or other materials provided with the distribution.
  6904. 3. The names of the authors may not be used to endorse or promote products
  6905. derived from this software without specific prior written permission.
  6906. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  6907. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  6908. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  6909. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  6910. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6911. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  6912. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6913. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6914. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6915. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6916. */
  6917. function decodeText(value, encoding) {
  6918. if (encoding && encoding.trim().toLowerCase() == "cp437") {
  6919. return decodeCP437(value);
  6920. } else if (typeof TextDecoder == "undefined") {
  6921. const fileReader = new FileReader();
  6922. return new Promise((resolve, reject) => {
  6923. fileReader.onload = event => resolve(event.target.result);
  6924. fileReader.onerror = () => reject(fileReader.error);
  6925. fileReader.readAsText(new Blob([value]));
  6926. });
  6927. } else {
  6928. return new TextDecoder(encoding).decode(value);
  6929. }
  6930. }
  6931. /*
  6932. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  6933. Redistribution and use in source and binary forms, with or without
  6934. modification, are permitted provided that the following conditions are met:
  6935. 1. Redistributions of source code must retain the above copyright notice,
  6936. this list of conditions and the following disclaimer.
  6937. 2. Redistributions in binary form must reproduce the above copyright
  6938. notice, this list of conditions and the following disclaimer in
  6939. the documentation and/or other materials provided with the distribution.
  6940. 3. The names of the authors may not be used to endorse or promote products
  6941. derived from this software without specific prior written permission.
  6942. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  6943. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  6944. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  6945. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  6946. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  6947. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  6948. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  6949. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  6950. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  6951. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  6952. */
  6953. const MINIMUM_CHUNK_SIZE = 64;
  6954. const ERR_ABORT = "Abort error";
  6955. async function processData(codec, reader, writer, offset, inputLengthGetter, config, options) {
  6956. const chunkSize = Math.max(config.chunkSize, MINIMUM_CHUNK_SIZE);
  6957. return processChunk();
  6958. async function processChunk(chunkOffset = 0, outputLength = 0) {
  6959. const signal = options.signal;
  6960. const inputLength = inputLengthGetter();
  6961. if (chunkOffset < inputLength) {
  6962. testAborted(signal, codec);
  6963. const inputData = await reader.readUint8Array(chunkOffset + offset, Math.min(chunkSize, inputLength - chunkOffset));
  6964. const chunkLength = inputData.length;
  6965. testAborted(signal, codec);
  6966. const data = await codec.append(inputData);
  6967. testAborted(signal, codec);
  6968. outputLength += await writeData(writer, data);
  6969. if (options.onprogress) {
  6970. try {
  6971. options.onprogress(chunkOffset + chunkLength, inputLength);
  6972. } catch (error) {
  6973. // ignored
  6974. }
  6975. }
  6976. return processChunk(chunkOffset + chunkSize, outputLength);
  6977. } else {
  6978. const result = await codec.flush();
  6979. outputLength += await writeData(writer, result.data);
  6980. return { signature: result.signature, length: outputLength };
  6981. }
  6982. }
  6983. }
  6984. function testAborted(signal, codec) {
  6985. if (signal && signal.aborted) {
  6986. codec.abort();
  6987. throw new Error(ERR_ABORT);
  6988. }
  6989. }
  6990. async function writeData(writer, data) {
  6991. if (data.length) {
  6992. await writer.writeUint8Array(data);
  6993. }
  6994. return data.length;
  6995. }
  6996. /*
  6997. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  6998. Redistribution and use in source and binary forms, with or without
  6999. modification, are permitted provided that the following conditions are met:
  7000. 1. Redistributions of source code must retain the above copyright notice,
  7001. this list of conditions and the following disclaimer.
  7002. 2. Redistributions in binary form must reproduce the above copyright
  7003. notice, this list of conditions and the following disclaimer in
  7004. the documentation and/or other materials provided with the distribution.
  7005. 3. The names of the authors may not be used to endorse or promote products
  7006. derived from this software without specific prior written permission.
  7007. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  7008. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  7009. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  7010. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  7011. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  7012. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  7013. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  7014. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  7015. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  7016. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7017. */
  7018. const PROPERTY_NAMES = [
  7019. "filename", "rawFilename", "directory", "encrypted", "compressedSize", "uncompressedSize",
  7020. "lastModDate", "rawLastModDate", "comment", "rawComment", "signature", "extraField",
  7021. "rawExtraField", "bitFlag", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment",
  7022. "extraFieldAES", "filenameUTF8", "commentUTF8", "offset", "zip64", "compressionMethod",
  7023. "extraFieldNTFS", "lastAccessDate", "creationDate", "extraFieldExtendedTimestamp",
  7024. "version", "versionMadeBy", "msDosCompatible", "internalFileAttribute", "externalFileAttribute"];
  7025. class Entry {
  7026. constructor(data) {
  7027. PROPERTY_NAMES.forEach(name => this[name] = data[name]);
  7028. }
  7029. }
  7030. /*
  7031. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  7032. Redistribution and use in source and binary forms, with or without
  7033. modification, are permitted provided that the following conditions are met:
  7034. 1. Redistributions of source code must retain the above copyright notice,
  7035. this list of conditions and the following disclaimer.
  7036. 2. Redistributions in binary form must reproduce the above copyright
  7037. notice, this list of conditions and the following disclaimer in
  7038. the documentation and/or other materials provided with the distribution.
  7039. 3. The names of the authors may not be used to endorse or promote products
  7040. derived from this software without specific prior written permission.
  7041. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  7042. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  7043. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  7044. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  7045. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  7046. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  7047. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  7048. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  7049. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  7050. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7051. */
  7052. const ERR_BAD_FORMAT = "File format is not recognized";
  7053. const ERR_EOCDR_NOT_FOUND = "End of central directory not found";
  7054. const ERR_EOCDR_ZIP64_NOT_FOUND = "End of Zip64 central directory not found";
  7055. const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = "End of Zip64 central directory locator not found";
  7056. const ERR_CENTRAL_DIRECTORY_NOT_FOUND = "Central directory header not found";
  7057. const ERR_LOCAL_FILE_HEADER_NOT_FOUND = "Local file header not found";
  7058. const ERR_EXTRAFIELD_ZIP64_NOT_FOUND = "Zip64 extra field not found";
  7059. const ERR_ENCRYPTED = "File contains encrypted entry";
  7060. const ERR_UNSUPPORTED_ENCRYPTION = "Encryption method not supported";
  7061. const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
  7062. const CHARSET_UTF8 = "utf-8";
  7063. const CHARSET_CP437 = "cp437";
  7064. const ZIP64_PROPERTIES = ["uncompressedSize", "compressedSize", "offset"];
  7065. class ZipReader {
  7066. constructor(reader, options = {}) {
  7067. Object.assign(this, {
  7068. reader,
  7069. options,
  7070. config: getConfiguration()
  7071. });
  7072. }
  7073. async* getEntriesGenerator(options = {}) {
  7074. const zipReader = this;
  7075. const reader = zipReader.reader;
  7076. if (!reader.initialized) {
  7077. await reader.init();
  7078. }
  7079. if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
  7080. throw new Error(ERR_BAD_FORMAT);
  7081. }
  7082. const endOfDirectoryInfo = await seekSignature(reader, END_OF_CENTRAL_DIR_SIGNATURE, reader.size, END_OF_CENTRAL_DIR_LENGTH, MAX_16_BITS * 16);
  7083. if (!endOfDirectoryInfo) {
  7084. throw new Error(ERR_EOCDR_NOT_FOUND);
  7085. }
  7086. const endOfDirectoryView = getDataView$1(endOfDirectoryInfo);
  7087. let directoryDataLength = getUint32(endOfDirectoryView, 12);
  7088. let directoryDataOffset = getUint32(endOfDirectoryView, 16);
  7089. let filesLength = getUint16(endOfDirectoryView, 8);
  7090. let prependedDataLength = 0;
  7091. if (directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS) {
  7092. const endOfDirectoryLocatorArray = await readUint8Array(reader, endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH);
  7093. const endOfDirectoryLocatorView = getDataView$1(endOfDirectoryLocatorArray);
  7094. if (getUint32(endOfDirectoryLocatorView, 0) != ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
  7095. throw new Error(ERR_EOCDR_ZIP64_NOT_FOUND);
  7096. }
  7097. directoryDataOffset = getBigUint64(endOfDirectoryLocatorView, 8);
  7098. let endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
  7099. let endOfDirectoryView = getDataView$1(endOfDirectoryArray);
  7100. const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH - ZIP64_END_OF_CENTRAL_DIR_LENGTH;
  7101. if (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE && directoryDataOffset != expectedDirectoryDataOffset) {
  7102. const originalDirectoryDataOffset = directoryDataOffset;
  7103. directoryDataOffset = expectedDirectoryDataOffset;
  7104. prependedDataLength = directoryDataOffset - originalDirectoryDataOffset;
  7105. endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
  7106. endOfDirectoryView = getDataView$1(endOfDirectoryArray);
  7107. }
  7108. if (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
  7109. throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
  7110. }
  7111. filesLength = getBigUint64(endOfDirectoryView, 32);
  7112. directoryDataLength = getBigUint64(endOfDirectoryView, 40);
  7113. directoryDataOffset -= directoryDataLength;
  7114. }
  7115. if (directoryDataOffset < 0 || directoryDataOffset >= reader.size) {
  7116. throw new Error(ERR_BAD_FORMAT);
  7117. }
  7118. let offset = 0;
  7119. let directoryArray = await readUint8Array(reader, directoryDataOffset, directoryDataLength);
  7120. let directoryView = getDataView$1(directoryArray);
  7121. if (directoryDataLength) {
  7122. const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - directoryDataLength;
  7123. if (getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE && directoryDataOffset != expectedDirectoryDataOffset) {
  7124. const originalDirectoryDataOffset = directoryDataOffset;
  7125. directoryDataOffset = expectedDirectoryDataOffset;
  7126. prependedDataLength = directoryDataOffset - originalDirectoryDataOffset;
  7127. directoryArray = await readUint8Array(reader, directoryDataOffset, directoryDataLength);
  7128. directoryView = getDataView$1(directoryArray);
  7129. }
  7130. }
  7131. if (directoryDataOffset < 0 || directoryDataOffset >= reader.size) {
  7132. throw new Error(ERR_BAD_FORMAT);
  7133. }
  7134. for (let indexFile = 0; indexFile < filesLength; indexFile++) {
  7135. const fileEntry = new ZipEntry$1(reader, zipReader.config, zipReader.options);
  7136. if (getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
  7137. throw new Error(ERR_CENTRAL_DIRECTORY_NOT_FOUND);
  7138. }
  7139. readCommonHeader(fileEntry, directoryView, offset + 6);
  7140. const languageEncodingFlag = Boolean(fileEntry.bitFlag.languageEncodingFlag);
  7141. const filenameOffset = offset + 46;
  7142. const extraFieldOffset = filenameOffset + fileEntry.filenameLength;
  7143. const commentOffset = extraFieldOffset + fileEntry.extraFieldLength;
  7144. const versionMadeBy = getUint16(directoryView, offset + 4);
  7145. const msDosCompatible = (versionMadeBy & 0) == 0;
  7146. Object.assign(fileEntry, {
  7147. versionMadeBy,
  7148. msDosCompatible,
  7149. compressedSize: 0,
  7150. uncompressedSize: 0,
  7151. commentLength: getUint16(directoryView, offset + 32),
  7152. directory: msDosCompatible && ((getUint8(directoryView, offset + 38) & FILE_ATTR_MSDOS_DIR_MASK) == FILE_ATTR_MSDOS_DIR_MASK),
  7153. offset: getUint32(directoryView, offset + 42) + prependedDataLength,
  7154. internalFileAttribute: getUint32(directoryView, offset + 34),
  7155. externalFileAttribute: getUint32(directoryView, offset + 38),
  7156. rawFilename: directoryArray.subarray(filenameOffset, extraFieldOffset),
  7157. filenameUTF8: languageEncodingFlag,
  7158. commentUTF8: languageEncodingFlag,
  7159. rawExtraField: directoryArray.subarray(extraFieldOffset, commentOffset)
  7160. });
  7161. const endOffset = commentOffset + fileEntry.commentLength;
  7162. fileEntry.rawComment = directoryArray.subarray(commentOffset, endOffset);
  7163. const filenameEncoding = getOptionValue$1(zipReader, options, "filenameEncoding");
  7164. const commentEncoding = getOptionValue$1(zipReader, options, "commentEncoding");
  7165. const [filename, comment] = await Promise.all([
  7166. decodeText(fileEntry.rawFilename, fileEntry.filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437),
  7167. decodeText(fileEntry.rawComment, fileEntry.commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437)
  7168. ]);
  7169. fileEntry.filename = filename;
  7170. fileEntry.comment = comment;
  7171. if (!fileEntry.directory && fileEntry.filename.endsWith(DIRECTORY_SIGNATURE)) {
  7172. fileEntry.directory = true;
  7173. }
  7174. await readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6);
  7175. const entry = new Entry(fileEntry);
  7176. entry.getData = (writer, options) => fileEntry.getData(writer, entry, options);
  7177. offset = endOffset;
  7178. if (options.onprogress) {
  7179. try {
  7180. options.onprogress(indexFile + 1, filesLength, new Entry(fileEntry));
  7181. } catch (_error) {
  7182. // ignored
  7183. }
  7184. }
  7185. yield entry;
  7186. }
  7187. return true;
  7188. }
  7189. async getEntries(options = {}) {
  7190. const entries = [];
  7191. const iter = this.getEntriesGenerator(options);
  7192. let curr = iter.next();
  7193. while(!(await curr).done) {
  7194. entries.push((await curr).value);
  7195. curr = iter.next();
  7196. }
  7197. return entries;
  7198. }
  7199. async close() {
  7200. }
  7201. }
  7202. class ZipEntry$1 {
  7203. constructor(reader, config, options) {
  7204. Object.assign(this, {
  7205. reader,
  7206. config,
  7207. options
  7208. });
  7209. }
  7210. async getData(writer, fileEntry, options = {}) {
  7211. const zipEntry = this;
  7212. const {
  7213. reader,
  7214. offset,
  7215. extraFieldAES,
  7216. compressionMethod,
  7217. config,
  7218. bitFlag,
  7219. signature,
  7220. rawLastModDate,
  7221. compressedSize
  7222. } = zipEntry;
  7223. const localDirectory = zipEntry.localDirectory = {};
  7224. if (!reader.initialized) {
  7225. await reader.init();
  7226. }
  7227. let dataArray = await readUint8Array(reader, offset, 30);
  7228. const dataView = getDataView$1(dataArray);
  7229. let password = getOptionValue$1(zipEntry, options, "password");
  7230. password = password && password.length && password;
  7231. if (extraFieldAES) {
  7232. if (extraFieldAES.originalCompressionMethod != COMPRESSION_METHOD_AES) {
  7233. throw new Error(ERR_UNSUPPORTED_COMPRESSION);
  7234. }
  7235. }
  7236. if (compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE) {
  7237. throw new Error(ERR_UNSUPPORTED_COMPRESSION);
  7238. }
  7239. if (getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
  7240. throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
  7241. }
  7242. readCommonHeader(localDirectory, dataView, 4);
  7243. dataArray = await readUint8Array(reader, offset, 30 + localDirectory.filenameLength + localDirectory.extraFieldLength);
  7244. localDirectory.rawExtraField = dataArray.subarray(30 + localDirectory.filenameLength);
  7245. await readCommonFooter(zipEntry, localDirectory, dataView, 4);
  7246. fileEntry.lastAccessDate = localDirectory.lastAccessDate;
  7247. fileEntry.creationDate = localDirectory.creationDate;
  7248. const encrypted = zipEntry.encrypted && localDirectory.encrypted;
  7249. const zipCrypto = encrypted && !extraFieldAES;
  7250. if (encrypted) {
  7251. if (!zipCrypto && extraFieldAES.strength === undefined) {
  7252. throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
  7253. } else if (!password) {
  7254. throw new Error(ERR_ENCRYPTED);
  7255. }
  7256. }
  7257. const codec = await createCodec(config.Inflate, {
  7258. codecType: CODEC_INFLATE,
  7259. password,
  7260. zipCrypto,
  7261. encryptionStrength: extraFieldAES && extraFieldAES.strength,
  7262. signed: getOptionValue$1(zipEntry, options, "checkSignature"),
  7263. passwordVerification: zipCrypto && (bitFlag.dataDescriptor ? ((rawLastModDate >>> 8) & 0xFF) : ((signature >>> 24) & 0xFF)),
  7264. signature,
  7265. compressed: compressionMethod != 0,
  7266. encrypted,
  7267. useWebWorkers: getOptionValue$1(zipEntry, options, "useWebWorkers")
  7268. }, config);
  7269. if (!writer.initialized) {
  7270. await writer.init();
  7271. }
  7272. const signal = getOptionValue$1(zipEntry, options, "signal");
  7273. const dataOffset = offset + 30 + localDirectory.filenameLength + localDirectory.extraFieldLength;
  7274. await processData(codec, reader, writer, dataOffset, () => compressedSize, config, { onprogress: options.onprogress, signal });
  7275. return writer.getData();
  7276. }
  7277. }
  7278. function readCommonHeader(directory, dataView, offset) {
  7279. const rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2);
  7280. const encrypted = (rawBitFlag & BITFLAG_ENCRYPTED) == BITFLAG_ENCRYPTED;
  7281. const rawLastModDate = getUint32(dataView, offset + 6);
  7282. Object.assign(directory, {
  7283. encrypted,
  7284. version: getUint16(dataView, offset),
  7285. bitFlag: {
  7286. level: (rawBitFlag & BITFLAG_LEVEL) >> 1,
  7287. dataDescriptor: (rawBitFlag & BITFLAG_DATA_DESCRIPTOR) == BITFLAG_DATA_DESCRIPTOR,
  7288. languageEncodingFlag: (rawBitFlag & BITFLAG_LANG_ENCODING_FLAG) == BITFLAG_LANG_ENCODING_FLAG
  7289. },
  7290. rawLastModDate,
  7291. lastModDate: getDate(rawLastModDate),
  7292. filenameLength: getUint16(dataView, offset + 22),
  7293. extraFieldLength: getUint16(dataView, offset + 24)
  7294. });
  7295. }
  7296. async function readCommonFooter(fileEntry, directory, dataView, offset) {
  7297. const rawExtraField = directory.rawExtraField;
  7298. const extraField = directory.extraField = new Map();
  7299. const rawExtraFieldView = getDataView$1(new Uint8Array(rawExtraField));
  7300. let offsetExtraField = 0;
  7301. try {
  7302. while (offsetExtraField < rawExtraField.length) {
  7303. const type = getUint16(rawExtraFieldView, offsetExtraField);
  7304. const size = getUint16(rawExtraFieldView, offsetExtraField + 2);
  7305. extraField.set(type, {
  7306. type,
  7307. data: rawExtraField.slice(offsetExtraField + 4, offsetExtraField + 4 + size)
  7308. });
  7309. offsetExtraField += 4 + size;
  7310. }
  7311. } catch (_error) {
  7312. // ignored
  7313. }
  7314. const compressionMethod = getUint16(dataView, offset + 4);
  7315. directory.signature = getUint32(dataView, offset + 10);
  7316. directory.uncompressedSize = getUint32(dataView, offset + 18);
  7317. directory.compressedSize = getUint32(dataView, offset + 14);
  7318. const extraFieldZip64 = extraField.get(EXTRAFIELD_TYPE_ZIP64);
  7319. if (extraFieldZip64) {
  7320. readExtraFieldZip64(extraFieldZip64, directory);
  7321. directory.extraFieldZip64 = extraFieldZip64;
  7322. }
  7323. const extraFieldUnicodePath = extraField.get(EXTRAFIELD_TYPE_UNICODE_PATH);
  7324. if (extraFieldUnicodePath) {
  7325. await readExtraFieldUnicode(extraFieldUnicodePath, "filename", "rawFilename", directory, fileEntry);
  7326. directory.extraFieldUnicodePath = extraFieldUnicodePath;
  7327. }
  7328. const extraFieldUnicodeComment = extraField.get(EXTRAFIELD_TYPE_UNICODE_COMMENT);
  7329. if (extraFieldUnicodeComment) {
  7330. await readExtraFieldUnicode(extraFieldUnicodeComment, "comment", "rawComment", directory, fileEntry);
  7331. directory.extraFieldUnicodeComment = extraFieldUnicodeComment;
  7332. }
  7333. const extraFieldAES = extraField.get(EXTRAFIELD_TYPE_AES);
  7334. if (extraFieldAES) {
  7335. readExtraFieldAES(extraFieldAES, directory, compressionMethod);
  7336. directory.extraFieldAES = extraFieldAES;
  7337. } else {
  7338. directory.compressionMethod = compressionMethod;
  7339. }
  7340. const extraFieldNTFS = extraField.get(EXTRAFIELD_TYPE_NTFS);
  7341. if (extraFieldNTFS) {
  7342. readExtraFieldNTFS(extraFieldNTFS, directory);
  7343. directory.extraFieldNTFS = extraFieldNTFS;
  7344. }
  7345. const extraFieldExtendedTimestamp = extraField.get(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
  7346. if (extraFieldExtendedTimestamp) {
  7347. readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory);
  7348. directory.extraFieldExtendedTimestamp = extraFieldExtendedTimestamp;
  7349. }
  7350. }
  7351. function readExtraFieldZip64(extraFieldZip64, directory) {
  7352. directory.zip64 = true;
  7353. const extraFieldView = getDataView$1(extraFieldZip64.data);
  7354. extraFieldZip64.values = [];
  7355. for (let indexValue = 0; indexValue < Math.floor(extraFieldZip64.data.length / 8); indexValue++) {
  7356. extraFieldZip64.values.push(getBigUint64(extraFieldView, 0 + indexValue * 8));
  7357. }
  7358. const missingProperties = ZIP64_PROPERTIES.filter(propertyName => directory[propertyName] == MAX_32_BITS);
  7359. for (let indexMissingProperty = 0; indexMissingProperty < missingProperties.length; indexMissingProperty++) {
  7360. extraFieldZip64[missingProperties[indexMissingProperty]] = extraFieldZip64.values[indexMissingProperty];
  7361. }
  7362. ZIP64_PROPERTIES.forEach(propertyName => {
  7363. if (directory[propertyName] == MAX_32_BITS) {
  7364. if (extraFieldZip64[propertyName] !== undefined) {
  7365. directory[propertyName] = extraFieldZip64[propertyName];
  7366. } else {
  7367. throw new Error(ERR_EXTRAFIELD_ZIP64_NOT_FOUND);
  7368. }
  7369. }
  7370. });
  7371. }
  7372. async function readExtraFieldUnicode(extraFieldUnicode, propertyName, rawPropertyName, directory, fileEntry) {
  7373. const extraFieldView = getDataView$1(extraFieldUnicode.data);
  7374. extraFieldUnicode.version = getUint8(extraFieldView, 0);
  7375. extraFieldUnicode.signature = getUint32(extraFieldView, 1);
  7376. const crc32 = new Crc32();
  7377. crc32.append(fileEntry[rawPropertyName]);
  7378. const dataViewSignature = getDataView$1(new Uint8Array(4));
  7379. dataViewSignature.setUint32(0, crc32.get(), true);
  7380. extraFieldUnicode[propertyName] = await decodeText(extraFieldUnicode.data.subarray(5));
  7381. extraFieldUnicode.valid = !fileEntry.bitFlag.languageEncodingFlag && extraFieldUnicode.signature == getUint32(dataViewSignature, 0);
  7382. if (extraFieldUnicode.valid) {
  7383. directory[propertyName] = extraFieldUnicode[propertyName];
  7384. directory[propertyName + "UTF8"] = true;
  7385. }
  7386. }
  7387. function readExtraFieldAES(extraFieldAES, directory, compressionMethod) {
  7388. const extraFieldView = getDataView$1(extraFieldAES.data);
  7389. extraFieldAES.vendorVersion = getUint8(extraFieldView, 0);
  7390. extraFieldAES.vendorId = getUint8(extraFieldView, 2);
  7391. const strength = getUint8(extraFieldView, 4);
  7392. extraFieldAES.strength = strength;
  7393. extraFieldAES.originalCompressionMethod = compressionMethod;
  7394. directory.compressionMethod = extraFieldAES.compressionMethod = getUint16(extraFieldView, 5);
  7395. }
  7396. function readExtraFieldNTFS(extraFieldNTFS, directory) {
  7397. const extraFieldView = getDataView$1(extraFieldNTFS.data);
  7398. let offsetExtraField = 4;
  7399. let tag1Data;
  7400. try {
  7401. while (offsetExtraField < extraFieldNTFS.data.length && !tag1Data) {
  7402. const tagValue = getUint16(extraFieldView, offsetExtraField);
  7403. const attributeSize = getUint16(extraFieldView, offsetExtraField + 2);
  7404. if (tagValue == EXTRAFIELD_TYPE_NTFS_TAG1) {
  7405. tag1Data = extraFieldNTFS.data.slice(offsetExtraField + 4, offsetExtraField + 4 + attributeSize);
  7406. }
  7407. offsetExtraField += 4 + attributeSize;
  7408. }
  7409. } catch (_error) {
  7410. // ignored
  7411. }
  7412. try {
  7413. if (tag1Data && tag1Data.length == 24) {
  7414. const tag1View = getDataView$1(tag1Data);
  7415. const rawLastModDate = tag1View.getBigUint64(0, true);
  7416. const rawLastAccessDate = tag1View.getBigUint64(8, true);
  7417. const rawCreationDate = tag1View.getBigUint64(16, true);
  7418. Object.assign(extraFieldNTFS, {
  7419. rawLastModDate,
  7420. rawLastAccessDate,
  7421. rawCreationDate
  7422. });
  7423. const lastModDate = getDateNTFS(rawLastModDate);
  7424. const lastAccessDate = getDateNTFS(rawLastAccessDate);
  7425. const creationDate = getDateNTFS(rawCreationDate);
  7426. const extraFieldData = { lastModDate, lastAccessDate, creationDate };
  7427. Object.assign(extraFieldNTFS, extraFieldData);
  7428. Object.assign(directory, extraFieldData);
  7429. }
  7430. } catch (_error) {
  7431. // ignored
  7432. }
  7433. }
  7434. function readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory) {
  7435. const extraFieldView = getDataView$1(extraFieldExtendedTimestamp.data);
  7436. const flags = getUint8(extraFieldView, 0);
  7437. const timeProperties = [];
  7438. const timeRawProperties = [];
  7439. if ((flags & 0x1) == 0x1) {
  7440. timeProperties.push("lastModDate");
  7441. timeRawProperties.push("rawLastModDate");
  7442. }
  7443. if ((flags & 0x2) == 0x2) {
  7444. timeProperties.push("lastAccessDate");
  7445. timeRawProperties.push("rawLastAccessDate");
  7446. }
  7447. if ((flags & 0x4) == 0x4) {
  7448. timeProperties.push("creationDate");
  7449. timeRawProperties.push("rawCreationDate");
  7450. }
  7451. let offset = 1;
  7452. timeProperties.forEach((propertyName, indexProperty) => {
  7453. if (extraFieldExtendedTimestamp.data.length >= offset + 4) {
  7454. const time = getUint32(extraFieldView, offset);
  7455. directory[propertyName] = extraFieldExtendedTimestamp[propertyName] = new Date(time * 1000);
  7456. const rawPropertyName = timeRawProperties[indexProperty];
  7457. extraFieldExtendedTimestamp[rawPropertyName] = time;
  7458. }
  7459. offset += 4;
  7460. });
  7461. }
  7462. async function seekSignature(reader, signature, startOffset, minimumBytes, maximumLength) {
  7463. const signatureArray = new Uint8Array(4);
  7464. const signatureView = getDataView$1(signatureArray);
  7465. setUint32$1(signatureView, 0, signature);
  7466. const maximumBytes = minimumBytes + maximumLength;
  7467. return (await seek(minimumBytes)) || await seek(Math.min(maximumBytes, startOffset));
  7468. async function seek(length) {
  7469. const offset = startOffset - length;
  7470. const bytes = await readUint8Array(reader, offset, length);
  7471. for (let indexByte = bytes.length - minimumBytes; indexByte >= 0; indexByte--) {
  7472. if (bytes[indexByte] == signatureArray[0] && bytes[indexByte + 1] == signatureArray[1] &&
  7473. bytes[indexByte + 2] == signatureArray[2] && bytes[indexByte + 3] == signatureArray[3]) {
  7474. return {
  7475. offset: offset + indexByte,
  7476. buffer: bytes.slice(indexByte, indexByte + minimumBytes).buffer
  7477. };
  7478. }
  7479. }
  7480. }
  7481. }
  7482. function getOptionValue$1(zipReader, options, name) {
  7483. return options[name] === undefined ? zipReader.options[name] : options[name];
  7484. }
  7485. function getDate(timeRaw) {
  7486. const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & 0x0000ffff;
  7487. try {
  7488. return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
  7489. } catch (_error) {
  7490. // ignored
  7491. }
  7492. }
  7493. function getDateNTFS(timeRaw) {
  7494. return new Date((Number((timeRaw / BigInt(10000)) - BigInt(11644473600000))));
  7495. }
  7496. function getUint8(view, offset) {
  7497. return view.getUint8(offset);
  7498. }
  7499. function getUint16(view, offset) {
  7500. return view.getUint16(offset, true);
  7501. }
  7502. function getUint32(view, offset) {
  7503. return view.getUint32(offset, true);
  7504. }
  7505. function getBigUint64(view, offset) {
  7506. return Number(view.getBigUint64(offset, true));
  7507. }
  7508. function setUint32$1(view, offset, value) {
  7509. view.setUint32(offset, value, true);
  7510. }
  7511. function getDataView$1(array) {
  7512. return new DataView(array.buffer);
  7513. }
  7514. function readUint8Array(reader, offset, size) {
  7515. return reader.readUint8Array(offset, size);
  7516. }
  7517. /*
  7518. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  7519. Redistribution and use in source and binary forms, with or without
  7520. modification, are permitted provided that the following conditions are met:
  7521. 1. Redistributions of source code must retain the above copyright notice,
  7522. this list of conditions and the following disclaimer.
  7523. 2. Redistributions in binary form must reproduce the above copyright
  7524. notice, this list of conditions and the following disclaimer in
  7525. the documentation and/or other materials provided with the distribution.
  7526. 3. The names of the authors may not be used to endorse or promote products
  7527. derived from this software without specific prior written permission.
  7528. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  7529. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  7530. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  7531. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  7532. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  7533. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  7534. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  7535. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  7536. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  7537. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7538. */
  7539. const ERR_DUPLICATED_NAME = "File already exists";
  7540. const ERR_INVALID_COMMENT = "Zip file comment exceeds 64KB";
  7541. const ERR_INVALID_ENTRY_COMMENT = "File entry comment exceeds 64KB";
  7542. const ERR_INVALID_ENTRY_NAME = "File entry name exceeds 64KB";
  7543. const ERR_INVALID_VERSION = "Version exceeds 65535";
  7544. const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
  7545. const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
  7546. const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
  7547. const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported";
  7548. const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
  7549. const EXTRAFIELD_LENGTH_ZIP64 = 24;
  7550. let workers = 0;
  7551. class ZipWriter {
  7552. constructor(writer, options = {}) {
  7553. Object.assign(this, {
  7554. writer,
  7555. options,
  7556. config: getConfiguration(),
  7557. files: new Map(),
  7558. offset: writer.size,
  7559. pendingCompressedSize: 0,
  7560. pendingEntries: [],
  7561. pendingAddFileCalls: new Set()
  7562. });
  7563. }
  7564. async add(name = "", reader, options = {}) {
  7565. const zipWriter = this;
  7566. if (workers < zipWriter.config.maxWorkers) {
  7567. workers++;
  7568. let promiseAddFile;
  7569. try {
  7570. promiseAddFile = addFile(zipWriter, name, reader, options);
  7571. this.pendingAddFileCalls.add(promiseAddFile);
  7572. return await promiseAddFile;
  7573. } finally {
  7574. this.pendingAddFileCalls.delete(promiseAddFile);
  7575. workers--;
  7576. const pendingEntry = zipWriter.pendingEntries.shift();
  7577. if (pendingEntry) {
  7578. zipWriter.add(pendingEntry.name, pendingEntry.reader, pendingEntry.options)
  7579. .then(pendingEntry.resolve)
  7580. .catch(pendingEntry.reject);
  7581. }
  7582. }
  7583. } else {
  7584. return new Promise((resolve, reject) => zipWriter.pendingEntries.push({ name, reader, options, resolve, reject }));
  7585. }
  7586. }
  7587. async close(comment = new Uint8Array(0), options = {}) {
  7588. while (this.pendingAddFileCalls.size) {
  7589. await Promise.all(Array.from(this.pendingAddFileCalls));
  7590. }
  7591. await closeFile(this, comment, options);
  7592. return this.writer.getData();
  7593. }
  7594. }
  7595. async function addFile(zipWriter, name, reader, options) {
  7596. name = name.trim();
  7597. if (options.directory && (!name.endsWith(DIRECTORY_SIGNATURE))) {
  7598. name += DIRECTORY_SIGNATURE;
  7599. } else {
  7600. options.directory = name.endsWith(DIRECTORY_SIGNATURE);
  7601. }
  7602. if (zipWriter.files.has(name)) {
  7603. throw new Error(ERR_DUPLICATED_NAME);
  7604. }
  7605. const rawFilename = encodeText(name);
  7606. if (rawFilename.length > MAX_16_BITS) {
  7607. throw new Error(ERR_INVALID_ENTRY_NAME);
  7608. }
  7609. const comment = options.comment || "";
  7610. const rawComment = encodeText(comment);
  7611. if (rawComment.length > MAX_16_BITS) {
  7612. throw new Error(ERR_INVALID_ENTRY_COMMENT);
  7613. }
  7614. const version = zipWriter.options.version || options.version || 0;
  7615. if (version > MAX_16_BITS) {
  7616. throw new Error(ERR_INVALID_VERSION);
  7617. }
  7618. const versionMadeBy = zipWriter.options.versionMadeBy || options.versionMadeBy || 20;
  7619. if (versionMadeBy > MAX_16_BITS) {
  7620. throw new Error(ERR_INVALID_VERSION);
  7621. }
  7622. const lastModDate = getOptionValue(zipWriter, options, "lastModDate") || new Date();
  7623. const lastAccessDate = getOptionValue(zipWriter, options, "lastAccessDate");
  7624. const creationDate = getOptionValue(zipWriter, options, "creationDate");
  7625. const password = getOptionValue(zipWriter, options, "password");
  7626. const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
  7627. const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
  7628. if (password !== undefined && encryptionStrength !== undefined && (encryptionStrength < 1 || encryptionStrength > 3)) {
  7629. throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
  7630. }
  7631. let rawExtraField = new Uint8Array(0);
  7632. const extraField = options.extraField;
  7633. if (extraField) {
  7634. let extraFieldSize = 0;
  7635. let offset = 0;
  7636. extraField.forEach(data => extraFieldSize += 4 + data.length);
  7637. rawExtraField = new Uint8Array(extraFieldSize);
  7638. extraField.forEach((data, type) => {
  7639. if (type > MAX_16_BITS) {
  7640. throw new Error(ERR_INVALID_EXTRAFIELD_TYPE);
  7641. }
  7642. if (data.length > MAX_16_BITS) {
  7643. throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
  7644. }
  7645. arraySet(rawExtraField, new Uint16Array([type]), offset);
  7646. arraySet(rawExtraField, new Uint16Array([data.length]), offset + 2);
  7647. arraySet(rawExtraField, data, offset + 4);
  7648. offset += 4 + data.length;
  7649. });
  7650. }
  7651. let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
  7652. if (extendedTimestamp === undefined) {
  7653. extendedTimestamp = true;
  7654. }
  7655. let maximumCompressedSize = 0;
  7656. let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
  7657. if (keepOrder === undefined) {
  7658. keepOrder = true;
  7659. }
  7660. let uncompressedSize = 0;
  7661. let msDosCompatible = getOptionValue(zipWriter, options, "msDosCompatible");
  7662. if (msDosCompatible === undefined) {
  7663. msDosCompatible = true;
  7664. }
  7665. const internalFileAttribute = getOptionValue(zipWriter, options, "internalFileAttribute") || 0;
  7666. const externalFileAttribute = getOptionValue(zipWriter, options, "externalFileAttribute") || 0;
  7667. if (reader) {
  7668. if (!reader.initialized) {
  7669. await reader.init();
  7670. }
  7671. uncompressedSize = reader.size;
  7672. maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
  7673. }
  7674. let zip64 = options.zip64 || zipWriter.options.zip64 || false;
  7675. if (zipWriter.offset + zipWriter.pendingCompressedSize >= MAX_32_BITS ||
  7676. uncompressedSize >= MAX_32_BITS ||
  7677. maximumCompressedSize >= MAX_32_BITS) {
  7678. if (options.zip64 === false || zipWriter.options.zip64 === false || !keepOrder) {
  7679. throw new Error(ERR_UNSUPPORTED_FORMAT);
  7680. } else {
  7681. zip64 = true;
  7682. }
  7683. }
  7684. zipWriter.pendingCompressedSize += maximumCompressedSize;
  7685. await Promise.resolve();
  7686. const level = getOptionValue(zipWriter, options, "level");
  7687. const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
  7688. const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
  7689. let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor");
  7690. let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
  7691. const signal = getOptionValue(zipWriter, options, "signal");
  7692. if (dataDescriptor === undefined) {
  7693. dataDescriptor = true;
  7694. }
  7695. if (dataDescriptor && dataDescriptorSignature === undefined) {
  7696. dataDescriptorSignature = false;
  7697. }
  7698. const fileEntry = await getFileEntry(zipWriter, name, reader, Object.assign({}, options, {
  7699. rawFilename,
  7700. rawComment,
  7701. version,
  7702. versionMadeBy,
  7703. lastModDate,
  7704. lastAccessDate,
  7705. creationDate,
  7706. rawExtraField,
  7707. zip64,
  7708. password,
  7709. level,
  7710. useWebWorkers,
  7711. encryptionStrength,
  7712. extendedTimestamp,
  7713. zipCrypto,
  7714. bufferedWrite,
  7715. keepOrder,
  7716. dataDescriptor,
  7717. dataDescriptorSignature,
  7718. signal,
  7719. msDosCompatible,
  7720. internalFileAttribute,
  7721. externalFileAttribute
  7722. }));
  7723. if (maximumCompressedSize) {
  7724. zipWriter.pendingCompressedSize -= maximumCompressedSize;
  7725. }
  7726. Object.assign(fileEntry, { name, comment, extraField });
  7727. return new Entry(fileEntry);
  7728. }
  7729. async function getFileEntry(zipWriter, name, reader, options) {
  7730. const files = zipWriter.files;
  7731. const writer = zipWriter.writer;
  7732. const previousFileEntry = Array.from(files.values()).pop();
  7733. let fileEntry = {};
  7734. let bufferedWrite;
  7735. let resolveLockUnbufferedWrite;
  7736. let resolveLockCurrentFileEntry;
  7737. files.set(name, fileEntry);
  7738. try {
  7739. let lockPreviousFileEntry;
  7740. let fileWriter;
  7741. let lockCurrentFileEntry;
  7742. if (options.keepOrder) {
  7743. lockPreviousFileEntry = previousFileEntry && previousFileEntry.lock;
  7744. }
  7745. fileEntry.lock = lockCurrentFileEntry = new Promise(resolve => resolveLockCurrentFileEntry = resolve);
  7746. if (options.bufferedWrite || zipWriter.lockWrite || !options.dataDescriptor) {
  7747. fileWriter = new BlobWriter();
  7748. fileWriter.init();
  7749. bufferedWrite = true;
  7750. } else {
  7751. zipWriter.lockWrite = new Promise(resolve => resolveLockUnbufferedWrite = resolve);
  7752. if (!writer.initialized) {
  7753. await writer.init();
  7754. }
  7755. fileWriter = writer;
  7756. }
  7757. fileEntry = await createFileEntry(reader, fileWriter, zipWriter.config, options);
  7758. fileEntry.lock = lockCurrentFileEntry;
  7759. files.set(name, fileEntry);
  7760. fileEntry.filename = name;
  7761. if (bufferedWrite) {
  7762. let indexWrittenData = 0;
  7763. const blob = fileWriter.getData();
  7764. await Promise.all([zipWriter.lockWrite, lockPreviousFileEntry]);
  7765. let pendingFileEntry;
  7766. do {
  7767. pendingFileEntry = Array.from(files.values()).find(fileEntry => fileEntry.writingBufferedData);
  7768. if (pendingFileEntry) {
  7769. await pendingFileEntry.lock;
  7770. }
  7771. } while (pendingFileEntry && pendingFileEntry.lock);
  7772. fileEntry.writingBufferedData = true;
  7773. if (!options.dataDescriptor) {
  7774. const headerLength = 26;
  7775. const arrayBuffer = await sliceAsArrayBuffer(blob, 0, headerLength);
  7776. const arrayBufferView = new DataView(arrayBuffer);
  7777. if (!fileEntry.encrypted || options.zipCrypto) {
  7778. setUint32(arrayBufferView, 14, fileEntry.signature);
  7779. }
  7780. if (fileEntry.zip64) {
  7781. setUint32(arrayBufferView, 18, MAX_32_BITS);
  7782. setUint32(arrayBufferView, 22, MAX_32_BITS);
  7783. } else {
  7784. setUint32(arrayBufferView, 18, fileEntry.compressedSize);
  7785. setUint32(arrayBufferView, 22, fileEntry.uncompressedSize);
  7786. }
  7787. await writer.writeUint8Array(new Uint8Array(arrayBuffer));
  7788. indexWrittenData = headerLength;
  7789. }
  7790. await writeBlob(writer, blob, indexWrittenData);
  7791. delete fileEntry.writingBufferedData;
  7792. }
  7793. fileEntry.offset = zipWriter.offset;
  7794. if (fileEntry.zip64) {
  7795. const rawExtraFieldZip64View = getDataView(fileEntry.rawExtraFieldZip64);
  7796. setBigUint64(rawExtraFieldZip64View, 20, BigInt(fileEntry.offset));
  7797. } else if (fileEntry.offset >= MAX_32_BITS) {
  7798. throw new Error(ERR_UNSUPPORTED_FORMAT);
  7799. }
  7800. zipWriter.offset += fileEntry.length;
  7801. return fileEntry;
  7802. } catch (error) {
  7803. if ((bufferedWrite && fileEntry.writingBufferedData) || (!bufferedWrite && fileEntry.dataWritten)) {
  7804. error.corruptedEntry = zipWriter.hasCorruptedEntries = true;
  7805. if (fileEntry.uncompressedSize) {
  7806. zipWriter.offset += fileEntry.uncompressedSize;
  7807. }
  7808. }
  7809. files.delete(name);
  7810. throw error;
  7811. } finally {
  7812. resolveLockCurrentFileEntry();
  7813. if (resolveLockUnbufferedWrite) {
  7814. resolveLockUnbufferedWrite();
  7815. }
  7816. }
  7817. }
  7818. async function createFileEntry(reader, writer, config, options) {
  7819. const {
  7820. rawFilename,
  7821. lastAccessDate,
  7822. creationDate,
  7823. password,
  7824. level,
  7825. zip64,
  7826. zipCrypto,
  7827. dataDescriptor,
  7828. dataDescriptorSignature,
  7829. directory,
  7830. version,
  7831. versionMadeBy,
  7832. rawComment,
  7833. rawExtraField,
  7834. useWebWorkers,
  7835. onprogress,
  7836. signal,
  7837. encryptionStrength,
  7838. extendedTimestamp,
  7839. msDosCompatible,
  7840. internalFileAttribute,
  7841. externalFileAttribute
  7842. } = options;
  7843. const encrypted = Boolean(password && password.length);
  7844. const compressed = level !== 0 && !directory;
  7845. let rawExtraFieldAES;
  7846. if (encrypted && !zipCrypto) {
  7847. rawExtraFieldAES = new Uint8Array(EXTRAFIELD_DATA_AES.length + 2);
  7848. const extraFieldAESView = getDataView(rawExtraFieldAES);
  7849. setUint16(extraFieldAESView, 0, EXTRAFIELD_TYPE_AES);
  7850. arraySet(rawExtraFieldAES, EXTRAFIELD_DATA_AES, 2);
  7851. setUint8(extraFieldAESView, 8, encryptionStrength);
  7852. } else {
  7853. rawExtraFieldAES = new Uint8Array(0);
  7854. }
  7855. let rawExtraFieldNTFS;
  7856. let rawExtraFieldExtendedTimestamp;
  7857. if (extendedTimestamp) {
  7858. rawExtraFieldExtendedTimestamp = new Uint8Array(9 + (lastAccessDate ? 4 : 0) + (creationDate ? 4 : 0));
  7859. const extraFieldExtendedTimestampView = getDataView(rawExtraFieldExtendedTimestamp);
  7860. setUint16(extraFieldExtendedTimestampView, 0, EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
  7861. setUint16(extraFieldExtendedTimestampView, 2, rawExtraFieldExtendedTimestamp.length - 4);
  7862. const extraFieldExtendedTimestampFlag = 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0);
  7863. setUint8(extraFieldExtendedTimestampView, 4, extraFieldExtendedTimestampFlag);
  7864. setUint32(extraFieldExtendedTimestampView, 5, Math.floor(options.lastModDate.getTime() / 1000));
  7865. if (lastAccessDate) {
  7866. setUint32(extraFieldExtendedTimestampView, 9, Math.floor(lastAccessDate.getTime() / 1000));
  7867. }
  7868. if (creationDate) {
  7869. setUint32(extraFieldExtendedTimestampView, 13, Math.floor(creationDate.getTime() / 1000));
  7870. }
  7871. try {
  7872. rawExtraFieldNTFS = new Uint8Array(36);
  7873. const extraFieldNTFSView = getDataView(rawExtraFieldNTFS);
  7874. const lastModTimeNTFS = getTimeNTFS(options.lastModDate);
  7875. setUint16(extraFieldNTFSView, 0, EXTRAFIELD_TYPE_NTFS);
  7876. setUint16(extraFieldNTFSView, 2, 32);
  7877. setUint16(extraFieldNTFSView, 8, EXTRAFIELD_TYPE_NTFS_TAG1);
  7878. setUint16(extraFieldNTFSView, 10, 24);
  7879. setBigUint64(extraFieldNTFSView, 12, lastModTimeNTFS);
  7880. setBigUint64(extraFieldNTFSView, 20, getTimeNTFS(lastAccessDate) || lastModTimeNTFS);
  7881. setBigUint64(extraFieldNTFSView, 28, getTimeNTFS(creationDate) || lastModTimeNTFS);
  7882. } catch (_error) {
  7883. rawExtraFieldNTFS = new Uint8Array(0);
  7884. }
  7885. } else {
  7886. rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array(0);
  7887. }
  7888. const fileEntry = {
  7889. version: version || VERSION_DEFLATE,
  7890. versionMadeBy,
  7891. zip64,
  7892. directory: Boolean(directory),
  7893. filenameUTF8: true,
  7894. rawFilename,
  7895. commentUTF8: true,
  7896. rawComment,
  7897. rawExtraFieldZip64: zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array(0),
  7898. rawExtraFieldExtendedTimestamp,
  7899. rawExtraFieldNTFS,
  7900. rawExtraFieldAES,
  7901. rawExtraField,
  7902. extendedTimestamp,
  7903. msDosCompatible,
  7904. internalFileAttribute,
  7905. externalFileAttribute
  7906. };
  7907. let uncompressedSize = fileEntry.uncompressedSize = 0;
  7908. let bitFlag = BITFLAG_LANG_ENCODING_FLAG;
  7909. if (dataDescriptor) {
  7910. bitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;
  7911. }
  7912. let compressionMethod = COMPRESSION_METHOD_STORE;
  7913. if (compressed) {
  7914. compressionMethod = COMPRESSION_METHOD_DEFLATE;
  7915. }
  7916. if (zip64) {
  7917. fileEntry.version = fileEntry.version > VERSION_ZIP64 ? fileEntry.version : VERSION_ZIP64;
  7918. }
  7919. if (encrypted) {
  7920. bitFlag = bitFlag | BITFLAG_ENCRYPTED;
  7921. if (!zipCrypto) {
  7922. fileEntry.version = fileEntry.version > VERSION_AES ? fileEntry.version : VERSION_AES;
  7923. compressionMethod = COMPRESSION_METHOD_AES;
  7924. if (compressed) {
  7925. fileEntry.rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
  7926. }
  7927. }
  7928. }
  7929. fileEntry.compressionMethod = compressionMethod;
  7930. const headerArray = fileEntry.headerArray = new Uint8Array(26);
  7931. const headerView = getDataView(headerArray);
  7932. setUint16(headerView, 0, fileEntry.version);
  7933. setUint16(headerView, 2, bitFlag);
  7934. setUint16(headerView, 4, compressionMethod);
  7935. const dateArray = new Uint32Array(1);
  7936. const dateView = getDataView(dateArray);
  7937. let lastModDate;
  7938. if (options.lastModDate < MIN_DATE) {
  7939. lastModDate = MIN_DATE;
  7940. } else if (options.lastModDate > MAX_DATE) {
  7941. lastModDate = MAX_DATE;
  7942. } else {
  7943. lastModDate = options.lastModDate;
  7944. }
  7945. setUint16(dateView, 0, (((lastModDate.getHours() << 6) | lastModDate.getMinutes()) << 5) | lastModDate.getSeconds() / 2);
  7946. setUint16(dateView, 2, ((((lastModDate.getFullYear() - 1980) << 4) | (lastModDate.getMonth() + 1)) << 5) | lastModDate.getDate());
  7947. const rawLastModDate = dateArray[0];
  7948. setUint32(headerView, 6, rawLastModDate);
  7949. setUint16(headerView, 22, rawFilename.length);
  7950. const extraFieldLength = rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length + fileEntry.rawExtraField.length;
  7951. setUint16(headerView, 24, extraFieldLength);
  7952. const localHeaderArray = new Uint8Array(30 + rawFilename.length + extraFieldLength);
  7953. const localHeaderView = getDataView(localHeaderArray);
  7954. setUint32(localHeaderView, 0, LOCAL_FILE_HEADER_SIGNATURE);
  7955. arraySet(localHeaderArray, headerArray, 4);
  7956. arraySet(localHeaderArray, rawFilename, 30);
  7957. arraySet(localHeaderArray, rawExtraFieldAES, 30 + rawFilename.length);
  7958. arraySet(localHeaderArray, rawExtraFieldExtendedTimestamp, 30 + rawFilename.length + rawExtraFieldAES.length);
  7959. arraySet(localHeaderArray, rawExtraFieldNTFS, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length);
  7960. arraySet(localHeaderArray, fileEntry.rawExtraField, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length);
  7961. let result;
  7962. let compressedSize = 0;
  7963. if (reader) {
  7964. const codec = await createCodec(config.Deflate, {
  7965. codecType: CODEC_DEFLATE,
  7966. level,
  7967. password,
  7968. encryptionStrength,
  7969. zipCrypto: encrypted && zipCrypto,
  7970. passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
  7971. signed: true,
  7972. compressed,
  7973. encrypted,
  7974. useWebWorkers
  7975. }, config);
  7976. await writer.writeUint8Array(localHeaderArray);
  7977. fileEntry.dataWritten = true;
  7978. result = await processData(codec, reader, writer, 0, () => reader.size, config, { onprogress, signal });
  7979. uncompressedSize = fileEntry.uncompressedSize = reader.size;
  7980. compressedSize = result.length;
  7981. } else {
  7982. await writer.writeUint8Array(localHeaderArray);
  7983. fileEntry.dataWritten = true;
  7984. }
  7985. let dataDescriptorArray = new Uint8Array(0);
  7986. let dataDescriptorView, dataDescriptorOffset = 0;
  7987. if (dataDescriptor) {
  7988. dataDescriptorArray = new Uint8Array(zip64 ? (dataDescriptorSignature ? 24 : 20) : (dataDescriptorSignature ? 16 : 12));
  7989. dataDescriptorView = getDataView(dataDescriptorArray);
  7990. if (dataDescriptorSignature) {
  7991. dataDescriptorOffset = 4;
  7992. setUint32(dataDescriptorView, 0, DATA_DESCRIPTOR_RECORD_SIGNATURE);
  7993. }
  7994. }
  7995. if (reader) {
  7996. const signature = result.signature;
  7997. if ((!encrypted || zipCrypto) && signature !== undefined) {
  7998. setUint32(headerView, 10, signature);
  7999. fileEntry.signature = signature;
  8000. if (dataDescriptor) {
  8001. setUint32(dataDescriptorView, dataDescriptorOffset, signature);
  8002. }
  8003. }
  8004. if (zip64) {
  8005. const rawExtraFieldZip64View = getDataView(fileEntry.rawExtraFieldZip64);
  8006. setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
  8007. setUint16(rawExtraFieldZip64View, 2, EXTRAFIELD_LENGTH_ZIP64);
  8008. setUint32(headerView, 14, MAX_32_BITS);
  8009. setBigUint64(rawExtraFieldZip64View, 12, BigInt(compressedSize));
  8010. setUint32(headerView, 18, MAX_32_BITS);
  8011. setBigUint64(rawExtraFieldZip64View, 4, BigInt(uncompressedSize));
  8012. if (dataDescriptor) {
  8013. setBigUint64(dataDescriptorView, dataDescriptorOffset + 4, BigInt(compressedSize));
  8014. setBigUint64(dataDescriptorView, dataDescriptorOffset + 12, BigInt(uncompressedSize));
  8015. }
  8016. } else {
  8017. setUint32(headerView, 14, compressedSize);
  8018. setUint32(headerView, 18, uncompressedSize);
  8019. if (dataDescriptor) {
  8020. setUint32(dataDescriptorView, dataDescriptorOffset + 4, compressedSize);
  8021. setUint32(dataDescriptorView, dataDescriptorOffset + 8, uncompressedSize);
  8022. }
  8023. }
  8024. }
  8025. if (dataDescriptor) {
  8026. await writer.writeUint8Array(dataDescriptorArray);
  8027. }
  8028. const length = localHeaderArray.length + compressedSize + dataDescriptorArray.length;
  8029. Object.assign(fileEntry, { compressedSize, lastModDate, rawLastModDate, creationDate, lastAccessDate, encrypted, length });
  8030. return fileEntry;
  8031. }
  8032. async function closeFile(zipWriter, comment, options) {
  8033. const writer = zipWriter.writer;
  8034. const files = zipWriter.files;
  8035. let offset = 0;
  8036. let directoryDataLength = 0;
  8037. let directoryOffset = zipWriter.offset;
  8038. let filesLength = files.size;
  8039. for (const [, fileEntry] of files) {
  8040. directoryDataLength += 46 +
  8041. fileEntry.rawFilename.length +
  8042. fileEntry.rawComment.length +
  8043. fileEntry.rawExtraFieldZip64.length +
  8044. fileEntry.rawExtraFieldAES.length +
  8045. fileEntry.rawExtraFieldExtendedTimestamp.length +
  8046. fileEntry.rawExtraFieldNTFS.length +
  8047. fileEntry.rawExtraField.length;
  8048. }
  8049. let zip64 = options.zip64 || zipWriter.options.zip64 || false;
  8050. if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) {
  8051. if (options.zip64 === false || zipWriter.options.zip64 === false) {
  8052. throw new Error(ERR_UNSUPPORTED_FORMAT);
  8053. } else {
  8054. zip64 = true;
  8055. }
  8056. }
  8057. const directoryArray = new Uint8Array(directoryDataLength + (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH));
  8058. const directoryView = getDataView(directoryArray);
  8059. if (comment && comment.length) {
  8060. if (comment.length <= MAX_16_BITS) {
  8061. setUint16(directoryView, offset + 20, comment.length);
  8062. } else {
  8063. throw new Error(ERR_INVALID_COMMENT);
  8064. }
  8065. }
  8066. for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
  8067. const {
  8068. rawFilename,
  8069. rawExtraFieldZip64,
  8070. rawExtraFieldAES,
  8071. rawExtraField,
  8072. rawComment,
  8073. versionMadeBy,
  8074. headerArray,
  8075. directory,
  8076. zip64,
  8077. msDosCompatible,
  8078. internalFileAttribute,
  8079. externalFileAttribute
  8080. } = fileEntry;
  8081. let rawExtraFieldExtendedTimestamp;
  8082. let rawExtraFieldNTFS;
  8083. if (fileEntry.extendedTimestamp) {
  8084. rawExtraFieldNTFS = fileEntry.rawExtraFieldNTFS;
  8085. rawExtraFieldExtendedTimestamp = new Uint8Array(9);
  8086. const extraFieldExtendedTimestampView = getDataView(rawExtraFieldExtendedTimestamp);
  8087. setUint16(extraFieldExtendedTimestampView, 0, EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
  8088. setUint16(extraFieldExtendedTimestampView, 2, rawExtraFieldExtendedTimestamp.length - 4);
  8089. setUint8(extraFieldExtendedTimestampView, 4, 0x1);
  8090. setUint32(extraFieldExtendedTimestampView, 5, Math.floor(fileEntry.lastModDate.getTime() / 1000));
  8091. } else {
  8092. rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array(0);
  8093. }
  8094. const extraFieldLength = rawExtraFieldZip64.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length + rawExtraField.length;
  8095. setUint32(directoryView, offset, CENTRAL_FILE_HEADER_SIGNATURE);
  8096. setUint16(directoryView, offset + 4, versionMadeBy);
  8097. arraySet(directoryArray, headerArray, offset + 6);
  8098. setUint16(directoryView, offset + 30, extraFieldLength);
  8099. setUint16(directoryView, offset + 32, rawComment.length);
  8100. setUint32(directoryView, offset + 34, internalFileAttribute);
  8101. if (externalFileAttribute) {
  8102. setUint32(directoryView, offset + 38, externalFileAttribute);
  8103. } else if (directory && msDosCompatible) {
  8104. setUint8(directoryView, offset + 38, FILE_ATTR_MSDOS_DIR_MASK);
  8105. }
  8106. if (zip64) {
  8107. setUint32(directoryView, offset + 42, MAX_32_BITS);
  8108. } else {
  8109. setUint32(directoryView, offset + 42, fileEntry.offset);
  8110. }
  8111. arraySet(directoryArray, rawFilename, offset + 46);
  8112. arraySet(directoryArray, rawExtraFieldZip64, offset + 46 + rawFilename.length);
  8113. arraySet(directoryArray, rawExtraFieldAES, offset + 46 + rawFilename.length + rawExtraFieldZip64.length);
  8114. arraySet(directoryArray, rawExtraFieldExtendedTimestamp, offset + 46 + rawFilename.length + rawExtraFieldZip64.length + rawExtraFieldAES.length);
  8115. arraySet(directoryArray, rawExtraFieldNTFS, offset + 46 + rawFilename.length + rawExtraFieldZip64.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length);
  8116. arraySet(directoryArray, rawExtraField, offset + 46 + rawFilename.length + rawExtraFieldZip64.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length);
  8117. arraySet(directoryArray, rawComment, offset + 46 + rawFilename.length + extraFieldLength);
  8118. offset += 46 + rawFilename.length + extraFieldLength + rawComment.length;
  8119. if (options.onprogress) {
  8120. try {
  8121. options.onprogress(indexFileEntry + 1, files.size, new Entry(fileEntry));
  8122. } catch (_error) {
  8123. // ignored
  8124. }
  8125. }
  8126. }
  8127. if (zip64) {
  8128. setUint32(directoryView, offset, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
  8129. setBigUint64(directoryView, offset + 4, BigInt(44));
  8130. setUint16(directoryView, offset + 12, 45);
  8131. setUint16(directoryView, offset + 14, 45);
  8132. setBigUint64(directoryView, offset + 24, BigInt(filesLength));
  8133. setBigUint64(directoryView, offset + 32, BigInt(filesLength));
  8134. setBigUint64(directoryView, offset + 40, BigInt(directoryDataLength));
  8135. setBigUint64(directoryView, offset + 48, BigInt(directoryOffset));
  8136. setUint32(directoryView, offset + 56, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
  8137. setBigUint64(directoryView, offset + 64, BigInt(directoryOffset) + BigInt(directoryDataLength));
  8138. setUint32(directoryView, offset + 72, ZIP64_TOTAL_NUMBER_OF_DISKS);
  8139. filesLength = MAX_16_BITS;
  8140. directoryOffset = MAX_32_BITS;
  8141. directoryDataLength = MAX_32_BITS;
  8142. offset += 76;
  8143. }
  8144. setUint32(directoryView, offset, END_OF_CENTRAL_DIR_SIGNATURE);
  8145. setUint16(directoryView, offset + 8, filesLength);
  8146. setUint16(directoryView, offset + 10, filesLength);
  8147. setUint32(directoryView, offset + 12, directoryDataLength);
  8148. setUint32(directoryView, offset + 16, directoryOffset);
  8149. await writer.writeUint8Array(directoryArray);
  8150. if (comment && comment.length) {
  8151. await writer.writeUint8Array(comment);
  8152. }
  8153. }
  8154. function sliceAsArrayBuffer(blob, start, end) {
  8155. if (blob.arrayBuffer) {
  8156. if (start || end) {
  8157. return blob.slice(start, end).arrayBuffer();
  8158. } else {
  8159. return blob.arrayBuffer();
  8160. }
  8161. } else {
  8162. const fileReader = new FileReader();
  8163. return new Promise((resolve, reject) => {
  8164. fileReader.onload = event => resolve(event.target.result);
  8165. fileReader.onerror = () => reject(fileReader.error);
  8166. fileReader.readAsArrayBuffer(start || end ? blob.slice(start, end) : blob);
  8167. });
  8168. }
  8169. }
  8170. async function writeBlob(writer, blob, start = 0) {
  8171. const blockSize = 512 * 1024 * 1024;
  8172. await writeSlice();
  8173. async function writeSlice() {
  8174. if (start < blob.size) {
  8175. const arrayBuffer = await sliceAsArrayBuffer(blob, start, start + blockSize);
  8176. await writer.writeUint8Array(new Uint8Array(arrayBuffer));
  8177. start += blockSize;
  8178. await writeSlice();
  8179. }
  8180. }
  8181. }
  8182. function getTimeNTFS(date) {
  8183. if (date) {
  8184. return ((BigInt(date.getTime()) + BigInt(11644473600000)) * BigInt(10000));
  8185. }
  8186. }
  8187. function getOptionValue(zipWriter, options, name) {
  8188. return options[name] === undefined ? zipWriter.options[name] : options[name];
  8189. }
  8190. function getMaximumCompressedSize(uncompressedSize) {
  8191. return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
  8192. }
  8193. function setUint8(view, offset, value) {
  8194. view.setUint8(offset, value);
  8195. }
  8196. function setUint16(view, offset, value) {
  8197. view.setUint16(offset, value, true);
  8198. }
  8199. function setUint32(view, offset, value) {
  8200. view.setUint32(offset, value, true);
  8201. }
  8202. function setBigUint64(view, offset, value) {
  8203. view.setBigUint64(offset, value, true);
  8204. }
  8205. function arraySet(array, typedArray, offset) {
  8206. array.set(typedArray, offset);
  8207. }
  8208. function getDataView(array) {
  8209. return new DataView(array.buffer);
  8210. }
  8211. /*
  8212. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  8213. Redistribution and use in source and binary forms, with or without
  8214. modification, are permitted provided that the following conditions are met:
  8215. 1. Redistributions of source code must retain the above copyright notice,
  8216. this list of conditions and the following disclaimer.
  8217. 2. Redistributions in binary form must reproduce the above copyright
  8218. notice, this list of conditions and the following disclaimer in
  8219. the documentation and/or other materials provided with the distribution.
  8220. 3. The names of the authors may not be used to endorse or promote products
  8221. derived from this software without specific prior written permission.
  8222. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  8223. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  8224. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  8225. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  8226. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  8227. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  8228. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  8229. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  8230. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  8231. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8232. */
  8233. const CHUNK_SIZE = 512 * 1024;
  8234. class ZipEntry {
  8235. constructor(fs, name, params, parent) {
  8236. const zipEntry = this;
  8237. if (fs.root && parent && parent.getChildByName(name)) {
  8238. throw new Error("Entry filename already exists");
  8239. }
  8240. if (!params) {
  8241. params = {};
  8242. }
  8243. Object.assign(zipEntry, {
  8244. fs,
  8245. name,
  8246. data: params.data,
  8247. id: fs.entries.length,
  8248. parent,
  8249. children: [],
  8250. uncompressedSize: 0
  8251. });
  8252. fs.entries.push(zipEntry);
  8253. if (parent) {
  8254. zipEntry.parent.children.push(zipEntry);
  8255. }
  8256. }
  8257. moveTo(target) {
  8258. // deprecated
  8259. const zipEntry = this;
  8260. zipEntry.fs.move(zipEntry, target);
  8261. }
  8262. getFullname() {
  8263. return this.getRelativeName();
  8264. }
  8265. getRelativeName(ancestor = this.fs.root) {
  8266. const zipEntry = this;
  8267. let relativeName = zipEntry.name;
  8268. let entry = zipEntry.parent;
  8269. while (entry && entry != ancestor) {
  8270. relativeName = (entry.name ? entry.name + "/" : "") + relativeName;
  8271. entry = entry.parent;
  8272. }
  8273. return relativeName;
  8274. }
  8275. isDescendantOf(ancestor) {
  8276. let entry = this.parent;
  8277. while (entry && entry.id != ancestor.id) {
  8278. entry = entry.parent;
  8279. }
  8280. return Boolean(entry);
  8281. }
  8282. }
  8283. class ZipFileEntry extends ZipEntry {
  8284. constructor(fs, name, params, parent) {
  8285. super(fs, name, params, parent);
  8286. const zipEntry = this;
  8287. zipEntry.Reader = params.Reader;
  8288. zipEntry.Writer = params.Writer;
  8289. if (params.getData) {
  8290. zipEntry.getData = params.getData;
  8291. }
  8292. }
  8293. async getData(writer, options = {}) {
  8294. const zipEntry = this;
  8295. if (!writer || (writer.constructor == zipEntry.Writer && zipEntry.data)) {
  8296. return zipEntry.data;
  8297. } else {
  8298. zipEntry.reader = new zipEntry.Reader(zipEntry.data, options);
  8299. await zipEntry.reader.init();
  8300. if (!writer.initialized) {
  8301. await writer.init();
  8302. }
  8303. zipEntry.uncompressedSize = zipEntry.reader.size;
  8304. return pipe(zipEntry.reader, writer);
  8305. }
  8306. }
  8307. getText(encoding, options) {
  8308. return this.getData(new TextWriter(encoding), options);
  8309. }
  8310. getBlob(mimeType, options) {
  8311. return this.getData(new BlobWriter(mimeType), options);
  8312. }
  8313. getData64URI(mimeType, options) {
  8314. return this.getData(new Data64URIWriter(mimeType), options);
  8315. }
  8316. getUint8Array(options) {
  8317. return this.getData(new Uint8ArrayWriter(), options);
  8318. }
  8319. replaceBlob(blob) {
  8320. Object.assign(this, {
  8321. data: blob,
  8322. Reader: BlobReader,
  8323. Writer: BlobWriter,
  8324. reader: null
  8325. });
  8326. }
  8327. replaceText(text) {
  8328. Object.assign(this, {
  8329. data: text,
  8330. Reader: TextReader,
  8331. Writer: TextWriter,
  8332. reader: null
  8333. });
  8334. }
  8335. replaceData64URI(dataURI) {
  8336. Object.assign(this, {
  8337. data: dataURI,
  8338. Reader: Data64URIReader,
  8339. Writer: Data64URIWriter,
  8340. reader: null
  8341. });
  8342. }
  8343. replaceUint8Array(array) {
  8344. Object.assign(this, {
  8345. data: array,
  8346. Reader: Uint8ArrayReader,
  8347. Writer: Uint8ArrayWriter,
  8348. reader: null
  8349. });
  8350. }
  8351. }
  8352. class ZipDirectoryEntry extends ZipEntry {
  8353. constructor(fs, name, params, parent) {
  8354. super(fs, name, params, parent);
  8355. this.directory = true;
  8356. }
  8357. addDirectory(name) {
  8358. return addChild(this, name, null, true);
  8359. }
  8360. addText(name, text) {
  8361. return addChild(this, name, {
  8362. data: text,
  8363. Reader: TextReader,
  8364. Writer: TextWriter
  8365. });
  8366. }
  8367. addBlob(name, blob) {
  8368. return addChild(this, name, {
  8369. data: blob,
  8370. Reader: BlobReader,
  8371. Writer: BlobWriter
  8372. });
  8373. }
  8374. addData64URI(name, dataURI) {
  8375. return addChild(this, name, {
  8376. data: dataURI,
  8377. Reader: Data64URIReader,
  8378. Writer: Data64URIWriter
  8379. });
  8380. }
  8381. addUint8Array(name, array) {
  8382. return addChild(this, name, {
  8383. data: array,
  8384. Reader: Uint8ArrayReader,
  8385. Writer: Uint8ArrayWriter
  8386. });
  8387. }
  8388. addHttpContent(name, url, options = {}) {
  8389. return addChild(this, name, {
  8390. data: url,
  8391. Reader: class extends HttpReader {
  8392. constructor(url) {
  8393. super(url, options);
  8394. }
  8395. }
  8396. });
  8397. }
  8398. addFileSystemEntry(fileSystemEntry) {
  8399. return addFileSystemEntry(this, fileSystemEntry);
  8400. }
  8401. addData(name, params) {
  8402. return addChild(this, name, params);
  8403. }
  8404. async importBlob(blob, options = {}) {
  8405. await this.importZip(new BlobReader(blob), options);
  8406. }
  8407. async importData64URI(dataURI, options = {}) {
  8408. await this.importZip(new Data64URIReader(dataURI), options);
  8409. }
  8410. async importUint8Array(array, options = {}) {
  8411. await this.importZip(new Uint8ArrayReader(array), options);
  8412. }
  8413. async importHttpContent(url, options = {}) {
  8414. await this.importZip(new HttpReader(url, options), options);
  8415. }
  8416. exportBlob(options = {}) {
  8417. return this.exportZip(new BlobWriter("application/zip"), options);
  8418. }
  8419. exportData64URI(options = {}) {
  8420. return this.exportZip(new Data64URIWriter("application/zip"), options);
  8421. }
  8422. exportUint8Array(options = {}) {
  8423. return this.exportZip(new Uint8ArrayWriter(), options);
  8424. }
  8425. async importZip(reader, options) {
  8426. if (!reader.initialized) {
  8427. await reader.init();
  8428. }
  8429. const zipReader = new ZipReader(reader, options);
  8430. const entries = await zipReader.getEntries();
  8431. entries.forEach((entry) => {
  8432. let parent = this;
  8433. const path = entry.filename.split("/");
  8434. const name = path.pop();
  8435. path.forEach(pathPart => parent = parent.getChildByName(pathPart) || new ZipDirectoryEntry(this.fs, pathPart, null, parent));
  8436. if (!entry.directory) {
  8437. addChild(parent, name, {
  8438. data: entry,
  8439. Reader: getZipBlobReader(Object.assign({}, options))
  8440. });
  8441. }
  8442. });
  8443. }
  8444. async exportZip(writer, options) {
  8445. const zipEntry = this;
  8446. await initReaders(zipEntry);
  8447. await writer.init();
  8448. const zipWriter = new ZipWriter(writer, options);
  8449. await exportZip(zipWriter, zipEntry, getTotalSize([zipEntry], "uncompressedSize"), options);
  8450. await zipWriter.close();
  8451. return writer.getData();
  8452. }
  8453. getChildByName(name) {
  8454. const children = this.children;
  8455. for (let childIndex = 0; childIndex < children.length; childIndex++) {
  8456. const child = children[childIndex];
  8457. if (child.name == name) {
  8458. return child;
  8459. }
  8460. }
  8461. }
  8462. }
  8463. class FS {
  8464. constructor() {
  8465. resetFS(this);
  8466. }
  8467. get children() {
  8468. return this.root.children;
  8469. }
  8470. remove(entry) {
  8471. detach(entry);
  8472. this.entries[entry.id] = null;
  8473. }
  8474. move(entry, destination) {
  8475. if (entry == this.root) {
  8476. throw new Error("Root directory cannot be moved");
  8477. } else {
  8478. if (destination.directory) {
  8479. if (!destination.isDescendantOf(entry)) {
  8480. if (entry != destination) {
  8481. if (destination.getChildByName(entry.name)) {
  8482. throw new Error("Entry filename already exists");
  8483. }
  8484. detach(entry);
  8485. entry.parent = destination;
  8486. destination.children.push(entry);
  8487. }
  8488. } else {
  8489. throw new Error("Entry is a ancestor of target entry");
  8490. }
  8491. } else {
  8492. throw new Error("Target entry is not a directory");
  8493. }
  8494. }
  8495. }
  8496. find(fullname) {
  8497. const path = fullname.split("/");
  8498. let node = this.root;
  8499. for (let index = 0; node && index < path.length; index++) {
  8500. node = node.getChildByName(path[index]);
  8501. }
  8502. return node;
  8503. }
  8504. getById(id) {
  8505. return this.entries[id];
  8506. }
  8507. getChildByName(name) {
  8508. return this.root.getChildByName(name);
  8509. }
  8510. addDirectory(name) {
  8511. return this.root.addDirectory(name);
  8512. }
  8513. addText(name, text) {
  8514. return this.root.addText(name, text);
  8515. }
  8516. addBlob(name, blob) {
  8517. return this.root.addBlob(name, blob);
  8518. }
  8519. addData64URI(name, dataURI) {
  8520. return this.root.addData64URI(name, dataURI);
  8521. }
  8522. addHttpContent(name, url, options) {
  8523. return this.root.addHttpContent(name, url, options);
  8524. }
  8525. addFileSystemEntry(fileSystemEntry) {
  8526. return this.root.addFileSystemEntry(fileSystemEntry);
  8527. }
  8528. addData(name, params) {
  8529. return this.root.addData(name, params);
  8530. }
  8531. async importBlob(blob, options) {
  8532. resetFS(this);
  8533. await this.root.importBlob(blob, options);
  8534. }
  8535. async importData64URI(dataURI, options) {
  8536. resetFS(this);
  8537. await this.root.importData64URI(dataURI, options);
  8538. }
  8539. async importHttpContent(url, options) {
  8540. resetFS(this);
  8541. await this.root.importHttpContent(url, options);
  8542. }
  8543. exportBlob(options) {
  8544. return this.root.exportBlob(options);
  8545. }
  8546. exportData64URI(options) {
  8547. return this.root.exportData64URI(options);
  8548. }
  8549. }
  8550. const fs = { FS, ZipDirectoryEntry, ZipFileEntry };
  8551. function getTotalSize(entries, propertyName) {
  8552. let size = 0;
  8553. entries.forEach(process);
  8554. return size;
  8555. function process(entry) {
  8556. size += entry[propertyName];
  8557. if (entry.children) {
  8558. entry.children.forEach(process);
  8559. }
  8560. }
  8561. }
  8562. function getZipBlobReader(options) {
  8563. return class extends Reader {
  8564. constructor(entry, options = {}) {
  8565. super();
  8566. this.entry = entry;
  8567. this.options = options;
  8568. }
  8569. async init() {
  8570. const zipBlobReader = this;
  8571. zipBlobReader.size = zipBlobReader.entry.uncompressedSize;
  8572. const data = await zipBlobReader.entry.getData(new BlobWriter(), Object.assign({}, zipBlobReader.options, options));
  8573. zipBlobReader.data = data;
  8574. zipBlobReader.blobReader = new BlobReader(data);
  8575. }
  8576. readUint8Array(index, length) {
  8577. return this.blobReader.readUint8Array(index, length);
  8578. }
  8579. };
  8580. }
  8581. async function initReaders(entry) {
  8582. if (entry.children.length) {
  8583. for (const child of entry.children) {
  8584. if (child.directory) {
  8585. await initReaders(child);
  8586. } else {
  8587. child.reader = new child.Reader(child.data);
  8588. await child.reader.init();
  8589. child.uncompressedSize = child.reader.size;
  8590. }
  8591. }
  8592. }
  8593. }
  8594. function detach(entry) {
  8595. const children = entry.parent.children;
  8596. children.forEach((child, index) => {
  8597. if (child.id == entry.id) {
  8598. children.splice(index, 1);
  8599. }
  8600. });
  8601. }
  8602. async function exportZip(zipWriter, entry, totalSize, options) {
  8603. const selectedEntry = entry;
  8604. const entryOffsets = new Map();
  8605. await process(zipWriter, entry);
  8606. async function process(zipWriter, entry) {
  8607. await exportChild();
  8608. async function exportChild() {
  8609. if (options.bufferedWrite) {
  8610. await Promise.all(entry.children.map(processChild));
  8611. } else {
  8612. for (const child of entry.children) {
  8613. await processChild(child);
  8614. }
  8615. }
  8616. }
  8617. async function processChild(child) {
  8618. const name = options.relativePath ? child.getRelativeName(selectedEntry) : child.getFullname();
  8619. await zipWriter.add(name, child.reader, Object.assign({
  8620. directory: child.directory
  8621. }, Object.assign({}, options, {
  8622. onprogress: indexProgress => {
  8623. if (options.onprogress) {
  8624. entryOffsets.set(name, indexProgress);
  8625. try {
  8626. options.onprogress(Array.from(entryOffsets.values()).reduce((previousValue, currentValue) => previousValue + currentValue), totalSize);
  8627. } catch (_error) {
  8628. // ignored
  8629. }
  8630. }
  8631. }
  8632. })));
  8633. await process(zipWriter, child);
  8634. }
  8635. }
  8636. }
  8637. async function addFileSystemEntry(zipEntry, fileSystemEntry) {
  8638. if (fileSystemEntry.isDirectory) {
  8639. const entry = zipEntry.addDirectory(fileSystemEntry.name);
  8640. await addDirectory(entry, fileSystemEntry);
  8641. return entry;
  8642. } else {
  8643. return new Promise((resolve, reject) => fileSystemEntry.file(file => resolve(zipEntry.addBlob(fileSystemEntry.name, file)), reject));
  8644. }
  8645. async function addDirectory(zipEntry, fileEntry) {
  8646. const children = await getChildren(fileEntry);
  8647. for (const child of children) {
  8648. if (child.isDirectory) {
  8649. await addDirectory(zipEntry.addDirectory(child.name), child);
  8650. } else {
  8651. await new Promise((resolve, reject) => {
  8652. child.file(file => {
  8653. const childZipEntry = zipEntry.addBlob(child.name, file);
  8654. childZipEntry.uncompressedSize = file.size;
  8655. resolve(childZipEntry);
  8656. }, reject);
  8657. });
  8658. }
  8659. }
  8660. }
  8661. function getChildren(fileEntry) {
  8662. return new Promise((resolve, reject) => {
  8663. let entries = [];
  8664. if (fileEntry.isDirectory) {
  8665. readEntries(fileEntry.createReader());
  8666. }
  8667. if (fileEntry.isFile) {
  8668. resolve(entries);
  8669. }
  8670. function readEntries(directoryReader) {
  8671. directoryReader.readEntries(temporaryEntries => {
  8672. if (!temporaryEntries.length) {
  8673. resolve(entries);
  8674. } else {
  8675. entries = entries.concat(temporaryEntries);
  8676. readEntries(directoryReader);
  8677. }
  8678. }, reject);
  8679. }
  8680. });
  8681. }
  8682. }
  8683. function resetFS(fs) {
  8684. fs.entries = [];
  8685. fs.root = new ZipDirectoryEntry(fs);
  8686. }
  8687. function pipe(reader, writer) {
  8688. return copyChunk();
  8689. async function copyChunk(chunkIndex = 0) {
  8690. const index = chunkIndex * CHUNK_SIZE;
  8691. if (index < reader.size) {
  8692. const array = await reader.readUint8Array(index, Math.min(CHUNK_SIZE, reader.size - index));
  8693. await writer.writeUint8Array(array);
  8694. return copyChunk(chunkIndex + 1);
  8695. } else {
  8696. return writer.getData();
  8697. }
  8698. }
  8699. }
  8700. function addChild(parent, name, params, directory) {
  8701. if (parent.directory) {
  8702. return directory ? new ZipDirectoryEntry(parent.fs, name, params, parent) : new ZipFileEntry(parent.fs, name, params, parent);
  8703. } else {
  8704. throw new Error("Parent entry is not a directory");
  8705. }
  8706. }
  8707. /*
  8708. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  8709. Redistribution and use in source and binary forms, with or without
  8710. modification, are permitted provided that the following conditions are met:
  8711. 1. Redistributions of source code must retain the above copyright notice,
  8712. this list of conditions and the following disclaimer.
  8713. 2. Redistributions in binary form must reproduce the above copyright
  8714. notice, this list of conditions and the following disclaimer in
  8715. the documentation and/or other materials provided with the distribution.
  8716. 3. The names of the authors may not be used to endorse or promote products
  8717. derived from this software without specific prior written permission.
  8718. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  8719. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  8720. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  8721. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  8722. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  8723. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  8724. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  8725. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  8726. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  8727. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8728. */
  8729. let baseURL;
  8730. try {
  8731. 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-fs-full.js', document.baseURI).href));
  8732. } catch (_error) {
  8733. // ignored
  8734. }
  8735. configure({ baseURL });
  8736. t(configure);
  8737. /// <reference types="./index.d.ts" />
  8738. configure({ Deflate: ZipDeflate, Inflate: ZipInflate });
  8739. exports.BlobReader = BlobReader;
  8740. exports.BlobWriter = BlobWriter;
  8741. exports.Data64URIReader = Data64URIReader;
  8742. exports.Data64URIWriter = Data64URIWriter;
  8743. exports.ERR_ABORT = ERR_ABORT;
  8744. exports.ERR_BAD_FORMAT = ERR_BAD_FORMAT;
  8745. exports.ERR_CENTRAL_DIRECTORY_NOT_FOUND = ERR_CENTRAL_DIRECTORY_NOT_FOUND;
  8746. exports.ERR_DUPLICATED_NAME = ERR_DUPLICATED_NAME;
  8747. exports.ERR_ENCRYPTED = ERR_ENCRYPTED;
  8748. exports.ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND;
  8749. exports.ERR_EOCDR_NOT_FOUND = ERR_EOCDR_NOT_FOUND;
  8750. exports.ERR_EOCDR_ZIP64_NOT_FOUND = ERR_EOCDR_ZIP64_NOT_FOUND;
  8751. exports.ERR_EXTRAFIELD_ZIP64_NOT_FOUND = ERR_EXTRAFIELD_ZIP64_NOT_FOUND;
  8752. exports.ERR_HTTP_RANGE = ERR_HTTP_RANGE;
  8753. exports.ERR_INVALID_COMMENT = ERR_INVALID_COMMENT;
  8754. exports.ERR_INVALID_ENCRYPTION_STRENGTH = ERR_INVALID_ENCRYPTION_STRENGTH;
  8755. exports.ERR_INVALID_ENTRY_COMMENT = ERR_INVALID_ENTRY_COMMENT;
  8756. exports.ERR_INVALID_ENTRY_NAME = ERR_INVALID_ENTRY_NAME;
  8757. exports.ERR_INVALID_EXTRAFIELD_DATA = ERR_INVALID_EXTRAFIELD_DATA;
  8758. exports.ERR_INVALID_EXTRAFIELD_TYPE = ERR_INVALID_EXTRAFIELD_TYPE;
  8759. exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
  8760. exports.ERR_INVALID_SIGNATURE = ERR_INVALID_SIGNATURE;
  8761. exports.ERR_INVALID_VERSION = ERR_INVALID_VERSION;
  8762. exports.ERR_LOCAL_FILE_HEADER_NOT_FOUND = ERR_LOCAL_FILE_HEADER_NOT_FOUND;
  8763. exports.ERR_NOT_SEEKABLE_READER = ERR_NOT_SEEKABLE_READER;
  8764. exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION;
  8765. exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
  8766. exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
  8767. exports.HttpRangeReader = HttpRangeReader;
  8768. exports.HttpReader = HttpReader;
  8769. exports.ReadableStreamReader = ReadableStreamReader;
  8770. exports.Reader = Reader;
  8771. exports.TextReader = TextReader;
  8772. exports.TextWriter = TextWriter;
  8773. exports.Uint8ArrayReader = Uint8ArrayReader;
  8774. exports.Uint8ArrayWriter = Uint8ArrayWriter;
  8775. exports.WritableStreamWriter = WritableStreamWriter;
  8776. exports.Writer = Writer;
  8777. exports.ZipReader = ZipReader;
  8778. exports.ZipWriter = ZipWriter;
  8779. exports.configure = configure;
  8780. exports.fs = fs;
  8781. exports.getMimeType = getMimeType;
  8782. exports.initShimAsyncCodec = streamCodecShim;
  8783. exports.terminateWorkers = terminateWorkers;
  8784. Object.defineProperty(exports, '__esModule', { value: true });
  8785. }));