zip-fs.js 196 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686
  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. /* global navigator */
  30. const DEFAULT_CONFIGURATION = {
  31. chunkSize: 512 * 1024,
  32. maxWorkers: (typeof navigator != "undefined" && navigator.hardwareConcurrency) || 2,
  33. terminateWorkerTimeout: 5000,
  34. useWebWorkers: true,
  35. workerScripts: undefined
  36. };
  37. const config = Object.assign({}, DEFAULT_CONFIGURATION);
  38. function getConfiguration() {
  39. return config;
  40. }
  41. function configure(configuration) {
  42. if (configuration.baseURL !== undefined) {
  43. config.baseURL = configuration.baseURL;
  44. }
  45. if (configuration.chunkSize !== undefined) {
  46. config.chunkSize = configuration.chunkSize;
  47. }
  48. if (configuration.maxWorkers !== undefined) {
  49. config.maxWorkers = configuration.maxWorkers;
  50. }
  51. if (configuration.terminateWorkerTimeout !== undefined) {
  52. config.terminateWorkerTimeout = configuration.terminateWorkerTimeout;
  53. }
  54. if (configuration.useWebWorkers !== undefined) {
  55. config.useWebWorkers = configuration.useWebWorkers;
  56. }
  57. if (configuration.Deflate !== undefined) {
  58. config.Deflate = configuration.Deflate;
  59. }
  60. if (configuration.Inflate !== undefined) {
  61. config.Inflate = configuration.Inflate;
  62. }
  63. if (configuration.workerScripts !== undefined) {
  64. if (configuration.workerScripts.deflate) {
  65. if (!Array.isArray(configuration.workerScripts.deflate)) {
  66. throw new Error("workerScripts.deflate must be an array");
  67. }
  68. if (!config.workerScripts) {
  69. config.workerScripts = {};
  70. }
  71. config.workerScripts.deflate = configuration.workerScripts.deflate;
  72. }
  73. if (configuration.workerScripts.inflate) {
  74. if (!Array.isArray(configuration.workerScripts.inflate)) {
  75. throw new Error("workerScripts.inflate must be an array");
  76. }
  77. if (!config.workerScripts) {
  78. config.workerScripts = {};
  79. }
  80. config.workerScripts.inflate = configuration.workerScripts.inflate;
  81. }
  82. }
  83. }
  84. 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]}});}};
  85. /*
  86. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  87. Redistribution and use in source and binary forms, with or without
  88. modification, are permitted provided that the following conditions are met:
  89. 1. Redistributions of source code must retain the above copyright notice,
  90. this list of conditions and the following disclaimer.
  91. 2. Redistributions in binary form must reproduce the above copyright
  92. notice, this list of conditions and the following disclaimer in
  93. the documentation and/or other materials provided with the distribution.
  94. 3. The names of the authors may not be used to endorse or promote products
  95. derived from this software without specific prior written permission.
  96. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  97. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  98. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  99. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  100. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  101. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  102. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  103. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  104. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  105. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  106. */
  107. function getMimeType() {
  108. return "application/octet-stream";
  109. }
  110. /*
  111. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  112. Redistribution and use in source and binary forms, with or without
  113. modification, are permitted provided that the following conditions are met:
  114. 1. Redistributions of source code must retain the above copyright notice,
  115. this list of conditions and the following disclaimer.
  116. 2. Redistributions in binary form must reproduce the above copyright
  117. notice, this list of conditions and the following disclaimer in
  118. the documentation and/or other materials provided with the distribution.
  119. 3. The names of the authors may not be used to endorse or promote products
  120. derived from this software without specific prior written permission.
  121. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  122. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  123. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  124. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  125. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  126. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  127. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  128. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  129. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  130. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  131. */
  132. var streamCodecShim = (library, options = {}, registerDataHandler) => {
  133. return {
  134. Deflate: createCodecClass(library.Deflate, options.deflate, registerDataHandler),
  135. Inflate: createCodecClass(library.Inflate, options.inflate, registerDataHandler)
  136. };
  137. };
  138. function createCodecClass(constructor, constructorOptions, registerDataHandler) {
  139. return class {
  140. constructor(options) {
  141. const codecAdapter = this;
  142. const onData = data => {
  143. if (codecAdapter.pendingData) {
  144. const pendingData = codecAdapter.pendingData;
  145. codecAdapter.pendingData = new Uint8Array(pendingData.length + data.length);
  146. codecAdapter.pendingData.set(pendingData, 0);
  147. codecAdapter.pendingData.set(data, pendingData.length);
  148. } else {
  149. codecAdapter.pendingData = new Uint8Array(data);
  150. }
  151. };
  152. codecAdapter.codec = new constructor(Object.assign({}, constructorOptions, options));
  153. registerDataHandler(codecAdapter.codec, onData);
  154. }
  155. append(data) {
  156. this.codec.push(data);
  157. return getResponse(this);
  158. }
  159. flush() {
  160. this.codec.push(new Uint8Array(0), true);
  161. return getResponse(this);
  162. }
  163. };
  164. function getResponse(codec) {
  165. if (codec.pendingData) {
  166. const output = codec.pendingData;
  167. codec.pendingData = null;
  168. return output;
  169. } else {
  170. return new Uint8Array(0);
  171. }
  172. }
  173. }
  174. /*
  175. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  176. Redistribution and use in source and binary forms, with or without
  177. modification, are permitted provided that the following conditions are met:
  178. 1. Redistributions of source code must retain the above copyright notice,
  179. this list of conditions and the following disclaimer.
  180. 2. Redistributions in binary form must reproduce the above copyright
  181. notice, this list of conditions and the following disclaimer in
  182. the documentation and/or other materials provided with the distribution.
  183. 3. The names of the authors may not be used to endorse or promote products
  184. derived from this software without specific prior written permission.
  185. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  186. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  187. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  188. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  189. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  190. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  191. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  192. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  193. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  194. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  195. */
  196. const table = [];
  197. for (let i = 0; i < 256; i++) {
  198. let t = i;
  199. for (let j = 0; j < 8; j++) {
  200. if (t & 1) {
  201. t = (t >>> 1) ^ 0xEDB88320;
  202. } else {
  203. t = t >>> 1;
  204. }
  205. }
  206. table[i] = t;
  207. }
  208. class Crc32 {
  209. constructor(crc) {
  210. this.crc = crc || -1;
  211. }
  212. append(data) {
  213. let crc = this.crc | 0;
  214. for (let offset = 0, length = data.length | 0; offset < length; offset++) {
  215. crc = (crc >>> 8) ^ table[(crc ^ data[offset]) & 0xFF];
  216. }
  217. this.crc = crc;
  218. }
  219. get() {
  220. return ~this.crc;
  221. }
  222. }
  223. /*
  224. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  225. Redistribution and use in source and binary forms, with or without
  226. modification, are permitted provided that the following conditions are met:
  227. 1. Redistributions of source code must retain the above copyright notice,
  228. this list of conditions and the following disclaimer.
  229. 2. Redistributions in binary form must reproduce the above copyright
  230. notice, this list of conditions and the following disclaimer in
  231. the documentation and/or other materials provided with the distribution.
  232. 3. The names of the authors may not be used to endorse or promote products
  233. derived from this software without specific prior written permission.
  234. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  235. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  236. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  237. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  238. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  239. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  240. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  241. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  242. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  243. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  244. */
  245. function encodeText(value) {
  246. if (typeof TextEncoder == "undefined") {
  247. value = unescape(encodeURIComponent(value));
  248. const result = new Uint8Array(value.length);
  249. for (let i = 0; i < result.length; i++) {
  250. result[i] = value.charCodeAt(i);
  251. }
  252. return result;
  253. } else {
  254. return new TextEncoder().encode(value);
  255. }
  256. }
  257. // Derived from https://github.com/xqdoo00o/jszip/blob/master/lib/sjcl.js and https://github.com/bitwiseshiftleft/sjcl
  258. /*// deno-lint-ignore-file no-this-alias *
  259. /*
  260. * SJCL is open. You can use, modify and redistribute it under a BSD
  261. * license or under the GNU GPL, version 2.0.
  262. */
  263. /** @fileOverview Javascript cryptography implementation.
  264. *
  265. * Crush to remove comments, shorten variable names and
  266. * generally reduce transmission size.
  267. *
  268. * @author Emily Stark
  269. * @author Mike Hamburg
  270. * @author Dan Boneh
  271. */
  272. /*jslint indent: 2, bitwise: false, nomen: false, plusplus: false, white: false, regexp: false */
  273. /** @fileOverview Arrays of bits, encoded as arrays of Numbers.
  274. *
  275. * @author Emily Stark
  276. * @author Mike Hamburg
  277. * @author Dan Boneh
  278. */
  279. /**
  280. * Arrays of bits, encoded as arrays of Numbers.
  281. * @namespace
  282. * @description
  283. * <p>
  284. * These objects are the currency accepted by SJCL's crypto functions.
  285. * </p>
  286. *
  287. * <p>
  288. * Most of our crypto primitives operate on arrays of 4-byte words internally,
  289. * but many of them can take arguments that are not a multiple of 4 bytes.
  290. * This library encodes arrays of bits (whose size need not be a multiple of 8
  291. * bits) as arrays of 32-bit words. The bits are packed, big-endian, into an
  292. * array of words, 32 bits at a time. Since the words are double-precision
  293. * floating point numbers, they fit some extra data. We use this (in a private,
  294. * possibly-changing manner) to encode the number of bits actually present
  295. * in the last word of the array.
  296. * </p>
  297. *
  298. * <p>
  299. * Because bitwise ops clear this out-of-band data, these arrays can be passed
  300. * to ciphers like AES which want arrays of words.
  301. * </p>
  302. */
  303. const bitArray = {
  304. /**
  305. * Concatenate two bit arrays.
  306. * @param {bitArray} a1 The first array.
  307. * @param {bitArray} a2 The second array.
  308. * @return {bitArray} The concatenation of a1 and a2.
  309. */
  310. concat(a1, a2) {
  311. if (a1.length === 0 || a2.length === 0) {
  312. return a1.concat(a2);
  313. }
  314. const last = a1[a1.length - 1], shift = bitArray.getPartial(last);
  315. if (shift === 32) {
  316. return a1.concat(a2);
  317. } else {
  318. return bitArray._shiftRight(a2, shift, last | 0, a1.slice(0, a1.length - 1));
  319. }
  320. },
  321. /**
  322. * Find the length of an array of bits.
  323. * @param {bitArray} a The array.
  324. * @return {Number} The length of a, in bits.
  325. */
  326. bitLength(a) {
  327. const l = a.length;
  328. if (l === 0) {
  329. return 0;
  330. }
  331. const x = a[l - 1];
  332. return (l - 1) * 32 + bitArray.getPartial(x);
  333. },
  334. /**
  335. * Truncate an array.
  336. * @param {bitArray} a The array.
  337. * @param {Number} len The length to truncate to, in bits.
  338. * @return {bitArray} A new array, truncated to len bits.
  339. */
  340. clamp(a, len) {
  341. if (a.length * 32 < len) {
  342. return a;
  343. }
  344. a = a.slice(0, Math.ceil(len / 32));
  345. const l = a.length;
  346. len = len & 31;
  347. if (l > 0 && len) {
  348. a[l - 1] = bitArray.partial(len, a[l - 1] & 0x80000000 >> (len - 1), 1);
  349. }
  350. return a;
  351. },
  352. /**
  353. * Make a partial word for a bit array.
  354. * @param {Number} len The number of bits in the word.
  355. * @param {Number} x The bits.
  356. * @param {Number} [_end=0] Pass 1 if x has already been shifted to the high side.
  357. * @return {Number} The partial word.
  358. */
  359. partial(len, x, _end) {
  360. if (len === 32) {
  361. return x;
  362. }
  363. return (_end ? x | 0 : x << (32 - len)) + len * 0x10000000000;
  364. },
  365. /**
  366. * Get the number of bits used by a partial word.
  367. * @param {Number} x The partial word.
  368. * @return {Number} The number of bits used by the partial word.
  369. */
  370. getPartial(x) {
  371. return Math.round(x / 0x10000000000) || 32;
  372. },
  373. /** Shift an array right.
  374. * @param {bitArray} a The array to shift.
  375. * @param {Number} shift The number of bits to shift.
  376. * @param {Number} [carry=0] A byte to carry in
  377. * @param {bitArray} [out=[]] An array to prepend to the output.
  378. * @private
  379. */
  380. _shiftRight(a, shift, carry, out) {
  381. if (out === undefined) {
  382. out = [];
  383. }
  384. for (; shift >= 32; shift -= 32) {
  385. out.push(carry);
  386. carry = 0;
  387. }
  388. if (shift === 0) {
  389. return out.concat(a);
  390. }
  391. for (let i = 0; i < a.length; i++) {
  392. out.push(carry | a[i] >>> shift);
  393. carry = a[i] << (32 - shift);
  394. }
  395. const last2 = a.length ? a[a.length - 1] : 0;
  396. const shift2 = bitArray.getPartial(last2);
  397. out.push(bitArray.partial(shift + shift2 & 31, (shift + shift2 > 32) ? carry : out.pop(), 1));
  398. return out;
  399. }
  400. };
  401. /** @fileOverview Bit array codec implementations.
  402. *
  403. * @author Emily Stark
  404. * @author Mike Hamburg
  405. * @author Dan Boneh
  406. */
  407. /**
  408. * Arrays of bytes
  409. * @namespace
  410. */
  411. const codec = {
  412. bytes: {
  413. /** Convert from a bitArray to an array of bytes. */
  414. fromBits(arr) {
  415. const bl = bitArray.bitLength(arr);
  416. const byteLength = bl / 8;
  417. const out = new Uint8Array(byteLength);
  418. let tmp;
  419. for (let i = 0; i < byteLength; i++) {
  420. if ((i & 3) === 0) {
  421. tmp = arr[i / 4];
  422. }
  423. out[i] = tmp >>> 24;
  424. tmp <<= 8;
  425. }
  426. return out;
  427. },
  428. /** Convert from an array of bytes to a bitArray. */
  429. toBits(bytes) {
  430. const out = [];
  431. let i;
  432. let tmp = 0;
  433. for (i = 0; i < bytes.length; i++) {
  434. tmp = tmp << 8 | bytes[i];
  435. if ((i & 3) === 3) {
  436. out.push(tmp);
  437. tmp = 0;
  438. }
  439. }
  440. if (i & 3) {
  441. out.push(bitArray.partial(8 * (i & 3), tmp));
  442. }
  443. return out;
  444. }
  445. }
  446. };
  447. const hash = {};
  448. /**
  449. * Context for a SHA-1 operation in progress.
  450. * @constructor
  451. */
  452. hash.sha1 = function (hash) {
  453. if (hash) {
  454. this._h = hash._h.slice(0);
  455. this._buffer = hash._buffer.slice(0);
  456. this._length = hash._length;
  457. } else {
  458. this.reset();
  459. }
  460. };
  461. hash.sha1.prototype = {
  462. /**
  463. * The hash's block size, in bits.
  464. * @constant
  465. */
  466. blockSize: 512,
  467. /**
  468. * Reset the hash state.
  469. * @return this
  470. */
  471. reset: function () {
  472. const sha1 = this;
  473. sha1._h = this._init.slice(0);
  474. sha1._buffer = [];
  475. sha1._length = 0;
  476. return sha1;
  477. },
  478. /**
  479. * Input several words to the hash.
  480. * @param {bitArray|String} data the data to hash.
  481. * @return this
  482. */
  483. update: function (data) {
  484. const sha1 = this;
  485. if (typeof data === "string") {
  486. data = codec.utf8String.toBits(data);
  487. }
  488. const b = sha1._buffer = bitArray.concat(sha1._buffer, data);
  489. const ol = sha1._length;
  490. const nl = sha1._length = ol + bitArray.bitLength(data);
  491. if (nl > 9007199254740991) {
  492. throw new Error("Cannot hash more than 2^53 - 1 bits");
  493. }
  494. const c = new Uint32Array(b);
  495. let j = 0;
  496. for (let i = sha1.blockSize + ol - ((sha1.blockSize + ol) & (sha1.blockSize - 1)); i <= nl;
  497. i += sha1.blockSize) {
  498. sha1._block(c.subarray(16 * j, 16 * (j + 1)));
  499. j += 1;
  500. }
  501. b.splice(0, 16 * j);
  502. return sha1;
  503. },
  504. /**
  505. * Complete hashing and output the hash value.
  506. * @return {bitArray} The hash value, an array of 5 big-endian words. TODO
  507. */
  508. finalize: function () {
  509. const sha1 = this;
  510. let b = sha1._buffer;
  511. const h = sha1._h;
  512. // Round out and push the buffer
  513. b = bitArray.concat(b, [bitArray.partial(1, 1)]);
  514. // Round out the buffer to a multiple of 16 words, less the 2 length words.
  515. for (let i = b.length + 2; i & 15; i++) {
  516. b.push(0);
  517. }
  518. // append the length
  519. b.push(Math.floor(sha1._length / 0x100000000));
  520. b.push(sha1._length | 0);
  521. while (b.length) {
  522. sha1._block(b.splice(0, 16));
  523. }
  524. sha1.reset();
  525. return h;
  526. },
  527. /**
  528. * The SHA-1 initialization vector.
  529. * @private
  530. */
  531. _init: [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0],
  532. /**
  533. * The SHA-1 hash key.
  534. * @private
  535. */
  536. _key: [0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6],
  537. /**
  538. * The SHA-1 logical functions f(0), f(1), ..., f(79).
  539. * @private
  540. */
  541. _f: function (t, b, c, d) {
  542. if (t <= 19) {
  543. return (b & c) | (~b & d);
  544. } else if (t <= 39) {
  545. return b ^ c ^ d;
  546. } else if (t <= 59) {
  547. return (b & c) | (b & d) | (c & d);
  548. } else if (t <= 79) {
  549. return b ^ c ^ d;
  550. }
  551. },
  552. /**
  553. * Circular left-shift operator.
  554. * @private
  555. */
  556. _S: function (n, x) {
  557. return (x << n) | (x >>> 32 - n);
  558. },
  559. /**
  560. * Perform one cycle of SHA-1.
  561. * @param {Uint32Array|bitArray} words one block of words.
  562. * @private
  563. */
  564. _block: function (words) {
  565. const sha1 = this;
  566. const h = sha1._h;
  567. // When words is passed to _block, it has 16 elements. SHA1 _block
  568. // function extends words with new elements (at the end there are 80 elements).
  569. // The problem is that if we use Uint32Array instead of Array,
  570. // the length of Uint32Array cannot be changed. Thus, we replace words with a
  571. // normal Array here.
  572. const w = Array(80); // do not use Uint32Array here as the instantiation is slower
  573. for (let j = 0; j < 16; j++) {
  574. w[j] = words[j];
  575. }
  576. let a = h[0];
  577. let b = h[1];
  578. let c = h[2];
  579. let d = h[3];
  580. let e = h[4];
  581. for (let t = 0; t <= 79; t++) {
  582. if (t >= 16) {
  583. w[t] = sha1._S(1, w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16]);
  584. }
  585. const tmp = (sha1._S(5, a) + sha1._f(t, b, c, d) + e + w[t] +
  586. sha1._key[Math.floor(t / 20)]) | 0;
  587. e = d;
  588. d = c;
  589. c = sha1._S(30, b);
  590. b = a;
  591. a = tmp;
  592. }
  593. h[0] = (h[0] + a) | 0;
  594. h[1] = (h[1] + b) | 0;
  595. h[2] = (h[2] + c) | 0;
  596. h[3] = (h[3] + d) | 0;
  597. h[4] = (h[4] + e) | 0;
  598. }
  599. };
  600. /** @fileOverview Low-level AES implementation.
  601. *
  602. * This file contains a low-level implementation of AES, optimized for
  603. * size and for efficiency on several browsers. It is based on
  604. * OpenSSL's aes_core.c, a public-domain implementation by Vincent
  605. * Rijmen, Antoon Bosselaers and Paulo Barreto.
  606. *
  607. * An older version of this implementation is available in the public
  608. * domain, but this one is (c) Emily Stark, Mike Hamburg, Dan Boneh,
  609. * Stanford University 2008-2010 and BSD-licensed for liability
  610. * reasons.
  611. *
  612. * @author Emily Stark
  613. * @author Mike Hamburg
  614. * @author Dan Boneh
  615. */
  616. const cipher = {};
  617. /**
  618. * Schedule out an AES key for both encryption and decryption. This
  619. * is a low-level class. Use a cipher mode to do bulk encryption.
  620. *
  621. * @constructor
  622. * @param {Array} key The key as an array of 4, 6 or 8 words.
  623. */
  624. cipher.aes = class {
  625. constructor(key) {
  626. /**
  627. * The expanded S-box and inverse S-box tables. These will be computed
  628. * on the client so that we don't have to send them down the wire.
  629. *
  630. * There are two tables, _tables[0] is for encryption and
  631. * _tables[1] is for decryption.
  632. *
  633. * The first 4 sub-tables are the expanded S-box with MixColumns. The
  634. * last (_tables[01][4]) is the S-box itself.
  635. *
  636. * @private
  637. */
  638. const aes = this;
  639. aes._tables = [[[], [], [], [], []], [[], [], [], [], []]];
  640. if (!aes._tables[0][0][0]) {
  641. aes._precompute();
  642. }
  643. const sbox = aes._tables[0][4];
  644. const decTable = aes._tables[1];
  645. const keyLen = key.length;
  646. let i, encKey, decKey, rcon = 1;
  647. if (keyLen !== 4 && keyLen !== 6 && keyLen !== 8) {
  648. throw new Error("invalid aes key size");
  649. }
  650. aes._key = [encKey = key.slice(0), decKey = []];
  651. // schedule encryption keys
  652. for (i = keyLen; i < 4 * keyLen + 28; i++) {
  653. let tmp = encKey[i - 1];
  654. // apply sbox
  655. if (i % keyLen === 0 || (keyLen === 8 && i % keyLen === 4)) {
  656. tmp = sbox[tmp >>> 24] << 24 ^ sbox[tmp >> 16 & 255] << 16 ^ sbox[tmp >> 8 & 255] << 8 ^ sbox[tmp & 255];
  657. // shift rows and add rcon
  658. if (i % keyLen === 0) {
  659. tmp = tmp << 8 ^ tmp >>> 24 ^ rcon << 24;
  660. rcon = rcon << 1 ^ (rcon >> 7) * 283;
  661. }
  662. }
  663. encKey[i] = encKey[i - keyLen] ^ tmp;
  664. }
  665. // schedule decryption keys
  666. for (let j = 0; i; j++, i--) {
  667. const tmp = encKey[j & 3 ? i : i - 4];
  668. if (i <= 4 || j < 4) {
  669. decKey[j] = tmp;
  670. } else {
  671. decKey[j] = decTable[0][sbox[tmp >>> 24]] ^
  672. decTable[1][sbox[tmp >> 16 & 255]] ^
  673. decTable[2][sbox[tmp >> 8 & 255]] ^
  674. decTable[3][sbox[tmp & 255]];
  675. }
  676. }
  677. }
  678. // public
  679. /* Something like this might appear here eventually
  680. name: "AES",
  681. blockSize: 4,
  682. keySizes: [4,6,8],
  683. */
  684. /**
  685. * Encrypt an array of 4 big-endian words.
  686. * @param {Array} data The plaintext.
  687. * @return {Array} The ciphertext.
  688. */
  689. encrypt(data) {
  690. return this._crypt(data, 0);
  691. }
  692. /**
  693. * Decrypt an array of 4 big-endian words.
  694. * @param {Array} data The ciphertext.
  695. * @return {Array} The plaintext.
  696. */
  697. decrypt(data) {
  698. return this._crypt(data, 1);
  699. }
  700. /**
  701. * Expand the S-box tables.
  702. *
  703. * @private
  704. */
  705. _precompute() {
  706. const encTable = this._tables[0];
  707. const decTable = this._tables[1];
  708. const sbox = encTable[4];
  709. const sboxInv = decTable[4];
  710. const d = [];
  711. const th = [];
  712. let xInv, x2, x4, x8;
  713. // Compute double and third tables
  714. for (let i = 0; i < 256; i++) {
  715. th[(d[i] = i << 1 ^ (i >> 7) * 283) ^ i] = i;
  716. }
  717. for (let x = xInv = 0; !sbox[x]; x ^= x2 || 1, xInv = th[xInv] || 1) {
  718. // Compute sbox
  719. let s = xInv ^ xInv << 1 ^ xInv << 2 ^ xInv << 3 ^ xInv << 4;
  720. s = s >> 8 ^ s & 255 ^ 99;
  721. sbox[x] = s;
  722. sboxInv[s] = x;
  723. // Compute MixColumns
  724. x8 = d[x4 = d[x2 = d[x]]];
  725. let tDec = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
  726. let tEnc = d[s] * 0x101 ^ s * 0x1010100;
  727. for (let i = 0; i < 4; i++) {
  728. encTable[i][x] = tEnc = tEnc << 24 ^ tEnc >>> 8;
  729. decTable[i][s] = tDec = tDec << 24 ^ tDec >>> 8;
  730. }
  731. }
  732. // Compactify. Considerable speedup on Firefox.
  733. for (let i = 0; i < 5; i++) {
  734. encTable[i] = encTable[i].slice(0);
  735. decTable[i] = decTable[i].slice(0);
  736. }
  737. }
  738. /**
  739. * Encryption and decryption core.
  740. * @param {Array} input Four words to be encrypted or decrypted.
  741. * @param dir The direction, 0 for encrypt and 1 for decrypt.
  742. * @return {Array} The four encrypted or decrypted words.
  743. * @private
  744. */
  745. _crypt(input, dir) {
  746. if (input.length !== 4) {
  747. throw new Error("invalid aes block size");
  748. }
  749. const key = this._key[dir];
  750. const nInnerRounds = key.length / 4 - 2;
  751. const out = [0, 0, 0, 0];
  752. const table = this._tables[dir];
  753. // load up the tables
  754. const t0 = table[0];
  755. const t1 = table[1];
  756. const t2 = table[2];
  757. const t3 = table[3];
  758. const sbox = table[4];
  759. // state variables a,b,c,d are loaded with pre-whitened data
  760. let a = input[0] ^ key[0];
  761. let b = input[dir ? 3 : 1] ^ key[1];
  762. let c = input[2] ^ key[2];
  763. let d = input[dir ? 1 : 3] ^ key[3];
  764. let kIndex = 4;
  765. let a2, b2, c2;
  766. // Inner rounds. Cribbed from OpenSSL.
  767. for (let i = 0; i < nInnerRounds; i++) {
  768. a2 = t0[a >>> 24] ^ t1[b >> 16 & 255] ^ t2[c >> 8 & 255] ^ t3[d & 255] ^ key[kIndex];
  769. b2 = t0[b >>> 24] ^ t1[c >> 16 & 255] ^ t2[d >> 8 & 255] ^ t3[a & 255] ^ key[kIndex + 1];
  770. c2 = t0[c >>> 24] ^ t1[d >> 16 & 255] ^ t2[a >> 8 & 255] ^ t3[b & 255] ^ key[kIndex + 2];
  771. d = t0[d >>> 24] ^ t1[a >> 16 & 255] ^ t2[b >> 8 & 255] ^ t3[c & 255] ^ key[kIndex + 3];
  772. kIndex += 4;
  773. a = a2; b = b2; c = c2;
  774. }
  775. // Last round.
  776. for (let i = 0; i < 4; i++) {
  777. out[dir ? 3 & -i : i] =
  778. sbox[a >>> 24] << 24 ^
  779. sbox[b >> 16 & 255] << 16 ^
  780. sbox[c >> 8 & 255] << 8 ^
  781. sbox[d & 255] ^
  782. key[kIndex++];
  783. a2 = a; a = b; b = c; c = d; d = a2;
  784. }
  785. return out;
  786. }
  787. };
  788. /**
  789. * Random values
  790. * @namespace
  791. */
  792. const random = {
  793. /**
  794. * Generate random words with pure js, cryptographically not as strong & safe as native implementation.
  795. * @param {TypedArray} typedArray The array to fill.
  796. * @return {TypedArray} The random values.
  797. */
  798. getRandomValues(typedArray) {
  799. const words = new Uint32Array(typedArray.buffer);
  800. const r = (m_w) => {
  801. let m_z = 0x3ade68b1;
  802. const mask = 0xffffffff;
  803. return function () {
  804. m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
  805. m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
  806. const result = ((((m_z << 0x10) + m_w) & mask) / 0x100000000) + .5;
  807. return result * (Math.random() > .5 ? 1 : -1);
  808. };
  809. };
  810. for (let i = 0, rcache; i < typedArray.length; i += 4) {
  811. const _r = r((rcache || Math.random()) * 0x100000000);
  812. rcache = _r() * 0x3ade67b7;
  813. words[i / 4] = (_r() * 0x100000000) | 0;
  814. }
  815. return typedArray;
  816. }
  817. };
  818. /** @fileOverview CTR mode implementation.
  819. *
  820. * Special thanks to Roy Nicholson for pointing out a bug in our
  821. * implementation.
  822. *
  823. * @author Emily Stark
  824. * @author Mike Hamburg
  825. * @author Dan Boneh
  826. */
  827. /** Brian Gladman's CTR Mode.
  828. * @constructor
  829. * @param {Object} _prf The aes instance to generate key.
  830. * @param {bitArray} _iv The iv for ctr mode, it must be 128 bits.
  831. */
  832. const mode = {};
  833. /**
  834. * Brian Gladman's CTR Mode.
  835. * @namespace
  836. */
  837. mode.ctrGladman = class {
  838. constructor(prf, iv) {
  839. this._prf = prf;
  840. this._initIv = iv;
  841. this._iv = iv;
  842. }
  843. reset() {
  844. this._iv = this._initIv;
  845. }
  846. /** Input some data to calculate.
  847. * @param {bitArray} data the data to process, it must be intergral multiple of 128 bits unless it's the last.
  848. */
  849. update(data) {
  850. return this.calculate(this._prf, data, this._iv);
  851. }
  852. incWord(word) {
  853. if (((word >> 24) & 0xff) === 0xff) { //overflow
  854. let b1 = (word >> 16) & 0xff;
  855. let b2 = (word >> 8) & 0xff;
  856. let b3 = word & 0xff;
  857. if (b1 === 0xff) { // overflow b1
  858. b1 = 0;
  859. if (b2 === 0xff) {
  860. b2 = 0;
  861. if (b3 === 0xff) {
  862. b3 = 0;
  863. } else {
  864. ++b3;
  865. }
  866. } else {
  867. ++b2;
  868. }
  869. } else {
  870. ++b1;
  871. }
  872. word = 0;
  873. word += (b1 << 16);
  874. word += (b2 << 8);
  875. word += b3;
  876. } else {
  877. word += (0x01 << 24);
  878. }
  879. return word;
  880. }
  881. incCounter(counter) {
  882. if ((counter[0] = this.incWord(counter[0])) === 0) {
  883. // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
  884. counter[1] = this.incWord(counter[1]);
  885. }
  886. }
  887. calculate(prf, data, iv) {
  888. let l;
  889. if (!(l = data.length)) {
  890. return [];
  891. }
  892. const bl = bitArray.bitLength(data);
  893. for (let i = 0; i < l; i += 4) {
  894. this.incCounter(iv);
  895. const e = prf.encrypt(iv);
  896. data[i] ^= e[0];
  897. data[i + 1] ^= e[1];
  898. data[i + 2] ^= e[2];
  899. data[i + 3] ^= e[3];
  900. }
  901. return bitArray.clamp(data, bl);
  902. }
  903. };
  904. const misc = {
  905. importKey(password) {
  906. return new misc.hmacSha1(codec.bytes.toBits(password));
  907. },
  908. pbkdf2(prf, salt, count, length) {
  909. count = count || 10000;
  910. if (length < 0 || count < 0) {
  911. throw new Error("invalid params to pbkdf2");
  912. }
  913. const byteLength = ((length >> 5) + 1) << 2;
  914. let u, ui, i, j, k;
  915. const arrayBuffer = new ArrayBuffer(byteLength);
  916. const out = new DataView(arrayBuffer);
  917. let outLength = 0;
  918. const b = bitArray;
  919. salt = codec.bytes.toBits(salt);
  920. for (k = 1; outLength < (byteLength || 1); k++) {
  921. u = ui = prf.encrypt(b.concat(salt, [k]));
  922. for (i = 1; i < count; i++) {
  923. ui = prf.encrypt(ui);
  924. for (j = 0; j < ui.length; j++) {
  925. u[j] ^= ui[j];
  926. }
  927. }
  928. for (i = 0; outLength < (byteLength || 1) && i < u.length; i++) {
  929. out.setInt32(outLength, u[i]);
  930. outLength += 4;
  931. }
  932. }
  933. return arrayBuffer.slice(0, length / 8);
  934. }
  935. };
  936. /** @fileOverview HMAC implementation.
  937. *
  938. * @author Emily Stark
  939. * @author Mike Hamburg
  940. * @author Dan Boneh
  941. */
  942. /** HMAC with the specified hash function.
  943. * @constructor
  944. * @param {bitArray} key the key for HMAC.
  945. * @param {Object} [Hash=hash.sha1] The hash function to use.
  946. */
  947. misc.hmacSha1 = class {
  948. constructor(key) {
  949. const hmac = this;
  950. const Hash = hmac._hash = hash.sha1;
  951. const exKey = [[], []];
  952. const bs = Hash.prototype.blockSize / 32;
  953. hmac._baseHash = [new Hash(), new Hash()];
  954. if (key.length > bs) {
  955. key = Hash.hash(key);
  956. }
  957. for (let i = 0; i < bs; i++) {
  958. exKey[0][i] = key[i] ^ 0x36363636;
  959. exKey[1][i] = key[i] ^ 0x5C5C5C5C;
  960. }
  961. hmac._baseHash[0].update(exKey[0]);
  962. hmac._baseHash[1].update(exKey[1]);
  963. hmac._resultHash = new Hash(hmac._baseHash[0]);
  964. }
  965. reset() {
  966. const hmac = this;
  967. hmac._resultHash = new hmac._hash(hmac._baseHash[0]);
  968. hmac._updated = false;
  969. }
  970. update(data) {
  971. const hmac = this;
  972. hmac._updated = true;
  973. hmac._resultHash.update(data);
  974. }
  975. digest() {
  976. const hmac = this;
  977. const w = hmac._resultHash.finalize();
  978. const result = new (hmac._hash)(hmac._baseHash[1]).update(w).finalize();
  979. hmac.reset();
  980. return result;
  981. }
  982. encrypt(data) {
  983. if (!this._updated) {
  984. this.update(data);
  985. return this.digest(data);
  986. } else {
  987. throw new Error("encrypt on already updated hmac called!");
  988. }
  989. }
  990. };
  991. /*
  992. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  993. Redistribution and use in source and binary forms, with or without
  994. modification, are permitted provided that the following conditions are met:
  995. 1. Redistributions of source code must retain the above copyright notice,
  996. this list of conditions and the following disclaimer.
  997. 2. Redistributions in binary form must reproduce the above copyright
  998. notice, this list of conditions and the following disclaimer in
  999. the documentation and/or other materials provided with the distribution.
  1000. 3. The names of the authors may not be used to endorse or promote products
  1001. derived from this software without specific prior written permission.
  1002. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  1003. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1004. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  1005. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  1006. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1007. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  1008. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1009. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1010. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1011. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1012. */
  1013. const ERR_INVALID_PASSWORD = "Invalid pasword";
  1014. const BLOCK_LENGTH = 16;
  1015. const RAW_FORMAT = "raw";
  1016. const PBKDF2_ALGORITHM = { name: "PBKDF2" };
  1017. const HASH_ALGORITHM = { name: "HMAC" };
  1018. const HASH_FUNCTION = "SHA-1";
  1019. const BASE_KEY_ALGORITHM = Object.assign({ hash: HASH_ALGORITHM }, PBKDF2_ALGORITHM);
  1020. const DERIVED_BITS_ALGORITHM = Object.assign({ iterations: 1000, hash: { name: HASH_FUNCTION } }, PBKDF2_ALGORITHM);
  1021. const DERIVED_BITS_USAGE = ["deriveBits"];
  1022. const SALT_LENGTH = [8, 12, 16];
  1023. const KEY_LENGTH = [16, 24, 32];
  1024. const SIGNATURE_LENGTH = 10;
  1025. const COUNTER_DEFAULT_VALUE = [0, 0, 0, 0];
  1026. const CRYPTO_API_SUPPORTED = typeof crypto != "undefined";
  1027. const SUBTLE_API_SUPPORTED = CRYPTO_API_SUPPORTED && typeof crypto.subtle != "undefined";
  1028. const codecBytes = codec.bytes;
  1029. const Aes = cipher.aes;
  1030. const CtrGladman = mode.ctrGladman;
  1031. const HmacSha1 = misc.hmacSha1;
  1032. class AESDecrypt {
  1033. constructor(password, signed, strength) {
  1034. Object.assign(this, {
  1035. password,
  1036. signed,
  1037. strength: strength - 1,
  1038. pendingInput: new Uint8Array(0)
  1039. });
  1040. }
  1041. async append(input) {
  1042. const aesCrypto = this;
  1043. if (aesCrypto.password) {
  1044. const preamble = subarray(input, 0, SALT_LENGTH[aesCrypto.strength] + 2);
  1045. await createDecryptionKeys(aesCrypto, preamble, aesCrypto.password);
  1046. aesCrypto.password = null;
  1047. aesCrypto.aesCtrGladman = new CtrGladman(new Aes(aesCrypto.keys.key), Array.from(COUNTER_DEFAULT_VALUE));
  1048. aesCrypto.hmac = new HmacSha1(aesCrypto.keys.authentication);
  1049. input = subarray(input, SALT_LENGTH[aesCrypto.strength] + 2);
  1050. }
  1051. const output = new Uint8Array(input.length - SIGNATURE_LENGTH - ((input.length - SIGNATURE_LENGTH) % BLOCK_LENGTH));
  1052. return append(aesCrypto, input, output, 0, SIGNATURE_LENGTH, true);
  1053. }
  1054. flush() {
  1055. const aesCrypto = this;
  1056. const pendingInput = aesCrypto.pendingInput;
  1057. const chunkToDecrypt = subarray(pendingInput, 0, pendingInput.length - SIGNATURE_LENGTH);
  1058. const originalSignature = subarray(pendingInput, pendingInput.length - SIGNATURE_LENGTH);
  1059. let decryptedChunkArray = new Uint8Array(0);
  1060. if (chunkToDecrypt.length) {
  1061. const encryptedChunk = codecBytes.toBits(chunkToDecrypt);
  1062. aesCrypto.hmac.update(encryptedChunk);
  1063. const decryptedChunk = aesCrypto.aesCtrGladman.update(encryptedChunk);
  1064. decryptedChunkArray = codecBytes.fromBits(decryptedChunk);
  1065. }
  1066. let valid = true;
  1067. if (aesCrypto.signed) {
  1068. const signature = subarray(codecBytes.fromBits(aesCrypto.hmac.digest()), 0, SIGNATURE_LENGTH);
  1069. for (let indexSignature = 0; indexSignature < SIGNATURE_LENGTH; indexSignature++) {
  1070. if (signature[indexSignature] != originalSignature[indexSignature]) {
  1071. valid = false;
  1072. }
  1073. }
  1074. }
  1075. return {
  1076. valid,
  1077. data: decryptedChunkArray
  1078. };
  1079. }
  1080. }
  1081. class AESEncrypt {
  1082. constructor(password, strength) {
  1083. Object.assign(this, {
  1084. password,
  1085. strength: strength - 1,
  1086. pendingInput: new Uint8Array(0)
  1087. });
  1088. }
  1089. async append(input) {
  1090. const aesCrypto = this;
  1091. let preamble = new Uint8Array(0);
  1092. if (aesCrypto.password) {
  1093. preamble = await createEncryptionKeys(aesCrypto, aesCrypto.password);
  1094. aesCrypto.password = null;
  1095. aesCrypto.aesCtrGladman = new CtrGladman(new Aes(aesCrypto.keys.key), Array.from(COUNTER_DEFAULT_VALUE));
  1096. aesCrypto.hmac = new HmacSha1(aesCrypto.keys.authentication);
  1097. }
  1098. const output = new Uint8Array(preamble.length + input.length - (input.length % BLOCK_LENGTH));
  1099. output.set(preamble, 0);
  1100. return append(aesCrypto, input, output, preamble.length, 0);
  1101. }
  1102. flush() {
  1103. const aesCrypto = this;
  1104. let encryptedChunkArray = new Uint8Array(0);
  1105. if (aesCrypto.pendingInput.length) {
  1106. const encryptedChunk = aesCrypto.aesCtrGladman.update(codecBytes.toBits(aesCrypto.pendingInput));
  1107. aesCrypto.hmac.update(encryptedChunk);
  1108. encryptedChunkArray = codecBytes.fromBits(encryptedChunk);
  1109. }
  1110. const signature = subarray(codecBytes.fromBits(aesCrypto.hmac.digest()), 0, SIGNATURE_LENGTH);
  1111. return {
  1112. data: concat(encryptedChunkArray, signature),
  1113. signature
  1114. };
  1115. }
  1116. }
  1117. function append(aesCrypto, input, output, paddingStart, paddingEnd, verifySignature) {
  1118. const inputLength = input.length - paddingEnd;
  1119. if (aesCrypto.pendingInput.length) {
  1120. input = concat(aesCrypto.pendingInput, input);
  1121. output = expand(output, inputLength - (inputLength % BLOCK_LENGTH));
  1122. }
  1123. let offset;
  1124. for (offset = 0; offset <= inputLength - BLOCK_LENGTH; offset += BLOCK_LENGTH) {
  1125. const inputChunk = codecBytes.toBits(subarray(input, offset, offset + BLOCK_LENGTH));
  1126. if (verifySignature) {
  1127. aesCrypto.hmac.update(inputChunk);
  1128. }
  1129. const outputChunk = aesCrypto.aesCtrGladman.update(inputChunk);
  1130. if (!verifySignature) {
  1131. aesCrypto.hmac.update(outputChunk);
  1132. }
  1133. output.set(codecBytes.fromBits(outputChunk), offset + paddingStart);
  1134. }
  1135. aesCrypto.pendingInput = subarray(input, offset);
  1136. return output;
  1137. }
  1138. async function createDecryptionKeys(decrypt, preambleArray, password) {
  1139. await createKeys$1(decrypt, password, subarray(preambleArray, 0, SALT_LENGTH[decrypt.strength]));
  1140. const passwordVerification = subarray(preambleArray, SALT_LENGTH[decrypt.strength]);
  1141. const passwordVerificationKey = decrypt.keys.passwordVerification;
  1142. if (passwordVerificationKey[0] != passwordVerification[0] || passwordVerificationKey[1] != passwordVerification[1]) {
  1143. throw new Error(ERR_INVALID_PASSWORD);
  1144. }
  1145. }
  1146. async function createEncryptionKeys(encrypt, password) {
  1147. const salt = getRandomValues(new Uint8Array(SALT_LENGTH[encrypt.strength]));
  1148. await createKeys$1(encrypt, password, salt);
  1149. return concat(salt, encrypt.keys.passwordVerification);
  1150. }
  1151. async function createKeys$1(target, password, salt) {
  1152. const encodedPassword = encodeText(password);
  1153. const basekey = await importKey(RAW_FORMAT, encodedPassword, BASE_KEY_ALGORITHM, false, DERIVED_BITS_USAGE);
  1154. const derivedBits = await deriveBits(Object.assign({ salt }, DERIVED_BITS_ALGORITHM), basekey, 8 * ((KEY_LENGTH[target.strength] * 2) + 2));
  1155. const compositeKey = new Uint8Array(derivedBits);
  1156. target.keys = {
  1157. key: codecBytes.toBits(subarray(compositeKey, 0, KEY_LENGTH[target.strength])),
  1158. authentication: codecBytes.toBits(subarray(compositeKey, KEY_LENGTH[target.strength], KEY_LENGTH[target.strength] * 2)),
  1159. passwordVerification: subarray(compositeKey, KEY_LENGTH[target.strength] * 2)
  1160. };
  1161. }
  1162. function getRandomValues(array) {
  1163. if (CRYPTO_API_SUPPORTED && typeof crypto.getRandomValues == "function") {
  1164. return crypto.getRandomValues(array);
  1165. } else {
  1166. return random.getRandomValues(array);
  1167. }
  1168. }
  1169. function importKey(format, password, algorithm, extractable, keyUsages) {
  1170. if (CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof crypto.subtle.importKey == "function") {
  1171. return crypto.subtle.importKey(format, password, algorithm, extractable, keyUsages);
  1172. } else {
  1173. return misc.importKey(password);
  1174. }
  1175. }
  1176. async function deriveBits(algorithm, baseKey, length) {
  1177. if (CRYPTO_API_SUPPORTED && SUBTLE_API_SUPPORTED && typeof crypto.subtle.deriveBits == "function") {
  1178. return await crypto.subtle.deriveBits(algorithm, baseKey, length);
  1179. } else {
  1180. return misc.pbkdf2(baseKey, algorithm.salt, DERIVED_BITS_ALGORITHM.iterations, length);
  1181. }
  1182. }
  1183. function concat(leftArray, rightArray) {
  1184. let array = leftArray;
  1185. if (leftArray.length + rightArray.length) {
  1186. array = new Uint8Array(leftArray.length + rightArray.length);
  1187. array.set(leftArray, 0);
  1188. array.set(rightArray, leftArray.length);
  1189. }
  1190. return array;
  1191. }
  1192. function expand(inputArray, length) {
  1193. if (length && length > inputArray.length) {
  1194. const array = inputArray;
  1195. inputArray = new Uint8Array(length);
  1196. inputArray.set(array, 0);
  1197. }
  1198. return inputArray;
  1199. }
  1200. function subarray(array, begin, end) {
  1201. return array.subarray(begin, end);
  1202. }
  1203. /*
  1204. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  1205. Redistribution and use in source and binary forms, with or without
  1206. modification, are permitted provided that the following conditions are met:
  1207. 1. Redistributions of source code must retain the above copyright notice,
  1208. this list of conditions and the following disclaimer.
  1209. 2. Redistributions in binary form must reproduce the above copyright
  1210. notice, this list of conditions and the following disclaimer in
  1211. the documentation and/or other materials provided with the distribution.
  1212. 3. The names of the authors may not be used to endorse or promote products
  1213. derived from this software without specific prior written permission.
  1214. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  1215. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1216. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  1217. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  1218. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1219. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  1220. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1221. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1222. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1223. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1224. */
  1225. const HEADER_LENGTH = 12;
  1226. class ZipCryptoDecrypt {
  1227. constructor(password, passwordVerification) {
  1228. const zipCrypto = this;
  1229. Object.assign(zipCrypto, {
  1230. password,
  1231. passwordVerification
  1232. });
  1233. createKeys(zipCrypto, password);
  1234. }
  1235. append(input) {
  1236. const zipCrypto = this;
  1237. if (zipCrypto.password) {
  1238. const decryptedHeader = decrypt(zipCrypto, input.subarray(0, HEADER_LENGTH));
  1239. zipCrypto.password = null;
  1240. if (decryptedHeader[HEADER_LENGTH - 1] != zipCrypto.passwordVerification) {
  1241. throw new Error(ERR_INVALID_PASSWORD);
  1242. }
  1243. input = input.subarray(HEADER_LENGTH);
  1244. }
  1245. return decrypt(zipCrypto, input);
  1246. }
  1247. flush() {
  1248. return {
  1249. valid: true,
  1250. data: new Uint8Array(0)
  1251. };
  1252. }
  1253. }
  1254. class ZipCryptoEncrypt {
  1255. constructor(password, passwordVerification) {
  1256. const zipCrypto = this;
  1257. Object.assign(zipCrypto, {
  1258. password,
  1259. passwordVerification
  1260. });
  1261. createKeys(zipCrypto, password);
  1262. }
  1263. append(input) {
  1264. const zipCrypto = this;
  1265. let output;
  1266. let offset;
  1267. if (zipCrypto.password) {
  1268. zipCrypto.password = null;
  1269. const header = crypto.getRandomValues(new Uint8Array(HEADER_LENGTH));
  1270. header[HEADER_LENGTH - 1] = zipCrypto.passwordVerification;
  1271. output = new Uint8Array(input.length + header.length);
  1272. output.set(encrypt(zipCrypto, header), 0);
  1273. offset = HEADER_LENGTH;
  1274. } else {
  1275. output = new Uint8Array(input.length);
  1276. offset = 0;
  1277. }
  1278. output.set(encrypt(zipCrypto, input), offset);
  1279. return output;
  1280. }
  1281. flush() {
  1282. return {
  1283. data: new Uint8Array(0)
  1284. };
  1285. }
  1286. }
  1287. function decrypt(target, input) {
  1288. const output = new Uint8Array(input.length);
  1289. for (let index = 0; index < input.length; index++) {
  1290. output[index] = getByte(target) ^ input[index];
  1291. updateKeys(target, output[index]);
  1292. }
  1293. return output;
  1294. }
  1295. function encrypt(target, input) {
  1296. const output = new Uint8Array(input.length);
  1297. for (let index = 0; index < input.length; index++) {
  1298. output[index] = getByte(target) ^ input[index];
  1299. updateKeys(target, input[index]);
  1300. }
  1301. return output;
  1302. }
  1303. function createKeys(target, password) {
  1304. target.keys = [0x12345678, 0x23456789, 0x34567890];
  1305. target.crcKey0 = new Crc32(target.keys[0]);
  1306. target.crcKey2 = new Crc32(target.keys[2]);
  1307. for (let index = 0; index < password.length; index++) {
  1308. updateKeys(target, password.charCodeAt(index));
  1309. }
  1310. }
  1311. function updateKeys(target, byte) {
  1312. target.crcKey0.append([byte]);
  1313. target.keys[0] = ~target.crcKey0.get();
  1314. target.keys[1] = getInt32(target.keys[1] + getInt8(target.keys[0]));
  1315. target.keys[1] = getInt32(Math.imul(target.keys[1], 134775813) + 1);
  1316. target.crcKey2.append([target.keys[1] >>> 24]);
  1317. target.keys[2] = ~target.crcKey2.get();
  1318. }
  1319. function getByte(target) {
  1320. const temp = target.keys[2] | 2;
  1321. return getInt8(Math.imul(temp, (temp ^ 1)) >>> 8);
  1322. }
  1323. function getInt8(number) {
  1324. return number & 0xFF;
  1325. }
  1326. function getInt32(number) {
  1327. return number & 0xFFFFFFFF;
  1328. }
  1329. /*
  1330. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  1331. Redistribution and use in source and binary forms, with or without
  1332. modification, are permitted provided that the following conditions are met:
  1333. 1. Redistributions of source code must retain the above copyright notice,
  1334. this list of conditions and the following disclaimer.
  1335. 2. Redistributions in binary form must reproduce the above copyright
  1336. notice, this list of conditions and the following disclaimer in
  1337. the documentation and/or other materials provided with the distribution.
  1338. 3. The names of the authors may not be used to endorse or promote products
  1339. derived from this software without specific prior written permission.
  1340. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  1341. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1342. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  1343. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  1344. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1345. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  1346. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1347. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1348. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1349. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1350. */
  1351. const CODEC_DEFLATE = "deflate";
  1352. const CODEC_INFLATE = "inflate";
  1353. const ERR_INVALID_SIGNATURE = "Invalid signature";
  1354. class Inflate {
  1355. constructor(codecConstructor, {
  1356. signature,
  1357. password,
  1358. signed,
  1359. compressed,
  1360. zipCrypto,
  1361. passwordVerification,
  1362. encryptionStrength
  1363. }, { chunkSize }) {
  1364. const encrypted = Boolean(password);
  1365. Object.assign(this, {
  1366. signature,
  1367. encrypted,
  1368. signed,
  1369. compressed,
  1370. inflate: compressed && new codecConstructor({ chunkSize }),
  1371. crc32: signed && new Crc32(),
  1372. zipCrypto,
  1373. decrypt: encrypted && zipCrypto ?
  1374. new ZipCryptoDecrypt(password, passwordVerification) :
  1375. new AESDecrypt(password, signed, encryptionStrength)
  1376. });
  1377. }
  1378. async append(data) {
  1379. const codec = this;
  1380. if (codec.encrypted && data.length) {
  1381. data = await codec.decrypt.append(data);
  1382. }
  1383. if (codec.compressed && data.length) {
  1384. data = await codec.inflate.append(data);
  1385. }
  1386. if ((!codec.encrypted || codec.zipCrypto) && codec.signed && data.length) {
  1387. codec.crc32.append(data);
  1388. }
  1389. return data;
  1390. }
  1391. async flush() {
  1392. const codec = this;
  1393. let signature;
  1394. let data = new Uint8Array(0);
  1395. if (codec.encrypted) {
  1396. const result = codec.decrypt.flush();
  1397. if (!result.valid) {
  1398. throw new Error(ERR_INVALID_SIGNATURE);
  1399. }
  1400. data = result.data;
  1401. }
  1402. if ((!codec.encrypted || codec.zipCrypto) && codec.signed) {
  1403. const dataViewSignature = new DataView(new Uint8Array(4).buffer);
  1404. signature = codec.crc32.get();
  1405. dataViewSignature.setUint32(0, signature);
  1406. if (codec.signature != dataViewSignature.getUint32(0, false)) {
  1407. throw new Error(ERR_INVALID_SIGNATURE);
  1408. }
  1409. }
  1410. if (codec.compressed) {
  1411. data = (await codec.inflate.append(data)) || new Uint8Array(0);
  1412. await codec.inflate.flush();
  1413. }
  1414. return { data, signature };
  1415. }
  1416. }
  1417. class Deflate {
  1418. constructor(codecConstructor, {
  1419. encrypted,
  1420. signed,
  1421. compressed,
  1422. level,
  1423. zipCrypto,
  1424. password,
  1425. passwordVerification,
  1426. encryptionStrength
  1427. }, { chunkSize }) {
  1428. Object.assign(this, {
  1429. encrypted,
  1430. signed,
  1431. compressed,
  1432. deflate: compressed && new codecConstructor({ level: level || 5, chunkSize }),
  1433. crc32: signed && new Crc32(),
  1434. zipCrypto,
  1435. encrypt: encrypted && zipCrypto ?
  1436. new ZipCryptoEncrypt(password, passwordVerification) :
  1437. new AESEncrypt(password, encryptionStrength)
  1438. });
  1439. }
  1440. async append(inputData) {
  1441. const codec = this;
  1442. let data = inputData;
  1443. if (codec.compressed && inputData.length) {
  1444. data = await codec.deflate.append(inputData);
  1445. }
  1446. if (codec.encrypted && data.length) {
  1447. data = await codec.encrypt.append(data);
  1448. }
  1449. if ((!codec.encrypted || codec.zipCrypto) && codec.signed && inputData.length) {
  1450. codec.crc32.append(inputData);
  1451. }
  1452. return data;
  1453. }
  1454. async flush() {
  1455. const codec = this;
  1456. let signature;
  1457. let data = new Uint8Array(0);
  1458. if (codec.compressed) {
  1459. data = (await codec.deflate.flush()) || new Uint8Array(0);
  1460. }
  1461. if (codec.encrypted) {
  1462. data = await codec.encrypt.append(data);
  1463. const result = codec.encrypt.flush();
  1464. signature = result.signature;
  1465. const newData = new Uint8Array(data.length + result.data.length);
  1466. newData.set(data, 0);
  1467. newData.set(result.data, data.length);
  1468. data = newData;
  1469. }
  1470. if ((!codec.encrypted || codec.zipCrypto) && codec.signed) {
  1471. signature = codec.crc32.get();
  1472. }
  1473. return { data, signature };
  1474. }
  1475. }
  1476. function createCodec$1(codecConstructor, options, config) {
  1477. if (options.codecType.startsWith(CODEC_DEFLATE)) {
  1478. return new Deflate(codecConstructor, options, config);
  1479. } else if (options.codecType.startsWith(CODEC_INFLATE)) {
  1480. return new Inflate(codecConstructor, options, config);
  1481. }
  1482. }
  1483. /*
  1484. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  1485. Redistribution and use in source and binary forms, with or without
  1486. modification, are permitted provided that the following conditions are met:
  1487. 1. Redistributions of source code must retain the above copyright notice,
  1488. this list of conditions and the following disclaimer.
  1489. 2. Redistributions in binary form must reproduce the above copyright
  1490. notice, this list of conditions and the following disclaimer in
  1491. the documentation and/or other materials provided with the distribution.
  1492. 3. The names of the authors may not be used to endorse or promote products
  1493. derived from this software without specific prior written permission.
  1494. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  1495. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1496. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  1497. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  1498. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1499. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  1500. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1501. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1502. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1503. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1504. */
  1505. const MESSAGE_INIT = "init";
  1506. const MESSAGE_APPEND = "append";
  1507. const MESSAGE_FLUSH = "flush";
  1508. const MESSAGE_EVENT_TYPE = "message";
  1509. let classicWorkersSupported = true;
  1510. var getWorker = (workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts) => {
  1511. Object.assign(workerData, {
  1512. busy: true,
  1513. codecConstructor,
  1514. options: Object.assign({}, options),
  1515. scripts,
  1516. terminate() {
  1517. if (workerData.worker && !workerData.busy) {
  1518. workerData.worker.terminate();
  1519. workerData.interface = null;
  1520. }
  1521. },
  1522. onTaskFinished() {
  1523. workerData.busy = false;
  1524. onTaskFinished(workerData);
  1525. }
  1526. });
  1527. return webWorker ? createWebWorkerInterface(workerData, config) : createWorkerInterface(workerData, config);
  1528. };
  1529. function createWorkerInterface(workerData, config) {
  1530. const interfaceCodec = createCodec$1(workerData.codecConstructor, workerData.options, config);
  1531. return {
  1532. async append(data) {
  1533. try {
  1534. return await interfaceCodec.append(data);
  1535. } catch (error) {
  1536. workerData.onTaskFinished();
  1537. throw error;
  1538. }
  1539. },
  1540. async flush() {
  1541. try {
  1542. return await interfaceCodec.flush();
  1543. } finally {
  1544. workerData.onTaskFinished();
  1545. }
  1546. },
  1547. abort() {
  1548. workerData.onTaskFinished();
  1549. }
  1550. };
  1551. }
  1552. function createWebWorkerInterface(workerData, config) {
  1553. let messageTask;
  1554. const workerOptions = { type: "module" };
  1555. if (!workerData.interface) {
  1556. if (!classicWorkersSupported) {
  1557. workerData.worker = getWorker(workerOptions, config.baseURL);
  1558. } else {
  1559. try {
  1560. workerData.worker = getWorker({}, config.baseURL);
  1561. } catch (_error) {
  1562. classicWorkersSupported = false;
  1563. workerData.worker = getWorker(workerOptions, config.baseURL);
  1564. }
  1565. }
  1566. workerData.worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false);
  1567. workerData.interface = {
  1568. append(data) {
  1569. return initAndSendMessage({ type: MESSAGE_APPEND, data });
  1570. },
  1571. flush() {
  1572. return initAndSendMessage({ type: MESSAGE_FLUSH });
  1573. },
  1574. abort() {
  1575. workerData.onTaskFinished();
  1576. }
  1577. };
  1578. }
  1579. return workerData.interface;
  1580. function getWorker(options, baseURL) {
  1581. let url, scriptUrl;
  1582. url = workerData.scripts[0];
  1583. if (typeof url == "function") {
  1584. url = url();
  1585. }
  1586. try {
  1587. scriptUrl = new URL(url, baseURL);
  1588. } catch (_error) {
  1589. scriptUrl = url;
  1590. }
  1591. return new Worker(scriptUrl, options);
  1592. }
  1593. async function initAndSendMessage(message) {
  1594. if (!messageTask) {
  1595. const options = workerData.options;
  1596. const scripts = workerData.scripts.slice(1);
  1597. await sendMessage({ scripts, type: MESSAGE_INIT, options, config: { chunkSize: config.chunkSize } });
  1598. }
  1599. return sendMessage(message);
  1600. }
  1601. function sendMessage(message) {
  1602. const worker = workerData.worker;
  1603. const result = new Promise((resolve, reject) => messageTask = { resolve, reject });
  1604. try {
  1605. if (message.data) {
  1606. try {
  1607. message.data = message.data.buffer;
  1608. worker.postMessage(message, [message.data]);
  1609. } catch (_error) {
  1610. worker.postMessage(message);
  1611. }
  1612. } else {
  1613. worker.postMessage(message);
  1614. }
  1615. } catch (error) {
  1616. messageTask.reject(error);
  1617. messageTask = null;
  1618. workerData.onTaskFinished();
  1619. }
  1620. return result;
  1621. }
  1622. function onMessage(event) {
  1623. const message = event.data;
  1624. if (messageTask) {
  1625. const reponseError = message.error;
  1626. const type = message.type;
  1627. if (reponseError) {
  1628. const error = new Error(reponseError.message);
  1629. error.stack = reponseError.stack;
  1630. messageTask.reject(error);
  1631. messageTask = null;
  1632. workerData.onTaskFinished();
  1633. } else if (type == MESSAGE_INIT || type == MESSAGE_FLUSH || type == MESSAGE_APPEND) {
  1634. const data = message.data;
  1635. if (type == MESSAGE_FLUSH) {
  1636. messageTask.resolve({ data: new Uint8Array(data), signature: message.signature });
  1637. messageTask = null;
  1638. workerData.onTaskFinished();
  1639. } else {
  1640. messageTask.resolve(data && new Uint8Array(data));
  1641. }
  1642. }
  1643. }
  1644. }
  1645. }
  1646. /*
  1647. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  1648. Redistribution and use in source and binary forms, with or without
  1649. modification, are permitted provided that the following conditions are met:
  1650. 1. Redistributions of source code must retain the above copyright notice,
  1651. this list of conditions and the following disclaimer.
  1652. 2. Redistributions in binary form must reproduce the above copyright
  1653. notice, this list of conditions and the following disclaimer in
  1654. the documentation and/or other materials provided with the distribution.
  1655. 3. The names of the authors may not be used to endorse or promote products
  1656. derived from this software without specific prior written permission.
  1657. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  1658. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1659. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  1660. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  1661. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1662. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  1663. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1664. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1665. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1666. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1667. */
  1668. let pool = [];
  1669. const pendingRequests = [];
  1670. function createCodec(codecConstructor, options, config) {
  1671. const streamCopy = !options.compressed && !options.signed && !options.encrypted;
  1672. const webWorker = !streamCopy && (options.useWebWorkers || (options.useWebWorkers === undefined && config.useWebWorkers));
  1673. const scripts = webWorker && config.workerScripts ? config.workerScripts[options.codecType] : [];
  1674. if (pool.length < config.maxWorkers) {
  1675. const workerData = {};
  1676. pool.push(workerData);
  1677. return getWorker(workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts);
  1678. } else {
  1679. const workerData = pool.find(workerData => !workerData.busy);
  1680. if (workerData) {
  1681. clearTerminateTimeout(workerData);
  1682. return getWorker(workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts);
  1683. } else {
  1684. return new Promise(resolve => pendingRequests.push({ resolve, codecConstructor, options, webWorker, scripts }));
  1685. }
  1686. }
  1687. function onTaskFinished(workerData) {
  1688. if (pendingRequests.length) {
  1689. const [{ resolve, codecConstructor, options, webWorker, scripts }] = pendingRequests.splice(0, 1);
  1690. resolve(getWorker(workerData, codecConstructor, options, config, onTaskFinished, webWorker, scripts));
  1691. } else if (workerData.worker) {
  1692. clearTerminateTimeout(workerData);
  1693. if (Number.isFinite(config.terminateWorkerTimeout) && config.terminateWorkerTimeout >= 0) {
  1694. workerData.terminateTimeout = setTimeout(() => {
  1695. pool = pool.filter(data => data != workerData);
  1696. workerData.terminate();
  1697. }, config.terminateWorkerTimeout);
  1698. }
  1699. } else {
  1700. pool = pool.filter(data => data != workerData);
  1701. }
  1702. }
  1703. }
  1704. function clearTerminateTimeout(workerData) {
  1705. if (workerData.terminateTimeout) {
  1706. clearTimeout(workerData.terminateTimeout);
  1707. workerData.terminateTimeout = null;
  1708. }
  1709. }
  1710. function terminateWorkers() {
  1711. pool.forEach(workerData => {
  1712. clearTerminateTimeout(workerData);
  1713. workerData.terminate();
  1714. });
  1715. }
  1716. /*
  1717. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  1718. Redistribution and use in source and binary forms, with or without
  1719. modification, are permitted provided that the following conditions are met:
  1720. 1. Redistributions of source code must retain the above copyright notice,
  1721. this list of conditions and the following disclaimer.
  1722. 2. Redistributions in binary form must reproduce the above copyright
  1723. notice, this list of conditions and the following disclaimer in
  1724. the documentation and/or other materials provided with the distribution.
  1725. 3. The names of the authors may not be used to endorse or promote products
  1726. derived from this software without specific prior written permission.
  1727. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  1728. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1729. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  1730. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  1731. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  1732. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  1733. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  1734. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  1735. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  1736. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1737. */
  1738. /* global Blob, FileReader, atob, btoa, XMLHttpRequest, document, fetch */
  1739. const ERR_HTTP_STATUS = "HTTP error ";
  1740. const ERR_HTTP_RANGE = "HTTP Range not supported";
  1741. const ERR_NOT_SEEKABLE_READER = "Reader is not seekable";
  1742. const CONTENT_TYPE_TEXT_PLAIN = "text/plain";
  1743. const HTTP_HEADER_CONTENT_LENGTH = "Content-Length";
  1744. const HTTP_HEADER_CONTENT_RANGE = "Content-Range";
  1745. const HTTP_HEADER_ACCEPT_RANGES = "Accept-Ranges";
  1746. const HTTP_HEADER_RANGE = "Range";
  1747. const HTTP_METHOD_HEAD = "HEAD";
  1748. const HTTP_METHOD_GET = "GET";
  1749. const HTTP_RANGE_UNIT = "bytes";
  1750. class Stream {
  1751. constructor() {
  1752. this.size = 0;
  1753. }
  1754. init() {
  1755. this.initialized = true;
  1756. }
  1757. }
  1758. class Reader extends Stream {
  1759. }
  1760. class Writer extends Stream {
  1761. writeUint8Array(array) {
  1762. this.size += array.length;
  1763. }
  1764. }
  1765. class TextReader extends Reader {
  1766. constructor(text) {
  1767. super();
  1768. this.blobReader = new BlobReader(new Blob([text], { type: CONTENT_TYPE_TEXT_PLAIN }));
  1769. }
  1770. init() {
  1771. super.init();
  1772. this.blobReader.init();
  1773. this.size = this.blobReader.size;
  1774. }
  1775. readUint8Array(offset, length) {
  1776. return this.blobReader.readUint8Array(offset, length);
  1777. }
  1778. }
  1779. class TextWriter extends Writer {
  1780. constructor(encoding) {
  1781. super();
  1782. this.encoding = encoding;
  1783. this.blob = new Blob([], { type: CONTENT_TYPE_TEXT_PLAIN });
  1784. }
  1785. writeUint8Array(array) {
  1786. super.writeUint8Array(array);
  1787. this.blob = new Blob([this.blob, array.buffer], { type: CONTENT_TYPE_TEXT_PLAIN });
  1788. }
  1789. getData() {
  1790. if (this.blob.text) {
  1791. return this.blob.text();
  1792. } else {
  1793. const reader = new FileReader();
  1794. return new Promise((resolve, reject) => {
  1795. reader.onload = event => resolve(event.target.result);
  1796. reader.onerror = () => reject(reader.error);
  1797. reader.readAsText(this.blob, this.encoding);
  1798. });
  1799. }
  1800. }
  1801. }
  1802. class Data64URIReader extends Reader {
  1803. constructor(dataURI) {
  1804. super();
  1805. this.dataURI = dataURI;
  1806. let dataEnd = dataURI.length;
  1807. while (dataURI.charAt(dataEnd - 1) == "=") {
  1808. dataEnd--;
  1809. }
  1810. this.dataStart = dataURI.indexOf(",") + 1;
  1811. this.size = Math.floor((dataEnd - this.dataStart) * 0.75);
  1812. }
  1813. readUint8Array(offset, length) {
  1814. const dataArray = new Uint8Array(length);
  1815. const start = Math.floor(offset / 3) * 4;
  1816. const bytes = atob(this.dataURI.substring(start + this.dataStart, Math.ceil((offset + length) / 3) * 4 + this.dataStart));
  1817. const delta = offset - Math.floor(start / 4) * 3;
  1818. for (let indexByte = delta; indexByte < delta + length; indexByte++) {
  1819. dataArray[indexByte - delta] = bytes.charCodeAt(indexByte);
  1820. }
  1821. return dataArray;
  1822. }
  1823. }
  1824. class Data64URIWriter extends Writer {
  1825. constructor(contentType) {
  1826. super();
  1827. this.data = "data:" + (contentType || "") + ";base64,";
  1828. this.pending = [];
  1829. }
  1830. writeUint8Array(array) {
  1831. super.writeUint8Array(array);
  1832. let indexArray = 0;
  1833. let dataString = this.pending;
  1834. const delta = this.pending.length;
  1835. this.pending = "";
  1836. for (indexArray = 0; indexArray < (Math.floor((delta + array.length) / 3) * 3) - delta; indexArray++) {
  1837. dataString += String.fromCharCode(array[indexArray]);
  1838. }
  1839. for (; indexArray < array.length; indexArray++) {
  1840. this.pending += String.fromCharCode(array[indexArray]);
  1841. }
  1842. if (dataString.length > 2) {
  1843. this.data += btoa(dataString);
  1844. } else {
  1845. this.pending = dataString;
  1846. }
  1847. }
  1848. getData() {
  1849. return this.data + btoa(this.pending);
  1850. }
  1851. }
  1852. class BlobReader extends Reader {
  1853. constructor(blob) {
  1854. super();
  1855. this.blob = blob;
  1856. this.size = blob.size;
  1857. }
  1858. async readUint8Array(offset, length) {
  1859. if (this.blob.arrayBuffer) {
  1860. return new Uint8Array(await this.blob.slice(offset, offset + length).arrayBuffer());
  1861. } else {
  1862. const reader = new FileReader();
  1863. return new Promise((resolve, reject) => {
  1864. reader.onload = event => resolve(new Uint8Array(event.target.result));
  1865. reader.onerror = () => reject(reader.error);
  1866. reader.readAsArrayBuffer(this.blob.slice(offset, offset + length));
  1867. });
  1868. }
  1869. }
  1870. }
  1871. class BlobWriter extends Writer {
  1872. constructor(contentType) {
  1873. super();
  1874. this.contentType = contentType;
  1875. this.arrayBuffersMaxlength = 8;
  1876. initArrayBuffers(this);
  1877. }
  1878. writeUint8Array(array) {
  1879. super.writeUint8Array(array);
  1880. if (this.arrayBuffers.length == this.arrayBuffersMaxlength) {
  1881. flushArrayBuffers(this);
  1882. }
  1883. this.arrayBuffers.push(array.buffer);
  1884. }
  1885. getData() {
  1886. if (!this.blob) {
  1887. if (this.arrayBuffers.length) {
  1888. flushArrayBuffers(this);
  1889. }
  1890. this.blob = this.pendingBlob;
  1891. initArrayBuffers(this);
  1892. }
  1893. return this.blob;
  1894. }
  1895. }
  1896. function initArrayBuffers(blobWriter) {
  1897. blobWriter.pendingBlob = new Blob([], { type: blobWriter.contentType });
  1898. blobWriter.arrayBuffers = [];
  1899. }
  1900. function flushArrayBuffers(blobWriter) {
  1901. blobWriter.pendingBlob = new Blob([blobWriter.pendingBlob, ...blobWriter.arrayBuffers], { type: blobWriter.contentType });
  1902. blobWriter.arrayBuffers = [];
  1903. }
  1904. class ReadableStreamReader {
  1905. constructor(readableStream) {
  1906. this.readableStream = readableStream;
  1907. this.reader = readableStream.getReader();
  1908. this.size = Infinity;
  1909. this.index = 0;
  1910. this.currentSize = 0;
  1911. this.pendingValue = new Uint8Array();
  1912. }
  1913. init() {
  1914. this.initialized = true;
  1915. }
  1916. async readUint8Array(index, length) {
  1917. if (this.index != index) {
  1918. throw new Error(ERR_NOT_SEEKABLE_READER);
  1919. }
  1920. let data = new Uint8Array(length);
  1921. let size = 0, done;
  1922. do {
  1923. const result = await this.reader.read();
  1924. let { value } = result;
  1925. done = result.done;
  1926. if (value) {
  1927. this.currentSize += value.length;
  1928. } else {
  1929. value = this.pendingValue;
  1930. this.pendingValue = new Uint8Array();
  1931. }
  1932. if (this.pendingValue.length) {
  1933. const newValue = new Uint8Array(this.pendingValue.length + value.length);
  1934. newValue.set(this.pendingValue);
  1935. newValue.set(value, this.pendingValue.length);
  1936. this.pendingValue = new Uint8Array();
  1937. value = newValue;
  1938. }
  1939. if (size + value.length > length) {
  1940. data.set(value.subarray(0, length), size);
  1941. this.pendingValue = value.subarray(length);
  1942. size += length;
  1943. } else {
  1944. data.set(value, size);
  1945. size += value.length;
  1946. }
  1947. } while (size < length && !done);
  1948. if (done && this.size == Infinity) {
  1949. this.size = this.currentSize;
  1950. }
  1951. if (this.size < length) {
  1952. data = data.slice(0, this.size);
  1953. length = this.size;
  1954. }
  1955. this.index += length;
  1956. return data;
  1957. }
  1958. }
  1959. class WritableStreamWriter extends Writer {
  1960. constructor(writableStream) {
  1961. super();
  1962. this.writableStream = writableStream;
  1963. this.writer = writableStream.getWriter();
  1964. }
  1965. async writeUint8Array(array) {
  1966. await this.writer.ready;
  1967. return this.writer.write(array);
  1968. }
  1969. async getData() {
  1970. await this.writer.ready;
  1971. await this.writer.close();
  1972. return this.writableStream;
  1973. }
  1974. }
  1975. class FetchReader extends Reader {
  1976. constructor(url, options) {
  1977. super();
  1978. this.url = url;
  1979. this.preventHeadRequest = options.preventHeadRequest;
  1980. this.useRangeHeader = options.useRangeHeader;
  1981. this.forceRangeRequests = options.forceRangeRequests;
  1982. this.options = Object.assign({}, options);
  1983. delete this.options.preventHeadRequest;
  1984. delete this.options.useRangeHeader;
  1985. delete this.options.forceRangeRequests;
  1986. delete this.options.useXHR;
  1987. }
  1988. async init() {
  1989. super.init();
  1990. await initHttpReader(this, sendFetchRequest, getFetchRequestData);
  1991. }
  1992. readUint8Array(index, length) {
  1993. return readUint8ArrayHttpReader(this, index, length, sendFetchRequest, getFetchRequestData);
  1994. }
  1995. }
  1996. class XHRReader extends Reader {
  1997. constructor(url, options) {
  1998. super();
  1999. this.url = url;
  2000. this.preventHeadRequest = options.preventHeadRequest;
  2001. this.useRangeHeader = options.useRangeHeader;
  2002. this.forceRangeRequests = options.forceRangeRequests;
  2003. this.options = options;
  2004. }
  2005. async init() {
  2006. super.init();
  2007. await initHttpReader(this, sendXMLHttpRequest, getXMLHttpRequestData);
  2008. }
  2009. readUint8Array(index, length) {
  2010. return readUint8ArrayHttpReader(this, index, length, sendXMLHttpRequest, getXMLHttpRequestData);
  2011. }
  2012. }
  2013. async function initHttpReader(httpReader, sendRequest, getRequestData) {
  2014. if (isHttpFamily(httpReader.url) && (httpReader.useRangeHeader || httpReader.forceRangeRequests)) {
  2015. const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader));
  2016. if (!httpReader.forceRangeRequests && response.headers.get(HTTP_HEADER_ACCEPT_RANGES) != HTTP_RANGE_UNIT) {
  2017. throw new Error(ERR_HTTP_RANGE);
  2018. } else {
  2019. let contentSize;
  2020. const contentRangeHeader = response.headers.get(HTTP_HEADER_CONTENT_RANGE);
  2021. if (contentRangeHeader) {
  2022. const splitHeader = contentRangeHeader.trim().split(/\s*\/\s*/);
  2023. if (splitHeader.length) {
  2024. const headerValue = splitHeader[1];
  2025. if (headerValue && headerValue != "*") {
  2026. contentSize = Number(headerValue);
  2027. }
  2028. }
  2029. }
  2030. if (contentSize === undefined) {
  2031. await getContentLength(httpReader, sendRequest, getRequestData);
  2032. } else {
  2033. httpReader.size = contentSize;
  2034. }
  2035. }
  2036. } else {
  2037. await getContentLength(httpReader, sendRequest, getRequestData);
  2038. }
  2039. }
  2040. async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest, getRequestData) {
  2041. if (httpReader.useRangeHeader || httpReader.forceRangeRequests) {
  2042. const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
  2043. if (response.status != 206) {
  2044. throw new Error(ERR_HTTP_RANGE);
  2045. }
  2046. return new Uint8Array(await response.arrayBuffer());
  2047. } else {
  2048. if (!httpReader.data) {
  2049. await getRequestData(httpReader, httpReader.options);
  2050. }
  2051. return new Uint8Array(httpReader.data.subarray(index, index + length));
  2052. }
  2053. }
  2054. function getRangeHeaders(httpReader, index = 0, length = 1) {
  2055. return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + index + "-" + (index + length - 1) });
  2056. }
  2057. function getHeaders(httpReader) {
  2058. const headers = httpReader.options.headers;
  2059. if (headers) {
  2060. if (Symbol.iterator in headers) {
  2061. return Object.fromEntries(headers);
  2062. } else {
  2063. return headers;
  2064. }
  2065. }
  2066. }
  2067. async function getFetchRequestData(httpReader) {
  2068. await getRequestData(httpReader, sendFetchRequest);
  2069. }
  2070. async function getXMLHttpRequestData(httpReader) {
  2071. await getRequestData(httpReader, sendXMLHttpRequest);
  2072. }
  2073. async function getRequestData(httpReader, sendRequest) {
  2074. const response = await sendRequest(HTTP_METHOD_GET, httpReader, getHeaders(httpReader));
  2075. httpReader.data = new Uint8Array(await response.arrayBuffer());
  2076. if (!httpReader.size) {
  2077. httpReader.size = httpReader.data.length;
  2078. }
  2079. }
  2080. async function getContentLength(httpReader, sendRequest, getRequestData) {
  2081. if (httpReader.preventHeadRequest) {
  2082. await getRequestData(httpReader, httpReader.options);
  2083. } else {
  2084. const response = await sendRequest(HTTP_METHOD_HEAD, httpReader, getHeaders(httpReader));
  2085. const contentLength = response.headers.get(HTTP_HEADER_CONTENT_LENGTH);
  2086. if (contentLength) {
  2087. httpReader.size = Number(contentLength);
  2088. } else {
  2089. await getRequestData(httpReader, httpReader.options);
  2090. }
  2091. }
  2092. }
  2093. async function sendFetchRequest(method, { options, url }, headers) {
  2094. const response = await fetch(url, Object.assign({}, options, { method, headers }));
  2095. if (response.status < 400) {
  2096. return response;
  2097. } else {
  2098. throw new Error(ERR_HTTP_STATUS + (response.statusText || response.status));
  2099. }
  2100. }
  2101. function sendXMLHttpRequest(method, { url }, headers) {
  2102. return new Promise((resolve, reject) => {
  2103. const request = new XMLHttpRequest();
  2104. request.addEventListener("load", () => {
  2105. if (request.status < 400) {
  2106. const headers = [];
  2107. request.getAllResponseHeaders().trim().split(/[\r\n]+/).forEach(header => {
  2108. const splitHeader = header.trim().split(/\s*:\s*/);
  2109. splitHeader[0] = splitHeader[0].trim().replace(/^[a-z]|-[a-z]/g, value => value.toUpperCase());
  2110. headers.push(splitHeader);
  2111. });
  2112. resolve({
  2113. status: request.status,
  2114. arrayBuffer: () => request.response,
  2115. headers: new Map(headers)
  2116. });
  2117. } else {
  2118. reject(new Error(ERR_HTTP_STATUS + (request.statusText || request.status)));
  2119. }
  2120. }, false);
  2121. request.addEventListener("error", event => reject(event.detail.error), false);
  2122. request.open(method, url);
  2123. if (headers) {
  2124. for (const entry of Object.entries(headers)) {
  2125. request.setRequestHeader(entry[0], entry[1]);
  2126. }
  2127. }
  2128. request.responseType = "arraybuffer";
  2129. request.send();
  2130. });
  2131. }
  2132. class HttpReader extends Reader {
  2133. constructor(url, options = {}) {
  2134. super();
  2135. this.url = url;
  2136. if (options.useXHR) {
  2137. this.reader = new XHRReader(url, options);
  2138. } else {
  2139. this.reader = new FetchReader(url, options);
  2140. }
  2141. }
  2142. set size(value) {
  2143. // ignored
  2144. }
  2145. get size() {
  2146. return this.reader.size;
  2147. }
  2148. async init() {
  2149. super.init();
  2150. await this.reader.init();
  2151. }
  2152. readUint8Array(index, length) {
  2153. return this.reader.readUint8Array(index, length);
  2154. }
  2155. }
  2156. class HttpRangeReader extends HttpReader {
  2157. constructor(url, options = {}) {
  2158. options.useRangeHeader = true;
  2159. super(url, options);
  2160. }
  2161. }
  2162. class Uint8ArrayReader extends Reader {
  2163. constructor(array) {
  2164. super();
  2165. this.array = array;
  2166. this.size = array.length;
  2167. }
  2168. readUint8Array(index, length) {
  2169. return this.array.slice(index, index + length);
  2170. }
  2171. }
  2172. class Uint8ArrayWriter extends Writer {
  2173. constructor() {
  2174. super();
  2175. this.array = new Uint8Array(0);
  2176. }
  2177. writeUint8Array(array) {
  2178. super.writeUint8Array(array);
  2179. const previousArray = this.array;
  2180. this.array = new Uint8Array(previousArray.length + array.length);
  2181. this.array.set(previousArray);
  2182. this.array.set(array, previousArray.length);
  2183. }
  2184. getData() {
  2185. return this.array;
  2186. }
  2187. }
  2188. function isHttpFamily(url) {
  2189. if (typeof document != "undefined") {
  2190. const anchor = document.createElement("a");
  2191. anchor.href = url;
  2192. return anchor.protocol == "http:" || anchor.protocol == "https:";
  2193. } else {
  2194. return /^https?:\/\//i.test(url);
  2195. }
  2196. }
  2197. /*
  2198. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  2199. Redistribution and use in source and binary forms, with or without
  2200. modification, are permitted provided that the following conditions are met:
  2201. 1. Redistributions of source code must retain the above copyright notice,
  2202. this list of conditions and the following disclaimer.
  2203. 2. Redistributions in binary form must reproduce the above copyright
  2204. notice, this list of conditions and the following disclaimer in
  2205. the documentation and/or other materials provided with the distribution.
  2206. 3. The names of the authors may not be used to endorse or promote products
  2207. derived from this software without specific prior written permission.
  2208. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  2209. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  2210. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  2211. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  2212. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2213. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  2214. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2215. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2216. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2217. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2218. */
  2219. const MAX_32_BITS = 0xffffffff;
  2220. const MAX_16_BITS = 0xffff;
  2221. const COMPRESSION_METHOD_DEFLATE = 0x08;
  2222. const COMPRESSION_METHOD_STORE = 0x00;
  2223. const COMPRESSION_METHOD_AES = 0x63;
  2224. const LOCAL_FILE_HEADER_SIGNATURE = 0x04034b50;
  2225. const DATA_DESCRIPTOR_RECORD_SIGNATURE = 0x08074b50;
  2226. const CENTRAL_FILE_HEADER_SIGNATURE = 0x02014b50;
  2227. const END_OF_CENTRAL_DIR_SIGNATURE = 0x06054b50;
  2228. const ZIP64_END_OF_CENTRAL_DIR_SIGNATURE = 0x06064b50;
  2229. const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE = 0x07064b50;
  2230. const END_OF_CENTRAL_DIR_LENGTH = 22;
  2231. const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
  2232. const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
  2233. 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;
  2234. const ZIP64_TOTAL_NUMBER_OF_DISKS = 1;
  2235. const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
  2236. const EXTRAFIELD_TYPE_AES = 0x9901;
  2237. const EXTRAFIELD_TYPE_NTFS = 0x000a;
  2238. const EXTRAFIELD_TYPE_NTFS_TAG1 = 0x0001;
  2239. const EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP = 0x5455;
  2240. const EXTRAFIELD_TYPE_UNICODE_PATH = 0x7075;
  2241. const EXTRAFIELD_TYPE_UNICODE_COMMENT = 0x6375;
  2242. const BITFLAG_ENCRYPTED = 0x01;
  2243. const BITFLAG_LEVEL = 0x06;
  2244. const BITFLAG_DATA_DESCRIPTOR = 0x0008;
  2245. const BITFLAG_LANG_ENCODING_FLAG = 0x0800;
  2246. const FILE_ATTR_MSDOS_DIR_MASK = 0x10;
  2247. const VERSION_DEFLATE = 0x14;
  2248. const VERSION_ZIP64 = 0x2D;
  2249. const VERSION_AES = 0x33;
  2250. const DIRECTORY_SIGNATURE = "/";
  2251. const MAX_DATE = new Date(2107, 11, 31);
  2252. const MIN_DATE = new Date(1980, 0, 1);
  2253. /*
  2254. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  2255. Redistribution and use in source and binary forms, with or without
  2256. modification, are permitted provided that the following conditions are met:
  2257. 1. Redistributions of source code must retain the above copyright notice,
  2258. this list of conditions and the following disclaimer.
  2259. 2. Redistributions in binary form must reproduce the above copyright
  2260. notice, this list of conditions and the following disclaimer in
  2261. the documentation and/or other materials provided with the distribution.
  2262. 3. The names of the authors may not be used to endorse or promote products
  2263. derived from this software without specific prior written permission.
  2264. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  2265. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  2266. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  2267. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  2268. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2269. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  2270. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2271. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2272. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2273. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2274. */
  2275. const CP437 = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ".split("");
  2276. var decodeCP437 = stringValue => {
  2277. let result = "";
  2278. for (let indexCharacter = 0; indexCharacter < stringValue.length; indexCharacter++) {
  2279. result += CP437[stringValue[indexCharacter]];
  2280. }
  2281. return result;
  2282. };
  2283. /*
  2284. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  2285. Redistribution and use in source and binary forms, with or without
  2286. modification, are permitted provided that the following conditions are met:
  2287. 1. Redistributions of source code must retain the above copyright notice,
  2288. this list of conditions and the following disclaimer.
  2289. 2. Redistributions in binary form must reproduce the above copyright
  2290. notice, this list of conditions and the following disclaimer in
  2291. the documentation and/or other materials provided with the distribution.
  2292. 3. The names of the authors may not be used to endorse or promote products
  2293. derived from this software without specific prior written permission.
  2294. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  2295. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  2296. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  2297. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  2298. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2299. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  2300. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2301. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2302. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2303. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2304. */
  2305. function decodeText(value, encoding) {
  2306. if (encoding && encoding.trim().toLowerCase() == "cp437") {
  2307. return decodeCP437(value);
  2308. } else if (typeof TextDecoder == "undefined") {
  2309. const fileReader = new FileReader();
  2310. return new Promise((resolve, reject) => {
  2311. fileReader.onload = event => resolve(event.target.result);
  2312. fileReader.onerror = () => reject(fileReader.error);
  2313. fileReader.readAsText(new Blob([value]));
  2314. });
  2315. } else {
  2316. return new TextDecoder(encoding).decode(value);
  2317. }
  2318. }
  2319. /*
  2320. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  2321. Redistribution and use in source and binary forms, with or without
  2322. modification, are permitted provided that the following conditions are met:
  2323. 1. Redistributions of source code must retain the above copyright notice,
  2324. this list of conditions and the following disclaimer.
  2325. 2. Redistributions in binary form must reproduce the above copyright
  2326. notice, this list of conditions and the following disclaimer in
  2327. the documentation and/or other materials provided with the distribution.
  2328. 3. The names of the authors may not be used to endorse or promote products
  2329. derived from this software without specific prior written permission.
  2330. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  2331. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  2332. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  2333. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  2334. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2335. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  2336. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2337. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2338. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2339. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2340. */
  2341. const MINIMUM_CHUNK_SIZE = 64;
  2342. const ERR_ABORT = "Abort error";
  2343. async function processData(codec, reader, writer, offset, inputLengthGetter, config, options) {
  2344. const chunkSize = Math.max(config.chunkSize, MINIMUM_CHUNK_SIZE);
  2345. return processChunk();
  2346. async function processChunk(chunkOffset = 0, outputLength = 0) {
  2347. const signal = options.signal;
  2348. const inputLength = inputLengthGetter();
  2349. if (chunkOffset < inputLength) {
  2350. testAborted(signal, codec);
  2351. const inputData = await reader.readUint8Array(chunkOffset + offset, Math.min(chunkSize, inputLength - chunkOffset));
  2352. const chunkLength = inputData.length;
  2353. testAborted(signal, codec);
  2354. const data = await codec.append(inputData);
  2355. testAborted(signal, codec);
  2356. outputLength += await writeData(writer, data);
  2357. if (options.onprogress) {
  2358. try {
  2359. options.onprogress(chunkOffset + chunkLength, inputLength);
  2360. } catch (error) {
  2361. // ignored
  2362. }
  2363. }
  2364. return processChunk(chunkOffset + chunkSize, outputLength);
  2365. } else {
  2366. const result = await codec.flush();
  2367. outputLength += await writeData(writer, result.data);
  2368. return { signature: result.signature, length: outputLength };
  2369. }
  2370. }
  2371. }
  2372. function testAborted(signal, codec) {
  2373. if (signal && signal.aborted) {
  2374. codec.abort();
  2375. throw new Error(ERR_ABORT);
  2376. }
  2377. }
  2378. async function writeData(writer, data) {
  2379. if (data.length) {
  2380. await writer.writeUint8Array(data);
  2381. }
  2382. return data.length;
  2383. }
  2384. /*
  2385. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  2386. Redistribution and use in source and binary forms, with or without
  2387. modification, are permitted provided that the following conditions are met:
  2388. 1. Redistributions of source code must retain the above copyright notice,
  2389. this list of conditions and the following disclaimer.
  2390. 2. Redistributions in binary form must reproduce the above copyright
  2391. notice, this list of conditions and the following disclaimer in
  2392. the documentation and/or other materials provided with the distribution.
  2393. 3. The names of the authors may not be used to endorse or promote products
  2394. derived from this software without specific prior written permission.
  2395. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  2396. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  2397. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  2398. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  2399. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2400. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  2401. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2402. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2403. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2404. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2405. */
  2406. const PROPERTY_NAMES = [
  2407. "filename", "rawFilename", "directory", "encrypted", "compressedSize", "uncompressedSize",
  2408. "lastModDate", "rawLastModDate", "comment", "rawComment", "signature", "extraField",
  2409. "rawExtraField", "bitFlag", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment",
  2410. "extraFieldAES", "filenameUTF8", "commentUTF8", "offset", "zip64", "compressionMethod",
  2411. "extraFieldNTFS", "lastAccessDate", "creationDate", "extraFieldExtendedTimestamp",
  2412. "version", "versionMadeBy", "msDosCompatible", "internalFileAttribute", "externalFileAttribute"];
  2413. class Entry {
  2414. constructor(data) {
  2415. PROPERTY_NAMES.forEach(name => this[name] = data[name]);
  2416. }
  2417. }
  2418. /*
  2419. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  2420. Redistribution and use in source and binary forms, with or without
  2421. modification, are permitted provided that the following conditions are met:
  2422. 1. Redistributions of source code must retain the above copyright notice,
  2423. this list of conditions and the following disclaimer.
  2424. 2. Redistributions in binary form must reproduce the above copyright
  2425. notice, this list of conditions and the following disclaimer in
  2426. the documentation and/or other materials provided with the distribution.
  2427. 3. The names of the authors may not be used to endorse or promote products
  2428. derived from this software without specific prior written permission.
  2429. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  2430. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  2431. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  2432. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  2433. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2434. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  2435. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2436. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2437. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2438. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2439. */
  2440. const ERR_BAD_FORMAT = "File format is not recognized";
  2441. const ERR_EOCDR_NOT_FOUND = "End of central directory not found";
  2442. const ERR_EOCDR_ZIP64_NOT_FOUND = "End of Zip64 central directory not found";
  2443. const ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = "End of Zip64 central directory locator not found";
  2444. const ERR_CENTRAL_DIRECTORY_NOT_FOUND = "Central directory header not found";
  2445. const ERR_LOCAL_FILE_HEADER_NOT_FOUND = "Local file header not found";
  2446. const ERR_EXTRAFIELD_ZIP64_NOT_FOUND = "Zip64 extra field not found";
  2447. const ERR_ENCRYPTED = "File contains encrypted entry";
  2448. const ERR_UNSUPPORTED_ENCRYPTION = "Encryption method not supported";
  2449. const ERR_UNSUPPORTED_COMPRESSION = "Compression method not supported";
  2450. const CHARSET_UTF8 = "utf-8";
  2451. const CHARSET_CP437 = "cp437";
  2452. const ZIP64_PROPERTIES = ["uncompressedSize", "compressedSize", "offset"];
  2453. class ZipReader {
  2454. constructor(reader, options = {}) {
  2455. Object.assign(this, {
  2456. reader,
  2457. options,
  2458. config: getConfiguration()
  2459. });
  2460. }
  2461. async* getEntriesGenerator(options = {}) {
  2462. const zipReader = this;
  2463. const reader = zipReader.reader;
  2464. if (!reader.initialized) {
  2465. await reader.init();
  2466. }
  2467. if (reader.size < END_OF_CENTRAL_DIR_LENGTH) {
  2468. throw new Error(ERR_BAD_FORMAT);
  2469. }
  2470. const endOfDirectoryInfo = await seekSignature(reader, END_OF_CENTRAL_DIR_SIGNATURE, reader.size, END_OF_CENTRAL_DIR_LENGTH, MAX_16_BITS * 16);
  2471. if (!endOfDirectoryInfo) {
  2472. throw new Error(ERR_EOCDR_NOT_FOUND);
  2473. }
  2474. const endOfDirectoryView = getDataView$1(endOfDirectoryInfo);
  2475. let directoryDataLength = getUint32(endOfDirectoryView, 12);
  2476. let directoryDataOffset = getUint32(endOfDirectoryView, 16);
  2477. let filesLength = getUint16(endOfDirectoryView, 8);
  2478. let prependedDataLength = 0;
  2479. if (directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS) {
  2480. const endOfDirectoryLocatorArray = await readUint8Array(reader, endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH);
  2481. const endOfDirectoryLocatorView = getDataView$1(endOfDirectoryLocatorArray);
  2482. if (getUint32(endOfDirectoryLocatorView, 0) != ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) {
  2483. throw new Error(ERR_EOCDR_ZIP64_NOT_FOUND);
  2484. }
  2485. directoryDataOffset = getBigUint64(endOfDirectoryLocatorView, 8);
  2486. let endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
  2487. let endOfDirectoryView = getDataView$1(endOfDirectoryArray);
  2488. const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH - ZIP64_END_OF_CENTRAL_DIR_LENGTH;
  2489. if (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE && directoryDataOffset != expectedDirectoryDataOffset) {
  2490. const originalDirectoryDataOffset = directoryDataOffset;
  2491. directoryDataOffset = expectedDirectoryDataOffset;
  2492. prependedDataLength = directoryDataOffset - originalDirectoryDataOffset;
  2493. endOfDirectoryArray = await readUint8Array(reader, directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH);
  2494. endOfDirectoryView = getDataView$1(endOfDirectoryArray);
  2495. }
  2496. if (getUint32(endOfDirectoryView, 0) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) {
  2497. throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND);
  2498. }
  2499. filesLength = getBigUint64(endOfDirectoryView, 32);
  2500. directoryDataLength = getBigUint64(endOfDirectoryView, 40);
  2501. directoryDataOffset -= directoryDataLength;
  2502. }
  2503. if (directoryDataOffset < 0 || directoryDataOffset >= reader.size) {
  2504. throw new Error(ERR_BAD_FORMAT);
  2505. }
  2506. let offset = 0;
  2507. let directoryArray = await readUint8Array(reader, directoryDataOffset, directoryDataLength);
  2508. let directoryView = getDataView$1(directoryArray);
  2509. if (directoryDataLength) {
  2510. const expectedDirectoryDataOffset = endOfDirectoryInfo.offset - directoryDataLength;
  2511. if (getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE && directoryDataOffset != expectedDirectoryDataOffset) {
  2512. const originalDirectoryDataOffset = directoryDataOffset;
  2513. directoryDataOffset = expectedDirectoryDataOffset;
  2514. prependedDataLength = directoryDataOffset - originalDirectoryDataOffset;
  2515. directoryArray = await readUint8Array(reader, directoryDataOffset, directoryDataLength);
  2516. directoryView = getDataView$1(directoryArray);
  2517. }
  2518. }
  2519. if (directoryDataOffset < 0 || directoryDataOffset >= reader.size) {
  2520. throw new Error(ERR_BAD_FORMAT);
  2521. }
  2522. for (let indexFile = 0; indexFile < filesLength; indexFile++) {
  2523. const fileEntry = new ZipEntry$1(reader, zipReader.config, zipReader.options);
  2524. if (getUint32(directoryView, offset) != CENTRAL_FILE_HEADER_SIGNATURE) {
  2525. throw new Error(ERR_CENTRAL_DIRECTORY_NOT_FOUND);
  2526. }
  2527. readCommonHeader(fileEntry, directoryView, offset + 6);
  2528. const languageEncodingFlag = Boolean(fileEntry.bitFlag.languageEncodingFlag);
  2529. const filenameOffset = offset + 46;
  2530. const extraFieldOffset = filenameOffset + fileEntry.filenameLength;
  2531. const commentOffset = extraFieldOffset + fileEntry.extraFieldLength;
  2532. const versionMadeBy = getUint16(directoryView, offset + 4);
  2533. const msDosCompatible = (versionMadeBy & 0) == 0;
  2534. Object.assign(fileEntry, {
  2535. versionMadeBy,
  2536. msDosCompatible,
  2537. compressedSize: 0,
  2538. uncompressedSize: 0,
  2539. commentLength: getUint16(directoryView, offset + 32),
  2540. directory: msDosCompatible && ((getUint8(directoryView, offset + 38) & FILE_ATTR_MSDOS_DIR_MASK) == FILE_ATTR_MSDOS_DIR_MASK),
  2541. offset: getUint32(directoryView, offset + 42) + prependedDataLength,
  2542. internalFileAttribute: getUint32(directoryView, offset + 34),
  2543. externalFileAttribute: getUint32(directoryView, offset + 38),
  2544. rawFilename: directoryArray.subarray(filenameOffset, extraFieldOffset),
  2545. filenameUTF8: languageEncodingFlag,
  2546. commentUTF8: languageEncodingFlag,
  2547. rawExtraField: directoryArray.subarray(extraFieldOffset, commentOffset)
  2548. });
  2549. const endOffset = commentOffset + fileEntry.commentLength;
  2550. fileEntry.rawComment = directoryArray.subarray(commentOffset, endOffset);
  2551. const filenameEncoding = getOptionValue$1(zipReader, options, "filenameEncoding");
  2552. const commentEncoding = getOptionValue$1(zipReader, options, "commentEncoding");
  2553. const [filename, comment] = await Promise.all([
  2554. decodeText(fileEntry.rawFilename, fileEntry.filenameUTF8 ? CHARSET_UTF8 : filenameEncoding || CHARSET_CP437),
  2555. decodeText(fileEntry.rawComment, fileEntry.commentUTF8 ? CHARSET_UTF8 : commentEncoding || CHARSET_CP437)
  2556. ]);
  2557. fileEntry.filename = filename;
  2558. fileEntry.comment = comment;
  2559. if (!fileEntry.directory && fileEntry.filename.endsWith(DIRECTORY_SIGNATURE)) {
  2560. fileEntry.directory = true;
  2561. }
  2562. await readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6);
  2563. const entry = new Entry(fileEntry);
  2564. entry.getData = (writer, options) => fileEntry.getData(writer, entry, options);
  2565. offset = endOffset;
  2566. if (options.onprogress) {
  2567. try {
  2568. options.onprogress(indexFile + 1, filesLength, new Entry(fileEntry));
  2569. } catch (_error) {
  2570. // ignored
  2571. }
  2572. }
  2573. yield entry;
  2574. }
  2575. return true;
  2576. }
  2577. async getEntries(options = {}) {
  2578. const entries = [];
  2579. const iter = this.getEntriesGenerator(options);
  2580. let curr = iter.next();
  2581. while(!(await curr).done) {
  2582. entries.push((await curr).value);
  2583. curr = iter.next();
  2584. }
  2585. return entries;
  2586. }
  2587. async close() {
  2588. }
  2589. }
  2590. class ZipEntry$1 {
  2591. constructor(reader, config, options) {
  2592. Object.assign(this, {
  2593. reader,
  2594. config,
  2595. options
  2596. });
  2597. }
  2598. async getData(writer, fileEntry, options = {}) {
  2599. const zipEntry = this;
  2600. const {
  2601. reader,
  2602. offset,
  2603. extraFieldAES,
  2604. compressionMethod,
  2605. config,
  2606. bitFlag,
  2607. signature,
  2608. rawLastModDate,
  2609. compressedSize
  2610. } = zipEntry;
  2611. const localDirectory = zipEntry.localDirectory = {};
  2612. if (!reader.initialized) {
  2613. await reader.init();
  2614. }
  2615. let dataArray = await readUint8Array(reader, offset, 30);
  2616. const dataView = getDataView$1(dataArray);
  2617. let password = getOptionValue$1(zipEntry, options, "password");
  2618. password = password && password.length && password;
  2619. if (extraFieldAES) {
  2620. if (extraFieldAES.originalCompressionMethod != COMPRESSION_METHOD_AES) {
  2621. throw new Error(ERR_UNSUPPORTED_COMPRESSION);
  2622. }
  2623. }
  2624. if (compressionMethod != COMPRESSION_METHOD_STORE && compressionMethod != COMPRESSION_METHOD_DEFLATE) {
  2625. throw new Error(ERR_UNSUPPORTED_COMPRESSION);
  2626. }
  2627. if (getUint32(dataView, 0) != LOCAL_FILE_HEADER_SIGNATURE) {
  2628. throw new Error(ERR_LOCAL_FILE_HEADER_NOT_FOUND);
  2629. }
  2630. readCommonHeader(localDirectory, dataView, 4);
  2631. dataArray = await readUint8Array(reader, offset, 30 + localDirectory.filenameLength + localDirectory.extraFieldLength);
  2632. localDirectory.rawExtraField = dataArray.subarray(30 + localDirectory.filenameLength);
  2633. await readCommonFooter(zipEntry, localDirectory, dataView, 4);
  2634. fileEntry.lastAccessDate = localDirectory.lastAccessDate;
  2635. fileEntry.creationDate = localDirectory.creationDate;
  2636. const encrypted = zipEntry.encrypted && localDirectory.encrypted;
  2637. const zipCrypto = encrypted && !extraFieldAES;
  2638. if (encrypted) {
  2639. if (!zipCrypto && extraFieldAES.strength === undefined) {
  2640. throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
  2641. } else if (!password) {
  2642. throw new Error(ERR_ENCRYPTED);
  2643. }
  2644. }
  2645. const codec = await createCodec(config.Inflate, {
  2646. codecType: CODEC_INFLATE,
  2647. password,
  2648. zipCrypto,
  2649. encryptionStrength: extraFieldAES && extraFieldAES.strength,
  2650. signed: getOptionValue$1(zipEntry, options, "checkSignature"),
  2651. passwordVerification: zipCrypto && (bitFlag.dataDescriptor ? ((rawLastModDate >>> 8) & 0xFF) : ((signature >>> 24) & 0xFF)),
  2652. signature,
  2653. compressed: compressionMethod != 0,
  2654. encrypted,
  2655. useWebWorkers: getOptionValue$1(zipEntry, options, "useWebWorkers")
  2656. }, config);
  2657. if (!writer.initialized) {
  2658. await writer.init();
  2659. }
  2660. const signal = getOptionValue$1(zipEntry, options, "signal");
  2661. const dataOffset = offset + 30 + localDirectory.filenameLength + localDirectory.extraFieldLength;
  2662. await processData(codec, reader, writer, dataOffset, () => compressedSize, config, { onprogress: options.onprogress, signal });
  2663. return writer.getData();
  2664. }
  2665. }
  2666. function readCommonHeader(directory, dataView, offset) {
  2667. const rawBitFlag = directory.rawBitFlag = getUint16(dataView, offset + 2);
  2668. const encrypted = (rawBitFlag & BITFLAG_ENCRYPTED) == BITFLAG_ENCRYPTED;
  2669. const rawLastModDate = getUint32(dataView, offset + 6);
  2670. Object.assign(directory, {
  2671. encrypted,
  2672. version: getUint16(dataView, offset),
  2673. bitFlag: {
  2674. level: (rawBitFlag & BITFLAG_LEVEL) >> 1,
  2675. dataDescriptor: (rawBitFlag & BITFLAG_DATA_DESCRIPTOR) == BITFLAG_DATA_DESCRIPTOR,
  2676. languageEncodingFlag: (rawBitFlag & BITFLAG_LANG_ENCODING_FLAG) == BITFLAG_LANG_ENCODING_FLAG
  2677. },
  2678. rawLastModDate,
  2679. lastModDate: getDate(rawLastModDate),
  2680. filenameLength: getUint16(dataView, offset + 22),
  2681. extraFieldLength: getUint16(dataView, offset + 24)
  2682. });
  2683. }
  2684. async function readCommonFooter(fileEntry, directory, dataView, offset) {
  2685. const rawExtraField = directory.rawExtraField;
  2686. const extraField = directory.extraField = new Map();
  2687. const rawExtraFieldView = getDataView$1(new Uint8Array(rawExtraField));
  2688. let offsetExtraField = 0;
  2689. try {
  2690. while (offsetExtraField < rawExtraField.length) {
  2691. const type = getUint16(rawExtraFieldView, offsetExtraField);
  2692. const size = getUint16(rawExtraFieldView, offsetExtraField + 2);
  2693. extraField.set(type, {
  2694. type,
  2695. data: rawExtraField.slice(offsetExtraField + 4, offsetExtraField + 4 + size)
  2696. });
  2697. offsetExtraField += 4 + size;
  2698. }
  2699. } catch (_error) {
  2700. // ignored
  2701. }
  2702. const compressionMethod = getUint16(dataView, offset + 4);
  2703. directory.signature = getUint32(dataView, offset + 10);
  2704. directory.uncompressedSize = getUint32(dataView, offset + 18);
  2705. directory.compressedSize = getUint32(dataView, offset + 14);
  2706. const extraFieldZip64 = extraField.get(EXTRAFIELD_TYPE_ZIP64);
  2707. if (extraFieldZip64) {
  2708. readExtraFieldZip64(extraFieldZip64, directory);
  2709. directory.extraFieldZip64 = extraFieldZip64;
  2710. }
  2711. const extraFieldUnicodePath = extraField.get(EXTRAFIELD_TYPE_UNICODE_PATH);
  2712. if (extraFieldUnicodePath) {
  2713. await readExtraFieldUnicode(extraFieldUnicodePath, "filename", "rawFilename", directory, fileEntry);
  2714. directory.extraFieldUnicodePath = extraFieldUnicodePath;
  2715. }
  2716. const extraFieldUnicodeComment = extraField.get(EXTRAFIELD_TYPE_UNICODE_COMMENT);
  2717. if (extraFieldUnicodeComment) {
  2718. await readExtraFieldUnicode(extraFieldUnicodeComment, "comment", "rawComment", directory, fileEntry);
  2719. directory.extraFieldUnicodeComment = extraFieldUnicodeComment;
  2720. }
  2721. const extraFieldAES = extraField.get(EXTRAFIELD_TYPE_AES);
  2722. if (extraFieldAES) {
  2723. readExtraFieldAES(extraFieldAES, directory, compressionMethod);
  2724. directory.extraFieldAES = extraFieldAES;
  2725. } else {
  2726. directory.compressionMethod = compressionMethod;
  2727. }
  2728. const extraFieldNTFS = extraField.get(EXTRAFIELD_TYPE_NTFS);
  2729. if (extraFieldNTFS) {
  2730. readExtraFieldNTFS(extraFieldNTFS, directory);
  2731. directory.extraFieldNTFS = extraFieldNTFS;
  2732. }
  2733. const extraFieldExtendedTimestamp = extraField.get(EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
  2734. if (extraFieldExtendedTimestamp) {
  2735. readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory);
  2736. directory.extraFieldExtendedTimestamp = extraFieldExtendedTimestamp;
  2737. }
  2738. }
  2739. function readExtraFieldZip64(extraFieldZip64, directory) {
  2740. directory.zip64 = true;
  2741. const extraFieldView = getDataView$1(extraFieldZip64.data);
  2742. extraFieldZip64.values = [];
  2743. for (let indexValue = 0; indexValue < Math.floor(extraFieldZip64.data.length / 8); indexValue++) {
  2744. extraFieldZip64.values.push(getBigUint64(extraFieldView, 0 + indexValue * 8));
  2745. }
  2746. const missingProperties = ZIP64_PROPERTIES.filter(propertyName => directory[propertyName] == MAX_32_BITS);
  2747. for (let indexMissingProperty = 0; indexMissingProperty < missingProperties.length; indexMissingProperty++) {
  2748. extraFieldZip64[missingProperties[indexMissingProperty]] = extraFieldZip64.values[indexMissingProperty];
  2749. }
  2750. ZIP64_PROPERTIES.forEach(propertyName => {
  2751. if (directory[propertyName] == MAX_32_BITS) {
  2752. if (extraFieldZip64[propertyName] !== undefined) {
  2753. directory[propertyName] = extraFieldZip64[propertyName];
  2754. } else {
  2755. throw new Error(ERR_EXTRAFIELD_ZIP64_NOT_FOUND);
  2756. }
  2757. }
  2758. });
  2759. }
  2760. async function readExtraFieldUnicode(extraFieldUnicode, propertyName, rawPropertyName, directory, fileEntry) {
  2761. const extraFieldView = getDataView$1(extraFieldUnicode.data);
  2762. extraFieldUnicode.version = getUint8(extraFieldView, 0);
  2763. extraFieldUnicode.signature = getUint32(extraFieldView, 1);
  2764. const crc32 = new Crc32();
  2765. crc32.append(fileEntry[rawPropertyName]);
  2766. const dataViewSignature = getDataView$1(new Uint8Array(4));
  2767. dataViewSignature.setUint32(0, crc32.get(), true);
  2768. extraFieldUnicode[propertyName] = await decodeText(extraFieldUnicode.data.subarray(5));
  2769. extraFieldUnicode.valid = !fileEntry.bitFlag.languageEncodingFlag && extraFieldUnicode.signature == getUint32(dataViewSignature, 0);
  2770. if (extraFieldUnicode.valid) {
  2771. directory[propertyName] = extraFieldUnicode[propertyName];
  2772. directory[propertyName + "UTF8"] = true;
  2773. }
  2774. }
  2775. function readExtraFieldAES(extraFieldAES, directory, compressionMethod) {
  2776. const extraFieldView = getDataView$1(extraFieldAES.data);
  2777. extraFieldAES.vendorVersion = getUint8(extraFieldView, 0);
  2778. extraFieldAES.vendorId = getUint8(extraFieldView, 2);
  2779. const strength = getUint8(extraFieldView, 4);
  2780. extraFieldAES.strength = strength;
  2781. extraFieldAES.originalCompressionMethod = compressionMethod;
  2782. directory.compressionMethod = extraFieldAES.compressionMethod = getUint16(extraFieldView, 5);
  2783. }
  2784. function readExtraFieldNTFS(extraFieldNTFS, directory) {
  2785. const extraFieldView = getDataView$1(extraFieldNTFS.data);
  2786. let offsetExtraField = 4;
  2787. let tag1Data;
  2788. try {
  2789. while (offsetExtraField < extraFieldNTFS.data.length && !tag1Data) {
  2790. const tagValue = getUint16(extraFieldView, offsetExtraField);
  2791. const attributeSize = getUint16(extraFieldView, offsetExtraField + 2);
  2792. if (tagValue == EXTRAFIELD_TYPE_NTFS_TAG1) {
  2793. tag1Data = extraFieldNTFS.data.slice(offsetExtraField + 4, offsetExtraField + 4 + attributeSize);
  2794. }
  2795. offsetExtraField += 4 + attributeSize;
  2796. }
  2797. } catch (_error) {
  2798. // ignored
  2799. }
  2800. try {
  2801. if (tag1Data && tag1Data.length == 24) {
  2802. const tag1View = getDataView$1(tag1Data);
  2803. const rawLastModDate = tag1View.getBigUint64(0, true);
  2804. const rawLastAccessDate = tag1View.getBigUint64(8, true);
  2805. const rawCreationDate = tag1View.getBigUint64(16, true);
  2806. Object.assign(extraFieldNTFS, {
  2807. rawLastModDate,
  2808. rawLastAccessDate,
  2809. rawCreationDate
  2810. });
  2811. const lastModDate = getDateNTFS(rawLastModDate);
  2812. const lastAccessDate = getDateNTFS(rawLastAccessDate);
  2813. const creationDate = getDateNTFS(rawCreationDate);
  2814. const extraFieldData = { lastModDate, lastAccessDate, creationDate };
  2815. Object.assign(extraFieldNTFS, extraFieldData);
  2816. Object.assign(directory, extraFieldData);
  2817. }
  2818. } catch (_error) {
  2819. // ignored
  2820. }
  2821. }
  2822. function readExtraFieldExtendedTimestamp(extraFieldExtendedTimestamp, directory) {
  2823. const extraFieldView = getDataView$1(extraFieldExtendedTimestamp.data);
  2824. const flags = getUint8(extraFieldView, 0);
  2825. const timeProperties = [];
  2826. const timeRawProperties = [];
  2827. if ((flags & 0x1) == 0x1) {
  2828. timeProperties.push("lastModDate");
  2829. timeRawProperties.push("rawLastModDate");
  2830. }
  2831. if ((flags & 0x2) == 0x2) {
  2832. timeProperties.push("lastAccessDate");
  2833. timeRawProperties.push("rawLastAccessDate");
  2834. }
  2835. if ((flags & 0x4) == 0x4) {
  2836. timeProperties.push("creationDate");
  2837. timeRawProperties.push("rawCreationDate");
  2838. }
  2839. let offset = 1;
  2840. timeProperties.forEach((propertyName, indexProperty) => {
  2841. if (extraFieldExtendedTimestamp.data.length >= offset + 4) {
  2842. const time = getUint32(extraFieldView, offset);
  2843. directory[propertyName] = extraFieldExtendedTimestamp[propertyName] = new Date(time * 1000);
  2844. const rawPropertyName = timeRawProperties[indexProperty];
  2845. extraFieldExtendedTimestamp[rawPropertyName] = time;
  2846. }
  2847. offset += 4;
  2848. });
  2849. }
  2850. async function seekSignature(reader, signature, startOffset, minimumBytes, maximumLength) {
  2851. const signatureArray = new Uint8Array(4);
  2852. const signatureView = getDataView$1(signatureArray);
  2853. setUint32$1(signatureView, 0, signature);
  2854. const maximumBytes = minimumBytes + maximumLength;
  2855. return (await seek(minimumBytes)) || await seek(Math.min(maximumBytes, startOffset));
  2856. async function seek(length) {
  2857. const offset = startOffset - length;
  2858. const bytes = await readUint8Array(reader, offset, length);
  2859. for (let indexByte = bytes.length - minimumBytes; indexByte >= 0; indexByte--) {
  2860. if (bytes[indexByte] == signatureArray[0] && bytes[indexByte + 1] == signatureArray[1] &&
  2861. bytes[indexByte + 2] == signatureArray[2] && bytes[indexByte + 3] == signatureArray[3]) {
  2862. return {
  2863. offset: offset + indexByte,
  2864. buffer: bytes.slice(indexByte, indexByte + minimumBytes).buffer
  2865. };
  2866. }
  2867. }
  2868. }
  2869. }
  2870. function getOptionValue$1(zipReader, options, name) {
  2871. return options[name] === undefined ? zipReader.options[name] : options[name];
  2872. }
  2873. function getDate(timeRaw) {
  2874. const date = (timeRaw & 0xffff0000) >> 16, time = timeRaw & 0x0000ffff;
  2875. try {
  2876. return new Date(1980 + ((date & 0xFE00) >> 9), ((date & 0x01E0) >> 5) - 1, date & 0x001F, (time & 0xF800) >> 11, (time & 0x07E0) >> 5, (time & 0x001F) * 2, 0);
  2877. } catch (_error) {
  2878. // ignored
  2879. }
  2880. }
  2881. function getDateNTFS(timeRaw) {
  2882. return new Date((Number((timeRaw / BigInt(10000)) - BigInt(11644473600000))));
  2883. }
  2884. function getUint8(view, offset) {
  2885. return view.getUint8(offset);
  2886. }
  2887. function getUint16(view, offset) {
  2888. return view.getUint16(offset, true);
  2889. }
  2890. function getUint32(view, offset) {
  2891. return view.getUint32(offset, true);
  2892. }
  2893. function getBigUint64(view, offset) {
  2894. return Number(view.getBigUint64(offset, true));
  2895. }
  2896. function setUint32$1(view, offset, value) {
  2897. view.setUint32(offset, value, true);
  2898. }
  2899. function getDataView$1(array) {
  2900. return new DataView(array.buffer);
  2901. }
  2902. function readUint8Array(reader, offset, size) {
  2903. return reader.readUint8Array(offset, size);
  2904. }
  2905. /*
  2906. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  2907. Redistribution and use in source and binary forms, with or without
  2908. modification, are permitted provided that the following conditions are met:
  2909. 1. Redistributions of source code must retain the above copyright notice,
  2910. this list of conditions and the following disclaimer.
  2911. 2. Redistributions in binary form must reproduce the above copyright
  2912. notice, this list of conditions and the following disclaimer in
  2913. the documentation and/or other materials provided with the distribution.
  2914. 3. The names of the authors may not be used to endorse or promote products
  2915. derived from this software without specific prior written permission.
  2916. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  2917. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  2918. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  2919. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  2920. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  2921. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  2922. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  2923. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  2924. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  2925. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2926. */
  2927. const ERR_DUPLICATED_NAME = "File already exists";
  2928. const ERR_INVALID_COMMENT = "Zip file comment exceeds 64KB";
  2929. const ERR_INVALID_ENTRY_COMMENT = "File entry comment exceeds 64KB";
  2930. const ERR_INVALID_ENTRY_NAME = "File entry name exceeds 64KB";
  2931. const ERR_INVALID_VERSION = "Version exceeds 65535";
  2932. const ERR_INVALID_ENCRYPTION_STRENGTH = "The strength must equal 1, 2, or 3";
  2933. const ERR_INVALID_EXTRAFIELD_TYPE = "Extra field type exceeds 65535";
  2934. const ERR_INVALID_EXTRAFIELD_DATA = "Extra field data exceeds 64KB";
  2935. const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported";
  2936. const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
  2937. const EXTRAFIELD_LENGTH_ZIP64 = 24;
  2938. let workers = 0;
  2939. class ZipWriter {
  2940. constructor(writer, options = {}) {
  2941. Object.assign(this, {
  2942. writer,
  2943. options,
  2944. config: getConfiguration(),
  2945. files: new Map(),
  2946. offset: writer.size,
  2947. pendingCompressedSize: 0,
  2948. pendingEntries: [],
  2949. pendingAddFileCalls: new Set()
  2950. });
  2951. }
  2952. async add(name = "", reader, options = {}) {
  2953. const zipWriter = this;
  2954. if (workers < zipWriter.config.maxWorkers) {
  2955. workers++;
  2956. let promiseAddFile;
  2957. try {
  2958. promiseAddFile = addFile(zipWriter, name, reader, options);
  2959. this.pendingAddFileCalls.add(promiseAddFile);
  2960. return await promiseAddFile;
  2961. } finally {
  2962. this.pendingAddFileCalls.delete(promiseAddFile);
  2963. workers--;
  2964. const pendingEntry = zipWriter.pendingEntries.shift();
  2965. if (pendingEntry) {
  2966. zipWriter.add(pendingEntry.name, pendingEntry.reader, pendingEntry.options)
  2967. .then(pendingEntry.resolve)
  2968. .catch(pendingEntry.reject);
  2969. }
  2970. }
  2971. } else {
  2972. return new Promise((resolve, reject) => zipWriter.pendingEntries.push({ name, reader, options, resolve, reject }));
  2973. }
  2974. }
  2975. async close(comment = new Uint8Array(0), options = {}) {
  2976. while (this.pendingAddFileCalls.size) {
  2977. await Promise.all(Array.from(this.pendingAddFileCalls));
  2978. }
  2979. await closeFile(this, comment, options);
  2980. return this.writer.getData();
  2981. }
  2982. }
  2983. async function addFile(zipWriter, name, reader, options) {
  2984. name = name.trim();
  2985. if (options.directory && (!name.endsWith(DIRECTORY_SIGNATURE))) {
  2986. name += DIRECTORY_SIGNATURE;
  2987. } else {
  2988. options.directory = name.endsWith(DIRECTORY_SIGNATURE);
  2989. }
  2990. if (zipWriter.files.has(name)) {
  2991. throw new Error(ERR_DUPLICATED_NAME);
  2992. }
  2993. const rawFilename = encodeText(name);
  2994. if (rawFilename.length > MAX_16_BITS) {
  2995. throw new Error(ERR_INVALID_ENTRY_NAME);
  2996. }
  2997. const comment = options.comment || "";
  2998. const rawComment = encodeText(comment);
  2999. if (rawComment.length > MAX_16_BITS) {
  3000. throw new Error(ERR_INVALID_ENTRY_COMMENT);
  3001. }
  3002. const version = zipWriter.options.version || options.version || 0;
  3003. if (version > MAX_16_BITS) {
  3004. throw new Error(ERR_INVALID_VERSION);
  3005. }
  3006. const versionMadeBy = zipWriter.options.versionMadeBy || options.versionMadeBy || 20;
  3007. if (versionMadeBy > MAX_16_BITS) {
  3008. throw new Error(ERR_INVALID_VERSION);
  3009. }
  3010. const lastModDate = getOptionValue(zipWriter, options, "lastModDate") || new Date();
  3011. const lastAccessDate = getOptionValue(zipWriter, options, "lastAccessDate");
  3012. const creationDate = getOptionValue(zipWriter, options, "creationDate");
  3013. const password = getOptionValue(zipWriter, options, "password");
  3014. const encryptionStrength = getOptionValue(zipWriter, options, "encryptionStrength") || 3;
  3015. const zipCrypto = getOptionValue(zipWriter, options, "zipCrypto");
  3016. if (password !== undefined && encryptionStrength !== undefined && (encryptionStrength < 1 || encryptionStrength > 3)) {
  3017. throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
  3018. }
  3019. let rawExtraField = new Uint8Array(0);
  3020. const extraField = options.extraField;
  3021. if (extraField) {
  3022. let extraFieldSize = 0;
  3023. let offset = 0;
  3024. extraField.forEach(data => extraFieldSize += 4 + data.length);
  3025. rawExtraField = new Uint8Array(extraFieldSize);
  3026. extraField.forEach((data, type) => {
  3027. if (type > MAX_16_BITS) {
  3028. throw new Error(ERR_INVALID_EXTRAFIELD_TYPE);
  3029. }
  3030. if (data.length > MAX_16_BITS) {
  3031. throw new Error(ERR_INVALID_EXTRAFIELD_DATA);
  3032. }
  3033. arraySet(rawExtraField, new Uint16Array([type]), offset);
  3034. arraySet(rawExtraField, new Uint16Array([data.length]), offset + 2);
  3035. arraySet(rawExtraField, data, offset + 4);
  3036. offset += 4 + data.length;
  3037. });
  3038. }
  3039. let extendedTimestamp = getOptionValue(zipWriter, options, "extendedTimestamp");
  3040. if (extendedTimestamp === undefined) {
  3041. extendedTimestamp = true;
  3042. }
  3043. let maximumCompressedSize = 0;
  3044. let keepOrder = getOptionValue(zipWriter, options, "keepOrder");
  3045. if (keepOrder === undefined) {
  3046. keepOrder = true;
  3047. }
  3048. let uncompressedSize = 0;
  3049. let msDosCompatible = getOptionValue(zipWriter, options, "msDosCompatible");
  3050. if (msDosCompatible === undefined) {
  3051. msDosCompatible = true;
  3052. }
  3053. const internalFileAttribute = getOptionValue(zipWriter, options, "internalFileAttribute") || 0;
  3054. const externalFileAttribute = getOptionValue(zipWriter, options, "externalFileAttribute") || 0;
  3055. if (reader) {
  3056. if (!reader.initialized) {
  3057. await reader.init();
  3058. }
  3059. uncompressedSize = reader.size;
  3060. maximumCompressedSize = getMaximumCompressedSize(uncompressedSize);
  3061. }
  3062. let zip64 = options.zip64 || zipWriter.options.zip64 || false;
  3063. if (zipWriter.offset + zipWriter.pendingCompressedSize >= MAX_32_BITS ||
  3064. uncompressedSize >= MAX_32_BITS ||
  3065. maximumCompressedSize >= MAX_32_BITS) {
  3066. if (options.zip64 === false || zipWriter.options.zip64 === false || !keepOrder) {
  3067. throw new Error(ERR_UNSUPPORTED_FORMAT);
  3068. } else {
  3069. zip64 = true;
  3070. }
  3071. }
  3072. zipWriter.pendingCompressedSize += maximumCompressedSize;
  3073. await Promise.resolve();
  3074. const level = getOptionValue(zipWriter, options, "level");
  3075. const useWebWorkers = getOptionValue(zipWriter, options, "useWebWorkers");
  3076. const bufferedWrite = getOptionValue(zipWriter, options, "bufferedWrite");
  3077. let dataDescriptor = getOptionValue(zipWriter, options, "dataDescriptor");
  3078. let dataDescriptorSignature = getOptionValue(zipWriter, options, "dataDescriptorSignature");
  3079. const signal = getOptionValue(zipWriter, options, "signal");
  3080. if (dataDescriptor === undefined) {
  3081. dataDescriptor = true;
  3082. }
  3083. if (dataDescriptor && dataDescriptorSignature === undefined) {
  3084. dataDescriptorSignature = false;
  3085. }
  3086. const fileEntry = await getFileEntry(zipWriter, name, reader, Object.assign({}, options, {
  3087. rawFilename,
  3088. rawComment,
  3089. version,
  3090. versionMadeBy,
  3091. lastModDate,
  3092. lastAccessDate,
  3093. creationDate,
  3094. rawExtraField,
  3095. zip64,
  3096. password,
  3097. level,
  3098. useWebWorkers,
  3099. encryptionStrength,
  3100. extendedTimestamp,
  3101. zipCrypto,
  3102. bufferedWrite,
  3103. keepOrder,
  3104. dataDescriptor,
  3105. dataDescriptorSignature,
  3106. signal,
  3107. msDosCompatible,
  3108. internalFileAttribute,
  3109. externalFileAttribute
  3110. }));
  3111. if (maximumCompressedSize) {
  3112. zipWriter.pendingCompressedSize -= maximumCompressedSize;
  3113. }
  3114. Object.assign(fileEntry, { name, comment, extraField });
  3115. return new Entry(fileEntry);
  3116. }
  3117. async function getFileEntry(zipWriter, name, reader, options) {
  3118. const files = zipWriter.files;
  3119. const writer = zipWriter.writer;
  3120. const previousFileEntry = Array.from(files.values()).pop();
  3121. let fileEntry = {};
  3122. let bufferedWrite;
  3123. let resolveLockUnbufferedWrite;
  3124. let resolveLockCurrentFileEntry;
  3125. files.set(name, fileEntry);
  3126. try {
  3127. let lockPreviousFileEntry;
  3128. let fileWriter;
  3129. let lockCurrentFileEntry;
  3130. if (options.keepOrder) {
  3131. lockPreviousFileEntry = previousFileEntry && previousFileEntry.lock;
  3132. }
  3133. fileEntry.lock = lockCurrentFileEntry = new Promise(resolve => resolveLockCurrentFileEntry = resolve);
  3134. if (options.bufferedWrite || zipWriter.lockWrite || !options.dataDescriptor) {
  3135. fileWriter = new BlobWriter();
  3136. fileWriter.init();
  3137. bufferedWrite = true;
  3138. } else {
  3139. zipWriter.lockWrite = new Promise(resolve => resolveLockUnbufferedWrite = resolve);
  3140. if (!writer.initialized) {
  3141. await writer.init();
  3142. }
  3143. fileWriter = writer;
  3144. }
  3145. fileEntry = await createFileEntry(reader, fileWriter, zipWriter.config, options);
  3146. fileEntry.lock = lockCurrentFileEntry;
  3147. files.set(name, fileEntry);
  3148. fileEntry.filename = name;
  3149. if (bufferedWrite) {
  3150. let indexWrittenData = 0;
  3151. const blob = fileWriter.getData();
  3152. await Promise.all([zipWriter.lockWrite, lockPreviousFileEntry]);
  3153. let pendingFileEntry;
  3154. do {
  3155. pendingFileEntry = Array.from(files.values()).find(fileEntry => fileEntry.writingBufferedData);
  3156. if (pendingFileEntry) {
  3157. await pendingFileEntry.lock;
  3158. }
  3159. } while (pendingFileEntry && pendingFileEntry.lock);
  3160. fileEntry.writingBufferedData = true;
  3161. if (!options.dataDescriptor) {
  3162. const headerLength = 26;
  3163. const arrayBuffer = await sliceAsArrayBuffer(blob, 0, headerLength);
  3164. const arrayBufferView = new DataView(arrayBuffer);
  3165. if (!fileEntry.encrypted || options.zipCrypto) {
  3166. setUint32(arrayBufferView, 14, fileEntry.signature);
  3167. }
  3168. if (fileEntry.zip64) {
  3169. setUint32(arrayBufferView, 18, MAX_32_BITS);
  3170. setUint32(arrayBufferView, 22, MAX_32_BITS);
  3171. } else {
  3172. setUint32(arrayBufferView, 18, fileEntry.compressedSize);
  3173. setUint32(arrayBufferView, 22, fileEntry.uncompressedSize);
  3174. }
  3175. await writer.writeUint8Array(new Uint8Array(arrayBuffer));
  3176. indexWrittenData = headerLength;
  3177. }
  3178. await writeBlob(writer, blob, indexWrittenData);
  3179. delete fileEntry.writingBufferedData;
  3180. }
  3181. fileEntry.offset = zipWriter.offset;
  3182. if (fileEntry.zip64) {
  3183. const rawExtraFieldZip64View = getDataView(fileEntry.rawExtraFieldZip64);
  3184. setBigUint64(rawExtraFieldZip64View, 20, BigInt(fileEntry.offset));
  3185. } else if (fileEntry.offset >= MAX_32_BITS) {
  3186. throw new Error(ERR_UNSUPPORTED_FORMAT);
  3187. }
  3188. zipWriter.offset += fileEntry.length;
  3189. return fileEntry;
  3190. } catch (error) {
  3191. if ((bufferedWrite && fileEntry.writingBufferedData) || (!bufferedWrite && fileEntry.dataWritten)) {
  3192. error.corruptedEntry = zipWriter.hasCorruptedEntries = true;
  3193. if (fileEntry.uncompressedSize) {
  3194. zipWriter.offset += fileEntry.uncompressedSize;
  3195. }
  3196. }
  3197. files.delete(name);
  3198. throw error;
  3199. } finally {
  3200. resolveLockCurrentFileEntry();
  3201. if (resolveLockUnbufferedWrite) {
  3202. resolveLockUnbufferedWrite();
  3203. }
  3204. }
  3205. }
  3206. async function createFileEntry(reader, writer, config, options) {
  3207. const {
  3208. rawFilename,
  3209. lastAccessDate,
  3210. creationDate,
  3211. password,
  3212. level,
  3213. zip64,
  3214. zipCrypto,
  3215. dataDescriptor,
  3216. dataDescriptorSignature,
  3217. directory,
  3218. version,
  3219. versionMadeBy,
  3220. rawComment,
  3221. rawExtraField,
  3222. useWebWorkers,
  3223. onprogress,
  3224. signal,
  3225. encryptionStrength,
  3226. extendedTimestamp,
  3227. msDosCompatible,
  3228. internalFileAttribute,
  3229. externalFileAttribute
  3230. } = options;
  3231. const encrypted = Boolean(password && password.length);
  3232. const compressed = level !== 0 && !directory;
  3233. let rawExtraFieldAES;
  3234. if (encrypted && !zipCrypto) {
  3235. rawExtraFieldAES = new Uint8Array(EXTRAFIELD_DATA_AES.length + 2);
  3236. const extraFieldAESView = getDataView(rawExtraFieldAES);
  3237. setUint16(extraFieldAESView, 0, EXTRAFIELD_TYPE_AES);
  3238. arraySet(rawExtraFieldAES, EXTRAFIELD_DATA_AES, 2);
  3239. setUint8(extraFieldAESView, 8, encryptionStrength);
  3240. } else {
  3241. rawExtraFieldAES = new Uint8Array(0);
  3242. }
  3243. let rawExtraFieldNTFS;
  3244. let rawExtraFieldExtendedTimestamp;
  3245. if (extendedTimestamp) {
  3246. rawExtraFieldExtendedTimestamp = new Uint8Array(9 + (lastAccessDate ? 4 : 0) + (creationDate ? 4 : 0));
  3247. const extraFieldExtendedTimestampView = getDataView(rawExtraFieldExtendedTimestamp);
  3248. setUint16(extraFieldExtendedTimestampView, 0, EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
  3249. setUint16(extraFieldExtendedTimestampView, 2, rawExtraFieldExtendedTimestamp.length - 4);
  3250. const extraFieldExtendedTimestampFlag = 0x1 + (lastAccessDate ? 0x2 : 0) + (creationDate ? 0x4 : 0);
  3251. setUint8(extraFieldExtendedTimestampView, 4, extraFieldExtendedTimestampFlag);
  3252. setUint32(extraFieldExtendedTimestampView, 5, Math.floor(options.lastModDate.getTime() / 1000));
  3253. if (lastAccessDate) {
  3254. setUint32(extraFieldExtendedTimestampView, 9, Math.floor(lastAccessDate.getTime() / 1000));
  3255. }
  3256. if (creationDate) {
  3257. setUint32(extraFieldExtendedTimestampView, 13, Math.floor(creationDate.getTime() / 1000));
  3258. }
  3259. try {
  3260. rawExtraFieldNTFS = new Uint8Array(36);
  3261. const extraFieldNTFSView = getDataView(rawExtraFieldNTFS);
  3262. const lastModTimeNTFS = getTimeNTFS(options.lastModDate);
  3263. setUint16(extraFieldNTFSView, 0, EXTRAFIELD_TYPE_NTFS);
  3264. setUint16(extraFieldNTFSView, 2, 32);
  3265. setUint16(extraFieldNTFSView, 8, EXTRAFIELD_TYPE_NTFS_TAG1);
  3266. setUint16(extraFieldNTFSView, 10, 24);
  3267. setBigUint64(extraFieldNTFSView, 12, lastModTimeNTFS);
  3268. setBigUint64(extraFieldNTFSView, 20, getTimeNTFS(lastAccessDate) || lastModTimeNTFS);
  3269. setBigUint64(extraFieldNTFSView, 28, getTimeNTFS(creationDate) || lastModTimeNTFS);
  3270. } catch (_error) {
  3271. rawExtraFieldNTFS = new Uint8Array(0);
  3272. }
  3273. } else {
  3274. rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array(0);
  3275. }
  3276. const fileEntry = {
  3277. version: version || VERSION_DEFLATE,
  3278. versionMadeBy,
  3279. zip64,
  3280. directory: Boolean(directory),
  3281. filenameUTF8: true,
  3282. rawFilename,
  3283. commentUTF8: true,
  3284. rawComment,
  3285. rawExtraFieldZip64: zip64 ? new Uint8Array(EXTRAFIELD_LENGTH_ZIP64 + 4) : new Uint8Array(0),
  3286. rawExtraFieldExtendedTimestamp,
  3287. rawExtraFieldNTFS,
  3288. rawExtraFieldAES,
  3289. rawExtraField,
  3290. extendedTimestamp,
  3291. msDosCompatible,
  3292. internalFileAttribute,
  3293. externalFileAttribute
  3294. };
  3295. let uncompressedSize = fileEntry.uncompressedSize = 0;
  3296. let bitFlag = BITFLAG_LANG_ENCODING_FLAG;
  3297. if (dataDescriptor) {
  3298. bitFlag = bitFlag | BITFLAG_DATA_DESCRIPTOR;
  3299. }
  3300. let compressionMethod = COMPRESSION_METHOD_STORE;
  3301. if (compressed) {
  3302. compressionMethod = COMPRESSION_METHOD_DEFLATE;
  3303. }
  3304. if (zip64) {
  3305. fileEntry.version = fileEntry.version > VERSION_ZIP64 ? fileEntry.version : VERSION_ZIP64;
  3306. }
  3307. if (encrypted) {
  3308. bitFlag = bitFlag | BITFLAG_ENCRYPTED;
  3309. if (!zipCrypto) {
  3310. fileEntry.version = fileEntry.version > VERSION_AES ? fileEntry.version : VERSION_AES;
  3311. compressionMethod = COMPRESSION_METHOD_AES;
  3312. if (compressed) {
  3313. fileEntry.rawExtraFieldAES[9] = COMPRESSION_METHOD_DEFLATE;
  3314. }
  3315. }
  3316. }
  3317. fileEntry.compressionMethod = compressionMethod;
  3318. const headerArray = fileEntry.headerArray = new Uint8Array(26);
  3319. const headerView = getDataView(headerArray);
  3320. setUint16(headerView, 0, fileEntry.version);
  3321. setUint16(headerView, 2, bitFlag);
  3322. setUint16(headerView, 4, compressionMethod);
  3323. const dateArray = new Uint32Array(1);
  3324. const dateView = getDataView(dateArray);
  3325. let lastModDate;
  3326. if (options.lastModDate < MIN_DATE) {
  3327. lastModDate = MIN_DATE;
  3328. } else if (options.lastModDate > MAX_DATE) {
  3329. lastModDate = MAX_DATE;
  3330. } else {
  3331. lastModDate = options.lastModDate;
  3332. }
  3333. setUint16(dateView, 0, (((lastModDate.getHours() << 6) | lastModDate.getMinutes()) << 5) | lastModDate.getSeconds() / 2);
  3334. setUint16(dateView, 2, ((((lastModDate.getFullYear() - 1980) << 4) | (lastModDate.getMonth() + 1)) << 5) | lastModDate.getDate());
  3335. const rawLastModDate = dateArray[0];
  3336. setUint32(headerView, 6, rawLastModDate);
  3337. setUint16(headerView, 22, rawFilename.length);
  3338. const extraFieldLength = rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length + fileEntry.rawExtraField.length;
  3339. setUint16(headerView, 24, extraFieldLength);
  3340. const localHeaderArray = new Uint8Array(30 + rawFilename.length + extraFieldLength);
  3341. const localHeaderView = getDataView(localHeaderArray);
  3342. setUint32(localHeaderView, 0, LOCAL_FILE_HEADER_SIGNATURE);
  3343. arraySet(localHeaderArray, headerArray, 4);
  3344. arraySet(localHeaderArray, rawFilename, 30);
  3345. arraySet(localHeaderArray, rawExtraFieldAES, 30 + rawFilename.length);
  3346. arraySet(localHeaderArray, rawExtraFieldExtendedTimestamp, 30 + rawFilename.length + rawExtraFieldAES.length);
  3347. arraySet(localHeaderArray, rawExtraFieldNTFS, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length);
  3348. arraySet(localHeaderArray, fileEntry.rawExtraField, 30 + rawFilename.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length);
  3349. let result;
  3350. let compressedSize = 0;
  3351. if (reader) {
  3352. const codec = await createCodec(config.Deflate, {
  3353. codecType: CODEC_DEFLATE,
  3354. level,
  3355. password,
  3356. encryptionStrength,
  3357. zipCrypto: encrypted && zipCrypto,
  3358. passwordVerification: encrypted && zipCrypto && (rawLastModDate >> 8) & 0xFF,
  3359. signed: true,
  3360. compressed,
  3361. encrypted,
  3362. useWebWorkers
  3363. }, config);
  3364. await writer.writeUint8Array(localHeaderArray);
  3365. fileEntry.dataWritten = true;
  3366. result = await processData(codec, reader, writer, 0, () => reader.size, config, { onprogress, signal });
  3367. uncompressedSize = fileEntry.uncompressedSize = reader.size;
  3368. compressedSize = result.length;
  3369. } else {
  3370. await writer.writeUint8Array(localHeaderArray);
  3371. fileEntry.dataWritten = true;
  3372. }
  3373. let dataDescriptorArray = new Uint8Array(0);
  3374. let dataDescriptorView, dataDescriptorOffset = 0;
  3375. if (dataDescriptor) {
  3376. dataDescriptorArray = new Uint8Array(zip64 ? (dataDescriptorSignature ? 24 : 20) : (dataDescriptorSignature ? 16 : 12));
  3377. dataDescriptorView = getDataView(dataDescriptorArray);
  3378. if (dataDescriptorSignature) {
  3379. dataDescriptorOffset = 4;
  3380. setUint32(dataDescriptorView, 0, DATA_DESCRIPTOR_RECORD_SIGNATURE);
  3381. }
  3382. }
  3383. if (reader) {
  3384. const signature = result.signature;
  3385. if ((!encrypted || zipCrypto) && signature !== undefined) {
  3386. setUint32(headerView, 10, signature);
  3387. fileEntry.signature = signature;
  3388. if (dataDescriptor) {
  3389. setUint32(dataDescriptorView, dataDescriptorOffset, signature);
  3390. }
  3391. }
  3392. if (zip64) {
  3393. const rawExtraFieldZip64View = getDataView(fileEntry.rawExtraFieldZip64);
  3394. setUint16(rawExtraFieldZip64View, 0, EXTRAFIELD_TYPE_ZIP64);
  3395. setUint16(rawExtraFieldZip64View, 2, EXTRAFIELD_LENGTH_ZIP64);
  3396. setUint32(headerView, 14, MAX_32_BITS);
  3397. setBigUint64(rawExtraFieldZip64View, 12, BigInt(compressedSize));
  3398. setUint32(headerView, 18, MAX_32_BITS);
  3399. setBigUint64(rawExtraFieldZip64View, 4, BigInt(uncompressedSize));
  3400. if (dataDescriptor) {
  3401. setBigUint64(dataDescriptorView, dataDescriptorOffset + 4, BigInt(compressedSize));
  3402. setBigUint64(dataDescriptorView, dataDescriptorOffset + 12, BigInt(uncompressedSize));
  3403. }
  3404. } else {
  3405. setUint32(headerView, 14, compressedSize);
  3406. setUint32(headerView, 18, uncompressedSize);
  3407. if (dataDescriptor) {
  3408. setUint32(dataDescriptorView, dataDescriptorOffset + 4, compressedSize);
  3409. setUint32(dataDescriptorView, dataDescriptorOffset + 8, uncompressedSize);
  3410. }
  3411. }
  3412. }
  3413. if (dataDescriptor) {
  3414. await writer.writeUint8Array(dataDescriptorArray);
  3415. }
  3416. const length = localHeaderArray.length + compressedSize + dataDescriptorArray.length;
  3417. Object.assign(fileEntry, { compressedSize, lastModDate, rawLastModDate, creationDate, lastAccessDate, encrypted, length });
  3418. return fileEntry;
  3419. }
  3420. async function closeFile(zipWriter, comment, options) {
  3421. const writer = zipWriter.writer;
  3422. const files = zipWriter.files;
  3423. let offset = 0;
  3424. let directoryDataLength = 0;
  3425. let directoryOffset = zipWriter.offset;
  3426. let filesLength = files.size;
  3427. for (const [, fileEntry] of files) {
  3428. directoryDataLength += 46 +
  3429. fileEntry.rawFilename.length +
  3430. fileEntry.rawComment.length +
  3431. fileEntry.rawExtraFieldZip64.length +
  3432. fileEntry.rawExtraFieldAES.length +
  3433. fileEntry.rawExtraFieldExtendedTimestamp.length +
  3434. fileEntry.rawExtraFieldNTFS.length +
  3435. fileEntry.rawExtraField.length;
  3436. }
  3437. let zip64 = options.zip64 || zipWriter.options.zip64 || false;
  3438. if (directoryOffset >= MAX_32_BITS || directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) {
  3439. if (options.zip64 === false || zipWriter.options.zip64 === false) {
  3440. throw new Error(ERR_UNSUPPORTED_FORMAT);
  3441. } else {
  3442. zip64 = true;
  3443. }
  3444. }
  3445. const directoryArray = new Uint8Array(directoryDataLength + (zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH));
  3446. const directoryView = getDataView(directoryArray);
  3447. if (comment && comment.length) {
  3448. if (comment.length <= MAX_16_BITS) {
  3449. setUint16(directoryView, offset + 20, comment.length);
  3450. } else {
  3451. throw new Error(ERR_INVALID_COMMENT);
  3452. }
  3453. }
  3454. for (const [indexFileEntry, fileEntry] of Array.from(files.values()).entries()) {
  3455. const {
  3456. rawFilename,
  3457. rawExtraFieldZip64,
  3458. rawExtraFieldAES,
  3459. rawExtraField,
  3460. rawComment,
  3461. versionMadeBy,
  3462. headerArray,
  3463. directory,
  3464. zip64,
  3465. msDosCompatible,
  3466. internalFileAttribute,
  3467. externalFileAttribute
  3468. } = fileEntry;
  3469. let rawExtraFieldExtendedTimestamp;
  3470. let rawExtraFieldNTFS;
  3471. if (fileEntry.extendedTimestamp) {
  3472. rawExtraFieldNTFS = fileEntry.rawExtraFieldNTFS;
  3473. rawExtraFieldExtendedTimestamp = new Uint8Array(9);
  3474. const extraFieldExtendedTimestampView = getDataView(rawExtraFieldExtendedTimestamp);
  3475. setUint16(extraFieldExtendedTimestampView, 0, EXTRAFIELD_TYPE_EXTENDED_TIMESTAMP);
  3476. setUint16(extraFieldExtendedTimestampView, 2, rawExtraFieldExtendedTimestamp.length - 4);
  3477. setUint8(extraFieldExtendedTimestampView, 4, 0x1);
  3478. setUint32(extraFieldExtendedTimestampView, 5, Math.floor(fileEntry.lastModDate.getTime() / 1000));
  3479. } else {
  3480. rawExtraFieldNTFS = rawExtraFieldExtendedTimestamp = new Uint8Array(0);
  3481. }
  3482. const extraFieldLength = rawExtraFieldZip64.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length + rawExtraField.length;
  3483. setUint32(directoryView, offset, CENTRAL_FILE_HEADER_SIGNATURE);
  3484. setUint16(directoryView, offset + 4, versionMadeBy);
  3485. arraySet(directoryArray, headerArray, offset + 6);
  3486. setUint16(directoryView, offset + 30, extraFieldLength);
  3487. setUint16(directoryView, offset + 32, rawComment.length);
  3488. setUint32(directoryView, offset + 34, internalFileAttribute);
  3489. if (externalFileAttribute) {
  3490. setUint32(directoryView, offset + 38, externalFileAttribute);
  3491. } else if (directory && msDosCompatible) {
  3492. setUint8(directoryView, offset + 38, FILE_ATTR_MSDOS_DIR_MASK);
  3493. }
  3494. if (zip64) {
  3495. setUint32(directoryView, offset + 42, MAX_32_BITS);
  3496. } else {
  3497. setUint32(directoryView, offset + 42, fileEntry.offset);
  3498. }
  3499. arraySet(directoryArray, rawFilename, offset + 46);
  3500. arraySet(directoryArray, rawExtraFieldZip64, offset + 46 + rawFilename.length);
  3501. arraySet(directoryArray, rawExtraFieldAES, offset + 46 + rawFilename.length + rawExtraFieldZip64.length);
  3502. arraySet(directoryArray, rawExtraFieldExtendedTimestamp, offset + 46 + rawFilename.length + rawExtraFieldZip64.length + rawExtraFieldAES.length);
  3503. arraySet(directoryArray, rawExtraFieldNTFS, offset + 46 + rawFilename.length + rawExtraFieldZip64.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length);
  3504. arraySet(directoryArray, rawExtraField, offset + 46 + rawFilename.length + rawExtraFieldZip64.length + rawExtraFieldAES.length + rawExtraFieldExtendedTimestamp.length + rawExtraFieldNTFS.length);
  3505. arraySet(directoryArray, rawComment, offset + 46 + rawFilename.length + extraFieldLength);
  3506. offset += 46 + rawFilename.length + extraFieldLength + rawComment.length;
  3507. if (options.onprogress) {
  3508. try {
  3509. options.onprogress(indexFileEntry + 1, files.size, new Entry(fileEntry));
  3510. } catch (_error) {
  3511. // ignored
  3512. }
  3513. }
  3514. }
  3515. if (zip64) {
  3516. setUint32(directoryView, offset, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE);
  3517. setBigUint64(directoryView, offset + 4, BigInt(44));
  3518. setUint16(directoryView, offset + 12, 45);
  3519. setUint16(directoryView, offset + 14, 45);
  3520. setBigUint64(directoryView, offset + 24, BigInt(filesLength));
  3521. setBigUint64(directoryView, offset + 32, BigInt(filesLength));
  3522. setBigUint64(directoryView, offset + 40, BigInt(directoryDataLength));
  3523. setBigUint64(directoryView, offset + 48, BigInt(directoryOffset));
  3524. setUint32(directoryView, offset + 56, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE);
  3525. setBigUint64(directoryView, offset + 64, BigInt(directoryOffset) + BigInt(directoryDataLength));
  3526. setUint32(directoryView, offset + 72, ZIP64_TOTAL_NUMBER_OF_DISKS);
  3527. filesLength = MAX_16_BITS;
  3528. directoryOffset = MAX_32_BITS;
  3529. directoryDataLength = MAX_32_BITS;
  3530. offset += 76;
  3531. }
  3532. setUint32(directoryView, offset, END_OF_CENTRAL_DIR_SIGNATURE);
  3533. setUint16(directoryView, offset + 8, filesLength);
  3534. setUint16(directoryView, offset + 10, filesLength);
  3535. setUint32(directoryView, offset + 12, directoryDataLength);
  3536. setUint32(directoryView, offset + 16, directoryOffset);
  3537. await writer.writeUint8Array(directoryArray);
  3538. if (comment && comment.length) {
  3539. await writer.writeUint8Array(comment);
  3540. }
  3541. }
  3542. function sliceAsArrayBuffer(blob, start, end) {
  3543. if (blob.arrayBuffer) {
  3544. if (start || end) {
  3545. return blob.slice(start, end).arrayBuffer();
  3546. } else {
  3547. return blob.arrayBuffer();
  3548. }
  3549. } else {
  3550. const fileReader = new FileReader();
  3551. return new Promise((resolve, reject) => {
  3552. fileReader.onload = event => resolve(event.target.result);
  3553. fileReader.onerror = () => reject(fileReader.error);
  3554. fileReader.readAsArrayBuffer(start || end ? blob.slice(start, end) : blob);
  3555. });
  3556. }
  3557. }
  3558. async function writeBlob(writer, blob, start = 0) {
  3559. const blockSize = 512 * 1024 * 1024;
  3560. await writeSlice();
  3561. async function writeSlice() {
  3562. if (start < blob.size) {
  3563. const arrayBuffer = await sliceAsArrayBuffer(blob, start, start + blockSize);
  3564. await writer.writeUint8Array(new Uint8Array(arrayBuffer));
  3565. start += blockSize;
  3566. await writeSlice();
  3567. }
  3568. }
  3569. }
  3570. function getTimeNTFS(date) {
  3571. if (date) {
  3572. return ((BigInt(date.getTime()) + BigInt(11644473600000)) * BigInt(10000));
  3573. }
  3574. }
  3575. function getOptionValue(zipWriter, options, name) {
  3576. return options[name] === undefined ? zipWriter.options[name] : options[name];
  3577. }
  3578. function getMaximumCompressedSize(uncompressedSize) {
  3579. return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
  3580. }
  3581. function setUint8(view, offset, value) {
  3582. view.setUint8(offset, value);
  3583. }
  3584. function setUint16(view, offset, value) {
  3585. view.setUint16(offset, value, true);
  3586. }
  3587. function setUint32(view, offset, value) {
  3588. view.setUint32(offset, value, true);
  3589. }
  3590. function setBigUint64(view, offset, value) {
  3591. view.setBigUint64(offset, value, true);
  3592. }
  3593. function arraySet(array, typedArray, offset) {
  3594. array.set(typedArray, offset);
  3595. }
  3596. function getDataView(array) {
  3597. return new DataView(array.buffer);
  3598. }
  3599. /*
  3600. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  3601. Redistribution and use in source and binary forms, with or without
  3602. modification, are permitted provided that the following conditions are met:
  3603. 1. Redistributions of source code must retain the above copyright notice,
  3604. this list of conditions and the following disclaimer.
  3605. 2. Redistributions in binary form must reproduce the above copyright
  3606. notice, this list of conditions and the following disclaimer in
  3607. the documentation and/or other materials provided with the distribution.
  3608. 3. The names of the authors may not be used to endorse or promote products
  3609. derived from this software without specific prior written permission.
  3610. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  3611. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  3612. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  3613. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  3614. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  3615. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  3616. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  3617. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  3618. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  3619. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3620. */
  3621. const CHUNK_SIZE = 512 * 1024;
  3622. class ZipEntry {
  3623. constructor(fs, name, params, parent) {
  3624. const zipEntry = this;
  3625. if (fs.root && parent && parent.getChildByName(name)) {
  3626. throw new Error("Entry filename already exists");
  3627. }
  3628. if (!params) {
  3629. params = {};
  3630. }
  3631. Object.assign(zipEntry, {
  3632. fs,
  3633. name,
  3634. data: params.data,
  3635. id: fs.entries.length,
  3636. parent,
  3637. children: [],
  3638. uncompressedSize: 0
  3639. });
  3640. fs.entries.push(zipEntry);
  3641. if (parent) {
  3642. zipEntry.parent.children.push(zipEntry);
  3643. }
  3644. }
  3645. moveTo(target) {
  3646. // deprecated
  3647. const zipEntry = this;
  3648. zipEntry.fs.move(zipEntry, target);
  3649. }
  3650. getFullname() {
  3651. return this.getRelativeName();
  3652. }
  3653. getRelativeName(ancestor = this.fs.root) {
  3654. const zipEntry = this;
  3655. let relativeName = zipEntry.name;
  3656. let entry = zipEntry.parent;
  3657. while (entry && entry != ancestor) {
  3658. relativeName = (entry.name ? entry.name + "/" : "") + relativeName;
  3659. entry = entry.parent;
  3660. }
  3661. return relativeName;
  3662. }
  3663. isDescendantOf(ancestor) {
  3664. let entry = this.parent;
  3665. while (entry && entry.id != ancestor.id) {
  3666. entry = entry.parent;
  3667. }
  3668. return Boolean(entry);
  3669. }
  3670. }
  3671. class ZipFileEntry extends ZipEntry {
  3672. constructor(fs, name, params, parent) {
  3673. super(fs, name, params, parent);
  3674. const zipEntry = this;
  3675. zipEntry.Reader = params.Reader;
  3676. zipEntry.Writer = params.Writer;
  3677. if (params.getData) {
  3678. zipEntry.getData = params.getData;
  3679. }
  3680. }
  3681. async getData(writer, options = {}) {
  3682. const zipEntry = this;
  3683. if (!writer || (writer.constructor == zipEntry.Writer && zipEntry.data)) {
  3684. return zipEntry.data;
  3685. } else {
  3686. zipEntry.reader = new zipEntry.Reader(zipEntry.data, options);
  3687. await zipEntry.reader.init();
  3688. if (!writer.initialized) {
  3689. await writer.init();
  3690. }
  3691. zipEntry.uncompressedSize = zipEntry.reader.size;
  3692. return pipe(zipEntry.reader, writer);
  3693. }
  3694. }
  3695. getText(encoding, options) {
  3696. return this.getData(new TextWriter(encoding), options);
  3697. }
  3698. getBlob(mimeType, options) {
  3699. return this.getData(new BlobWriter(mimeType), options);
  3700. }
  3701. getData64URI(mimeType, options) {
  3702. return this.getData(new Data64URIWriter(mimeType), options);
  3703. }
  3704. getUint8Array(options) {
  3705. return this.getData(new Uint8ArrayWriter(), options);
  3706. }
  3707. replaceBlob(blob) {
  3708. Object.assign(this, {
  3709. data: blob,
  3710. Reader: BlobReader,
  3711. Writer: BlobWriter,
  3712. reader: null
  3713. });
  3714. }
  3715. replaceText(text) {
  3716. Object.assign(this, {
  3717. data: text,
  3718. Reader: TextReader,
  3719. Writer: TextWriter,
  3720. reader: null
  3721. });
  3722. }
  3723. replaceData64URI(dataURI) {
  3724. Object.assign(this, {
  3725. data: dataURI,
  3726. Reader: Data64URIReader,
  3727. Writer: Data64URIWriter,
  3728. reader: null
  3729. });
  3730. }
  3731. replaceUint8Array(array) {
  3732. Object.assign(this, {
  3733. data: array,
  3734. Reader: Uint8ArrayReader,
  3735. Writer: Uint8ArrayWriter,
  3736. reader: null
  3737. });
  3738. }
  3739. }
  3740. class ZipDirectoryEntry extends ZipEntry {
  3741. constructor(fs, name, params, parent) {
  3742. super(fs, name, params, parent);
  3743. this.directory = true;
  3744. }
  3745. addDirectory(name) {
  3746. return addChild(this, name, null, true);
  3747. }
  3748. addText(name, text) {
  3749. return addChild(this, name, {
  3750. data: text,
  3751. Reader: TextReader,
  3752. Writer: TextWriter
  3753. });
  3754. }
  3755. addBlob(name, blob) {
  3756. return addChild(this, name, {
  3757. data: blob,
  3758. Reader: BlobReader,
  3759. Writer: BlobWriter
  3760. });
  3761. }
  3762. addData64URI(name, dataURI) {
  3763. return addChild(this, name, {
  3764. data: dataURI,
  3765. Reader: Data64URIReader,
  3766. Writer: Data64URIWriter
  3767. });
  3768. }
  3769. addUint8Array(name, array) {
  3770. return addChild(this, name, {
  3771. data: array,
  3772. Reader: Uint8ArrayReader,
  3773. Writer: Uint8ArrayWriter
  3774. });
  3775. }
  3776. addHttpContent(name, url, options = {}) {
  3777. return addChild(this, name, {
  3778. data: url,
  3779. Reader: class extends HttpReader {
  3780. constructor(url) {
  3781. super(url, options);
  3782. }
  3783. }
  3784. });
  3785. }
  3786. addFileSystemEntry(fileSystemEntry) {
  3787. return addFileSystemEntry(this, fileSystemEntry);
  3788. }
  3789. addData(name, params) {
  3790. return addChild(this, name, params);
  3791. }
  3792. async importBlob(blob, options = {}) {
  3793. await this.importZip(new BlobReader(blob), options);
  3794. }
  3795. async importData64URI(dataURI, options = {}) {
  3796. await this.importZip(new Data64URIReader(dataURI), options);
  3797. }
  3798. async importUint8Array(array, options = {}) {
  3799. await this.importZip(new Uint8ArrayReader(array), options);
  3800. }
  3801. async importHttpContent(url, options = {}) {
  3802. await this.importZip(new HttpReader(url, options), options);
  3803. }
  3804. exportBlob(options = {}) {
  3805. return this.exportZip(new BlobWriter("application/zip"), options);
  3806. }
  3807. exportData64URI(options = {}) {
  3808. return this.exportZip(new Data64URIWriter("application/zip"), options);
  3809. }
  3810. exportUint8Array(options = {}) {
  3811. return this.exportZip(new Uint8ArrayWriter(), options);
  3812. }
  3813. async importZip(reader, options) {
  3814. if (!reader.initialized) {
  3815. await reader.init();
  3816. }
  3817. const zipReader = new ZipReader(reader, options);
  3818. const entries = await zipReader.getEntries();
  3819. entries.forEach((entry) => {
  3820. let parent = this;
  3821. const path = entry.filename.split("/");
  3822. const name = path.pop();
  3823. path.forEach(pathPart => parent = parent.getChildByName(pathPart) || new ZipDirectoryEntry(this.fs, pathPart, null, parent));
  3824. if (!entry.directory) {
  3825. addChild(parent, name, {
  3826. data: entry,
  3827. Reader: getZipBlobReader(Object.assign({}, options))
  3828. });
  3829. }
  3830. });
  3831. }
  3832. async exportZip(writer, options) {
  3833. const zipEntry = this;
  3834. await initReaders(zipEntry);
  3835. await writer.init();
  3836. const zipWriter = new ZipWriter(writer, options);
  3837. await exportZip(zipWriter, zipEntry, getTotalSize([zipEntry], "uncompressedSize"), options);
  3838. await zipWriter.close();
  3839. return writer.getData();
  3840. }
  3841. getChildByName(name) {
  3842. const children = this.children;
  3843. for (let childIndex = 0; childIndex < children.length; childIndex++) {
  3844. const child = children[childIndex];
  3845. if (child.name == name) {
  3846. return child;
  3847. }
  3848. }
  3849. }
  3850. }
  3851. class FS {
  3852. constructor() {
  3853. resetFS(this);
  3854. }
  3855. get children() {
  3856. return this.root.children;
  3857. }
  3858. remove(entry) {
  3859. detach(entry);
  3860. this.entries[entry.id] = null;
  3861. }
  3862. move(entry, destination) {
  3863. if (entry == this.root) {
  3864. throw new Error("Root directory cannot be moved");
  3865. } else {
  3866. if (destination.directory) {
  3867. if (!destination.isDescendantOf(entry)) {
  3868. if (entry != destination) {
  3869. if (destination.getChildByName(entry.name)) {
  3870. throw new Error("Entry filename already exists");
  3871. }
  3872. detach(entry);
  3873. entry.parent = destination;
  3874. destination.children.push(entry);
  3875. }
  3876. } else {
  3877. throw new Error("Entry is a ancestor of target entry");
  3878. }
  3879. } else {
  3880. throw new Error("Target entry is not a directory");
  3881. }
  3882. }
  3883. }
  3884. find(fullname) {
  3885. const path = fullname.split("/");
  3886. let node = this.root;
  3887. for (let index = 0; node && index < path.length; index++) {
  3888. node = node.getChildByName(path[index]);
  3889. }
  3890. return node;
  3891. }
  3892. getById(id) {
  3893. return this.entries[id];
  3894. }
  3895. getChildByName(name) {
  3896. return this.root.getChildByName(name);
  3897. }
  3898. addDirectory(name) {
  3899. return this.root.addDirectory(name);
  3900. }
  3901. addText(name, text) {
  3902. return this.root.addText(name, text);
  3903. }
  3904. addBlob(name, blob) {
  3905. return this.root.addBlob(name, blob);
  3906. }
  3907. addData64URI(name, dataURI) {
  3908. return this.root.addData64URI(name, dataURI);
  3909. }
  3910. addHttpContent(name, url, options) {
  3911. return this.root.addHttpContent(name, url, options);
  3912. }
  3913. addFileSystemEntry(fileSystemEntry) {
  3914. return this.root.addFileSystemEntry(fileSystemEntry);
  3915. }
  3916. addData(name, params) {
  3917. return this.root.addData(name, params);
  3918. }
  3919. async importBlob(blob, options) {
  3920. resetFS(this);
  3921. await this.root.importBlob(blob, options);
  3922. }
  3923. async importData64URI(dataURI, options) {
  3924. resetFS(this);
  3925. await this.root.importData64URI(dataURI, options);
  3926. }
  3927. async importHttpContent(url, options) {
  3928. resetFS(this);
  3929. await this.root.importHttpContent(url, options);
  3930. }
  3931. exportBlob(options) {
  3932. return this.root.exportBlob(options);
  3933. }
  3934. exportData64URI(options) {
  3935. return this.root.exportData64URI(options);
  3936. }
  3937. }
  3938. const fs = { FS, ZipDirectoryEntry, ZipFileEntry };
  3939. function getTotalSize(entries, propertyName) {
  3940. let size = 0;
  3941. entries.forEach(process);
  3942. return size;
  3943. function process(entry) {
  3944. size += entry[propertyName];
  3945. if (entry.children) {
  3946. entry.children.forEach(process);
  3947. }
  3948. }
  3949. }
  3950. function getZipBlobReader(options) {
  3951. return class extends Reader {
  3952. constructor(entry, options = {}) {
  3953. super();
  3954. this.entry = entry;
  3955. this.options = options;
  3956. }
  3957. async init() {
  3958. const zipBlobReader = this;
  3959. zipBlobReader.size = zipBlobReader.entry.uncompressedSize;
  3960. const data = await zipBlobReader.entry.getData(new BlobWriter(), Object.assign({}, zipBlobReader.options, options));
  3961. zipBlobReader.data = data;
  3962. zipBlobReader.blobReader = new BlobReader(data);
  3963. }
  3964. readUint8Array(index, length) {
  3965. return this.blobReader.readUint8Array(index, length);
  3966. }
  3967. };
  3968. }
  3969. async function initReaders(entry) {
  3970. if (entry.children.length) {
  3971. for (const child of entry.children) {
  3972. if (child.directory) {
  3973. await initReaders(child);
  3974. } else {
  3975. child.reader = new child.Reader(child.data);
  3976. await child.reader.init();
  3977. child.uncompressedSize = child.reader.size;
  3978. }
  3979. }
  3980. }
  3981. }
  3982. function detach(entry) {
  3983. const children = entry.parent.children;
  3984. children.forEach((child, index) => {
  3985. if (child.id == entry.id) {
  3986. children.splice(index, 1);
  3987. }
  3988. });
  3989. }
  3990. async function exportZip(zipWriter, entry, totalSize, options) {
  3991. const selectedEntry = entry;
  3992. const entryOffsets = new Map();
  3993. await process(zipWriter, entry);
  3994. async function process(zipWriter, entry) {
  3995. await exportChild();
  3996. async function exportChild() {
  3997. if (options.bufferedWrite) {
  3998. await Promise.all(entry.children.map(processChild));
  3999. } else {
  4000. for (const child of entry.children) {
  4001. await processChild(child);
  4002. }
  4003. }
  4004. }
  4005. async function processChild(child) {
  4006. const name = options.relativePath ? child.getRelativeName(selectedEntry) : child.getFullname();
  4007. await zipWriter.add(name, child.reader, Object.assign({
  4008. directory: child.directory
  4009. }, Object.assign({}, options, {
  4010. onprogress: indexProgress => {
  4011. if (options.onprogress) {
  4012. entryOffsets.set(name, indexProgress);
  4013. try {
  4014. options.onprogress(Array.from(entryOffsets.values()).reduce((previousValue, currentValue) => previousValue + currentValue), totalSize);
  4015. } catch (_error) {
  4016. // ignored
  4017. }
  4018. }
  4019. }
  4020. })));
  4021. await process(zipWriter, child);
  4022. }
  4023. }
  4024. }
  4025. async function addFileSystemEntry(zipEntry, fileSystemEntry) {
  4026. if (fileSystemEntry.isDirectory) {
  4027. const entry = zipEntry.addDirectory(fileSystemEntry.name);
  4028. await addDirectory(entry, fileSystemEntry);
  4029. return entry;
  4030. } else {
  4031. return new Promise((resolve, reject) => fileSystemEntry.file(file => resolve(zipEntry.addBlob(fileSystemEntry.name, file)), reject));
  4032. }
  4033. async function addDirectory(zipEntry, fileEntry) {
  4034. const children = await getChildren(fileEntry);
  4035. for (const child of children) {
  4036. if (child.isDirectory) {
  4037. await addDirectory(zipEntry.addDirectory(child.name), child);
  4038. } else {
  4039. await new Promise((resolve, reject) => {
  4040. child.file(file => {
  4041. const childZipEntry = zipEntry.addBlob(child.name, file);
  4042. childZipEntry.uncompressedSize = file.size;
  4043. resolve(childZipEntry);
  4044. }, reject);
  4045. });
  4046. }
  4047. }
  4048. }
  4049. function getChildren(fileEntry) {
  4050. return new Promise((resolve, reject) => {
  4051. let entries = [];
  4052. if (fileEntry.isDirectory) {
  4053. readEntries(fileEntry.createReader());
  4054. }
  4055. if (fileEntry.isFile) {
  4056. resolve(entries);
  4057. }
  4058. function readEntries(directoryReader) {
  4059. directoryReader.readEntries(temporaryEntries => {
  4060. if (!temporaryEntries.length) {
  4061. resolve(entries);
  4062. } else {
  4063. entries = entries.concat(temporaryEntries);
  4064. readEntries(directoryReader);
  4065. }
  4066. }, reject);
  4067. }
  4068. });
  4069. }
  4070. }
  4071. function resetFS(fs) {
  4072. fs.entries = [];
  4073. fs.root = new ZipDirectoryEntry(fs);
  4074. }
  4075. function pipe(reader, writer) {
  4076. return copyChunk();
  4077. async function copyChunk(chunkIndex = 0) {
  4078. const index = chunkIndex * CHUNK_SIZE;
  4079. if (index < reader.size) {
  4080. const array = await reader.readUint8Array(index, Math.min(CHUNK_SIZE, reader.size - index));
  4081. await writer.writeUint8Array(array);
  4082. return copyChunk(chunkIndex + 1);
  4083. } else {
  4084. return writer.getData();
  4085. }
  4086. }
  4087. }
  4088. function addChild(parent, name, params, directory) {
  4089. if (parent.directory) {
  4090. return directory ? new ZipDirectoryEntry(parent.fs, name, params, parent) : new ZipFileEntry(parent.fs, name, params, parent);
  4091. } else {
  4092. throw new Error("Parent entry is not a directory");
  4093. }
  4094. }
  4095. /*
  4096. Copyright (c) 2022 Gildas Lormeau. All rights reserved.
  4097. Redistribution and use in source and binary forms, with or without
  4098. modification, are permitted provided that the following conditions are met:
  4099. 1. Redistributions of source code must retain the above copyright notice,
  4100. this list of conditions and the following disclaimer.
  4101. 2. Redistributions in binary form must reproduce the above copyright
  4102. notice, this list of conditions and the following disclaimer in
  4103. the documentation and/or other materials provided with the distribution.
  4104. 3. The names of the authors may not be used to endorse or promote products
  4105. derived from this software without specific prior written permission.
  4106. THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  4107. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  4108. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
  4109. INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
  4110. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  4111. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  4112. OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  4113. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  4114. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  4115. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4116. */
  4117. let baseURL;
  4118. try {
  4119. 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.js', document.baseURI).href));
  4120. } catch (_error) {
  4121. // ignored
  4122. }
  4123. configure({ baseURL });
  4124. t(configure);
  4125. exports.BlobReader = BlobReader;
  4126. exports.BlobWriter = BlobWriter;
  4127. exports.Data64URIReader = Data64URIReader;
  4128. exports.Data64URIWriter = Data64URIWriter;
  4129. exports.ERR_ABORT = ERR_ABORT;
  4130. exports.ERR_BAD_FORMAT = ERR_BAD_FORMAT;
  4131. exports.ERR_CENTRAL_DIRECTORY_NOT_FOUND = ERR_CENTRAL_DIRECTORY_NOT_FOUND;
  4132. exports.ERR_DUPLICATED_NAME = ERR_DUPLICATED_NAME;
  4133. exports.ERR_ENCRYPTED = ERR_ENCRYPTED;
  4134. exports.ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND = ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND;
  4135. exports.ERR_EOCDR_NOT_FOUND = ERR_EOCDR_NOT_FOUND;
  4136. exports.ERR_EOCDR_ZIP64_NOT_FOUND = ERR_EOCDR_ZIP64_NOT_FOUND;
  4137. exports.ERR_EXTRAFIELD_ZIP64_NOT_FOUND = ERR_EXTRAFIELD_ZIP64_NOT_FOUND;
  4138. exports.ERR_HTTP_RANGE = ERR_HTTP_RANGE;
  4139. exports.ERR_INVALID_COMMENT = ERR_INVALID_COMMENT;
  4140. exports.ERR_INVALID_ENCRYPTION_STRENGTH = ERR_INVALID_ENCRYPTION_STRENGTH;
  4141. exports.ERR_INVALID_ENTRY_COMMENT = ERR_INVALID_ENTRY_COMMENT;
  4142. exports.ERR_INVALID_ENTRY_NAME = ERR_INVALID_ENTRY_NAME;
  4143. exports.ERR_INVALID_EXTRAFIELD_DATA = ERR_INVALID_EXTRAFIELD_DATA;
  4144. exports.ERR_INVALID_EXTRAFIELD_TYPE = ERR_INVALID_EXTRAFIELD_TYPE;
  4145. exports.ERR_INVALID_PASSWORD = ERR_INVALID_PASSWORD;
  4146. exports.ERR_INVALID_SIGNATURE = ERR_INVALID_SIGNATURE;
  4147. exports.ERR_INVALID_VERSION = ERR_INVALID_VERSION;
  4148. exports.ERR_LOCAL_FILE_HEADER_NOT_FOUND = ERR_LOCAL_FILE_HEADER_NOT_FOUND;
  4149. exports.ERR_NOT_SEEKABLE_READER = ERR_NOT_SEEKABLE_READER;
  4150. exports.ERR_UNSUPPORTED_COMPRESSION = ERR_UNSUPPORTED_COMPRESSION;
  4151. exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
  4152. exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
  4153. exports.HttpRangeReader = HttpRangeReader;
  4154. exports.HttpReader = HttpReader;
  4155. exports.ReadableStreamReader = ReadableStreamReader;
  4156. exports.Reader = Reader;
  4157. exports.TextReader = TextReader;
  4158. exports.TextWriter = TextWriter;
  4159. exports.Uint8ArrayReader = Uint8ArrayReader;
  4160. exports.Uint8ArrayWriter = Uint8ArrayWriter;
  4161. exports.WritableStreamWriter = WritableStreamWriter;
  4162. exports.Writer = Writer;
  4163. exports.ZipReader = ZipReader;
  4164. exports.ZipWriter = ZipWriter;
  4165. exports.configure = configure;
  4166. exports.fs = fs;
  4167. exports.getMimeType = getMimeType;
  4168. exports.initShimAsyncCodec = streamCodecShim;
  4169. exports.terminateWorkers = terminateWorkers;
  4170. Object.defineProperty(exports, '__esModule', { value: true });
  4171. }));