Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

zipbase64_1.0.0.html 313KB

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