html-docx.js 406 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216
  1. !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.htmlDocx=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
  2. /*!
  3. * The buffer module from node.js, for the browser.
  4. *
  5. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  6. * @license MIT
  7. */
  8. var base64 = _dereq_('base64-js')
  9. var ieee754 = _dereq_('ieee754')
  10. var isArray = _dereq_('is-array')
  11. exports.Buffer = Buffer
  12. exports.SlowBuffer = Buffer
  13. exports.INSPECT_MAX_BYTES = 50
  14. Buffer.poolSize = 8192 // not used by this implementation
  15. var kMaxLength = 0x3fffffff
  16. /**
  17. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  18. * === true Use Uint8Array implementation (fastest)
  19. * === false Use Object implementation (most compatible, even IE6)
  20. *
  21. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  22. * Opera 11.6+, iOS 4.2+.
  23. *
  24. * Note:
  25. *
  26. * - Implementation must support adding new properties to `Uint8Array` instances.
  27. * Firefox 4-29 lacked support, fixed in Firefox 30+.
  28. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  29. *
  30. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  31. *
  32. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  33. * incorrect length in some situations.
  34. *
  35. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they will
  36. * get the Object implementation, which is slower but will work correctly.
  37. */
  38. Buffer.TYPED_ARRAY_SUPPORT = (function () {
  39. try {
  40. var buf = new ArrayBuffer(0)
  41. var arr = new Uint8Array(buf)
  42. arr.foo = function () { return 42 }
  43. return 42 === arr.foo() && // typed array instances can be augmented
  44. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  45. new Uint8Array(1).subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  46. } catch (e) {
  47. return false
  48. }
  49. })()
  50. /**
  51. * Class: Buffer
  52. * =============
  53. *
  54. * The Buffer constructor returns instances of `Uint8Array` that are augmented
  55. * with function properties for all the node `Buffer` API functions. We use
  56. * `Uint8Array` so that square bracket notation works as expected -- it returns
  57. * a single octet.
  58. *
  59. * By augmenting the instances, we can avoid modifying the `Uint8Array`
  60. * prototype.
  61. */
  62. function Buffer (subject, encoding, noZero) {
  63. if (!(this instanceof Buffer))
  64. return new Buffer(subject, encoding, noZero)
  65. var type = typeof subject
  66. // Find the length
  67. var length
  68. if (type === 'number')
  69. length = subject > 0 ? subject >>> 0 : 0
  70. else if (type === 'string') {
  71. if (encoding === 'base64')
  72. subject = base64clean(subject)
  73. length = Buffer.byteLength(subject, encoding)
  74. } else if (type === 'object' && subject !== null) { // assume object is array-like
  75. if (subject.type === 'Buffer' && isArray(subject.data))
  76. subject = subject.data
  77. length = +subject.length > 0 ? Math.floor(+subject.length) : 0
  78. } else
  79. throw new TypeError('must start with number, buffer, array or string')
  80. if (this.length > kMaxLength)
  81. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  82. 'size: 0x' + kMaxLength.toString(16) + ' bytes')
  83. var buf
  84. if (Buffer.TYPED_ARRAY_SUPPORT) {
  85. // Preferred: Return an augmented `Uint8Array` instance for best performance
  86. buf = Buffer._augment(new Uint8Array(length))
  87. } else {
  88. // Fallback: Return THIS instance of Buffer (created by `new`)
  89. buf = this
  90. buf.length = length
  91. buf._isBuffer = true
  92. }
  93. var i
  94. if (Buffer.TYPED_ARRAY_SUPPORT && typeof subject.byteLength === 'number') {
  95. // Speed optimization -- use set if we're copying from a typed array
  96. buf._set(subject)
  97. } else if (isArrayish(subject)) {
  98. // Treat array-ish objects as a byte array
  99. if (Buffer.isBuffer(subject)) {
  100. for (i = 0; i < length; i++)
  101. buf[i] = subject.readUInt8(i)
  102. } else {
  103. for (i = 0; i < length; i++)
  104. buf[i] = ((subject[i] % 256) + 256) % 256
  105. }
  106. } else if (type === 'string') {
  107. buf.write(subject, 0, encoding)
  108. } else if (type === 'number' && !Buffer.TYPED_ARRAY_SUPPORT && !noZero) {
  109. for (i = 0; i < length; i++) {
  110. buf[i] = 0
  111. }
  112. }
  113. return buf
  114. }
  115. Buffer.isBuffer = function (b) {
  116. return !!(b != null && b._isBuffer)
  117. }
  118. Buffer.compare = function (a, b) {
  119. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b))
  120. throw new TypeError('Arguments must be Buffers')
  121. var x = a.length
  122. var y = b.length
  123. for (var i = 0, len = Math.min(x, y); i < len && a[i] === b[i]; i++) {}
  124. if (i !== len) {
  125. x = a[i]
  126. y = b[i]
  127. }
  128. if (x < y) return -1
  129. if (y < x) return 1
  130. return 0
  131. }
  132. Buffer.isEncoding = function (encoding) {
  133. switch (String(encoding).toLowerCase()) {
  134. case 'hex':
  135. case 'utf8':
  136. case 'utf-8':
  137. case 'ascii':
  138. case 'binary':
  139. case 'base64':
  140. case 'raw':
  141. case 'ucs2':
  142. case 'ucs-2':
  143. case 'utf16le':
  144. case 'utf-16le':
  145. return true
  146. default:
  147. return false
  148. }
  149. }
  150. Buffer.concat = function (list, totalLength) {
  151. if (!isArray(list)) throw new TypeError('Usage: Buffer.concat(list[, length])')
  152. if (list.length === 0) {
  153. return new Buffer(0)
  154. } else if (list.length === 1) {
  155. return list[0]
  156. }
  157. var i
  158. if (totalLength === undefined) {
  159. totalLength = 0
  160. for (i = 0; i < list.length; i++) {
  161. totalLength += list[i].length
  162. }
  163. }
  164. var buf = new Buffer(totalLength)
  165. var pos = 0
  166. for (i = 0; i < list.length; i++) {
  167. var item = list[i]
  168. item.copy(buf, pos)
  169. pos += item.length
  170. }
  171. return buf
  172. }
  173. Buffer.byteLength = function (str, encoding) {
  174. var ret
  175. str = str + ''
  176. switch (encoding || 'utf8') {
  177. case 'ascii':
  178. case 'binary':
  179. case 'raw':
  180. ret = str.length
  181. break
  182. case 'ucs2':
  183. case 'ucs-2':
  184. case 'utf16le':
  185. case 'utf-16le':
  186. ret = str.length * 2
  187. break
  188. case 'hex':
  189. ret = str.length >>> 1
  190. break
  191. case 'utf8':
  192. case 'utf-8':
  193. ret = utf8ToBytes(str).length
  194. break
  195. case 'base64':
  196. ret = base64ToBytes(str).length
  197. break
  198. default:
  199. ret = str.length
  200. }
  201. return ret
  202. }
  203. // pre-set for values that may exist in the future
  204. Buffer.prototype.length = undefined
  205. Buffer.prototype.parent = undefined
  206. // toString(encoding, start=0, end=buffer.length)
  207. Buffer.prototype.toString = function (encoding, start, end) {
  208. var loweredCase = false
  209. start = start >>> 0
  210. end = end === undefined || end === Infinity ? this.length : end >>> 0
  211. if (!encoding) encoding = 'utf8'
  212. if (start < 0) start = 0
  213. if (end > this.length) end = this.length
  214. if (end <= start) return ''
  215. while (true) {
  216. switch (encoding) {
  217. case 'hex':
  218. return hexSlice(this, start, end)
  219. case 'utf8':
  220. case 'utf-8':
  221. return utf8Slice(this, start, end)
  222. case 'ascii':
  223. return asciiSlice(this, start, end)
  224. case 'binary':
  225. return binarySlice(this, start, end)
  226. case 'base64':
  227. return base64Slice(this, start, end)
  228. case 'ucs2':
  229. case 'ucs-2':
  230. case 'utf16le':
  231. case 'utf-16le':
  232. return utf16leSlice(this, start, end)
  233. default:
  234. if (loweredCase)
  235. throw new TypeError('Unknown encoding: ' + encoding)
  236. encoding = (encoding + '').toLowerCase()
  237. loweredCase = true
  238. }
  239. }
  240. }
  241. Buffer.prototype.equals = function (b) {
  242. if(!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  243. return Buffer.compare(this, b) === 0
  244. }
  245. Buffer.prototype.inspect = function () {
  246. var str = ''
  247. var max = exports.INSPECT_MAX_BYTES
  248. if (this.length > 0) {
  249. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  250. if (this.length > max)
  251. str += ' ... '
  252. }
  253. return '<Buffer ' + str + '>'
  254. }
  255. Buffer.prototype.compare = function (b) {
  256. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  257. return Buffer.compare(this, b)
  258. }
  259. // `get` will be removed in Node 0.13+
  260. Buffer.prototype.get = function (offset) {
  261. console.log('.get() is deprecated. Access using array indexes instead.')
  262. return this.readUInt8(offset)
  263. }
  264. // `set` will be removed in Node 0.13+
  265. Buffer.prototype.set = function (v, offset) {
  266. console.log('.set() is deprecated. Access using array indexes instead.')
  267. return this.writeUInt8(v, offset)
  268. }
  269. function hexWrite (buf, string, offset, length) {
  270. offset = Number(offset) || 0
  271. var remaining = buf.length - offset
  272. if (!length) {
  273. length = remaining
  274. } else {
  275. length = Number(length)
  276. if (length > remaining) {
  277. length = remaining
  278. }
  279. }
  280. // must be an even number of digits
  281. var strLen = string.length
  282. if (strLen % 2 !== 0) throw new Error('Invalid hex string')
  283. if (length > strLen / 2) {
  284. length = strLen / 2
  285. }
  286. for (var i = 0; i < length; i++) {
  287. var byte = parseInt(string.substr(i * 2, 2), 16)
  288. if (isNaN(byte)) throw new Error('Invalid hex string')
  289. buf[offset + i] = byte
  290. }
  291. return i
  292. }
  293. function utf8Write (buf, string, offset, length) {
  294. var charsWritten = blitBuffer(utf8ToBytes(string), buf, offset, length)
  295. return charsWritten
  296. }
  297. function asciiWrite (buf, string, offset, length) {
  298. var charsWritten = blitBuffer(asciiToBytes(string), buf, offset, length)
  299. return charsWritten
  300. }
  301. function binaryWrite (buf, string, offset, length) {
  302. return asciiWrite(buf, string, offset, length)
  303. }
  304. function base64Write (buf, string, offset, length) {
  305. var charsWritten = blitBuffer(base64ToBytes(string), buf, offset, length)
  306. return charsWritten
  307. }
  308. function utf16leWrite (buf, string, offset, length) {
  309. var charsWritten = blitBuffer(utf16leToBytes(string), buf, offset, length, 2)
  310. return charsWritten
  311. }
  312. Buffer.prototype.write = function (string, offset, length, encoding) {
  313. // Support both (string, offset, length, encoding)
  314. // and the legacy (string, encoding, offset, length)
  315. if (isFinite(offset)) {
  316. if (!isFinite(length)) {
  317. encoding = length
  318. length = undefined
  319. }
  320. } else { // legacy
  321. var swap = encoding
  322. encoding = offset
  323. offset = length
  324. length = swap
  325. }
  326. offset = Number(offset) || 0
  327. var remaining = this.length - offset
  328. if (!length) {
  329. length = remaining
  330. } else {
  331. length = Number(length)
  332. if (length > remaining) {
  333. length = remaining
  334. }
  335. }
  336. encoding = String(encoding || 'utf8').toLowerCase()
  337. var ret
  338. switch (encoding) {
  339. case 'hex':
  340. ret = hexWrite(this, string, offset, length)
  341. break
  342. case 'utf8':
  343. case 'utf-8':
  344. ret = utf8Write(this, string, offset, length)
  345. break
  346. case 'ascii':
  347. ret = asciiWrite(this, string, offset, length)
  348. break
  349. case 'binary':
  350. ret = binaryWrite(this, string, offset, length)
  351. break
  352. case 'base64':
  353. ret = base64Write(this, string, offset, length)
  354. break
  355. case 'ucs2':
  356. case 'ucs-2':
  357. case 'utf16le':
  358. case 'utf-16le':
  359. ret = utf16leWrite(this, string, offset, length)
  360. break
  361. default:
  362. throw new TypeError('Unknown encoding: ' + encoding)
  363. }
  364. return ret
  365. }
  366. Buffer.prototype.toJSON = function () {
  367. return {
  368. type: 'Buffer',
  369. data: Array.prototype.slice.call(this._arr || this, 0)
  370. }
  371. }
  372. function base64Slice (buf, start, end) {
  373. if (start === 0 && end === buf.length) {
  374. return base64.fromByteArray(buf)
  375. } else {
  376. return base64.fromByteArray(buf.slice(start, end))
  377. }
  378. }
  379. function utf8Slice (buf, start, end) {
  380. var res = ''
  381. var tmp = ''
  382. end = Math.min(buf.length, end)
  383. for (var i = start; i < end; i++) {
  384. if (buf[i] <= 0x7F) {
  385. res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
  386. tmp = ''
  387. } else {
  388. tmp += '%' + buf[i].toString(16)
  389. }
  390. }
  391. return res + decodeUtf8Char(tmp)
  392. }
  393. function asciiSlice (buf, start, end) {
  394. var ret = ''
  395. end = Math.min(buf.length, end)
  396. for (var i = start; i < end; i++) {
  397. ret += String.fromCharCode(buf[i])
  398. }
  399. return ret
  400. }
  401. function binarySlice (buf, start, end) {
  402. return asciiSlice(buf, start, end)
  403. }
  404. function hexSlice (buf, start, end) {
  405. var len = buf.length
  406. if (!start || start < 0) start = 0
  407. if (!end || end < 0 || end > len) end = len
  408. var out = ''
  409. for (var i = start; i < end; i++) {
  410. out += toHex(buf[i])
  411. }
  412. return out
  413. }
  414. function utf16leSlice (buf, start, end) {
  415. var bytes = buf.slice(start, end)
  416. var res = ''
  417. for (var i = 0; i < bytes.length; i += 2) {
  418. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  419. }
  420. return res
  421. }
  422. Buffer.prototype.slice = function (start, end) {
  423. var len = this.length
  424. start = ~~start
  425. end = end === undefined ? len : ~~end
  426. if (start < 0) {
  427. start += len;
  428. if (start < 0)
  429. start = 0
  430. } else if (start > len) {
  431. start = len
  432. }
  433. if (end < 0) {
  434. end += len
  435. if (end < 0)
  436. end = 0
  437. } else if (end > len) {
  438. end = len
  439. }
  440. if (end < start)
  441. end = start
  442. if (Buffer.TYPED_ARRAY_SUPPORT) {
  443. return Buffer._augment(this.subarray(start, end))
  444. } else {
  445. var sliceLen = end - start
  446. var newBuf = new Buffer(sliceLen, undefined, true)
  447. for (var i = 0; i < sliceLen; i++) {
  448. newBuf[i] = this[i + start]
  449. }
  450. return newBuf
  451. }
  452. }
  453. /*
  454. * Need to make sure that buffer isn't trying to write out of bounds.
  455. */
  456. function checkOffset (offset, ext, length) {
  457. if ((offset % 1) !== 0 || offset < 0)
  458. throw new RangeError('offset is not uint')
  459. if (offset + ext > length)
  460. throw new RangeError('Trying to access beyond buffer length')
  461. }
  462. Buffer.prototype.readUInt8 = function (offset, noAssert) {
  463. if (!noAssert)
  464. checkOffset(offset, 1, this.length)
  465. return this[offset]
  466. }
  467. Buffer.prototype.readUInt16LE = function (offset, noAssert) {
  468. if (!noAssert)
  469. checkOffset(offset, 2, this.length)
  470. return this[offset] | (this[offset + 1] << 8)
  471. }
  472. Buffer.prototype.readUInt16BE = function (offset, noAssert) {
  473. if (!noAssert)
  474. checkOffset(offset, 2, this.length)
  475. return (this[offset] << 8) | this[offset + 1]
  476. }
  477. Buffer.prototype.readUInt32LE = function (offset, noAssert) {
  478. if (!noAssert)
  479. checkOffset(offset, 4, this.length)
  480. return ((this[offset]) |
  481. (this[offset + 1] << 8) |
  482. (this[offset + 2] << 16)) +
  483. (this[offset + 3] * 0x1000000)
  484. }
  485. Buffer.prototype.readUInt32BE = function (offset, noAssert) {
  486. if (!noAssert)
  487. checkOffset(offset, 4, this.length)
  488. return (this[offset] * 0x1000000) +
  489. ((this[offset + 1] << 16) |
  490. (this[offset + 2] << 8) |
  491. this[offset + 3])
  492. }
  493. Buffer.prototype.readInt8 = function (offset, noAssert) {
  494. if (!noAssert)
  495. checkOffset(offset, 1, this.length)
  496. if (!(this[offset] & 0x80))
  497. return (this[offset])
  498. return ((0xff - this[offset] + 1) * -1)
  499. }
  500. Buffer.prototype.readInt16LE = function (offset, noAssert) {
  501. if (!noAssert)
  502. checkOffset(offset, 2, this.length)
  503. var val = this[offset] | (this[offset + 1] << 8)
  504. return (val & 0x8000) ? val | 0xFFFF0000 : val
  505. }
  506. Buffer.prototype.readInt16BE = function (offset, noAssert) {
  507. if (!noAssert)
  508. checkOffset(offset, 2, this.length)
  509. var val = this[offset + 1] | (this[offset] << 8)
  510. return (val & 0x8000) ? val | 0xFFFF0000 : val
  511. }
  512. Buffer.prototype.readInt32LE = function (offset, noAssert) {
  513. if (!noAssert)
  514. checkOffset(offset, 4, this.length)
  515. return (this[offset]) |
  516. (this[offset + 1] << 8) |
  517. (this[offset + 2] << 16) |
  518. (this[offset + 3] << 24)
  519. }
  520. Buffer.prototype.readInt32BE = function (offset, noAssert) {
  521. if (!noAssert)
  522. checkOffset(offset, 4, this.length)
  523. return (this[offset] << 24) |
  524. (this[offset + 1] << 16) |
  525. (this[offset + 2] << 8) |
  526. (this[offset + 3])
  527. }
  528. Buffer.prototype.readFloatLE = function (offset, noAssert) {
  529. if (!noAssert)
  530. checkOffset(offset, 4, this.length)
  531. return ieee754.read(this, offset, true, 23, 4)
  532. }
  533. Buffer.prototype.readFloatBE = function (offset, noAssert) {
  534. if (!noAssert)
  535. checkOffset(offset, 4, this.length)
  536. return ieee754.read(this, offset, false, 23, 4)
  537. }
  538. Buffer.prototype.readDoubleLE = function (offset, noAssert) {
  539. if (!noAssert)
  540. checkOffset(offset, 8, this.length)
  541. return ieee754.read(this, offset, true, 52, 8)
  542. }
  543. Buffer.prototype.readDoubleBE = function (offset, noAssert) {
  544. if (!noAssert)
  545. checkOffset(offset, 8, this.length)
  546. return ieee754.read(this, offset, false, 52, 8)
  547. }
  548. function checkInt (buf, value, offset, ext, max, min) {
  549. if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance')
  550. if (value > max || value < min) throw new TypeError('value is out of bounds')
  551. if (offset + ext > buf.length) throw new TypeError('index out of range')
  552. }
  553. Buffer.prototype.writeUInt8 = function (value, offset, noAssert) {
  554. value = +value
  555. offset = offset >>> 0
  556. if (!noAssert)
  557. checkInt(this, value, offset, 1, 0xff, 0)
  558. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  559. this[offset] = value
  560. return offset + 1
  561. }
  562. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  563. if (value < 0) value = 0xffff + value + 1
  564. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) {
  565. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  566. (littleEndian ? i : 1 - i) * 8
  567. }
  568. }
  569. Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) {
  570. value = +value
  571. offset = offset >>> 0
  572. if (!noAssert)
  573. checkInt(this, value, offset, 2, 0xffff, 0)
  574. if (Buffer.TYPED_ARRAY_SUPPORT) {
  575. this[offset] = value
  576. this[offset + 1] = (value >>> 8)
  577. } else objectWriteUInt16(this, value, offset, true)
  578. return offset + 2
  579. }
  580. Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) {
  581. value = +value
  582. offset = offset >>> 0
  583. if (!noAssert)
  584. checkInt(this, value, offset, 2, 0xffff, 0)
  585. if (Buffer.TYPED_ARRAY_SUPPORT) {
  586. this[offset] = (value >>> 8)
  587. this[offset + 1] = value
  588. } else objectWriteUInt16(this, value, offset, false)
  589. return offset + 2
  590. }
  591. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  592. if (value < 0) value = 0xffffffff + value + 1
  593. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) {
  594. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  595. }
  596. }
  597. Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) {
  598. value = +value
  599. offset = offset >>> 0
  600. if (!noAssert)
  601. checkInt(this, value, offset, 4, 0xffffffff, 0)
  602. if (Buffer.TYPED_ARRAY_SUPPORT) {
  603. this[offset + 3] = (value >>> 24)
  604. this[offset + 2] = (value >>> 16)
  605. this[offset + 1] = (value >>> 8)
  606. this[offset] = value
  607. } else objectWriteUInt32(this, value, offset, true)
  608. return offset + 4
  609. }
  610. Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) {
  611. value = +value
  612. offset = offset >>> 0
  613. if (!noAssert)
  614. checkInt(this, value, offset, 4, 0xffffffff, 0)
  615. if (Buffer.TYPED_ARRAY_SUPPORT) {
  616. this[offset] = (value >>> 24)
  617. this[offset + 1] = (value >>> 16)
  618. this[offset + 2] = (value >>> 8)
  619. this[offset + 3] = value
  620. } else objectWriteUInt32(this, value, offset, false)
  621. return offset + 4
  622. }
  623. Buffer.prototype.writeInt8 = function (value, offset, noAssert) {
  624. value = +value
  625. offset = offset >>> 0
  626. if (!noAssert)
  627. checkInt(this, value, offset, 1, 0x7f, -0x80)
  628. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  629. if (value < 0) value = 0xff + value + 1
  630. this[offset] = value
  631. return offset + 1
  632. }
  633. Buffer.prototype.writeInt16LE = function (value, offset, noAssert) {
  634. value = +value
  635. offset = offset >>> 0
  636. if (!noAssert)
  637. checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  638. if (Buffer.TYPED_ARRAY_SUPPORT) {
  639. this[offset] = value
  640. this[offset + 1] = (value >>> 8)
  641. } else objectWriteUInt16(this, value, offset, true)
  642. return offset + 2
  643. }
  644. Buffer.prototype.writeInt16BE = function (value, offset, noAssert) {
  645. value = +value
  646. offset = offset >>> 0
  647. if (!noAssert)
  648. checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  649. if (Buffer.TYPED_ARRAY_SUPPORT) {
  650. this[offset] = (value >>> 8)
  651. this[offset + 1] = value
  652. } else objectWriteUInt16(this, value, offset, false)
  653. return offset + 2
  654. }
  655. Buffer.prototype.writeInt32LE = function (value, offset, noAssert) {
  656. value = +value
  657. offset = offset >>> 0
  658. if (!noAssert)
  659. checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  660. if (Buffer.TYPED_ARRAY_SUPPORT) {
  661. this[offset] = value
  662. this[offset + 1] = (value >>> 8)
  663. this[offset + 2] = (value >>> 16)
  664. this[offset + 3] = (value >>> 24)
  665. } else objectWriteUInt32(this, value, offset, true)
  666. return offset + 4
  667. }
  668. Buffer.prototype.writeInt32BE = function (value, offset, noAssert) {
  669. value = +value
  670. offset = offset >>> 0
  671. if (!noAssert)
  672. checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  673. if (value < 0) value = 0xffffffff + value + 1
  674. if (Buffer.TYPED_ARRAY_SUPPORT) {
  675. this[offset] = (value >>> 24)
  676. this[offset + 1] = (value >>> 16)
  677. this[offset + 2] = (value >>> 8)
  678. this[offset + 3] = value
  679. } else objectWriteUInt32(this, value, offset, false)
  680. return offset + 4
  681. }
  682. function checkIEEE754 (buf, value, offset, ext, max, min) {
  683. if (value > max || value < min) throw new TypeError('value is out of bounds')
  684. if (offset + ext > buf.length) throw new TypeError('index out of range')
  685. }
  686. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  687. if (!noAssert)
  688. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  689. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  690. return offset + 4
  691. }
  692. Buffer.prototype.writeFloatLE = function (value, offset, noAssert) {
  693. return writeFloat(this, value, offset, true, noAssert)
  694. }
  695. Buffer.prototype.writeFloatBE = function (value, offset, noAssert) {
  696. return writeFloat(this, value, offset, false, noAssert)
  697. }
  698. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  699. if (!noAssert)
  700. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  701. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  702. return offset + 8
  703. }
  704. Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) {
  705. return writeDouble(this, value, offset, true, noAssert)
  706. }
  707. Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) {
  708. return writeDouble(this, value, offset, false, noAssert)
  709. }
  710. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  711. Buffer.prototype.copy = function (target, target_start, start, end) {
  712. var source = this
  713. if (!start) start = 0
  714. if (!end && end !== 0) end = this.length
  715. if (!target_start) target_start = 0
  716. // Copy 0 bytes; we're done
  717. if (end === start) return
  718. if (target.length === 0 || source.length === 0) return
  719. // Fatal error conditions
  720. if (end < start) throw new TypeError('sourceEnd < sourceStart')
  721. if (target_start < 0 || target_start >= target.length)
  722. throw new TypeError('targetStart out of bounds')
  723. if (start < 0 || start >= source.length) throw new TypeError('sourceStart out of bounds')
  724. if (end < 0 || end > source.length) throw new TypeError('sourceEnd out of bounds')
  725. // Are we oob?
  726. if (end > this.length)
  727. end = this.length
  728. if (target.length - target_start < end - start)
  729. end = target.length - target_start + start
  730. var len = end - start
  731. if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  732. for (var i = 0; i < len; i++) {
  733. target[i + target_start] = this[i + start]
  734. }
  735. } else {
  736. target._set(this.subarray(start, start + len), target_start)
  737. }
  738. }
  739. // fill(value, start=0, end=buffer.length)
  740. Buffer.prototype.fill = function (value, start, end) {
  741. if (!value) value = 0
  742. if (!start) start = 0
  743. if (!end) end = this.length
  744. if (end < start) throw new TypeError('end < start')
  745. // Fill 0 bytes; we're done
  746. if (end === start) return
  747. if (this.length === 0) return
  748. if (start < 0 || start >= this.length) throw new TypeError('start out of bounds')
  749. if (end < 0 || end > this.length) throw new TypeError('end out of bounds')
  750. var i
  751. if (typeof value === 'number') {
  752. for (i = start; i < end; i++) {
  753. this[i] = value
  754. }
  755. } else {
  756. var bytes = utf8ToBytes(value.toString())
  757. var len = bytes.length
  758. for (i = start; i < end; i++) {
  759. this[i] = bytes[i % len]
  760. }
  761. }
  762. return this
  763. }
  764. /**
  765. * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
  766. * Added in Node 0.12. Only available in browsers that support ArrayBuffer.
  767. */
  768. Buffer.prototype.toArrayBuffer = function () {
  769. if (typeof Uint8Array !== 'undefined') {
  770. if (Buffer.TYPED_ARRAY_SUPPORT) {
  771. return (new Buffer(this)).buffer
  772. } else {
  773. var buf = new Uint8Array(this.length)
  774. for (var i = 0, len = buf.length; i < len; i += 1) {
  775. buf[i] = this[i]
  776. }
  777. return buf.buffer
  778. }
  779. } else {
  780. throw new TypeError('Buffer.toArrayBuffer not supported in this browser')
  781. }
  782. }
  783. // HELPER FUNCTIONS
  784. // ================
  785. var BP = Buffer.prototype
  786. /**
  787. * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods
  788. */
  789. Buffer._augment = function (arr) {
  790. arr.constructor = Buffer
  791. arr._isBuffer = true
  792. // save reference to original Uint8Array get/set methods before overwriting
  793. arr._get = arr.get
  794. arr._set = arr.set
  795. // deprecated, will be removed in node 0.13+
  796. arr.get = BP.get
  797. arr.set = BP.set
  798. arr.write = BP.write
  799. arr.toString = BP.toString
  800. arr.toLocaleString = BP.toString
  801. arr.toJSON = BP.toJSON
  802. arr.equals = BP.equals
  803. arr.compare = BP.compare
  804. arr.copy = BP.copy
  805. arr.slice = BP.slice
  806. arr.readUInt8 = BP.readUInt8
  807. arr.readUInt16LE = BP.readUInt16LE
  808. arr.readUInt16BE = BP.readUInt16BE
  809. arr.readUInt32LE = BP.readUInt32LE
  810. arr.readUInt32BE = BP.readUInt32BE
  811. arr.readInt8 = BP.readInt8
  812. arr.readInt16LE = BP.readInt16LE
  813. arr.readInt16BE = BP.readInt16BE
  814. arr.readInt32LE = BP.readInt32LE
  815. arr.readInt32BE = BP.readInt32BE
  816. arr.readFloatLE = BP.readFloatLE
  817. arr.readFloatBE = BP.readFloatBE
  818. arr.readDoubleLE = BP.readDoubleLE
  819. arr.readDoubleBE = BP.readDoubleBE
  820. arr.writeUInt8 = BP.writeUInt8
  821. arr.writeUInt16LE = BP.writeUInt16LE
  822. arr.writeUInt16BE = BP.writeUInt16BE
  823. arr.writeUInt32LE = BP.writeUInt32LE
  824. arr.writeUInt32BE = BP.writeUInt32BE
  825. arr.writeInt8 = BP.writeInt8
  826. arr.writeInt16LE = BP.writeInt16LE
  827. arr.writeInt16BE = BP.writeInt16BE
  828. arr.writeInt32LE = BP.writeInt32LE
  829. arr.writeInt32BE = BP.writeInt32BE
  830. arr.writeFloatLE = BP.writeFloatLE
  831. arr.writeFloatBE = BP.writeFloatBE
  832. arr.writeDoubleLE = BP.writeDoubleLE
  833. arr.writeDoubleBE = BP.writeDoubleBE
  834. arr.fill = BP.fill
  835. arr.inspect = BP.inspect
  836. arr.toArrayBuffer = BP.toArrayBuffer
  837. return arr
  838. }
  839. var INVALID_BASE64_RE = /[^+\/0-9A-z]/g
  840. function base64clean (str) {
  841. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  842. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  843. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  844. while (str.length % 4 !== 0) {
  845. str = str + '='
  846. }
  847. return str
  848. }
  849. function stringtrim (str) {
  850. if (str.trim) return str.trim()
  851. return str.replace(/^\s+|\s+$/g, '')
  852. }
  853. function isArrayish (subject) {
  854. return isArray(subject) || Buffer.isBuffer(subject) ||
  855. subject && typeof subject === 'object' &&
  856. typeof subject.length === 'number'
  857. }
  858. function toHex (n) {
  859. if (n < 16) return '0' + n.toString(16)
  860. return n.toString(16)
  861. }
  862. function utf8ToBytes (str) {
  863. var byteArray = []
  864. for (var i = 0; i < str.length; i++) {
  865. var b = str.charCodeAt(i)
  866. if (b <= 0x7F) {
  867. byteArray.push(b)
  868. } else {
  869. var start = i
  870. if (b >= 0xD800 && b <= 0xDFFF) i++
  871. var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%')
  872. for (var j = 0; j < h.length; j++) {
  873. byteArray.push(parseInt(h[j], 16))
  874. }
  875. }
  876. }
  877. return byteArray
  878. }
  879. function asciiToBytes (str) {
  880. var byteArray = []
  881. for (var i = 0; i < str.length; i++) {
  882. // Node's code seems to be doing this and not & 0x7F..
  883. byteArray.push(str.charCodeAt(i) & 0xFF)
  884. }
  885. return byteArray
  886. }
  887. function utf16leToBytes (str) {
  888. var c, hi, lo
  889. var byteArray = []
  890. for (var i = 0; i < str.length; i++) {
  891. c = str.charCodeAt(i)
  892. hi = c >> 8
  893. lo = c % 256
  894. byteArray.push(lo)
  895. byteArray.push(hi)
  896. }
  897. return byteArray
  898. }
  899. function base64ToBytes (str) {
  900. return base64.toByteArray(str)
  901. }
  902. function blitBuffer (src, dst, offset, length, unitSize) {
  903. if (unitSize) length -= length % unitSize;
  904. for (var i = 0; i < length; i++) {
  905. if ((i + offset >= dst.length) || (i >= src.length))
  906. break
  907. dst[i + offset] = src[i]
  908. }
  909. return i
  910. }
  911. function decodeUtf8Char (str) {
  912. try {
  913. return decodeURIComponent(str)
  914. } catch (err) {
  915. return String.fromCharCode(0xFFFD) // UTF 8 invalid char
  916. }
  917. }
  918. },{"base64-js":2,"ieee754":3,"is-array":4}],2:[function(_dereq_,module,exports){
  919. var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  920. ;(function (exports) {
  921. 'use strict';
  922. var Arr = (typeof Uint8Array !== 'undefined')
  923. ? Uint8Array
  924. : Array
  925. var PLUS = '+'.charCodeAt(0)
  926. var SLASH = '/'.charCodeAt(0)
  927. var NUMBER = '0'.charCodeAt(0)
  928. var LOWER = 'a'.charCodeAt(0)
  929. var UPPER = 'A'.charCodeAt(0)
  930. function decode (elt) {
  931. var code = elt.charCodeAt(0)
  932. if (code === PLUS)
  933. return 62 // '+'
  934. if (code === SLASH)
  935. return 63 // '/'
  936. if (code < NUMBER)
  937. return -1 //no match
  938. if (code < NUMBER + 10)
  939. return code - NUMBER + 26 + 26
  940. if (code < UPPER + 26)
  941. return code - UPPER
  942. if (code < LOWER + 26)
  943. return code - LOWER + 26
  944. }
  945. function b64ToByteArray (b64) {
  946. var i, j, l, tmp, placeHolders, arr
  947. if (b64.length % 4 > 0) {
  948. throw new Error('Invalid string. Length must be a multiple of 4')
  949. }
  950. // the number of equal signs (place holders)
  951. // if there are two placeholders, than the two characters before it
  952. // represent one byte
  953. // if there is only one, then the three characters before it represent 2 bytes
  954. // this is just a cheap hack to not do indexOf twice
  955. var len = b64.length
  956. placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
  957. // base64 is 4/3 + up to two characters of the original data
  958. arr = new Arr(b64.length * 3 / 4 - placeHolders)
  959. // if there are placeholders, only get up to the last complete 4 chars
  960. l = placeHolders > 0 ? b64.length - 4 : b64.length
  961. var L = 0
  962. function push (v) {
  963. arr[L++] = v
  964. }
  965. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  966. tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
  967. push((tmp & 0xFF0000) >> 16)
  968. push((tmp & 0xFF00) >> 8)
  969. push(tmp & 0xFF)
  970. }
  971. if (placeHolders === 2) {
  972. tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
  973. push(tmp & 0xFF)
  974. } else if (placeHolders === 1) {
  975. tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
  976. push((tmp >> 8) & 0xFF)
  977. push(tmp & 0xFF)
  978. }
  979. return arr
  980. }
  981. function uint8ToBase64 (uint8) {
  982. var i,
  983. extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
  984. output = "",
  985. temp, length
  986. function encode (num) {
  987. return lookup.charAt(num)
  988. }
  989. function tripletToBase64 (num) {
  990. return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
  991. }
  992. // go through the array every three bytes, we'll deal with trailing stuff later
  993. for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
  994. temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  995. output += tripletToBase64(temp)
  996. }
  997. // pad the end with zeros, but make sure to not forget the extra bytes
  998. switch (extraBytes) {
  999. case 1:
  1000. temp = uint8[uint8.length - 1]
  1001. output += encode(temp >> 2)
  1002. output += encode((temp << 4) & 0x3F)
  1003. output += '=='
  1004. break
  1005. case 2:
  1006. temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
  1007. output += encode(temp >> 10)
  1008. output += encode((temp >> 4) & 0x3F)
  1009. output += encode((temp << 2) & 0x3F)
  1010. output += '='
  1011. break
  1012. }
  1013. return output
  1014. }
  1015. exports.toByteArray = b64ToByteArray
  1016. exports.fromByteArray = uint8ToBase64
  1017. }(typeof exports === 'undefined' ? (this.base64js = {}) : exports))
  1018. },{}],3:[function(_dereq_,module,exports){
  1019. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  1020. var e, m
  1021. var eLen = nBytes * 8 - mLen - 1
  1022. var eMax = (1 << eLen) - 1
  1023. var eBias = eMax >> 1
  1024. var nBits = -7
  1025. var i = isLE ? (nBytes - 1) : 0
  1026. var d = isLE ? -1 : 1
  1027. var s = buffer[offset + i]
  1028. i += d
  1029. e = s & ((1 << (-nBits)) - 1)
  1030. s >>= (-nBits)
  1031. nBits += eLen
  1032. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  1033. m = e & ((1 << (-nBits)) - 1)
  1034. e >>= (-nBits)
  1035. nBits += mLen
  1036. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  1037. if (e === 0) {
  1038. e = 1 - eBias
  1039. } else if (e === eMax) {
  1040. return m ? NaN : ((s ? -1 : 1) * Infinity)
  1041. } else {
  1042. m = m + Math.pow(2, mLen)
  1043. e = e - eBias
  1044. }
  1045. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  1046. }
  1047. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  1048. var e, m, c
  1049. var eLen = nBytes * 8 - mLen - 1
  1050. var eMax = (1 << eLen) - 1
  1051. var eBias = eMax >> 1
  1052. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  1053. var i = isLE ? 0 : (nBytes - 1)
  1054. var d = isLE ? 1 : -1
  1055. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  1056. value = Math.abs(value)
  1057. if (isNaN(value) || value === Infinity) {
  1058. m = isNaN(value) ? 1 : 0
  1059. e = eMax
  1060. } else {
  1061. e = Math.floor(Math.log(value) / Math.LN2)
  1062. if (value * (c = Math.pow(2, -e)) < 1) {
  1063. e--
  1064. c *= 2
  1065. }
  1066. if (e + eBias >= 1) {
  1067. value += rt / c
  1068. } else {
  1069. value += rt * Math.pow(2, 1 - eBias)
  1070. }
  1071. if (value * c >= 2) {
  1072. e++
  1073. c /= 2
  1074. }
  1075. if (e + eBias >= eMax) {
  1076. m = 0
  1077. e = eMax
  1078. } else if (e + eBias >= 1) {
  1079. m = (value * c - 1) * Math.pow(2, mLen)
  1080. e = e + eBias
  1081. } else {
  1082. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  1083. e = 0
  1084. }
  1085. }
  1086. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  1087. e = (e << mLen) | m
  1088. eLen += mLen
  1089. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  1090. buffer[offset + i - d] |= s * 128
  1091. }
  1092. },{}],4:[function(_dereq_,module,exports){
  1093. /**
  1094. * isArray
  1095. */
  1096. var isArray = Array.isArray;
  1097. /**
  1098. * toString
  1099. */
  1100. var str = Object.prototype.toString;
  1101. /**
  1102. * Whether or not the given `val`
  1103. * is an array.
  1104. *
  1105. * example:
  1106. *
  1107. * isArray([]);
  1108. * // > true
  1109. * isArray(arguments);
  1110. * // > false
  1111. * isArray('');
  1112. * // > false
  1113. *
  1114. * @param {mixed} val
  1115. * @return {bool}
  1116. */
  1117. module.exports = isArray || function (val) {
  1118. return !! val && '[object Array]' == str.call(val);
  1119. };
  1120. },{}],5:[function(_dereq_,module,exports){
  1121. 'use strict';
  1122. var DataReader = _dereq_('./dataReader');
  1123. function ArrayReader(data) {
  1124. if (data) {
  1125. this.data = data;
  1126. this.length = this.data.length;
  1127. this.index = 0;
  1128. this.zero = 0;
  1129. for(var i = 0; i < this.data.length; i++) {
  1130. data[i] = data[i] & 0xFF;
  1131. }
  1132. }
  1133. }
  1134. ArrayReader.prototype = new DataReader();
  1135. /**
  1136. * @see DataReader.byteAt
  1137. */
  1138. ArrayReader.prototype.byteAt = function(i) {
  1139. return this.data[this.zero + i];
  1140. };
  1141. /**
  1142. * @see DataReader.lastIndexOfSignature
  1143. */
  1144. ArrayReader.prototype.lastIndexOfSignature = function(sig) {
  1145. var sig0 = sig.charCodeAt(0),
  1146. sig1 = sig.charCodeAt(1),
  1147. sig2 = sig.charCodeAt(2),
  1148. sig3 = sig.charCodeAt(3);
  1149. for (var i = this.length - 4; i >= 0; --i) {
  1150. if (this.data[i] === sig0 && this.data[i + 1] === sig1 && this.data[i + 2] === sig2 && this.data[i + 3] === sig3) {
  1151. return i - this.zero;
  1152. }
  1153. }
  1154. return -1;
  1155. };
  1156. /**
  1157. * @see DataReader.readData
  1158. */
  1159. ArrayReader.prototype.readData = function(size) {
  1160. this.checkOffset(size);
  1161. if(size === 0) {
  1162. return [];
  1163. }
  1164. var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
  1165. this.index += size;
  1166. return result;
  1167. };
  1168. module.exports = ArrayReader;
  1169. },{"./dataReader":10}],6:[function(_dereq_,module,exports){
  1170. 'use strict';
  1171. // private property
  1172. var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  1173. // public method for encoding
  1174. exports.encode = function(input, utf8) {
  1175. var output = "";
  1176. var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  1177. var i = 0;
  1178. while (i < input.length) {
  1179. chr1 = input.charCodeAt(i++);
  1180. chr2 = input.charCodeAt(i++);
  1181. chr3 = input.charCodeAt(i++);
  1182. enc1 = chr1 >> 2;
  1183. enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
  1184. enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
  1185. enc4 = chr3 & 63;
  1186. if (isNaN(chr2)) {
  1187. enc3 = enc4 = 64;
  1188. }
  1189. else if (isNaN(chr3)) {
  1190. enc4 = 64;
  1191. }
  1192. output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
  1193. }
  1194. return output;
  1195. };
  1196. // public method for decoding
  1197. exports.decode = function(input, utf8) {
  1198. var output = "";
  1199. var chr1, chr2, chr3;
  1200. var enc1, enc2, enc3, enc4;
  1201. var i = 0;
  1202. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  1203. while (i < input.length) {
  1204. enc1 = _keyStr.indexOf(input.charAt(i++));
  1205. enc2 = _keyStr.indexOf(input.charAt(i++));
  1206. enc3 = _keyStr.indexOf(input.charAt(i++));
  1207. enc4 = _keyStr.indexOf(input.charAt(i++));
  1208. chr1 = (enc1 << 2) | (enc2 >> 4);
  1209. chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
  1210. chr3 = ((enc3 & 3) << 6) | enc4;
  1211. output = output + String.fromCharCode(chr1);
  1212. if (enc3 != 64) {
  1213. output = output + String.fromCharCode(chr2);
  1214. }
  1215. if (enc4 != 64) {
  1216. output = output + String.fromCharCode(chr3);
  1217. }
  1218. }
  1219. return output;
  1220. };
  1221. },{}],7:[function(_dereq_,module,exports){
  1222. 'use strict';
  1223. function CompressedObject() {
  1224. this.compressedSize = 0;
  1225. this.uncompressedSize = 0;
  1226. this.crc32 = 0;
  1227. this.compressionMethod = null;
  1228. this.compressedContent = null;
  1229. }
  1230. CompressedObject.prototype = {
  1231. /**
  1232. * Return the decompressed content in an unspecified format.
  1233. * The format will depend on the decompressor.
  1234. * @return {Object} the decompressed content.
  1235. */
  1236. getContent: function() {
  1237. return null; // see implementation
  1238. },
  1239. /**
  1240. * Return the compressed content in an unspecified format.
  1241. * The format will depend on the compressed conten source.
  1242. * @return {Object} the compressed content.
  1243. */
  1244. getCompressedContent: function() {
  1245. return null; // see implementation
  1246. }
  1247. };
  1248. module.exports = CompressedObject;
  1249. },{}],8:[function(_dereq_,module,exports){
  1250. 'use strict';
  1251. exports.STORE = {
  1252. magic: "\x00\x00",
  1253. compress: function(content, compressionOptions) {
  1254. return content; // no compression
  1255. },
  1256. uncompress: function(content) {
  1257. return content; // no compression
  1258. },
  1259. compressInputType: null,
  1260. uncompressInputType: null
  1261. };
  1262. exports.DEFLATE = _dereq_('./flate');
  1263. },{"./flate":13}],9:[function(_dereq_,module,exports){
  1264. 'use strict';
  1265. var utils = _dereq_('./utils');
  1266. var table = [
  1267. 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
  1268. 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
  1269. 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
  1270. 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
  1271. 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
  1272. 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
  1273. 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
  1274. 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
  1275. 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
  1276. 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
  1277. 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
  1278. 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
  1279. 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
  1280. 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
  1281. 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
  1282. 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
  1283. 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
  1284. 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
  1285. 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
  1286. 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
  1287. 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
  1288. 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
  1289. 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
  1290. 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
  1291. 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
  1292. 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
  1293. 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
  1294. 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
  1295. 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
  1296. 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
  1297. 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
  1298. 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
  1299. 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
  1300. 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
  1301. 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
  1302. 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
  1303. 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
  1304. 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
  1305. 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
  1306. 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
  1307. 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
  1308. 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
  1309. 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
  1310. 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
  1311. 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
  1312. 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
  1313. 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
  1314. 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
  1315. 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
  1316. 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
  1317. 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
  1318. 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
  1319. 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
  1320. 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
  1321. 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
  1322. 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
  1323. 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
  1324. 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
  1325. 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
  1326. 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
  1327. 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
  1328. 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
  1329. 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
  1330. 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
  1331. ];
  1332. /**
  1333. *
  1334. * Javascript crc32
  1335. * http://www.webtoolkit.info/
  1336. *
  1337. */
  1338. module.exports = function crc32(input, crc) {
  1339. if (typeof input === "undefined" || !input.length) {
  1340. return 0;
  1341. }
  1342. var isArray = utils.getTypeOf(input) !== "string";
  1343. if (typeof(crc) == "undefined") {
  1344. crc = 0;
  1345. }
  1346. var x = 0;
  1347. var y = 0;
  1348. var b = 0;
  1349. crc = crc ^ (-1);
  1350. for (var i = 0, iTop = input.length; i < iTop; i++) {
  1351. b = isArray ? input[i] : input.charCodeAt(i);
  1352. y = (crc ^ b) & 0xFF;
  1353. x = table[y];
  1354. crc = (crc >>> 8) ^ x;
  1355. }
  1356. return crc ^ (-1);
  1357. };
  1358. // vim: set shiftwidth=4 softtabstop=4:
  1359. },{"./utils":26}],10:[function(_dereq_,module,exports){
  1360. 'use strict';
  1361. var utils = _dereq_('./utils');
  1362. function DataReader(data) {
  1363. this.data = null; // type : see implementation
  1364. this.length = 0;
  1365. this.index = 0;
  1366. this.zero = 0;
  1367. }
  1368. DataReader.prototype = {
  1369. /**
  1370. * Check that the offset will not go too far.
  1371. * @param {string} offset the additional offset to check.
  1372. * @throws {Error} an Error if the offset is out of bounds.
  1373. */
  1374. checkOffset: function(offset) {
  1375. this.checkIndex(this.index + offset);
  1376. },
  1377. /**
  1378. * Check that the specifed index will not be too far.
  1379. * @param {string} newIndex the index to check.
  1380. * @throws {Error} an Error if the index is out of bounds.
  1381. */
  1382. checkIndex: function(newIndex) {
  1383. if (this.length < this.zero + newIndex || newIndex < 0) {
  1384. throw new Error("End of data reached (data length = " + this.length + ", asked index = " + (newIndex) + "). Corrupted zip ?");
  1385. }
  1386. },
  1387. /**
  1388. * Change the index.
  1389. * @param {number} newIndex The new index.
  1390. * @throws {Error} if the new index is out of the data.
  1391. */
  1392. setIndex: function(newIndex) {
  1393. this.checkIndex(newIndex);
  1394. this.index = newIndex;
  1395. },
  1396. /**
  1397. * Skip the next n bytes.
  1398. * @param {number} n the number of bytes to skip.
  1399. * @throws {Error} if the new index is out of the data.
  1400. */
  1401. skip: function(n) {
  1402. this.setIndex(this.index + n);
  1403. },
  1404. /**
  1405. * Get the byte at the specified index.
  1406. * @param {number} i the index to use.
  1407. * @return {number} a byte.
  1408. */
  1409. byteAt: function(i) {
  1410. // see implementations
  1411. },
  1412. /**
  1413. * Get the next number with a given byte size.
  1414. * @param {number} size the number of bytes to read.
  1415. * @return {number} the corresponding number.
  1416. */
  1417. readInt: function(size) {
  1418. var result = 0,
  1419. i;
  1420. this.checkOffset(size);
  1421. for (i = this.index + size - 1; i >= this.index; i--) {
  1422. result = (result << 8) + this.byteAt(i);
  1423. }
  1424. this.index += size;
  1425. return result;
  1426. },
  1427. /**
  1428. * Get the next string with a given byte size.
  1429. * @param {number} size the number of bytes to read.
  1430. * @return {string} the corresponding string.
  1431. */
  1432. readString: function(size) {
  1433. return utils.transformTo("string", this.readData(size));
  1434. },
  1435. /**
  1436. * Get raw data without conversion, <size> bytes.
  1437. * @param {number} size the number of bytes to read.
  1438. * @return {Object} the raw data, implementation specific.
  1439. */
  1440. readData: function(size) {
  1441. // see implementations
  1442. },
  1443. /**
  1444. * Find the last occurence of a zip signature (4 bytes).
  1445. * @param {string} sig the signature to find.
  1446. * @return {number} the index of the last occurence, -1 if not found.
  1447. */
  1448. lastIndexOfSignature: function(sig) {
  1449. // see implementations
  1450. },
  1451. /**
  1452. * Get the next date.
  1453. * @return {Date} the date.
  1454. */
  1455. readDate: function() {
  1456. var dostime = this.readInt(4);
  1457. return new Date(
  1458. ((dostime >> 25) & 0x7f) + 1980, // year
  1459. ((dostime >> 21) & 0x0f) - 1, // month
  1460. (dostime >> 16) & 0x1f, // day
  1461. (dostime >> 11) & 0x1f, // hour
  1462. (dostime >> 5) & 0x3f, // minute
  1463. (dostime & 0x1f) << 1); // second
  1464. }
  1465. };
  1466. module.exports = DataReader;
  1467. },{"./utils":26}],11:[function(_dereq_,module,exports){
  1468. 'use strict';
  1469. exports.base64 = false;
  1470. exports.binary = false;
  1471. exports.dir = false;
  1472. exports.createFolders = false;
  1473. exports.date = null;
  1474. exports.compression = null;
  1475. exports.compressionOptions = null;
  1476. exports.comment = null;
  1477. exports.unixPermissions = null;
  1478. exports.dosPermissions = null;
  1479. },{}],12:[function(_dereq_,module,exports){
  1480. 'use strict';
  1481. var utils = _dereq_('./utils');
  1482. /**
  1483. * @deprecated
  1484. * This function will be removed in a future version without replacement.
  1485. */
  1486. exports.string2binary = function(str) {
  1487. return utils.string2binary(str);
  1488. };
  1489. /**
  1490. * @deprecated
  1491. * This function will be removed in a future version without replacement.
  1492. */
  1493. exports.string2Uint8Array = function(str) {
  1494. return utils.transformTo("uint8array", str);
  1495. };
  1496. /**
  1497. * @deprecated
  1498. * This function will be removed in a future version without replacement.
  1499. */
  1500. exports.uint8Array2String = function(array) {
  1501. return utils.transformTo("string", array);
  1502. };
  1503. /**
  1504. * @deprecated
  1505. * This function will be removed in a future version without replacement.
  1506. */
  1507. exports.string2Blob = function(str) {
  1508. var buffer = utils.transformTo("arraybuffer", str);
  1509. return utils.arrayBuffer2Blob(buffer);
  1510. };
  1511. /**
  1512. * @deprecated
  1513. * This function will be removed in a future version without replacement.
  1514. */
  1515. exports.arrayBuffer2Blob = function(buffer) {
  1516. return utils.arrayBuffer2Blob(buffer);
  1517. };
  1518. /**
  1519. * @deprecated
  1520. * This function will be removed in a future version without replacement.
  1521. */
  1522. exports.transformTo = function(outputType, input) {
  1523. return utils.transformTo(outputType, input);
  1524. };
  1525. /**
  1526. * @deprecated
  1527. * This function will be removed in a future version without replacement.
  1528. */
  1529. exports.getTypeOf = function(input) {
  1530. return utils.getTypeOf(input);
  1531. };
  1532. /**
  1533. * @deprecated
  1534. * This function will be removed in a future version without replacement.
  1535. */
  1536. exports.checkSupport = function(type) {
  1537. return utils.checkSupport(type);
  1538. };
  1539. /**
  1540. * @deprecated
  1541. * This value will be removed in a future version without replacement.
  1542. */
  1543. exports.MAX_VALUE_16BITS = utils.MAX_VALUE_16BITS;
  1544. /**
  1545. * @deprecated
  1546. * This value will be removed in a future version without replacement.
  1547. */
  1548. exports.MAX_VALUE_32BITS = utils.MAX_VALUE_32BITS;
  1549. /**
  1550. * @deprecated
  1551. * This function will be removed in a future version without replacement.
  1552. */
  1553. exports.pretty = function(str) {
  1554. return utils.pretty(str);
  1555. };
  1556. /**
  1557. * @deprecated
  1558. * This function will be removed in a future version without replacement.
  1559. */
  1560. exports.findCompression = function(compressionMethod) {
  1561. return utils.findCompression(compressionMethod);
  1562. };
  1563. /**
  1564. * @deprecated
  1565. * This function will be removed in a future version without replacement.
  1566. */
  1567. exports.isRegExp = function (object) {
  1568. return utils.isRegExp(object);
  1569. };
  1570. },{"./utils":26}],13:[function(_dereq_,module,exports){
  1571. 'use strict';
  1572. var USE_TYPEDARRAY = (typeof Uint8Array !== 'undefined') && (typeof Uint16Array !== 'undefined') && (typeof Uint32Array !== 'undefined');
  1573. var pako = _dereq_("pako");
  1574. exports.uncompressInputType = USE_TYPEDARRAY ? "uint8array" : "array";
  1575. exports.compressInputType = USE_TYPEDARRAY ? "uint8array" : "array";
  1576. exports.magic = "\x08\x00";
  1577. exports.compress = function(input, compressionOptions) {
  1578. return pako.deflateRaw(input, {
  1579. level : compressionOptions.level || -1 // default compression
  1580. });
  1581. };
  1582. exports.uncompress = function(input) {
  1583. return pako.inflateRaw(input);
  1584. };
  1585. },{"pako":29}],14:[function(_dereq_,module,exports){
  1586. 'use strict';
  1587. var base64 = _dereq_('./base64');
  1588. /**
  1589. Usage:
  1590. zip = new JSZip();
  1591. zip.file("hello.txt", "Hello, World!").file("tempfile", "nothing");
  1592. zip.folder("images").file("smile.gif", base64Data, {base64: true});
  1593. zip.file("Xmas.txt", "Ho ho ho !", {date : new Date("December 25, 2007 00:00:01")});
  1594. zip.remove("tempfile");
  1595. base64zip = zip.generate();
  1596. **/
  1597. /**
  1598. * Representation a of zip file in js
  1599. * @constructor
  1600. * @param {String=|ArrayBuffer=|Uint8Array=} data the data to load, if any (optional).
  1601. * @param {Object=} options the options for creating this objects (optional).
  1602. */
  1603. function JSZip(data, options) {
  1604. // if this constructor is used without `new`, it adds `new` before itself:
  1605. if(!(this instanceof JSZip)) return new JSZip(data, options);
  1606. // object containing the files :
  1607. // {
  1608. // "folder/" : {...},
  1609. // "folder/data.txt" : {...}
  1610. // }
  1611. this.files = {};
  1612. this.comment = null;
  1613. // Where we are in the hierarchy
  1614. this.root = "";
  1615. if (data) {
  1616. this.load(data, options);
  1617. }
  1618. this.clone = function() {
  1619. var newObj = new JSZip();
  1620. for (var i in this) {
  1621. if (typeof this[i] !== "function") {
  1622. newObj[i] = this[i];
  1623. }
  1624. }
  1625. return newObj;
  1626. };
  1627. }
  1628. JSZip.prototype = _dereq_('./object');
  1629. JSZip.prototype.load = _dereq_('./load');
  1630. JSZip.support = _dereq_('./support');
  1631. JSZip.defaults = _dereq_('./defaults');
  1632. /**
  1633. * @deprecated
  1634. * This namespace will be removed in a future version without replacement.
  1635. */
  1636. JSZip.utils = _dereq_('./deprecatedPublicUtils');
  1637. JSZip.base64 = {
  1638. /**
  1639. * @deprecated
  1640. * This method will be removed in a future version without replacement.
  1641. */
  1642. encode : function(input) {
  1643. return base64.encode(input);
  1644. },
  1645. /**
  1646. * @deprecated
  1647. * This method will be removed in a future version without replacement.
  1648. */
  1649. decode : function(input) {
  1650. return base64.decode(input);
  1651. }
  1652. };
  1653. JSZip.compressions = _dereq_('./compressions');
  1654. module.exports = JSZip;
  1655. },{"./base64":6,"./compressions":8,"./defaults":11,"./deprecatedPublicUtils":12,"./load":15,"./object":18,"./support":22}],15:[function(_dereq_,module,exports){
  1656. 'use strict';
  1657. var base64 = _dereq_('./base64');
  1658. var utf8 = _dereq_('./utf8');
  1659. var utils = _dereq_('./utils');
  1660. var ZipEntries = _dereq_('./zipEntries');
  1661. module.exports = function(data, options) {
  1662. var files, zipEntries, i, input;
  1663. options = utils.extend(options || {}, {
  1664. base64: false,
  1665. checkCRC32: false,
  1666. optimizedBinaryString : false,
  1667. createFolders: false,
  1668. decodeFileName: utf8.utf8decode
  1669. });
  1670. if (options.base64) {
  1671. data = base64.decode(data);
  1672. }
  1673. zipEntries = new ZipEntries(data, options);
  1674. files = zipEntries.files;
  1675. for (i = 0; i < files.length; i++) {
  1676. input = files[i];
  1677. this.file(input.fileNameStr, input.decompressed, {
  1678. binary: true,
  1679. optimizedBinaryString: true,
  1680. date: input.date,
  1681. dir: input.dir,
  1682. comment : input.fileCommentStr.length ? input.fileCommentStr : null,
  1683. unixPermissions : input.unixPermissions,
  1684. dosPermissions : input.dosPermissions,
  1685. createFolders: options.createFolders
  1686. });
  1687. }
  1688. if (zipEntries.zipComment.length) {
  1689. this.comment = zipEntries.zipComment;
  1690. }
  1691. return this;
  1692. };
  1693. },{"./base64":6,"./utf8":25,"./utils":26,"./zipEntries":27}],16:[function(_dereq_,module,exports){
  1694. (function (Buffer){
  1695. 'use strict';
  1696. module.exports = function(data, encoding){
  1697. return new Buffer(data, encoding);
  1698. };
  1699. module.exports.test = function(b){
  1700. return Buffer.isBuffer(b);
  1701. };
  1702. }).call(this,_dereq_("buffer").Buffer)
  1703. },{"buffer":1}],17:[function(_dereq_,module,exports){
  1704. 'use strict';
  1705. var Uint8ArrayReader = _dereq_('./uint8ArrayReader');
  1706. function NodeBufferReader(data) {
  1707. this.data = data;
  1708. this.length = this.data.length;
  1709. this.index = 0;
  1710. this.zero = 0;
  1711. }
  1712. NodeBufferReader.prototype = new Uint8ArrayReader();
  1713. /**
  1714. * @see DataReader.readData
  1715. */
  1716. NodeBufferReader.prototype.readData = function(size) {
  1717. this.checkOffset(size);
  1718. var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
  1719. this.index += size;
  1720. return result;
  1721. };
  1722. module.exports = NodeBufferReader;
  1723. },{"./uint8ArrayReader":23}],18:[function(_dereq_,module,exports){
  1724. 'use strict';
  1725. var support = _dereq_('./support');
  1726. var utils = _dereq_('./utils');
  1727. var crc32 = _dereq_('./crc32');
  1728. var signature = _dereq_('./signature');
  1729. var defaults = _dereq_('./defaults');
  1730. var base64 = _dereq_('./base64');
  1731. var compressions = _dereq_('./compressions');
  1732. var CompressedObject = _dereq_('./compressedObject');
  1733. var nodeBuffer = _dereq_('./nodeBuffer');
  1734. var utf8 = _dereq_('./utf8');
  1735. var StringWriter = _dereq_('./stringWriter');
  1736. var Uint8ArrayWriter = _dereq_('./uint8ArrayWriter');
  1737. /**
  1738. * Returns the raw data of a ZipObject, decompress the content if necessary.
  1739. * @param {ZipObject} file the file to use.
  1740. * @return {String|ArrayBuffer|Uint8Array|Buffer} the data.
  1741. */
  1742. var getRawData = function(file) {
  1743. if (file._data instanceof CompressedObject) {
  1744. file._data = file._data.getContent();
  1745. file.options.binary = true;
  1746. file.options.base64 = false;
  1747. if (utils.getTypeOf(file._data) === "uint8array") {
  1748. var copy = file._data;
  1749. // when reading an arraybuffer, the CompressedObject mechanism will keep it and subarray() a Uint8Array.
  1750. // if we request a file in the same format, we might get the same Uint8Array or its ArrayBuffer (the original zip file).
  1751. file._data = new Uint8Array(copy.length);
  1752. // with an empty Uint8Array, Opera fails with a "Offset larger than array size"
  1753. if (copy.length !== 0) {
  1754. file._data.set(copy, 0);
  1755. }
  1756. }
  1757. }
  1758. return file._data;
  1759. };
  1760. /**
  1761. * Returns the data of a ZipObject in a binary form. If the content is an unicode string, encode it.
  1762. * @param {ZipObject} file the file to use.
  1763. * @return {String|ArrayBuffer|Uint8Array|Buffer} the data.
  1764. */
  1765. var getBinaryData = function(file) {
  1766. var result = getRawData(file),
  1767. type = utils.getTypeOf(result);
  1768. if (type === "string") {
  1769. if (!file.options.binary) {
  1770. // unicode text !
  1771. // unicode string => binary string is a painful process, check if we can avoid it.
  1772. if (support.nodebuffer) {
  1773. return nodeBuffer(result, "utf-8");
  1774. }
  1775. }
  1776. return file.asBinary();
  1777. }
  1778. return result;
  1779. };
  1780. /**
  1781. * Transform this._data into a string.
  1782. * @param {function} filter a function String -> String, applied if not null on the result.
  1783. * @return {String} the string representing this._data.
  1784. */
  1785. var dataToString = function(asUTF8) {
  1786. var result = getRawData(this);
  1787. if (result === null || typeof result === "undefined") {
  1788. return "";
  1789. }
  1790. // if the data is a base64 string, we decode it before checking the encoding !
  1791. if (this.options.base64) {
  1792. result = base64.decode(result);
  1793. }
  1794. if (asUTF8 && this.options.binary) {
  1795. // JSZip.prototype.utf8decode supports arrays as input
  1796. // skip to array => string step, utf8decode will do it.
  1797. result = out.utf8decode(result);
  1798. }
  1799. else {
  1800. // no utf8 transformation, do the array => string step.
  1801. result = utils.transformTo("string", result);
  1802. }
  1803. if (!asUTF8 && !this.options.binary) {
  1804. result = utils.transformTo("string", out.utf8encode(result));
  1805. }
  1806. return result;
  1807. };
  1808. /**
  1809. * A simple object representing a file in the zip file.
  1810. * @constructor
  1811. * @param {string} name the name of the file
  1812. * @param {String|ArrayBuffer|Uint8Array|Buffer} data the data
  1813. * @param {Object} options the options of the file
  1814. */
  1815. var ZipObject = function(name, data, options) {
  1816. this.name = name;
  1817. this.dir = options.dir;
  1818. this.date = options.date;
  1819. this.comment = options.comment;
  1820. this.unixPermissions = options.unixPermissions;
  1821. this.dosPermissions = options.dosPermissions;
  1822. this._data = data;
  1823. this.options = options;
  1824. /*
  1825. * This object contains initial values for dir and date.
  1826. * With them, we can check if the user changed the deprecated metadata in
  1827. * `ZipObject#options` or not.
  1828. */
  1829. this._initialMetadata = {
  1830. dir : options.dir,
  1831. date : options.date
  1832. };
  1833. };
  1834. ZipObject.prototype = {
  1835. /**
  1836. * Return the content as UTF8 string.
  1837. * @return {string} the UTF8 string.
  1838. */
  1839. asText: function() {
  1840. return dataToString.call(this, true);
  1841. },
  1842. /**
  1843. * Returns the binary content.
  1844. * @return {string} the content as binary.
  1845. */
  1846. asBinary: function() {
  1847. return dataToString.call(this, false);
  1848. },
  1849. /**
  1850. * Returns the content as a nodejs Buffer.
  1851. * @return {Buffer} the content as a Buffer.
  1852. */
  1853. asNodeBuffer: function() {
  1854. var result = getBinaryData(this);
  1855. return utils.transformTo("nodebuffer", result);
  1856. },
  1857. /**
  1858. * Returns the content as an Uint8Array.
  1859. * @return {Uint8Array} the content as an Uint8Array.
  1860. */
  1861. asUint8Array: function() {
  1862. var result = getBinaryData(this);
  1863. return utils.transformTo("uint8array", result);
  1864. },
  1865. /**
  1866. * Returns the content as an ArrayBuffer.
  1867. * @return {ArrayBuffer} the content as an ArrayBufer.
  1868. */
  1869. asArrayBuffer: function() {
  1870. return this.asUint8Array().buffer;
  1871. }
  1872. };
  1873. /**
  1874. * Transform an integer into a string in hexadecimal.
  1875. * @private
  1876. * @param {number} dec the number to convert.
  1877. * @param {number} bytes the number of bytes to generate.
  1878. * @returns {string} the result.
  1879. */
  1880. var decToHex = function(dec, bytes) {
  1881. var hex = "",
  1882. i;
  1883. for (i = 0; i < bytes; i++) {
  1884. hex += String.fromCharCode(dec & 0xff);
  1885. dec = dec >>> 8;
  1886. }
  1887. return hex;
  1888. };
  1889. /**
  1890. * Transforms the (incomplete) options from the user into the complete
  1891. * set of options to create a file.
  1892. * @private
  1893. * @param {Object} o the options from the user.
  1894. * @return {Object} the complete set of options.
  1895. */
  1896. var prepareFileAttrs = function(o) {
  1897. o = o || {};
  1898. if (o.base64 === true && (o.binary === null || o.binary === undefined)) {
  1899. o.binary = true;
  1900. }
  1901. o = utils.extend(o, defaults);
  1902. o.date = o.date || new Date();
  1903. if (o.compression !== null) o.compression = o.compression.toUpperCase();
  1904. return o;
  1905. };
  1906. /**
  1907. * Add a file in the current folder.
  1908. * @private
  1909. * @param {string} name the name of the file
  1910. * @param {String|ArrayBuffer|Uint8Array|Buffer} data the data of the file
  1911. * @param {Object} o the options of the file
  1912. * @return {Object} the new file.
  1913. */
  1914. var fileAdd = function(name, data, o) {
  1915. // be sure sub folders exist
  1916. var dataType = utils.getTypeOf(data),
  1917. parent;
  1918. o = prepareFileAttrs(o);
  1919. if (typeof o.unixPermissions === "string") {
  1920. o.unixPermissions = parseInt(o.unixPermissions, 8);
  1921. }
  1922. // UNX_IFDIR 0040000 see zipinfo.c
  1923. if (o.unixPermissions && (o.unixPermissions & 0x4000)) {
  1924. o.dir = true;
  1925. }
  1926. // Bit 4 Directory
  1927. if (o.dosPermissions && (o.dosPermissions & 0x0010)) {
  1928. o.dir = true;
  1929. }
  1930. if (o.dir) {
  1931. name = forceTrailingSlash(name);
  1932. }
  1933. if (o.createFolders && (parent = parentFolder(name))) {
  1934. folderAdd.call(this, parent, true);
  1935. }
  1936. if (o.dir || data === null || typeof data === "undefined") {
  1937. o.base64 = false;
  1938. o.binary = false;
  1939. data = null;
  1940. dataType = null;
  1941. }
  1942. else if (dataType === "string") {
  1943. if (o.binary && !o.base64) {
  1944. // optimizedBinaryString == true means that the file has already been filtered with a 0xFF mask
  1945. if (o.optimizedBinaryString !== true) {
  1946. // this is a string, not in a base64 format.
  1947. // Be sure that this is a correct "binary string"
  1948. data = utils.string2binary(data);
  1949. }
  1950. }
  1951. }
  1952. else { // arraybuffer, uint8array, ...
  1953. o.base64 = false;
  1954. o.binary = true;
  1955. if (!dataType && !(data instanceof CompressedObject)) {
  1956. throw new Error("The data of '" + name + "' is in an unsupported format !");
  1957. }
  1958. // special case : it's way easier to work with Uint8Array than with ArrayBuffer
  1959. if (dataType === "arraybuffer") {
  1960. data = utils.transformTo("uint8array", data);
  1961. }
  1962. }
  1963. var object = new ZipObject(name, data, o);
  1964. this.files[name] = object;
  1965. return object;
  1966. };
  1967. /**
  1968. * Find the parent folder of the path.
  1969. * @private
  1970. * @param {string} path the path to use
  1971. * @return {string} the parent folder, or ""
  1972. */
  1973. var parentFolder = function (path) {
  1974. if (path.slice(-1) == '/') {
  1975. path = path.substring(0, path.length - 1);
  1976. }
  1977. var lastSlash = path.lastIndexOf('/');
  1978. return (lastSlash > 0) ? path.substring(0, lastSlash) : "";
  1979. };
  1980. /**
  1981. * Returns the path with a slash at the end.
  1982. * @private
  1983. * @param {String} path the path to check.
  1984. * @return {String} the path with a trailing slash.
  1985. */
  1986. var forceTrailingSlash = function(path) {
  1987. // Check the name ends with a /
  1988. if (path.slice(-1) != "/") {
  1989. path += "/"; // IE doesn't like substr(-1)
  1990. }
  1991. return path;
  1992. };
  1993. /**
  1994. * Add a (sub) folder in the current folder.
  1995. * @private
  1996. * @param {string} name the folder's name
  1997. * @param {boolean=} [createFolders] If true, automatically create sub
  1998. * folders. Defaults to false.
  1999. * @return {Object} the new folder.
  2000. */
  2001. var folderAdd = function(name, createFolders) {
  2002. createFolders = (typeof createFolders !== 'undefined') ? createFolders : false;
  2003. name = forceTrailingSlash(name);
  2004. // Does this folder already exist?
  2005. if (!this.files[name]) {
  2006. fileAdd.call(this, name, null, {
  2007. dir: true,
  2008. createFolders: createFolders
  2009. });
  2010. }
  2011. return this.files[name];
  2012. };
  2013. /**
  2014. * Generate a JSZip.CompressedObject for a given zipOject.
  2015. * @param {ZipObject} file the object to read.
  2016. * @param {JSZip.compression} compression the compression to use.
  2017. * @param {Object} compressionOptions the options to use when compressing.
  2018. * @return {JSZip.CompressedObject} the compressed result.
  2019. */
  2020. var generateCompressedObjectFrom = function(file, compression, compressionOptions) {
  2021. var result = new CompressedObject(),
  2022. content;
  2023. // the data has not been decompressed, we might reuse things !
  2024. if (file._data instanceof CompressedObject) {
  2025. result.uncompressedSize = file._data.uncompressedSize;
  2026. result.crc32 = file._data.crc32;
  2027. if (result.uncompressedSize === 0 || file.dir) {
  2028. compression = compressions['STORE'];
  2029. result.compressedContent = "";
  2030. result.crc32 = 0;
  2031. }
  2032. else if (file._data.compressionMethod === compression.magic) {
  2033. result.compressedContent = file._data.getCompressedContent();
  2034. }
  2035. else {
  2036. content = file._data.getContent();
  2037. // need to decompress / recompress
  2038. result.compressedContent = compression.compress(utils.transformTo(compression.compressInputType, content), compressionOptions);
  2039. }
  2040. }
  2041. else {
  2042. // have uncompressed data
  2043. content = getBinaryData(file);
  2044. if (!content || content.length === 0 || file.dir) {
  2045. compression = compressions['STORE'];
  2046. content = "";
  2047. }
  2048. result.uncompressedSize = content.length;
  2049. result.crc32 = crc32(content);
  2050. result.compressedContent = compression.compress(utils.transformTo(compression.compressInputType, content), compressionOptions);
  2051. }
  2052. result.compressedSize = result.compressedContent.length;
  2053. result.compressionMethod = compression.magic;
  2054. return result;
  2055. };
  2056. /**
  2057. * Generate the UNIX part of the external file attributes.
  2058. * @param {Object} unixPermissions the unix permissions or null.
  2059. * @param {Boolean} isDir true if the entry is a directory, false otherwise.
  2060. * @return {Number} a 32 bit integer.
  2061. *
  2062. * adapted from http://unix.stackexchange.com/questions/14705/the-zip-formats-external-file-attribute :
  2063. *
  2064. * TTTTsstrwxrwxrwx0000000000ADVSHR
  2065. * ^^^^____________________________ file type, see zipinfo.c (UNX_*)
  2066. * ^^^_________________________ setuid, setgid, sticky
  2067. * ^^^^^^^^^________________ permissions
  2068. * ^^^^^^^^^^______ not used ?
  2069. * ^^^^^^ DOS attribute bits : Archive, Directory, Volume label, System file, Hidden, Read only
  2070. */
  2071. var generateUnixExternalFileAttr = function (unixPermissions, isDir) {
  2072. var result = unixPermissions;
  2073. if (!unixPermissions) {
  2074. // I can't use octal values in strict mode, hence the hexa.
  2075. // 040775 => 0x41fd
  2076. // 0100664 => 0x81b4
  2077. result = isDir ? 0x41fd : 0x81b4;
  2078. }
  2079. return (result & 0xFFFF) << 16;
  2080. };
  2081. /**
  2082. * Generate the DOS part of the external file attributes.
  2083. * @param {Object} dosPermissions the dos permissions or null.
  2084. * @param {Boolean} isDir true if the entry is a directory, false otherwise.
  2085. * @return {Number} a 32 bit integer.
  2086. *
  2087. * Bit 0 Read-Only
  2088. * Bit 1 Hidden
  2089. * Bit 2 System
  2090. * Bit 3 Volume Label
  2091. * Bit 4 Directory
  2092. * Bit 5 Archive
  2093. */
  2094. var generateDosExternalFileAttr = function (dosPermissions, isDir) {
  2095. // the dir flag is already set for compatibility
  2096. return (dosPermissions || 0) & 0x3F;
  2097. };
  2098. /**
  2099. * Generate the various parts used in the construction of the final zip file.
  2100. * @param {string} name the file name.
  2101. * @param {ZipObject} file the file content.
  2102. * @param {JSZip.CompressedObject} compressedObject the compressed object.
  2103. * @param {number} offset the current offset from the start of the zip file.
  2104. * @param {String} platform let's pretend we are this platform (change platform dependents fields)
  2105. * @param {Function} encodeFileName the function to encode the file name / comment.
  2106. * @return {object} the zip parts.
  2107. */
  2108. var generateZipParts = function(name, file, compressedObject, offset, platform, encodeFileName) {
  2109. var data = compressedObject.compressedContent,
  2110. useCustomEncoding = encodeFileName !== utf8.utf8encode,
  2111. encodedFileName = utils.transformTo("string", encodeFileName(file.name)),
  2112. utfEncodedFileName = utils.transformTo("string", utf8.utf8encode(file.name)),
  2113. comment = file.comment || "",
  2114. encodedComment = utils.transformTo("string", encodeFileName(comment)),
  2115. utfEncodedComment = utils.transformTo("string", utf8.utf8encode(comment)),
  2116. useUTF8ForFileName = utfEncodedFileName.length !== file.name.length,
  2117. useUTF8ForComment = utfEncodedComment.length !== comment.length,
  2118. o = file.options,
  2119. dosTime,
  2120. dosDate,
  2121. extraFields = "",
  2122. unicodePathExtraField = "",
  2123. unicodeCommentExtraField = "",
  2124. dir, date;
  2125. // handle the deprecated options.dir
  2126. if (file._initialMetadata.dir !== file.dir) {
  2127. dir = file.dir;
  2128. } else {
  2129. dir = o.dir;
  2130. }
  2131. // handle the deprecated options.date
  2132. if(file._initialMetadata.date !== file.date) {
  2133. date = file.date;
  2134. } else {
  2135. date = o.date;
  2136. }
  2137. var extFileAttr = 0;
  2138. var versionMadeBy = 0;
  2139. if (dir) {
  2140. // dos or unix, we set the dos dir flag
  2141. extFileAttr |= 0x00010;
  2142. }
  2143. if(platform === "UNIX") {
  2144. versionMadeBy = 0x031E; // UNIX, version 3.0
  2145. extFileAttr |= generateUnixExternalFileAttr(file.unixPermissions, dir);
  2146. } else { // DOS or other, fallback to DOS
  2147. versionMadeBy = 0x0014; // DOS, version 2.0
  2148. extFileAttr |= generateDosExternalFileAttr(file.dosPermissions, dir);
  2149. }
  2150. // date
  2151. // @see http://www.delorie.com/djgpp/doc/rbinter/it/52/13.html
  2152. // @see http://www.delorie.com/djgpp/doc/rbinter/it/65/16.html
  2153. // @see http://www.delorie.com/djgpp/doc/rbinter/it/66/16.html
  2154. dosTime = date.getHours();
  2155. dosTime = dosTime << 6;
  2156. dosTime = dosTime | date.getMinutes();
  2157. dosTime = dosTime << 5;
  2158. dosTime = dosTime | date.getSeconds() / 2;
  2159. dosDate = date.getFullYear() - 1980;
  2160. dosDate = dosDate << 4;
  2161. dosDate = dosDate | (date.getMonth() + 1);
  2162. dosDate = dosDate << 5;
  2163. dosDate = dosDate | date.getDate();
  2164. if (useUTF8ForFileName) {
  2165. // set the unicode path extra field. unzip needs at least one extra
  2166. // field to correctly handle unicode path, so using the path is as good
  2167. // as any other information. This could improve the situation with
  2168. // other archive managers too.
  2169. // This field is usually used without the utf8 flag, with a non
  2170. // unicode path in the header (winrar, winzip). This helps (a bit)
  2171. // with the messy Windows' default compressed folders feature but
  2172. // breaks on p7zip which doesn't seek the unicode path extra field.
  2173. // So for now, UTF-8 everywhere !
  2174. unicodePathExtraField =
  2175. // Version
  2176. decToHex(1, 1) +
  2177. // NameCRC32
  2178. decToHex(crc32(encodedFileName), 4) +
  2179. // UnicodeName
  2180. utfEncodedFileName;
  2181. extraFields +=
  2182. // Info-ZIP Unicode Path Extra Field
  2183. "\x75\x70" +
  2184. // size
  2185. decToHex(unicodePathExtraField.length, 2) +
  2186. // content
  2187. unicodePathExtraField;
  2188. }
  2189. if(useUTF8ForComment) {
  2190. unicodeCommentExtraField =
  2191. // Version
  2192. decToHex(1, 1) +
  2193. // CommentCRC32
  2194. decToHex(this.crc32(encodedComment), 4) +
  2195. // UnicodeName
  2196. utfEncodedComment;
  2197. extraFields +=
  2198. // Info-ZIP Unicode Path Extra Field
  2199. "\x75\x63" +
  2200. // size
  2201. decToHex(unicodeCommentExtraField.length, 2) +
  2202. // content
  2203. unicodeCommentExtraField;
  2204. }
  2205. var header = "";
  2206. // version needed to extract
  2207. header += "\x0A\x00";
  2208. // general purpose bit flag
  2209. // set bit 11 if utf8
  2210. header += !useCustomEncoding && (useUTF8ForFileName || useUTF8ForComment) ? "\x00\x08" : "\x00\x00";
  2211. // compression method
  2212. header += compressedObject.compressionMethod;
  2213. // last mod file time
  2214. header += decToHex(dosTime, 2);
  2215. // last mod file date
  2216. header += decToHex(dosDate, 2);
  2217. // crc-32
  2218. header += decToHex(compressedObject.crc32, 4);
  2219. // compressed size
  2220. header += decToHex(compressedObject.compressedSize, 4);
  2221. // uncompressed size
  2222. header += decToHex(compressedObject.uncompressedSize, 4);
  2223. // file name length
  2224. header += decToHex(encodedFileName.length, 2);
  2225. // extra field length
  2226. header += decToHex(extraFields.length, 2);
  2227. var fileRecord = signature.LOCAL_FILE_HEADER + header + encodedFileName + extraFields;
  2228. var dirRecord = signature.CENTRAL_FILE_HEADER +
  2229. // version made by (00: DOS)
  2230. decToHex(versionMadeBy, 2) +
  2231. // file header (common to file and central directory)
  2232. header +
  2233. // file comment length
  2234. decToHex(encodedComment.length, 2) +
  2235. // disk number start
  2236. "\x00\x00" +
  2237. // internal file attributes TODO
  2238. "\x00\x00" +
  2239. // external file attributes
  2240. decToHex(extFileAttr, 4) +
  2241. // relative offset of local header
  2242. decToHex(offset, 4) +
  2243. // file name
  2244. encodedFileName +
  2245. // extra field
  2246. extraFields +
  2247. // file comment
  2248. encodedComment;
  2249. return {
  2250. fileRecord: fileRecord,
  2251. dirRecord: dirRecord,
  2252. compressedObject: compressedObject
  2253. };
  2254. };
  2255. // return the actual prototype of JSZip
  2256. var out = {
  2257. /**
  2258. * Read an existing zip and merge the data in the current JSZip object.
  2259. * The implementation is in jszip-load.js, don't forget to include it.
  2260. * @param {String|ArrayBuffer|Uint8Array|Buffer} stream The stream to load
  2261. * @param {Object} options Options for loading the stream.
  2262. * options.base64 : is the stream in base64 ? default : false
  2263. * @return {JSZip} the current JSZip object
  2264. */
  2265. load: function(stream, options) {
  2266. throw new Error("Load method is not defined. Is the file jszip-load.js included ?");
  2267. },
  2268. /**
  2269. * Filter nested files/folders with the specified function.
  2270. * @param {Function} search the predicate to use :
  2271. * function (relativePath, file) {...}
  2272. * It takes 2 arguments : the relative path and the file.
  2273. * @return {Array} An array of matching elements.
  2274. */
  2275. filter: function(search) {
  2276. var result = [],
  2277. filename, relativePath, file, fileClone;
  2278. for (filename in this.files) {
  2279. if (!this.files.hasOwnProperty(filename)) {
  2280. continue;
  2281. }
  2282. file = this.files[filename];
  2283. // return a new object, don't let the user mess with our internal objects :)
  2284. fileClone = new ZipObject(file.name, file._data, utils.extend(file.options));
  2285. relativePath = filename.slice(this.root.length, filename.length);
  2286. if (filename.slice(0, this.root.length) === this.root && // the file is in the current root
  2287. search(relativePath, fileClone)) { // and the file matches the function
  2288. result.push(fileClone);
  2289. }
  2290. }
  2291. return result;
  2292. },
  2293. /**
  2294. * Add a file to the zip file, or search a file.
  2295. * @param {string|RegExp} name The name of the file to add (if data is defined),
  2296. * the name of the file to find (if no data) or a regex to match files.
  2297. * @param {String|ArrayBuffer|Uint8Array|Buffer} data The file data, either raw or base64 encoded
  2298. * @param {Object} o File options
  2299. * @return {JSZip|Object|Array} this JSZip object (when adding a file),
  2300. * a file (when searching by string) or an array of files (when searching by regex).
  2301. */
  2302. file: function(name, data, o) {
  2303. if (arguments.length === 1) {
  2304. if (utils.isRegExp(name)) {
  2305. var regexp = name;
  2306. return this.filter(function(relativePath, file) {
  2307. return !file.dir && regexp.test(relativePath);
  2308. });
  2309. }
  2310. else { // text
  2311. return this.filter(function(relativePath, file) {
  2312. return !file.dir && relativePath === name;
  2313. })[0] || null;
  2314. }
  2315. }
  2316. else { // more than one argument : we have data !
  2317. name = this.root + name;
  2318. fileAdd.call(this, name, data, o);
  2319. }
  2320. return this;
  2321. },
  2322. /**
  2323. * Add a directory to the zip file, or search.
  2324. * @param {String|RegExp} arg The name of the directory to add, or a regex to search folders.
  2325. * @return {JSZip} an object with the new directory as the root, or an array containing matching folders.
  2326. */
  2327. folder: function(arg) {
  2328. if (!arg) {
  2329. return this;
  2330. }
  2331. if (utils.isRegExp(arg)) {
  2332. return this.filter(function(relativePath, file) {
  2333. return file.dir && arg.test(relativePath);
  2334. });
  2335. }
  2336. // else, name is a new folder
  2337. var name = this.root + arg;
  2338. var newFolder = folderAdd.call(this, name);
  2339. // Allow chaining by returning a new object with this folder as the root
  2340. var ret = this.clone();
  2341. ret.root = newFolder.name;
  2342. return ret;
  2343. },
  2344. /**
  2345. * Delete a file, or a directory and all sub-files, from the zip
  2346. * @param {string} name the name of the file to delete
  2347. * @return {JSZip} this JSZip object
  2348. */
  2349. remove: function(name) {
  2350. name = this.root + name;
  2351. var file = this.files[name];
  2352. if (!file) {
  2353. // Look for any folders
  2354. if (name.slice(-1) != "/") {
  2355. name += "/";
  2356. }
  2357. file = this.files[name];
  2358. }
  2359. if (file && !file.dir) {
  2360. // file
  2361. delete this.files[name];
  2362. } else {
  2363. // maybe a folder, delete recursively
  2364. var kids = this.filter(function(relativePath, file) {
  2365. return file.name.slice(0, name.length) === name;
  2366. });
  2367. for (var i = 0; i < kids.length; i++) {
  2368. delete this.files[kids[i].name];
  2369. }
  2370. }
  2371. return this;
  2372. },
  2373. /**
  2374. * Generate the complete zip file
  2375. * @param {Object} options the options to generate the zip file :
  2376. * - base64, (deprecated, use type instead) true to generate base64.
  2377. * - compression, "STORE" by default.
  2378. * - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob.
  2379. * @return {String|Uint8Array|ArrayBuffer|Buffer|Blob} the zip file
  2380. */
  2381. generate: function(options) {
  2382. options = utils.extend(options || {}, {
  2383. base64: true,
  2384. compression: "STORE",
  2385. compressionOptions : null,
  2386. type: "base64",
  2387. platform: "DOS",
  2388. comment: null,
  2389. mimeType: 'application/zip',
  2390. encodeFileName: utf8.utf8encode
  2391. });
  2392. utils.checkSupport(options.type);
  2393. // accept nodejs `process.platform`
  2394. if(
  2395. options.platform === 'darwin' ||
  2396. options.platform === 'freebsd' ||
  2397. options.platform === 'linux' ||
  2398. options.platform === 'sunos'
  2399. ) {
  2400. options.platform = "UNIX";
  2401. }
  2402. if (options.platform === 'win32') {
  2403. options.platform = "DOS";
  2404. }
  2405. var zipData = [],
  2406. localDirLength = 0,
  2407. centralDirLength = 0,
  2408. writer, i,
  2409. encodedComment = utils.transformTo("string", options.encodeFileName(options.comment || this.comment || ""));
  2410. // first, generate all the zip parts.
  2411. for (var name in this.files) {
  2412. if (!this.files.hasOwnProperty(name)) {
  2413. continue;
  2414. }
  2415. var file = this.files[name];
  2416. var compressionName = file.options.compression || options.compression.toUpperCase();
  2417. var compression = compressions[compressionName];
  2418. if (!compression) {
  2419. throw new Error(compressionName + " is not a valid compression method !");
  2420. }
  2421. var compressionOptions = file.options.compressionOptions || options.compressionOptions || {};
  2422. var compressedObject = generateCompressedObjectFrom.call(this, file, compression, compressionOptions);
  2423. var zipPart = generateZipParts.call(this, name, file, compressedObject, localDirLength, options.platform, options.encodeFileName);
  2424. localDirLength += zipPart.fileRecord.length + compressedObject.compressedSize;
  2425. centralDirLength += zipPart.dirRecord.length;
  2426. zipData.push(zipPart);
  2427. }
  2428. var dirEnd = "";
  2429. // end of central dir signature
  2430. dirEnd = signature.CENTRAL_DIRECTORY_END +
  2431. // number of this disk
  2432. "\x00\x00" +
  2433. // number of the disk with the start of the central directory
  2434. "\x00\x00" +
  2435. // total number of entries in the central directory on this disk
  2436. decToHex(zipData.length, 2) +
  2437. // total number of entries in the central directory
  2438. decToHex(zipData.length, 2) +
  2439. // size of the central directory 4 bytes
  2440. decToHex(centralDirLength, 4) +
  2441. // offset of start of central directory with respect to the starting disk number
  2442. decToHex(localDirLength, 4) +
  2443. // .ZIP file comment length
  2444. decToHex(encodedComment.length, 2) +
  2445. // .ZIP file comment
  2446. encodedComment;
  2447. // we have all the parts (and the total length)
  2448. // time to create a writer !
  2449. var typeName = options.type.toLowerCase();
  2450. if(typeName==="uint8array"||typeName==="arraybuffer"||typeName==="blob"||typeName==="nodebuffer") {
  2451. writer = new Uint8ArrayWriter(localDirLength + centralDirLength + dirEnd.length);
  2452. }else{
  2453. writer = new StringWriter(localDirLength + centralDirLength + dirEnd.length);
  2454. }
  2455. for (i = 0; i < zipData.length; i++) {
  2456. writer.append(zipData[i].fileRecord);
  2457. writer.append(zipData[i].compressedObject.compressedContent);
  2458. }
  2459. for (i = 0; i < zipData.length; i++) {
  2460. writer.append(zipData[i].dirRecord);
  2461. }
  2462. writer.append(dirEnd);
  2463. var zip = writer.finalize();
  2464. switch(options.type.toLowerCase()) {
  2465. // case "zip is an Uint8Array"
  2466. case "uint8array" :
  2467. case "arraybuffer" :
  2468. case "nodebuffer" :
  2469. return utils.transformTo(options.type.toLowerCase(), zip);
  2470. case "blob" :
  2471. return utils.arrayBuffer2Blob(utils.transformTo("arraybuffer", zip), options.mimeType);
  2472. // case "zip is a string"
  2473. case "base64" :
  2474. return (options.base64) ? base64.encode(zip) : zip;
  2475. default : // case "string" :
  2476. return zip;
  2477. }
  2478. },
  2479. /**
  2480. * @deprecated
  2481. * This method will be removed in a future version without replacement.
  2482. */
  2483. crc32: function (input, crc) {
  2484. return crc32(input, crc);
  2485. },
  2486. /**
  2487. * @deprecated
  2488. * This method will be removed in a future version without replacement.
  2489. */
  2490. utf8encode: function (string) {
  2491. return utils.transformTo("string", utf8.utf8encode(string));
  2492. },
  2493. /**
  2494. * @deprecated
  2495. * This method will be removed in a future version without replacement.
  2496. */
  2497. utf8decode: function (input) {
  2498. return utf8.utf8decode(input);
  2499. }
  2500. };
  2501. module.exports = out;
  2502. },{"./base64":6,"./compressedObject":7,"./compressions":8,"./crc32":9,"./defaults":11,"./nodeBuffer":16,"./signature":19,"./stringWriter":21,"./support":22,"./uint8ArrayWriter":24,"./utf8":25,"./utils":26}],19:[function(_dereq_,module,exports){
  2503. 'use strict';
  2504. exports.LOCAL_FILE_HEADER = "PK\x03\x04";
  2505. exports.CENTRAL_FILE_HEADER = "PK\x01\x02";
  2506. exports.CENTRAL_DIRECTORY_END = "PK\x05\x06";
  2507. exports.ZIP64_CENTRAL_DIRECTORY_LOCATOR = "PK\x06\x07";
  2508. exports.ZIP64_CENTRAL_DIRECTORY_END = "PK\x06\x06";
  2509. exports.DATA_DESCRIPTOR = "PK\x07\x08";
  2510. },{}],20:[function(_dereq_,module,exports){
  2511. 'use strict';
  2512. var DataReader = _dereq_('./dataReader');
  2513. var utils = _dereq_('./utils');
  2514. function StringReader(data, optimizedBinaryString) {
  2515. this.data = data;
  2516. if (!optimizedBinaryString) {
  2517. this.data = utils.string2binary(this.data);
  2518. }
  2519. this.length = this.data.length;
  2520. this.index = 0;
  2521. this.zero = 0;
  2522. }
  2523. StringReader.prototype = new DataReader();
  2524. /**
  2525. * @see DataReader.byteAt
  2526. */
  2527. StringReader.prototype.byteAt = function(i) {
  2528. return this.data.charCodeAt(this.zero + i);
  2529. };
  2530. /**
  2531. * @see DataReader.lastIndexOfSignature
  2532. */
  2533. StringReader.prototype.lastIndexOfSignature = function(sig) {
  2534. return this.data.lastIndexOf(sig) - this.zero;
  2535. };
  2536. /**
  2537. * @see DataReader.readData
  2538. */
  2539. StringReader.prototype.readData = function(size) {
  2540. this.checkOffset(size);
  2541. // this will work because the constructor applied the "& 0xff" mask.
  2542. var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
  2543. this.index += size;
  2544. return result;
  2545. };
  2546. module.exports = StringReader;
  2547. },{"./dataReader":10,"./utils":26}],21:[function(_dereq_,module,exports){
  2548. 'use strict';
  2549. var utils = _dereq_('./utils');
  2550. /**
  2551. * An object to write any content to a string.
  2552. * @constructor
  2553. */
  2554. var StringWriter = function() {
  2555. this.data = [];
  2556. };
  2557. StringWriter.prototype = {
  2558. /**
  2559. * Append any content to the current string.
  2560. * @param {Object} input the content to add.
  2561. */
  2562. append: function(input) {
  2563. input = utils.transformTo("string", input);
  2564. this.data.push(input);
  2565. },
  2566. /**
  2567. * Finalize the construction an return the result.
  2568. * @return {string} the generated string.
  2569. */
  2570. finalize: function() {
  2571. return this.data.join("");
  2572. }
  2573. };
  2574. module.exports = StringWriter;
  2575. },{"./utils":26}],22:[function(_dereq_,module,exports){
  2576. (function (Buffer){
  2577. 'use strict';
  2578. exports.base64 = true;
  2579. exports.array = true;
  2580. exports.string = true;
  2581. exports.arraybuffer = typeof ArrayBuffer !== "undefined" && typeof Uint8Array !== "undefined";
  2582. // contains true if JSZip can read/generate nodejs Buffer, false otherwise.
  2583. // Browserify will provide a Buffer implementation for browsers, which is
  2584. // an augmented Uint8Array (i.e., can be used as either Buffer or U8).
  2585. exports.nodebuffer = typeof Buffer !== "undefined";
  2586. // contains true if JSZip can read/generate Uint8Array, false otherwise.
  2587. exports.uint8array = typeof Uint8Array !== "undefined";
  2588. if (typeof ArrayBuffer === "undefined") {
  2589. exports.blob = false;
  2590. }
  2591. else {
  2592. var buffer = new ArrayBuffer(0);
  2593. try {
  2594. exports.blob = new Blob([buffer], {
  2595. type: "application/zip"
  2596. }).size === 0;
  2597. }
  2598. catch (e) {
  2599. try {
  2600. var Builder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
  2601. var builder = new Builder();
  2602. builder.append(buffer);
  2603. exports.blob = builder.getBlob('application/zip').size === 0;
  2604. }
  2605. catch (e) {
  2606. exports.blob = false;
  2607. }
  2608. }
  2609. }
  2610. }).call(this,_dereq_("buffer").Buffer)
  2611. },{"buffer":1}],23:[function(_dereq_,module,exports){
  2612. 'use strict';
  2613. var ArrayReader = _dereq_('./arrayReader');
  2614. function Uint8ArrayReader(data) {
  2615. if (data) {
  2616. this.data = data;
  2617. this.length = this.data.length;
  2618. this.index = 0;
  2619. this.zero = 0;
  2620. }
  2621. }
  2622. Uint8ArrayReader.prototype = new ArrayReader();
  2623. /**
  2624. * @see DataReader.readData
  2625. */
  2626. Uint8ArrayReader.prototype.readData = function(size) {
  2627. this.checkOffset(size);
  2628. if(size === 0) {
  2629. // in IE10, when using subarray(idx, idx), we get the array [0x00] instead of [].
  2630. return new Uint8Array(0);
  2631. }
  2632. var result = this.data.subarray(this.zero + this.index, this.zero + this.index + size);
  2633. this.index += size;
  2634. return result;
  2635. };
  2636. module.exports = Uint8ArrayReader;
  2637. },{"./arrayReader":5}],24:[function(_dereq_,module,exports){
  2638. 'use strict';
  2639. var utils = _dereq_('./utils');
  2640. /**
  2641. * An object to write any content to an Uint8Array.
  2642. * @constructor
  2643. * @param {number} length The length of the array.
  2644. */
  2645. var Uint8ArrayWriter = function(length) {
  2646. this.data = new Uint8Array(length);
  2647. this.index = 0;
  2648. };
  2649. Uint8ArrayWriter.prototype = {
  2650. /**
  2651. * Append any content to the current array.
  2652. * @param {Object} input the content to add.
  2653. */
  2654. append: function(input) {
  2655. if (input.length !== 0) {
  2656. // with an empty Uint8Array, Opera fails with a "Offset larger than array size"
  2657. input = utils.transformTo("uint8array", input);
  2658. this.data.set(input, this.index);
  2659. this.index += input.length;
  2660. }
  2661. },
  2662. /**
  2663. * Finalize the construction an return the result.
  2664. * @return {Uint8Array} the generated array.
  2665. */
  2666. finalize: function() {
  2667. return this.data;
  2668. }
  2669. };
  2670. module.exports = Uint8ArrayWriter;
  2671. },{"./utils":26}],25:[function(_dereq_,module,exports){
  2672. 'use strict';
  2673. var utils = _dereq_('./utils');
  2674. var support = _dereq_('./support');
  2675. var nodeBuffer = _dereq_('./nodeBuffer');
  2676. /**
  2677. * The following functions come from pako, from pako/lib/utils/strings
  2678. * released under the MIT license, see pako https://github.com/nodeca/pako/
  2679. */
  2680. // Table with utf8 lengths (calculated by first byte of sequence)
  2681. // Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
  2682. // because max possible codepoint is 0x10ffff
  2683. var _utf8len = new Array(256);
  2684. for (var i=0; i<256; i++) {
  2685. _utf8len[i] = (i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1);
  2686. }
  2687. _utf8len[254]=_utf8len[254]=1; // Invalid sequence start
  2688. // convert string to array (typed, when possible)
  2689. var string2buf = function (str) {
  2690. var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;
  2691. // count binary size
  2692. for (m_pos = 0; m_pos < str_len; m_pos++) {
  2693. c = str.charCodeAt(m_pos);
  2694. if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {
  2695. c2 = str.charCodeAt(m_pos+1);
  2696. if ((c2 & 0xfc00) === 0xdc00) {
  2697. c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
  2698. m_pos++;
  2699. }
  2700. }
  2701. buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
  2702. }
  2703. // allocate buffer
  2704. if (support.uint8array) {
  2705. buf = new Uint8Array(buf_len);
  2706. } else {
  2707. buf = new Array(buf_len);
  2708. }
  2709. // convert
  2710. for (i=0, m_pos = 0; i < buf_len; m_pos++) {
  2711. c = str.charCodeAt(m_pos);
  2712. if ((c & 0xfc00) === 0xd800 && (m_pos+1 < str_len)) {
  2713. c2 = str.charCodeAt(m_pos+1);
  2714. if ((c2 & 0xfc00) === 0xdc00) {
  2715. c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
  2716. m_pos++;
  2717. }
  2718. }
  2719. if (c < 0x80) {
  2720. /* one byte */
  2721. buf[i++] = c;
  2722. } else if (c < 0x800) {
  2723. /* two bytes */
  2724. buf[i++] = 0xC0 | (c >>> 6);
  2725. buf[i++] = 0x80 | (c & 0x3f);
  2726. } else if (c < 0x10000) {
  2727. /* three bytes */
  2728. buf[i++] = 0xE0 | (c >>> 12);
  2729. buf[i++] = 0x80 | (c >>> 6 & 0x3f);
  2730. buf[i++] = 0x80 | (c & 0x3f);
  2731. } else {
  2732. /* four bytes */
  2733. buf[i++] = 0xf0 | (c >>> 18);
  2734. buf[i++] = 0x80 | (c >>> 12 & 0x3f);
  2735. buf[i++] = 0x80 | (c >>> 6 & 0x3f);
  2736. buf[i++] = 0x80 | (c & 0x3f);
  2737. }
  2738. }
  2739. return buf;
  2740. };
  2741. // Calculate max possible position in utf8 buffer,
  2742. // that will not break sequence. If that's not possible
  2743. // - (very small limits) return max size as is.
  2744. //
  2745. // buf[] - utf8 bytes array
  2746. // max - length limit (mandatory);
  2747. var utf8border = function(buf, max) {
  2748. var pos;
  2749. max = max || buf.length;
  2750. if (max > buf.length) { max = buf.length; }
  2751. // go back from last position, until start of sequence found
  2752. pos = max-1;
  2753. while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }
  2754. // Fuckup - very small and broken sequence,
  2755. // return max, because we should return something anyway.
  2756. if (pos < 0) { return max; }
  2757. // If we came to start of buffer - that means vuffer is too small,
  2758. // return max too.
  2759. if (pos === 0) { return max; }
  2760. return (pos + _utf8len[buf[pos]] > max) ? pos : max;
  2761. };
  2762. // convert array to string
  2763. var buf2string = function (buf) {
  2764. var str, i, out, c, c_len;
  2765. var len = buf.length;
  2766. // Reserve max possible length (2 words per char)
  2767. // NB: by unknown reasons, Array is significantly faster for
  2768. // String.fromCharCode.apply than Uint16Array.
  2769. var utf16buf = new Array(len*2);
  2770. for (out=0, i=0; i<len;) {
  2771. c = buf[i++];
  2772. // quick process ascii
  2773. if (c < 0x80) { utf16buf[out++] = c; continue; }
  2774. c_len = _utf8len[c];
  2775. // skip 5 & 6 byte codes
  2776. if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len-1; continue; }
  2777. // apply mask on first byte
  2778. c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
  2779. // join the rest
  2780. while (c_len > 1 && i < len) {
  2781. c = (c << 6) | (buf[i++] & 0x3f);
  2782. c_len--;
  2783. }
  2784. // terminated by end of string?
  2785. if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }
  2786. if (c < 0x10000) {
  2787. utf16buf[out++] = c;
  2788. } else {
  2789. c -= 0x10000;
  2790. utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);
  2791. utf16buf[out++] = 0xdc00 | (c & 0x3ff);
  2792. }
  2793. }
  2794. // shrinkBuf(utf16buf, out)
  2795. if (utf16buf.length !== out) {
  2796. if(utf16buf.subarray) {
  2797. utf16buf = utf16buf.subarray(0, out);
  2798. } else {
  2799. utf16buf.length = out;
  2800. }
  2801. }
  2802. // return String.fromCharCode.apply(null, utf16buf);
  2803. return utils.applyFromCharCode(utf16buf);
  2804. };
  2805. // That's all for the pako functions.
  2806. /**
  2807. * Transform a javascript string into an array (typed if possible) of bytes,
  2808. * UTF-8 encoded.
  2809. * @param {String} str the string to encode
  2810. * @return {Array|Uint8Array|Buffer} the UTF-8 encoded string.
  2811. */
  2812. exports.utf8encode = function utf8encode(str) {
  2813. if (support.nodebuffer) {
  2814. return nodeBuffer(str, "utf-8");
  2815. }
  2816. return string2buf(str);
  2817. };
  2818. /**
  2819. * Transform a bytes array (or a representation) representing an UTF-8 encoded
  2820. * string into a javascript string.
  2821. * @param {Array|Uint8Array|Buffer} buf the data de decode
  2822. * @return {String} the decoded string.
  2823. */
  2824. exports.utf8decode = function utf8decode(buf) {
  2825. if (support.nodebuffer) {
  2826. return utils.transformTo("nodebuffer", buf).toString("utf-8");
  2827. }
  2828. buf = utils.transformTo(support.uint8array ? "uint8array" : "array", buf);
  2829. // return buf2string(buf);
  2830. // Chrome prefers to work with "small" chunks of data
  2831. // for the method buf2string.
  2832. // Firefox and Chrome has their own shortcut, IE doesn't seem to really care.
  2833. var result = [], k = 0, len = buf.length, chunk = 65536;
  2834. while (k < len) {
  2835. var nextBoundary = utf8border(buf, Math.min(k + chunk, len));
  2836. if (support.uint8array) {
  2837. result.push(buf2string(buf.subarray(k, nextBoundary)));
  2838. } else {
  2839. result.push(buf2string(buf.slice(k, nextBoundary)));
  2840. }
  2841. k = nextBoundary;
  2842. }
  2843. return result.join("");
  2844. };
  2845. // vim: set shiftwidth=4 softtabstop=4:
  2846. },{"./nodeBuffer":16,"./support":22,"./utils":26}],26:[function(_dereq_,module,exports){
  2847. 'use strict';
  2848. var support = _dereq_('./support');
  2849. var compressions = _dereq_('./compressions');
  2850. var nodeBuffer = _dereq_('./nodeBuffer');
  2851. /**
  2852. * Convert a string to a "binary string" : a string containing only char codes between 0 and 255.
  2853. * @param {string} str the string to transform.
  2854. * @return {String} the binary string.
  2855. */
  2856. exports.string2binary = function(str) {
  2857. var result = "";
  2858. for (var i = 0; i < str.length; i++) {
  2859. result += String.fromCharCode(str.charCodeAt(i) & 0xff);
  2860. }
  2861. return result;
  2862. };
  2863. exports.arrayBuffer2Blob = function(buffer, mimeType) {
  2864. exports.checkSupport("blob");
  2865. mimeType = mimeType || 'application/zip';
  2866. try {
  2867. // Blob constructor
  2868. return new Blob([buffer], {
  2869. type: mimeType
  2870. });
  2871. }
  2872. catch (e) {
  2873. try {
  2874. // deprecated, browser only, old way
  2875. var Builder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
  2876. var builder = new Builder();
  2877. builder.append(buffer);
  2878. return builder.getBlob(mimeType);
  2879. }
  2880. catch (e) {
  2881. // well, fuck ?!
  2882. throw new Error("Bug : can't construct the Blob.");
  2883. }
  2884. }
  2885. };
  2886. /**
  2887. * The identity function.
  2888. * @param {Object} input the input.
  2889. * @return {Object} the same input.
  2890. */
  2891. function identity(input) {
  2892. return input;
  2893. }
  2894. /**
  2895. * Fill in an array with a string.
  2896. * @param {String} str the string to use.
  2897. * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to fill in (will be mutated).
  2898. * @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated array.
  2899. */
  2900. function stringToArrayLike(str, array) {
  2901. for (var i = 0; i < str.length; ++i) {
  2902. array[i] = str.charCodeAt(i) & 0xFF;
  2903. }
  2904. return array;
  2905. }
  2906. /**
  2907. * Transform an array-like object to a string.
  2908. * @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.
  2909. * @return {String} the result.
  2910. */
  2911. function arrayLikeToString(array) {
  2912. // Performances notes :
  2913. // --------------------
  2914. // String.fromCharCode.apply(null, array) is the fastest, see
  2915. // see http://jsperf.com/converting-a-uint8array-to-a-string/2
  2916. // but the stack is limited (and we can get huge arrays !).
  2917. //
  2918. // result += String.fromCharCode(array[i]); generate too many strings !
  2919. //
  2920. // This code is inspired by http://jsperf.com/arraybuffer-to-string-apply-performance/2
  2921. var chunk = 65536;
  2922. var result = [],
  2923. len = array.length,
  2924. type = exports.getTypeOf(array),
  2925. k = 0,
  2926. canUseApply = true;
  2927. try {
  2928. switch(type) {
  2929. case "uint8array":
  2930. String.fromCharCode.apply(null, new Uint8Array(0));
  2931. break;
  2932. case "nodebuffer":
  2933. String.fromCharCode.apply(null, nodeBuffer(0));
  2934. break;
  2935. }
  2936. } catch(e) {
  2937. canUseApply = false;
  2938. }
  2939. // no apply : slow and painful algorithm
  2940. // default browser on android 4.*
  2941. if (!canUseApply) {
  2942. var resultStr = "";
  2943. for(var i = 0; i < array.length;i++) {
  2944. resultStr += String.fromCharCode(array[i]);
  2945. }
  2946. return resultStr;
  2947. }
  2948. while (k < len && chunk > 1) {
  2949. try {
  2950. if (type === "array" || type === "nodebuffer") {
  2951. result.push(String.fromCharCode.apply(null, array.slice(k, Math.min(k + chunk, len))));
  2952. }
  2953. else {
  2954. result.push(String.fromCharCode.apply(null, array.subarray(k, Math.min(k + chunk, len))));
  2955. }
  2956. k += chunk;
  2957. }
  2958. catch (e) {
  2959. chunk = Math.floor(chunk / 2);
  2960. }
  2961. }
  2962. return result.join("");
  2963. }
  2964. exports.applyFromCharCode = arrayLikeToString;
  2965. /**
  2966. * Copy the data from an array-like to an other array-like.
  2967. * @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayFrom the origin array.
  2968. * @param {Array|ArrayBuffer|Uint8Array|Buffer} arrayTo the destination array which will be mutated.
  2969. * @return {Array|ArrayBuffer|Uint8Array|Buffer} the updated destination array.
  2970. */
  2971. function arrayLikeToArrayLike(arrayFrom, arrayTo) {
  2972. for (var i = 0; i < arrayFrom.length; i++) {
  2973. arrayTo[i] = arrayFrom[i];
  2974. }
  2975. return arrayTo;
  2976. }
  2977. // a matrix containing functions to transform everything into everything.
  2978. var transform = {};
  2979. // string to ?
  2980. transform["string"] = {
  2981. "string": identity,
  2982. "array": function(input) {
  2983. return stringToArrayLike(input, new Array(input.length));
  2984. },
  2985. "arraybuffer": function(input) {
  2986. return transform["string"]["uint8array"](input).buffer;
  2987. },
  2988. "uint8array": function(input) {
  2989. return stringToArrayLike(input, new Uint8Array(input.length));
  2990. },
  2991. "nodebuffer": function(input) {
  2992. return stringToArrayLike(input, nodeBuffer(input.length));
  2993. }
  2994. };
  2995. // array to ?
  2996. transform["array"] = {
  2997. "string": arrayLikeToString,
  2998. "array": identity,
  2999. "arraybuffer": function(input) {
  3000. return (new Uint8Array(input)).buffer;
  3001. },
  3002. "uint8array": function(input) {
  3003. return new Uint8Array(input);
  3004. },
  3005. "nodebuffer": function(input) {
  3006. return nodeBuffer(input);
  3007. }
  3008. };
  3009. // arraybuffer to ?
  3010. transform["arraybuffer"] = {
  3011. "string": function(input) {
  3012. return arrayLikeToString(new Uint8Array(input));
  3013. },
  3014. "array": function(input) {
  3015. return arrayLikeToArrayLike(new Uint8Array(input), new Array(input.byteLength));
  3016. },
  3017. "arraybuffer": identity,
  3018. "uint8array": function(input) {
  3019. return new Uint8Array(input);
  3020. },
  3021. "nodebuffer": function(input) {
  3022. return nodeBuffer(new Uint8Array(input));
  3023. }
  3024. };
  3025. // uint8array to ?
  3026. transform["uint8array"] = {
  3027. "string": arrayLikeToString,
  3028. "array": function(input) {
  3029. return arrayLikeToArrayLike(input, new Array(input.length));
  3030. },
  3031. "arraybuffer": function(input) {
  3032. return input.buffer;
  3033. },
  3034. "uint8array": identity,
  3035. "nodebuffer": function(input) {
  3036. return nodeBuffer(input);
  3037. }
  3038. };
  3039. // nodebuffer to ?
  3040. transform["nodebuffer"] = {
  3041. "string": arrayLikeToString,
  3042. "array": function(input) {
  3043. return arrayLikeToArrayLike(input, new Array(input.length));
  3044. },
  3045. "arraybuffer": function(input) {
  3046. return transform["nodebuffer"]["uint8array"](input).buffer;
  3047. },
  3048. "uint8array": function(input) {
  3049. return arrayLikeToArrayLike(input, new Uint8Array(input.length));
  3050. },
  3051. "nodebuffer": identity
  3052. };
  3053. /**
  3054. * Transform an input into any type.
  3055. * The supported output type are : string, array, uint8array, arraybuffer, nodebuffer.
  3056. * If no output type is specified, the unmodified input will be returned.
  3057. * @param {String} outputType the output type.
  3058. * @param {String|Array|ArrayBuffer|Uint8Array|Buffer} input the input to convert.
  3059. * @throws {Error} an Error if the browser doesn't support the requested output type.
  3060. */
  3061. exports.transformTo = function(outputType, input) {
  3062. if (!input) {
  3063. // undefined, null, etc
  3064. // an empty string won't harm.
  3065. input = "";
  3066. }
  3067. if (!outputType) {
  3068. return input;
  3069. }
  3070. exports.checkSupport(outputType);
  3071. var inputType = exports.getTypeOf(input);
  3072. var result = transform[inputType][outputType](input);
  3073. return result;
  3074. };
  3075. /**
  3076. * Return the type of the input.
  3077. * The type will be in a format valid for JSZip.utils.transformTo : string, array, uint8array, arraybuffer.
  3078. * @param {Object} input the input to identify.
  3079. * @return {String} the (lowercase) type of the input.
  3080. */
  3081. exports.getTypeOf = function(input) {
  3082. if (typeof input === "string") {
  3083. return "string";
  3084. }
  3085. if (Object.prototype.toString.call(input) === "[object Array]") {
  3086. return "array";
  3087. }
  3088. if (support.nodebuffer && nodeBuffer.test(input)) {
  3089. return "nodebuffer";
  3090. }
  3091. if (support.uint8array && input instanceof Uint8Array) {
  3092. return "uint8array";
  3093. }
  3094. if (support.arraybuffer && input instanceof ArrayBuffer) {
  3095. return "arraybuffer";
  3096. }
  3097. };
  3098. /**
  3099. * Throw an exception if the type is not supported.
  3100. * @param {String} type the type to check.
  3101. * @throws {Error} an Error if the browser doesn't support the requested type.
  3102. */
  3103. exports.checkSupport = function(type) {
  3104. var supported = support[type.toLowerCase()];
  3105. if (!supported) {
  3106. throw new Error(type + " is not supported by this browser");
  3107. }
  3108. };
  3109. exports.MAX_VALUE_16BITS = 65535;
  3110. exports.MAX_VALUE_32BITS = -1; // well, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" is parsed as -1
  3111. /**
  3112. * Prettify a string read as binary.
  3113. * @param {string} str the string to prettify.
  3114. * @return {string} a pretty string.
  3115. */
  3116. exports.pretty = function(str) {
  3117. var res = '',
  3118. code, i;
  3119. for (i = 0; i < (str || "").length; i++) {
  3120. code = str.charCodeAt(i);
  3121. res += '\\x' + (code < 16 ? "0" : "") + code.toString(16).toUpperCase();
  3122. }
  3123. return res;
  3124. };
  3125. /**
  3126. * Find a compression registered in JSZip.
  3127. * @param {string} compressionMethod the method magic to find.
  3128. * @return {Object|null} the JSZip compression object, null if none found.
  3129. */
  3130. exports.findCompression = function(compressionMethod) {
  3131. for (var method in compressions) {
  3132. if (!compressions.hasOwnProperty(method)) {
  3133. continue;
  3134. }
  3135. if (compressions[method].magic === compressionMethod) {
  3136. return compressions[method];
  3137. }
  3138. }
  3139. return null;
  3140. };
  3141. /**
  3142. * Cross-window, cross-Node-context regular expression detection
  3143. * @param {Object} object Anything
  3144. * @return {Boolean} true if the object is a regular expression,
  3145. * false otherwise
  3146. */
  3147. exports.isRegExp = function (object) {
  3148. return Object.prototype.toString.call(object) === "[object RegExp]";
  3149. };
  3150. /**
  3151. * Merge the objects passed as parameters into a new one.
  3152. * @private
  3153. * @param {...Object} var_args All objects to merge.
  3154. * @return {Object} a new object with the data of the others.
  3155. */
  3156. exports.extend = function() {
  3157. var result = {}, i, attr;
  3158. for (i = 0; i < arguments.length; i++) { // arguments is not enumerable in some browsers
  3159. for (attr in arguments[i]) {
  3160. if (arguments[i].hasOwnProperty(attr) && typeof result[attr] === "undefined") {
  3161. result[attr] = arguments[i][attr];
  3162. }
  3163. }
  3164. }
  3165. return result;
  3166. };
  3167. },{"./compressions":8,"./nodeBuffer":16,"./support":22}],27:[function(_dereq_,module,exports){
  3168. 'use strict';
  3169. var StringReader = _dereq_('./stringReader');
  3170. var NodeBufferReader = _dereq_('./nodeBufferReader');
  3171. var Uint8ArrayReader = _dereq_('./uint8ArrayReader');
  3172. var ArrayReader = _dereq_('./arrayReader');
  3173. var utils = _dereq_('./utils');
  3174. var sig = _dereq_('./signature');
  3175. var ZipEntry = _dereq_('./zipEntry');
  3176. var support = _dereq_('./support');
  3177. var jszipProto = _dereq_('./object');
  3178. // class ZipEntries {{{
  3179. /**
  3180. * All the entries in the zip file.
  3181. * @constructor
  3182. * @param {String|ArrayBuffer|Uint8Array} data the binary stream to load.
  3183. * @param {Object} loadOptions Options for loading the stream.
  3184. */
  3185. function ZipEntries(data, loadOptions) {
  3186. this.files = [];
  3187. this.loadOptions = loadOptions;
  3188. if (data) {
  3189. this.load(data);
  3190. }
  3191. }
  3192. ZipEntries.prototype = {
  3193. /**
  3194. * Check that the reader is on the speficied signature.
  3195. * @param {string} expectedSignature the expected signature.
  3196. * @throws {Error} if it is an other signature.
  3197. */
  3198. checkSignature: function(expectedSignature) {
  3199. var signature = this.reader.readString(4);
  3200. if (signature !== expectedSignature) {
  3201. throw new Error("Corrupted zip or bug : unexpected signature " + "(" + utils.pretty(signature) + ", expected " + utils.pretty(expectedSignature) + ")");
  3202. }
  3203. },
  3204. /**
  3205. * Check if the given signature is at the given index.
  3206. * @param {number} askedIndex the index to check.
  3207. * @param {string} expectedSignature the signature to expect.
  3208. * @return {boolean} true if the signature is here, false otherwise.
  3209. */
  3210. isSignature: function(askedIndex, expectedSignature) {
  3211. var currentIndex = this.reader.index;
  3212. this.reader.setIndex(askedIndex);
  3213. var signature = this.reader.readString(4);
  3214. var result = signature === expectedSignature;
  3215. this.reader.setIndex(currentIndex);
  3216. return result;
  3217. },
  3218. /**
  3219. * Read the end of the central directory.
  3220. */
  3221. readBlockEndOfCentral: function() {
  3222. this.diskNumber = this.reader.readInt(2);
  3223. this.diskWithCentralDirStart = this.reader.readInt(2);
  3224. this.centralDirRecordsOnThisDisk = this.reader.readInt(2);
  3225. this.centralDirRecords = this.reader.readInt(2);
  3226. this.centralDirSize = this.reader.readInt(4);
  3227. this.centralDirOffset = this.reader.readInt(4);
  3228. this.zipCommentLength = this.reader.readInt(2);
  3229. // warning : the encoding depends of the system locale
  3230. // On a linux machine with LANG=en_US.utf8, this field is utf8 encoded.
  3231. // On a windows machine, this field is encoded with the localized windows code page.
  3232. var zipComment = this.reader.readData(this.zipCommentLength);
  3233. var decodeParamType = support.uint8array ? "uint8array" : "array";
  3234. // To get consistent behavior with the generation part, we will assume that
  3235. // this is utf8 encoded unless specified otherwise.
  3236. var decodeContent = utils.transformTo(decodeParamType, zipComment);
  3237. this.zipComment = this.loadOptions.decodeFileName(decodeContent);
  3238. },
  3239. /**
  3240. * Read the end of the Zip 64 central directory.
  3241. * Not merged with the method readEndOfCentral :
  3242. * The end of central can coexist with its Zip64 brother,
  3243. * I don't want to read the wrong number of bytes !
  3244. */
  3245. readBlockZip64EndOfCentral: function() {
  3246. this.zip64EndOfCentralSize = this.reader.readInt(8);
  3247. this.versionMadeBy = this.reader.readString(2);
  3248. this.versionNeeded = this.reader.readInt(2);
  3249. this.diskNumber = this.reader.readInt(4);
  3250. this.diskWithCentralDirStart = this.reader.readInt(4);
  3251. this.centralDirRecordsOnThisDisk = this.reader.readInt(8);
  3252. this.centralDirRecords = this.reader.readInt(8);
  3253. this.centralDirSize = this.reader.readInt(8);
  3254. this.centralDirOffset = this.reader.readInt(8);
  3255. this.zip64ExtensibleData = {};
  3256. var extraDataSize = this.zip64EndOfCentralSize - 44,
  3257. index = 0,
  3258. extraFieldId,
  3259. extraFieldLength,
  3260. extraFieldValue;
  3261. while (index < extraDataSize) {
  3262. extraFieldId = this.reader.readInt(2);
  3263. extraFieldLength = this.reader.readInt(4);
  3264. extraFieldValue = this.reader.readString(extraFieldLength);
  3265. this.zip64ExtensibleData[extraFieldId] = {
  3266. id: extraFieldId,
  3267. length: extraFieldLength,
  3268. value: extraFieldValue
  3269. };
  3270. }
  3271. },
  3272. /**
  3273. * Read the end of the Zip 64 central directory locator.
  3274. */
  3275. readBlockZip64EndOfCentralLocator: function() {
  3276. this.diskWithZip64CentralDirStart = this.reader.readInt(4);
  3277. this.relativeOffsetEndOfZip64CentralDir = this.reader.readInt(8);
  3278. this.disksCount = this.reader.readInt(4);
  3279. if (this.disksCount > 1) {
  3280. throw new Error("Multi-volumes zip are not supported");
  3281. }
  3282. },
  3283. /**
  3284. * Read the local files, based on the offset read in the central part.
  3285. */
  3286. readLocalFiles: function() {
  3287. var i, file;
  3288. for (i = 0; i < this.files.length; i++) {
  3289. file = this.files[i];
  3290. this.reader.setIndex(file.localHeaderOffset);
  3291. this.checkSignature(sig.LOCAL_FILE_HEADER);
  3292. file.readLocalPart(this.reader);
  3293. file.handleUTF8();
  3294. file.processAttributes();
  3295. }
  3296. },
  3297. /**
  3298. * Read the central directory.
  3299. */
  3300. readCentralDir: function() {
  3301. var file;
  3302. this.reader.setIndex(this.centralDirOffset);
  3303. while (this.reader.readString(4) === sig.CENTRAL_FILE_HEADER) {
  3304. file = new ZipEntry({
  3305. zip64: this.zip64
  3306. }, this.loadOptions);
  3307. file.readCentralPart(this.reader);
  3308. this.files.push(file);
  3309. }
  3310. if (this.centralDirRecords !== this.files.length) {
  3311. if (this.centralDirRecords !== 0 && this.files.length === 0) {
  3312. // We expected some records but couldn't find ANY.
  3313. // This is really suspicious, as if something went wrong.
  3314. throw new Error("Corrupted zip or bug: expected " + this.centralDirRecords + " records in central dir, got " + this.files.length);
  3315. } else {
  3316. // We found some records but not all.
  3317. // Something is wrong but we got something for the user: no error here.
  3318. // console.warn("expected", this.centralDirRecords, "records in central dir, got", this.files.length);
  3319. }
  3320. }
  3321. },
  3322. /**
  3323. * Read the end of central directory.
  3324. */
  3325. readEndOfCentral: function() {
  3326. var offset = this.reader.lastIndexOfSignature(sig.CENTRAL_DIRECTORY_END);
  3327. if (offset < 0) {
  3328. // Check if the content is a truncated zip or complete garbage.
  3329. // A "LOCAL_FILE_HEADER" is not required at the beginning (auto
  3330. // extractible zip for example) but it can give a good hint.
  3331. // If an ajax request was used without responseType, we will also
  3332. // get unreadable data.
  3333. var isGarbage = !this.isSignature(0, sig.LOCAL_FILE_HEADER);
  3334. if (isGarbage) {
  3335. throw new Error("Can't find end of central directory : is this a zip file ? " +
  3336. "If it is, see http://stuk.github.io/jszip/documentation/howto/read_zip.html");
  3337. } else {
  3338. throw new Error("Corrupted zip : can't find end of central directory");
  3339. }
  3340. }
  3341. this.reader.setIndex(offset);
  3342. var endOfCentralDirOffset = offset;
  3343. this.checkSignature(sig.CENTRAL_DIRECTORY_END);
  3344. this.readBlockEndOfCentral();
  3345. /* extract from the zip spec :
  3346. 4) If one of the fields in the end of central directory
  3347. record is too small to hold required data, the field
  3348. should be set to -1 (0xFFFF or 0xFFFFFFFF) and the
  3349. ZIP64 format record should be created.
  3350. 5) The end of central directory record and the
  3351. Zip64 end of central directory locator record must
  3352. reside on the same disk when splitting or spanning
  3353. an archive.
  3354. */
  3355. if (this.diskNumber === utils.MAX_VALUE_16BITS || this.diskWithCentralDirStart === utils.MAX_VALUE_16BITS || this.centralDirRecordsOnThisDisk === utils.MAX_VALUE_16BITS || this.centralDirRecords === utils.MAX_VALUE_16BITS || this.centralDirSize === utils.MAX_VALUE_32BITS || this.centralDirOffset === utils.MAX_VALUE_32BITS) {
  3356. this.zip64 = true;
  3357. /*
  3358. Warning : the zip64 extension is supported, but ONLY if the 64bits integer read from
  3359. the zip file can fit into a 32bits integer. This cannot be solved : Javascript represents
  3360. all numbers as 64-bit double precision IEEE 754 floating point numbers.
  3361. So, we have 53bits for integers and bitwise operations treat everything as 32bits.
  3362. see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Bitwise_Operators
  3363. and http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf section 8.5
  3364. */
  3365. // should look for a zip64 EOCD locator
  3366. offset = this.reader.lastIndexOfSignature(sig.ZIP64_CENTRAL_DIRECTORY_LOCATOR);
  3367. if (offset < 0) {
  3368. throw new Error("Corrupted zip : can't find the ZIP64 end of central directory locator");
  3369. }
  3370. this.reader.setIndex(offset);
  3371. this.checkSignature(sig.ZIP64_CENTRAL_DIRECTORY_LOCATOR);
  3372. this.readBlockZip64EndOfCentralLocator();
  3373. // now the zip64 EOCD record
  3374. if (!this.isSignature(this.relativeOffsetEndOfZip64CentralDir, sig.ZIP64_CENTRAL_DIRECTORY_END)) {
  3375. // console.warn("ZIP64 end of central directory not where expected.");
  3376. this.relativeOffsetEndOfZip64CentralDir = this.reader.lastIndexOfSignature(sig.ZIP64_CENTRAL_DIRECTORY_END);
  3377. if (this.relativeOffsetEndOfZip64CentralDir < 0) {
  3378. throw new Error("Corrupted zip : can't find the ZIP64 end of central directory");
  3379. }
  3380. }
  3381. this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir);
  3382. this.checkSignature(sig.ZIP64_CENTRAL_DIRECTORY_END);
  3383. this.readBlockZip64EndOfCentral();
  3384. }
  3385. var expectedEndOfCentralDirOffset = this.centralDirOffset + this.centralDirSize;
  3386. if (this.zip64) {
  3387. expectedEndOfCentralDirOffset += 20; // end of central dir 64 locator
  3388. expectedEndOfCentralDirOffset += 12 /* should not include the leading 12 bytes */ + this.zip64EndOfCentralSize;
  3389. }
  3390. var extraBytes = endOfCentralDirOffset - expectedEndOfCentralDirOffset;
  3391. if (extraBytes > 0) {
  3392. // console.warn(extraBytes, "extra bytes at beginning or within zipfile");
  3393. if (this.isSignature(endOfCentralDirOffset, sig.CENTRAL_FILE_HEADER)) {
  3394. // The offsets seem wrong, but we have something at the specified offset.
  3395. // So… we keep it.
  3396. } else {
  3397. // the offset is wrong, update the "zero" of the reader
  3398. // this happens if data has been prepended (crx files for example)
  3399. this.reader.zero = extraBytes;
  3400. }
  3401. } else if (extraBytes < 0) {
  3402. throw new Error("Corrupted zip: missing " + Math.abs(extraBytes) + " bytes.");
  3403. }
  3404. },
  3405. prepareReader: function(data) {
  3406. var type = utils.getTypeOf(data);
  3407. utils.checkSupport(type);
  3408. if (type === "string" && !support.uint8array) {
  3409. this.reader = new StringReader(data, this.loadOptions.optimizedBinaryString);
  3410. }
  3411. else if (type === "nodebuffer") {
  3412. this.reader = new NodeBufferReader(data);
  3413. }
  3414. else if (support.uint8array) {
  3415. this.reader = new Uint8ArrayReader(utils.transformTo("uint8array", data));
  3416. } else if (support.array) {
  3417. this.reader = new ArrayReader(utils.transformTo("array", data));
  3418. } else {
  3419. throw new Error("Unexpected error: unsupported type '" + type + "'");
  3420. }
  3421. },
  3422. /**
  3423. * Read a zip file and create ZipEntries.
  3424. * @param {String|ArrayBuffer|Uint8Array|Buffer} data the binary string representing a zip file.
  3425. */
  3426. load: function(data) {
  3427. this.prepareReader(data);
  3428. this.readEndOfCentral();
  3429. this.readCentralDir();
  3430. this.readLocalFiles();
  3431. }
  3432. };
  3433. // }}} end of ZipEntries
  3434. module.exports = ZipEntries;
  3435. },{"./arrayReader":5,"./nodeBufferReader":17,"./object":18,"./signature":19,"./stringReader":20,"./support":22,"./uint8ArrayReader":23,"./utils":26,"./zipEntry":28}],28:[function(_dereq_,module,exports){
  3436. 'use strict';
  3437. var StringReader = _dereq_('./stringReader');
  3438. var utils = _dereq_('./utils');
  3439. var CompressedObject = _dereq_('./compressedObject');
  3440. var jszipProto = _dereq_('./object');
  3441. var support = _dereq_('./support');
  3442. var MADE_BY_DOS = 0x00;
  3443. var MADE_BY_UNIX = 0x03;
  3444. // class ZipEntry {{{
  3445. /**
  3446. * An entry in the zip file.
  3447. * @constructor
  3448. * @param {Object} options Options of the current file.
  3449. * @param {Object} loadOptions Options for loading the stream.
  3450. */
  3451. function ZipEntry(options, loadOptions) {
  3452. this.options = options;
  3453. this.loadOptions = loadOptions;
  3454. }
  3455. ZipEntry.prototype = {
  3456. /**
  3457. * say if the file is encrypted.
  3458. * @return {boolean} true if the file is encrypted, false otherwise.
  3459. */
  3460. isEncrypted: function() {
  3461. // bit 1 is set
  3462. return (this.bitFlag & 0x0001) === 0x0001;
  3463. },
  3464. /**
  3465. * say if the file has utf-8 filename/comment.
  3466. * @return {boolean} true if the filename/comment is in utf-8, false otherwise.
  3467. */
  3468. useUTF8: function() {
  3469. // bit 11 is set
  3470. return (this.bitFlag & 0x0800) === 0x0800;
  3471. },
  3472. /**
  3473. * Prepare the function used to generate the compressed content from this ZipFile.
  3474. * @param {DataReader} reader the reader to use.
  3475. * @param {number} from the offset from where we should read the data.
  3476. * @param {number} length the length of the data to read.
  3477. * @return {Function} the callback to get the compressed content (the type depends of the DataReader class).
  3478. */
  3479. prepareCompressedContent: function(reader, from, length) {
  3480. return function() {
  3481. var previousIndex = reader.index;
  3482. reader.setIndex(from);
  3483. var compressedFileData = reader.readData(length);
  3484. reader.setIndex(previousIndex);
  3485. return compressedFileData;
  3486. };
  3487. },
  3488. /**
  3489. * Prepare the function used to generate the uncompressed content from this ZipFile.
  3490. * @param {DataReader} reader the reader to use.
  3491. * @param {number} from the offset from where we should read the data.
  3492. * @param {number} length the length of the data to read.
  3493. * @param {JSZip.compression} compression the compression used on this file.
  3494. * @param {number} uncompressedSize the uncompressed size to expect.
  3495. * @return {Function} the callback to get the uncompressed content (the type depends of the DataReader class).
  3496. */
  3497. prepareContent: function(reader, from, length, compression, uncompressedSize) {
  3498. return function() {
  3499. var compressedFileData = utils.transformTo(compression.uncompressInputType, this.getCompressedContent());
  3500. var uncompressedFileData = compression.uncompress(compressedFileData);
  3501. if (uncompressedFileData.length !== uncompressedSize) {
  3502. throw new Error("Bug : uncompressed data size mismatch");
  3503. }
  3504. return uncompressedFileData;
  3505. };
  3506. },
  3507. /**
  3508. * Read the local part of a zip file and add the info in this object.
  3509. * @param {DataReader} reader the reader to use.
  3510. */
  3511. readLocalPart: function(reader) {
  3512. var compression, localExtraFieldsLength;
  3513. // we already know everything from the central dir !
  3514. // If the central dir data are false, we are doomed.
  3515. // On the bright side, the local part is scary : zip64, data descriptors, both, etc.
  3516. // The less data we get here, the more reliable this should be.
  3517. // Let's skip the whole header and dash to the data !
  3518. reader.skip(22);
  3519. // in some zip created on windows, the filename stored in the central dir contains \ instead of /.
  3520. // Strangely, the filename here is OK.
  3521. // I would love to treat these zip files as corrupted (see http://www.info-zip.org/FAQ.html#backslashes
  3522. // or APPNOTE#4.4.17.1, "All slashes MUST be forward slashes '/'") but there are a lot of bad zip generators...
  3523. // Search "unzip mismatching "local" filename continuing with "central" filename version" on
  3524. // the internet.
  3525. //
  3526. // I think I see the logic here : the central directory is used to display
  3527. // content and the local directory is used to extract the files. Mixing / and \
  3528. // may be used to display \ to windows users and use / when extracting the files.
  3529. // Unfortunately, this lead also to some issues : http://seclists.org/fulldisclosure/2009/Sep/394
  3530. this.fileNameLength = reader.readInt(2);
  3531. localExtraFieldsLength = reader.readInt(2); // can't be sure this will be the same as the central dir
  3532. this.fileName = reader.readData(this.fileNameLength);
  3533. reader.skip(localExtraFieldsLength);
  3534. if (this.compressedSize == -1 || this.uncompressedSize == -1) {
  3535. throw new Error("Bug or corrupted zip : didn't get enough informations from the central directory " + "(compressedSize == -1 || uncompressedSize == -1)");
  3536. }
  3537. compression = utils.findCompression(this.compressionMethod);
  3538. if (compression === null) { // no compression found
  3539. throw new Error("Corrupted zip : compression " + utils.pretty(this.compressionMethod) + " unknown (inner file : " + utils.transformTo("string", this.fileName) + ")");
  3540. }
  3541. this.decompressed = new CompressedObject();
  3542. this.decompressed.compressedSize = this.compressedSize;
  3543. this.decompressed.uncompressedSize = this.uncompressedSize;
  3544. this.decompressed.crc32 = this.crc32;
  3545. this.decompressed.compressionMethod = this.compressionMethod;
  3546. this.decompressed.getCompressedContent = this.prepareCompressedContent(reader, reader.index, this.compressedSize, compression);
  3547. this.decompressed.getContent = this.prepareContent(reader, reader.index, this.compressedSize, compression, this.uncompressedSize);
  3548. // we need to compute the crc32...
  3549. if (this.loadOptions.checkCRC32) {
  3550. this.decompressed = utils.transformTo("string", this.decompressed.getContent());
  3551. if (jszipProto.crc32(this.decompressed) !== this.crc32) {
  3552. throw new Error("Corrupted zip : CRC32 mismatch");
  3553. }
  3554. }
  3555. },
  3556. /**
  3557. * Read the central part of a zip file and add the info in this object.
  3558. * @param {DataReader} reader the reader to use.
  3559. */
  3560. readCentralPart: function(reader) {
  3561. this.versionMadeBy = reader.readInt(2);
  3562. this.versionNeeded = reader.readInt(2);
  3563. this.bitFlag = reader.readInt(2);
  3564. this.compressionMethod = reader.readString(2);
  3565. this.date = reader.readDate();
  3566. this.crc32 = reader.readInt(4);
  3567. this.compressedSize = reader.readInt(4);
  3568. this.uncompressedSize = reader.readInt(4);
  3569. this.fileNameLength = reader.readInt(2);
  3570. this.extraFieldsLength = reader.readInt(2);
  3571. this.fileCommentLength = reader.readInt(2);
  3572. this.diskNumberStart = reader.readInt(2);
  3573. this.internalFileAttributes = reader.readInt(2);
  3574. this.externalFileAttributes = reader.readInt(4);
  3575. this.localHeaderOffset = reader.readInt(4);
  3576. if (this.isEncrypted()) {
  3577. throw new Error("Encrypted zip are not supported");
  3578. }
  3579. this.fileName = reader.readData(this.fileNameLength);
  3580. this.readExtraFields(reader);
  3581. this.parseZIP64ExtraField(reader);
  3582. this.fileComment = reader.readData(this.fileCommentLength);
  3583. },
  3584. /**
  3585. * Parse the external file attributes and get the unix/dos permissions.
  3586. */
  3587. processAttributes: function () {
  3588. this.unixPermissions = null;
  3589. this.dosPermissions = null;
  3590. var madeBy = this.versionMadeBy >> 8;
  3591. // Check if we have the DOS directory flag set.
  3592. // We look for it in the DOS and UNIX permissions
  3593. // but some unknown platform could set it as a compatibility flag.
  3594. this.dir = this.externalFileAttributes & 0x0010 ? true : false;
  3595. if(madeBy === MADE_BY_DOS) {
  3596. // first 6 bits (0 to 5)
  3597. this.dosPermissions = this.externalFileAttributes & 0x3F;
  3598. }
  3599. if(madeBy === MADE_BY_UNIX) {
  3600. this.unixPermissions = (this.externalFileAttributes >> 16) & 0xFFFF;
  3601. // the octal permissions are in (this.unixPermissions & 0x01FF).toString(8);
  3602. }
  3603. // fail safe : if the name ends with a / it probably means a folder
  3604. if (!this.dir && this.fileNameStr.slice(-1) === '/') {
  3605. this.dir = true;
  3606. }
  3607. },
  3608. /**
  3609. * Parse the ZIP64 extra field and merge the info in the current ZipEntry.
  3610. * @param {DataReader} reader the reader to use.
  3611. */
  3612. parseZIP64ExtraField: function(reader) {
  3613. if (!this.extraFields[0x0001]) {
  3614. return;
  3615. }
  3616. // should be something, preparing the extra reader
  3617. var extraReader = new StringReader(this.extraFields[0x0001].value);
  3618. // I really hope that these 64bits integer can fit in 32 bits integer, because js
  3619. // won't let us have more.
  3620. if (this.uncompressedSize === utils.MAX_VALUE_32BITS) {
  3621. this.uncompressedSize = extraReader.readInt(8);
  3622. }
  3623. if (this.compressedSize === utils.MAX_VALUE_32BITS) {
  3624. this.compressedSize = extraReader.readInt(8);
  3625. }
  3626. if (this.localHeaderOffset === utils.MAX_VALUE_32BITS) {
  3627. this.localHeaderOffset = extraReader.readInt(8);
  3628. }
  3629. if (this.diskNumberStart === utils.MAX_VALUE_32BITS) {
  3630. this.diskNumberStart = extraReader.readInt(4);
  3631. }
  3632. },
  3633. /**
  3634. * Read the central part of a zip file and add the info in this object.
  3635. * @param {DataReader} reader the reader to use.
  3636. */
  3637. readExtraFields: function(reader) {
  3638. var start = reader.index,
  3639. extraFieldId,
  3640. extraFieldLength,
  3641. extraFieldValue;
  3642. this.extraFields = this.extraFields || {};
  3643. while (reader.index < start + this.extraFieldsLength) {
  3644. extraFieldId = reader.readInt(2);
  3645. extraFieldLength = reader.readInt(2);
  3646. extraFieldValue = reader.readString(extraFieldLength);
  3647. this.extraFields[extraFieldId] = {
  3648. id: extraFieldId,
  3649. length: extraFieldLength,
  3650. value: extraFieldValue
  3651. };
  3652. }
  3653. },
  3654. /**
  3655. * Apply an UTF8 transformation if needed.
  3656. */
  3657. handleUTF8: function() {
  3658. var decodeParamType = support.uint8array ? "uint8array" : "array";
  3659. if (this.useUTF8()) {
  3660. this.fileNameStr = jszipProto.utf8decode(this.fileName);
  3661. this.fileCommentStr = jszipProto.utf8decode(this.fileComment);
  3662. } else {
  3663. var upath = this.findExtraFieldUnicodePath();
  3664. if (upath !== null) {
  3665. this.fileNameStr = upath;
  3666. } else {
  3667. var fileNameByteArray = utils.transformTo(decodeParamType, this.fileName);
  3668. this.fileNameStr = this.loadOptions.decodeFileName(fileNameByteArray);
  3669. }
  3670. var ucomment = this.findExtraFieldUnicodeComment();
  3671. if (ucomment !== null) {
  3672. this.fileCommentStr = ucomment;
  3673. } else {
  3674. var commentByteArray = utils.transformTo(decodeParamType, this.fileComment);
  3675. this.fileCommentStr = this.loadOptions.decodeFileName(commentByteArray);
  3676. }
  3677. }
  3678. },
  3679. /**
  3680. * Find the unicode path declared in the extra field, if any.
  3681. * @return {String} the unicode path, null otherwise.
  3682. */
  3683. findExtraFieldUnicodePath: function() {
  3684. var upathField = this.extraFields[0x7075];
  3685. if (upathField) {
  3686. var extraReader = new StringReader(upathField.value);
  3687. // wrong version
  3688. if (extraReader.readInt(1) !== 1) {
  3689. return null;
  3690. }
  3691. // the crc of the filename changed, this field is out of date.
  3692. if (jszipProto.crc32(this.fileName) !== extraReader.readInt(4)) {
  3693. return null;
  3694. }
  3695. return jszipProto.utf8decode(extraReader.readString(upathField.length - 5));
  3696. }
  3697. return null;
  3698. },
  3699. /**
  3700. * Find the unicode comment declared in the extra field, if any.
  3701. * @return {String} the unicode comment, null otherwise.
  3702. */
  3703. findExtraFieldUnicodeComment: function() {
  3704. var ucommentField = this.extraFields[0x6375];
  3705. if (ucommentField) {
  3706. var extraReader = new StringReader(ucommentField.value);
  3707. // wrong version
  3708. if (extraReader.readInt(1) !== 1) {
  3709. return null;
  3710. }
  3711. // the crc of the comment changed, this field is out of date.
  3712. if (jszipProto.crc32(this.fileComment) !== extraReader.readInt(4)) {
  3713. return null;
  3714. }
  3715. return jszipProto.utf8decode(extraReader.readString(ucommentField.length - 5));
  3716. }
  3717. return null;
  3718. }
  3719. };
  3720. module.exports = ZipEntry;
  3721. },{"./compressedObject":7,"./object":18,"./stringReader":20,"./support":22,"./utils":26}],29:[function(_dereq_,module,exports){
  3722. // Top level file is just a mixin of submodules & constants
  3723. 'use strict';
  3724. var assign = _dereq_('./lib/utils/common').assign;
  3725. var deflate = _dereq_('./lib/deflate');
  3726. var inflate = _dereq_('./lib/inflate');
  3727. var constants = _dereq_('./lib/zlib/constants');
  3728. var pako = {};
  3729. assign(pako, deflate, inflate, constants);
  3730. module.exports = pako;
  3731. },{"./lib/deflate":30,"./lib/inflate":31,"./lib/utils/common":32,"./lib/zlib/constants":35}],30:[function(_dereq_,module,exports){
  3732. 'use strict';
  3733. var zlib_deflate = _dereq_('./zlib/deflate');
  3734. var utils = _dereq_('./utils/common');
  3735. var strings = _dereq_('./utils/strings');
  3736. var msg = _dereq_('./zlib/messages');
  3737. var ZStream = _dereq_('./zlib/zstream');
  3738. var toString = Object.prototype.toString;
  3739. /* Public constants ==========================================================*/
  3740. /* ===========================================================================*/
  3741. var Z_NO_FLUSH = 0;
  3742. var Z_FINISH = 4;
  3743. var Z_OK = 0;
  3744. var Z_STREAM_END = 1;
  3745. var Z_SYNC_FLUSH = 2;
  3746. var Z_DEFAULT_COMPRESSION = -1;
  3747. var Z_DEFAULT_STRATEGY = 0;
  3748. var Z_DEFLATED = 8;
  3749. /* ===========================================================================*/
  3750. /**
  3751. * class Deflate
  3752. *
  3753. * Generic JS-style wrapper for zlib calls. If you don't need
  3754. * streaming behaviour - use more simple functions: [[deflate]],
  3755. * [[deflateRaw]] and [[gzip]].
  3756. **/
  3757. /* internal
  3758. * Deflate.chunks -> Array
  3759. *
  3760. * Chunks of output data, if [[Deflate#onData]] not overriden.
  3761. **/
  3762. /**
  3763. * Deflate.result -> Uint8Array|Array
  3764. *
  3765. * Compressed result, generated by default [[Deflate#onData]]
  3766. * and [[Deflate#onEnd]] handlers. Filled after you push last chunk
  3767. * (call [[Deflate#push]] with `Z_FINISH` / `true` param) or if you
  3768. * push a chunk with explicit flush (call [[Deflate#push]] with
  3769. * `Z_SYNC_FLUSH` param).
  3770. **/
  3771. /**
  3772. * Deflate.err -> Number
  3773. *
  3774. * Error code after deflate finished. 0 (Z_OK) on success.
  3775. * You will not need it in real life, because deflate errors
  3776. * are possible only on wrong options or bad `onData` / `onEnd`
  3777. * custom handlers.
  3778. **/
  3779. /**
  3780. * Deflate.msg -> String
  3781. *
  3782. * Error message, if [[Deflate.err]] != 0
  3783. **/
  3784. /**
  3785. * new Deflate(options)
  3786. * - options (Object): zlib deflate options.
  3787. *
  3788. * Creates new deflator instance with specified params. Throws exception
  3789. * on bad params. Supported options:
  3790. *
  3791. * - `level`
  3792. * - `windowBits`
  3793. * - `memLevel`
  3794. * - `strategy`
  3795. * - `dictionary`
  3796. *
  3797. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  3798. * for more information on these.
  3799. *
  3800. * Additional options, for internal needs:
  3801. *
  3802. * - `chunkSize` - size of generated data chunks (16K by default)
  3803. * - `raw` (Boolean) - do raw deflate
  3804. * - `gzip` (Boolean) - create gzip wrapper
  3805. * - `to` (String) - if equal to 'string', then result will be "binary string"
  3806. * (each char code [0..255])
  3807. * - `header` (Object) - custom header for gzip
  3808. * - `text` (Boolean) - true if compressed data believed to be text
  3809. * - `time` (Number) - modification time, unix timestamp
  3810. * - `os` (Number) - operation system code
  3811. * - `extra` (Array) - array of bytes with extra data (max 65536)
  3812. * - `name` (String) - file name (binary string)
  3813. * - `comment` (String) - comment (binary string)
  3814. * - `hcrc` (Boolean) - true if header crc should be added
  3815. *
  3816. * ##### Example:
  3817. *
  3818. * ```javascript
  3819. * var pako = require('pako')
  3820. * , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
  3821. * , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
  3822. *
  3823. * var deflate = new pako.Deflate({ level: 3});
  3824. *
  3825. * deflate.push(chunk1, false);
  3826. * deflate.push(chunk2, true); // true -> last chunk
  3827. *
  3828. * if (deflate.err) { throw new Error(deflate.err); }
  3829. *
  3830. * console.log(deflate.result);
  3831. * ```
  3832. **/
  3833. function Deflate(options) {
  3834. if (!(this instanceof Deflate)) return new Deflate(options);
  3835. this.options = utils.assign({
  3836. level: Z_DEFAULT_COMPRESSION,
  3837. method: Z_DEFLATED,
  3838. chunkSize: 16384,
  3839. windowBits: 15,
  3840. memLevel: 8,
  3841. strategy: Z_DEFAULT_STRATEGY,
  3842. to: ''
  3843. }, options || {});
  3844. var opt = this.options;
  3845. if (opt.raw && (opt.windowBits > 0)) {
  3846. opt.windowBits = -opt.windowBits;
  3847. }
  3848. else if (opt.gzip && (opt.windowBits > 0) && (opt.windowBits < 16)) {
  3849. opt.windowBits += 16;
  3850. }
  3851. this.err = 0; // error code, if happens (0 = Z_OK)
  3852. this.msg = ''; // error message
  3853. this.ended = false; // used to avoid multiple onEnd() calls
  3854. this.chunks = []; // chunks of compressed data
  3855. this.strm = new ZStream();
  3856. this.strm.avail_out = 0;
  3857. var status = zlib_deflate.deflateInit2(
  3858. this.strm,
  3859. opt.level,
  3860. opt.method,
  3861. opt.windowBits,
  3862. opt.memLevel,
  3863. opt.strategy
  3864. );
  3865. if (status !== Z_OK) {
  3866. throw new Error(msg[status]);
  3867. }
  3868. if (opt.header) {
  3869. zlib_deflate.deflateSetHeader(this.strm, opt.header);
  3870. }
  3871. if (opt.dictionary) {
  3872. var dict;
  3873. // Convert data if needed
  3874. if (typeof opt.dictionary === 'string') {
  3875. // If we need to compress text, change encoding to utf8.
  3876. dict = strings.string2buf(opt.dictionary);
  3877. } else if (toString.call(opt.dictionary) === '[object ArrayBuffer]') {
  3878. dict = new Uint8Array(opt.dictionary);
  3879. } else {
  3880. dict = opt.dictionary;
  3881. }
  3882. status = zlib_deflate.deflateSetDictionary(this.strm, dict);
  3883. if (status !== Z_OK) {
  3884. throw new Error(msg[status]);
  3885. }
  3886. this._dict_set = true;
  3887. }
  3888. }
  3889. /**
  3890. * Deflate#push(data[, mode]) -> Boolean
  3891. * - data (Uint8Array|Array|ArrayBuffer|String): input data. Strings will be
  3892. * converted to utf8 byte sequence.
  3893. * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
  3894. * See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
  3895. *
  3896. * Sends input data to deflate pipe, generating [[Deflate#onData]] calls with
  3897. * new compressed chunks. Returns `true` on success. The last data block must have
  3898. * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
  3899. * [[Deflate#onEnd]]. For interim explicit flushes (without ending the stream) you
  3900. * can use mode Z_SYNC_FLUSH, keeping the compression context.
  3901. *
  3902. * On fail call [[Deflate#onEnd]] with error code and return false.
  3903. *
  3904. * We strongly recommend to use `Uint8Array` on input for best speed (output
  3905. * array format is detected automatically). Also, don't skip last param and always
  3906. * use the same type in your code (boolean or number). That will improve JS speed.
  3907. *
  3908. * For regular `Array`-s make sure all elements are [0..255].
  3909. *
  3910. * ##### Example
  3911. *
  3912. * ```javascript
  3913. * push(chunk, false); // push one of data chunks
  3914. * ...
  3915. * push(chunk, true); // push last chunk
  3916. * ```
  3917. **/
  3918. Deflate.prototype.push = function (data, mode) {
  3919. var strm = this.strm;
  3920. var chunkSize = this.options.chunkSize;
  3921. var status, _mode;
  3922. if (this.ended) { return false; }
  3923. _mode = (mode === ~~mode) ? mode : ((mode === true) ? Z_FINISH : Z_NO_FLUSH);
  3924. // Convert data if needed
  3925. if (typeof data === 'string') {
  3926. // If we need to compress text, change encoding to utf8.
  3927. strm.input = strings.string2buf(data);
  3928. } else if (toString.call(data) === '[object ArrayBuffer]') {
  3929. strm.input = new Uint8Array(data);
  3930. } else {
  3931. strm.input = data;
  3932. }
  3933. strm.next_in = 0;
  3934. strm.avail_in = strm.input.length;
  3935. do {
  3936. if (strm.avail_out === 0) {
  3937. strm.output = new utils.Buf8(chunkSize);
  3938. strm.next_out = 0;
  3939. strm.avail_out = chunkSize;
  3940. }
  3941. status = zlib_deflate.deflate(strm, _mode); /* no bad return value */
  3942. if (status !== Z_STREAM_END && status !== Z_OK) {
  3943. this.onEnd(status);
  3944. this.ended = true;
  3945. return false;
  3946. }
  3947. if (strm.avail_out === 0 || (strm.avail_in === 0 && (_mode === Z_FINISH || _mode === Z_SYNC_FLUSH))) {
  3948. if (this.options.to === 'string') {
  3949. this.onData(strings.buf2binstring(utils.shrinkBuf(strm.output, strm.next_out)));
  3950. } else {
  3951. this.onData(utils.shrinkBuf(strm.output, strm.next_out));
  3952. }
  3953. }
  3954. } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== Z_STREAM_END);
  3955. // Finalize on the last chunk.
  3956. if (_mode === Z_FINISH) {
  3957. status = zlib_deflate.deflateEnd(this.strm);
  3958. this.onEnd(status);
  3959. this.ended = true;
  3960. return status === Z_OK;
  3961. }
  3962. // callback interim results if Z_SYNC_FLUSH.
  3963. if (_mode === Z_SYNC_FLUSH) {
  3964. this.onEnd(Z_OK);
  3965. strm.avail_out = 0;
  3966. return true;
  3967. }
  3968. return true;
  3969. };
  3970. /**
  3971. * Deflate#onData(chunk) -> Void
  3972. * - chunk (Uint8Array|Array|String): ouput data. Type of array depends
  3973. * on js engine support. When string output requested, each chunk
  3974. * will be string.
  3975. *
  3976. * By default, stores data blocks in `chunks[]` property and glue
  3977. * those in `onEnd`. Override this handler, if you need another behaviour.
  3978. **/
  3979. Deflate.prototype.onData = function (chunk) {
  3980. this.chunks.push(chunk);
  3981. };
  3982. /**
  3983. * Deflate#onEnd(status) -> Void
  3984. * - status (Number): deflate status. 0 (Z_OK) on success,
  3985. * other if not.
  3986. *
  3987. * Called once after you tell deflate that the input stream is
  3988. * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
  3989. * or if an error happened. By default - join collected chunks,
  3990. * free memory and fill `results` / `err` properties.
  3991. **/
  3992. Deflate.prototype.onEnd = function (status) {
  3993. // On success - join
  3994. if (status === Z_OK) {
  3995. if (this.options.to === 'string') {
  3996. this.result = this.chunks.join('');
  3997. } else {
  3998. this.result = utils.flattenChunks(this.chunks);
  3999. }
  4000. }
  4001. this.chunks = [];
  4002. this.err = status;
  4003. this.msg = this.strm.msg;
  4004. };
  4005. /**
  4006. * deflate(data[, options]) -> Uint8Array|Array|String
  4007. * - data (Uint8Array|Array|String): input data to compress.
  4008. * - options (Object): zlib deflate options.
  4009. *
  4010. * Compress `data` with deflate algorithm and `options`.
  4011. *
  4012. * Supported options are:
  4013. *
  4014. * - level
  4015. * - windowBits
  4016. * - memLevel
  4017. * - strategy
  4018. * - dictionary
  4019. *
  4020. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  4021. * for more information on these.
  4022. *
  4023. * Sugar (options):
  4024. *
  4025. * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
  4026. * negative windowBits implicitly.
  4027. * - `to` (String) - if equal to 'string', then result will be "binary string"
  4028. * (each char code [0..255])
  4029. *
  4030. * ##### Example:
  4031. *
  4032. * ```javascript
  4033. * var pako = require('pako')
  4034. * , data = Uint8Array([1,2,3,4,5,6,7,8,9]);
  4035. *
  4036. * console.log(pako.deflate(data));
  4037. * ```
  4038. **/
  4039. function deflate(input, options) {
  4040. var deflator = new Deflate(options);
  4041. deflator.push(input, true);
  4042. // That will never happens, if you don't cheat with options :)
  4043. if (deflator.err) { throw deflator.msg; }
  4044. return deflator.result;
  4045. }
  4046. /**
  4047. * deflateRaw(data[, options]) -> Uint8Array|Array|String
  4048. * - data (Uint8Array|Array|String): input data to compress.
  4049. * - options (Object): zlib deflate options.
  4050. *
  4051. * The same as [[deflate]], but creates raw data, without wrapper
  4052. * (header and adler32 crc).
  4053. **/
  4054. function deflateRaw(input, options) {
  4055. options = options || {};
  4056. options.raw = true;
  4057. return deflate(input, options);
  4058. }
  4059. /**
  4060. * gzip(data[, options]) -> Uint8Array|Array|String
  4061. * - data (Uint8Array|Array|String): input data to compress.
  4062. * - options (Object): zlib deflate options.
  4063. *
  4064. * The same as [[deflate]], but create gzip wrapper instead of
  4065. * deflate one.
  4066. **/
  4067. function gzip(input, options) {
  4068. options = options || {};
  4069. options.gzip = true;
  4070. return deflate(input, options);
  4071. }
  4072. exports.Deflate = Deflate;
  4073. exports.deflate = deflate;
  4074. exports.deflateRaw = deflateRaw;
  4075. exports.gzip = gzip;
  4076. },{"./utils/common":32,"./utils/strings":33,"./zlib/deflate":37,"./zlib/messages":42,"./zlib/zstream":44}],31:[function(_dereq_,module,exports){
  4077. 'use strict';
  4078. var zlib_inflate = _dereq_('./zlib/inflate');
  4079. var utils = _dereq_('./utils/common');
  4080. var strings = _dereq_('./utils/strings');
  4081. var c = _dereq_('./zlib/constants');
  4082. var msg = _dereq_('./zlib/messages');
  4083. var ZStream = _dereq_('./zlib/zstream');
  4084. var GZheader = _dereq_('./zlib/gzheader');
  4085. var toString = Object.prototype.toString;
  4086. /**
  4087. * class Inflate
  4088. *
  4089. * Generic JS-style wrapper for zlib calls. If you don't need
  4090. * streaming behaviour - use more simple functions: [[inflate]]
  4091. * and [[inflateRaw]].
  4092. **/
  4093. /* internal
  4094. * inflate.chunks -> Array
  4095. *
  4096. * Chunks of output data, if [[Inflate#onData]] not overriden.
  4097. **/
  4098. /**
  4099. * Inflate.result -> Uint8Array|Array|String
  4100. *
  4101. * Uncompressed result, generated by default [[Inflate#onData]]
  4102. * and [[Inflate#onEnd]] handlers. Filled after you push last chunk
  4103. * (call [[Inflate#push]] with `Z_FINISH` / `true` param) or if you
  4104. * push a chunk with explicit flush (call [[Inflate#push]] with
  4105. * `Z_SYNC_FLUSH` param).
  4106. **/
  4107. /**
  4108. * Inflate.err -> Number
  4109. *
  4110. * Error code after inflate finished. 0 (Z_OK) on success.
  4111. * Should be checked if broken data possible.
  4112. **/
  4113. /**
  4114. * Inflate.msg -> String
  4115. *
  4116. * Error message, if [[Inflate.err]] != 0
  4117. **/
  4118. /**
  4119. * new Inflate(options)
  4120. * - options (Object): zlib inflate options.
  4121. *
  4122. * Creates new inflator instance with specified params. Throws exception
  4123. * on bad params. Supported options:
  4124. *
  4125. * - `windowBits`
  4126. * - `dictionary`
  4127. *
  4128. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  4129. * for more information on these.
  4130. *
  4131. * Additional options, for internal needs:
  4132. *
  4133. * - `chunkSize` - size of generated data chunks (16K by default)
  4134. * - `raw` (Boolean) - do raw inflate
  4135. * - `to` (String) - if equal to 'string', then result will be converted
  4136. * from utf8 to utf16 (javascript) string. When string output requested,
  4137. * chunk length can differ from `chunkSize`, depending on content.
  4138. *
  4139. * By default, when no options set, autodetect deflate/gzip data format via
  4140. * wrapper header.
  4141. *
  4142. * ##### Example:
  4143. *
  4144. * ```javascript
  4145. * var pako = require('pako')
  4146. * , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9])
  4147. * , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]);
  4148. *
  4149. * var inflate = new pako.Inflate({ level: 3});
  4150. *
  4151. * inflate.push(chunk1, false);
  4152. * inflate.push(chunk2, true); // true -> last chunk
  4153. *
  4154. * if (inflate.err) { throw new Error(inflate.err); }
  4155. *
  4156. * console.log(inflate.result);
  4157. * ```
  4158. **/
  4159. function Inflate(options) {
  4160. if (!(this instanceof Inflate)) return new Inflate(options);
  4161. this.options = utils.assign({
  4162. chunkSize: 16384,
  4163. windowBits: 0,
  4164. to: ''
  4165. }, options || {});
  4166. var opt = this.options;
  4167. // Force window size for `raw` data, if not set directly,
  4168. // because we have no header for autodetect.
  4169. if (opt.raw && (opt.windowBits >= 0) && (opt.windowBits < 16)) {
  4170. opt.windowBits = -opt.windowBits;
  4171. if (opt.windowBits === 0) { opt.windowBits = -15; }
  4172. }
  4173. // If `windowBits` not defined (and mode not raw) - set autodetect flag for gzip/deflate
  4174. if ((opt.windowBits >= 0) && (opt.windowBits < 16) &&
  4175. !(options && options.windowBits)) {
  4176. opt.windowBits += 32;
  4177. }
  4178. // Gzip header has no info about windows size, we can do autodetect only
  4179. // for deflate. So, if window size not set, force it to max when gzip possible
  4180. if ((opt.windowBits > 15) && (opt.windowBits < 48)) {
  4181. // bit 3 (16) -> gzipped data
  4182. // bit 4 (32) -> autodetect gzip/deflate
  4183. if ((opt.windowBits & 15) === 0) {
  4184. opt.windowBits |= 15;
  4185. }
  4186. }
  4187. this.err = 0; // error code, if happens (0 = Z_OK)
  4188. this.msg = ''; // error message
  4189. this.ended = false; // used to avoid multiple onEnd() calls
  4190. this.chunks = []; // chunks of compressed data
  4191. this.strm = new ZStream();
  4192. this.strm.avail_out = 0;
  4193. var status = zlib_inflate.inflateInit2(
  4194. this.strm,
  4195. opt.windowBits
  4196. );
  4197. if (status !== c.Z_OK) {
  4198. throw new Error(msg[status]);
  4199. }
  4200. this.header = new GZheader();
  4201. zlib_inflate.inflateGetHeader(this.strm, this.header);
  4202. }
  4203. /**
  4204. * Inflate#push(data[, mode]) -> Boolean
  4205. * - data (Uint8Array|Array|ArrayBuffer|String): input data
  4206. * - mode (Number|Boolean): 0..6 for corresponding Z_NO_FLUSH..Z_TREE modes.
  4207. * See constants. Skipped or `false` means Z_NO_FLUSH, `true` meansh Z_FINISH.
  4208. *
  4209. * Sends input data to inflate pipe, generating [[Inflate#onData]] calls with
  4210. * new output chunks. Returns `true` on success. The last data block must have
  4211. * mode Z_FINISH (or `true`). That will flush internal pending buffers and call
  4212. * [[Inflate#onEnd]]. For interim explicit flushes (without ending the stream) you
  4213. * can use mode Z_SYNC_FLUSH, keeping the decompression context.
  4214. *
  4215. * On fail call [[Inflate#onEnd]] with error code and return false.
  4216. *
  4217. * We strongly recommend to use `Uint8Array` on input for best speed (output
  4218. * format is detected automatically). Also, don't skip last param and always
  4219. * use the same type in your code (boolean or number). That will improve JS speed.
  4220. *
  4221. * For regular `Array`-s make sure all elements are [0..255].
  4222. *
  4223. * ##### Example
  4224. *
  4225. * ```javascript
  4226. * push(chunk, false); // push one of data chunks
  4227. * ...
  4228. * push(chunk, true); // push last chunk
  4229. * ```
  4230. **/
  4231. Inflate.prototype.push = function (data, mode) {
  4232. var strm = this.strm;
  4233. var chunkSize = this.options.chunkSize;
  4234. var dictionary = this.options.dictionary;
  4235. var status, _mode;
  4236. var next_out_utf8, tail, utf8str;
  4237. var dict;
  4238. // Flag to properly process Z_BUF_ERROR on testing inflate call
  4239. // when we check that all output data was flushed.
  4240. var allowBufError = false;
  4241. if (this.ended) { return false; }
  4242. _mode = (mode === ~~mode) ? mode : ((mode === true) ? c.Z_FINISH : c.Z_NO_FLUSH);
  4243. // Convert data if needed
  4244. if (typeof data === 'string') {
  4245. // Only binary strings can be decompressed on practice
  4246. strm.input = strings.binstring2buf(data);
  4247. } else if (toString.call(data) === '[object ArrayBuffer]') {
  4248. strm.input = new Uint8Array(data);
  4249. } else {
  4250. strm.input = data;
  4251. }
  4252. strm.next_in = 0;
  4253. strm.avail_in = strm.input.length;
  4254. do {
  4255. if (strm.avail_out === 0) {
  4256. strm.output = new utils.Buf8(chunkSize);
  4257. strm.next_out = 0;
  4258. strm.avail_out = chunkSize;
  4259. }
  4260. status = zlib_inflate.inflate(strm, c.Z_NO_FLUSH); /* no bad return value */
  4261. if (status === c.Z_NEED_DICT && dictionary) {
  4262. // Convert data if needed
  4263. if (typeof dictionary === 'string') {
  4264. dict = strings.string2buf(dictionary);
  4265. } else if (toString.call(dictionary) === '[object ArrayBuffer]') {
  4266. dict = new Uint8Array(dictionary);
  4267. } else {
  4268. dict = dictionary;
  4269. }
  4270. status = zlib_inflate.inflateSetDictionary(this.strm, dict);
  4271. }
  4272. if (status === c.Z_BUF_ERROR && allowBufError === true) {
  4273. status = c.Z_OK;
  4274. allowBufError = false;
  4275. }
  4276. if (status !== c.Z_STREAM_END && status !== c.Z_OK) {
  4277. this.onEnd(status);
  4278. this.ended = true;
  4279. return false;
  4280. }
  4281. if (strm.next_out) {
  4282. if (strm.avail_out === 0 || status === c.Z_STREAM_END || (strm.avail_in === 0 && (_mode === c.Z_FINISH || _mode === c.Z_SYNC_FLUSH))) {
  4283. if (this.options.to === 'string') {
  4284. next_out_utf8 = strings.utf8border(strm.output, strm.next_out);
  4285. tail = strm.next_out - next_out_utf8;
  4286. utf8str = strings.buf2string(strm.output, next_out_utf8);
  4287. // move tail
  4288. strm.next_out = tail;
  4289. strm.avail_out = chunkSize - tail;
  4290. if (tail) { utils.arraySet(strm.output, strm.output, next_out_utf8, tail, 0); }
  4291. this.onData(utf8str);
  4292. } else {
  4293. this.onData(utils.shrinkBuf(strm.output, strm.next_out));
  4294. }
  4295. }
  4296. }
  4297. // When no more input data, we should check that internal inflate buffers
  4298. // are flushed. The only way to do it when avail_out = 0 - run one more
  4299. // inflate pass. But if output data not exists, inflate return Z_BUF_ERROR.
  4300. // Here we set flag to process this error properly.
  4301. //
  4302. // NOTE. Deflate does not return error in this case and does not needs such
  4303. // logic.
  4304. if (strm.avail_in === 0 && strm.avail_out === 0) {
  4305. allowBufError = true;
  4306. }
  4307. } while ((strm.avail_in > 0 || strm.avail_out === 0) && status !== c.Z_STREAM_END);
  4308. if (status === c.Z_STREAM_END) {
  4309. _mode = c.Z_FINISH;
  4310. }
  4311. // Finalize on the last chunk.
  4312. if (_mode === c.Z_FINISH) {
  4313. status = zlib_inflate.inflateEnd(this.strm);
  4314. this.onEnd(status);
  4315. this.ended = true;
  4316. return status === c.Z_OK;
  4317. }
  4318. // callback interim results if Z_SYNC_FLUSH.
  4319. if (_mode === c.Z_SYNC_FLUSH) {
  4320. this.onEnd(c.Z_OK);
  4321. strm.avail_out = 0;
  4322. return true;
  4323. }
  4324. return true;
  4325. };
  4326. /**
  4327. * Inflate#onData(chunk) -> Void
  4328. * - chunk (Uint8Array|Array|String): ouput data. Type of array depends
  4329. * on js engine support. When string output requested, each chunk
  4330. * will be string.
  4331. *
  4332. * By default, stores data blocks in `chunks[]` property and glue
  4333. * those in `onEnd`. Override this handler, if you need another behaviour.
  4334. **/
  4335. Inflate.prototype.onData = function (chunk) {
  4336. this.chunks.push(chunk);
  4337. };
  4338. /**
  4339. * Inflate#onEnd(status) -> Void
  4340. * - status (Number): inflate status. 0 (Z_OK) on success,
  4341. * other if not.
  4342. *
  4343. * Called either after you tell inflate that the input stream is
  4344. * complete (Z_FINISH) or should be flushed (Z_SYNC_FLUSH)
  4345. * or if an error happened. By default - join collected chunks,
  4346. * free memory and fill `results` / `err` properties.
  4347. **/
  4348. Inflate.prototype.onEnd = function (status) {
  4349. // On success - join
  4350. if (status === c.Z_OK) {
  4351. if (this.options.to === 'string') {
  4352. // Glue & convert here, until we teach pako to send
  4353. // utf8 alligned strings to onData
  4354. this.result = this.chunks.join('');
  4355. } else {
  4356. this.result = utils.flattenChunks(this.chunks);
  4357. }
  4358. }
  4359. this.chunks = [];
  4360. this.err = status;
  4361. this.msg = this.strm.msg;
  4362. };
  4363. /**
  4364. * inflate(data[, options]) -> Uint8Array|Array|String
  4365. * - data (Uint8Array|Array|String): input data to decompress.
  4366. * - options (Object): zlib inflate options.
  4367. *
  4368. * Decompress `data` with inflate/ungzip and `options`. Autodetect
  4369. * format via wrapper header by default. That's why we don't provide
  4370. * separate `ungzip` method.
  4371. *
  4372. * Supported options are:
  4373. *
  4374. * - windowBits
  4375. *
  4376. * [http://zlib.net/manual.html#Advanced](http://zlib.net/manual.html#Advanced)
  4377. * for more information.
  4378. *
  4379. * Sugar (options):
  4380. *
  4381. * - `raw` (Boolean) - say that we work with raw stream, if you don't wish to specify
  4382. * negative windowBits implicitly.
  4383. * - `to` (String) - if equal to 'string', then result will be converted
  4384. * from utf8 to utf16 (javascript) string. When string output requested,
  4385. * chunk length can differ from `chunkSize`, depending on content.
  4386. *
  4387. *
  4388. * ##### Example:
  4389. *
  4390. * ```javascript
  4391. * var pako = require('pako')
  4392. * , input = pako.deflate([1,2,3,4,5,6,7,8,9])
  4393. * , output;
  4394. *
  4395. * try {
  4396. * output = pako.inflate(input);
  4397. * } catch (err)
  4398. * console.log(err);
  4399. * }
  4400. * ```
  4401. **/
  4402. function inflate(input, options) {
  4403. var inflator = new Inflate(options);
  4404. inflator.push(input, true);
  4405. // That will never happens, if you don't cheat with options :)
  4406. if (inflator.err) { throw inflator.msg; }
  4407. return inflator.result;
  4408. }
  4409. /**
  4410. * inflateRaw(data[, options]) -> Uint8Array|Array|String
  4411. * - data (Uint8Array|Array|String): input data to decompress.
  4412. * - options (Object): zlib inflate options.
  4413. *
  4414. * The same as [[inflate]], but creates raw data, without wrapper
  4415. * (header and adler32 crc).
  4416. **/
  4417. function inflateRaw(input, options) {
  4418. options = options || {};
  4419. options.raw = true;
  4420. return inflate(input, options);
  4421. }
  4422. /**
  4423. * ungzip(data[, options]) -> Uint8Array|Array|String
  4424. * - data (Uint8Array|Array|String): input data to decompress.
  4425. * - options (Object): zlib inflate options.
  4426. *
  4427. * Just shortcut to [[inflate]], because it autodetects format
  4428. * by header.content. Done for convenience.
  4429. **/
  4430. exports.Inflate = Inflate;
  4431. exports.inflate = inflate;
  4432. exports.inflateRaw = inflateRaw;
  4433. exports.ungzip = inflate;
  4434. },{"./utils/common":32,"./utils/strings":33,"./zlib/constants":35,"./zlib/gzheader":38,"./zlib/inflate":40,"./zlib/messages":42,"./zlib/zstream":44}],32:[function(_dereq_,module,exports){
  4435. 'use strict';
  4436. var TYPED_OK = (typeof Uint8Array !== 'undefined') &&
  4437. (typeof Uint16Array !== 'undefined') &&
  4438. (typeof Int32Array !== 'undefined');
  4439. exports.assign = function (obj /*from1, from2, from3, ...*/) {
  4440. var sources = Array.prototype.slice.call(arguments, 1);
  4441. while (sources.length) {
  4442. var source = sources.shift();
  4443. if (!source) { continue; }
  4444. if (typeof source !== 'object') {
  4445. throw new TypeError(source + 'must be non-object');
  4446. }
  4447. for (var p in source) {
  4448. if (source.hasOwnProperty(p)) {
  4449. obj[p] = source[p];
  4450. }
  4451. }
  4452. }
  4453. return obj;
  4454. };
  4455. // reduce buffer size, avoiding mem copy
  4456. exports.shrinkBuf = function (buf, size) {
  4457. if (buf.length === size) { return buf; }
  4458. if (buf.subarray) { return buf.subarray(0, size); }
  4459. buf.length = size;
  4460. return buf;
  4461. };
  4462. var fnTyped = {
  4463. arraySet: function (dest, src, src_offs, len, dest_offs) {
  4464. if (src.subarray && dest.subarray) {
  4465. dest.set(src.subarray(src_offs, src_offs + len), dest_offs);
  4466. return;
  4467. }
  4468. // Fallback to ordinary array
  4469. for (var i = 0; i < len; i++) {
  4470. dest[dest_offs + i] = src[src_offs + i];
  4471. }
  4472. },
  4473. // Join array of chunks to single array.
  4474. flattenChunks: function (chunks) {
  4475. var i, l, len, pos, chunk, result;
  4476. // calculate data length
  4477. len = 0;
  4478. for (i = 0, l = chunks.length; i < l; i++) {
  4479. len += chunks[i].length;
  4480. }
  4481. // join chunks
  4482. result = new Uint8Array(len);
  4483. pos = 0;
  4484. for (i = 0, l = chunks.length; i < l; i++) {
  4485. chunk = chunks[i];
  4486. result.set(chunk, pos);
  4487. pos += chunk.length;
  4488. }
  4489. return result;
  4490. }
  4491. };
  4492. var fnUntyped = {
  4493. arraySet: function (dest, src, src_offs, len, dest_offs) {
  4494. for (var i = 0; i < len; i++) {
  4495. dest[dest_offs + i] = src[src_offs + i];
  4496. }
  4497. },
  4498. // Join array of chunks to single array.
  4499. flattenChunks: function (chunks) {
  4500. return [].concat.apply([], chunks);
  4501. }
  4502. };
  4503. // Enable/Disable typed arrays use, for testing
  4504. //
  4505. exports.setTyped = function (on) {
  4506. if (on) {
  4507. exports.Buf8 = Uint8Array;
  4508. exports.Buf16 = Uint16Array;
  4509. exports.Buf32 = Int32Array;
  4510. exports.assign(exports, fnTyped);
  4511. } else {
  4512. exports.Buf8 = Array;
  4513. exports.Buf16 = Array;
  4514. exports.Buf32 = Array;
  4515. exports.assign(exports, fnUntyped);
  4516. }
  4517. };
  4518. exports.setTyped(TYPED_OK);
  4519. },{}],33:[function(_dereq_,module,exports){
  4520. // String encode/decode helpers
  4521. 'use strict';
  4522. var utils = _dereq_('./common');
  4523. // Quick check if we can use fast array to bin string conversion
  4524. //
  4525. // - apply(Array) can fail on Android 2.2
  4526. // - apply(Uint8Array) can fail on iOS 5.1 Safary
  4527. //
  4528. var STR_APPLY_OK = true;
  4529. var STR_APPLY_UIA_OK = true;
  4530. try { String.fromCharCode.apply(null, [ 0 ]); } catch (__) { STR_APPLY_OK = false; }
  4531. try { String.fromCharCode.apply(null, new Uint8Array(1)); } catch (__) { STR_APPLY_UIA_OK = false; }
  4532. // Table with utf8 lengths (calculated by first byte of sequence)
  4533. // Note, that 5 & 6-byte values and some 4-byte values can not be represented in JS,
  4534. // because max possible codepoint is 0x10ffff
  4535. var _utf8len = new utils.Buf8(256);
  4536. for (var q = 0; q < 256; q++) {
  4537. _utf8len[q] = (q >= 252 ? 6 : q >= 248 ? 5 : q >= 240 ? 4 : q >= 224 ? 3 : q >= 192 ? 2 : 1);
  4538. }
  4539. _utf8len[254] = _utf8len[254] = 1; // Invalid sequence start
  4540. // convert string to array (typed, when possible)
  4541. exports.string2buf = function (str) {
  4542. var buf, c, c2, m_pos, i, str_len = str.length, buf_len = 0;
  4543. // count binary size
  4544. for (m_pos = 0; m_pos < str_len; m_pos++) {
  4545. c = str.charCodeAt(m_pos);
  4546. if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
  4547. c2 = str.charCodeAt(m_pos + 1);
  4548. if ((c2 & 0xfc00) === 0xdc00) {
  4549. c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
  4550. m_pos++;
  4551. }
  4552. }
  4553. buf_len += c < 0x80 ? 1 : c < 0x800 ? 2 : c < 0x10000 ? 3 : 4;
  4554. }
  4555. // allocate buffer
  4556. buf = new utils.Buf8(buf_len);
  4557. // convert
  4558. for (i = 0, m_pos = 0; i < buf_len; m_pos++) {
  4559. c = str.charCodeAt(m_pos);
  4560. if ((c & 0xfc00) === 0xd800 && (m_pos + 1 < str_len)) {
  4561. c2 = str.charCodeAt(m_pos + 1);
  4562. if ((c2 & 0xfc00) === 0xdc00) {
  4563. c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);
  4564. m_pos++;
  4565. }
  4566. }
  4567. if (c < 0x80) {
  4568. /* one byte */
  4569. buf[i++] = c;
  4570. } else if (c < 0x800) {
  4571. /* two bytes */
  4572. buf[i++] = 0xC0 | (c >>> 6);
  4573. buf[i++] = 0x80 | (c & 0x3f);
  4574. } else if (c < 0x10000) {
  4575. /* three bytes */
  4576. buf[i++] = 0xE0 | (c >>> 12);
  4577. buf[i++] = 0x80 | (c >>> 6 & 0x3f);
  4578. buf[i++] = 0x80 | (c & 0x3f);
  4579. } else {
  4580. /* four bytes */
  4581. buf[i++] = 0xf0 | (c >>> 18);
  4582. buf[i++] = 0x80 | (c >>> 12 & 0x3f);
  4583. buf[i++] = 0x80 | (c >>> 6 & 0x3f);
  4584. buf[i++] = 0x80 | (c & 0x3f);
  4585. }
  4586. }
  4587. return buf;
  4588. };
  4589. // Helper (used in 2 places)
  4590. function buf2binstring(buf, len) {
  4591. // use fallback for big arrays to avoid stack overflow
  4592. if (len < 65537) {
  4593. if ((buf.subarray && STR_APPLY_UIA_OK) || (!buf.subarray && STR_APPLY_OK)) {
  4594. return String.fromCharCode.apply(null, utils.shrinkBuf(buf, len));
  4595. }
  4596. }
  4597. var result = '';
  4598. for (var i = 0; i < len; i++) {
  4599. result += String.fromCharCode(buf[i]);
  4600. }
  4601. return result;
  4602. }
  4603. // Convert byte array to binary string
  4604. exports.buf2binstring = function (buf) {
  4605. return buf2binstring(buf, buf.length);
  4606. };
  4607. // Convert binary string (typed, when possible)
  4608. exports.binstring2buf = function (str) {
  4609. var buf = new utils.Buf8(str.length);
  4610. for (var i = 0, len = buf.length; i < len; i++) {
  4611. buf[i] = str.charCodeAt(i);
  4612. }
  4613. return buf;
  4614. };
  4615. // convert array to string
  4616. exports.buf2string = function (buf, max) {
  4617. var i, out, c, c_len;
  4618. var len = max || buf.length;
  4619. // Reserve max possible length (2 words per char)
  4620. // NB: by unknown reasons, Array is significantly faster for
  4621. // String.fromCharCode.apply than Uint16Array.
  4622. var utf16buf = new Array(len * 2);
  4623. for (out = 0, i = 0; i < len;) {
  4624. c = buf[i++];
  4625. // quick process ascii
  4626. if (c < 0x80) { utf16buf[out++] = c; continue; }
  4627. c_len = _utf8len[c];
  4628. // skip 5 & 6 byte codes
  4629. if (c_len > 4) { utf16buf[out++] = 0xfffd; i += c_len - 1; continue; }
  4630. // apply mask on first byte
  4631. c &= c_len === 2 ? 0x1f : c_len === 3 ? 0x0f : 0x07;
  4632. // join the rest
  4633. while (c_len > 1 && i < len) {
  4634. c = (c << 6) | (buf[i++] & 0x3f);
  4635. c_len--;
  4636. }
  4637. // terminated by end of string?
  4638. if (c_len > 1) { utf16buf[out++] = 0xfffd; continue; }
  4639. if (c < 0x10000) {
  4640. utf16buf[out++] = c;
  4641. } else {
  4642. c -= 0x10000;
  4643. utf16buf[out++] = 0xd800 | ((c >> 10) & 0x3ff);
  4644. utf16buf[out++] = 0xdc00 | (c & 0x3ff);
  4645. }
  4646. }
  4647. return buf2binstring(utf16buf, out);
  4648. };
  4649. // Calculate max possible position in utf8 buffer,
  4650. // that will not break sequence. If that's not possible
  4651. // - (very small limits) return max size as is.
  4652. //
  4653. // buf[] - utf8 bytes array
  4654. // max - length limit (mandatory);
  4655. exports.utf8border = function (buf, max) {
  4656. var pos;
  4657. max = max || buf.length;
  4658. if (max > buf.length) { max = buf.length; }
  4659. // go back from last position, until start of sequence found
  4660. pos = max - 1;
  4661. while (pos >= 0 && (buf[pos] & 0xC0) === 0x80) { pos--; }
  4662. // Fuckup - very small and broken sequence,
  4663. // return max, because we should return something anyway.
  4664. if (pos < 0) { return max; }
  4665. // If we came to start of buffer - that means vuffer is too small,
  4666. // return max too.
  4667. if (pos === 0) { return max; }
  4668. return (pos + _utf8len[buf[pos]] > max) ? pos : max;
  4669. };
  4670. },{"./common":32}],34:[function(_dereq_,module,exports){
  4671. 'use strict';
  4672. // Note: adler32 takes 12% for level 0 and 2% for level 6.
  4673. // It doesn't worth to make additional optimizationa as in original.
  4674. // Small size is preferable.
  4675. function adler32(adler, buf, len, pos) {
  4676. var s1 = (adler & 0xffff) |0,
  4677. s2 = ((adler >>> 16) & 0xffff) |0,
  4678. n = 0;
  4679. while (len !== 0) {
  4680. // Set limit ~ twice less than 5552, to keep
  4681. // s2 in 31-bits, because we force signed ints.
  4682. // in other case %= will fail.
  4683. n = len > 2000 ? 2000 : len;
  4684. len -= n;
  4685. do {
  4686. s1 = (s1 + buf[pos++]) |0;
  4687. s2 = (s2 + s1) |0;
  4688. } while (--n);
  4689. s1 %= 65521;
  4690. s2 %= 65521;
  4691. }
  4692. return (s1 | (s2 << 16)) |0;
  4693. }
  4694. module.exports = adler32;
  4695. },{}],35:[function(_dereq_,module,exports){
  4696. 'use strict';
  4697. module.exports = {
  4698. /* Allowed flush values; see deflate() and inflate() below for details */
  4699. Z_NO_FLUSH: 0,
  4700. Z_PARTIAL_FLUSH: 1,
  4701. Z_SYNC_FLUSH: 2,
  4702. Z_FULL_FLUSH: 3,
  4703. Z_FINISH: 4,
  4704. Z_BLOCK: 5,
  4705. Z_TREES: 6,
  4706. /* Return codes for the compression/decompression functions. Negative values
  4707. * are errors, positive values are used for special but normal events.
  4708. */
  4709. Z_OK: 0,
  4710. Z_STREAM_END: 1,
  4711. Z_NEED_DICT: 2,
  4712. Z_ERRNO: -1,
  4713. Z_STREAM_ERROR: -2,
  4714. Z_DATA_ERROR: -3,
  4715. //Z_MEM_ERROR: -4,
  4716. Z_BUF_ERROR: -5,
  4717. //Z_VERSION_ERROR: -6,
  4718. /* compression levels */
  4719. Z_NO_COMPRESSION: 0,
  4720. Z_BEST_SPEED: 1,
  4721. Z_BEST_COMPRESSION: 9,
  4722. Z_DEFAULT_COMPRESSION: -1,
  4723. Z_FILTERED: 1,
  4724. Z_HUFFMAN_ONLY: 2,
  4725. Z_RLE: 3,
  4726. Z_FIXED: 4,
  4727. Z_DEFAULT_STRATEGY: 0,
  4728. /* Possible values of the data_type field (though see inflate()) */
  4729. Z_BINARY: 0,
  4730. Z_TEXT: 1,
  4731. //Z_ASCII: 1, // = Z_TEXT (deprecated)
  4732. Z_UNKNOWN: 2,
  4733. /* The deflate compression method */
  4734. Z_DEFLATED: 8
  4735. //Z_NULL: null // Use -1 or null inline, depending on var type
  4736. };
  4737. },{}],36:[function(_dereq_,module,exports){
  4738. 'use strict';
  4739. // Note: we can't get significant speed boost here.
  4740. // So write code to minimize size - no pregenerated tables
  4741. // and array tools dependencies.
  4742. // Use ordinary array, since untyped makes no boost here
  4743. function makeTable() {
  4744. var c, table = [];
  4745. for (var n = 0; n < 256; n++) {
  4746. c = n;
  4747. for (var k = 0; k < 8; k++) {
  4748. c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
  4749. }
  4750. table[n] = c;
  4751. }
  4752. return table;
  4753. }
  4754. // Create table on load. Just 255 signed longs. Not a problem.
  4755. var crcTable = makeTable();
  4756. function crc32(crc, buf, len, pos) {
  4757. var t = crcTable,
  4758. end = pos + len;
  4759. crc ^= -1;
  4760. for (var i = pos; i < end; i++) {
  4761. crc = (crc >>> 8) ^ t[(crc ^ buf[i]) & 0xFF];
  4762. }
  4763. return (crc ^ (-1)); // >>> 0;
  4764. }
  4765. module.exports = crc32;
  4766. },{}],37:[function(_dereq_,module,exports){
  4767. 'use strict';
  4768. var utils = _dereq_('../utils/common');
  4769. var trees = _dereq_('./trees');
  4770. var adler32 = _dereq_('./adler32');
  4771. var crc32 = _dereq_('./crc32');
  4772. var msg = _dereq_('./messages');
  4773. /* Public constants ==========================================================*/
  4774. /* ===========================================================================*/
  4775. /* Allowed flush values; see deflate() and inflate() below for details */
  4776. var Z_NO_FLUSH = 0;
  4777. var Z_PARTIAL_FLUSH = 1;
  4778. //var Z_SYNC_FLUSH = 2;
  4779. var Z_FULL_FLUSH = 3;
  4780. var Z_FINISH = 4;
  4781. var Z_BLOCK = 5;
  4782. //var Z_TREES = 6;
  4783. /* Return codes for the compression/decompression functions. Negative values
  4784. * are errors, positive values are used for special but normal events.
  4785. */
  4786. var Z_OK = 0;
  4787. var Z_STREAM_END = 1;
  4788. //var Z_NEED_DICT = 2;
  4789. //var Z_ERRNO = -1;
  4790. var Z_STREAM_ERROR = -2;
  4791. var Z_DATA_ERROR = -3;
  4792. //var Z_MEM_ERROR = -4;
  4793. var Z_BUF_ERROR = -5;
  4794. //var Z_VERSION_ERROR = -6;
  4795. /* compression levels */
  4796. //var Z_NO_COMPRESSION = 0;
  4797. //var Z_BEST_SPEED = 1;
  4798. //var Z_BEST_COMPRESSION = 9;
  4799. var Z_DEFAULT_COMPRESSION = -1;
  4800. var Z_FILTERED = 1;
  4801. var Z_HUFFMAN_ONLY = 2;
  4802. var Z_RLE = 3;
  4803. var Z_FIXED = 4;
  4804. var Z_DEFAULT_STRATEGY = 0;
  4805. /* Possible values of the data_type field (though see inflate()) */
  4806. //var Z_BINARY = 0;
  4807. //var Z_TEXT = 1;
  4808. //var Z_ASCII = 1; // = Z_TEXT
  4809. var Z_UNKNOWN = 2;
  4810. /* The deflate compression method */
  4811. var Z_DEFLATED = 8;
  4812. /*============================================================================*/
  4813. var MAX_MEM_LEVEL = 9;
  4814. /* Maximum value for memLevel in deflateInit2 */
  4815. var MAX_WBITS = 15;
  4816. /* 32K LZ77 window */
  4817. var DEF_MEM_LEVEL = 8;
  4818. var LENGTH_CODES = 29;
  4819. /* number of length codes, not counting the special END_BLOCK code */
  4820. var LITERALS = 256;
  4821. /* number of literal bytes 0..255 */
  4822. var L_CODES = LITERALS + 1 + LENGTH_CODES;
  4823. /* number of Literal or Length codes, including the END_BLOCK code */
  4824. var D_CODES = 30;
  4825. /* number of distance codes */
  4826. var BL_CODES = 19;
  4827. /* number of codes used to transfer the bit lengths */
  4828. var HEAP_SIZE = 2 * L_CODES + 1;
  4829. /* maximum heap size */
  4830. var MAX_BITS = 15;
  4831. /* All codes must not exceed MAX_BITS bits */
  4832. var MIN_MATCH = 3;
  4833. var MAX_MATCH = 258;
  4834. var MIN_LOOKAHEAD = (MAX_MATCH + MIN_MATCH + 1);
  4835. var PRESET_DICT = 0x20;
  4836. var INIT_STATE = 42;
  4837. var EXTRA_STATE = 69;
  4838. var NAME_STATE = 73;
  4839. var COMMENT_STATE = 91;
  4840. var HCRC_STATE = 103;
  4841. var BUSY_STATE = 113;
  4842. var FINISH_STATE = 666;
  4843. var BS_NEED_MORE = 1; /* block not completed, need more input or more output */
  4844. var BS_BLOCK_DONE = 2; /* block flush performed */
  4845. var BS_FINISH_STARTED = 3; /* finish started, need only more output at next deflate */
  4846. var BS_FINISH_DONE = 4; /* finish done, accept no more input or output */
  4847. var OS_CODE = 0x03; // Unix :) . Don't detect, use this default.
  4848. function err(strm, errorCode) {
  4849. strm.msg = msg[errorCode];
  4850. return errorCode;
  4851. }
  4852. function rank(f) {
  4853. return ((f) << 1) - ((f) > 4 ? 9 : 0);
  4854. }
  4855. function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
  4856. /* =========================================================================
  4857. * Flush as much pending output as possible. All deflate() output goes
  4858. * through this function so some applications may wish to modify it
  4859. * to avoid allocating a large strm->output buffer and copying into it.
  4860. * (See also read_buf()).
  4861. */
  4862. function flush_pending(strm) {
  4863. var s = strm.state;
  4864. //_tr_flush_bits(s);
  4865. var len = s.pending;
  4866. if (len > strm.avail_out) {
  4867. len = strm.avail_out;
  4868. }
  4869. if (len === 0) { return; }
  4870. utils.arraySet(strm.output, s.pending_buf, s.pending_out, len, strm.next_out);
  4871. strm.next_out += len;
  4872. s.pending_out += len;
  4873. strm.total_out += len;
  4874. strm.avail_out -= len;
  4875. s.pending -= len;
  4876. if (s.pending === 0) {
  4877. s.pending_out = 0;
  4878. }
  4879. }
  4880. function flush_block_only(s, last) {
  4881. trees._tr_flush_block(s, (s.block_start >= 0 ? s.block_start : -1), s.strstart - s.block_start, last);
  4882. s.block_start = s.strstart;
  4883. flush_pending(s.strm);
  4884. }
  4885. function put_byte(s, b) {
  4886. s.pending_buf[s.pending++] = b;
  4887. }
  4888. /* =========================================================================
  4889. * Put a short in the pending buffer. The 16-bit value is put in MSB order.
  4890. * IN assertion: the stream state is correct and there is enough room in
  4891. * pending_buf.
  4892. */
  4893. function putShortMSB(s, b) {
  4894. // put_byte(s, (Byte)(b >> 8));
  4895. // put_byte(s, (Byte)(b & 0xff));
  4896. s.pending_buf[s.pending++] = (b >>> 8) & 0xff;
  4897. s.pending_buf[s.pending++] = b & 0xff;
  4898. }
  4899. /* ===========================================================================
  4900. * Read a new buffer from the current input stream, update the adler32
  4901. * and total number of bytes read. All deflate() input goes through
  4902. * this function so some applications may wish to modify it to avoid
  4903. * allocating a large strm->input buffer and copying from it.
  4904. * (See also flush_pending()).
  4905. */
  4906. function read_buf(strm, buf, start, size) {
  4907. var len = strm.avail_in;
  4908. if (len > size) { len = size; }
  4909. if (len === 0) { return 0; }
  4910. strm.avail_in -= len;
  4911. // zmemcpy(buf, strm->next_in, len);
  4912. utils.arraySet(buf, strm.input, strm.next_in, len, start);
  4913. if (strm.state.wrap === 1) {
  4914. strm.adler = adler32(strm.adler, buf, len, start);
  4915. }
  4916. else if (strm.state.wrap === 2) {
  4917. strm.adler = crc32(strm.adler, buf, len, start);
  4918. }
  4919. strm.next_in += len;
  4920. strm.total_in += len;
  4921. return len;
  4922. }
  4923. /* ===========================================================================
  4924. * Set match_start to the longest match starting at the given string and
  4925. * return its length. Matches shorter or equal to prev_length are discarded,
  4926. * in which case the result is equal to prev_length and match_start is
  4927. * garbage.
  4928. * IN assertions: cur_match is the head of the hash chain for the current
  4929. * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
  4930. * OUT assertion: the match length is not greater than s->lookahead.
  4931. */
  4932. function longest_match(s, cur_match) {
  4933. var chain_length = s.max_chain_length; /* max hash chain length */
  4934. var scan = s.strstart; /* current string */
  4935. var match; /* matched string */
  4936. var len; /* length of current match */
  4937. var best_len = s.prev_length; /* best match length so far */
  4938. var nice_match = s.nice_match; /* stop if match long enough */
  4939. var limit = (s.strstart > (s.w_size - MIN_LOOKAHEAD)) ?
  4940. s.strstart - (s.w_size - MIN_LOOKAHEAD) : 0/*NIL*/;
  4941. var _win = s.window; // shortcut
  4942. var wmask = s.w_mask;
  4943. var prev = s.prev;
  4944. /* Stop when cur_match becomes <= limit. To simplify the code,
  4945. * we prevent matches with the string of window index 0.
  4946. */
  4947. var strend = s.strstart + MAX_MATCH;
  4948. var scan_end1 = _win[scan + best_len - 1];
  4949. var scan_end = _win[scan + best_len];
  4950. /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
  4951. * It is easy to get rid of this optimization if necessary.
  4952. */
  4953. // Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  4954. /* Do not waste too much time if we already have a good match: */
  4955. if (s.prev_length >= s.good_match) {
  4956. chain_length >>= 2;
  4957. }
  4958. /* Do not look for matches beyond the end of the input. This is necessary
  4959. * to make deflate deterministic.
  4960. */
  4961. if (nice_match > s.lookahead) { nice_match = s.lookahead; }
  4962. // Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  4963. do {
  4964. // Assert(cur_match < s->strstart, "no future");
  4965. match = cur_match;
  4966. /* Skip to next match if the match length cannot increase
  4967. * or if the match length is less than 2. Note that the checks below
  4968. * for insufficient lookahead only occur occasionally for performance
  4969. * reasons. Therefore uninitialized memory will be accessed, and
  4970. * conditional jumps will be made that depend on those values.
  4971. * However the length of the match is limited to the lookahead, so
  4972. * the output of deflate is not affected by the uninitialized values.
  4973. */
  4974. if (_win[match + best_len] !== scan_end ||
  4975. _win[match + best_len - 1] !== scan_end1 ||
  4976. _win[match] !== _win[scan] ||
  4977. _win[++match] !== _win[scan + 1]) {
  4978. continue;
  4979. }
  4980. /* The check at best_len-1 can be removed because it will be made
  4981. * again later. (This heuristic is not always a win.)
  4982. * It is not necessary to compare scan[2] and match[2] since they
  4983. * are always equal when the other bytes match, given that
  4984. * the hash keys are equal and that HASH_BITS >= 8.
  4985. */
  4986. scan += 2;
  4987. match++;
  4988. // Assert(*scan == *match, "match[2]?");
  4989. /* We check for insufficient lookahead only every 8th comparison;
  4990. * the 256th check will be made at strstart+258.
  4991. */
  4992. do {
  4993. /*jshint noempty:false*/
  4994. } while (_win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
  4995. _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
  4996. _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
  4997. _win[++scan] === _win[++match] && _win[++scan] === _win[++match] &&
  4998. scan < strend);
  4999. // Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  5000. len = MAX_MATCH - (strend - scan);
  5001. scan = strend - MAX_MATCH;
  5002. if (len > best_len) {
  5003. s.match_start = cur_match;
  5004. best_len = len;
  5005. if (len >= nice_match) {
  5006. break;
  5007. }
  5008. scan_end1 = _win[scan + best_len - 1];
  5009. scan_end = _win[scan + best_len];
  5010. }
  5011. } while ((cur_match = prev[cur_match & wmask]) > limit && --chain_length !== 0);
  5012. if (best_len <= s.lookahead) {
  5013. return best_len;
  5014. }
  5015. return s.lookahead;
  5016. }
  5017. /* ===========================================================================
  5018. * Fill the window when the lookahead becomes insufficient.
  5019. * Updates strstart and lookahead.
  5020. *
  5021. * IN assertion: lookahead < MIN_LOOKAHEAD
  5022. * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
  5023. * At least one byte has been read, or avail_in == 0; reads are
  5024. * performed for at least two bytes (required for the zip translate_eol
  5025. * option -- not supported here).
  5026. */
  5027. function fill_window(s) {
  5028. var _w_size = s.w_size;
  5029. var p, n, m, more, str;
  5030. //Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead");
  5031. do {
  5032. more = s.window_size - s.lookahead - s.strstart;
  5033. // JS ints have 32 bit, block below not needed
  5034. /* Deal with !@#$% 64K limit: */
  5035. //if (sizeof(int) <= 2) {
  5036. // if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  5037. // more = wsize;
  5038. //
  5039. // } else if (more == (unsigned)(-1)) {
  5040. // /* Very unlikely, but possible on 16 bit machine if
  5041. // * strstart == 0 && lookahead == 1 (input done a byte at time)
  5042. // */
  5043. // more--;
  5044. // }
  5045. //}
  5046. /* If the window is almost full and there is insufficient lookahead,
  5047. * move the upper half to the lower one to make room in the upper half.
  5048. */
  5049. if (s.strstart >= _w_size + (_w_size - MIN_LOOKAHEAD)) {
  5050. utils.arraySet(s.window, s.window, _w_size, _w_size, 0);
  5051. s.match_start -= _w_size;
  5052. s.strstart -= _w_size;
  5053. /* we now have strstart >= MAX_DIST */
  5054. s.block_start -= _w_size;
  5055. /* Slide the hash table (could be avoided with 32 bit values
  5056. at the expense of memory usage). We slide even when level == 0
  5057. to keep the hash table consistent if we switch back to level > 0
  5058. later. (Using level 0 permanently is not an optimal usage of
  5059. zlib, so we don't care about this pathological case.)
  5060. */
  5061. n = s.hash_size;
  5062. p = n;
  5063. do {
  5064. m = s.head[--p];
  5065. s.head[p] = (m >= _w_size ? m - _w_size : 0);
  5066. } while (--n);
  5067. n = _w_size;
  5068. p = n;
  5069. do {
  5070. m = s.prev[--p];
  5071. s.prev[p] = (m >= _w_size ? m - _w_size : 0);
  5072. /* If n is not on any hash chain, prev[n] is garbage but
  5073. * its value will never be used.
  5074. */
  5075. } while (--n);
  5076. more += _w_size;
  5077. }
  5078. if (s.strm.avail_in === 0) {
  5079. break;
  5080. }
  5081. /* If there was no sliding:
  5082. * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
  5083. * more == window_size - lookahead - strstart
  5084. * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
  5085. * => more >= window_size - 2*WSIZE + 2
  5086. * In the BIG_MEM or MMAP case (not yet supported),
  5087. * window_size == input_size + MIN_LOOKAHEAD &&
  5088. * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
  5089. * Otherwise, window_size == 2*WSIZE so more >= 2.
  5090. * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
  5091. */
  5092. //Assert(more >= 2, "more < 2");
  5093. n = read_buf(s.strm, s.window, s.strstart + s.lookahead, more);
  5094. s.lookahead += n;
  5095. /* Initialize the hash value now that we have some input: */
  5096. if (s.lookahead + s.insert >= MIN_MATCH) {
  5097. str = s.strstart - s.insert;
  5098. s.ins_h = s.window[str];
  5099. /* UPDATE_HASH(s, s->ins_h, s->window[str + 1]); */
  5100. s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + 1]) & s.hash_mask;
  5101. //#if MIN_MATCH != 3
  5102. // Call update_hash() MIN_MATCH-3 more times
  5103. //#endif
  5104. while (s.insert) {
  5105. /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
  5106. s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
  5107. s.prev[str & s.w_mask] = s.head[s.ins_h];
  5108. s.head[s.ins_h] = str;
  5109. str++;
  5110. s.insert--;
  5111. if (s.lookahead + s.insert < MIN_MATCH) {
  5112. break;
  5113. }
  5114. }
  5115. }
  5116. /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
  5117. * but this is not important since only literal bytes will be emitted.
  5118. */
  5119. } while (s.lookahead < MIN_LOOKAHEAD && s.strm.avail_in !== 0);
  5120. /* If the WIN_INIT bytes after the end of the current data have never been
  5121. * written, then zero those bytes in order to avoid memory check reports of
  5122. * the use of uninitialized (or uninitialised as Julian writes) bytes by
  5123. * the longest match routines. Update the high water mark for the next
  5124. * time through here. WIN_INIT is set to MAX_MATCH since the longest match
  5125. * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead.
  5126. */
  5127. // if (s.high_water < s.window_size) {
  5128. // var curr = s.strstart + s.lookahead;
  5129. // var init = 0;
  5130. //
  5131. // if (s.high_water < curr) {
  5132. // /* Previous high water mark below current data -- zero WIN_INIT
  5133. // * bytes or up to end of window, whichever is less.
  5134. // */
  5135. // init = s.window_size - curr;
  5136. // if (init > WIN_INIT)
  5137. // init = WIN_INIT;
  5138. // zmemzero(s->window + curr, (unsigned)init);
  5139. // s->high_water = curr + init;
  5140. // }
  5141. // else if (s->high_water < (ulg)curr + WIN_INIT) {
  5142. // /* High water mark at or above current data, but below current data
  5143. // * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up
  5144. // * to end of window, whichever is less.
  5145. // */
  5146. // init = (ulg)curr + WIN_INIT - s->high_water;
  5147. // if (init > s->window_size - s->high_water)
  5148. // init = s->window_size - s->high_water;
  5149. // zmemzero(s->window + s->high_water, (unsigned)init);
  5150. // s->high_water += init;
  5151. // }
  5152. // }
  5153. //
  5154. // Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD,
  5155. // "not enough room for search");
  5156. }
  5157. /* ===========================================================================
  5158. * Copy without compression as much as possible from the input stream, return
  5159. * the current block state.
  5160. * This function does not insert new strings in the dictionary since
  5161. * uncompressible data is probably not useful. This function is used
  5162. * only for the level=0 compression option.
  5163. * NOTE: this function should be optimized to avoid extra copying from
  5164. * window to pending_buf.
  5165. */
  5166. function deflate_stored(s, flush) {
  5167. /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
  5168. * to pending_buf_size, and each stored block has a 5 byte header:
  5169. */
  5170. var max_block_size = 0xffff;
  5171. if (max_block_size > s.pending_buf_size - 5) {
  5172. max_block_size = s.pending_buf_size - 5;
  5173. }
  5174. /* Copy as much as possible from input to output: */
  5175. for (;;) {
  5176. /* Fill the window as much as possible: */
  5177. if (s.lookahead <= 1) {
  5178. //Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  5179. // s->block_start >= (long)s->w_size, "slide too late");
  5180. // if (!(s.strstart < s.w_size + (s.w_size - MIN_LOOKAHEAD) ||
  5181. // s.block_start >= s.w_size)) {
  5182. // throw new Error("slide too late");
  5183. // }
  5184. fill_window(s);
  5185. if (s.lookahead === 0 && flush === Z_NO_FLUSH) {
  5186. return BS_NEED_MORE;
  5187. }
  5188. if (s.lookahead === 0) {
  5189. break;
  5190. }
  5191. /* flush the current block */
  5192. }
  5193. //Assert(s->block_start >= 0L, "block gone");
  5194. // if (s.block_start < 0) throw new Error("block gone");
  5195. s.strstart += s.lookahead;
  5196. s.lookahead = 0;
  5197. /* Emit a stored block if pending_buf will be full: */
  5198. var max_start = s.block_start + max_block_size;
  5199. if (s.strstart === 0 || s.strstart >= max_start) {
  5200. /* strstart == 0 is possible when wraparound on 16-bit machine */
  5201. s.lookahead = s.strstart - max_start;
  5202. s.strstart = max_start;
  5203. /*** FLUSH_BLOCK(s, 0); ***/
  5204. flush_block_only(s, false);
  5205. if (s.strm.avail_out === 0) {
  5206. return BS_NEED_MORE;
  5207. }
  5208. /***/
  5209. }
  5210. /* Flush if we may have to slide, otherwise block_start may become
  5211. * negative and the data will be gone:
  5212. */
  5213. if (s.strstart - s.block_start >= (s.w_size - MIN_LOOKAHEAD)) {
  5214. /*** FLUSH_BLOCK(s, 0); ***/
  5215. flush_block_only(s, false);
  5216. if (s.strm.avail_out === 0) {
  5217. return BS_NEED_MORE;
  5218. }
  5219. /***/
  5220. }
  5221. }
  5222. s.insert = 0;
  5223. if (flush === Z_FINISH) {
  5224. /*** FLUSH_BLOCK(s, 1); ***/
  5225. flush_block_only(s, true);
  5226. if (s.strm.avail_out === 0) {
  5227. return BS_FINISH_STARTED;
  5228. }
  5229. /***/
  5230. return BS_FINISH_DONE;
  5231. }
  5232. if (s.strstart > s.block_start) {
  5233. /*** FLUSH_BLOCK(s, 0); ***/
  5234. flush_block_only(s, false);
  5235. if (s.strm.avail_out === 0) {
  5236. return BS_NEED_MORE;
  5237. }
  5238. /***/
  5239. }
  5240. return BS_NEED_MORE;
  5241. }
  5242. /* ===========================================================================
  5243. * Compress as much as possible from the input stream, return the current
  5244. * block state.
  5245. * This function does not perform lazy evaluation of matches and inserts
  5246. * new strings in the dictionary only for unmatched strings or for short
  5247. * matches. It is used only for the fast compression options.
  5248. */
  5249. function deflate_fast(s, flush) {
  5250. var hash_head; /* head of the hash chain */
  5251. var bflush; /* set if current block must be flushed */
  5252. for (;;) {
  5253. /* Make sure that we always have enough lookahead, except
  5254. * at the end of the input file. We need MAX_MATCH bytes
  5255. * for the next match, plus MIN_MATCH bytes to insert the
  5256. * string following the next match.
  5257. */
  5258. if (s.lookahead < MIN_LOOKAHEAD) {
  5259. fill_window(s);
  5260. if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
  5261. return BS_NEED_MORE;
  5262. }
  5263. if (s.lookahead === 0) {
  5264. break; /* flush the current block */
  5265. }
  5266. }
  5267. /* Insert the string window[strstart .. strstart+2] in the
  5268. * dictionary, and set hash_head to the head of the hash chain:
  5269. */
  5270. hash_head = 0/*NIL*/;
  5271. if (s.lookahead >= MIN_MATCH) {
  5272. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  5273. s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  5274. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  5275. s.head[s.ins_h] = s.strstart;
  5276. /***/
  5277. }
  5278. /* Find the longest match, discarding those <= prev_length.
  5279. * At this point we have always match_length < MIN_MATCH
  5280. */
  5281. if (hash_head !== 0/*NIL*/ && ((s.strstart - hash_head) <= (s.w_size - MIN_LOOKAHEAD))) {
  5282. /* To simplify the code, we prevent matches with the string
  5283. * of window index 0 (in particular we have to avoid a match
  5284. * of the string with itself at the start of the input file).
  5285. */
  5286. s.match_length = longest_match(s, hash_head);
  5287. /* longest_match() sets match_start */
  5288. }
  5289. if (s.match_length >= MIN_MATCH) {
  5290. // check_match(s, s.strstart, s.match_start, s.match_length); // for debug only
  5291. /*** _tr_tally_dist(s, s.strstart - s.match_start,
  5292. s.match_length - MIN_MATCH, bflush); ***/
  5293. bflush = trees._tr_tally(s, s.strstart - s.match_start, s.match_length - MIN_MATCH);
  5294. s.lookahead -= s.match_length;
  5295. /* Insert new strings in the hash table only if the match length
  5296. * is not too large. This saves time but degrades compression.
  5297. */
  5298. if (s.match_length <= s.max_lazy_match/*max_insert_length*/ && s.lookahead >= MIN_MATCH) {
  5299. s.match_length--; /* string at strstart already in table */
  5300. do {
  5301. s.strstart++;
  5302. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  5303. s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  5304. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  5305. s.head[s.ins_h] = s.strstart;
  5306. /***/
  5307. /* strstart never exceeds WSIZE-MAX_MATCH, so there are
  5308. * always MIN_MATCH bytes ahead.
  5309. */
  5310. } while (--s.match_length !== 0);
  5311. s.strstart++;
  5312. } else
  5313. {
  5314. s.strstart += s.match_length;
  5315. s.match_length = 0;
  5316. s.ins_h = s.window[s.strstart];
  5317. /* UPDATE_HASH(s, s.ins_h, s.window[s.strstart+1]); */
  5318. s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + 1]) & s.hash_mask;
  5319. //#if MIN_MATCH != 3
  5320. // Call UPDATE_HASH() MIN_MATCH-3 more times
  5321. //#endif
  5322. /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
  5323. * matter since it will be recomputed at next deflate call.
  5324. */
  5325. }
  5326. } else {
  5327. /* No match, output a literal byte */
  5328. //Tracevv((stderr,"%c", s.window[s.strstart]));
  5329. /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  5330. bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
  5331. s.lookahead--;
  5332. s.strstart++;
  5333. }
  5334. if (bflush) {
  5335. /*** FLUSH_BLOCK(s, 0); ***/
  5336. flush_block_only(s, false);
  5337. if (s.strm.avail_out === 0) {
  5338. return BS_NEED_MORE;
  5339. }
  5340. /***/
  5341. }
  5342. }
  5343. s.insert = ((s.strstart < (MIN_MATCH - 1)) ? s.strstart : MIN_MATCH - 1);
  5344. if (flush === Z_FINISH) {
  5345. /*** FLUSH_BLOCK(s, 1); ***/
  5346. flush_block_only(s, true);
  5347. if (s.strm.avail_out === 0) {
  5348. return BS_FINISH_STARTED;
  5349. }
  5350. /***/
  5351. return BS_FINISH_DONE;
  5352. }
  5353. if (s.last_lit) {
  5354. /*** FLUSH_BLOCK(s, 0); ***/
  5355. flush_block_only(s, false);
  5356. if (s.strm.avail_out === 0) {
  5357. return BS_NEED_MORE;
  5358. }
  5359. /***/
  5360. }
  5361. return BS_BLOCK_DONE;
  5362. }
  5363. /* ===========================================================================
  5364. * Same as above, but achieves better compression. We use a lazy
  5365. * evaluation for matches: a match is finally adopted only if there is
  5366. * no better match at the next window position.
  5367. */
  5368. function deflate_slow(s, flush) {
  5369. var hash_head; /* head of hash chain */
  5370. var bflush; /* set if current block must be flushed */
  5371. var max_insert;
  5372. /* Process the input block. */
  5373. for (;;) {
  5374. /* Make sure that we always have enough lookahead, except
  5375. * at the end of the input file. We need MAX_MATCH bytes
  5376. * for the next match, plus MIN_MATCH bytes to insert the
  5377. * string following the next match.
  5378. */
  5379. if (s.lookahead < MIN_LOOKAHEAD) {
  5380. fill_window(s);
  5381. if (s.lookahead < MIN_LOOKAHEAD && flush === Z_NO_FLUSH) {
  5382. return BS_NEED_MORE;
  5383. }
  5384. if (s.lookahead === 0) { break; } /* flush the current block */
  5385. }
  5386. /* Insert the string window[strstart .. strstart+2] in the
  5387. * dictionary, and set hash_head to the head of the hash chain:
  5388. */
  5389. hash_head = 0/*NIL*/;
  5390. if (s.lookahead >= MIN_MATCH) {
  5391. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  5392. s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  5393. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  5394. s.head[s.ins_h] = s.strstart;
  5395. /***/
  5396. }
  5397. /* Find the longest match, discarding those <= prev_length.
  5398. */
  5399. s.prev_length = s.match_length;
  5400. s.prev_match = s.match_start;
  5401. s.match_length = MIN_MATCH - 1;
  5402. if (hash_head !== 0/*NIL*/ && s.prev_length < s.max_lazy_match &&
  5403. s.strstart - hash_head <= (s.w_size - MIN_LOOKAHEAD)/*MAX_DIST(s)*/) {
  5404. /* To simplify the code, we prevent matches with the string
  5405. * of window index 0 (in particular we have to avoid a match
  5406. * of the string with itself at the start of the input file).
  5407. */
  5408. s.match_length = longest_match(s, hash_head);
  5409. /* longest_match() sets match_start */
  5410. if (s.match_length <= 5 &&
  5411. (s.strategy === Z_FILTERED || (s.match_length === MIN_MATCH && s.strstart - s.match_start > 4096/*TOO_FAR*/))) {
  5412. /* If prev_match is also MIN_MATCH, match_start is garbage
  5413. * but we will ignore the current match anyway.
  5414. */
  5415. s.match_length = MIN_MATCH - 1;
  5416. }
  5417. }
  5418. /* If there was a match at the previous step and the current
  5419. * match is not better, output the previous match:
  5420. */
  5421. if (s.prev_length >= MIN_MATCH && s.match_length <= s.prev_length) {
  5422. max_insert = s.strstart + s.lookahead - MIN_MATCH;
  5423. /* Do not insert strings in hash table beyond this. */
  5424. //check_match(s, s.strstart-1, s.prev_match, s.prev_length);
  5425. /***_tr_tally_dist(s, s.strstart - 1 - s.prev_match,
  5426. s.prev_length - MIN_MATCH, bflush);***/
  5427. bflush = trees._tr_tally(s, s.strstart - 1 - s.prev_match, s.prev_length - MIN_MATCH);
  5428. /* Insert in hash table all strings up to the end of the match.
  5429. * strstart-1 and strstart are already inserted. If there is not
  5430. * enough lookahead, the last two strings are not inserted in
  5431. * the hash table.
  5432. */
  5433. s.lookahead -= s.prev_length - 1;
  5434. s.prev_length -= 2;
  5435. do {
  5436. if (++s.strstart <= max_insert) {
  5437. /*** INSERT_STRING(s, s.strstart, hash_head); ***/
  5438. s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[s.strstart + MIN_MATCH - 1]) & s.hash_mask;
  5439. hash_head = s.prev[s.strstart & s.w_mask] = s.head[s.ins_h];
  5440. s.head[s.ins_h] = s.strstart;
  5441. /***/
  5442. }
  5443. } while (--s.prev_length !== 0);
  5444. s.match_available = 0;
  5445. s.match_length = MIN_MATCH - 1;
  5446. s.strstart++;
  5447. if (bflush) {
  5448. /*** FLUSH_BLOCK(s, 0); ***/
  5449. flush_block_only(s, false);
  5450. if (s.strm.avail_out === 0) {
  5451. return BS_NEED_MORE;
  5452. }
  5453. /***/
  5454. }
  5455. } else if (s.match_available) {
  5456. /* If there was no match at the previous position, output a
  5457. * single literal. If there was a match but the current match
  5458. * is longer, truncate the previous match to a single literal.
  5459. */
  5460. //Tracevv((stderr,"%c", s->window[s->strstart-1]));
  5461. /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
  5462. bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
  5463. if (bflush) {
  5464. /*** FLUSH_BLOCK_ONLY(s, 0) ***/
  5465. flush_block_only(s, false);
  5466. /***/
  5467. }
  5468. s.strstart++;
  5469. s.lookahead--;
  5470. if (s.strm.avail_out === 0) {
  5471. return BS_NEED_MORE;
  5472. }
  5473. } else {
  5474. /* There is no previous match to compare with, wait for
  5475. * the next step to decide.
  5476. */
  5477. s.match_available = 1;
  5478. s.strstart++;
  5479. s.lookahead--;
  5480. }
  5481. }
  5482. //Assert (flush != Z_NO_FLUSH, "no flush?");
  5483. if (s.match_available) {
  5484. //Tracevv((stderr,"%c", s->window[s->strstart-1]));
  5485. /*** _tr_tally_lit(s, s.window[s.strstart-1], bflush); ***/
  5486. bflush = trees._tr_tally(s, 0, s.window[s.strstart - 1]);
  5487. s.match_available = 0;
  5488. }
  5489. s.insert = s.strstart < MIN_MATCH - 1 ? s.strstart : MIN_MATCH - 1;
  5490. if (flush === Z_FINISH) {
  5491. /*** FLUSH_BLOCK(s, 1); ***/
  5492. flush_block_only(s, true);
  5493. if (s.strm.avail_out === 0) {
  5494. return BS_FINISH_STARTED;
  5495. }
  5496. /***/
  5497. return BS_FINISH_DONE;
  5498. }
  5499. if (s.last_lit) {
  5500. /*** FLUSH_BLOCK(s, 0); ***/
  5501. flush_block_only(s, false);
  5502. if (s.strm.avail_out === 0) {
  5503. return BS_NEED_MORE;
  5504. }
  5505. /***/
  5506. }
  5507. return BS_BLOCK_DONE;
  5508. }
  5509. /* ===========================================================================
  5510. * For Z_RLE, simply look for runs of bytes, generate matches only of distance
  5511. * one. Do not maintain a hash table. (It will be regenerated if this run of
  5512. * deflate switches away from Z_RLE.)
  5513. */
  5514. function deflate_rle(s, flush) {
  5515. var bflush; /* set if current block must be flushed */
  5516. var prev; /* byte at distance one to match */
  5517. var scan, strend; /* scan goes up to strend for length of run */
  5518. var _win = s.window;
  5519. for (;;) {
  5520. /* Make sure that we always have enough lookahead, except
  5521. * at the end of the input file. We need MAX_MATCH bytes
  5522. * for the longest run, plus one for the unrolled loop.
  5523. */
  5524. if (s.lookahead <= MAX_MATCH) {
  5525. fill_window(s);
  5526. if (s.lookahead <= MAX_MATCH && flush === Z_NO_FLUSH) {
  5527. return BS_NEED_MORE;
  5528. }
  5529. if (s.lookahead === 0) { break; } /* flush the current block */
  5530. }
  5531. /* See how many times the previous byte repeats */
  5532. s.match_length = 0;
  5533. if (s.lookahead >= MIN_MATCH && s.strstart > 0) {
  5534. scan = s.strstart - 1;
  5535. prev = _win[scan];
  5536. if (prev === _win[++scan] && prev === _win[++scan] && prev === _win[++scan]) {
  5537. strend = s.strstart + MAX_MATCH;
  5538. do {
  5539. /*jshint noempty:false*/
  5540. } while (prev === _win[++scan] && prev === _win[++scan] &&
  5541. prev === _win[++scan] && prev === _win[++scan] &&
  5542. prev === _win[++scan] && prev === _win[++scan] &&
  5543. prev === _win[++scan] && prev === _win[++scan] &&
  5544. scan < strend);
  5545. s.match_length = MAX_MATCH - (strend - scan);
  5546. if (s.match_length > s.lookahead) {
  5547. s.match_length = s.lookahead;
  5548. }
  5549. }
  5550. //Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan");
  5551. }
  5552. /* Emit match if have run of MIN_MATCH or longer, else emit literal */
  5553. if (s.match_length >= MIN_MATCH) {
  5554. //check_match(s, s.strstart, s.strstart - 1, s.match_length);
  5555. /*** _tr_tally_dist(s, 1, s.match_length - MIN_MATCH, bflush); ***/
  5556. bflush = trees._tr_tally(s, 1, s.match_length - MIN_MATCH);
  5557. s.lookahead -= s.match_length;
  5558. s.strstart += s.match_length;
  5559. s.match_length = 0;
  5560. } else {
  5561. /* No match, output a literal byte */
  5562. //Tracevv((stderr,"%c", s->window[s->strstart]));
  5563. /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  5564. bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
  5565. s.lookahead--;
  5566. s.strstart++;
  5567. }
  5568. if (bflush) {
  5569. /*** FLUSH_BLOCK(s, 0); ***/
  5570. flush_block_only(s, false);
  5571. if (s.strm.avail_out === 0) {
  5572. return BS_NEED_MORE;
  5573. }
  5574. /***/
  5575. }
  5576. }
  5577. s.insert = 0;
  5578. if (flush === Z_FINISH) {
  5579. /*** FLUSH_BLOCK(s, 1); ***/
  5580. flush_block_only(s, true);
  5581. if (s.strm.avail_out === 0) {
  5582. return BS_FINISH_STARTED;
  5583. }
  5584. /***/
  5585. return BS_FINISH_DONE;
  5586. }
  5587. if (s.last_lit) {
  5588. /*** FLUSH_BLOCK(s, 0); ***/
  5589. flush_block_only(s, false);
  5590. if (s.strm.avail_out === 0) {
  5591. return BS_NEED_MORE;
  5592. }
  5593. /***/
  5594. }
  5595. return BS_BLOCK_DONE;
  5596. }
  5597. /* ===========================================================================
  5598. * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table.
  5599. * (It will be regenerated if this run of deflate switches away from Huffman.)
  5600. */
  5601. function deflate_huff(s, flush) {
  5602. var bflush; /* set if current block must be flushed */
  5603. for (;;) {
  5604. /* Make sure that we have a literal to write. */
  5605. if (s.lookahead === 0) {
  5606. fill_window(s);
  5607. if (s.lookahead === 0) {
  5608. if (flush === Z_NO_FLUSH) {
  5609. return BS_NEED_MORE;
  5610. }
  5611. break; /* flush the current block */
  5612. }
  5613. }
  5614. /* Output a literal byte */
  5615. s.match_length = 0;
  5616. //Tracevv((stderr,"%c", s->window[s->strstart]));
  5617. /*** _tr_tally_lit(s, s.window[s.strstart], bflush); ***/
  5618. bflush = trees._tr_tally(s, 0, s.window[s.strstart]);
  5619. s.lookahead--;
  5620. s.strstart++;
  5621. if (bflush) {
  5622. /*** FLUSH_BLOCK(s, 0); ***/
  5623. flush_block_only(s, false);
  5624. if (s.strm.avail_out === 0) {
  5625. return BS_NEED_MORE;
  5626. }
  5627. /***/
  5628. }
  5629. }
  5630. s.insert = 0;
  5631. if (flush === Z_FINISH) {
  5632. /*** FLUSH_BLOCK(s, 1); ***/
  5633. flush_block_only(s, true);
  5634. if (s.strm.avail_out === 0) {
  5635. return BS_FINISH_STARTED;
  5636. }
  5637. /***/
  5638. return BS_FINISH_DONE;
  5639. }
  5640. if (s.last_lit) {
  5641. /*** FLUSH_BLOCK(s, 0); ***/
  5642. flush_block_only(s, false);
  5643. if (s.strm.avail_out === 0) {
  5644. return BS_NEED_MORE;
  5645. }
  5646. /***/
  5647. }
  5648. return BS_BLOCK_DONE;
  5649. }
  5650. /* Values for max_lazy_match, good_match and max_chain_length, depending on
  5651. * the desired pack level (0..9). The values given below have been tuned to
  5652. * exclude worst case performance for pathological files. Better values may be
  5653. * found for specific files.
  5654. */
  5655. function Config(good_length, max_lazy, nice_length, max_chain, func) {
  5656. this.good_length = good_length;
  5657. this.max_lazy = max_lazy;
  5658. this.nice_length = nice_length;
  5659. this.max_chain = max_chain;
  5660. this.func = func;
  5661. }
  5662. var configuration_table;
  5663. configuration_table = [
  5664. /* good lazy nice chain */
  5665. new Config(0, 0, 0, 0, deflate_stored), /* 0 store only */
  5666. new Config(4, 4, 8, 4, deflate_fast), /* 1 max speed, no lazy matches */
  5667. new Config(4, 5, 16, 8, deflate_fast), /* 2 */
  5668. new Config(4, 6, 32, 32, deflate_fast), /* 3 */
  5669. new Config(4, 4, 16, 16, deflate_slow), /* 4 lazy matches */
  5670. new Config(8, 16, 32, 32, deflate_slow), /* 5 */
  5671. new Config(8, 16, 128, 128, deflate_slow), /* 6 */
  5672. new Config(8, 32, 128, 256, deflate_slow), /* 7 */
  5673. new Config(32, 128, 258, 1024, deflate_slow), /* 8 */
  5674. new Config(32, 258, 258, 4096, deflate_slow) /* 9 max compression */
  5675. ];
  5676. /* ===========================================================================
  5677. * Initialize the "longest match" routines for a new zlib stream
  5678. */
  5679. function lm_init(s) {
  5680. s.window_size = 2 * s.w_size;
  5681. /*** CLEAR_HASH(s); ***/
  5682. zero(s.head); // Fill with NIL (= 0);
  5683. /* Set the default configuration parameters:
  5684. */
  5685. s.max_lazy_match = configuration_table[s.level].max_lazy;
  5686. s.good_match = configuration_table[s.level].good_length;
  5687. s.nice_match = configuration_table[s.level].nice_length;
  5688. s.max_chain_length = configuration_table[s.level].max_chain;
  5689. s.strstart = 0;
  5690. s.block_start = 0;
  5691. s.lookahead = 0;
  5692. s.insert = 0;
  5693. s.match_length = s.prev_length = MIN_MATCH - 1;
  5694. s.match_available = 0;
  5695. s.ins_h = 0;
  5696. }
  5697. function DeflateState() {
  5698. this.strm = null; /* pointer back to this zlib stream */
  5699. this.status = 0; /* as the name implies */
  5700. this.pending_buf = null; /* output still pending */
  5701. this.pending_buf_size = 0; /* size of pending_buf */
  5702. this.pending_out = 0; /* next pending byte to output to the stream */
  5703. this.pending = 0; /* nb of bytes in the pending buffer */
  5704. this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */
  5705. this.gzhead = null; /* gzip header information to write */
  5706. this.gzindex = 0; /* where in extra, name, or comment */
  5707. this.method = Z_DEFLATED; /* can only be DEFLATED */
  5708. this.last_flush = -1; /* value of flush param for previous deflate call */
  5709. this.w_size = 0; /* LZ77 window size (32K by default) */
  5710. this.w_bits = 0; /* log2(w_size) (8..16) */
  5711. this.w_mask = 0; /* w_size - 1 */
  5712. this.window = null;
  5713. /* Sliding window. Input bytes are read into the second half of the window,
  5714. * and move to the first half later to keep a dictionary of at least wSize
  5715. * bytes. With this organization, matches are limited to a distance of
  5716. * wSize-MAX_MATCH bytes, but this ensures that IO is always
  5717. * performed with a length multiple of the block size.
  5718. */
  5719. this.window_size = 0;
  5720. /* Actual size of window: 2*wSize, except when the user input buffer
  5721. * is directly used as sliding window.
  5722. */
  5723. this.prev = null;
  5724. /* Link to older string with same hash index. To limit the size of this
  5725. * array to 64K, this link is maintained only for the last 32K strings.
  5726. * An index in this array is thus a window index modulo 32K.
  5727. */
  5728. this.head = null; /* Heads of the hash chains or NIL. */
  5729. this.ins_h = 0; /* hash index of string to be inserted */
  5730. this.hash_size = 0; /* number of elements in hash table */
  5731. this.hash_bits = 0; /* log2(hash_size) */
  5732. this.hash_mask = 0; /* hash_size-1 */
  5733. this.hash_shift = 0;
  5734. /* Number of bits by which ins_h must be shifted at each input
  5735. * step. It must be such that after MIN_MATCH steps, the oldest
  5736. * byte no longer takes part in the hash key, that is:
  5737. * hash_shift * MIN_MATCH >= hash_bits
  5738. */
  5739. this.block_start = 0;
  5740. /* Window position at the beginning of the current output block. Gets
  5741. * negative when the window is moved backwards.
  5742. */
  5743. this.match_length = 0; /* length of best match */
  5744. this.prev_match = 0; /* previous match */
  5745. this.match_available = 0; /* set if previous match exists */
  5746. this.strstart = 0; /* start of string to insert */
  5747. this.match_start = 0; /* start of matching string */
  5748. this.lookahead = 0; /* number of valid bytes ahead in window */
  5749. this.prev_length = 0;
  5750. /* Length of the best match at previous step. Matches not greater than this
  5751. * are discarded. This is used in the lazy match evaluation.
  5752. */
  5753. this.max_chain_length = 0;
  5754. /* To speed up deflation, hash chains are never searched beyond this
  5755. * length. A higher limit improves compression ratio but degrades the
  5756. * speed.
  5757. */
  5758. this.max_lazy_match = 0;
  5759. /* Attempt to find a better match only when the current match is strictly
  5760. * smaller than this value. This mechanism is used only for compression
  5761. * levels >= 4.
  5762. */
  5763. // That's alias to max_lazy_match, don't use directly
  5764. //this.max_insert_length = 0;
  5765. /* Insert new strings in the hash table only if the match length is not
  5766. * greater than this length. This saves time but degrades compression.
  5767. * max_insert_length is used only for compression levels <= 3.
  5768. */
  5769. this.level = 0; /* compression level (1..9) */
  5770. this.strategy = 0; /* favor or force Huffman coding*/
  5771. this.good_match = 0;
  5772. /* Use a faster search when the previous match is longer than this */
  5773. this.nice_match = 0; /* Stop searching when current match exceeds this */
  5774. /* used by trees.c: */
  5775. /* Didn't use ct_data typedef below to suppress compiler warning */
  5776. // struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  5777. // struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  5778. // struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  5779. // Use flat array of DOUBLE size, with interleaved fata,
  5780. // because JS does not support effective
  5781. this.dyn_ltree = new utils.Buf16(HEAP_SIZE * 2);
  5782. this.dyn_dtree = new utils.Buf16((2 * D_CODES + 1) * 2);
  5783. this.bl_tree = new utils.Buf16((2 * BL_CODES + 1) * 2);
  5784. zero(this.dyn_ltree);
  5785. zero(this.dyn_dtree);
  5786. zero(this.bl_tree);
  5787. this.l_desc = null; /* desc. for literal tree */
  5788. this.d_desc = null; /* desc. for distance tree */
  5789. this.bl_desc = null; /* desc. for bit length tree */
  5790. //ush bl_count[MAX_BITS+1];
  5791. this.bl_count = new utils.Buf16(MAX_BITS + 1);
  5792. /* number of codes at each bit length for an optimal tree */
  5793. //int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  5794. this.heap = new utils.Buf16(2 * L_CODES + 1); /* heap used to build the Huffman trees */
  5795. zero(this.heap);
  5796. this.heap_len = 0; /* number of elements in the heap */
  5797. this.heap_max = 0; /* element of largest frequency */
  5798. /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
  5799. * The same heap array is used to build all trees.
  5800. */
  5801. this.depth = new utils.Buf16(2 * L_CODES + 1); //uch depth[2*L_CODES+1];
  5802. zero(this.depth);
  5803. /* Depth of each subtree used as tie breaker for trees of equal frequency
  5804. */
  5805. this.l_buf = 0; /* buffer index for literals or lengths */
  5806. this.lit_bufsize = 0;
  5807. /* Size of match buffer for literals/lengths. There are 4 reasons for
  5808. * limiting lit_bufsize to 64K:
  5809. * - frequencies can be kept in 16 bit counters
  5810. * - if compression is not successful for the first block, all input
  5811. * data is still in the window so we can still emit a stored block even
  5812. * when input comes from standard input. (This can also be done for
  5813. * all blocks if lit_bufsize is not greater than 32K.)
  5814. * - if compression is not successful for a file smaller than 64K, we can
  5815. * even emit a stored file instead of a stored block (saving 5 bytes).
  5816. * This is applicable only for zip (not gzip or zlib).
  5817. * - creating new Huffman trees less frequently may not provide fast
  5818. * adaptation to changes in the input data statistics. (Take for
  5819. * example a binary file with poorly compressible code followed by
  5820. * a highly compressible string table.) Smaller buffer sizes give
  5821. * fast adaptation but have of course the overhead of transmitting
  5822. * trees more frequently.
  5823. * - I can't count above 4
  5824. */
  5825. this.last_lit = 0; /* running index in l_buf */
  5826. this.d_buf = 0;
  5827. /* Buffer index for distances. To simplify the code, d_buf and l_buf have
  5828. * the same number of elements. To use different lengths, an extra flag
  5829. * array would be necessary.
  5830. */
  5831. this.opt_len = 0; /* bit length of current block with optimal trees */
  5832. this.static_len = 0; /* bit length of current block with static trees */
  5833. this.matches = 0; /* number of string matches in current block */
  5834. this.insert = 0; /* bytes at end of window left to insert */
  5835. this.bi_buf = 0;
  5836. /* Output buffer. bits are inserted starting at the bottom (least
  5837. * significant bits).
  5838. */
  5839. this.bi_valid = 0;
  5840. /* Number of valid bits in bi_buf. All bits above the last valid bit
  5841. * are always zero.
  5842. */
  5843. // Used for window memory init. We safely ignore it for JS. That makes
  5844. // sense only for pointers and memory check tools.
  5845. //this.high_water = 0;
  5846. /* High water mark offset in window for initialized bytes -- bytes above
  5847. * this are set to zero in order to avoid memory check warnings when
  5848. * longest match routines access bytes past the input. This is then
  5849. * updated to the new high water mark.
  5850. */
  5851. }
  5852. function deflateResetKeep(strm) {
  5853. var s;
  5854. if (!strm || !strm.state) {
  5855. return err(strm, Z_STREAM_ERROR);
  5856. }
  5857. strm.total_in = strm.total_out = 0;
  5858. strm.data_type = Z_UNKNOWN;
  5859. s = strm.state;
  5860. s.pending = 0;
  5861. s.pending_out = 0;
  5862. if (s.wrap < 0) {
  5863. s.wrap = -s.wrap;
  5864. /* was made negative by deflate(..., Z_FINISH); */
  5865. }
  5866. s.status = (s.wrap ? INIT_STATE : BUSY_STATE);
  5867. strm.adler = (s.wrap === 2) ?
  5868. 0 // crc32(0, Z_NULL, 0)
  5869. :
  5870. 1; // adler32(0, Z_NULL, 0)
  5871. s.last_flush = Z_NO_FLUSH;
  5872. trees._tr_init(s);
  5873. return Z_OK;
  5874. }
  5875. function deflateReset(strm) {
  5876. var ret = deflateResetKeep(strm);
  5877. if (ret === Z_OK) {
  5878. lm_init(strm.state);
  5879. }
  5880. return ret;
  5881. }
  5882. function deflateSetHeader(strm, head) {
  5883. if (!strm || !strm.state) { return Z_STREAM_ERROR; }
  5884. if (strm.state.wrap !== 2) { return Z_STREAM_ERROR; }
  5885. strm.state.gzhead = head;
  5886. return Z_OK;
  5887. }
  5888. function deflateInit2(strm, level, method, windowBits, memLevel, strategy) {
  5889. if (!strm) { // === Z_NULL
  5890. return Z_STREAM_ERROR;
  5891. }
  5892. var wrap = 1;
  5893. if (level === Z_DEFAULT_COMPRESSION) {
  5894. level = 6;
  5895. }
  5896. if (windowBits < 0) { /* suppress zlib wrapper */
  5897. wrap = 0;
  5898. windowBits = -windowBits;
  5899. }
  5900. else if (windowBits > 15) {
  5901. wrap = 2; /* write gzip wrapper instead */
  5902. windowBits -= 16;
  5903. }
  5904. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method !== Z_DEFLATED ||
  5905. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  5906. strategy < 0 || strategy > Z_FIXED) {
  5907. return err(strm, Z_STREAM_ERROR);
  5908. }
  5909. if (windowBits === 8) {
  5910. windowBits = 9;
  5911. }
  5912. /* until 256-byte window bug fixed */
  5913. var s = new DeflateState();
  5914. strm.state = s;
  5915. s.strm = strm;
  5916. s.wrap = wrap;
  5917. s.gzhead = null;
  5918. s.w_bits = windowBits;
  5919. s.w_size = 1 << s.w_bits;
  5920. s.w_mask = s.w_size - 1;
  5921. s.hash_bits = memLevel + 7;
  5922. s.hash_size = 1 << s.hash_bits;
  5923. s.hash_mask = s.hash_size - 1;
  5924. s.hash_shift = ~~((s.hash_bits + MIN_MATCH - 1) / MIN_MATCH);
  5925. s.window = new utils.Buf8(s.w_size * 2);
  5926. s.head = new utils.Buf16(s.hash_size);
  5927. s.prev = new utils.Buf16(s.w_size);
  5928. // Don't need mem init magic for JS.
  5929. //s.high_water = 0; /* nothing written to s->window yet */
  5930. s.lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  5931. s.pending_buf_size = s.lit_bufsize * 4;
  5932. s.pending_buf = new utils.Buf8(s.pending_buf_size);
  5933. s.d_buf = s.lit_bufsize >> 1;
  5934. s.l_buf = (1 + 2) * s.lit_bufsize;
  5935. s.level = level;
  5936. s.strategy = strategy;
  5937. s.method = method;
  5938. return deflateReset(strm);
  5939. }
  5940. function deflateInit(strm, level) {
  5941. return deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
  5942. }
  5943. function deflate(strm, flush) {
  5944. var old_flush, s;
  5945. var beg, val; // for gzip header write only
  5946. if (!strm || !strm.state ||
  5947. flush > Z_BLOCK || flush < 0) {
  5948. return strm ? err(strm, Z_STREAM_ERROR) : Z_STREAM_ERROR;
  5949. }
  5950. s = strm.state;
  5951. if (!strm.output ||
  5952. (!strm.input && strm.avail_in !== 0) ||
  5953. (s.status === FINISH_STATE && flush !== Z_FINISH)) {
  5954. return err(strm, (strm.avail_out === 0) ? Z_BUF_ERROR : Z_STREAM_ERROR);
  5955. }
  5956. s.strm = strm; /* just in case */
  5957. old_flush = s.last_flush;
  5958. s.last_flush = flush;
  5959. /* Write the header */
  5960. if (s.status === INIT_STATE) {
  5961. if (s.wrap === 2) { // GZIP header
  5962. strm.adler = 0; //crc32(0L, Z_NULL, 0);
  5963. put_byte(s, 31);
  5964. put_byte(s, 139);
  5965. put_byte(s, 8);
  5966. if (!s.gzhead) { // s->gzhead == Z_NULL
  5967. put_byte(s, 0);
  5968. put_byte(s, 0);
  5969. put_byte(s, 0);
  5970. put_byte(s, 0);
  5971. put_byte(s, 0);
  5972. put_byte(s, s.level === 9 ? 2 :
  5973. (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?
  5974. 4 : 0));
  5975. put_byte(s, OS_CODE);
  5976. s.status = BUSY_STATE;
  5977. }
  5978. else {
  5979. put_byte(s, (s.gzhead.text ? 1 : 0) +
  5980. (s.gzhead.hcrc ? 2 : 0) +
  5981. (!s.gzhead.extra ? 0 : 4) +
  5982. (!s.gzhead.name ? 0 : 8) +
  5983. (!s.gzhead.comment ? 0 : 16)
  5984. );
  5985. put_byte(s, s.gzhead.time & 0xff);
  5986. put_byte(s, (s.gzhead.time >> 8) & 0xff);
  5987. put_byte(s, (s.gzhead.time >> 16) & 0xff);
  5988. put_byte(s, (s.gzhead.time >> 24) & 0xff);
  5989. put_byte(s, s.level === 9 ? 2 :
  5990. (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2 ?
  5991. 4 : 0));
  5992. put_byte(s, s.gzhead.os & 0xff);
  5993. if (s.gzhead.extra && s.gzhead.extra.length) {
  5994. put_byte(s, s.gzhead.extra.length & 0xff);
  5995. put_byte(s, (s.gzhead.extra.length >> 8) & 0xff);
  5996. }
  5997. if (s.gzhead.hcrc) {
  5998. strm.adler = crc32(strm.adler, s.pending_buf, s.pending, 0);
  5999. }
  6000. s.gzindex = 0;
  6001. s.status = EXTRA_STATE;
  6002. }
  6003. }
  6004. else // DEFLATE header
  6005. {
  6006. var header = (Z_DEFLATED + ((s.w_bits - 8) << 4)) << 8;
  6007. var level_flags = -1;
  6008. if (s.strategy >= Z_HUFFMAN_ONLY || s.level < 2) {
  6009. level_flags = 0;
  6010. } else if (s.level < 6) {
  6011. level_flags = 1;
  6012. } else if (s.level === 6) {
  6013. level_flags = 2;
  6014. } else {
  6015. level_flags = 3;
  6016. }
  6017. header |= (level_flags << 6);
  6018. if (s.strstart !== 0) { header |= PRESET_DICT; }
  6019. header += 31 - (header % 31);
  6020. s.status = BUSY_STATE;
  6021. putShortMSB(s, header);
  6022. /* Save the adler32 of the preset dictionary: */
  6023. if (s.strstart !== 0) {
  6024. putShortMSB(s, strm.adler >>> 16);
  6025. putShortMSB(s, strm.adler & 0xffff);
  6026. }
  6027. strm.adler = 1; // adler32(0L, Z_NULL, 0);
  6028. }
  6029. }
  6030. //#ifdef GZIP
  6031. if (s.status === EXTRA_STATE) {
  6032. if (s.gzhead.extra/* != Z_NULL*/) {
  6033. beg = s.pending; /* start of bytes to update crc */
  6034. while (s.gzindex < (s.gzhead.extra.length & 0xffff)) {
  6035. if (s.pending === s.pending_buf_size) {
  6036. if (s.gzhead.hcrc && s.pending > beg) {
  6037. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  6038. }
  6039. flush_pending(strm);
  6040. beg = s.pending;
  6041. if (s.pending === s.pending_buf_size) {
  6042. break;
  6043. }
  6044. }
  6045. put_byte(s, s.gzhead.extra[s.gzindex] & 0xff);
  6046. s.gzindex++;
  6047. }
  6048. if (s.gzhead.hcrc && s.pending > beg) {
  6049. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  6050. }
  6051. if (s.gzindex === s.gzhead.extra.length) {
  6052. s.gzindex = 0;
  6053. s.status = NAME_STATE;
  6054. }
  6055. }
  6056. else {
  6057. s.status = NAME_STATE;
  6058. }
  6059. }
  6060. if (s.status === NAME_STATE) {
  6061. if (s.gzhead.name/* != Z_NULL*/) {
  6062. beg = s.pending; /* start of bytes to update crc */
  6063. //int val;
  6064. do {
  6065. if (s.pending === s.pending_buf_size) {
  6066. if (s.gzhead.hcrc && s.pending > beg) {
  6067. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  6068. }
  6069. flush_pending(strm);
  6070. beg = s.pending;
  6071. if (s.pending === s.pending_buf_size) {
  6072. val = 1;
  6073. break;
  6074. }
  6075. }
  6076. // JS specific: little magic to add zero terminator to end of string
  6077. if (s.gzindex < s.gzhead.name.length) {
  6078. val = s.gzhead.name.charCodeAt(s.gzindex++) & 0xff;
  6079. } else {
  6080. val = 0;
  6081. }
  6082. put_byte(s, val);
  6083. } while (val !== 0);
  6084. if (s.gzhead.hcrc && s.pending > beg) {
  6085. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  6086. }
  6087. if (val === 0) {
  6088. s.gzindex = 0;
  6089. s.status = COMMENT_STATE;
  6090. }
  6091. }
  6092. else {
  6093. s.status = COMMENT_STATE;
  6094. }
  6095. }
  6096. if (s.status === COMMENT_STATE) {
  6097. if (s.gzhead.comment/* != Z_NULL*/) {
  6098. beg = s.pending; /* start of bytes to update crc */
  6099. //int val;
  6100. do {
  6101. if (s.pending === s.pending_buf_size) {
  6102. if (s.gzhead.hcrc && s.pending > beg) {
  6103. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  6104. }
  6105. flush_pending(strm);
  6106. beg = s.pending;
  6107. if (s.pending === s.pending_buf_size) {
  6108. val = 1;
  6109. break;
  6110. }
  6111. }
  6112. // JS specific: little magic to add zero terminator to end of string
  6113. if (s.gzindex < s.gzhead.comment.length) {
  6114. val = s.gzhead.comment.charCodeAt(s.gzindex++) & 0xff;
  6115. } else {
  6116. val = 0;
  6117. }
  6118. put_byte(s, val);
  6119. } while (val !== 0);
  6120. if (s.gzhead.hcrc && s.pending > beg) {
  6121. strm.adler = crc32(strm.adler, s.pending_buf, s.pending - beg, beg);
  6122. }
  6123. if (val === 0) {
  6124. s.status = HCRC_STATE;
  6125. }
  6126. }
  6127. else {
  6128. s.status = HCRC_STATE;
  6129. }
  6130. }
  6131. if (s.status === HCRC_STATE) {
  6132. if (s.gzhead.hcrc) {
  6133. if (s.pending + 2 > s.pending_buf_size) {
  6134. flush_pending(strm);
  6135. }
  6136. if (s.pending + 2 <= s.pending_buf_size) {
  6137. put_byte(s, strm.adler & 0xff);
  6138. put_byte(s, (strm.adler >> 8) & 0xff);
  6139. strm.adler = 0; //crc32(0L, Z_NULL, 0);
  6140. s.status = BUSY_STATE;
  6141. }
  6142. }
  6143. else {
  6144. s.status = BUSY_STATE;
  6145. }
  6146. }
  6147. //#endif
  6148. /* Flush as much pending output as possible */
  6149. if (s.pending !== 0) {
  6150. flush_pending(strm);
  6151. if (strm.avail_out === 0) {
  6152. /* Since avail_out is 0, deflate will be called again with
  6153. * more output space, but possibly with both pending and
  6154. * avail_in equal to zero. There won't be anything to do,
  6155. * but this is not an error situation so make sure we
  6156. * return OK instead of BUF_ERROR at next call of deflate:
  6157. */
  6158. s.last_flush = -1;
  6159. return Z_OK;
  6160. }
  6161. /* Make sure there is something to do and avoid duplicate consecutive
  6162. * flushes. For repeated and useless calls with Z_FINISH, we keep
  6163. * returning Z_STREAM_END instead of Z_BUF_ERROR.
  6164. */
  6165. } else if (strm.avail_in === 0 && rank(flush) <= rank(old_flush) &&
  6166. flush !== Z_FINISH) {
  6167. return err(strm, Z_BUF_ERROR);
  6168. }
  6169. /* User must not provide more input after the first FINISH: */
  6170. if (s.status === FINISH_STATE && strm.avail_in !== 0) {
  6171. return err(strm, Z_BUF_ERROR);
  6172. }
  6173. /* Start a new block or continue the current one.
  6174. */
  6175. if (strm.avail_in !== 0 || s.lookahead !== 0 ||
  6176. (flush !== Z_NO_FLUSH && s.status !== FINISH_STATE)) {
  6177. var bstate = (s.strategy === Z_HUFFMAN_ONLY) ? deflate_huff(s, flush) :
  6178. (s.strategy === Z_RLE ? deflate_rle(s, flush) :
  6179. configuration_table[s.level].func(s, flush));
  6180. if (bstate === BS_FINISH_STARTED || bstate === BS_FINISH_DONE) {
  6181. s.status = FINISH_STATE;
  6182. }
  6183. if (bstate === BS_NEED_MORE || bstate === BS_FINISH_STARTED) {
  6184. if (strm.avail_out === 0) {
  6185. s.last_flush = -1;
  6186. /* avoid BUF_ERROR next call, see above */
  6187. }
  6188. return Z_OK;
  6189. /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
  6190. * of deflate should use the same flush parameter to make sure
  6191. * that the flush is complete. So we don't have to output an
  6192. * empty block here, this will be done at next call. This also
  6193. * ensures that for a very small output buffer, we emit at most
  6194. * one empty block.
  6195. */
  6196. }
  6197. if (bstate === BS_BLOCK_DONE) {
  6198. if (flush === Z_PARTIAL_FLUSH) {
  6199. trees._tr_align(s);
  6200. }
  6201. else if (flush !== Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */
  6202. trees._tr_stored_block(s, 0, 0, false);
  6203. /* For a full flush, this empty block will be recognized
  6204. * as a special marker by inflate_sync().
  6205. */
  6206. if (flush === Z_FULL_FLUSH) {
  6207. /*** CLEAR_HASH(s); ***/ /* forget history */
  6208. zero(s.head); // Fill with NIL (= 0);
  6209. if (s.lookahead === 0) {
  6210. s.strstart = 0;
  6211. s.block_start = 0;
  6212. s.insert = 0;
  6213. }
  6214. }
  6215. }
  6216. flush_pending(strm);
  6217. if (strm.avail_out === 0) {
  6218. s.last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  6219. return Z_OK;
  6220. }
  6221. }
  6222. }
  6223. //Assert(strm->avail_out > 0, "bug2");
  6224. //if (strm.avail_out <= 0) { throw new Error("bug2");}
  6225. if (flush !== Z_FINISH) { return Z_OK; }
  6226. if (s.wrap <= 0) { return Z_STREAM_END; }
  6227. /* Write the trailer */
  6228. if (s.wrap === 2) {
  6229. put_byte(s, strm.adler & 0xff);
  6230. put_byte(s, (strm.adler >> 8) & 0xff);
  6231. put_byte(s, (strm.adler >> 16) & 0xff);
  6232. put_byte(s, (strm.adler >> 24) & 0xff);
  6233. put_byte(s, strm.total_in & 0xff);
  6234. put_byte(s, (strm.total_in >> 8) & 0xff);
  6235. put_byte(s, (strm.total_in >> 16) & 0xff);
  6236. put_byte(s, (strm.total_in >> 24) & 0xff);
  6237. }
  6238. else
  6239. {
  6240. putShortMSB(s, strm.adler >>> 16);
  6241. putShortMSB(s, strm.adler & 0xffff);
  6242. }
  6243. flush_pending(strm);
  6244. /* If avail_out is zero, the application will call deflate again
  6245. * to flush the rest.
  6246. */
  6247. if (s.wrap > 0) { s.wrap = -s.wrap; }
  6248. /* write the trailer only once! */
  6249. return s.pending !== 0 ? Z_OK : Z_STREAM_END;
  6250. }
  6251. function deflateEnd(strm) {
  6252. var status;
  6253. if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {
  6254. return Z_STREAM_ERROR;
  6255. }
  6256. status = strm.state.status;
  6257. if (status !== INIT_STATE &&
  6258. status !== EXTRA_STATE &&
  6259. status !== NAME_STATE &&
  6260. status !== COMMENT_STATE &&
  6261. status !== HCRC_STATE &&
  6262. status !== BUSY_STATE &&
  6263. status !== FINISH_STATE
  6264. ) {
  6265. return err(strm, Z_STREAM_ERROR);
  6266. }
  6267. strm.state = null;
  6268. return status === BUSY_STATE ? err(strm, Z_DATA_ERROR) : Z_OK;
  6269. }
  6270. /* =========================================================================
  6271. * Initializes the compression dictionary from the given byte
  6272. * sequence without producing any compressed output.
  6273. */
  6274. function deflateSetDictionary(strm, dictionary) {
  6275. var dictLength = dictionary.length;
  6276. var s;
  6277. var str, n;
  6278. var wrap;
  6279. var avail;
  6280. var next;
  6281. var input;
  6282. var tmpDict;
  6283. if (!strm/*== Z_NULL*/ || !strm.state/*== Z_NULL*/) {
  6284. return Z_STREAM_ERROR;
  6285. }
  6286. s = strm.state;
  6287. wrap = s.wrap;
  6288. if (wrap === 2 || (wrap === 1 && s.status !== INIT_STATE) || s.lookahead) {
  6289. return Z_STREAM_ERROR;
  6290. }
  6291. /* when using zlib wrappers, compute Adler-32 for provided dictionary */
  6292. if (wrap === 1) {
  6293. /* adler32(strm->adler, dictionary, dictLength); */
  6294. strm.adler = adler32(strm.adler, dictionary, dictLength, 0);
  6295. }
  6296. s.wrap = 0; /* avoid computing Adler-32 in read_buf */
  6297. /* if dictionary would fill window, just replace the history */
  6298. if (dictLength >= s.w_size) {
  6299. if (wrap === 0) { /* already empty otherwise */
  6300. /*** CLEAR_HASH(s); ***/
  6301. zero(s.head); // Fill with NIL (= 0);
  6302. s.strstart = 0;
  6303. s.block_start = 0;
  6304. s.insert = 0;
  6305. }
  6306. /* use the tail */
  6307. // dictionary = dictionary.slice(dictLength - s.w_size);
  6308. tmpDict = new utils.Buf8(s.w_size);
  6309. utils.arraySet(tmpDict, dictionary, dictLength - s.w_size, s.w_size, 0);
  6310. dictionary = tmpDict;
  6311. dictLength = s.w_size;
  6312. }
  6313. /* insert dictionary into window and hash */
  6314. avail = strm.avail_in;
  6315. next = strm.next_in;
  6316. input = strm.input;
  6317. strm.avail_in = dictLength;
  6318. strm.next_in = 0;
  6319. strm.input = dictionary;
  6320. fill_window(s);
  6321. while (s.lookahead >= MIN_MATCH) {
  6322. str = s.strstart;
  6323. n = s.lookahead - (MIN_MATCH - 1);
  6324. do {
  6325. /* UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); */
  6326. s.ins_h = ((s.ins_h << s.hash_shift) ^ s.window[str + MIN_MATCH - 1]) & s.hash_mask;
  6327. s.prev[str & s.w_mask] = s.head[s.ins_h];
  6328. s.head[s.ins_h] = str;
  6329. str++;
  6330. } while (--n);
  6331. s.strstart = str;
  6332. s.lookahead = MIN_MATCH - 1;
  6333. fill_window(s);
  6334. }
  6335. s.strstart += s.lookahead;
  6336. s.block_start = s.strstart;
  6337. s.insert = s.lookahead;
  6338. s.lookahead = 0;
  6339. s.match_length = s.prev_length = MIN_MATCH - 1;
  6340. s.match_available = 0;
  6341. strm.next_in = next;
  6342. strm.input = input;
  6343. strm.avail_in = avail;
  6344. s.wrap = wrap;
  6345. return Z_OK;
  6346. }
  6347. exports.deflateInit = deflateInit;
  6348. exports.deflateInit2 = deflateInit2;
  6349. exports.deflateReset = deflateReset;
  6350. exports.deflateResetKeep = deflateResetKeep;
  6351. exports.deflateSetHeader = deflateSetHeader;
  6352. exports.deflate = deflate;
  6353. exports.deflateEnd = deflateEnd;
  6354. exports.deflateSetDictionary = deflateSetDictionary;
  6355. exports.deflateInfo = 'pako deflate (from Nodeca project)';
  6356. /* Not implemented
  6357. exports.deflateBound = deflateBound;
  6358. exports.deflateCopy = deflateCopy;
  6359. exports.deflateParams = deflateParams;
  6360. exports.deflatePending = deflatePending;
  6361. exports.deflatePrime = deflatePrime;
  6362. exports.deflateTune = deflateTune;
  6363. */
  6364. },{"../utils/common":32,"./adler32":34,"./crc32":36,"./messages":42,"./trees":43}],38:[function(_dereq_,module,exports){
  6365. 'use strict';
  6366. function GZheader() {
  6367. /* true if compressed data believed to be text */
  6368. this.text = 0;
  6369. /* modification time */
  6370. this.time = 0;
  6371. /* extra flags (not used when writing a gzip file) */
  6372. this.xflags = 0;
  6373. /* operating system */
  6374. this.os = 0;
  6375. /* pointer to extra field or Z_NULL if none */
  6376. this.extra = null;
  6377. /* extra field length (valid if extra != Z_NULL) */
  6378. this.extra_len = 0; // Actually, we don't need it in JS,
  6379. // but leave for few code modifications
  6380. //
  6381. // Setup limits is not necessary because in js we should not preallocate memory
  6382. // for inflate use constant limit in 65536 bytes
  6383. //
  6384. /* space at extra (only when reading header) */
  6385. // this.extra_max = 0;
  6386. /* pointer to zero-terminated file name or Z_NULL */
  6387. this.name = '';
  6388. /* space at name (only when reading header) */
  6389. // this.name_max = 0;
  6390. /* pointer to zero-terminated comment or Z_NULL */
  6391. this.comment = '';
  6392. /* space at comment (only when reading header) */
  6393. // this.comm_max = 0;
  6394. /* true if there was or will be a header crc */
  6395. this.hcrc = 0;
  6396. /* true when done reading gzip header (not used when writing a gzip file) */
  6397. this.done = false;
  6398. }
  6399. module.exports = GZheader;
  6400. },{}],39:[function(_dereq_,module,exports){
  6401. 'use strict';
  6402. // See state defs from inflate.js
  6403. var BAD = 30; /* got a data error -- remain here until reset */
  6404. var TYPE = 12; /* i: waiting for type bits, including last-flag bit */
  6405. /*
  6406. Decode literal, length, and distance codes and write out the resulting
  6407. literal and match bytes until either not enough input or output is
  6408. available, an end-of-block is encountered, or a data error is encountered.
  6409. When large enough input and output buffers are supplied to inflate(), for
  6410. example, a 16K input buffer and a 64K output buffer, more than 95% of the
  6411. inflate execution time is spent in this routine.
  6412. Entry assumptions:
  6413. state.mode === LEN
  6414. strm.avail_in >= 6
  6415. strm.avail_out >= 258
  6416. start >= strm.avail_out
  6417. state.bits < 8
  6418. On return, state.mode is one of:
  6419. LEN -- ran out of enough output space or enough available input
  6420. TYPE -- reached end of block code, inflate() to interpret next block
  6421. BAD -- error in block data
  6422. Notes:
  6423. - The maximum input bits used by a length/distance pair is 15 bits for the
  6424. length code, 5 bits for the length extra, 15 bits for the distance code,
  6425. and 13 bits for the distance extra. This totals 48 bits, or six bytes.
  6426. Therefore if strm.avail_in >= 6, then there is enough input to avoid
  6427. checking for available input while decoding.
  6428. - The maximum bytes that a single length/distance pair can output is 258
  6429. bytes, which is the maximum length that can be coded. inflate_fast()
  6430. requires strm.avail_out >= 258 for each loop to avoid checking for
  6431. output space.
  6432. */
  6433. module.exports = function inflate_fast(strm, start) {
  6434. var state;
  6435. var _in; /* local strm.input */
  6436. var last; /* have enough input while in < last */
  6437. var _out; /* local strm.output */
  6438. var beg; /* inflate()'s initial strm.output */
  6439. var end; /* while out < end, enough space available */
  6440. //#ifdef INFLATE_STRICT
  6441. var dmax; /* maximum distance from zlib header */
  6442. //#endif
  6443. var wsize; /* window size or zero if not using window */
  6444. var whave; /* valid bytes in the window */
  6445. var wnext; /* window write index */
  6446. // Use `s_window` instead `window`, avoid conflict with instrumentation tools
  6447. var s_window; /* allocated sliding window, if wsize != 0 */
  6448. var hold; /* local strm.hold */
  6449. var bits; /* local strm.bits */
  6450. var lcode; /* local strm.lencode */
  6451. var dcode; /* local strm.distcode */
  6452. var lmask; /* mask for first level of length codes */
  6453. var dmask; /* mask for first level of distance codes */
  6454. var here; /* retrieved table entry */
  6455. var op; /* code bits, operation, extra bits, or */
  6456. /* window position, window bytes to copy */
  6457. var len; /* match length, unused bytes */
  6458. var dist; /* match distance */
  6459. var from; /* where to copy match from */
  6460. var from_source;
  6461. var input, output; // JS specific, because we have no pointers
  6462. /* copy state to local variables */
  6463. state = strm.state;
  6464. //here = state.here;
  6465. _in = strm.next_in;
  6466. input = strm.input;
  6467. last = _in + (strm.avail_in - 5);
  6468. _out = strm.next_out;
  6469. output = strm.output;
  6470. beg = _out - (start - strm.avail_out);
  6471. end = _out + (strm.avail_out - 257);
  6472. //#ifdef INFLATE_STRICT
  6473. dmax = state.dmax;
  6474. //#endif
  6475. wsize = state.wsize;
  6476. whave = state.whave;
  6477. wnext = state.wnext;
  6478. s_window = state.window;
  6479. hold = state.hold;
  6480. bits = state.bits;
  6481. lcode = state.lencode;
  6482. dcode = state.distcode;
  6483. lmask = (1 << state.lenbits) - 1;
  6484. dmask = (1 << state.distbits) - 1;
  6485. /* decode literals and length/distances until end-of-block or not enough
  6486. input data or output space */
  6487. top:
  6488. do {
  6489. if (bits < 15) {
  6490. hold += input[_in++] << bits;
  6491. bits += 8;
  6492. hold += input[_in++] << bits;
  6493. bits += 8;
  6494. }
  6495. here = lcode[hold & lmask];
  6496. dolen:
  6497. for (;;) { // Goto emulation
  6498. op = here >>> 24/*here.bits*/;
  6499. hold >>>= op;
  6500. bits -= op;
  6501. op = (here >>> 16) & 0xff/*here.op*/;
  6502. if (op === 0) { /* literal */
  6503. //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
  6504. // "inflate: literal '%c'\n" :
  6505. // "inflate: literal 0x%02x\n", here.val));
  6506. output[_out++] = here & 0xffff/*here.val*/;
  6507. }
  6508. else if (op & 16) { /* length base */
  6509. len = here & 0xffff/*here.val*/;
  6510. op &= 15; /* number of extra bits */
  6511. if (op) {
  6512. if (bits < op) {
  6513. hold += input[_in++] << bits;
  6514. bits += 8;
  6515. }
  6516. len += hold & ((1 << op) - 1);
  6517. hold >>>= op;
  6518. bits -= op;
  6519. }
  6520. //Tracevv((stderr, "inflate: length %u\n", len));
  6521. if (bits < 15) {
  6522. hold += input[_in++] << bits;
  6523. bits += 8;
  6524. hold += input[_in++] << bits;
  6525. bits += 8;
  6526. }
  6527. here = dcode[hold & dmask];
  6528. dodist:
  6529. for (;;) { // goto emulation
  6530. op = here >>> 24/*here.bits*/;
  6531. hold >>>= op;
  6532. bits -= op;
  6533. op = (here >>> 16) & 0xff/*here.op*/;
  6534. if (op & 16) { /* distance base */
  6535. dist = here & 0xffff/*here.val*/;
  6536. op &= 15; /* number of extra bits */
  6537. if (bits < op) {
  6538. hold += input[_in++] << bits;
  6539. bits += 8;
  6540. if (bits < op) {
  6541. hold += input[_in++] << bits;
  6542. bits += 8;
  6543. }
  6544. }
  6545. dist += hold & ((1 << op) - 1);
  6546. //#ifdef INFLATE_STRICT
  6547. if (dist > dmax) {
  6548. strm.msg = 'invalid distance too far back';
  6549. state.mode = BAD;
  6550. break top;
  6551. }
  6552. //#endif
  6553. hold >>>= op;
  6554. bits -= op;
  6555. //Tracevv((stderr, "inflate: distance %u\n", dist));
  6556. op = _out - beg; /* max distance in output */
  6557. if (dist > op) { /* see if copy from window */
  6558. op = dist - op; /* distance back in window */
  6559. if (op > whave) {
  6560. if (state.sane) {
  6561. strm.msg = 'invalid distance too far back';
  6562. state.mode = BAD;
  6563. break top;
  6564. }
  6565. // (!) This block is disabled in zlib defailts,
  6566. // don't enable it for binary compatibility
  6567. //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
  6568. // if (len <= op - whave) {
  6569. // do {
  6570. // output[_out++] = 0;
  6571. // } while (--len);
  6572. // continue top;
  6573. // }
  6574. // len -= op - whave;
  6575. // do {
  6576. // output[_out++] = 0;
  6577. // } while (--op > whave);
  6578. // if (op === 0) {
  6579. // from = _out - dist;
  6580. // do {
  6581. // output[_out++] = output[from++];
  6582. // } while (--len);
  6583. // continue top;
  6584. // }
  6585. //#endif
  6586. }
  6587. from = 0; // window index
  6588. from_source = s_window;
  6589. if (wnext === 0) { /* very common case */
  6590. from += wsize - op;
  6591. if (op < len) { /* some from window */
  6592. len -= op;
  6593. do {
  6594. output[_out++] = s_window[from++];
  6595. } while (--op);
  6596. from = _out - dist; /* rest from output */
  6597. from_source = output;
  6598. }
  6599. }
  6600. else if (wnext < op) { /* wrap around window */
  6601. from += wsize + wnext - op;
  6602. op -= wnext;
  6603. if (op < len) { /* some from end of window */
  6604. len -= op;
  6605. do {
  6606. output[_out++] = s_window[from++];
  6607. } while (--op);
  6608. from = 0;
  6609. if (wnext < len) { /* some from start of window */
  6610. op = wnext;
  6611. len -= op;
  6612. do {
  6613. output[_out++] = s_window[from++];
  6614. } while (--op);
  6615. from = _out - dist; /* rest from output */
  6616. from_source = output;
  6617. }
  6618. }
  6619. }
  6620. else { /* contiguous in window */
  6621. from += wnext - op;
  6622. if (op < len) { /* some from window */
  6623. len -= op;
  6624. do {
  6625. output[_out++] = s_window[from++];
  6626. } while (--op);
  6627. from = _out - dist; /* rest from output */
  6628. from_source = output;
  6629. }
  6630. }
  6631. while (len > 2) {
  6632. output[_out++] = from_source[from++];
  6633. output[_out++] = from_source[from++];
  6634. output[_out++] = from_source[from++];
  6635. len -= 3;
  6636. }
  6637. if (len) {
  6638. output[_out++] = from_source[from++];
  6639. if (len > 1) {
  6640. output[_out++] = from_source[from++];
  6641. }
  6642. }
  6643. }
  6644. else {
  6645. from = _out - dist; /* copy direct from output */
  6646. do { /* minimum length is three */
  6647. output[_out++] = output[from++];
  6648. output[_out++] = output[from++];
  6649. output[_out++] = output[from++];
  6650. len -= 3;
  6651. } while (len > 2);
  6652. if (len) {
  6653. output[_out++] = output[from++];
  6654. if (len > 1) {
  6655. output[_out++] = output[from++];
  6656. }
  6657. }
  6658. }
  6659. }
  6660. else if ((op & 64) === 0) { /* 2nd level distance code */
  6661. here = dcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
  6662. continue dodist;
  6663. }
  6664. else {
  6665. strm.msg = 'invalid distance code';
  6666. state.mode = BAD;
  6667. break top;
  6668. }
  6669. break; // need to emulate goto via "continue"
  6670. }
  6671. }
  6672. else if ((op & 64) === 0) { /* 2nd level length code */
  6673. here = lcode[(here & 0xffff)/*here.val*/ + (hold & ((1 << op) - 1))];
  6674. continue dolen;
  6675. }
  6676. else if (op & 32) { /* end-of-block */
  6677. //Tracevv((stderr, "inflate: end of block\n"));
  6678. state.mode = TYPE;
  6679. break top;
  6680. }
  6681. else {
  6682. strm.msg = 'invalid literal/length code';
  6683. state.mode = BAD;
  6684. break top;
  6685. }
  6686. break; // need to emulate goto via "continue"
  6687. }
  6688. } while (_in < last && _out < end);
  6689. /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
  6690. len = bits >> 3;
  6691. _in -= len;
  6692. bits -= len << 3;
  6693. hold &= (1 << bits) - 1;
  6694. /* update state and return */
  6695. strm.next_in = _in;
  6696. strm.next_out = _out;
  6697. strm.avail_in = (_in < last ? 5 + (last - _in) : 5 - (_in - last));
  6698. strm.avail_out = (_out < end ? 257 + (end - _out) : 257 - (_out - end));
  6699. state.hold = hold;
  6700. state.bits = bits;
  6701. return;
  6702. };
  6703. },{}],40:[function(_dereq_,module,exports){
  6704. 'use strict';
  6705. var utils = _dereq_('../utils/common');
  6706. var adler32 = _dereq_('./adler32');
  6707. var crc32 = _dereq_('./crc32');
  6708. var inflate_fast = _dereq_('./inffast');
  6709. var inflate_table = _dereq_('./inftrees');
  6710. var CODES = 0;
  6711. var LENS = 1;
  6712. var DISTS = 2;
  6713. /* Public constants ==========================================================*/
  6714. /* ===========================================================================*/
  6715. /* Allowed flush values; see deflate() and inflate() below for details */
  6716. //var Z_NO_FLUSH = 0;
  6717. //var Z_PARTIAL_FLUSH = 1;
  6718. //var Z_SYNC_FLUSH = 2;
  6719. //var Z_FULL_FLUSH = 3;
  6720. var Z_FINISH = 4;
  6721. var Z_BLOCK = 5;
  6722. var Z_TREES = 6;
  6723. /* Return codes for the compression/decompression functions. Negative values
  6724. * are errors, positive values are used for special but normal events.
  6725. */
  6726. var Z_OK = 0;
  6727. var Z_STREAM_END = 1;
  6728. var Z_NEED_DICT = 2;
  6729. //var Z_ERRNO = -1;
  6730. var Z_STREAM_ERROR = -2;
  6731. var Z_DATA_ERROR = -3;
  6732. var Z_MEM_ERROR = -4;
  6733. var Z_BUF_ERROR = -5;
  6734. //var Z_VERSION_ERROR = -6;
  6735. /* The deflate compression method */
  6736. var Z_DEFLATED = 8;
  6737. /* STATES ====================================================================*/
  6738. /* ===========================================================================*/
  6739. var HEAD = 1; /* i: waiting for magic header */
  6740. var FLAGS = 2; /* i: waiting for method and flags (gzip) */
  6741. var TIME = 3; /* i: waiting for modification time (gzip) */
  6742. var OS = 4; /* i: waiting for extra flags and operating system (gzip) */
  6743. var EXLEN = 5; /* i: waiting for extra length (gzip) */
  6744. var EXTRA = 6; /* i: waiting for extra bytes (gzip) */
  6745. var NAME = 7; /* i: waiting for end of file name (gzip) */
  6746. var COMMENT = 8; /* i: waiting for end of comment (gzip) */
  6747. var HCRC = 9; /* i: waiting for header crc (gzip) */
  6748. var DICTID = 10; /* i: waiting for dictionary check value */
  6749. var DICT = 11; /* waiting for inflateSetDictionary() call */
  6750. var TYPE = 12; /* i: waiting for type bits, including last-flag bit */
  6751. var TYPEDO = 13; /* i: same, but skip check to exit inflate on new block */
  6752. var STORED = 14; /* i: waiting for stored size (length and complement) */
  6753. var COPY_ = 15; /* i/o: same as COPY below, but only first time in */
  6754. var COPY = 16; /* i/o: waiting for input or output to copy stored block */
  6755. var TABLE = 17; /* i: waiting for dynamic block table lengths */
  6756. var LENLENS = 18; /* i: waiting for code length code lengths */
  6757. var CODELENS = 19; /* i: waiting for length/lit and distance code lengths */
  6758. var LEN_ = 20; /* i: same as LEN below, but only first time in */
  6759. var LEN = 21; /* i: waiting for length/lit/eob code */
  6760. var LENEXT = 22; /* i: waiting for length extra bits */
  6761. var DIST = 23; /* i: waiting for distance code */
  6762. var DISTEXT = 24; /* i: waiting for distance extra bits */
  6763. var MATCH = 25; /* o: waiting for output space to copy string */
  6764. var LIT = 26; /* o: waiting for output space to write literal */
  6765. var CHECK = 27; /* i: waiting for 32-bit check value */
  6766. var LENGTH = 28; /* i: waiting for 32-bit length (gzip) */
  6767. var DONE = 29; /* finished check, done -- remain here until reset */
  6768. var BAD = 30; /* got a data error -- remain here until reset */
  6769. var MEM = 31; /* got an inflate() memory error -- remain here until reset */
  6770. var SYNC = 32; /* looking for synchronization bytes to restart inflate() */
  6771. /* ===========================================================================*/
  6772. var ENOUGH_LENS = 852;
  6773. var ENOUGH_DISTS = 592;
  6774. //var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
  6775. var MAX_WBITS = 15;
  6776. /* 32K LZ77 window */
  6777. var DEF_WBITS = MAX_WBITS;
  6778. function zswap32(q) {
  6779. return (((q >>> 24) & 0xff) +
  6780. ((q >>> 8) & 0xff00) +
  6781. ((q & 0xff00) << 8) +
  6782. ((q & 0xff) << 24));
  6783. }
  6784. function InflateState() {
  6785. this.mode = 0; /* current inflate mode */
  6786. this.last = false; /* true if processing last block */
  6787. this.wrap = 0; /* bit 0 true for zlib, bit 1 true for gzip */
  6788. this.havedict = false; /* true if dictionary provided */
  6789. this.flags = 0; /* gzip header method and flags (0 if zlib) */
  6790. this.dmax = 0; /* zlib header max distance (INFLATE_STRICT) */
  6791. this.check = 0; /* protected copy of check value */
  6792. this.total = 0; /* protected copy of output count */
  6793. // TODO: may be {}
  6794. this.head = null; /* where to save gzip header information */
  6795. /* sliding window */
  6796. this.wbits = 0; /* log base 2 of requested window size */
  6797. this.wsize = 0; /* window size or zero if not using window */
  6798. this.whave = 0; /* valid bytes in the window */
  6799. this.wnext = 0; /* window write index */
  6800. this.window = null; /* allocated sliding window, if needed */
  6801. /* bit accumulator */
  6802. this.hold = 0; /* input bit accumulator */
  6803. this.bits = 0; /* number of bits in "in" */
  6804. /* for string and stored block copying */
  6805. this.length = 0; /* literal or length of data to copy */
  6806. this.offset = 0; /* distance back to copy string from */
  6807. /* for table and code decoding */
  6808. this.extra = 0; /* extra bits needed */
  6809. /* fixed and dynamic code tables */
  6810. this.lencode = null; /* starting table for length/literal codes */
  6811. this.distcode = null; /* starting table for distance codes */
  6812. this.lenbits = 0; /* index bits for lencode */
  6813. this.distbits = 0; /* index bits for distcode */
  6814. /* dynamic table building */
  6815. this.ncode = 0; /* number of code length code lengths */
  6816. this.nlen = 0; /* number of length code lengths */
  6817. this.ndist = 0; /* number of distance code lengths */
  6818. this.have = 0; /* number of code lengths in lens[] */
  6819. this.next = null; /* next available space in codes[] */
  6820. this.lens = new utils.Buf16(320); /* temporary storage for code lengths */
  6821. this.work = new utils.Buf16(288); /* work area for code table building */
  6822. /*
  6823. because we don't have pointers in js, we use lencode and distcode directly
  6824. as buffers so we don't need codes
  6825. */
  6826. //this.codes = new utils.Buf32(ENOUGH); /* space for code tables */
  6827. this.lendyn = null; /* dynamic table for length/literal codes (JS specific) */
  6828. this.distdyn = null; /* dynamic table for distance codes (JS specific) */
  6829. this.sane = 0; /* if false, allow invalid distance too far */
  6830. this.back = 0; /* bits back of last unprocessed length/lit */
  6831. this.was = 0; /* initial length of match */
  6832. }
  6833. function inflateResetKeep(strm) {
  6834. var state;
  6835. if (!strm || !strm.state) { return Z_STREAM_ERROR; }
  6836. state = strm.state;
  6837. strm.total_in = strm.total_out = state.total = 0;
  6838. strm.msg = ''; /*Z_NULL*/
  6839. if (state.wrap) { /* to support ill-conceived Java test suite */
  6840. strm.adler = state.wrap & 1;
  6841. }
  6842. state.mode = HEAD;
  6843. state.last = 0;
  6844. state.havedict = 0;
  6845. state.dmax = 32768;
  6846. state.head = null/*Z_NULL*/;
  6847. state.hold = 0;
  6848. state.bits = 0;
  6849. //state.lencode = state.distcode = state.next = state.codes;
  6850. state.lencode = state.lendyn = new utils.Buf32(ENOUGH_LENS);
  6851. state.distcode = state.distdyn = new utils.Buf32(ENOUGH_DISTS);
  6852. state.sane = 1;
  6853. state.back = -1;
  6854. //Tracev((stderr, "inflate: reset\n"));
  6855. return Z_OK;
  6856. }
  6857. function inflateReset(strm) {
  6858. var state;
  6859. if (!strm || !strm.state) { return Z_STREAM_ERROR; }
  6860. state = strm.state;
  6861. state.wsize = 0;
  6862. state.whave = 0;
  6863. state.wnext = 0;
  6864. return inflateResetKeep(strm);
  6865. }
  6866. function inflateReset2(strm, windowBits) {
  6867. var wrap;
  6868. var state;
  6869. /* get the state */
  6870. if (!strm || !strm.state) { return Z_STREAM_ERROR; }
  6871. state = strm.state;
  6872. /* extract wrap request from windowBits parameter */
  6873. if (windowBits < 0) {
  6874. wrap = 0;
  6875. windowBits = -windowBits;
  6876. }
  6877. else {
  6878. wrap = (windowBits >> 4) + 1;
  6879. if (windowBits < 48) {
  6880. windowBits &= 15;
  6881. }
  6882. }
  6883. /* set number of window bits, free window if different */
  6884. if (windowBits && (windowBits < 8 || windowBits > 15)) {
  6885. return Z_STREAM_ERROR;
  6886. }
  6887. if (state.window !== null && state.wbits !== windowBits) {
  6888. state.window = null;
  6889. }
  6890. /* update state and reset the rest of it */
  6891. state.wrap = wrap;
  6892. state.wbits = windowBits;
  6893. return inflateReset(strm);
  6894. }
  6895. function inflateInit2(strm, windowBits) {
  6896. var ret;
  6897. var state;
  6898. if (!strm) { return Z_STREAM_ERROR; }
  6899. //strm.msg = Z_NULL; /* in case we return an error */
  6900. state = new InflateState();
  6901. //if (state === Z_NULL) return Z_MEM_ERROR;
  6902. //Tracev((stderr, "inflate: allocated\n"));
  6903. strm.state = state;
  6904. state.window = null/*Z_NULL*/;
  6905. ret = inflateReset2(strm, windowBits);
  6906. if (ret !== Z_OK) {
  6907. strm.state = null/*Z_NULL*/;
  6908. }
  6909. return ret;
  6910. }
  6911. function inflateInit(strm) {
  6912. return inflateInit2(strm, DEF_WBITS);
  6913. }
  6914. /*
  6915. Return state with length and distance decoding tables and index sizes set to
  6916. fixed code decoding. Normally this returns fixed tables from inffixed.h.
  6917. If BUILDFIXED is defined, then instead this routine builds the tables the
  6918. first time it's called, and returns those tables the first time and
  6919. thereafter. This reduces the size of the code by about 2K bytes, in
  6920. exchange for a little execution time. However, BUILDFIXED should not be
  6921. used for threaded applications, since the rewriting of the tables and virgin
  6922. may not be thread-safe.
  6923. */
  6924. var virgin = true;
  6925. var lenfix, distfix; // We have no pointers in JS, so keep tables separate
  6926. function fixedtables(state) {
  6927. /* build fixed huffman tables if first call (may not be thread safe) */
  6928. if (virgin) {
  6929. var sym;
  6930. lenfix = new utils.Buf32(512);
  6931. distfix = new utils.Buf32(32);
  6932. /* literal/length table */
  6933. sym = 0;
  6934. while (sym < 144) { state.lens[sym++] = 8; }
  6935. while (sym < 256) { state.lens[sym++] = 9; }
  6936. while (sym < 280) { state.lens[sym++] = 7; }
  6937. while (sym < 288) { state.lens[sym++] = 8; }
  6938. inflate_table(LENS, state.lens, 0, 288, lenfix, 0, state.work, { bits: 9 });
  6939. /* distance table */
  6940. sym = 0;
  6941. while (sym < 32) { state.lens[sym++] = 5; }
  6942. inflate_table(DISTS, state.lens, 0, 32, distfix, 0, state.work, { bits: 5 });
  6943. /* do this just once */
  6944. virgin = false;
  6945. }
  6946. state.lencode = lenfix;
  6947. state.lenbits = 9;
  6948. state.distcode = distfix;
  6949. state.distbits = 5;
  6950. }
  6951. /*
  6952. Update the window with the last wsize (normally 32K) bytes written before
  6953. returning. If window does not exist yet, create it. This is only called
  6954. when a window is already in use, or when output has been written during this
  6955. inflate call, but the end of the deflate stream has not been reached yet.
  6956. It is also called to create a window for dictionary data when a dictionary
  6957. is loaded.
  6958. Providing output buffers larger than 32K to inflate() should provide a speed
  6959. advantage, since only the last 32K of output is copied to the sliding window
  6960. upon return from inflate(), and since all distances after the first 32K of
  6961. output will fall in the output data, making match copies simpler and faster.
  6962. The advantage may be dependent on the size of the processor's data caches.
  6963. */
  6964. function updatewindow(strm, src, end, copy) {
  6965. var dist;
  6966. var state = strm.state;
  6967. /* if it hasn't been done already, allocate space for the window */
  6968. if (state.window === null) {
  6969. state.wsize = 1 << state.wbits;
  6970. state.wnext = 0;
  6971. state.whave = 0;
  6972. state.window = new utils.Buf8(state.wsize);
  6973. }
  6974. /* copy state->wsize or less output bytes into the circular window */
  6975. if (copy >= state.wsize) {
  6976. utils.arraySet(state.window, src, end - state.wsize, state.wsize, 0);
  6977. state.wnext = 0;
  6978. state.whave = state.wsize;
  6979. }
  6980. else {
  6981. dist = state.wsize - state.wnext;
  6982. if (dist > copy) {
  6983. dist = copy;
  6984. }
  6985. //zmemcpy(state->window + state->wnext, end - copy, dist);
  6986. utils.arraySet(state.window, src, end - copy, dist, state.wnext);
  6987. copy -= dist;
  6988. if (copy) {
  6989. //zmemcpy(state->window, end - copy, copy);
  6990. utils.arraySet(state.window, src, end - copy, copy, 0);
  6991. state.wnext = copy;
  6992. state.whave = state.wsize;
  6993. }
  6994. else {
  6995. state.wnext += dist;
  6996. if (state.wnext === state.wsize) { state.wnext = 0; }
  6997. if (state.whave < state.wsize) { state.whave += dist; }
  6998. }
  6999. }
  7000. return 0;
  7001. }
  7002. function inflate(strm, flush) {
  7003. var state;
  7004. var input, output; // input/output buffers
  7005. var next; /* next input INDEX */
  7006. var put; /* next output INDEX */
  7007. var have, left; /* available input and output */
  7008. var hold; /* bit buffer */
  7009. var bits; /* bits in bit buffer */
  7010. var _in, _out; /* save starting available input and output */
  7011. var copy; /* number of stored or match bytes to copy */
  7012. var from; /* where to copy match bytes from */
  7013. var from_source;
  7014. var here = 0; /* current decoding table entry */
  7015. var here_bits, here_op, here_val; // paked "here" denormalized (JS specific)
  7016. //var last; /* parent table entry */
  7017. var last_bits, last_op, last_val; // paked "last" denormalized (JS specific)
  7018. var len; /* length to copy for repeats, bits to drop */
  7019. var ret; /* return code */
  7020. var hbuf = new utils.Buf8(4); /* buffer for gzip header crc calculation */
  7021. var opts;
  7022. var n; // temporary var for NEED_BITS
  7023. var order = /* permutation of code lengths */
  7024. [ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 ];
  7025. if (!strm || !strm.state || !strm.output ||
  7026. (!strm.input && strm.avail_in !== 0)) {
  7027. return Z_STREAM_ERROR;
  7028. }
  7029. state = strm.state;
  7030. if (state.mode === TYPE) { state.mode = TYPEDO; } /* skip check */
  7031. //--- LOAD() ---
  7032. put = strm.next_out;
  7033. output = strm.output;
  7034. left = strm.avail_out;
  7035. next = strm.next_in;
  7036. input = strm.input;
  7037. have = strm.avail_in;
  7038. hold = state.hold;
  7039. bits = state.bits;
  7040. //---
  7041. _in = have;
  7042. _out = left;
  7043. ret = Z_OK;
  7044. inf_leave: // goto emulation
  7045. for (;;) {
  7046. switch (state.mode) {
  7047. case HEAD:
  7048. if (state.wrap === 0) {
  7049. state.mode = TYPEDO;
  7050. break;
  7051. }
  7052. //=== NEEDBITS(16);
  7053. while (bits < 16) {
  7054. if (have === 0) { break inf_leave; }
  7055. have--;
  7056. hold += input[next++] << bits;
  7057. bits += 8;
  7058. }
  7059. //===//
  7060. if ((state.wrap & 2) && hold === 0x8b1f) { /* gzip header */
  7061. state.check = 0/*crc32(0L, Z_NULL, 0)*/;
  7062. //=== CRC2(state.check, hold);
  7063. hbuf[0] = hold & 0xff;
  7064. hbuf[1] = (hold >>> 8) & 0xff;
  7065. state.check = crc32(state.check, hbuf, 2, 0);
  7066. //===//
  7067. //=== INITBITS();
  7068. hold = 0;
  7069. bits = 0;
  7070. //===//
  7071. state.mode = FLAGS;
  7072. break;
  7073. }
  7074. state.flags = 0; /* expect zlib header */
  7075. if (state.head) {
  7076. state.head.done = false;
  7077. }
  7078. if (!(state.wrap & 1) || /* check if zlib header allowed */
  7079. (((hold & 0xff)/*BITS(8)*/ << 8) + (hold >> 8)) % 31) {
  7080. strm.msg = 'incorrect header check';
  7081. state.mode = BAD;
  7082. break;
  7083. }
  7084. if ((hold & 0x0f)/*BITS(4)*/ !== Z_DEFLATED) {
  7085. strm.msg = 'unknown compression method';
  7086. state.mode = BAD;
  7087. break;
  7088. }
  7089. //--- DROPBITS(4) ---//
  7090. hold >>>= 4;
  7091. bits -= 4;
  7092. //---//
  7093. len = (hold & 0x0f)/*BITS(4)*/ + 8;
  7094. if (state.wbits === 0) {
  7095. state.wbits = len;
  7096. }
  7097. else if (len > state.wbits) {
  7098. strm.msg = 'invalid window size';
  7099. state.mode = BAD;
  7100. break;
  7101. }
  7102. state.dmax = 1 << len;
  7103. //Tracev((stderr, "inflate: zlib header ok\n"));
  7104. strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
  7105. state.mode = hold & 0x200 ? DICTID : TYPE;
  7106. //=== INITBITS();
  7107. hold = 0;
  7108. bits = 0;
  7109. //===//
  7110. break;
  7111. case FLAGS:
  7112. //=== NEEDBITS(16); */
  7113. while (bits < 16) {
  7114. if (have === 0) { break inf_leave; }
  7115. have--;
  7116. hold += input[next++] << bits;
  7117. bits += 8;
  7118. }
  7119. //===//
  7120. state.flags = hold;
  7121. if ((state.flags & 0xff) !== Z_DEFLATED) {
  7122. strm.msg = 'unknown compression method';
  7123. state.mode = BAD;
  7124. break;
  7125. }
  7126. if (state.flags & 0xe000) {
  7127. strm.msg = 'unknown header flags set';
  7128. state.mode = BAD;
  7129. break;
  7130. }
  7131. if (state.head) {
  7132. state.head.text = ((hold >> 8) & 1);
  7133. }
  7134. if (state.flags & 0x0200) {
  7135. //=== CRC2(state.check, hold);
  7136. hbuf[0] = hold & 0xff;
  7137. hbuf[1] = (hold >>> 8) & 0xff;
  7138. state.check = crc32(state.check, hbuf, 2, 0);
  7139. //===//
  7140. }
  7141. //=== INITBITS();
  7142. hold = 0;
  7143. bits = 0;
  7144. //===//
  7145. state.mode = TIME;
  7146. /* falls through */
  7147. case TIME:
  7148. //=== NEEDBITS(32); */
  7149. while (bits < 32) {
  7150. if (have === 0) { break inf_leave; }
  7151. have--;
  7152. hold += input[next++] << bits;
  7153. bits += 8;
  7154. }
  7155. //===//
  7156. if (state.head) {
  7157. state.head.time = hold;
  7158. }
  7159. if (state.flags & 0x0200) {
  7160. //=== CRC4(state.check, hold)
  7161. hbuf[0] = hold & 0xff;
  7162. hbuf[1] = (hold >>> 8) & 0xff;
  7163. hbuf[2] = (hold >>> 16) & 0xff;
  7164. hbuf[3] = (hold >>> 24) & 0xff;
  7165. state.check = crc32(state.check, hbuf, 4, 0);
  7166. //===
  7167. }
  7168. //=== INITBITS();
  7169. hold = 0;
  7170. bits = 0;
  7171. //===//
  7172. state.mode = OS;
  7173. /* falls through */
  7174. case OS:
  7175. //=== NEEDBITS(16); */
  7176. while (bits < 16) {
  7177. if (have === 0) { break inf_leave; }
  7178. have--;
  7179. hold += input[next++] << bits;
  7180. bits += 8;
  7181. }
  7182. //===//
  7183. if (state.head) {
  7184. state.head.xflags = (hold & 0xff);
  7185. state.head.os = (hold >> 8);
  7186. }
  7187. if (state.flags & 0x0200) {
  7188. //=== CRC2(state.check, hold);
  7189. hbuf[0] = hold & 0xff;
  7190. hbuf[1] = (hold >>> 8) & 0xff;
  7191. state.check = crc32(state.check, hbuf, 2, 0);
  7192. //===//
  7193. }
  7194. //=== INITBITS();
  7195. hold = 0;
  7196. bits = 0;
  7197. //===//
  7198. state.mode = EXLEN;
  7199. /* falls through */
  7200. case EXLEN:
  7201. if (state.flags & 0x0400) {
  7202. //=== NEEDBITS(16); */
  7203. while (bits < 16) {
  7204. if (have === 0) { break inf_leave; }
  7205. have--;
  7206. hold += input[next++] << bits;
  7207. bits += 8;
  7208. }
  7209. //===//
  7210. state.length = hold;
  7211. if (state.head) {
  7212. state.head.extra_len = hold;
  7213. }
  7214. if (state.flags & 0x0200) {
  7215. //=== CRC2(state.check, hold);
  7216. hbuf[0] = hold & 0xff;
  7217. hbuf[1] = (hold >>> 8) & 0xff;
  7218. state.check = crc32(state.check, hbuf, 2, 0);
  7219. //===//
  7220. }
  7221. //=== INITBITS();
  7222. hold = 0;
  7223. bits = 0;
  7224. //===//
  7225. }
  7226. else if (state.head) {
  7227. state.head.extra = null/*Z_NULL*/;
  7228. }
  7229. state.mode = EXTRA;
  7230. /* falls through */
  7231. case EXTRA:
  7232. if (state.flags & 0x0400) {
  7233. copy = state.length;
  7234. if (copy > have) { copy = have; }
  7235. if (copy) {
  7236. if (state.head) {
  7237. len = state.head.extra_len - state.length;
  7238. if (!state.head.extra) {
  7239. // Use untyped array for more conveniend processing later
  7240. state.head.extra = new Array(state.head.extra_len);
  7241. }
  7242. utils.arraySet(
  7243. state.head.extra,
  7244. input,
  7245. next,
  7246. // extra field is limited to 65536 bytes
  7247. // - no need for additional size check
  7248. copy,
  7249. /*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
  7250. len
  7251. );
  7252. //zmemcpy(state.head.extra + len, next,
  7253. // len + copy > state.head.extra_max ?
  7254. // state.head.extra_max - len : copy);
  7255. }
  7256. if (state.flags & 0x0200) {
  7257. state.check = crc32(state.check, input, copy, next);
  7258. }
  7259. have -= copy;
  7260. next += copy;
  7261. state.length -= copy;
  7262. }
  7263. if (state.length) { break inf_leave; }
  7264. }
  7265. state.length = 0;
  7266. state.mode = NAME;
  7267. /* falls through */
  7268. case NAME:
  7269. if (state.flags & 0x0800) {
  7270. if (have === 0) { break inf_leave; }
  7271. copy = 0;
  7272. do {
  7273. // TODO: 2 or 1 bytes?
  7274. len = input[next + copy++];
  7275. /* use constant limit because in js we should not preallocate memory */
  7276. if (state.head && len &&
  7277. (state.length < 65536 /*state.head.name_max*/)) {
  7278. state.head.name += String.fromCharCode(len);
  7279. }
  7280. } while (len && copy < have);
  7281. if (state.flags & 0x0200) {
  7282. state.check = crc32(state.check, input, copy, next);
  7283. }
  7284. have -= copy;
  7285. next += copy;
  7286. if (len) { break inf_leave; }
  7287. }
  7288. else if (state.head) {
  7289. state.head.name = null;
  7290. }
  7291. state.length = 0;
  7292. state.mode = COMMENT;
  7293. /* falls through */
  7294. case COMMENT:
  7295. if (state.flags & 0x1000) {
  7296. if (have === 0) { break inf_leave; }
  7297. copy = 0;
  7298. do {
  7299. len = input[next + copy++];
  7300. /* use constant limit because in js we should not preallocate memory */
  7301. if (state.head && len &&
  7302. (state.length < 65536 /*state.head.comm_max*/)) {
  7303. state.head.comment += String.fromCharCode(len);
  7304. }
  7305. } while (len && copy < have);
  7306. if (state.flags & 0x0200) {
  7307. state.check = crc32(state.check, input, copy, next);
  7308. }
  7309. have -= copy;
  7310. next += copy;
  7311. if (len) { break inf_leave; }
  7312. }
  7313. else if (state.head) {
  7314. state.head.comment = null;
  7315. }
  7316. state.mode = HCRC;
  7317. /* falls through */
  7318. case HCRC:
  7319. if (state.flags & 0x0200) {
  7320. //=== NEEDBITS(16); */
  7321. while (bits < 16) {
  7322. if (have === 0) { break inf_leave; }
  7323. have--;
  7324. hold += input[next++] << bits;
  7325. bits += 8;
  7326. }
  7327. //===//
  7328. if (hold !== (state.check & 0xffff)) {
  7329. strm.msg = 'header crc mismatch';
  7330. state.mode = BAD;
  7331. break;
  7332. }
  7333. //=== INITBITS();
  7334. hold = 0;
  7335. bits = 0;
  7336. //===//
  7337. }
  7338. if (state.head) {
  7339. state.head.hcrc = ((state.flags >> 9) & 1);
  7340. state.head.done = true;
  7341. }
  7342. strm.adler = state.check = 0;
  7343. state.mode = TYPE;
  7344. break;
  7345. case DICTID:
  7346. //=== NEEDBITS(32); */
  7347. while (bits < 32) {
  7348. if (have === 0) { break inf_leave; }
  7349. have--;
  7350. hold += input[next++] << bits;
  7351. bits += 8;
  7352. }
  7353. //===//
  7354. strm.adler = state.check = zswap32(hold);
  7355. //=== INITBITS();
  7356. hold = 0;
  7357. bits = 0;
  7358. //===//
  7359. state.mode = DICT;
  7360. /* falls through */
  7361. case DICT:
  7362. if (state.havedict === 0) {
  7363. //--- RESTORE() ---
  7364. strm.next_out = put;
  7365. strm.avail_out = left;
  7366. strm.next_in = next;
  7367. strm.avail_in = have;
  7368. state.hold = hold;
  7369. state.bits = bits;
  7370. //---
  7371. return Z_NEED_DICT;
  7372. }
  7373. strm.adler = state.check = 1/*adler32(0L, Z_NULL, 0)*/;
  7374. state.mode = TYPE;
  7375. /* falls through */
  7376. case TYPE:
  7377. if (flush === Z_BLOCK || flush === Z_TREES) { break inf_leave; }
  7378. /* falls through */
  7379. case TYPEDO:
  7380. if (state.last) {
  7381. //--- BYTEBITS() ---//
  7382. hold >>>= bits & 7;
  7383. bits -= bits & 7;
  7384. //---//
  7385. state.mode = CHECK;
  7386. break;
  7387. }
  7388. //=== NEEDBITS(3); */
  7389. while (bits < 3) {
  7390. if (have === 0) { break inf_leave; }
  7391. have--;
  7392. hold += input[next++] << bits;
  7393. bits += 8;
  7394. }
  7395. //===//
  7396. state.last = (hold & 0x01)/*BITS(1)*/;
  7397. //--- DROPBITS(1) ---//
  7398. hold >>>= 1;
  7399. bits -= 1;
  7400. //---//
  7401. switch ((hold & 0x03)/*BITS(2)*/) {
  7402. case 0: /* stored block */
  7403. //Tracev((stderr, "inflate: stored block%s\n",
  7404. // state.last ? " (last)" : ""));
  7405. state.mode = STORED;
  7406. break;
  7407. case 1: /* fixed block */
  7408. fixedtables(state);
  7409. //Tracev((stderr, "inflate: fixed codes block%s\n",
  7410. // state.last ? " (last)" : ""));
  7411. state.mode = LEN_; /* decode codes */
  7412. if (flush === Z_TREES) {
  7413. //--- DROPBITS(2) ---//
  7414. hold >>>= 2;
  7415. bits -= 2;
  7416. //---//
  7417. break inf_leave;
  7418. }
  7419. break;
  7420. case 2: /* dynamic block */
  7421. //Tracev((stderr, "inflate: dynamic codes block%s\n",
  7422. // state.last ? " (last)" : ""));
  7423. state.mode = TABLE;
  7424. break;
  7425. case 3:
  7426. strm.msg = 'invalid block type';
  7427. state.mode = BAD;
  7428. }
  7429. //--- DROPBITS(2) ---//
  7430. hold >>>= 2;
  7431. bits -= 2;
  7432. //---//
  7433. break;
  7434. case STORED:
  7435. //--- BYTEBITS() ---// /* go to byte boundary */
  7436. hold >>>= bits & 7;
  7437. bits -= bits & 7;
  7438. //---//
  7439. //=== NEEDBITS(32); */
  7440. while (bits < 32) {
  7441. if (have === 0) { break inf_leave; }
  7442. have--;
  7443. hold += input[next++] << bits;
  7444. bits += 8;
  7445. }
  7446. //===//
  7447. if ((hold & 0xffff) !== ((hold >>> 16) ^ 0xffff)) {
  7448. strm.msg = 'invalid stored block lengths';
  7449. state.mode = BAD;
  7450. break;
  7451. }
  7452. state.length = hold & 0xffff;
  7453. //Tracev((stderr, "inflate: stored length %u\n",
  7454. // state.length));
  7455. //=== INITBITS();
  7456. hold = 0;
  7457. bits = 0;
  7458. //===//
  7459. state.mode = COPY_;
  7460. if (flush === Z_TREES) { break inf_leave; }
  7461. /* falls through */
  7462. case COPY_:
  7463. state.mode = COPY;
  7464. /* falls through */
  7465. case COPY:
  7466. copy = state.length;
  7467. if (copy) {
  7468. if (copy > have) { copy = have; }
  7469. if (copy > left) { copy = left; }
  7470. if (copy === 0) { break inf_leave; }
  7471. //--- zmemcpy(put, next, copy); ---
  7472. utils.arraySet(output, input, next, copy, put);
  7473. //---//
  7474. have -= copy;
  7475. next += copy;
  7476. left -= copy;
  7477. put += copy;
  7478. state.length -= copy;
  7479. break;
  7480. }
  7481. //Tracev((stderr, "inflate: stored end\n"));
  7482. state.mode = TYPE;
  7483. break;
  7484. case TABLE:
  7485. //=== NEEDBITS(14); */
  7486. while (bits < 14) {
  7487. if (have === 0) { break inf_leave; }
  7488. have--;
  7489. hold += input[next++] << bits;
  7490. bits += 8;
  7491. }
  7492. //===//
  7493. state.nlen = (hold & 0x1f)/*BITS(5)*/ + 257;
  7494. //--- DROPBITS(5) ---//
  7495. hold >>>= 5;
  7496. bits -= 5;
  7497. //---//
  7498. state.ndist = (hold & 0x1f)/*BITS(5)*/ + 1;
  7499. //--- DROPBITS(5) ---//
  7500. hold >>>= 5;
  7501. bits -= 5;
  7502. //---//
  7503. state.ncode = (hold & 0x0f)/*BITS(4)*/ + 4;
  7504. //--- DROPBITS(4) ---//
  7505. hold >>>= 4;
  7506. bits -= 4;
  7507. //---//
  7508. //#ifndef PKZIP_BUG_WORKAROUND
  7509. if (state.nlen > 286 || state.ndist > 30) {
  7510. strm.msg = 'too many length or distance symbols';
  7511. state.mode = BAD;
  7512. break;
  7513. }
  7514. //#endif
  7515. //Tracev((stderr, "inflate: table sizes ok\n"));
  7516. state.have = 0;
  7517. state.mode = LENLENS;
  7518. /* falls through */
  7519. case LENLENS:
  7520. while (state.have < state.ncode) {
  7521. //=== NEEDBITS(3);
  7522. while (bits < 3) {
  7523. if (have === 0) { break inf_leave; }
  7524. have--;
  7525. hold += input[next++] << bits;
  7526. bits += 8;
  7527. }
  7528. //===//
  7529. state.lens[order[state.have++]] = (hold & 0x07);//BITS(3);
  7530. //--- DROPBITS(3) ---//
  7531. hold >>>= 3;
  7532. bits -= 3;
  7533. //---//
  7534. }
  7535. while (state.have < 19) {
  7536. state.lens[order[state.have++]] = 0;
  7537. }
  7538. // We have separate tables & no pointers. 2 commented lines below not needed.
  7539. //state.next = state.codes;
  7540. //state.lencode = state.next;
  7541. // Switch to use dynamic table
  7542. state.lencode = state.lendyn;
  7543. state.lenbits = 7;
  7544. opts = { bits: state.lenbits };
  7545. ret = inflate_table(CODES, state.lens, 0, 19, state.lencode, 0, state.work, opts);
  7546. state.lenbits = opts.bits;
  7547. if (ret) {
  7548. strm.msg = 'invalid code lengths set';
  7549. state.mode = BAD;
  7550. break;
  7551. }
  7552. //Tracev((stderr, "inflate: code lengths ok\n"));
  7553. state.have = 0;
  7554. state.mode = CODELENS;
  7555. /* falls through */
  7556. case CODELENS:
  7557. while (state.have < state.nlen + state.ndist) {
  7558. for (;;) {
  7559. here = state.lencode[hold & ((1 << state.lenbits) - 1)];/*BITS(state.lenbits)*/
  7560. here_bits = here >>> 24;
  7561. here_op = (here >>> 16) & 0xff;
  7562. here_val = here & 0xffff;
  7563. if ((here_bits) <= bits) { break; }
  7564. //--- PULLBYTE() ---//
  7565. if (have === 0) { break inf_leave; }
  7566. have--;
  7567. hold += input[next++] << bits;
  7568. bits += 8;
  7569. //---//
  7570. }
  7571. if (here_val < 16) {
  7572. //--- DROPBITS(here.bits) ---//
  7573. hold >>>= here_bits;
  7574. bits -= here_bits;
  7575. //---//
  7576. state.lens[state.have++] = here_val;
  7577. }
  7578. else {
  7579. if (here_val === 16) {
  7580. //=== NEEDBITS(here.bits + 2);
  7581. n = here_bits + 2;
  7582. while (bits < n) {
  7583. if (have === 0) { break inf_leave; }
  7584. have--;
  7585. hold += input[next++] << bits;
  7586. bits += 8;
  7587. }
  7588. //===//
  7589. //--- DROPBITS(here.bits) ---//
  7590. hold >>>= here_bits;
  7591. bits -= here_bits;
  7592. //---//
  7593. if (state.have === 0) {
  7594. strm.msg = 'invalid bit length repeat';
  7595. state.mode = BAD;
  7596. break;
  7597. }
  7598. len = state.lens[state.have - 1];
  7599. copy = 3 + (hold & 0x03);//BITS(2);
  7600. //--- DROPBITS(2) ---//
  7601. hold >>>= 2;
  7602. bits -= 2;
  7603. //---//
  7604. }
  7605. else if (here_val === 17) {
  7606. //=== NEEDBITS(here.bits + 3);
  7607. n = here_bits + 3;
  7608. while (bits < n) {
  7609. if (have === 0) { break inf_leave; }
  7610. have--;
  7611. hold += input[next++] << bits;
  7612. bits += 8;
  7613. }
  7614. //===//
  7615. //--- DROPBITS(here.bits) ---//
  7616. hold >>>= here_bits;
  7617. bits -= here_bits;
  7618. //---//
  7619. len = 0;
  7620. copy = 3 + (hold & 0x07);//BITS(3);
  7621. //--- DROPBITS(3) ---//
  7622. hold >>>= 3;
  7623. bits -= 3;
  7624. //---//
  7625. }
  7626. else {
  7627. //=== NEEDBITS(here.bits + 7);
  7628. n = here_bits + 7;
  7629. while (bits < n) {
  7630. if (have === 0) { break inf_leave; }
  7631. have--;
  7632. hold += input[next++] << bits;
  7633. bits += 8;
  7634. }
  7635. //===//
  7636. //--- DROPBITS(here.bits) ---//
  7637. hold >>>= here_bits;
  7638. bits -= here_bits;
  7639. //---//
  7640. len = 0;
  7641. copy = 11 + (hold & 0x7f);//BITS(7);
  7642. //--- DROPBITS(7) ---//
  7643. hold >>>= 7;
  7644. bits -= 7;
  7645. //---//
  7646. }
  7647. if (state.have + copy > state.nlen + state.ndist) {
  7648. strm.msg = 'invalid bit length repeat';
  7649. state.mode = BAD;
  7650. break;
  7651. }
  7652. while (copy--) {
  7653. state.lens[state.have++] = len;
  7654. }
  7655. }
  7656. }
  7657. /* handle error breaks in while */
  7658. if (state.mode === BAD) { break; }
  7659. /* check for end-of-block code (better have one) */
  7660. if (state.lens[256] === 0) {
  7661. strm.msg = 'invalid code -- missing end-of-block';
  7662. state.mode = BAD;
  7663. break;
  7664. }
  7665. /* build code tables -- note: do not change the lenbits or distbits
  7666. values here (9 and 6) without reading the comments in inftrees.h
  7667. concerning the ENOUGH constants, which depend on those values */
  7668. state.lenbits = 9;
  7669. opts = { bits: state.lenbits };
  7670. ret = inflate_table(LENS, state.lens, 0, state.nlen, state.lencode, 0, state.work, opts);
  7671. // We have separate tables & no pointers. 2 commented lines below not needed.
  7672. // state.next_index = opts.table_index;
  7673. state.lenbits = opts.bits;
  7674. // state.lencode = state.next;
  7675. if (ret) {
  7676. strm.msg = 'invalid literal/lengths set';
  7677. state.mode = BAD;
  7678. break;
  7679. }
  7680. state.distbits = 6;
  7681. //state.distcode.copy(state.codes);
  7682. // Switch to use dynamic table
  7683. state.distcode = state.distdyn;
  7684. opts = { bits: state.distbits };
  7685. ret = inflate_table(DISTS, state.lens, state.nlen, state.ndist, state.distcode, 0, state.work, opts);
  7686. // We have separate tables & no pointers. 2 commented lines below not needed.
  7687. // state.next_index = opts.table_index;
  7688. state.distbits = opts.bits;
  7689. // state.distcode = state.next;
  7690. if (ret) {
  7691. strm.msg = 'invalid distances set';
  7692. state.mode = BAD;
  7693. break;
  7694. }
  7695. //Tracev((stderr, 'inflate: codes ok\n'));
  7696. state.mode = LEN_;
  7697. if (flush === Z_TREES) { break inf_leave; }
  7698. /* falls through */
  7699. case LEN_:
  7700. state.mode = LEN;
  7701. /* falls through */
  7702. case LEN:
  7703. if (have >= 6 && left >= 258) {
  7704. //--- RESTORE() ---
  7705. strm.next_out = put;
  7706. strm.avail_out = left;
  7707. strm.next_in = next;
  7708. strm.avail_in = have;
  7709. state.hold = hold;
  7710. state.bits = bits;
  7711. //---
  7712. inflate_fast(strm, _out);
  7713. //--- LOAD() ---
  7714. put = strm.next_out;
  7715. output = strm.output;
  7716. left = strm.avail_out;
  7717. next = strm.next_in;
  7718. input = strm.input;
  7719. have = strm.avail_in;
  7720. hold = state.hold;
  7721. bits = state.bits;
  7722. //---
  7723. if (state.mode === TYPE) {
  7724. state.back = -1;
  7725. }
  7726. break;
  7727. }
  7728. state.back = 0;
  7729. for (;;) {
  7730. here = state.lencode[hold & ((1 << state.lenbits) - 1)]; /*BITS(state.lenbits)*/
  7731. here_bits = here >>> 24;
  7732. here_op = (here >>> 16) & 0xff;
  7733. here_val = here & 0xffff;
  7734. if (here_bits <= bits) { break; }
  7735. //--- PULLBYTE() ---//
  7736. if (have === 0) { break inf_leave; }
  7737. have--;
  7738. hold += input[next++] << bits;
  7739. bits += 8;
  7740. //---//
  7741. }
  7742. if (here_op && (here_op & 0xf0) === 0) {
  7743. last_bits = here_bits;
  7744. last_op = here_op;
  7745. last_val = here_val;
  7746. for (;;) {
  7747. here = state.lencode[last_val +
  7748. ((hold & ((1 << (last_bits + last_op)) - 1))/*BITS(last.bits + last.op)*/ >> last_bits)];
  7749. here_bits = here >>> 24;
  7750. here_op = (here >>> 16) & 0xff;
  7751. here_val = here & 0xffff;
  7752. if ((last_bits + here_bits) <= bits) { break; }
  7753. //--- PULLBYTE() ---//
  7754. if (have === 0) { break inf_leave; }
  7755. have--;
  7756. hold += input[next++] << bits;
  7757. bits += 8;
  7758. //---//
  7759. }
  7760. //--- DROPBITS(last.bits) ---//
  7761. hold >>>= last_bits;
  7762. bits -= last_bits;
  7763. //---//
  7764. state.back += last_bits;
  7765. }
  7766. //--- DROPBITS(here.bits) ---//
  7767. hold >>>= here_bits;
  7768. bits -= here_bits;
  7769. //---//
  7770. state.back += here_bits;
  7771. state.length = here_val;
  7772. if (here_op === 0) {
  7773. //Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
  7774. // "inflate: literal '%c'\n" :
  7775. // "inflate: literal 0x%02x\n", here.val));
  7776. state.mode = LIT;
  7777. break;
  7778. }
  7779. if (here_op & 32) {
  7780. //Tracevv((stderr, "inflate: end of block\n"));
  7781. state.back = -1;
  7782. state.mode = TYPE;
  7783. break;
  7784. }
  7785. if (here_op & 64) {
  7786. strm.msg = 'invalid literal/length code';
  7787. state.mode = BAD;
  7788. break;
  7789. }
  7790. state.extra = here_op & 15;
  7791. state.mode = LENEXT;
  7792. /* falls through */
  7793. case LENEXT:
  7794. if (state.extra) {
  7795. //=== NEEDBITS(state.extra);
  7796. n = state.extra;
  7797. while (bits < n) {
  7798. if (have === 0) { break inf_leave; }
  7799. have--;
  7800. hold += input[next++] << bits;
  7801. bits += 8;
  7802. }
  7803. //===//
  7804. state.length += hold & ((1 << state.extra) - 1)/*BITS(state.extra)*/;
  7805. //--- DROPBITS(state.extra) ---//
  7806. hold >>>= state.extra;
  7807. bits -= state.extra;
  7808. //---//
  7809. state.back += state.extra;
  7810. }
  7811. //Tracevv((stderr, "inflate: length %u\n", state.length));
  7812. state.was = state.length;
  7813. state.mode = DIST;
  7814. /* falls through */
  7815. case DIST:
  7816. for (;;) {
  7817. here = state.distcode[hold & ((1 << state.distbits) - 1)];/*BITS(state.distbits)*/
  7818. here_bits = here >>> 24;
  7819. here_op = (here >>> 16) & 0xff;
  7820. here_val = here & 0xffff;
  7821. if ((here_bits) <= bits) { break; }
  7822. //--- PULLBYTE() ---//
  7823. if (have === 0) { break inf_leave; }
  7824. have--;
  7825. hold += input[next++] << bits;
  7826. bits += 8;
  7827. //---//
  7828. }
  7829. if ((here_op & 0xf0) === 0) {
  7830. last_bits = here_bits;
  7831. last_op = here_op;
  7832. last_val = here_val;
  7833. for (;;) {
  7834. here = state.distcode[last_val +
  7835. ((hold & ((1 << (last_bits + last_op)) - 1))/*BITS(last.bits + last.op)*/ >> last_bits)];
  7836. here_bits = here >>> 24;
  7837. here_op = (here >>> 16) & 0xff;
  7838. here_val = here & 0xffff;
  7839. if ((last_bits + here_bits) <= bits) { break; }
  7840. //--- PULLBYTE() ---//
  7841. if (have === 0) { break inf_leave; }
  7842. have--;
  7843. hold += input[next++] << bits;
  7844. bits += 8;
  7845. //---//
  7846. }
  7847. //--- DROPBITS(last.bits) ---//
  7848. hold >>>= last_bits;
  7849. bits -= last_bits;
  7850. //---//
  7851. state.back += last_bits;
  7852. }
  7853. //--- DROPBITS(here.bits) ---//
  7854. hold >>>= here_bits;
  7855. bits -= here_bits;
  7856. //---//
  7857. state.back += here_bits;
  7858. if (here_op & 64) {
  7859. strm.msg = 'invalid distance code';
  7860. state.mode = BAD;
  7861. break;
  7862. }
  7863. state.offset = here_val;
  7864. state.extra = (here_op) & 15;
  7865. state.mode = DISTEXT;
  7866. /* falls through */
  7867. case DISTEXT:
  7868. if (state.extra) {
  7869. //=== NEEDBITS(state.extra);
  7870. n = state.extra;
  7871. while (bits < n) {
  7872. if (have === 0) { break inf_leave; }
  7873. have--;
  7874. hold += input[next++] << bits;
  7875. bits += 8;
  7876. }
  7877. //===//
  7878. state.offset += hold & ((1 << state.extra) - 1)/*BITS(state.extra)*/;
  7879. //--- DROPBITS(state.extra) ---//
  7880. hold >>>= state.extra;
  7881. bits -= state.extra;
  7882. //---//
  7883. state.back += state.extra;
  7884. }
  7885. //#ifdef INFLATE_STRICT
  7886. if (state.offset > state.dmax) {
  7887. strm.msg = 'invalid distance too far back';
  7888. state.mode = BAD;
  7889. break;
  7890. }
  7891. //#endif
  7892. //Tracevv((stderr, "inflate: distance %u\n", state.offset));
  7893. state.mode = MATCH;
  7894. /* falls through */
  7895. case MATCH:
  7896. if (left === 0) { break inf_leave; }
  7897. copy = _out - left;
  7898. if (state.offset > copy) { /* copy from window */
  7899. copy = state.offset - copy;
  7900. if (copy > state.whave) {
  7901. if (state.sane) {
  7902. strm.msg = 'invalid distance too far back';
  7903. state.mode = BAD;
  7904. break;
  7905. }
  7906. // (!) This block is disabled in zlib defailts,
  7907. // don't enable it for binary compatibility
  7908. //#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
  7909. // Trace((stderr, "inflate.c too far\n"));
  7910. // copy -= state.whave;
  7911. // if (copy > state.length) { copy = state.length; }
  7912. // if (copy > left) { copy = left; }
  7913. // left -= copy;
  7914. // state.length -= copy;
  7915. // do {
  7916. // output[put++] = 0;
  7917. // } while (--copy);
  7918. // if (state.length === 0) { state.mode = LEN; }
  7919. // break;
  7920. //#endif
  7921. }
  7922. if (copy > state.wnext) {
  7923. copy -= state.wnext;
  7924. from = state.wsize - copy;
  7925. }
  7926. else {
  7927. from = state.wnext - copy;
  7928. }
  7929. if (copy > state.length) { copy = state.length; }
  7930. from_source = state.window;
  7931. }
  7932. else { /* copy from output */
  7933. from_source = output;
  7934. from = put - state.offset;
  7935. copy = state.length;
  7936. }
  7937. if (copy > left) { copy = left; }
  7938. left -= copy;
  7939. state.length -= copy;
  7940. do {
  7941. output[put++] = from_source[from++];
  7942. } while (--copy);
  7943. if (state.length === 0) { state.mode = LEN; }
  7944. break;
  7945. case LIT:
  7946. if (left === 0) { break inf_leave; }
  7947. output[put++] = state.length;
  7948. left--;
  7949. state.mode = LEN;
  7950. break;
  7951. case CHECK:
  7952. if (state.wrap) {
  7953. //=== NEEDBITS(32);
  7954. while (bits < 32) {
  7955. if (have === 0) { break inf_leave; }
  7956. have--;
  7957. // Use '|' insdead of '+' to make sure that result is signed
  7958. hold |= input[next++] << bits;
  7959. bits += 8;
  7960. }
  7961. //===//
  7962. _out -= left;
  7963. strm.total_out += _out;
  7964. state.total += _out;
  7965. if (_out) {
  7966. strm.adler = state.check =
  7967. /*UPDATE(state.check, put - _out, _out);*/
  7968. (state.flags ? crc32(state.check, output, _out, put - _out) : adler32(state.check, output, _out, put - _out));
  7969. }
  7970. _out = left;
  7971. // NB: crc32 stored as signed 32-bit int, zswap32 returns signed too
  7972. if ((state.flags ? hold : zswap32(hold)) !== state.check) {
  7973. strm.msg = 'incorrect data check';
  7974. state.mode = BAD;
  7975. break;
  7976. }
  7977. //=== INITBITS();
  7978. hold = 0;
  7979. bits = 0;
  7980. //===//
  7981. //Tracev((stderr, "inflate: check matches trailer\n"));
  7982. }
  7983. state.mode = LENGTH;
  7984. /* falls through */
  7985. case LENGTH:
  7986. if (state.wrap && state.flags) {
  7987. //=== NEEDBITS(32);
  7988. while (bits < 32) {
  7989. if (have === 0) { break inf_leave; }
  7990. have--;
  7991. hold += input[next++] << bits;
  7992. bits += 8;
  7993. }
  7994. //===//
  7995. if (hold !== (state.total & 0xffffffff)) {
  7996. strm.msg = 'incorrect length check';
  7997. state.mode = BAD;
  7998. break;
  7999. }
  8000. //=== INITBITS();
  8001. hold = 0;
  8002. bits = 0;
  8003. //===//
  8004. //Tracev((stderr, "inflate: length matches trailer\n"));
  8005. }
  8006. state.mode = DONE;
  8007. /* falls through */
  8008. case DONE:
  8009. ret = Z_STREAM_END;
  8010. break inf_leave;
  8011. case BAD:
  8012. ret = Z_DATA_ERROR;
  8013. break inf_leave;
  8014. case MEM:
  8015. return Z_MEM_ERROR;
  8016. case SYNC:
  8017. /* falls through */
  8018. default:
  8019. return Z_STREAM_ERROR;
  8020. }
  8021. }
  8022. // inf_leave <- here is real place for "goto inf_leave", emulated via "break inf_leave"
  8023. /*
  8024. Return from inflate(), updating the total counts and the check value.
  8025. If there was no progress during the inflate() call, return a buffer
  8026. error. Call updatewindow() to create and/or update the window state.
  8027. Note: a memory error from inflate() is non-recoverable.
  8028. */
  8029. //--- RESTORE() ---
  8030. strm.next_out = put;
  8031. strm.avail_out = left;
  8032. strm.next_in = next;
  8033. strm.avail_in = have;
  8034. state.hold = hold;
  8035. state.bits = bits;
  8036. //---
  8037. if (state.wsize || (_out !== strm.avail_out && state.mode < BAD &&
  8038. (state.mode < CHECK || flush !== Z_FINISH))) {
  8039. if (updatewindow(strm, strm.output, strm.next_out, _out - strm.avail_out)) {
  8040. state.mode = MEM;
  8041. return Z_MEM_ERROR;
  8042. }
  8043. }
  8044. _in -= strm.avail_in;
  8045. _out -= strm.avail_out;
  8046. strm.total_in += _in;
  8047. strm.total_out += _out;
  8048. state.total += _out;
  8049. if (state.wrap && _out) {
  8050. strm.adler = state.check = /*UPDATE(state.check, strm.next_out - _out, _out);*/
  8051. (state.flags ? crc32(state.check, output, _out, strm.next_out - _out) : adler32(state.check, output, _out, strm.next_out - _out));
  8052. }
  8053. strm.data_type = state.bits + (state.last ? 64 : 0) +
  8054. (state.mode === TYPE ? 128 : 0) +
  8055. (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);
  8056. if (((_in === 0 && _out === 0) || flush === Z_FINISH) && ret === Z_OK) {
  8057. ret = Z_BUF_ERROR;
  8058. }
  8059. return ret;
  8060. }
  8061. function inflateEnd(strm) {
  8062. if (!strm || !strm.state /*|| strm->zfree == (free_func)0*/) {
  8063. return Z_STREAM_ERROR;
  8064. }
  8065. var state = strm.state;
  8066. if (state.window) {
  8067. state.window = null;
  8068. }
  8069. strm.state = null;
  8070. return Z_OK;
  8071. }
  8072. function inflateGetHeader(strm, head) {
  8073. var state;
  8074. /* check state */
  8075. if (!strm || !strm.state) { return Z_STREAM_ERROR; }
  8076. state = strm.state;
  8077. if ((state.wrap & 2) === 0) { return Z_STREAM_ERROR; }
  8078. /* save header structure */
  8079. state.head = head;
  8080. head.done = false;
  8081. return Z_OK;
  8082. }
  8083. function inflateSetDictionary(strm, dictionary) {
  8084. var dictLength = dictionary.length;
  8085. var state;
  8086. var dictid;
  8087. var ret;
  8088. /* check state */
  8089. if (!strm /* == Z_NULL */ || !strm.state /* == Z_NULL */) { return Z_STREAM_ERROR; }
  8090. state = strm.state;
  8091. if (state.wrap !== 0 && state.mode !== DICT) {
  8092. return Z_STREAM_ERROR;
  8093. }
  8094. /* check for correct dictionary identifier */
  8095. if (state.mode === DICT) {
  8096. dictid = 1; /* adler32(0, null, 0)*/
  8097. /* dictid = adler32(dictid, dictionary, dictLength); */
  8098. dictid = adler32(dictid, dictionary, dictLength, 0);
  8099. if (dictid !== state.check) {
  8100. return Z_DATA_ERROR;
  8101. }
  8102. }
  8103. /* copy dictionary to window using updatewindow(), which will amend the
  8104. existing dictionary if appropriate */
  8105. ret = updatewindow(strm, dictionary, dictLength, dictLength);
  8106. if (ret) {
  8107. state.mode = MEM;
  8108. return Z_MEM_ERROR;
  8109. }
  8110. state.havedict = 1;
  8111. // Tracev((stderr, "inflate: dictionary set\n"));
  8112. return Z_OK;
  8113. }
  8114. exports.inflateReset = inflateReset;
  8115. exports.inflateReset2 = inflateReset2;
  8116. exports.inflateResetKeep = inflateResetKeep;
  8117. exports.inflateInit = inflateInit;
  8118. exports.inflateInit2 = inflateInit2;
  8119. exports.inflate = inflate;
  8120. exports.inflateEnd = inflateEnd;
  8121. exports.inflateGetHeader = inflateGetHeader;
  8122. exports.inflateSetDictionary = inflateSetDictionary;
  8123. exports.inflateInfo = 'pako inflate (from Nodeca project)';
  8124. /* Not implemented
  8125. exports.inflateCopy = inflateCopy;
  8126. exports.inflateGetDictionary = inflateGetDictionary;
  8127. exports.inflateMark = inflateMark;
  8128. exports.inflatePrime = inflatePrime;
  8129. exports.inflateSync = inflateSync;
  8130. exports.inflateSyncPoint = inflateSyncPoint;
  8131. exports.inflateUndermine = inflateUndermine;
  8132. */
  8133. },{"../utils/common":32,"./adler32":34,"./crc32":36,"./inffast":39,"./inftrees":41}],41:[function(_dereq_,module,exports){
  8134. 'use strict';
  8135. var utils = _dereq_('../utils/common');
  8136. var MAXBITS = 15;
  8137. var ENOUGH_LENS = 852;
  8138. var ENOUGH_DISTS = 592;
  8139. //var ENOUGH = (ENOUGH_LENS+ENOUGH_DISTS);
  8140. var CODES = 0;
  8141. var LENS = 1;
  8142. var DISTS = 2;
  8143. var lbase = [ /* Length codes 257..285 base */
  8144. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  8145. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0
  8146. ];
  8147. var lext = [ /* Length codes 257..285 extra */
  8148. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  8149. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78
  8150. ];
  8151. var dbase = [ /* Distance codes 0..29 base */
  8152. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  8153. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  8154. 8193, 12289, 16385, 24577, 0, 0
  8155. ];
  8156. var dext = [ /* Distance codes 0..29 extra */
  8157. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  8158. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  8159. 28, 28, 29, 29, 64, 64
  8160. ];
  8161. module.exports = function inflate_table(type, lens, lens_index, codes, table, table_index, work, opts)
  8162. {
  8163. var bits = opts.bits;
  8164. //here = opts.here; /* table entry for duplication */
  8165. var len = 0; /* a code's length in bits */
  8166. var sym = 0; /* index of code symbols */
  8167. var min = 0, max = 0; /* minimum and maximum code lengths */
  8168. var root = 0; /* number of index bits for root table */
  8169. var curr = 0; /* number of index bits for current table */
  8170. var drop = 0; /* code bits to drop for sub-table */
  8171. var left = 0; /* number of prefix codes available */
  8172. var used = 0; /* code entries in table used */
  8173. var huff = 0; /* Huffman code */
  8174. var incr; /* for incrementing code, index */
  8175. var fill; /* index for replicating entries */
  8176. var low; /* low bits for current root entry */
  8177. var mask; /* mask for low root bits */
  8178. var next; /* next available space in table */
  8179. var base = null; /* base value table to use */
  8180. var base_index = 0;
  8181. // var shoextra; /* extra bits table to use */
  8182. var end; /* use base and extra for symbol > end */
  8183. var count = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* number of codes of each length */
  8184. var offs = new utils.Buf16(MAXBITS + 1); //[MAXBITS+1]; /* offsets in table for each length */
  8185. var extra = null;
  8186. var extra_index = 0;
  8187. var here_bits, here_op, here_val;
  8188. /*
  8189. Process a set of code lengths to create a canonical Huffman code. The
  8190. code lengths are lens[0..codes-1]. Each length corresponds to the
  8191. symbols 0..codes-1. The Huffman code is generated by first sorting the
  8192. symbols by length from short to long, and retaining the symbol order
  8193. for codes with equal lengths. Then the code starts with all zero bits
  8194. for the first code of the shortest length, and the codes are integer
  8195. increments for the same length, and zeros are appended as the length
  8196. increases. For the deflate format, these bits are stored backwards
  8197. from their more natural integer increment ordering, and so when the
  8198. decoding tables are built in the large loop below, the integer codes
  8199. are incremented backwards.
  8200. This routine assumes, but does not check, that all of the entries in
  8201. lens[] are in the range 0..MAXBITS. The caller must assure this.
  8202. 1..MAXBITS is interpreted as that code length. zero means that that
  8203. symbol does not occur in this code.
  8204. The codes are sorted by computing a count of codes for each length,
  8205. creating from that a table of starting indices for each length in the
  8206. sorted table, and then entering the symbols in order in the sorted
  8207. table. The sorted table is work[], with that space being provided by
  8208. the caller.
  8209. The length counts are used for other purposes as well, i.e. finding
  8210. the minimum and maximum length codes, determining if there are any
  8211. codes at all, checking for a valid set of lengths, and looking ahead
  8212. at length counts to determine sub-table sizes when building the
  8213. decoding tables.
  8214. */
  8215. /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
  8216. for (len = 0; len <= MAXBITS; len++) {
  8217. count[len] = 0;
  8218. }
  8219. for (sym = 0; sym < codes; sym++) {
  8220. count[lens[lens_index + sym]]++;
  8221. }
  8222. /* bound code lengths, force root to be within code lengths */
  8223. root = bits;
  8224. for (max = MAXBITS; max >= 1; max--) {
  8225. if (count[max] !== 0) { break; }
  8226. }
  8227. if (root > max) {
  8228. root = max;
  8229. }
  8230. if (max === 0) { /* no symbols to code at all */
  8231. //table.op[opts.table_index] = 64; //here.op = (var char)64; /* invalid code marker */
  8232. //table.bits[opts.table_index] = 1; //here.bits = (var char)1;
  8233. //table.val[opts.table_index++] = 0; //here.val = (var short)0;
  8234. table[table_index++] = (1 << 24) | (64 << 16) | 0;
  8235. //table.op[opts.table_index] = 64;
  8236. //table.bits[opts.table_index] = 1;
  8237. //table.val[opts.table_index++] = 0;
  8238. table[table_index++] = (1 << 24) | (64 << 16) | 0;
  8239. opts.bits = 1;
  8240. return 0; /* no symbols, but wait for decoding to report error */
  8241. }
  8242. for (min = 1; min < max; min++) {
  8243. if (count[min] !== 0) { break; }
  8244. }
  8245. if (root < min) {
  8246. root = min;
  8247. }
  8248. /* check for an over-subscribed or incomplete set of lengths */
  8249. left = 1;
  8250. for (len = 1; len <= MAXBITS; len++) {
  8251. left <<= 1;
  8252. left -= count[len];
  8253. if (left < 0) {
  8254. return -1;
  8255. } /* over-subscribed */
  8256. }
  8257. if (left > 0 && (type === CODES || max !== 1)) {
  8258. return -1; /* incomplete set */
  8259. }
  8260. /* generate offsets into symbol table for each length for sorting */
  8261. offs[1] = 0;
  8262. for (len = 1; len < MAXBITS; len++) {
  8263. offs[len + 1] = offs[len] + count[len];
  8264. }
  8265. /* sort symbols by length, by symbol order within each length */
  8266. for (sym = 0; sym < codes; sym++) {
  8267. if (lens[lens_index + sym] !== 0) {
  8268. work[offs[lens[lens_index + sym]]++] = sym;
  8269. }
  8270. }
  8271. /*
  8272. Create and fill in decoding tables. In this loop, the table being
  8273. filled is at next and has curr index bits. The code being used is huff
  8274. with length len. That code is converted to an index by dropping drop
  8275. bits off of the bottom. For codes where len is less than drop + curr,
  8276. those top drop + curr - len bits are incremented through all values to
  8277. fill the table with replicated entries.
  8278. root is the number of index bits for the root table. When len exceeds
  8279. root, sub-tables are created pointed to by the root entry with an index
  8280. of the low root bits of huff. This is saved in low to check for when a
  8281. new sub-table should be started. drop is zero when the root table is
  8282. being filled, and drop is root when sub-tables are being filled.
  8283. When a new sub-table is needed, it is necessary to look ahead in the
  8284. code lengths to determine what size sub-table is needed. The length
  8285. counts are used for this, and so count[] is decremented as codes are
  8286. entered in the tables.
  8287. used keeps track of how many table entries have been allocated from the
  8288. provided *table space. It is checked for LENS and DIST tables against
  8289. the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
  8290. the initial root table size constants. See the comments in inftrees.h
  8291. for more information.
  8292. sym increments through all symbols, and the loop terminates when
  8293. all codes of length max, i.e. all codes, have been processed. This
  8294. routine permits incomplete codes, so another loop after this one fills
  8295. in the rest of the decoding tables with invalid code markers.
  8296. */
  8297. /* set up for code type */
  8298. // poor man optimization - use if-else instead of switch,
  8299. // to avoid deopts in old v8
  8300. if (type === CODES) {
  8301. base = extra = work; /* dummy value--not used */
  8302. end = 19;
  8303. } else if (type === LENS) {
  8304. base = lbase;
  8305. base_index -= 257;
  8306. extra = lext;
  8307. extra_index -= 257;
  8308. end = 256;
  8309. } else { /* DISTS */
  8310. base = dbase;
  8311. extra = dext;
  8312. end = -1;
  8313. }
  8314. /* initialize opts for loop */
  8315. huff = 0; /* starting code */
  8316. sym = 0; /* starting code symbol */
  8317. len = min; /* starting code length */
  8318. next = table_index; /* current table to fill in */
  8319. curr = root; /* current table index bits */
  8320. drop = 0; /* current bits to drop from code for index */
  8321. low = -1; /* trigger new sub-table when len > root */
  8322. used = 1 << root; /* use root table entries */
  8323. mask = used - 1; /* mask for comparing low */
  8324. /* check available table space */
  8325. if ((type === LENS && used > ENOUGH_LENS) ||
  8326. (type === DISTS && used > ENOUGH_DISTS)) {
  8327. return 1;
  8328. }
  8329. var i = 0;
  8330. /* process all codes and make table entries */
  8331. for (;;) {
  8332. i++;
  8333. /* create table entry */
  8334. here_bits = len - drop;
  8335. if (work[sym] < end) {
  8336. here_op = 0;
  8337. here_val = work[sym];
  8338. }
  8339. else if (work[sym] > end) {
  8340. here_op = extra[extra_index + work[sym]];
  8341. here_val = base[base_index + work[sym]];
  8342. }
  8343. else {
  8344. here_op = 32 + 64; /* end of block */
  8345. here_val = 0;
  8346. }
  8347. /* replicate for those indices with low len bits equal to huff */
  8348. incr = 1 << (len - drop);
  8349. fill = 1 << curr;
  8350. min = fill; /* save offset to next table */
  8351. do {
  8352. fill -= incr;
  8353. table[next + (huff >> drop) + fill] = (here_bits << 24) | (here_op << 16) | here_val |0;
  8354. } while (fill !== 0);
  8355. /* backwards increment the len-bit code huff */
  8356. incr = 1 << (len - 1);
  8357. while (huff & incr) {
  8358. incr >>= 1;
  8359. }
  8360. if (incr !== 0) {
  8361. huff &= incr - 1;
  8362. huff += incr;
  8363. } else {
  8364. huff = 0;
  8365. }
  8366. /* go to next symbol, update count, len */
  8367. sym++;
  8368. if (--count[len] === 0) {
  8369. if (len === max) { break; }
  8370. len = lens[lens_index + work[sym]];
  8371. }
  8372. /* create new sub-table if needed */
  8373. if (len > root && (huff & mask) !== low) {
  8374. /* if first time, transition to sub-tables */
  8375. if (drop === 0) {
  8376. drop = root;
  8377. }
  8378. /* increment past last table */
  8379. next += min; /* here min is 1 << curr */
  8380. /* determine length of next table */
  8381. curr = len - drop;
  8382. left = 1 << curr;
  8383. while (curr + drop < max) {
  8384. left -= count[curr + drop];
  8385. if (left <= 0) { break; }
  8386. curr++;
  8387. left <<= 1;
  8388. }
  8389. /* check for enough space */
  8390. used += 1 << curr;
  8391. if ((type === LENS && used > ENOUGH_LENS) ||
  8392. (type === DISTS && used > ENOUGH_DISTS)) {
  8393. return 1;
  8394. }
  8395. /* point entry in root table to sub-table */
  8396. low = huff & mask;
  8397. /*table.op[low] = curr;
  8398. table.bits[low] = root;
  8399. table.val[low] = next - opts.table_index;*/
  8400. table[low] = (root << 24) | (curr << 16) | (next - table_index) |0;
  8401. }
  8402. }
  8403. /* fill in remaining table entry if code is incomplete (guaranteed to have
  8404. at most one remaining entry, since if the code is incomplete, the
  8405. maximum code length that was allowed to get this far is one bit) */
  8406. if (huff !== 0) {
  8407. //table.op[next + huff] = 64; /* invalid code marker */
  8408. //table.bits[next + huff] = len - drop;
  8409. //table.val[next + huff] = 0;
  8410. table[next + huff] = ((len - drop) << 24) | (64 << 16) |0;
  8411. }
  8412. /* set return parameters */
  8413. //opts.table_index += used;
  8414. opts.bits = root;
  8415. return 0;
  8416. };
  8417. },{"../utils/common":32}],42:[function(_dereq_,module,exports){
  8418. 'use strict';
  8419. module.exports = {
  8420. 2: 'need dictionary', /* Z_NEED_DICT 2 */
  8421. 1: 'stream end', /* Z_STREAM_END 1 */
  8422. 0: '', /* Z_OK 0 */
  8423. '-1': 'file error', /* Z_ERRNO (-1) */
  8424. '-2': 'stream error', /* Z_STREAM_ERROR (-2) */
  8425. '-3': 'data error', /* Z_DATA_ERROR (-3) */
  8426. '-4': 'insufficient memory', /* Z_MEM_ERROR (-4) */
  8427. '-5': 'buffer error', /* Z_BUF_ERROR (-5) */
  8428. '-6': 'incompatible version' /* Z_VERSION_ERROR (-6) */
  8429. };
  8430. },{}],43:[function(_dereq_,module,exports){
  8431. 'use strict';
  8432. var utils = _dereq_('../utils/common');
  8433. /* Public constants ==========================================================*/
  8434. /* ===========================================================================*/
  8435. //var Z_FILTERED = 1;
  8436. //var Z_HUFFMAN_ONLY = 2;
  8437. //var Z_RLE = 3;
  8438. var Z_FIXED = 4;
  8439. //var Z_DEFAULT_STRATEGY = 0;
  8440. /* Possible values of the data_type field (though see inflate()) */
  8441. var Z_BINARY = 0;
  8442. var Z_TEXT = 1;
  8443. //var Z_ASCII = 1; // = Z_TEXT
  8444. var Z_UNKNOWN = 2;
  8445. /*============================================================================*/
  8446. function zero(buf) { var len = buf.length; while (--len >= 0) { buf[len] = 0; } }
  8447. // From zutil.h
  8448. var STORED_BLOCK = 0;
  8449. var STATIC_TREES = 1;
  8450. var DYN_TREES = 2;
  8451. /* The three kinds of block type */
  8452. var MIN_MATCH = 3;
  8453. var MAX_MATCH = 258;
  8454. /* The minimum and maximum match lengths */
  8455. // From deflate.h
  8456. /* ===========================================================================
  8457. * Internal compression state.
  8458. */
  8459. var LENGTH_CODES = 29;
  8460. /* number of length codes, not counting the special END_BLOCK code */
  8461. var LITERALS = 256;
  8462. /* number of literal bytes 0..255 */
  8463. var L_CODES = LITERALS + 1 + LENGTH_CODES;
  8464. /* number of Literal or Length codes, including the END_BLOCK code */
  8465. var D_CODES = 30;
  8466. /* number of distance codes */
  8467. var BL_CODES = 19;
  8468. /* number of codes used to transfer the bit lengths */
  8469. var HEAP_SIZE = 2 * L_CODES + 1;
  8470. /* maximum heap size */
  8471. var MAX_BITS = 15;
  8472. /* All codes must not exceed MAX_BITS bits */
  8473. var Buf_size = 16;
  8474. /* size of bit buffer in bi_buf */
  8475. /* ===========================================================================
  8476. * Constants
  8477. */
  8478. var MAX_BL_BITS = 7;
  8479. /* Bit length codes must not exceed MAX_BL_BITS bits */
  8480. var END_BLOCK = 256;
  8481. /* end of block literal code */
  8482. var REP_3_6 = 16;
  8483. /* repeat previous bit length 3-6 times (2 bits of repeat count) */
  8484. var REPZ_3_10 = 17;
  8485. /* repeat a zero length 3-10 times (3 bits of repeat count) */
  8486. var REPZ_11_138 = 18;
  8487. /* repeat a zero length 11-138 times (7 bits of repeat count) */
  8488. /* eslint-disable comma-spacing,array-bracket-spacing */
  8489. var extra_lbits = /* extra bits for each length code */
  8490. [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];
  8491. var extra_dbits = /* extra bits for each distance code */
  8492. [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];
  8493. var extra_blbits = /* extra bits for each bit length code */
  8494. [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7];
  8495. var bl_order =
  8496. [16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];
  8497. /* eslint-enable comma-spacing,array-bracket-spacing */
  8498. /* The lengths of the bit length codes are sent in order of decreasing
  8499. * probability, to avoid transmitting the lengths for unused bit length codes.
  8500. */
  8501. /* ===========================================================================
  8502. * Local data. These are initialized only once.
  8503. */
  8504. // We pre-fill arrays with 0 to avoid uninitialized gaps
  8505. var DIST_CODE_LEN = 512; /* see definition of array dist_code below */
  8506. // !!!! Use flat array insdead of structure, Freq = i*2, Len = i*2+1
  8507. var static_ltree = new Array((L_CODES + 2) * 2);
  8508. zero(static_ltree);
  8509. /* The static literal tree. Since the bit lengths are imposed, there is no
  8510. * need for the L_CODES extra codes used during heap construction. However
  8511. * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
  8512. * below).
  8513. */
  8514. var static_dtree = new Array(D_CODES * 2);
  8515. zero(static_dtree);
  8516. /* The static distance tree. (Actually a trivial tree since all codes use
  8517. * 5 bits.)
  8518. */
  8519. var _dist_code = new Array(DIST_CODE_LEN);
  8520. zero(_dist_code);
  8521. /* Distance codes. The first 256 values correspond to the distances
  8522. * 3 .. 258, the last 256 values correspond to the top 8 bits of
  8523. * the 15 bit distances.
  8524. */
  8525. var _length_code = new Array(MAX_MATCH - MIN_MATCH + 1);
  8526. zero(_length_code);
  8527. /* length code for each normalized match length (0 == MIN_MATCH) */
  8528. var base_length = new Array(LENGTH_CODES);
  8529. zero(base_length);
  8530. /* First normalized length for each code (0 = MIN_MATCH) */
  8531. var base_dist = new Array(D_CODES);
  8532. zero(base_dist);
  8533. /* First normalized distance for each code (0 = distance of 1) */
  8534. function StaticTreeDesc(static_tree, extra_bits, extra_base, elems, max_length) {
  8535. this.static_tree = static_tree; /* static tree or NULL */
  8536. this.extra_bits = extra_bits; /* extra bits for each code or NULL */
  8537. this.extra_base = extra_base; /* base index for extra_bits */
  8538. this.elems = elems; /* max number of elements in the tree */
  8539. this.max_length = max_length; /* max bit length for the codes */
  8540. // show if `static_tree` has data or dummy - needed for monomorphic objects
  8541. this.has_stree = static_tree && static_tree.length;
  8542. }
  8543. var static_l_desc;
  8544. var static_d_desc;
  8545. var static_bl_desc;
  8546. function TreeDesc(dyn_tree, stat_desc) {
  8547. this.dyn_tree = dyn_tree; /* the dynamic tree */
  8548. this.max_code = 0; /* largest code with non zero frequency */
  8549. this.stat_desc = stat_desc; /* the corresponding static tree */
  8550. }
  8551. function d_code(dist) {
  8552. return dist < 256 ? _dist_code[dist] : _dist_code[256 + (dist >>> 7)];
  8553. }
  8554. /* ===========================================================================
  8555. * Output a short LSB first on the stream.
  8556. * IN assertion: there is enough room in pendingBuf.
  8557. */
  8558. function put_short(s, w) {
  8559. // put_byte(s, (uch)((w) & 0xff));
  8560. // put_byte(s, (uch)((ush)(w) >> 8));
  8561. s.pending_buf[s.pending++] = (w) & 0xff;
  8562. s.pending_buf[s.pending++] = (w >>> 8) & 0xff;
  8563. }
  8564. /* ===========================================================================
  8565. * Send a value on a given number of bits.
  8566. * IN assertion: length <= 16 and value fits in length bits.
  8567. */
  8568. function send_bits(s, value, length) {
  8569. if (s.bi_valid > (Buf_size - length)) {
  8570. s.bi_buf |= (value << s.bi_valid) & 0xffff;
  8571. put_short(s, s.bi_buf);
  8572. s.bi_buf = value >> (Buf_size - s.bi_valid);
  8573. s.bi_valid += length - Buf_size;
  8574. } else {
  8575. s.bi_buf |= (value << s.bi_valid) & 0xffff;
  8576. s.bi_valid += length;
  8577. }
  8578. }
  8579. function send_code(s, c, tree) {
  8580. send_bits(s, tree[c * 2]/*.Code*/, tree[c * 2 + 1]/*.Len*/);
  8581. }
  8582. /* ===========================================================================
  8583. * Reverse the first len bits of a code, using straightforward code (a faster
  8584. * method would use a table)
  8585. * IN assertion: 1 <= len <= 15
  8586. */
  8587. function bi_reverse(code, len) {
  8588. var res = 0;
  8589. do {
  8590. res |= code & 1;
  8591. code >>>= 1;
  8592. res <<= 1;
  8593. } while (--len > 0);
  8594. return res >>> 1;
  8595. }
  8596. /* ===========================================================================
  8597. * Flush the bit buffer, keeping at most 7 bits in it.
  8598. */
  8599. function bi_flush(s) {
  8600. if (s.bi_valid === 16) {
  8601. put_short(s, s.bi_buf);
  8602. s.bi_buf = 0;
  8603. s.bi_valid = 0;
  8604. } else if (s.bi_valid >= 8) {
  8605. s.pending_buf[s.pending++] = s.bi_buf & 0xff;
  8606. s.bi_buf >>= 8;
  8607. s.bi_valid -= 8;
  8608. }
  8609. }
  8610. /* ===========================================================================
  8611. * Compute the optimal bit lengths for a tree and update the total bit length
  8612. * for the current block.
  8613. * IN assertion: the fields freq and dad are set, heap[heap_max] and
  8614. * above are the tree nodes sorted by increasing frequency.
  8615. * OUT assertions: the field len is set to the optimal bit length, the
  8616. * array bl_count contains the frequencies for each bit length.
  8617. * The length opt_len is updated; static_len is also updated if stree is
  8618. * not null.
  8619. */
  8620. function gen_bitlen(s, desc)
  8621. // deflate_state *s;
  8622. // tree_desc *desc; /* the tree descriptor */
  8623. {
  8624. var tree = desc.dyn_tree;
  8625. var max_code = desc.max_code;
  8626. var stree = desc.stat_desc.static_tree;
  8627. var has_stree = desc.stat_desc.has_stree;
  8628. var extra = desc.stat_desc.extra_bits;
  8629. var base = desc.stat_desc.extra_base;
  8630. var max_length = desc.stat_desc.max_length;
  8631. var h; /* heap index */
  8632. var n, m; /* iterate over the tree elements */
  8633. var bits; /* bit length */
  8634. var xbits; /* extra bits */
  8635. var f; /* frequency */
  8636. var overflow = 0; /* number of elements with bit length too large */
  8637. for (bits = 0; bits <= MAX_BITS; bits++) {
  8638. s.bl_count[bits] = 0;
  8639. }
  8640. /* In a first pass, compute the optimal bit lengths (which may
  8641. * overflow in the case of the bit length tree).
  8642. */
  8643. tree[s.heap[s.heap_max] * 2 + 1]/*.Len*/ = 0; /* root of the heap */
  8644. for (h = s.heap_max + 1; h < HEAP_SIZE; h++) {
  8645. n = s.heap[h];
  8646. bits = tree[tree[n * 2 + 1]/*.Dad*/ * 2 + 1]/*.Len*/ + 1;
  8647. if (bits > max_length) {
  8648. bits = max_length;
  8649. overflow++;
  8650. }
  8651. tree[n * 2 + 1]/*.Len*/ = bits;
  8652. /* We overwrite tree[n].Dad which is no longer needed */
  8653. if (n > max_code) { continue; } /* not a leaf node */
  8654. s.bl_count[bits]++;
  8655. xbits = 0;
  8656. if (n >= base) {
  8657. xbits = extra[n - base];
  8658. }
  8659. f = tree[n * 2]/*.Freq*/;
  8660. s.opt_len += f * (bits + xbits);
  8661. if (has_stree) {
  8662. s.static_len += f * (stree[n * 2 + 1]/*.Len*/ + xbits);
  8663. }
  8664. }
  8665. if (overflow === 0) { return; }
  8666. // Trace((stderr,"\nbit length overflow\n"));
  8667. /* This happens for example on obj2 and pic of the Calgary corpus */
  8668. /* Find the first bit length which could increase: */
  8669. do {
  8670. bits = max_length - 1;
  8671. while (s.bl_count[bits] === 0) { bits--; }
  8672. s.bl_count[bits]--; /* move one leaf down the tree */
  8673. s.bl_count[bits + 1] += 2; /* move one overflow item as its brother */
  8674. s.bl_count[max_length]--;
  8675. /* The brother of the overflow item also moves one step up,
  8676. * but this does not affect bl_count[max_length]
  8677. */
  8678. overflow -= 2;
  8679. } while (overflow > 0);
  8680. /* Now recompute all bit lengths, scanning in increasing frequency.
  8681. * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
  8682. * lengths instead of fixing only the wrong ones. This idea is taken
  8683. * from 'ar' written by Haruhiko Okumura.)
  8684. */
  8685. for (bits = max_length; bits !== 0; bits--) {
  8686. n = s.bl_count[bits];
  8687. while (n !== 0) {
  8688. m = s.heap[--h];
  8689. if (m > max_code) { continue; }
  8690. if (tree[m * 2 + 1]/*.Len*/ !== bits) {
  8691. // Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  8692. s.opt_len += (bits - tree[m * 2 + 1]/*.Len*/) * tree[m * 2]/*.Freq*/;
  8693. tree[m * 2 + 1]/*.Len*/ = bits;
  8694. }
  8695. n--;
  8696. }
  8697. }
  8698. }
  8699. /* ===========================================================================
  8700. * Generate the codes for a given tree and bit counts (which need not be
  8701. * optimal).
  8702. * IN assertion: the array bl_count contains the bit length statistics for
  8703. * the given tree and the field len is set for all tree elements.
  8704. * OUT assertion: the field code is set for all tree elements of non
  8705. * zero code length.
  8706. */
  8707. function gen_codes(tree, max_code, bl_count)
  8708. // ct_data *tree; /* the tree to decorate */
  8709. // int max_code; /* largest code with non zero frequency */
  8710. // ushf *bl_count; /* number of codes at each bit length */
  8711. {
  8712. var next_code = new Array(MAX_BITS + 1); /* next code value for each bit length */
  8713. var code = 0; /* running code value */
  8714. var bits; /* bit index */
  8715. var n; /* code index */
  8716. /* The distribution counts are first used to generate the code values
  8717. * without bit reversal.
  8718. */
  8719. for (bits = 1; bits <= MAX_BITS; bits++) {
  8720. next_code[bits] = code = (code + bl_count[bits - 1]) << 1;
  8721. }
  8722. /* Check that the bit counts in bl_count are consistent. The last code
  8723. * must be all ones.
  8724. */
  8725. //Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  8726. // "inconsistent bit counts");
  8727. //Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  8728. for (n = 0; n <= max_code; n++) {
  8729. var len = tree[n * 2 + 1]/*.Len*/;
  8730. if (len === 0) { continue; }
  8731. /* Now reverse the bits */
  8732. tree[n * 2]/*.Code*/ = bi_reverse(next_code[len]++, len);
  8733. //Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  8734. // n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  8735. }
  8736. }
  8737. /* ===========================================================================
  8738. * Initialize the various 'constant' tables.
  8739. */
  8740. function tr_static_init() {
  8741. var n; /* iterates over tree elements */
  8742. var bits; /* bit counter */
  8743. var length; /* length value */
  8744. var code; /* code value */
  8745. var dist; /* distance index */
  8746. var bl_count = new Array(MAX_BITS + 1);
  8747. /* number of codes at each bit length for an optimal tree */
  8748. // do check in _tr_init()
  8749. //if (static_init_done) return;
  8750. /* For some embedded targets, global variables are not initialized: */
  8751. /*#ifdef NO_INIT_GLOBAL_POINTERS
  8752. static_l_desc.static_tree = static_ltree;
  8753. static_l_desc.extra_bits = extra_lbits;
  8754. static_d_desc.static_tree = static_dtree;
  8755. static_d_desc.extra_bits = extra_dbits;
  8756. static_bl_desc.extra_bits = extra_blbits;
  8757. #endif*/
  8758. /* Initialize the mapping length (0..255) -> length code (0..28) */
  8759. length = 0;
  8760. for (code = 0; code < LENGTH_CODES - 1; code++) {
  8761. base_length[code] = length;
  8762. for (n = 0; n < (1 << extra_lbits[code]); n++) {
  8763. _length_code[length++] = code;
  8764. }
  8765. }
  8766. //Assert (length == 256, "tr_static_init: length != 256");
  8767. /* Note that the length 255 (match length 258) can be represented
  8768. * in two different ways: code 284 + 5 bits or code 285, so we
  8769. * overwrite length_code[255] to use the best encoding:
  8770. */
  8771. _length_code[length - 1] = code;
  8772. /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
  8773. dist = 0;
  8774. for (code = 0; code < 16; code++) {
  8775. base_dist[code] = dist;
  8776. for (n = 0; n < (1 << extra_dbits[code]); n++) {
  8777. _dist_code[dist++] = code;
  8778. }
  8779. }
  8780. //Assert (dist == 256, "tr_static_init: dist != 256");
  8781. dist >>= 7; /* from now on, all distances are divided by 128 */
  8782. for (; code < D_CODES; code++) {
  8783. base_dist[code] = dist << 7;
  8784. for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) {
  8785. _dist_code[256 + dist++] = code;
  8786. }
  8787. }
  8788. //Assert (dist == 256, "tr_static_init: 256+dist != 512");
  8789. /* Construct the codes of the static literal tree */
  8790. for (bits = 0; bits <= MAX_BITS; bits++) {
  8791. bl_count[bits] = 0;
  8792. }
  8793. n = 0;
  8794. while (n <= 143) {
  8795. static_ltree[n * 2 + 1]/*.Len*/ = 8;
  8796. n++;
  8797. bl_count[8]++;
  8798. }
  8799. while (n <= 255) {
  8800. static_ltree[n * 2 + 1]/*.Len*/ = 9;
  8801. n++;
  8802. bl_count[9]++;
  8803. }
  8804. while (n <= 279) {
  8805. static_ltree[n * 2 + 1]/*.Len*/ = 7;
  8806. n++;
  8807. bl_count[7]++;
  8808. }
  8809. while (n <= 287) {
  8810. static_ltree[n * 2 + 1]/*.Len*/ = 8;
  8811. n++;
  8812. bl_count[8]++;
  8813. }
  8814. /* Codes 286 and 287 do not exist, but we must include them in the
  8815. * tree construction to get a canonical Huffman tree (longest code
  8816. * all ones)
  8817. */
  8818. gen_codes(static_ltree, L_CODES + 1, bl_count);
  8819. /* The static distance tree is trivial: */
  8820. for (n = 0; n < D_CODES; n++) {
  8821. static_dtree[n * 2 + 1]/*.Len*/ = 5;
  8822. static_dtree[n * 2]/*.Code*/ = bi_reverse(n, 5);
  8823. }
  8824. // Now data ready and we can init static trees
  8825. static_l_desc = new StaticTreeDesc(static_ltree, extra_lbits, LITERALS + 1, L_CODES, MAX_BITS);
  8826. static_d_desc = new StaticTreeDesc(static_dtree, extra_dbits, 0, D_CODES, MAX_BITS);
  8827. static_bl_desc = new StaticTreeDesc(new Array(0), extra_blbits, 0, BL_CODES, MAX_BL_BITS);
  8828. //static_init_done = true;
  8829. }
  8830. /* ===========================================================================
  8831. * Initialize a new block.
  8832. */
  8833. function init_block(s) {
  8834. var n; /* iterates over tree elements */
  8835. /* Initialize the trees. */
  8836. for (n = 0; n < L_CODES; n++) { s.dyn_ltree[n * 2]/*.Freq*/ = 0; }
  8837. for (n = 0; n < D_CODES; n++) { s.dyn_dtree[n * 2]/*.Freq*/ = 0; }
  8838. for (n = 0; n < BL_CODES; n++) { s.bl_tree[n * 2]/*.Freq*/ = 0; }
  8839. s.dyn_ltree[END_BLOCK * 2]/*.Freq*/ = 1;
  8840. s.opt_len = s.static_len = 0;
  8841. s.last_lit = s.matches = 0;
  8842. }
  8843. /* ===========================================================================
  8844. * Flush the bit buffer and align the output on a byte boundary
  8845. */
  8846. function bi_windup(s)
  8847. {
  8848. if (s.bi_valid > 8) {
  8849. put_short(s, s.bi_buf);
  8850. } else if (s.bi_valid > 0) {
  8851. //put_byte(s, (Byte)s->bi_buf);
  8852. s.pending_buf[s.pending++] = s.bi_buf;
  8853. }
  8854. s.bi_buf = 0;
  8855. s.bi_valid = 0;
  8856. }
  8857. /* ===========================================================================
  8858. * Copy a stored block, storing first the length and its
  8859. * one's complement if requested.
  8860. */
  8861. function copy_block(s, buf, len, header)
  8862. //DeflateState *s;
  8863. //charf *buf; /* the input data */
  8864. //unsigned len; /* its length */
  8865. //int header; /* true if block header must be written */
  8866. {
  8867. bi_windup(s); /* align on byte boundary */
  8868. if (header) {
  8869. put_short(s, len);
  8870. put_short(s, ~len);
  8871. }
  8872. // while (len--) {
  8873. // put_byte(s, *buf++);
  8874. // }
  8875. utils.arraySet(s.pending_buf, s.window, buf, len, s.pending);
  8876. s.pending += len;
  8877. }
  8878. /* ===========================================================================
  8879. * Compares to subtrees, using the tree depth as tie breaker when
  8880. * the subtrees have equal frequency. This minimizes the worst case length.
  8881. */
  8882. function smaller(tree, n, m, depth) {
  8883. var _n2 = n * 2;
  8884. var _m2 = m * 2;
  8885. return (tree[_n2]/*.Freq*/ < tree[_m2]/*.Freq*/ ||
  8886. (tree[_n2]/*.Freq*/ === tree[_m2]/*.Freq*/ && depth[n] <= depth[m]));
  8887. }
  8888. /* ===========================================================================
  8889. * Restore the heap property by moving down the tree starting at node k,
  8890. * exchanging a node with the smallest of its two sons if necessary, stopping
  8891. * when the heap property is re-established (each father smaller than its
  8892. * two sons).
  8893. */
  8894. function pqdownheap(s, tree, k)
  8895. // deflate_state *s;
  8896. // ct_data *tree; /* the tree to restore */
  8897. // int k; /* node to move down */
  8898. {
  8899. var v = s.heap[k];
  8900. var j = k << 1; /* left son of k */
  8901. while (j <= s.heap_len) {
  8902. /* Set j to the smallest of the two sons: */
  8903. if (j < s.heap_len &&
  8904. smaller(tree, s.heap[j + 1], s.heap[j], s.depth)) {
  8905. j++;
  8906. }
  8907. /* Exit if v is smaller than both sons */
  8908. if (smaller(tree, v, s.heap[j], s.depth)) { break; }
  8909. /* Exchange v with the smallest son */
  8910. s.heap[k] = s.heap[j];
  8911. k = j;
  8912. /* And continue down the tree, setting j to the left son of k */
  8913. j <<= 1;
  8914. }
  8915. s.heap[k] = v;
  8916. }
  8917. // inlined manually
  8918. // var SMALLEST = 1;
  8919. /* ===========================================================================
  8920. * Send the block data compressed using the given Huffman trees
  8921. */
  8922. function compress_block(s, ltree, dtree)
  8923. // deflate_state *s;
  8924. // const ct_data *ltree; /* literal tree */
  8925. // const ct_data *dtree; /* distance tree */
  8926. {
  8927. var dist; /* distance of matched string */
  8928. var lc; /* match length or unmatched char (if dist == 0) */
  8929. var lx = 0; /* running index in l_buf */
  8930. var code; /* the code to send */
  8931. var extra; /* number of extra bits to send */
  8932. if (s.last_lit !== 0) {
  8933. do {
  8934. dist = (s.pending_buf[s.d_buf + lx * 2] << 8) | (s.pending_buf[s.d_buf + lx * 2 + 1]);
  8935. lc = s.pending_buf[s.l_buf + lx];
  8936. lx++;
  8937. if (dist === 0) {
  8938. send_code(s, lc, ltree); /* send a literal byte */
  8939. //Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  8940. } else {
  8941. /* Here, lc is the match length - MIN_MATCH */
  8942. code = _length_code[lc];
  8943. send_code(s, code + LITERALS + 1, ltree); /* send the length code */
  8944. extra = extra_lbits[code];
  8945. if (extra !== 0) {
  8946. lc -= base_length[code];
  8947. send_bits(s, lc, extra); /* send the extra length bits */
  8948. }
  8949. dist--; /* dist is now the match distance - 1 */
  8950. code = d_code(dist);
  8951. //Assert (code < D_CODES, "bad d_code");
  8952. send_code(s, code, dtree); /* send the distance code */
  8953. extra = extra_dbits[code];
  8954. if (extra !== 0) {
  8955. dist -= base_dist[code];
  8956. send_bits(s, dist, extra); /* send the extra distance bits */
  8957. }
  8958. } /* literal or match pair ? */
  8959. /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
  8960. //Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  8961. // "pendingBuf overflow");
  8962. } while (lx < s.last_lit);
  8963. }
  8964. send_code(s, END_BLOCK, ltree);
  8965. }
  8966. /* ===========================================================================
  8967. * Construct one Huffman tree and assigns the code bit strings and lengths.
  8968. * Update the total bit length for the current block.
  8969. * IN assertion: the field freq is set for all tree elements.
  8970. * OUT assertions: the fields len and code are set to the optimal bit length
  8971. * and corresponding code. The length opt_len is updated; static_len is
  8972. * also updated if stree is not null. The field max_code is set.
  8973. */
  8974. function build_tree(s, desc)
  8975. // deflate_state *s;
  8976. // tree_desc *desc; /* the tree descriptor */
  8977. {
  8978. var tree = desc.dyn_tree;
  8979. var stree = desc.stat_desc.static_tree;
  8980. var has_stree = desc.stat_desc.has_stree;
  8981. var elems = desc.stat_desc.elems;
  8982. var n, m; /* iterate over heap elements */
  8983. var max_code = -1; /* largest code with non zero frequency */
  8984. var node; /* new node being created */
  8985. /* Construct the initial heap, with least frequent element in
  8986. * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
  8987. * heap[0] is not used.
  8988. */
  8989. s.heap_len = 0;
  8990. s.heap_max = HEAP_SIZE;
  8991. for (n = 0; n < elems; n++) {
  8992. if (tree[n * 2]/*.Freq*/ !== 0) {
  8993. s.heap[++s.heap_len] = max_code = n;
  8994. s.depth[n] = 0;
  8995. } else {
  8996. tree[n * 2 + 1]/*.Len*/ = 0;
  8997. }
  8998. }
  8999. /* The pkzip format requires that at least one distance code exists,
  9000. * and that at least one bit should be sent even if there is only one
  9001. * possible code. So to avoid special checks later on we force at least
  9002. * two codes of non zero frequency.
  9003. */
  9004. while (s.heap_len < 2) {
  9005. node = s.heap[++s.heap_len] = (max_code < 2 ? ++max_code : 0);
  9006. tree[node * 2]/*.Freq*/ = 1;
  9007. s.depth[node] = 0;
  9008. s.opt_len--;
  9009. if (has_stree) {
  9010. s.static_len -= stree[node * 2 + 1]/*.Len*/;
  9011. }
  9012. /* node is 0 or 1 so it does not have extra bits */
  9013. }
  9014. desc.max_code = max_code;
  9015. /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
  9016. * establish sub-heaps of increasing lengths:
  9017. */
  9018. for (n = (s.heap_len >> 1/*int /2*/); n >= 1; n--) { pqdownheap(s, tree, n); }
  9019. /* Construct the Huffman tree by repeatedly combining the least two
  9020. * frequent nodes.
  9021. */
  9022. node = elems; /* next internal node of the tree */
  9023. do {
  9024. //pqremove(s, tree, n); /* n = node of least frequency */
  9025. /*** pqremove ***/
  9026. n = s.heap[1/*SMALLEST*/];
  9027. s.heap[1/*SMALLEST*/] = s.heap[s.heap_len--];
  9028. pqdownheap(s, tree, 1/*SMALLEST*/);
  9029. /***/
  9030. m = s.heap[1/*SMALLEST*/]; /* m = node of next least frequency */
  9031. s.heap[--s.heap_max] = n; /* keep the nodes sorted by frequency */
  9032. s.heap[--s.heap_max] = m;
  9033. /* Create a new node father of n and m */
  9034. tree[node * 2]/*.Freq*/ = tree[n * 2]/*.Freq*/ + tree[m * 2]/*.Freq*/;
  9035. s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;
  9036. tree[n * 2 + 1]/*.Dad*/ = tree[m * 2 + 1]/*.Dad*/ = node;
  9037. /* and insert the new node in the heap */
  9038. s.heap[1/*SMALLEST*/] = node++;
  9039. pqdownheap(s, tree, 1/*SMALLEST*/);
  9040. } while (s.heap_len >= 2);
  9041. s.heap[--s.heap_max] = s.heap[1/*SMALLEST*/];
  9042. /* At this point, the fields freq and dad are set. We can now
  9043. * generate the bit lengths.
  9044. */
  9045. gen_bitlen(s, desc);
  9046. /* The field len is now set, we can generate the bit codes */
  9047. gen_codes(tree, max_code, s.bl_count);
  9048. }
  9049. /* ===========================================================================
  9050. * Scan a literal or distance tree to determine the frequencies of the codes
  9051. * in the bit length tree.
  9052. */
  9053. function scan_tree(s, tree, max_code)
  9054. // deflate_state *s;
  9055. // ct_data *tree; /* the tree to be scanned */
  9056. // int max_code; /* and its largest code of non zero frequency */
  9057. {
  9058. var n; /* iterates over all tree elements */
  9059. var prevlen = -1; /* last emitted length */
  9060. var curlen; /* length of current code */
  9061. var nextlen = tree[0 * 2 + 1]/*.Len*/; /* length of next code */
  9062. var count = 0; /* repeat count of the current code */
  9063. var max_count = 7; /* max repeat count */
  9064. var min_count = 4; /* min repeat count */
  9065. if (nextlen === 0) {
  9066. max_count = 138;
  9067. min_count = 3;
  9068. }
  9069. tree[(max_code + 1) * 2 + 1]/*.Len*/ = 0xffff; /* guard */
  9070. for (n = 0; n <= max_code; n++) {
  9071. curlen = nextlen;
  9072. nextlen = tree[(n + 1) * 2 + 1]/*.Len*/;
  9073. if (++count < max_count && curlen === nextlen) {
  9074. continue;
  9075. } else if (count < min_count) {
  9076. s.bl_tree[curlen * 2]/*.Freq*/ += count;
  9077. } else if (curlen !== 0) {
  9078. if (curlen !== prevlen) { s.bl_tree[curlen * 2]/*.Freq*/++; }
  9079. s.bl_tree[REP_3_6 * 2]/*.Freq*/++;
  9080. } else if (count <= 10) {
  9081. s.bl_tree[REPZ_3_10 * 2]/*.Freq*/++;
  9082. } else {
  9083. s.bl_tree[REPZ_11_138 * 2]/*.Freq*/++;
  9084. }
  9085. count = 0;
  9086. prevlen = curlen;
  9087. if (nextlen === 0) {
  9088. max_count = 138;
  9089. min_count = 3;
  9090. } else if (curlen === nextlen) {
  9091. max_count = 6;
  9092. min_count = 3;
  9093. } else {
  9094. max_count = 7;
  9095. min_count = 4;
  9096. }
  9097. }
  9098. }
  9099. /* ===========================================================================
  9100. * Send a literal or distance tree in compressed form, using the codes in
  9101. * bl_tree.
  9102. */
  9103. function send_tree(s, tree, max_code)
  9104. // deflate_state *s;
  9105. // ct_data *tree; /* the tree to be scanned */
  9106. // int max_code; /* and its largest code of non zero frequency */
  9107. {
  9108. var n; /* iterates over all tree elements */
  9109. var prevlen = -1; /* last emitted length */
  9110. var curlen; /* length of current code */
  9111. var nextlen = tree[0 * 2 + 1]/*.Len*/; /* length of next code */
  9112. var count = 0; /* repeat count of the current code */
  9113. var max_count = 7; /* max repeat count */
  9114. var min_count = 4; /* min repeat count */
  9115. /* tree[max_code+1].Len = -1; */ /* guard already set */
  9116. if (nextlen === 0) {
  9117. max_count = 138;
  9118. min_count = 3;
  9119. }
  9120. for (n = 0; n <= max_code; n++) {
  9121. curlen = nextlen;
  9122. nextlen = tree[(n + 1) * 2 + 1]/*.Len*/;
  9123. if (++count < max_count && curlen === nextlen) {
  9124. continue;
  9125. } else if (count < min_count) {
  9126. do { send_code(s, curlen, s.bl_tree); } while (--count !== 0);
  9127. } else if (curlen !== 0) {
  9128. if (curlen !== prevlen) {
  9129. send_code(s, curlen, s.bl_tree);
  9130. count--;
  9131. }
  9132. //Assert(count >= 3 && count <= 6, " 3_6?");
  9133. send_code(s, REP_3_6, s.bl_tree);
  9134. send_bits(s, count - 3, 2);
  9135. } else if (count <= 10) {
  9136. send_code(s, REPZ_3_10, s.bl_tree);
  9137. send_bits(s, count - 3, 3);
  9138. } else {
  9139. send_code(s, REPZ_11_138, s.bl_tree);
  9140. send_bits(s, count - 11, 7);
  9141. }
  9142. count = 0;
  9143. prevlen = curlen;
  9144. if (nextlen === 0) {
  9145. max_count = 138;
  9146. min_count = 3;
  9147. } else if (curlen === nextlen) {
  9148. max_count = 6;
  9149. min_count = 3;
  9150. } else {
  9151. max_count = 7;
  9152. min_count = 4;
  9153. }
  9154. }
  9155. }
  9156. /* ===========================================================================
  9157. * Construct the Huffman tree for the bit lengths and return the index in
  9158. * bl_order of the last bit length code to send.
  9159. */
  9160. function build_bl_tree(s) {
  9161. var max_blindex; /* index of last bit length code of non zero freq */
  9162. /* Determine the bit length frequencies for literal and distance trees */
  9163. scan_tree(s, s.dyn_ltree, s.l_desc.max_code);
  9164. scan_tree(s, s.dyn_dtree, s.d_desc.max_code);
  9165. /* Build the bit length tree: */
  9166. build_tree(s, s.bl_desc);
  9167. /* opt_len now includes the length of the tree representations, except
  9168. * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
  9169. */
  9170. /* Determine the number of bit length codes to send. The pkzip format
  9171. * requires that at least 4 bit length codes be sent. (appnote.txt says
  9172. * 3 but the actual value used is 4.)
  9173. */
  9174. for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) {
  9175. if (s.bl_tree[bl_order[max_blindex] * 2 + 1]/*.Len*/ !== 0) {
  9176. break;
  9177. }
  9178. }
  9179. /* Update opt_len to include the bit length tree and counts */
  9180. s.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
  9181. //Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  9182. // s->opt_len, s->static_len));
  9183. return max_blindex;
  9184. }
  9185. /* ===========================================================================
  9186. * Send the header for a block using dynamic Huffman trees: the counts, the
  9187. * lengths of the bit length codes, the literal tree and the distance tree.
  9188. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
  9189. */
  9190. function send_all_trees(s, lcodes, dcodes, blcodes)
  9191. // deflate_state *s;
  9192. // int lcodes, dcodes, blcodes; /* number of codes for each tree */
  9193. {
  9194. var rank; /* index in bl_order */
  9195. //Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  9196. //Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  9197. // "too many codes");
  9198. //Tracev((stderr, "\nbl counts: "));
  9199. send_bits(s, lcodes - 257, 5); /* not +255 as stated in appnote.txt */
  9200. send_bits(s, dcodes - 1, 5);
  9201. send_bits(s, blcodes - 4, 4); /* not -3 as stated in appnote.txt */
  9202. for (rank = 0; rank < blcodes; rank++) {
  9203. //Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  9204. send_bits(s, s.bl_tree[bl_order[rank] * 2 + 1]/*.Len*/, 3);
  9205. }
  9206. //Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  9207. send_tree(s, s.dyn_ltree, lcodes - 1); /* literal tree */
  9208. //Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  9209. send_tree(s, s.dyn_dtree, dcodes - 1); /* distance tree */
  9210. //Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  9211. }
  9212. /* ===========================================================================
  9213. * Check if the data type is TEXT or BINARY, using the following algorithm:
  9214. * - TEXT if the two conditions below are satisfied:
  9215. * a) There are no non-portable control characters belonging to the
  9216. * "black list" (0..6, 14..25, 28..31).
  9217. * b) There is at least one printable character belonging to the
  9218. * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
  9219. * - BINARY otherwise.
  9220. * - The following partially-portable control characters form a
  9221. * "gray list" that is ignored in this detection algorithm:
  9222. * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
  9223. * IN assertion: the fields Freq of dyn_ltree are set.
  9224. */
  9225. function detect_data_type(s) {
  9226. /* black_mask is the bit mask of black-listed bytes
  9227. * set bits 0..6, 14..25, and 28..31
  9228. * 0xf3ffc07f = binary 11110011111111111100000001111111
  9229. */
  9230. var black_mask = 0xf3ffc07f;
  9231. var n;
  9232. /* Check for non-textual ("black-listed") bytes. */
  9233. for (n = 0; n <= 31; n++, black_mask >>>= 1) {
  9234. if ((black_mask & 1) && (s.dyn_ltree[n * 2]/*.Freq*/ !== 0)) {
  9235. return Z_BINARY;
  9236. }
  9237. }
  9238. /* Check for textual ("white-listed") bytes. */
  9239. if (s.dyn_ltree[9 * 2]/*.Freq*/ !== 0 || s.dyn_ltree[10 * 2]/*.Freq*/ !== 0 ||
  9240. s.dyn_ltree[13 * 2]/*.Freq*/ !== 0) {
  9241. return Z_TEXT;
  9242. }
  9243. for (n = 32; n < LITERALS; n++) {
  9244. if (s.dyn_ltree[n * 2]/*.Freq*/ !== 0) {
  9245. return Z_TEXT;
  9246. }
  9247. }
  9248. /* There are no "black-listed" or "white-listed" bytes:
  9249. * this stream either is empty or has tolerated ("gray-listed") bytes only.
  9250. */
  9251. return Z_BINARY;
  9252. }
  9253. var static_init_done = false;
  9254. /* ===========================================================================
  9255. * Initialize the tree data structures for a new zlib stream.
  9256. */
  9257. function _tr_init(s)
  9258. {
  9259. if (!static_init_done) {
  9260. tr_static_init();
  9261. static_init_done = true;
  9262. }
  9263. s.l_desc = new TreeDesc(s.dyn_ltree, static_l_desc);
  9264. s.d_desc = new TreeDesc(s.dyn_dtree, static_d_desc);
  9265. s.bl_desc = new TreeDesc(s.bl_tree, static_bl_desc);
  9266. s.bi_buf = 0;
  9267. s.bi_valid = 0;
  9268. /* Initialize the first block of the first file: */
  9269. init_block(s);
  9270. }
  9271. /* ===========================================================================
  9272. * Send a stored block
  9273. */
  9274. function _tr_stored_block(s, buf, stored_len, last)
  9275. //DeflateState *s;
  9276. //charf *buf; /* input block */
  9277. //ulg stored_len; /* length of input block */
  9278. //int last; /* one if this is the last block for a file */
  9279. {
  9280. send_bits(s, (STORED_BLOCK << 1) + (last ? 1 : 0), 3); /* send block type */
  9281. copy_block(s, buf, stored_len, true); /* with header */
  9282. }
  9283. /* ===========================================================================
  9284. * Send one empty static block to give enough lookahead for inflate.
  9285. * This takes 10 bits, of which 7 may remain in the bit buffer.
  9286. */
  9287. function _tr_align(s) {
  9288. send_bits(s, STATIC_TREES << 1, 3);
  9289. send_code(s, END_BLOCK, static_ltree);
  9290. bi_flush(s);
  9291. }
  9292. /* ===========================================================================
  9293. * Determine the best encoding for the current block: dynamic trees, static
  9294. * trees or store, and output the encoded block to the zip file.
  9295. */
  9296. function _tr_flush_block(s, buf, stored_len, last)
  9297. //DeflateState *s;
  9298. //charf *buf; /* input block, or NULL if too old */
  9299. //ulg stored_len; /* length of input block */
  9300. //int last; /* one if this is the last block for a file */
  9301. {
  9302. var opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  9303. var max_blindex = 0; /* index of last bit length code of non zero freq */
  9304. /* Build the Huffman trees unless a stored block is forced */
  9305. if (s.level > 0) {
  9306. /* Check if the file is binary or text */
  9307. if (s.strm.data_type === Z_UNKNOWN) {
  9308. s.strm.data_type = detect_data_type(s);
  9309. }
  9310. /* Construct the literal and distance trees */
  9311. build_tree(s, s.l_desc);
  9312. // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  9313. // s->static_len));
  9314. build_tree(s, s.d_desc);
  9315. // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  9316. // s->static_len));
  9317. /* At this point, opt_len and static_len are the total bit lengths of
  9318. * the compressed block data, excluding the tree representations.
  9319. */
  9320. /* Build the bit length tree for the above two trees, and get the index
  9321. * in bl_order of the last bit length code to send.
  9322. */
  9323. max_blindex = build_bl_tree(s);
  9324. /* Determine the best encoding. Compute the block lengths in bytes. */
  9325. opt_lenb = (s.opt_len + 3 + 7) >>> 3;
  9326. static_lenb = (s.static_len + 3 + 7) >>> 3;
  9327. // Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  9328. // opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  9329. // s->last_lit));
  9330. if (static_lenb <= opt_lenb) { opt_lenb = static_lenb; }
  9331. } else {
  9332. // Assert(buf != (char*)0, "lost buf");
  9333. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  9334. }
  9335. if ((stored_len + 4 <= opt_lenb) && (buf !== -1)) {
  9336. /* 4: two words for the lengths */
  9337. /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
  9338. * Otherwise we can't have processed more than WSIZE input bytes since
  9339. * the last block flush, because compression would have been
  9340. * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
  9341. * transform a block into a stored block.
  9342. */
  9343. _tr_stored_block(s, buf, stored_len, last);
  9344. } else if (s.strategy === Z_FIXED || static_lenb === opt_lenb) {
  9345. send_bits(s, (STATIC_TREES << 1) + (last ? 1 : 0), 3);
  9346. compress_block(s, static_ltree, static_dtree);
  9347. } else {
  9348. send_bits(s, (DYN_TREES << 1) + (last ? 1 : 0), 3);
  9349. send_all_trees(s, s.l_desc.max_code + 1, s.d_desc.max_code + 1, max_blindex + 1);
  9350. compress_block(s, s.dyn_ltree, s.dyn_dtree);
  9351. }
  9352. // Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  9353. /* The above check is made mod 2^32, for files larger than 512 MB
  9354. * and uLong implemented on 32 bits.
  9355. */
  9356. init_block(s);
  9357. if (last) {
  9358. bi_windup(s);
  9359. }
  9360. // Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  9361. // s->compressed_len-7*last));
  9362. }
  9363. /* ===========================================================================
  9364. * Save the match info and tally the frequency counts. Return true if
  9365. * the current block must be flushed.
  9366. */
  9367. function _tr_tally(s, dist, lc)
  9368. // deflate_state *s;
  9369. // unsigned dist; /* distance of matched string */
  9370. // unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
  9371. {
  9372. //var out_length, in_length, dcode;
  9373. s.pending_buf[s.d_buf + s.last_lit * 2] = (dist >>> 8) & 0xff;
  9374. s.pending_buf[s.d_buf + s.last_lit * 2 + 1] = dist & 0xff;
  9375. s.pending_buf[s.l_buf + s.last_lit] = lc & 0xff;
  9376. s.last_lit++;
  9377. if (dist === 0) {
  9378. /* lc is the unmatched char */
  9379. s.dyn_ltree[lc * 2]/*.Freq*/++;
  9380. } else {
  9381. s.matches++;
  9382. /* Here, lc is the match length - MIN_MATCH */
  9383. dist--; /* dist = match distance - 1 */
  9384. //Assert((ush)dist < (ush)MAX_DIST(s) &&
  9385. // (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  9386. // (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  9387. s.dyn_ltree[(_length_code[lc] + LITERALS + 1) * 2]/*.Freq*/++;
  9388. s.dyn_dtree[d_code(dist) * 2]/*.Freq*/++;
  9389. }
  9390. // (!) This block is disabled in zlib defailts,
  9391. // don't enable it for binary compatibility
  9392. //#ifdef TRUNCATE_BLOCK
  9393. // /* Try to guess if it is profitable to stop the current block here */
  9394. // if ((s.last_lit & 0x1fff) === 0 && s.level > 2) {
  9395. // /* Compute an upper bound for the compressed length */
  9396. // out_length = s.last_lit*8;
  9397. // in_length = s.strstart - s.block_start;
  9398. //
  9399. // for (dcode = 0; dcode < D_CODES; dcode++) {
  9400. // out_length += s.dyn_dtree[dcode*2]/*.Freq*/ * (5 + extra_dbits[dcode]);
  9401. // }
  9402. // out_length >>>= 3;
  9403. // //Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  9404. // // s->last_lit, in_length, out_length,
  9405. // // 100L - out_length*100L/in_length));
  9406. // if (s.matches < (s.last_lit>>1)/*int /2*/ && out_length < (in_length>>1)/*int /2*/) {
  9407. // return true;
  9408. // }
  9409. // }
  9410. //#endif
  9411. return (s.last_lit === s.lit_bufsize - 1);
  9412. /* We avoid equality with lit_bufsize because of wraparound at 64K
  9413. * on 16 bit machines and because stored blocks are restricted to
  9414. * 64K-1 bytes.
  9415. */
  9416. }
  9417. exports._tr_init = _tr_init;
  9418. exports._tr_stored_block = _tr_stored_block;
  9419. exports._tr_flush_block = _tr_flush_block;
  9420. exports._tr_tally = _tr_tally;
  9421. exports._tr_align = _tr_align;
  9422. },{"../utils/common":32}],44:[function(_dereq_,module,exports){
  9423. 'use strict';
  9424. function ZStream() {
  9425. /* next input byte */
  9426. this.input = null; // JS specific, because we have no pointers
  9427. this.next_in = 0;
  9428. /* number of bytes available at input */
  9429. this.avail_in = 0;
  9430. /* total number of input bytes read so far */
  9431. this.total_in = 0;
  9432. /* next output byte should be put there */
  9433. this.output = null; // JS specific, because we have no pointers
  9434. this.next_out = 0;
  9435. /* remaining free space at output */
  9436. this.avail_out = 0;
  9437. /* total number of bytes output so far */
  9438. this.total_out = 0;
  9439. /* last error message, NULL if no error */
  9440. this.msg = ''/*Z_NULL*/;
  9441. /* not visible by applications */
  9442. this.state = null;
  9443. /* best guess about the data type: binary or text */
  9444. this.data_type = 2/*Z_UNKNOWN*/;
  9445. /* adler32 value of the uncompressed data */
  9446. this.adler = 0;
  9447. }
  9448. module.exports = ZStream;
  9449. },{}],45:[function(_dereq_,module,exports){
  9450. /**
  9451. * lodash 3.2.0 (Custom Build) <https://lodash.com/>
  9452. * Build: `lodash modularize exports="npm" -o ./`
  9453. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  9454. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9455. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9456. * Available under MIT license <https://lodash.com/license>
  9457. */
  9458. var root = _dereq_('lodash._root');
  9459. /** Used as references for various `Number` constants. */
  9460. var INFINITY = 1 / 0;
  9461. /** `Object#toString` result references. */
  9462. var symbolTag = '[object Symbol]';
  9463. /** Used to match HTML entities and HTML characters. */
  9464. var reUnescapedHtml = /[&<>"'`]/g,
  9465. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  9466. /** Used to map characters to HTML entities. */
  9467. var htmlEscapes = {
  9468. '&': '&amp;',
  9469. '<': '&lt;',
  9470. '>': '&gt;',
  9471. '"': '&quot;',
  9472. "'": '&#39;',
  9473. '`': '&#96;'
  9474. };
  9475. /**
  9476. * Used by `_.escape` to convert characters to HTML entities.
  9477. *
  9478. * @private
  9479. * @param {string} chr The matched character to escape.
  9480. * @returns {string} Returns the escaped character.
  9481. */
  9482. function escapeHtmlChar(chr) {
  9483. return htmlEscapes[chr];
  9484. }
  9485. /** Used for built-in method references. */
  9486. var objectProto = Object.prototype;
  9487. /**
  9488. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  9489. * of values.
  9490. */
  9491. var objectToString = objectProto.toString;
  9492. /** Built-in value references. */
  9493. var Symbol = root.Symbol;
  9494. /** Used to convert symbols to primitives and strings. */
  9495. var symbolProto = Symbol ? Symbol.prototype : undefined,
  9496. symbolToString = Symbol ? symbolProto.toString : undefined;
  9497. /**
  9498. * Checks if `value` is object-like. A value is object-like if it's not `null`
  9499. * and has a `typeof` result of "object".
  9500. *
  9501. * @static
  9502. * @memberOf _
  9503. * @category Lang
  9504. * @param {*} value The value to check.
  9505. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  9506. * @example
  9507. *
  9508. * _.isObjectLike({});
  9509. * // => true
  9510. *
  9511. * _.isObjectLike([1, 2, 3]);
  9512. * // => true
  9513. *
  9514. * _.isObjectLike(_.noop);
  9515. * // => false
  9516. *
  9517. * _.isObjectLike(null);
  9518. * // => false
  9519. */
  9520. function isObjectLike(value) {
  9521. return !!value && typeof value == 'object';
  9522. }
  9523. /**
  9524. * Checks if `value` is classified as a `Symbol` primitive or object.
  9525. *
  9526. * @static
  9527. * @memberOf _
  9528. * @category Lang
  9529. * @param {*} value The value to check.
  9530. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  9531. * @example
  9532. *
  9533. * _.isSymbol(Symbol.iterator);
  9534. * // => true
  9535. *
  9536. * _.isSymbol('abc');
  9537. * // => false
  9538. */
  9539. function isSymbol(value) {
  9540. return typeof value == 'symbol' ||
  9541. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  9542. }
  9543. /**
  9544. * Converts `value` to a string if it's not one. An empty string is returned
  9545. * for `null` and `undefined` values. The sign of `-0` is preserved.
  9546. *
  9547. * @static
  9548. * @memberOf _
  9549. * @category Lang
  9550. * @param {*} value The value to process.
  9551. * @returns {string} Returns the string.
  9552. * @example
  9553. *
  9554. * _.toString(null);
  9555. * // => ''
  9556. *
  9557. * _.toString(-0);
  9558. * // => '-0'
  9559. *
  9560. * _.toString([1, 2, 3]);
  9561. * // => '1,2,3'
  9562. */
  9563. function toString(value) {
  9564. // Exit early for strings to avoid a performance hit in some environments.
  9565. if (typeof value == 'string') {
  9566. return value;
  9567. }
  9568. if (value == null) {
  9569. return '';
  9570. }
  9571. if (isSymbol(value)) {
  9572. return Symbol ? symbolToString.call(value) : '';
  9573. }
  9574. var result = (value + '');
  9575. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  9576. }
  9577. /**
  9578. * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
  9579. * their corresponding HTML entities.
  9580. *
  9581. * **Note:** No other characters are escaped. To escape additional
  9582. * characters use a third-party library like [_he_](https://mths.be/he).
  9583. *
  9584. * Though the ">" character is escaped for symmetry, characters like
  9585. * ">" and "/" don't need escaping in HTML and have no special meaning
  9586. * unless they're part of a tag or unquoted attribute value.
  9587. * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  9588. * (under "semi-related fun fact") for more details.
  9589. *
  9590. * Backticks are escaped because in IE < 9, they can break out of
  9591. * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
  9592. * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
  9593. * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
  9594. * for more details.
  9595. *
  9596. * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
  9597. * to reduce XSS vectors.
  9598. *
  9599. * @static
  9600. * @memberOf _
  9601. * @category String
  9602. * @param {string} [string=''] The string to escape.
  9603. * @returns {string} Returns the escaped string.
  9604. * @example
  9605. *
  9606. * _.escape('fred, barney, & pebbles');
  9607. * // => 'fred, barney, &amp; pebbles'
  9608. */
  9609. function escape(string) {
  9610. string = toString(string);
  9611. return (string && reHasUnescapedHtml.test(string))
  9612. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  9613. : string;
  9614. }
  9615. module.exports = escape;
  9616. },{"lodash._root":46}],46:[function(_dereq_,module,exports){
  9617. (function (global){
  9618. /**
  9619. * lodash 3.0.1 (Custom Build) <https://lodash.com/>
  9620. * Build: `lodash modularize exports="npm" -o ./`
  9621. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  9622. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9623. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9624. * Available under MIT license <https://lodash.com/license>
  9625. */
  9626. /** Used to determine if values are of the language type `Object`. */
  9627. var objectTypes = {
  9628. 'function': true,
  9629. 'object': true
  9630. };
  9631. /** Detect free variable `exports`. */
  9632. var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType)
  9633. ? exports
  9634. : undefined;
  9635. /** Detect free variable `module`. */
  9636. var freeModule = (objectTypes[typeof module] && module && !module.nodeType)
  9637. ? module
  9638. : undefined;
  9639. /** Detect free variable `global` from Node.js. */
  9640. var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'object' && global);
  9641. /** Detect free variable `self`. */
  9642. var freeSelf = checkGlobal(objectTypes[typeof self] && self);
  9643. /** Detect free variable `window`. */
  9644. var freeWindow = checkGlobal(objectTypes[typeof window] && window);
  9645. /** Detect `this` as the global object. */
  9646. var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
  9647. /**
  9648. * Used as a reference to the global object.
  9649. *
  9650. * The `this` value is used if it's the global object to avoid Greasemonkey's
  9651. * restricted `window` object, otherwise the `window` object is used.
  9652. */
  9653. var root = freeGlobal ||
  9654. ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) ||
  9655. freeSelf || thisGlobal || Function('return this')();
  9656. /**
  9657. * Checks if `value` is a global object.
  9658. *
  9659. * @private
  9660. * @param {*} value The value to check.
  9661. * @returns {null|Object} Returns `value` if it's a global object, else `null`.
  9662. */
  9663. function checkGlobal(value) {
  9664. return (value && value.Object === Object) ? value : null;
  9665. }
  9666. module.exports = root;
  9667. }).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  9668. },{}],47:[function(_dereq_,module,exports){
  9669. /**
  9670. * lodash 3.3.2 (Custom Build) <https://lodash.com/>
  9671. * Build: `lodash modern modularize exports="npm" -o ./`
  9672. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  9673. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9674. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9675. * Available under MIT license <https://lodash.com/license>
  9676. */
  9677. var arrayCopy = _dereq_('lodash._arraycopy'),
  9678. arrayEach = _dereq_('lodash._arrayeach'),
  9679. createAssigner = _dereq_('lodash._createassigner'),
  9680. isArguments = _dereq_('lodash.isarguments'),
  9681. isArray = _dereq_('lodash.isarray'),
  9682. isPlainObject = _dereq_('lodash.isplainobject'),
  9683. isTypedArray = _dereq_('lodash.istypedarray'),
  9684. keys = _dereq_('lodash.keys'),
  9685. toPlainObject = _dereq_('lodash.toplainobject');
  9686. /**
  9687. * Checks if `value` is object-like.
  9688. *
  9689. * @private
  9690. * @param {*} value The value to check.
  9691. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  9692. */
  9693. function isObjectLike(value) {
  9694. return !!value && typeof value == 'object';
  9695. }
  9696. /**
  9697. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  9698. * of an array-like value.
  9699. */
  9700. var MAX_SAFE_INTEGER = 9007199254740991;
  9701. /**
  9702. * The base implementation of `_.merge` without support for argument juggling,
  9703. * multiple sources, and `this` binding `customizer` functions.
  9704. *
  9705. * @private
  9706. * @param {Object} object The destination object.
  9707. * @param {Object} source The source object.
  9708. * @param {Function} [customizer] The function to customize merged values.
  9709. * @param {Array} [stackA=[]] Tracks traversed source objects.
  9710. * @param {Array} [stackB=[]] Associates values with source counterparts.
  9711. * @returns {Object} Returns `object`.
  9712. */
  9713. function baseMerge(object, source, customizer, stackA, stackB) {
  9714. if (!isObject(object)) {
  9715. return object;
  9716. }
  9717. var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
  9718. props = isSrcArr ? undefined : keys(source);
  9719. arrayEach(props || source, function(srcValue, key) {
  9720. if (props) {
  9721. key = srcValue;
  9722. srcValue = source[key];
  9723. }
  9724. if (isObjectLike(srcValue)) {
  9725. stackA || (stackA = []);
  9726. stackB || (stackB = []);
  9727. baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
  9728. }
  9729. else {
  9730. var value = object[key],
  9731. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  9732. isCommon = result === undefined;
  9733. if (isCommon) {
  9734. result = srcValue;
  9735. }
  9736. if ((result !== undefined || (isSrcArr && !(key in object))) &&
  9737. (isCommon || (result === result ? (result !== value) : (value === value)))) {
  9738. object[key] = result;
  9739. }
  9740. }
  9741. });
  9742. return object;
  9743. }
  9744. /**
  9745. * A specialized version of `baseMerge` for arrays and objects which performs
  9746. * deep merges and tracks traversed objects enabling objects with circular
  9747. * references to be merged.
  9748. *
  9749. * @private
  9750. * @param {Object} object The destination object.
  9751. * @param {Object} source The source object.
  9752. * @param {string} key The key of the value to merge.
  9753. * @param {Function} mergeFunc The function to merge values.
  9754. * @param {Function} [customizer] The function to customize merged values.
  9755. * @param {Array} [stackA=[]] Tracks traversed source objects.
  9756. * @param {Array} [stackB=[]] Associates values with source counterparts.
  9757. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  9758. */
  9759. function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
  9760. var length = stackA.length,
  9761. srcValue = source[key];
  9762. while (length--) {
  9763. if (stackA[length] == srcValue) {
  9764. object[key] = stackB[length];
  9765. return;
  9766. }
  9767. }
  9768. var value = object[key],
  9769. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  9770. isCommon = result === undefined;
  9771. if (isCommon) {
  9772. result = srcValue;
  9773. if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
  9774. result = isArray(value)
  9775. ? value
  9776. : (isArrayLike(value) ? arrayCopy(value) : []);
  9777. }
  9778. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  9779. result = isArguments(value)
  9780. ? toPlainObject(value)
  9781. : (isPlainObject(value) ? value : {});
  9782. }
  9783. else {
  9784. isCommon = false;
  9785. }
  9786. }
  9787. // Add the source value to the stack of traversed objects and associate
  9788. // it with its merged value.
  9789. stackA.push(srcValue);
  9790. stackB.push(result);
  9791. if (isCommon) {
  9792. // Recursively merge objects and arrays (susceptible to call stack limits).
  9793. object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
  9794. } else if (result === result ? (result !== value) : (value === value)) {
  9795. object[key] = result;
  9796. }
  9797. }
  9798. /**
  9799. * The base implementation of `_.property` without support for deep paths.
  9800. *
  9801. * @private
  9802. * @param {string} key The key of the property to get.
  9803. * @returns {Function} Returns the new function.
  9804. */
  9805. function baseProperty(key) {
  9806. return function(object) {
  9807. return object == null ? undefined : object[key];
  9808. };
  9809. }
  9810. /**
  9811. * Gets the "length" property value of `object`.
  9812. *
  9813. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  9814. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  9815. *
  9816. * @private
  9817. * @param {Object} object The object to query.
  9818. * @returns {*} Returns the "length" value.
  9819. */
  9820. var getLength = baseProperty('length');
  9821. /**
  9822. * Checks if `value` is array-like.
  9823. *
  9824. * @private
  9825. * @param {*} value The value to check.
  9826. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  9827. */
  9828. function isArrayLike(value) {
  9829. return value != null && isLength(getLength(value));
  9830. }
  9831. /**
  9832. * Checks if `value` is a valid array-like length.
  9833. *
  9834. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  9835. *
  9836. * @private
  9837. * @param {*} value The value to check.
  9838. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  9839. */
  9840. function isLength(value) {
  9841. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  9842. }
  9843. /**
  9844. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  9845. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  9846. *
  9847. * @static
  9848. * @memberOf _
  9849. * @category Lang
  9850. * @param {*} value The value to check.
  9851. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  9852. * @example
  9853. *
  9854. * _.isObject({});
  9855. * // => true
  9856. *
  9857. * _.isObject([1, 2, 3]);
  9858. * // => true
  9859. *
  9860. * _.isObject(1);
  9861. * // => false
  9862. */
  9863. function isObject(value) {
  9864. // Avoid a V8 JIT bug in Chrome 19-20.
  9865. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  9866. var type = typeof value;
  9867. return !!value && (type == 'object' || type == 'function');
  9868. }
  9869. /**
  9870. * Recursively merges own enumerable properties of the source object(s), that
  9871. * don't resolve to `undefined` into the destination object. Subsequent sources
  9872. * overwrite property assignments of previous sources. If `customizer` is
  9873. * provided it is invoked to produce the merged values of the destination and
  9874. * source properties. If `customizer` returns `undefined` merging is handled
  9875. * by the method instead. The `customizer` is bound to `thisArg` and invoked
  9876. * with five arguments: (objectValue, sourceValue, key, object, source).
  9877. *
  9878. * @static
  9879. * @memberOf _
  9880. * @category Object
  9881. * @param {Object} object The destination object.
  9882. * @param {...Object} [sources] The source objects.
  9883. * @param {Function} [customizer] The function to customize assigned values.
  9884. * @param {*} [thisArg] The `this` binding of `customizer`.
  9885. * @returns {Object} Returns `object`.
  9886. * @example
  9887. *
  9888. * var users = {
  9889. * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
  9890. * };
  9891. *
  9892. * var ages = {
  9893. * 'data': [{ 'age': 36 }, { 'age': 40 }]
  9894. * };
  9895. *
  9896. * _.merge(users, ages);
  9897. * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
  9898. *
  9899. * // using a customizer callback
  9900. * var object = {
  9901. * 'fruits': ['apple'],
  9902. * 'vegetables': ['beet']
  9903. * };
  9904. *
  9905. * var other = {
  9906. * 'fruits': ['banana'],
  9907. * 'vegetables': ['carrot']
  9908. * };
  9909. *
  9910. * _.merge(object, other, function(a, b) {
  9911. * if (_.isArray(a)) {
  9912. * return a.concat(b);
  9913. * }
  9914. * });
  9915. * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
  9916. */
  9917. var merge = createAssigner(baseMerge);
  9918. module.exports = merge;
  9919. },{"lodash._arraycopy":48,"lodash._arrayeach":49,"lodash._createassigner":50,"lodash.isarguments":55,"lodash.isarray":56,"lodash.isplainobject":57,"lodash.istypedarray":59,"lodash.keys":60,"lodash.toplainobject":62}],48:[function(_dereq_,module,exports){
  9920. /**
  9921. * lodash 3.0.0 (Custom Build) <https://lodash.com/>
  9922. * Build: `lodash modern modularize exports="npm" -o ./`
  9923. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  9924. * Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
  9925. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9926. * Available under MIT license <https://lodash.com/license>
  9927. */
  9928. /**
  9929. * Copies the values of `source` to `array`.
  9930. *
  9931. * @private
  9932. * @param {Array} source The array to copy values from.
  9933. * @param {Array} [array=[]] The array to copy values to.
  9934. * @returns {Array} Returns `array`.
  9935. */
  9936. function arrayCopy(source, array) {
  9937. var index = -1,
  9938. length = source.length;
  9939. array || (array = Array(length));
  9940. while (++index < length) {
  9941. array[index] = source[index];
  9942. }
  9943. return array;
  9944. }
  9945. module.exports = arrayCopy;
  9946. },{}],49:[function(_dereq_,module,exports){
  9947. /**
  9948. * lodash 3.0.0 (Custom Build) <https://lodash.com/>
  9949. * Build: `lodash modern modularize exports="npm" -o ./`
  9950. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  9951. * Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
  9952. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9953. * Available under MIT license <https://lodash.com/license>
  9954. */
  9955. /**
  9956. * A specialized version of `_.forEach` for arrays without support for callback
  9957. * shorthands or `this` binding.
  9958. *
  9959. * @private
  9960. * @param {Array} array The array to iterate over.
  9961. * @param {Function} iteratee The function invoked per iteration.
  9962. * @returns {Array} Returns `array`.
  9963. */
  9964. function arrayEach(array, iteratee) {
  9965. var index = -1,
  9966. length = array.length;
  9967. while (++index < length) {
  9968. if (iteratee(array[index], index, array) === false) {
  9969. break;
  9970. }
  9971. }
  9972. return array;
  9973. }
  9974. module.exports = arrayEach;
  9975. },{}],50:[function(_dereq_,module,exports){
  9976. /**
  9977. * lodash 3.1.1 (Custom Build) <https://lodash.com/>
  9978. * Build: `lodash modern modularize exports="npm" -o ./`
  9979. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  9980. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  9981. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  9982. * Available under MIT license <https://lodash.com/license>
  9983. */
  9984. var bindCallback = _dereq_('lodash._bindcallback'),
  9985. isIterateeCall = _dereq_('lodash._isiterateecall'),
  9986. restParam = _dereq_('lodash.restparam');
  9987. /**
  9988. * Creates a function that assigns properties of source object(s) to a given
  9989. * destination object.
  9990. *
  9991. * **Note:** This function is used to create `_.assign`, `_.defaults`, and `_.merge`.
  9992. *
  9993. * @private
  9994. * @param {Function} assigner The function to assign values.
  9995. * @returns {Function} Returns the new assigner function.
  9996. */
  9997. function createAssigner(assigner) {
  9998. return restParam(function(object, sources) {
  9999. var index = -1,
  10000. length = object == null ? 0 : sources.length,
  10001. customizer = length > 2 ? sources[length - 2] : undefined,
  10002. guard = length > 2 ? sources[2] : undefined,
  10003. thisArg = length > 1 ? sources[length - 1] : undefined;
  10004. if (typeof customizer == 'function') {
  10005. customizer = bindCallback(customizer, thisArg, 5);
  10006. length -= 2;
  10007. } else {
  10008. customizer = typeof thisArg == 'function' ? thisArg : undefined;
  10009. length -= (customizer ? 1 : 0);
  10010. }
  10011. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  10012. customizer = length < 3 ? undefined : customizer;
  10013. length = 1;
  10014. }
  10015. while (++index < length) {
  10016. var source = sources[index];
  10017. if (source) {
  10018. assigner(object, source, customizer);
  10019. }
  10020. }
  10021. return object;
  10022. });
  10023. }
  10024. module.exports = createAssigner;
  10025. },{"lodash._bindcallback":51,"lodash._isiterateecall":52,"lodash.restparam":53}],51:[function(_dereq_,module,exports){
  10026. /**
  10027. * lodash 3.0.1 (Custom Build) <https://lodash.com/>
  10028. * Build: `lodash modern modularize exports="npm" -o ./`
  10029. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10030. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10031. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10032. * Available under MIT license <https://lodash.com/license>
  10033. */
  10034. /**
  10035. * A specialized version of `baseCallback` which only supports `this` binding
  10036. * and specifying the number of arguments to provide to `func`.
  10037. *
  10038. * @private
  10039. * @param {Function} func The function to bind.
  10040. * @param {*} thisArg The `this` binding of `func`.
  10041. * @param {number} [argCount] The number of arguments to provide to `func`.
  10042. * @returns {Function} Returns the callback.
  10043. */
  10044. function bindCallback(func, thisArg, argCount) {
  10045. if (typeof func != 'function') {
  10046. return identity;
  10047. }
  10048. if (thisArg === undefined) {
  10049. return func;
  10050. }
  10051. switch (argCount) {
  10052. case 1: return function(value) {
  10053. return func.call(thisArg, value);
  10054. };
  10055. case 3: return function(value, index, collection) {
  10056. return func.call(thisArg, value, index, collection);
  10057. };
  10058. case 4: return function(accumulator, value, index, collection) {
  10059. return func.call(thisArg, accumulator, value, index, collection);
  10060. };
  10061. case 5: return function(value, other, key, object, source) {
  10062. return func.call(thisArg, value, other, key, object, source);
  10063. };
  10064. }
  10065. return function() {
  10066. return func.apply(thisArg, arguments);
  10067. };
  10068. }
  10069. /**
  10070. * This method returns the first argument provided to it.
  10071. *
  10072. * @static
  10073. * @memberOf _
  10074. * @category Utility
  10075. * @param {*} value Any value.
  10076. * @returns {*} Returns `value`.
  10077. * @example
  10078. *
  10079. * var object = { 'user': 'fred' };
  10080. *
  10081. * _.identity(object) === object;
  10082. * // => true
  10083. */
  10084. function identity(value) {
  10085. return value;
  10086. }
  10087. module.exports = bindCallback;
  10088. },{}],52:[function(_dereq_,module,exports){
  10089. /**
  10090. * lodash 3.0.9 (Custom Build) <https://lodash.com/>
  10091. * Build: `lodash modern modularize exports="npm" -o ./`
  10092. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10093. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10094. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10095. * Available under MIT license <https://lodash.com/license>
  10096. */
  10097. /** Used to detect unsigned integer values. */
  10098. var reIsUint = /^\d+$/;
  10099. /**
  10100. * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
  10101. * of an array-like value.
  10102. */
  10103. var MAX_SAFE_INTEGER = 9007199254740991;
  10104. /**
  10105. * The base implementation of `_.property` without support for deep paths.
  10106. *
  10107. * @private
  10108. * @param {string} key The key of the property to get.
  10109. * @returns {Function} Returns the new function.
  10110. */
  10111. function baseProperty(key) {
  10112. return function(object) {
  10113. return object == null ? undefined : object[key];
  10114. };
  10115. }
  10116. /**
  10117. * Gets the "length" property value of `object`.
  10118. *
  10119. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  10120. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  10121. *
  10122. * @private
  10123. * @param {Object} object The object to query.
  10124. * @returns {*} Returns the "length" value.
  10125. */
  10126. var getLength = baseProperty('length');
  10127. /**
  10128. * Checks if `value` is array-like.
  10129. *
  10130. * @private
  10131. * @param {*} value The value to check.
  10132. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10133. */
  10134. function isArrayLike(value) {
  10135. return value != null && isLength(getLength(value));
  10136. }
  10137. /**
  10138. * Checks if `value` is a valid array-like index.
  10139. *
  10140. * @private
  10141. * @param {*} value The value to check.
  10142. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  10143. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  10144. */
  10145. function isIndex(value, length) {
  10146. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  10147. length = length == null ? MAX_SAFE_INTEGER : length;
  10148. return value > -1 && value % 1 == 0 && value < length;
  10149. }
  10150. /**
  10151. * Checks if the provided arguments are from an iteratee call.
  10152. *
  10153. * @private
  10154. * @param {*} value The potential iteratee value argument.
  10155. * @param {*} index The potential iteratee index or key argument.
  10156. * @param {*} object The potential iteratee object argument.
  10157. * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
  10158. */
  10159. function isIterateeCall(value, index, object) {
  10160. if (!isObject(object)) {
  10161. return false;
  10162. }
  10163. var type = typeof index;
  10164. if (type == 'number'
  10165. ? (isArrayLike(object) && isIndex(index, object.length))
  10166. : (type == 'string' && index in object)) {
  10167. var other = object[index];
  10168. return value === value ? (value === other) : (other !== other);
  10169. }
  10170. return false;
  10171. }
  10172. /**
  10173. * Checks if `value` is a valid array-like length.
  10174. *
  10175. * **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
  10176. *
  10177. * @private
  10178. * @param {*} value The value to check.
  10179. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10180. */
  10181. function isLength(value) {
  10182. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10183. }
  10184. /**
  10185. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  10186. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10187. *
  10188. * @static
  10189. * @memberOf _
  10190. * @category Lang
  10191. * @param {*} value The value to check.
  10192. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10193. * @example
  10194. *
  10195. * _.isObject({});
  10196. * // => true
  10197. *
  10198. * _.isObject([1, 2, 3]);
  10199. * // => true
  10200. *
  10201. * _.isObject(1);
  10202. * // => false
  10203. */
  10204. function isObject(value) {
  10205. // Avoid a V8 JIT bug in Chrome 19-20.
  10206. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  10207. var type = typeof value;
  10208. return !!value && (type == 'object' || type == 'function');
  10209. }
  10210. module.exports = isIterateeCall;
  10211. },{}],53:[function(_dereq_,module,exports){
  10212. /**
  10213. * lodash 3.6.1 (Custom Build) <https://lodash.com/>
  10214. * Build: `lodash modern modularize exports="npm" -o ./`
  10215. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10216. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10217. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10218. * Available under MIT license <https://lodash.com/license>
  10219. */
  10220. /** Used as the `TypeError` message for "Functions" methods. */
  10221. var FUNC_ERROR_TEXT = 'Expected a function';
  10222. /* Native method references for those with the same name as other `lodash` methods. */
  10223. var nativeMax = Math.max;
  10224. /**
  10225. * Creates a function that invokes `func` with the `this` binding of the
  10226. * created function and arguments from `start` and beyond provided as an array.
  10227. *
  10228. * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
  10229. *
  10230. * @static
  10231. * @memberOf _
  10232. * @category Function
  10233. * @param {Function} func The function to apply a rest parameter to.
  10234. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10235. * @returns {Function} Returns the new function.
  10236. * @example
  10237. *
  10238. * var say = _.restParam(function(what, names) {
  10239. * return what + ' ' + _.initial(names).join(', ') +
  10240. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10241. * });
  10242. *
  10243. * say('hello', 'fred', 'barney', 'pebbles');
  10244. * // => 'hello fred, barney, & pebbles'
  10245. */
  10246. function restParam(func, start) {
  10247. if (typeof func != 'function') {
  10248. throw new TypeError(FUNC_ERROR_TEXT);
  10249. }
  10250. start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
  10251. return function() {
  10252. var args = arguments,
  10253. index = -1,
  10254. length = nativeMax(args.length - start, 0),
  10255. rest = Array(length);
  10256. while (++index < length) {
  10257. rest[index] = args[start + index];
  10258. }
  10259. switch (start) {
  10260. case 0: return func.call(this, rest);
  10261. case 1: return func.call(this, args[0], rest);
  10262. case 2: return func.call(this, args[0], args[1], rest);
  10263. }
  10264. var otherArgs = Array(start + 1);
  10265. index = -1;
  10266. while (++index < start) {
  10267. otherArgs[index] = args[index];
  10268. }
  10269. otherArgs[start] = rest;
  10270. return func.apply(this, otherArgs);
  10271. };
  10272. }
  10273. module.exports = restParam;
  10274. },{}],54:[function(_dereq_,module,exports){
  10275. /**
  10276. * lodash 3.9.1 (Custom Build) <https://lodash.com/>
  10277. * Build: `lodash modern modularize exports="npm" -o ./`
  10278. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10279. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10280. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10281. * Available under MIT license <https://lodash.com/license>
  10282. */
  10283. /** `Object#toString` result references. */
  10284. var funcTag = '[object Function]';
  10285. /** Used to detect host constructors (Safari > 5). */
  10286. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  10287. /**
  10288. * Checks if `value` is object-like.
  10289. *
  10290. * @private
  10291. * @param {*} value The value to check.
  10292. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10293. */
  10294. function isObjectLike(value) {
  10295. return !!value && typeof value == 'object';
  10296. }
  10297. /** Used for native method references. */
  10298. var objectProto = Object.prototype;
  10299. /** Used to resolve the decompiled source of functions. */
  10300. var fnToString = Function.prototype.toString;
  10301. /** Used to check objects for own properties. */
  10302. var hasOwnProperty = objectProto.hasOwnProperty;
  10303. /**
  10304. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  10305. * of values.
  10306. */
  10307. var objToString = objectProto.toString;
  10308. /** Used to detect if a method is native. */
  10309. var reIsNative = RegExp('^' +
  10310. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  10311. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  10312. );
  10313. /**
  10314. * Gets the native function at `key` of `object`.
  10315. *
  10316. * @private
  10317. * @param {Object} object The object to query.
  10318. * @param {string} key The key of the method to get.
  10319. * @returns {*} Returns the function if it's native, else `undefined`.
  10320. */
  10321. function getNative(object, key) {
  10322. var value = object == null ? undefined : object[key];
  10323. return isNative(value) ? value : undefined;
  10324. }
  10325. /**
  10326. * Checks if `value` is classified as a `Function` object.
  10327. *
  10328. * @static
  10329. * @memberOf _
  10330. * @category Lang
  10331. * @param {*} value The value to check.
  10332. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10333. * @example
  10334. *
  10335. * _.isFunction(_);
  10336. * // => true
  10337. *
  10338. * _.isFunction(/abc/);
  10339. * // => false
  10340. */
  10341. function isFunction(value) {
  10342. // The use of `Object#toString` avoids issues with the `typeof` operator
  10343. // in older versions of Chrome and Safari which return 'function' for regexes
  10344. // and Safari 8 equivalents which return 'object' for typed array constructors.
  10345. return isObject(value) && objToString.call(value) == funcTag;
  10346. }
  10347. /**
  10348. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  10349. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10350. *
  10351. * @static
  10352. * @memberOf _
  10353. * @category Lang
  10354. * @param {*} value The value to check.
  10355. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10356. * @example
  10357. *
  10358. * _.isObject({});
  10359. * // => true
  10360. *
  10361. * _.isObject([1, 2, 3]);
  10362. * // => true
  10363. *
  10364. * _.isObject(1);
  10365. * // => false
  10366. */
  10367. function isObject(value) {
  10368. // Avoid a V8 JIT bug in Chrome 19-20.
  10369. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  10370. var type = typeof value;
  10371. return !!value && (type == 'object' || type == 'function');
  10372. }
  10373. /**
  10374. * Checks if `value` is a native function.
  10375. *
  10376. * @static
  10377. * @memberOf _
  10378. * @category Lang
  10379. * @param {*} value The value to check.
  10380. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  10381. * @example
  10382. *
  10383. * _.isNative(Array.prototype.push);
  10384. * // => true
  10385. *
  10386. * _.isNative(_);
  10387. * // => false
  10388. */
  10389. function isNative(value) {
  10390. if (value == null) {
  10391. return false;
  10392. }
  10393. if (isFunction(value)) {
  10394. return reIsNative.test(fnToString.call(value));
  10395. }
  10396. return isObjectLike(value) && reIsHostCtor.test(value);
  10397. }
  10398. module.exports = getNative;
  10399. },{}],55:[function(_dereq_,module,exports){
  10400. /**
  10401. * lodash 3.0.8 (Custom Build) <https://lodash.com/>
  10402. * Build: `lodash modularize exports="npm" -o ./`
  10403. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  10404. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10405. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10406. * Available under MIT license <https://lodash.com/license>
  10407. */
  10408. /** Used as references for various `Number` constants. */
  10409. var MAX_SAFE_INTEGER = 9007199254740991;
  10410. /** `Object#toString` result references. */
  10411. var argsTag = '[object Arguments]',
  10412. funcTag = '[object Function]',
  10413. genTag = '[object GeneratorFunction]';
  10414. /** Used for built-in method references. */
  10415. var objectProto = Object.prototype;
  10416. /** Used to check objects for own properties. */
  10417. var hasOwnProperty = objectProto.hasOwnProperty;
  10418. /**
  10419. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  10420. * of values.
  10421. */
  10422. var objectToString = objectProto.toString;
  10423. /** Built-in value references. */
  10424. var propertyIsEnumerable = objectProto.propertyIsEnumerable;
  10425. /**
  10426. * The base implementation of `_.property` without support for deep paths.
  10427. *
  10428. * @private
  10429. * @param {string} key The key of the property to get.
  10430. * @returns {Function} Returns the new function.
  10431. */
  10432. function baseProperty(key) {
  10433. return function(object) {
  10434. return object == null ? undefined : object[key];
  10435. };
  10436. }
  10437. /**
  10438. * Gets the "length" property value of `object`.
  10439. *
  10440. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  10441. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  10442. *
  10443. * @private
  10444. * @param {Object} object The object to query.
  10445. * @returns {*} Returns the "length" value.
  10446. */
  10447. var getLength = baseProperty('length');
  10448. /**
  10449. * Checks if `value` is likely an `arguments` object.
  10450. *
  10451. * @static
  10452. * @memberOf _
  10453. * @category Lang
  10454. * @param {*} value The value to check.
  10455. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10456. * @example
  10457. *
  10458. * _.isArguments(function() { return arguments; }());
  10459. * // => true
  10460. *
  10461. * _.isArguments([1, 2, 3]);
  10462. * // => false
  10463. */
  10464. function isArguments(value) {
  10465. // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode.
  10466. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  10467. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  10468. }
  10469. /**
  10470. * Checks if `value` is array-like. A value is considered array-like if it's
  10471. * not a function and has a `value.length` that's an integer greater than or
  10472. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10473. *
  10474. * @static
  10475. * @memberOf _
  10476. * @category Lang
  10477. * @param {*} value The value to check.
  10478. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10479. * @example
  10480. *
  10481. * _.isArrayLike([1, 2, 3]);
  10482. * // => true
  10483. *
  10484. * _.isArrayLike(document.body.children);
  10485. * // => true
  10486. *
  10487. * _.isArrayLike('abc');
  10488. * // => true
  10489. *
  10490. * _.isArrayLike(_.noop);
  10491. * // => false
  10492. */
  10493. function isArrayLike(value) {
  10494. return value != null && isLength(getLength(value)) && !isFunction(value);
  10495. }
  10496. /**
  10497. * This method is like `_.isArrayLike` except that it also checks if `value`
  10498. * is an object.
  10499. *
  10500. * @static
  10501. * @memberOf _
  10502. * @category Lang
  10503. * @param {*} value The value to check.
  10504. * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
  10505. * @example
  10506. *
  10507. * _.isArrayLikeObject([1, 2, 3]);
  10508. * // => true
  10509. *
  10510. * _.isArrayLikeObject(document.body.children);
  10511. * // => true
  10512. *
  10513. * _.isArrayLikeObject('abc');
  10514. * // => false
  10515. *
  10516. * _.isArrayLikeObject(_.noop);
  10517. * // => false
  10518. */
  10519. function isArrayLikeObject(value) {
  10520. return isObjectLike(value) && isArrayLike(value);
  10521. }
  10522. /**
  10523. * Checks if `value` is classified as a `Function` object.
  10524. *
  10525. * @static
  10526. * @memberOf _
  10527. * @category Lang
  10528. * @param {*} value The value to check.
  10529. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10530. * @example
  10531. *
  10532. * _.isFunction(_);
  10533. * // => true
  10534. *
  10535. * _.isFunction(/abc/);
  10536. * // => false
  10537. */
  10538. function isFunction(value) {
  10539. // The use of `Object#toString` avoids issues with the `typeof` operator
  10540. // in Safari 8 which returns 'object' for typed array and weak map constructors,
  10541. // and PhantomJS 1.9 which returns 'function' for `NodeList` instances.
  10542. var tag = isObject(value) ? objectToString.call(value) : '';
  10543. return tag == funcTag || tag == genTag;
  10544. }
  10545. /**
  10546. * Checks if `value` is a valid array-like length.
  10547. *
  10548. * **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  10549. *
  10550. * @static
  10551. * @memberOf _
  10552. * @category Lang
  10553. * @param {*} value The value to check.
  10554. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10555. * @example
  10556. *
  10557. * _.isLength(3);
  10558. * // => true
  10559. *
  10560. * _.isLength(Number.MIN_VALUE);
  10561. * // => false
  10562. *
  10563. * _.isLength(Infinity);
  10564. * // => false
  10565. *
  10566. * _.isLength('3');
  10567. * // => false
  10568. */
  10569. function isLength(value) {
  10570. return typeof value == 'number' &&
  10571. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10572. }
  10573. /**
  10574. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  10575. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10576. *
  10577. * @static
  10578. * @memberOf _
  10579. * @category Lang
  10580. * @param {*} value The value to check.
  10581. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10582. * @example
  10583. *
  10584. * _.isObject({});
  10585. * // => true
  10586. *
  10587. * _.isObject([1, 2, 3]);
  10588. * // => true
  10589. *
  10590. * _.isObject(_.noop);
  10591. * // => true
  10592. *
  10593. * _.isObject(null);
  10594. * // => false
  10595. */
  10596. function isObject(value) {
  10597. var type = typeof value;
  10598. return !!value && (type == 'object' || type == 'function');
  10599. }
  10600. /**
  10601. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10602. * and has a `typeof` result of "object".
  10603. *
  10604. * @static
  10605. * @memberOf _
  10606. * @category Lang
  10607. * @param {*} value The value to check.
  10608. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10609. * @example
  10610. *
  10611. * _.isObjectLike({});
  10612. * // => true
  10613. *
  10614. * _.isObjectLike([1, 2, 3]);
  10615. * // => true
  10616. *
  10617. * _.isObjectLike(_.noop);
  10618. * // => false
  10619. *
  10620. * _.isObjectLike(null);
  10621. * // => false
  10622. */
  10623. function isObjectLike(value) {
  10624. return !!value && typeof value == 'object';
  10625. }
  10626. module.exports = isArguments;
  10627. },{}],56:[function(_dereq_,module,exports){
  10628. /**
  10629. * lodash 3.0.4 (Custom Build) <https://lodash.com/>
  10630. * Build: `lodash modern modularize exports="npm" -o ./`
  10631. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10632. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10633. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10634. * Available under MIT license <https://lodash.com/license>
  10635. */
  10636. /** `Object#toString` result references. */
  10637. var arrayTag = '[object Array]',
  10638. funcTag = '[object Function]';
  10639. /** Used to detect host constructors (Safari > 5). */
  10640. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  10641. /**
  10642. * Checks if `value` is object-like.
  10643. *
  10644. * @private
  10645. * @param {*} value The value to check.
  10646. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10647. */
  10648. function isObjectLike(value) {
  10649. return !!value && typeof value == 'object';
  10650. }
  10651. /** Used for native method references. */
  10652. var objectProto = Object.prototype;
  10653. /** Used to resolve the decompiled source of functions. */
  10654. var fnToString = Function.prototype.toString;
  10655. /** Used to check objects for own properties. */
  10656. var hasOwnProperty = objectProto.hasOwnProperty;
  10657. /**
  10658. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  10659. * of values.
  10660. */
  10661. var objToString = objectProto.toString;
  10662. /** Used to detect if a method is native. */
  10663. var reIsNative = RegExp('^' +
  10664. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  10665. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  10666. );
  10667. /* Native method references for those with the same name as other `lodash` methods. */
  10668. var nativeIsArray = getNative(Array, 'isArray');
  10669. /**
  10670. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  10671. * of an array-like value.
  10672. */
  10673. var MAX_SAFE_INTEGER = 9007199254740991;
  10674. /**
  10675. * Gets the native function at `key` of `object`.
  10676. *
  10677. * @private
  10678. * @param {Object} object The object to query.
  10679. * @param {string} key The key of the method to get.
  10680. * @returns {*} Returns the function if it's native, else `undefined`.
  10681. */
  10682. function getNative(object, key) {
  10683. var value = object == null ? undefined : object[key];
  10684. return isNative(value) ? value : undefined;
  10685. }
  10686. /**
  10687. * Checks if `value` is a valid array-like length.
  10688. *
  10689. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  10690. *
  10691. * @private
  10692. * @param {*} value The value to check.
  10693. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10694. */
  10695. function isLength(value) {
  10696. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10697. }
  10698. /**
  10699. * Checks if `value` is classified as an `Array` object.
  10700. *
  10701. * @static
  10702. * @memberOf _
  10703. * @category Lang
  10704. * @param {*} value The value to check.
  10705. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10706. * @example
  10707. *
  10708. * _.isArray([1, 2, 3]);
  10709. * // => true
  10710. *
  10711. * _.isArray(function() { return arguments; }());
  10712. * // => false
  10713. */
  10714. var isArray = nativeIsArray || function(value) {
  10715. return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
  10716. };
  10717. /**
  10718. * Checks if `value` is classified as a `Function` object.
  10719. *
  10720. * @static
  10721. * @memberOf _
  10722. * @category Lang
  10723. * @param {*} value The value to check.
  10724. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  10725. * @example
  10726. *
  10727. * _.isFunction(_);
  10728. * // => true
  10729. *
  10730. * _.isFunction(/abc/);
  10731. * // => false
  10732. */
  10733. function isFunction(value) {
  10734. // The use of `Object#toString` avoids issues with the `typeof` operator
  10735. // in older versions of Chrome and Safari which return 'function' for regexes
  10736. // and Safari 8 equivalents which return 'object' for typed array constructors.
  10737. return isObject(value) && objToString.call(value) == funcTag;
  10738. }
  10739. /**
  10740. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  10741. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10742. *
  10743. * @static
  10744. * @memberOf _
  10745. * @category Lang
  10746. * @param {*} value The value to check.
  10747. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10748. * @example
  10749. *
  10750. * _.isObject({});
  10751. * // => true
  10752. *
  10753. * _.isObject([1, 2, 3]);
  10754. * // => true
  10755. *
  10756. * _.isObject(1);
  10757. * // => false
  10758. */
  10759. function isObject(value) {
  10760. // Avoid a V8 JIT bug in Chrome 19-20.
  10761. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  10762. var type = typeof value;
  10763. return !!value && (type == 'object' || type == 'function');
  10764. }
  10765. /**
  10766. * Checks if `value` is a native function.
  10767. *
  10768. * @static
  10769. * @memberOf _
  10770. * @category Lang
  10771. * @param {*} value The value to check.
  10772. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  10773. * @example
  10774. *
  10775. * _.isNative(Array.prototype.push);
  10776. * // => true
  10777. *
  10778. * _.isNative(_);
  10779. * // => false
  10780. */
  10781. function isNative(value) {
  10782. if (value == null) {
  10783. return false;
  10784. }
  10785. if (isFunction(value)) {
  10786. return reIsNative.test(fnToString.call(value));
  10787. }
  10788. return isObjectLike(value) && reIsHostCtor.test(value);
  10789. }
  10790. module.exports = isArray;
  10791. },{}],57:[function(_dereq_,module,exports){
  10792. /**
  10793. * lodash 3.2.0 (Custom Build) <https://lodash.com/>
  10794. * Build: `lodash modern modularize exports="npm" -o ./`
  10795. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  10796. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10797. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10798. * Available under MIT license <https://lodash.com/license>
  10799. */
  10800. var baseFor = _dereq_('lodash._basefor'),
  10801. isArguments = _dereq_('lodash.isarguments'),
  10802. keysIn = _dereq_('lodash.keysin');
  10803. /** `Object#toString` result references. */
  10804. var objectTag = '[object Object]';
  10805. /**
  10806. * Checks if `value` is object-like.
  10807. *
  10808. * @private
  10809. * @param {*} value The value to check.
  10810. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10811. */
  10812. function isObjectLike(value) {
  10813. return !!value && typeof value == 'object';
  10814. }
  10815. /** Used for native method references. */
  10816. var objectProto = Object.prototype;
  10817. /** Used to check objects for own properties. */
  10818. var hasOwnProperty = objectProto.hasOwnProperty;
  10819. /**
  10820. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  10821. * of values.
  10822. */
  10823. var objToString = objectProto.toString;
  10824. /**
  10825. * The base implementation of `_.forIn` without support for callback
  10826. * shorthands and `this` binding.
  10827. *
  10828. * @private
  10829. * @param {Object} object The object to iterate over.
  10830. * @param {Function} iteratee The function invoked per iteration.
  10831. * @returns {Object} Returns `object`.
  10832. */
  10833. function baseForIn(object, iteratee) {
  10834. return baseFor(object, iteratee, keysIn);
  10835. }
  10836. /**
  10837. * Checks if `value` is a plain object, that is, an object created by the
  10838. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  10839. *
  10840. * **Note:** This method assumes objects created by the `Object` constructor
  10841. * have no inherited enumerable properties.
  10842. *
  10843. * @static
  10844. * @memberOf _
  10845. * @category Lang
  10846. * @param {*} value The value to check.
  10847. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  10848. * @example
  10849. *
  10850. * function Foo() {
  10851. * this.a = 1;
  10852. * }
  10853. *
  10854. * _.isPlainObject(new Foo);
  10855. * // => false
  10856. *
  10857. * _.isPlainObject([1, 2, 3]);
  10858. * // => false
  10859. *
  10860. * _.isPlainObject({ 'x': 0, 'y': 0 });
  10861. * // => true
  10862. *
  10863. * _.isPlainObject(Object.create(null));
  10864. * // => true
  10865. */
  10866. function isPlainObject(value) {
  10867. var Ctor;
  10868. // Exit early for non `Object` objects.
  10869. if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isArguments(value)) ||
  10870. (!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
  10871. return false;
  10872. }
  10873. // IE < 9 iterates inherited properties before own properties. If the first
  10874. // iterated property is an object's own property then there are no inherited
  10875. // enumerable properties.
  10876. var result;
  10877. // In most environments an object's own properties are iterated before
  10878. // its inherited properties. If the last iterated property is an object's
  10879. // own property then there are no inherited enumerable properties.
  10880. baseForIn(value, function(subValue, key) {
  10881. result = key;
  10882. });
  10883. return result === undefined || hasOwnProperty.call(value, result);
  10884. }
  10885. module.exports = isPlainObject;
  10886. },{"lodash._basefor":58,"lodash.isarguments":55,"lodash.keysin":61}],58:[function(_dereq_,module,exports){
  10887. /**
  10888. * lodash 3.0.3 (Custom Build) <https://lodash.com/>
  10889. * Build: `lodash modularize exports="npm" -o ./`
  10890. * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
  10891. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10892. * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10893. * Available under MIT license <https://lodash.com/license>
  10894. */
  10895. /**
  10896. * The base implementation of `baseForIn` and `baseForOwn` which iterates
  10897. * over `object` properties returned by `keysFunc` invoking `iteratee` for
  10898. * each property. Iteratee functions may exit iteration early by explicitly
  10899. * returning `false`.
  10900. *
  10901. * @private
  10902. * @param {Object} object The object to iterate over.
  10903. * @param {Function} iteratee The function invoked per iteration.
  10904. * @param {Function} keysFunc The function to get the keys of `object`.
  10905. * @returns {Object} Returns `object`.
  10906. */
  10907. var baseFor = createBaseFor();
  10908. /**
  10909. * Creates a base function for methods like `_.forIn`.
  10910. *
  10911. * @private
  10912. * @param {boolean} [fromRight] Specify iterating from right to left.
  10913. * @returns {Function} Returns the new base function.
  10914. */
  10915. function createBaseFor(fromRight) {
  10916. return function(object, iteratee, keysFunc) {
  10917. var index = -1,
  10918. iterable = Object(object),
  10919. props = keysFunc(object),
  10920. length = props.length;
  10921. while (length--) {
  10922. var key = props[fromRight ? length : ++index];
  10923. if (iteratee(iterable[key], key, iterable) === false) {
  10924. break;
  10925. }
  10926. }
  10927. return object;
  10928. };
  10929. }
  10930. module.exports = baseFor;
  10931. },{}],59:[function(_dereq_,module,exports){
  10932. /**
  10933. * lodash 3.0.6 (Custom Build) <https://lodash.com/>
  10934. * Build: `lodash modularize exports="npm" -o ./`
  10935. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  10936. * Released under MIT license <https://lodash.com/license>
  10937. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  10938. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  10939. */
  10940. /** Used as references for various `Number` constants. */
  10941. var MAX_SAFE_INTEGER = 9007199254740991;
  10942. /** `Object#toString` result references. */
  10943. var argsTag = '[object Arguments]',
  10944. arrayTag = '[object Array]',
  10945. boolTag = '[object Boolean]',
  10946. dateTag = '[object Date]',
  10947. errorTag = '[object Error]',
  10948. funcTag = '[object Function]',
  10949. mapTag = '[object Map]',
  10950. numberTag = '[object Number]',
  10951. objectTag = '[object Object]',
  10952. regexpTag = '[object RegExp]',
  10953. setTag = '[object Set]',
  10954. stringTag = '[object String]',
  10955. weakMapTag = '[object WeakMap]';
  10956. var arrayBufferTag = '[object ArrayBuffer]',
  10957. dataViewTag = '[object DataView]',
  10958. float32Tag = '[object Float32Array]',
  10959. float64Tag = '[object Float64Array]',
  10960. int8Tag = '[object Int8Array]',
  10961. int16Tag = '[object Int16Array]',
  10962. int32Tag = '[object Int32Array]',
  10963. uint8Tag = '[object Uint8Array]',
  10964. uint8ClampedTag = '[object Uint8ClampedArray]',
  10965. uint16Tag = '[object Uint16Array]',
  10966. uint32Tag = '[object Uint32Array]';
  10967. /** Used to identify `toStringTag` values of typed arrays. */
  10968. var typedArrayTags = {};
  10969. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  10970. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  10971. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  10972. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  10973. typedArrayTags[uint32Tag] = true;
  10974. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  10975. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  10976. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  10977. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  10978. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  10979. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  10980. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  10981. typedArrayTags[weakMapTag] = false;
  10982. /** Used for built-in method references. */
  10983. var objectProto = Object.prototype;
  10984. /**
  10985. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  10986. * of values.
  10987. */
  10988. var objectToString = objectProto.toString;
  10989. /**
  10990. * Checks if `value` is a valid array-like length.
  10991. *
  10992. * **Note:** This function is loosely based on
  10993. * [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  10994. *
  10995. * @static
  10996. * @memberOf _
  10997. * @since 4.0.0
  10998. * @category Lang
  10999. * @param {*} value The value to check.
  11000. * @returns {boolean} Returns `true` if `value` is a valid length,
  11001. * else `false`.
  11002. * @example
  11003. *
  11004. * _.isLength(3);
  11005. * // => true
  11006. *
  11007. * _.isLength(Number.MIN_VALUE);
  11008. * // => false
  11009. *
  11010. * _.isLength(Infinity);
  11011. * // => false
  11012. *
  11013. * _.isLength('3');
  11014. * // => false
  11015. */
  11016. function isLength(value) {
  11017. return typeof value == 'number' &&
  11018. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  11019. }
  11020. /**
  11021. * Checks if `value` is object-like. A value is object-like if it's not `null`
  11022. * and has a `typeof` result of "object".
  11023. *
  11024. * @static
  11025. * @memberOf _
  11026. * @since 4.0.0
  11027. * @category Lang
  11028. * @param {*} value The value to check.
  11029. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  11030. * @example
  11031. *
  11032. * _.isObjectLike({});
  11033. * // => true
  11034. *
  11035. * _.isObjectLike([1, 2, 3]);
  11036. * // => true
  11037. *
  11038. * _.isObjectLike(_.noop);
  11039. * // => false
  11040. *
  11041. * _.isObjectLike(null);
  11042. * // => false
  11043. */
  11044. function isObjectLike(value) {
  11045. return !!value && typeof value == 'object';
  11046. }
  11047. /**
  11048. * Checks if `value` is classified as a typed array.
  11049. *
  11050. * @static
  11051. * @memberOf _
  11052. * @since 3.0.0
  11053. * @category Lang
  11054. * @param {*} value The value to check.
  11055. * @returns {boolean} Returns `true` if `value` is correctly classified,
  11056. * else `false`.
  11057. * @example
  11058. *
  11059. * _.isTypedArray(new Uint8Array);
  11060. * // => true
  11061. *
  11062. * _.isTypedArray([]);
  11063. * // => false
  11064. */
  11065. function isTypedArray(value) {
  11066. return isObjectLike(value) &&
  11067. isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  11068. }
  11069. module.exports = isTypedArray;
  11070. },{}],60:[function(_dereq_,module,exports){
  11071. /**
  11072. * lodash 3.1.2 (Custom Build) <https://lodash.com/>
  11073. * Build: `lodash modern modularize exports="npm" -o ./`
  11074. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  11075. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  11076. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  11077. * Available under MIT license <https://lodash.com/license>
  11078. */
  11079. var getNative = _dereq_('lodash._getnative'),
  11080. isArguments = _dereq_('lodash.isarguments'),
  11081. isArray = _dereq_('lodash.isarray');
  11082. /** Used to detect unsigned integer values. */
  11083. var reIsUint = /^\d+$/;
  11084. /** Used for native method references. */
  11085. var objectProto = Object.prototype;
  11086. /** Used to check objects for own properties. */
  11087. var hasOwnProperty = objectProto.hasOwnProperty;
  11088. /* Native method references for those with the same name as other `lodash` methods. */
  11089. var nativeKeys = getNative(Object, 'keys');
  11090. /**
  11091. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  11092. * of an array-like value.
  11093. */
  11094. var MAX_SAFE_INTEGER = 9007199254740991;
  11095. /**
  11096. * The base implementation of `_.property` without support for deep paths.
  11097. *
  11098. * @private
  11099. * @param {string} key The key of the property to get.
  11100. * @returns {Function} Returns the new function.
  11101. */
  11102. function baseProperty(key) {
  11103. return function(object) {
  11104. return object == null ? undefined : object[key];
  11105. };
  11106. }
  11107. /**
  11108. * Gets the "length" property value of `object`.
  11109. *
  11110. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  11111. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  11112. *
  11113. * @private
  11114. * @param {Object} object The object to query.
  11115. * @returns {*} Returns the "length" value.
  11116. */
  11117. var getLength = baseProperty('length');
  11118. /**
  11119. * Checks if `value` is array-like.
  11120. *
  11121. * @private
  11122. * @param {*} value The value to check.
  11123. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  11124. */
  11125. function isArrayLike(value) {
  11126. return value != null && isLength(getLength(value));
  11127. }
  11128. /**
  11129. * Checks if `value` is a valid array-like index.
  11130. *
  11131. * @private
  11132. * @param {*} value The value to check.
  11133. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  11134. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  11135. */
  11136. function isIndex(value, length) {
  11137. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  11138. length = length == null ? MAX_SAFE_INTEGER : length;
  11139. return value > -1 && value % 1 == 0 && value < length;
  11140. }
  11141. /**
  11142. * Checks if `value` is a valid array-like length.
  11143. *
  11144. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  11145. *
  11146. * @private
  11147. * @param {*} value The value to check.
  11148. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  11149. */
  11150. function isLength(value) {
  11151. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  11152. }
  11153. /**
  11154. * A fallback implementation of `Object.keys` which creates an array of the
  11155. * own enumerable property names of `object`.
  11156. *
  11157. * @private
  11158. * @param {Object} object The object to query.
  11159. * @returns {Array} Returns the array of property names.
  11160. */
  11161. function shimKeys(object) {
  11162. var props = keysIn(object),
  11163. propsLength = props.length,
  11164. length = propsLength && object.length;
  11165. var allowIndexes = !!length && isLength(length) &&
  11166. (isArray(object) || isArguments(object));
  11167. var index = -1,
  11168. result = [];
  11169. while (++index < propsLength) {
  11170. var key = props[index];
  11171. if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
  11172. result.push(key);
  11173. }
  11174. }
  11175. return result;
  11176. }
  11177. /**
  11178. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  11179. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  11180. *
  11181. * @static
  11182. * @memberOf _
  11183. * @category Lang
  11184. * @param {*} value The value to check.
  11185. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  11186. * @example
  11187. *
  11188. * _.isObject({});
  11189. * // => true
  11190. *
  11191. * _.isObject([1, 2, 3]);
  11192. * // => true
  11193. *
  11194. * _.isObject(1);
  11195. * // => false
  11196. */
  11197. function isObject(value) {
  11198. // Avoid a V8 JIT bug in Chrome 19-20.
  11199. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  11200. var type = typeof value;
  11201. return !!value && (type == 'object' || type == 'function');
  11202. }
  11203. /**
  11204. * Creates an array of the own enumerable property names of `object`.
  11205. *
  11206. * **Note:** Non-object values are coerced to objects. See the
  11207. * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
  11208. * for more details.
  11209. *
  11210. * @static
  11211. * @memberOf _
  11212. * @category Object
  11213. * @param {Object} object The object to query.
  11214. * @returns {Array} Returns the array of property names.
  11215. * @example
  11216. *
  11217. * function Foo() {
  11218. * this.a = 1;
  11219. * this.b = 2;
  11220. * }
  11221. *
  11222. * Foo.prototype.c = 3;
  11223. *
  11224. * _.keys(new Foo);
  11225. * // => ['a', 'b'] (iteration order is not guaranteed)
  11226. *
  11227. * _.keys('hi');
  11228. * // => ['0', '1']
  11229. */
  11230. var keys = !nativeKeys ? shimKeys : function(object) {
  11231. var Ctor = object == null ? undefined : object.constructor;
  11232. if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
  11233. (typeof object != 'function' && isArrayLike(object))) {
  11234. return shimKeys(object);
  11235. }
  11236. return isObject(object) ? nativeKeys(object) : [];
  11237. };
  11238. /**
  11239. * Creates an array of the own and inherited enumerable property names of `object`.
  11240. *
  11241. * **Note:** Non-object values are coerced to objects.
  11242. *
  11243. * @static
  11244. * @memberOf _
  11245. * @category Object
  11246. * @param {Object} object The object to query.
  11247. * @returns {Array} Returns the array of property names.
  11248. * @example
  11249. *
  11250. * function Foo() {
  11251. * this.a = 1;
  11252. * this.b = 2;
  11253. * }
  11254. *
  11255. * Foo.prototype.c = 3;
  11256. *
  11257. * _.keysIn(new Foo);
  11258. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  11259. */
  11260. function keysIn(object) {
  11261. if (object == null) {
  11262. return [];
  11263. }
  11264. if (!isObject(object)) {
  11265. object = Object(object);
  11266. }
  11267. var length = object.length;
  11268. length = (length && isLength(length) &&
  11269. (isArray(object) || isArguments(object)) && length) || 0;
  11270. var Ctor = object.constructor,
  11271. index = -1,
  11272. isProto = typeof Ctor == 'function' && Ctor.prototype === object,
  11273. result = Array(length),
  11274. skipIndexes = length > 0;
  11275. while (++index < length) {
  11276. result[index] = (index + '');
  11277. }
  11278. for (var key in object) {
  11279. if (!(skipIndexes && isIndex(key, length)) &&
  11280. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  11281. result.push(key);
  11282. }
  11283. }
  11284. return result;
  11285. }
  11286. module.exports = keys;
  11287. },{"lodash._getnative":54,"lodash.isarguments":55,"lodash.isarray":56}],61:[function(_dereq_,module,exports){
  11288. /**
  11289. * lodash 3.0.8 (Custom Build) <https://lodash.com/>
  11290. * Build: `lodash modern modularize exports="npm" -o ./`
  11291. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  11292. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  11293. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  11294. * Available under MIT license <https://lodash.com/license>
  11295. */
  11296. var isArguments = _dereq_('lodash.isarguments'),
  11297. isArray = _dereq_('lodash.isarray');
  11298. /** Used to detect unsigned integer values. */
  11299. var reIsUint = /^\d+$/;
  11300. /** Used for native method references. */
  11301. var objectProto = Object.prototype;
  11302. /** Used to check objects for own properties. */
  11303. var hasOwnProperty = objectProto.hasOwnProperty;
  11304. /**
  11305. * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
  11306. * of an array-like value.
  11307. */
  11308. var MAX_SAFE_INTEGER = 9007199254740991;
  11309. /**
  11310. * Checks if `value` is a valid array-like index.
  11311. *
  11312. * @private
  11313. * @param {*} value The value to check.
  11314. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  11315. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  11316. */
  11317. function isIndex(value, length) {
  11318. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  11319. length = length == null ? MAX_SAFE_INTEGER : length;
  11320. return value > -1 && value % 1 == 0 && value < length;
  11321. }
  11322. /**
  11323. * Checks if `value` is a valid array-like length.
  11324. *
  11325. * **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength).
  11326. *
  11327. * @private
  11328. * @param {*} value The value to check.
  11329. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  11330. */
  11331. function isLength(value) {
  11332. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  11333. }
  11334. /**
  11335. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  11336. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  11337. *
  11338. * @static
  11339. * @memberOf _
  11340. * @category Lang
  11341. * @param {*} value The value to check.
  11342. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  11343. * @example
  11344. *
  11345. * _.isObject({});
  11346. * // => true
  11347. *
  11348. * _.isObject([1, 2, 3]);
  11349. * // => true
  11350. *
  11351. * _.isObject(1);
  11352. * // => false
  11353. */
  11354. function isObject(value) {
  11355. // Avoid a V8 JIT bug in Chrome 19-20.
  11356. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  11357. var type = typeof value;
  11358. return !!value && (type == 'object' || type == 'function');
  11359. }
  11360. /**
  11361. * Creates an array of the own and inherited enumerable property names of `object`.
  11362. *
  11363. * **Note:** Non-object values are coerced to objects.
  11364. *
  11365. * @static
  11366. * @memberOf _
  11367. * @category Object
  11368. * @param {Object} object The object to query.
  11369. * @returns {Array} Returns the array of property names.
  11370. * @example
  11371. *
  11372. * function Foo() {
  11373. * this.a = 1;
  11374. * this.b = 2;
  11375. * }
  11376. *
  11377. * Foo.prototype.c = 3;
  11378. *
  11379. * _.keysIn(new Foo);
  11380. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  11381. */
  11382. function keysIn(object) {
  11383. if (object == null) {
  11384. return [];
  11385. }
  11386. if (!isObject(object)) {
  11387. object = Object(object);
  11388. }
  11389. var length = object.length;
  11390. length = (length && isLength(length) &&
  11391. (isArray(object) || isArguments(object)) && length) || 0;
  11392. var Ctor = object.constructor,
  11393. index = -1,
  11394. isProto = typeof Ctor == 'function' && Ctor.prototype === object,
  11395. result = Array(length),
  11396. skipIndexes = length > 0;
  11397. while (++index < length) {
  11398. result[index] = (index + '');
  11399. }
  11400. for (var key in object) {
  11401. if (!(skipIndexes && isIndex(key, length)) &&
  11402. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  11403. result.push(key);
  11404. }
  11405. }
  11406. return result;
  11407. }
  11408. module.exports = keysIn;
  11409. },{"lodash.isarguments":55,"lodash.isarray":56}],62:[function(_dereq_,module,exports){
  11410. /**
  11411. * lodash 3.0.0 (Custom Build) <https://lodash.com/>
  11412. * Build: `lodash modern modularize exports="npm" -o ./`
  11413. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  11414. * Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
  11415. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  11416. * Available under MIT license <https://lodash.com/license>
  11417. */
  11418. var baseCopy = _dereq_('lodash._basecopy'),
  11419. keysIn = _dereq_('lodash.keysin');
  11420. /**
  11421. * Converts `value` to a plain object flattening inherited enumerable
  11422. * properties of `value` to own properties of the plain object.
  11423. *
  11424. * @static
  11425. * @memberOf _
  11426. * @category Lang
  11427. * @param {*} value The value to convert.
  11428. * @returns {Object} Returns the converted plain object.
  11429. * @example
  11430. *
  11431. * function Foo() {
  11432. * this.b = 2;
  11433. * }
  11434. *
  11435. * Foo.prototype.c = 3;
  11436. *
  11437. * _.assign({ 'a': 1 }, new Foo);
  11438. * // => { 'a': 1, 'b': 2 }
  11439. *
  11440. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11441. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11442. */
  11443. function toPlainObject(value) {
  11444. return baseCopy(value, keysIn(value));
  11445. }
  11446. module.exports = toPlainObject;
  11447. },{"lodash._basecopy":63,"lodash.keysin":61}],63:[function(_dereq_,module,exports){
  11448. /**
  11449. * lodash 3.0.1 (Custom Build) <https://lodash.com/>
  11450. * Build: `lodash modern modularize exports="npm" -o ./`
  11451. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  11452. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  11453. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  11454. * Available under MIT license <https://lodash.com/license>
  11455. */
  11456. /**
  11457. * Copies properties of `source` to `object`.
  11458. *
  11459. * @private
  11460. * @param {Object} source The object to copy properties from.
  11461. * @param {Array} props The property names to copy.
  11462. * @param {Object} [object={}] The object to copy properties to.
  11463. * @returns {Object} Returns `object`.
  11464. */
  11465. function baseCopy(source, props, object) {
  11466. object || (object = {});
  11467. var index = -1,
  11468. length = props.length;
  11469. while (++index < length) {
  11470. var key = props[index];
  11471. object[key] = source[key];
  11472. }
  11473. return object;
  11474. }
  11475. module.exports = baseCopy;
  11476. },{}],64:[function(_dereq_,module,exports){
  11477. var JSZip, fs, internal;
  11478. JSZip = _dereq_('jszip');
  11479. internal = _dereq_('./internal');
  11480. module.exports = {
  11481. asBlob: function(html, options) {
  11482. var zip;
  11483. zip = new JSZip();
  11484. internal.addFiles(zip, html, options);
  11485. return internal.generateDocument(zip);
  11486. }
  11487. };
  11488. },{"./internal":65,"jszip":14}],65:[function(_dereq_,module,exports){
  11489. (function (global,Buffer){
  11490. var documentTemplate, fs, utils, _;
  11491. documentTemplate = _dereq_('./templates/document');
  11492. utils = _dereq_('./utils');
  11493. _ = {
  11494. merge: _dereq_('lodash.merge')
  11495. };
  11496. module.exports = {
  11497. generateDocument: function(zip) {
  11498. var buffer;
  11499. buffer = zip.generate({
  11500. type: 'arraybuffer'
  11501. });
  11502. if (global.Blob) {
  11503. return new Blob([buffer], {
  11504. type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
  11505. });
  11506. } else if (global.Buffer) {
  11507. return new Buffer(new Uint8Array(buffer));
  11508. } else {
  11509. throw new Error("Neither Blob nor Buffer are accessible in this environment. " + "Consider adding Blob.js shim");
  11510. }
  11511. },
  11512. renderDocumentFile: function(documentOptions) {
  11513. var templateData;
  11514. if (documentOptions == null) {
  11515. documentOptions = {};
  11516. }
  11517. templateData = _.merge({
  11518. margins: {
  11519. top: 1440,
  11520. right: 1440,
  11521. bottom: 1440,
  11522. left: 1440,
  11523. header: 720,
  11524. footer: 720,
  11525. gutter: 0
  11526. }
  11527. }, (function() {
  11528. switch (documentOptions.orientation) {
  11529. case 'landscape':
  11530. return {
  11531. height: 12240,
  11532. width: 15840,
  11533. orient: 'landscape'
  11534. };
  11535. default:
  11536. return {
  11537. width: 12240,
  11538. height: 15840,
  11539. orient: 'portrait'
  11540. };
  11541. }
  11542. })(), {
  11543. margins: documentOptions.margins
  11544. });
  11545. return documentTemplate(templateData);
  11546. },
  11547. addFiles: function(zip, htmlSource, documentOptions) {
  11548. zip.file('[Content_Types].xml', Buffer("PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pgo8VHlwZXMgeG1sbnM9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9wYWNrYWdlLzIwMDYvY29udGVudC10eXBlcyI+CiAgPERlZmF1bHQgRXh0ZW5zaW9uPSJyZWxzIiBDb250ZW50VHlwZT0KICAgICJhcHBsaWNhdGlvbi92bmQub3BlbnhtbGZvcm1hdHMtcGFja2FnZS5yZWxhdGlvbnNoaXBzK3htbCIgLz4KICA8T3ZlcnJpZGUgUGFydE5hbWU9Ii93b3JkL2RvY3VtZW50LnhtbCIgQ29udGVudFR5cGU9CiAgICAiYXBwbGljYXRpb24vdm5kLm9wZW54bWxmb3JtYXRzLW9mZmljZWRvY3VtZW50LndvcmRwcm9jZXNzaW5nbWwuZG9jdW1lbnQubWFpbit4bWwiLz4KICA8T3ZlcnJpZGUgUGFydE5hbWU9Ii93b3JkL2FmY2h1bmsubWh0IiBDb250ZW50VHlwZT0ibWVzc2FnZS9yZmM4MjIiLz4KPC9UeXBlcz4K","base64"));
  11549. zip.folder('_rels').file('.rels', Buffer("PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pgo8UmVsYXRpb25zaGlwcyB4bWxucz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL3BhY2thZ2UvMjAwNi9yZWxhdGlvbnNoaXBzIj4KICA8UmVsYXRpb25zaGlwCiAgICAgIFR5cGU9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9vZmZpY2VEb2N1bWVudC8yMDA2L3JlbGF0aW9uc2hpcHMvb2ZmaWNlRG9jdW1lbnQiCiAgICAgIFRhcmdldD0iL3dvcmQvZG9jdW1lbnQueG1sIiBJZD0iUjA5YzgzZmFmYzA2NzQ4OGUiIC8+CjwvUmVsYXRpb25zaGlwcz4K","base64"));
  11550. return zip.folder('word').file('document.xml', this.renderDocumentFile(documentOptions)).file('afchunk.mht', utils.getMHTdocument(htmlSource)).folder('_rels').file('document.xml.rels', Buffer("PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pgo8UmVsYXRpb25zaGlwcyB4bWxucz0iaHR0cDovL3NjaGVtYXMub3BlbnhtbGZvcm1hdHMub3JnL3BhY2thZ2UvMjAwNi9yZWxhdGlvbnNoaXBzIj4KICA8UmVsYXRpb25zaGlwIFR5cGU9Imh0dHA6Ly9zY2hlbWFzLm9wZW54bWxmb3JtYXRzLm9yZy9vZmZpY2VEb2N1bWVudC8yMDA2L3JlbGF0aW9uc2hpcHMvYUZDaHVuayIKICAgIFRhcmdldD0iL3dvcmQvYWZjaHVuay5taHQiIElkPSJodG1sQ2h1bmsiIC8+CjwvUmVsYXRpb25zaGlwcz4K","base64"));
  11551. }
  11552. };
  11553. }).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},_dereq_("buffer").Buffer)
  11554. },{"./templates/document":66,"./utils":69,"buffer":1,"lodash.merge":47}],66:[function(_dereq_,module,exports){
  11555. var _ = {escape: _dereq_("lodash.escape")};
  11556. module.exports = function(obj){
  11557. var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};
  11558. with(obj||{}){
  11559. __p+='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<w:document\n xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"\n xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"\n xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"\n xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"\n xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"\n xmlns:ns6="http://schemas.openxmlformats.org/schemaLibrary/2006/main"\n xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"\n xmlns:ns8="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing"\n xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram"\n xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"\n xmlns:ns11="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"\n xmlns:dsp="http://schemas.microsoft.com/office/drawing/2008/diagram"\n xmlns:ns13="urn:schemas-microsoft-com:office:excel"\n xmlns:o="urn:schemas-microsoft-com:office:office"\n xmlns:v="urn:schemas-microsoft-com:vml"\n xmlns:w10="urn:schemas-microsoft-com:office:word"\n xmlns:ns17="urn:schemas-microsoft-com:office:powerpoint"\n xmlns:odx="http://opendope.org/xpaths"\n xmlns:odc="http://opendope.org/conditions"\n xmlns:odq="http://opendope.org/questions"\n xmlns:odi="http://opendope.org/components"\n xmlns:odgm="http://opendope.org/SmartArt/DataHierarchy"\n xmlns:ns24="http://schemas.openxmlformats.org/officeDocument/2006/bibliography"\n xmlns:ns25="http://schemas.openxmlformats.org/drawingml/2006/compatibility"\n xmlns:ns26="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas">\n <w:body>\n <w:altChunk r:id="htmlChunk" />\n <w:sectPr>\n <w:pgSz w:w="'+
  11560. ((__t=( width ))==null?'':__t)+
  11561. '" w:h="'+
  11562. ((__t=( height ))==null?'':__t)+
  11563. '" w:orient="'+
  11564. ((__t=( orient ))==null?'':__t)+
  11565. '" />\n <w:pgMar w:top="'+
  11566. ((__t=( margins.top ))==null?'':__t)+
  11567. '"\n w:right="'+
  11568. ((__t=( margins.right ))==null?'':__t)+
  11569. '"\n w:bottom="'+
  11570. ((__t=( margins.bottom ))==null?'':__t)+
  11571. '"\n w:left="'+
  11572. ((__t=( margins.left ))==null?'':__t)+
  11573. '"\n w:header="'+
  11574. ((__t=( margins.header ))==null?'':__t)+
  11575. '"\n w:footer="'+
  11576. ((__t=( margins.footer ))==null?'':__t)+
  11577. '"\n w:gutter="'+
  11578. ((__t=( margins.gutter ))==null?'':__t)+
  11579. '"/>\n </w:sectPr>\n </w:body>\n</w:document>\n';
  11580. }
  11581. return __p;
  11582. };
  11583. },{"lodash.escape":45}],67:[function(_dereq_,module,exports){
  11584. var _ = {escape: _dereq_("lodash.escape")};
  11585. module.exports = function(obj){
  11586. var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};
  11587. with(obj||{}){
  11588. __p+='MIME-Version: 1.0\nContent-Type: multipart/related;\n type="text/html";\n boundary="----=mhtDocumentPart"\n\n\n------=mhtDocumentPart\nContent-Type: text/html;\n charset="utf-8"\nContent-Transfer-Encoding: quoted-printable\nContent-Location: file:///C:/fake/document.html\n\n'+
  11589. ((__t=( htmlSource ))==null?'':__t)+
  11590. '\n\n'+
  11591. ((__t=( contentParts ))==null?'':__t)+
  11592. '\n\n------=mhtDocumentPart--\n';
  11593. }
  11594. return __p;
  11595. };
  11596. },{"lodash.escape":45}],68:[function(_dereq_,module,exports){
  11597. var _ = {escape: _dereq_("lodash.escape")};
  11598. module.exports = function(obj){
  11599. var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};
  11600. with(obj||{}){
  11601. __p+='------=mhtDocumentPart\nContent-Type: '+
  11602. ((__t=( contentType ))==null?'':__t)+
  11603. '\nContent-Transfer-Encoding: '+
  11604. ((__t=( contentEncoding ))==null?'':__t)+
  11605. '\nContent-Location: '+
  11606. ((__t=( contentLocation ))==null?'':__t)+
  11607. '\n\n'+
  11608. ((__t=( encodedContent ))==null?'':__t)+
  11609. '\n';
  11610. }
  11611. return __p;
  11612. };
  11613. },{"lodash.escape":45}],69:[function(_dereq_,module,exports){
  11614. var mhtDocumentTemplate, mhtPartTemplate;
  11615. mhtDocumentTemplate = _dereq_('./templates/mht_document');
  11616. mhtPartTemplate = _dereq_('./templates/mht_part');
  11617. module.exports = {
  11618. getMHTdocument: function(htmlSource) {
  11619. var imageContentParts, _ref;
  11620. _ref = this._prepareImageParts(htmlSource), htmlSource = _ref.htmlSource, imageContentParts = _ref.imageContentParts;
  11621. htmlSource = htmlSource.replace(/\=/g, '=3D');
  11622. return mhtDocumentTemplate({
  11623. htmlSource: htmlSource,
  11624. contentParts: imageContentParts.join('\n')
  11625. });
  11626. },
  11627. _prepareImageParts: function(htmlSource) {
  11628. var imageContentParts, inlinedReplacer, inlinedSrcPattern;
  11629. imageContentParts = [];
  11630. inlinedSrcPattern = /"data:(\w+\/\w+);(\w+),(\S+)"/g;
  11631. inlinedReplacer = function(match, contentType, contentEncoding, encodedContent) {
  11632. var contentLocation, extension, index;
  11633. index = imageContentParts.length;
  11634. extension = contentType.split('/')[1];
  11635. contentLocation = "file:///C:/fake/image" + index + "." + extension;
  11636. imageContentParts.push(mhtPartTemplate({
  11637. contentType: contentType,
  11638. contentEncoding: contentEncoding,
  11639. contentLocation: contentLocation,
  11640. encodedContent: encodedContent
  11641. }));
  11642. return "\"" + contentLocation + "\"";
  11643. };
  11644. if (typeof htmlSource === 'string') {
  11645. if (!/<img/g.test(htmlSource)) {
  11646. return {
  11647. htmlSource: htmlSource,
  11648. imageContentParts: imageContentParts
  11649. };
  11650. }
  11651. htmlSource = htmlSource.replace(inlinedSrcPattern, inlinedReplacer);
  11652. return {
  11653. htmlSource: htmlSource,
  11654. imageContentParts: imageContentParts
  11655. };
  11656. } else {
  11657. throw new Error("Not a valid source provided!");
  11658. }
  11659. }
  11660. };
  11661. },{"./templates/mht_document":67,"./templates/mht_part":68}]},{},[64])
  11662. (64)
  11663. });