object_hash_test.js 168 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737
  1. (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(require,module,exports){
  2. (function (global){
  3. !function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.objectHash=e()}}(function(){return function e(t,n,r){function o(u,a){if(!n[u]){if(!t[u]){var f="function"==typeof require&&require;if(!a&&f)return f(u,!0);if(i)return i(u,!0);throw new Error("Cannot find module '"+u+"'")}var s=n[u]={exports:{}};t[u][0].call(s.exports,function(e){var n=t[u][1][e];return o(n?n:e)},s,s.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(e,t,n){(function(r,o,i,u,a,f,s,c,l){"use strict";function d(e,t){return t=h(e,t),g(e,t)}function h(e,t){if(t=t||{},t.algorithm=t.algorithm||"sha1",t.encoding=t.encoding||"hex",t.excludeValues=!!t.excludeValues,t.algorithm=t.algorithm.toLowerCase(),t.encoding=t.encoding.toLowerCase(),t.ignoreUnknown=t.ignoreUnknown===!0,t.respectType=t.respectType!==!1,t.respectFunctionNames=t.respectFunctionNames!==!1,t.respectFunctionProperties=t.respectFunctionProperties!==!1,t.unorderedArrays=t.unorderedArrays===!0,t.unorderedSets=t.unorderedSets!==!1,t.unorderedObjects=t.unorderedObjects!==!1,t.replacer=t.replacer||void 0,t.excludeKeys=t.excludeKeys||void 0,"undefined"==typeof e)throw new Error("Object argument required.");for(var n=0;n<v.length;++n)v[n].toLowerCase()===t.algorithm.toLowerCase()&&(t.algorithm=v[n]);if(v.indexOf(t.algorithm)===-1)throw new Error('Algorithm "'+t.algorithm+'" not supported. supported values: '+v.join(", "));if(m.indexOf(t.encoding)===-1&&"passthrough"!==t.algorithm)throw new Error('Encoding "'+t.encoding+'" not supported. supported values: '+m.join(", "));return t}function p(e){if("function"!=typeof e)return!1;var t=/^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i;return null!=t.exec(Function.prototype.toString.call(e))}function g(e,t){var n;n="passthrough"!==t.algorithm?b.createHash(t.algorithm):new w,"undefined"==typeof n.write&&(n.write=n.update,n.end=n.update);var r=y(t,n);if(r.dispatch(e),n.update||n.end(""),n.digest)return n.digest("buffer"===t.encoding?void 0:t.encoding);var o=n.read();return"buffer"===t.encoding?o:o.toString(t.encoding)}function y(e,t,n){n=n||[];var r=function(e){return t.update?t.update(e,"utf8"):t.write(e,"utf8")};return{dispatch:function(t){e.replacer&&(t=e.replacer(t));var n=typeof t;return null===t&&(n="null"),this["_"+n](t)},_object:function(t){var o=/\[object (.*)\]/i,u=Object.prototype.toString.call(t),a=o.exec(u);a=a?a[1]:"unknown:["+u+"]",a=a.toLowerCase();var f=null;if((f=n.indexOf(t))>=0)return this.dispatch("[CIRCULAR:"+f+"]");if(n.push(t),"undefined"!=typeof i&&i.isBuffer&&i.isBuffer(t))return r("buffer:"),r(t);if("object"===a||"function"===a){var s=Object.keys(t);e.unorderedObjects&&(s=s.sort()),e.respectType===!1||p(t)||s.splice(0,0,"prototype","__proto__","constructor"),e.excludeKeys&&(s=s.filter(function(t){return!e.excludeKeys(t)})),r("object:"+s.length+":");var c=this;return s.forEach(function(n){c.dispatch(n),r(":"),e.excludeValues||c.dispatch(t[n]),r(",")})}if(!this["_"+a]){if(e.ignoreUnknown)return r("["+a+"]");throw new Error('Unknown object type "'+a+'"')}this["_"+a](t)},_array:function(t,o){o="undefined"!=typeof o?o:e.unorderedArrays!==!1;var i=this;if(r("array:"+t.length+":"),!o||t.length<=1)return t.forEach(function(e){return i.dispatch(e)});var u=[],a=t.map(function(t){var r=new w,o=n.slice(),i=y(e,r,o);return i.dispatch(t),u=u.concat(o.slice(n.length)),r.read().toString()});return n=n.concat(u),a.sort(),this._array(a,!1)},_date:function(e){return r("date:"+e.toJSON())},_symbol:function(e){return r("symbol:"+e.toString())},_error:function(e){return r("error:"+e.toString())},_boolean:function(e){return r("bool:"+e.toString())},_string:function(e){r("string:"+e.length+":"),r(e.toString())},_function:function(t){r("fn:"),p(t)?this.dispatch("[native]"):this.dispatch(t.toString()),e.respectFunctionNames!==!1&&this.dispatch("function-name:"+String(t.name)),e.respectFunctionProperties&&this._object(t)},_number:function(e){return r("number:"+e.toString())},_xml:function(e){return r("xml:"+e.toString())},_null:function(){return r("Null")},_undefined:function(){return r("Undefined")},_regexp:function(e){return r("regex:"+e.toString())},_uint8array:function(e){return r("uint8array:"),this.dispatch(Array.prototype.slice.call(e))},_uint8clampedarray:function(e){return r("uint8clampedarray:"),this.dispatch(Array.prototype.slice.call(e))},_int8array:function(e){return r("uint8array:"),this.dispatch(Array.prototype.slice.call(e))},_uint16array:function(e){return r("uint16array:"),this.dispatch(Array.prototype.slice.call(e))},_int16array:function(e){return r("uint16array:"),this.dispatch(Array.prototype.slice.call(e))},_uint32array:function(e){return r("uint32array:"),this.dispatch(Array.prototype.slice.call(e))},_int32array:function(e){return r("uint32array:"),this.dispatch(Array.prototype.slice.call(e))},_float32array:function(e){return r("float32array:"),this.dispatch(Array.prototype.slice.call(e))},_float64array:function(e){return r("float64array:"),this.dispatch(Array.prototype.slice.call(e))},_arraybuffer:function(e){return r("arraybuffer:"),this.dispatch(new Uint8Array(e))},_url:function(e){return r("url:"+e.toString(),"utf8")},_map:function(t){r("map:");var n=Array.from(t);return this._array(n,e.unorderedSets!==!1)},_set:function(t){r("set:");var n=Array.from(t);return this._array(n,e.unorderedSets!==!1)},_blob:function(){if(e.ignoreUnknown)return r("[blob]");throw Error('Hashing Blob objects is currently not supported\n(see https://github.com/puleos/object-hash/issues/26)\nUse "options.replacer" or "options.ignoreUnknown"\n')},_domwindow:function(){return r("domwindow")},_process:function(){return r("process")},_timer:function(){return r("timer")},_pipe:function(){return r("pipe")},_tcp:function(){return r("tcp")},_udp:function(){return r("udp")},_tty:function(){return r("tty")},_statwatcher:function(){return r("statwatcher")},_securecontext:function(){return r("securecontext")},_connection:function(){return r("connection")},_zlib:function(){return r("zlib")},_context:function(){return r("context")},_nodescript:function(){return r("nodescript")},_httpparser:function(){return r("httpparser")},_dataview:function(){return r("dataview")},_signal:function(){return r("signal")},_fsevent:function(){return r("fsevent")},_tlswrap:function(){return r("tlswrap")}}}function w(){return{buf:"",write:function(e){this.buf+=e},end:function(e){this.buf+=e},read:function(){return this.buf}}}var b=e("crypto");n=t.exports=d,n.sha1=function(e){return d(e)},n.keys=function(e){return d(e,{excludeValues:!0,algorithm:"sha1",encoding:"hex"})},n.MD5=function(e){return d(e,{algorithm:"md5",encoding:"hex"})},n.keysMD5=function(e){return d(e,{algorithm:"md5",encoding:"hex",excludeValues:!0})};var v=b.getHashes?b.getHashes().slice():["sha1","md5"];v.push("passthrough");var m=["buffer","hex","binary","base64"];n.writeToStream=function(e,t,n){return"undefined"==typeof n&&(n=t,t={}),t=h(e,t),y(t,n).dispatch(e)}}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/fake_e8180ef5.js","/")},{buffer:3,crypto:5,lYpoI2:10}],2:[function(e,t,n){(function(e,t,r,o,i,u,a,f,s){var c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(e){"use strict";function t(e){var t=e.charCodeAt(0);return t===i||t===l?62:t===u||t===d?63:t<a?-1:t<a+10?t-a+26+26:t<s+26?t-s:t<f+26?t-f+26:void 0}function n(e){function n(e){s[l++]=e}var r,i,u,a,f,s;if(e.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var c=e.length;f="="===e.charAt(c-2)?2:"="===e.charAt(c-1)?1:0,s=new o(3*e.length/4-f),u=f>0?e.length-4:e.length;var l=0;for(r=0,i=0;r<u;r+=4,i+=3)a=t(e.charAt(r))<<18|t(e.charAt(r+1))<<12|t(e.charAt(r+2))<<6|t(e.charAt(r+3)),n((16711680&a)>>16),n((65280&a)>>8),n(255&a);return 2===f?(a=t(e.charAt(r))<<2|t(e.charAt(r+1))>>4,n(255&a)):1===f&&(a=t(e.charAt(r))<<10|t(e.charAt(r+1))<<4|t(e.charAt(r+2))>>2,n(a>>8&255),n(255&a)),s}function r(e){function t(e){return c.charAt(e)}function n(e){return t(e>>18&63)+t(e>>12&63)+t(e>>6&63)+t(63&e)}var r,o,i,u=e.length%3,a="";for(r=0,i=e.length-u;r<i;r+=3)o=(e[r]<<16)+(e[r+1]<<8)+e[r+2],a+=n(o);switch(u){case 1:o=e[e.length-1],a+=t(o>>2),a+=t(o<<4&63),a+="==";break;case 2:o=(e[e.length-2]<<8)+e[e.length-1],a+=t(o>>10),a+=t(o>>4&63),a+=t(o<<2&63),a+="="}return a}var o="undefined"!=typeof Uint8Array?Uint8Array:Array,i="+".charCodeAt(0),u="/".charCodeAt(0),a="0".charCodeAt(0),f="a".charCodeAt(0),s="A".charCodeAt(0),l="-".charCodeAt(0),d="_".charCodeAt(0);e.toByteArray=n,e.fromByteArray=r}("undefined"==typeof n?this.base64js={}:n)}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/base64-js/lib/b64.js","/node_modules/gulp-browserify/node_modules/base64-js/lib")},{buffer:3,lYpoI2:10}],3:[function(e,t,n){(function(t,r,o,i,u,a,f,s,c){function o(e,t,n){if(!(this instanceof o))return new o(e,t,n);var r=typeof e;if("base64"===t&&"string"===r)for(e=N(e);e.length%4!==0;)e+="=";var i;if("number"===r)i=F(e);else if("string"===r)i=o.byteLength(e,t);else{if("object"!==r)throw new Error("First argument needs to be a number, array or string.");i=F(e.length)}var u;o._useTypedArrays?u=o._augment(new Uint8Array(i)):(u=this,u.length=i,u._isBuffer=!0);var a;if(o._useTypedArrays&&"number"==typeof e.byteLength)u._set(e);else if(O(e))for(a=0;a<i;a++)o.isBuffer(e)?u[a]=e.readUInt8(a):u[a]=e[a];else if("string"===r)u.write(e,0,t);else if("number"===r&&!o._useTypedArrays&&!n)for(a=0;a<i;a++)u[a]=0;return u}function l(e,t,n,r){n=Number(n)||0;var i=e.length-n;r?(r=Number(r),r>i&&(r=i)):r=i;var u=t.length;$(u%2===0,"Invalid hex string"),r>u/2&&(r=u/2);for(var a=0;a<r;a++){var f=parseInt(t.substr(2*a,2),16);$(!isNaN(f),"Invalid hex string"),e[n+a]=f}return o._charsWritten=2*a,a}function d(e,t,n,r){var i=o._charsWritten=W(V(t),e,n,r);return i}function h(e,t,n,r){var i=o._charsWritten=W(q(t),e,n,r);return i}function p(e,t,n,r){return h(e,t,n,r)}function g(e,t,n,r){var i=o._charsWritten=W(R(t),e,n,r);return i}function y(e,t,n,r){var i=o._charsWritten=W(P(t),e,n,r);return i}function w(e,t,n){return 0===t&&n===e.length?G.fromByteArray(e):G.fromByteArray(e.slice(t,n))}function b(e,t,n){var r="",o="";n=Math.min(e.length,n);for(var i=t;i<n;i++)e[i]<=127?(r+=J(o)+String.fromCharCode(e[i]),o=""):o+="%"+e[i].toString(16);return r+J(o)}function v(e,t,n){var r="";n=Math.min(e.length,n);for(var o=t;o<n;o++)r+=String.fromCharCode(e[o]);return r}function m(e,t,n){return v(e,t,n)}function _(e,t,n){var r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);for(var o="",i=t;i<n;i++)o+=H(e[i]);return o}function E(e,t,n){for(var r=e.slice(t,n),o="",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}function I(e,t,n,r){r||($("boolean"==typeof n,"missing or invalid endian"),$(void 0!==t&&null!==t,"missing offset"),$(t+1<e.length,"Trying to read beyond buffer length"));var o=e.length;if(!(t>=o)){var i;return n?(i=e[t],t+1<o&&(i|=e[t+1]<<8)):(i=e[t]<<8,t+1<o&&(i|=e[t+1])),i}}function A(e,t,n,r){r||($("boolean"==typeof n,"missing or invalid endian"),$(void 0!==t&&null!==t,"missing offset"),$(t+3<e.length,"Trying to read beyond buffer length"));var o=e.length;if(!(t>=o)){var i;return n?(t+2<o&&(i=e[t+2]<<16),t+1<o&&(i|=e[t+1]<<8),i|=e[t],t+3<o&&(i+=e[t+3]<<24>>>0)):(t+1<o&&(i=e[t+1]<<16),t+2<o&&(i|=e[t+2]<<8),t+3<o&&(i|=e[t+3]),i+=e[t]<<24>>>0),i}}function B(e,t,n,r){r||($("boolean"==typeof n,"missing or invalid endian"),$(void 0!==t&&null!==t,"missing offset"),$(t+1<e.length,"Trying to read beyond buffer length"));var o=e.length;if(!(t>=o)){var i=I(e,t,n,!0),u=32768&i;return u?(65535-i+1)*-1:i}}function L(e,t,n,r){r||($("boolean"==typeof n,"missing or invalid endian"),$(void 0!==t&&null!==t,"missing offset"),$(t+3<e.length,"Trying to read beyond buffer length"));var o=e.length;if(!(t>=o)){var i=A(e,t,n,!0),u=2147483648&i;return u?(4294967295-i+1)*-1:i}}function U(e,t,n,r){return r||($("boolean"==typeof n,"missing or invalid endian"),$(t+3<e.length,"Trying to read beyond buffer length")),Q.read(e,t,n,23,4)}function x(e,t,n,r){return r||($("boolean"==typeof n,"missing or invalid endian"),$(t+7<e.length,"Trying to read beyond buffer length")),Q.read(e,t,n,52,8)}function S(e,t,n,r,o){o||($(void 0!==t&&null!==t,"missing value"),$("boolean"==typeof r,"missing or invalid endian"),$(void 0!==n&&null!==n,"missing offset"),$(n+1<e.length,"trying to write beyond buffer length"),K(t,65535));var i=e.length;if(!(n>=i))for(var u=0,a=Math.min(i-n,2);u<a;u++)e[n+u]=(t&255<<8*(r?u:1-u))>>>8*(r?u:1-u)}function j(e,t,n,r,o){o||($(void 0!==t&&null!==t,"missing value"),$("boolean"==typeof r,"missing or invalid endian"),$(void 0!==n&&null!==n,"missing offset"),$(n+3<e.length,"trying to write beyond buffer length"),K(t,4294967295));var i=e.length;if(!(n>=i))for(var u=0,a=Math.min(i-n,4);u<a;u++)e[n+u]=t>>>8*(r?u:3-u)&255}function C(e,t,n,r,o){o||($(void 0!==t&&null!==t,"missing value"),$("boolean"==typeof r,"missing or invalid endian"),$(void 0!==n&&null!==n,"missing offset"),$(n+1<e.length,"Trying to write beyond buffer length"),z(t,32767,-32768));var i=e.length;n>=i||(t>=0?S(e,t,n,r,o):S(e,65535+t+1,n,r,o))}function k(e,t,n,r,o){o||($(void 0!==t&&null!==t,"missing value"),$("boolean"==typeof r,"missing or invalid endian"),$(void 0!==n&&null!==n,"missing offset"),$(n+3<e.length,"Trying to write beyond buffer length"),z(t,2147483647,-2147483648));var i=e.length;n>=i||(t>=0?j(e,t,n,r,o):j(e,4294967295+t+1,n,r,o))}function T(e,t,n,r,o){o||($(void 0!==t&&null!==t,"missing value"),$("boolean"==typeof r,"missing or invalid endian"),$(void 0!==n&&null!==n,"missing offset"),$(n+3<e.length,"Trying to write beyond buffer length"),X(t,3.4028234663852886e38,-3.4028234663852886e38));var i=e.length;n>=i||Q.write(e,t,n,r,23,4)}function M(e,t,n,r,o){o||($(void 0!==t&&null!==t,"missing value"),$("boolean"==typeof r,"missing or invalid endian"),$(void 0!==n&&null!==n,"missing offset"),$(n+7<e.length,"Trying to write beyond buffer length"),X(t,1.7976931348623157e308,-1.7976931348623157e308));var i=e.length;n>=i||Q.write(e,t,n,r,52,8)}function N(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function Y(e,t,n){return"number"!=typeof e?n:(e=~~e,e>=t?t:e>=0?e:(e+=t,e>=0?e:0))}function F(e){return e=~~Math.ceil(+e),e<0?0:e}function D(e){return(Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)})(e)}function O(e){return D(e)||o.isBuffer(e)||e&&"object"==typeof e&&"number"==typeof e.length}function H(e){return e<16?"0"+e.toString(16):e.toString(16)}function V(e){for(var t=[],n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<=127)t.push(e.charCodeAt(n));else{var o=n;r>=55296&&r<=57343&&n++;for(var i=encodeURIComponent(e.slice(o,n+1)).substr(1).split("%"),u=0;u<i.length;u++)t.push(parseInt(i[u],16))}}return t}function q(e){for(var t=[],n=0;n<e.length;n++)t.push(255&e.charCodeAt(n));return t}function P(e){for(var t,n,r,o=[],i=0;i<e.length;i++)t=e.charCodeAt(i),n=t>>8,r=t%256,o.push(r),o.push(n);return o}function R(e){return G.toByteArray(e)}function W(e,t,n,r){for(var o=0;o<r&&!(o+n>=t.length||o>=e.length);o++)t[o+n]=e[o];return o}function J(e){try{return decodeURIComponent(e)}catch(t){return String.fromCharCode(65533)}}function K(e,t){$("number"==typeof e,"cannot write a non-number as a number"),$(e>=0,"specified a negative value for writing an unsigned value"),$(e<=t,"value is larger than maximum value for type"),$(Math.floor(e)===e,"value has a fractional component")}function z(e,t,n){$("number"==typeof e,"cannot write a non-number as a number"),$(e<=t,"value larger than maximum allowed value"),$(e>=n,"value smaller than minimum allowed value"),$(Math.floor(e)===e,"value has a fractional component")}function X(e,t,n){$("number"==typeof e,"cannot write a non-number as a number"),$(e<=t,"value larger than maximum allowed value"),$(e>=n,"value smaller than minimum allowed value")}function $(e,t){if(!e)throw new Error(t||"Failed assertion")}var G=e("base64-js"),Q=e("ieee754");n.Buffer=o,n.SlowBuffer=o,n.INSPECT_MAX_BYTES=50,o.poolSize=8192,o._useTypedArrays=function(){try{var e=new ArrayBuffer(0),t=new Uint8Array(e);return t.foo=function(){return 42},42===t.foo()&&"function"==typeof t.subarray}catch(n){return!1}}(),o.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.isBuffer=function(e){return!(null===e||void 0===e||!e._isBuffer)},o.byteLength=function(e,t){var n;switch(e+="",t||"utf8"){case"hex":n=e.length/2;break;case"utf8":case"utf-8":n=V(e).length;break;case"ascii":case"binary":case"raw":n=e.length;break;case"base64":n=R(e).length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":n=2*e.length;break;default:throw new Error("Unknown encoding")}return n},o.concat=function(e,t){if($(D(e),"Usage: Buffer.concat(list, [totalLength])\nlist should be an Array."),0===e.length)return new o(0);if(1===e.length)return e[0];var n;if("number"!=typeof t)for(t=0,n=0;n<e.length;n++)t+=e[n].length;var r=new o(t),i=0;for(n=0;n<e.length;n++){var u=e[n];u.copy(r,i),i+=u.length}return r},o.prototype.write=function(e,t,n,r){if(isFinite(t))isFinite(n)||(r=n,n=void 0);else{var o=r;r=t,t=n,n=o}t=Number(t)||0;var i=this.length-t;n?(n=Number(n),n>i&&(n=i)):n=i,r=String(r||"utf8").toLowerCase();var u;switch(r){case"hex":u=l(this,e,t,n);break;case"utf8":case"utf-8":u=d(this,e,t,n);break;case"ascii":u=h(this,e,t,n);break;case"binary":u=p(this,e,t,n);break;case"base64":u=g(this,e,t,n);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":u=y(this,e,t,n);break;default:throw new Error("Unknown encoding")}return u},o.prototype.toString=function(e,t,n){var r=this;if(e=String(e||"utf8").toLowerCase(),t=Number(t)||0,n=void 0!==n?Number(n):n=r.length,n===t)return"";var o;switch(e){case"hex":o=_(r,t,n);break;case"utf8":case"utf-8":o=b(r,t,n);break;case"ascii":o=v(r,t,n);break;case"binary":o=m(r,t,n);break;case"base64":o=w(r,t,n);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":o=E(r,t,n);break;default:throw new Error("Unknown encoding")}return o},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},o.prototype.copy=function(e,t,n,r){var i=this;if(n||(n=0),r||0===r||(r=this.length),t||(t=0),r!==n&&0!==e.length&&0!==i.length){$(r>=n,"sourceEnd < sourceStart"),$(t>=0&&t<e.length,"targetStart out of bounds"),$(n>=0&&n<i.length,"sourceStart out of bounds"),$(r>=0&&r<=i.length,"sourceEnd out of bounds"),r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);var u=r-n;if(u<100||!o._useTypedArrays)for(var a=0;a<u;a++)e[a+t]=this[a+n];else e._set(this.subarray(n,n+u),t)}},o.prototype.slice=function(e,t){var n=this.length;if(e=Y(e,n,0),t=Y(t,n,n),o._useTypedArrays)return o._augment(this.subarray(e,t));for(var r=t-e,i=new o(r,(void 0),(!0)),u=0;u<r;u++)i[u]=this[u+e];return i},o.prototype.get=function(e){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(e)},o.prototype.set=function(e,t){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(e,t)},o.prototype.readUInt8=function(e,t){if(t||($(void 0!==e&&null!==e,"missing offset"),$(e<this.length,"Trying to read beyond buffer length")),!(e>=this.length))return this[e]},o.prototype.readUInt16LE=function(e,t){return I(this,e,!0,t)},o.prototype.readUInt16BE=function(e,t){return I(this,e,!1,t)},o.prototype.readUInt32LE=function(e,t){return A(this,e,!0,t)},o.prototype.readUInt32BE=function(e,t){return A(this,e,!1,t)},o.prototype.readInt8=function(e,t){if(t||($(void 0!==e&&null!==e,"missing offset"),$(e<this.length,"Trying to read beyond buffer length")),!(e>=this.length)){var n=128&this[e];return n?(255-this[e]+1)*-1:this[e]}},o.prototype.readInt16LE=function(e,t){return B(this,e,!0,t)},o.prototype.readInt16BE=function(e,t){return B(this,e,!1,t)},o.prototype.readInt32LE=function(e,t){return L(this,e,!0,t)},o.prototype.readInt32BE=function(e,t){return L(this,e,!1,t)},o.prototype.readFloatLE=function(e,t){return U(this,e,!0,t)},o.prototype.readFloatBE=function(e,t){return U(this,e,!1,t)},o.prototype.readDoubleLE=function(e,t){return x(this,e,!0,t)},o.prototype.readDoubleBE=function(e,t){return x(this,e,!1,t)},o.prototype.writeUInt8=function(e,t,n){n||($(void 0!==e&&null!==e,"missing value"),$(void 0!==t&&null!==t,"missing offset"),$(t<this.length,"trying to write beyond buffer length"),K(e,255)),t>=this.length||(this[t]=e)},o.prototype.writeUInt16LE=function(e,t,n){S(this,e,t,!0,n)},o.prototype.writeUInt16BE=function(e,t,n){S(this,e,t,!1,n)},o.prototype.writeUInt32LE=function(e,t,n){j(this,e,t,!0,n)},o.prototype.writeUInt32BE=function(e,t,n){j(this,e,t,!1,n)},o.prototype.writeInt8=function(e,t,n){n||($(void 0!==e&&null!==e,"missing value"),$(void 0!==t&&null!==t,"missing offset"),$(t<this.length,"Trying to write beyond buffer length"),z(e,127,-128)),t>=this.length||(e>=0?this.writeUInt8(e,t,n):this.writeUInt8(255+e+1,t,n))},o.prototype.writeInt16LE=function(e,t,n){C(this,e,t,!0,n)},o.prototype.writeInt16BE=function(e,t,n){C(this,e,t,!1,n)},o.prototype.writeInt32LE=function(e,t,n){k(this,e,t,!0,n)},o.prototype.writeInt32BE=function(e,t,n){k(this,e,t,!1,n)},o.prototype.writeFloatLE=function(e,t,n){T(this,e,t,!0,n)},o.prototype.writeFloatBE=function(e,t,n){T(this,e,t,!1,n)},o.prototype.writeDoubleLE=function(e,t,n){M(this,e,t,!0,n)},o.prototype.writeDoubleBE=function(e,t,n){M(this,e,t,!1,n)},o.prototype.fill=function(e,t,n){if(e||(e=0),t||(t=0),n||(n=this.length),"string"==typeof e&&(e=e.charCodeAt(0)),$("number"==typeof e&&!isNaN(e),"value is not a number"),$(n>=t,"end < start"),n!==t&&0!==this.length){$(t>=0&&t<this.length,"start out of bounds"),$(n>=0&&n<=this.length,"end out of bounds");for(var r=t;r<n;r++)this[r]=e}},o.prototype.inspect=function(){for(var e=[],t=this.length,r=0;r<t;r++)if(e[r]=H(this[r]),r===n.INSPECT_MAX_BYTES){e[r+1]="...";break}return"<Buffer "+e.join(" ")+">"},o.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(o._useTypedArrays)return new o(this).buffer;for(var e=new Uint8Array(this.length),t=0,n=e.length;t<n;t+=1)e[t]=this[t];return e.buffer}throw new Error("Buffer.toArrayBuffer not supported in this browser")};var Z=o.prototype;o._augment=function(e){return e._isBuffer=!0,e._get=e.get,e._set=e.set,e.get=Z.get,e.set=Z.set,e.write=Z.write,e.toString=Z.toString,e.toLocaleString=Z.toString,e.toJSON=Z.toJSON,e.copy=Z.copy,e.slice=Z.slice,e.readUInt8=Z.readUInt8,e.readUInt16LE=Z.readUInt16LE,e.readUInt16BE=Z.readUInt16BE,e.readUInt32LE=Z.readUInt32LE,e.readUInt32BE=Z.readUInt32BE,e.readInt8=Z.readInt8,e.readInt16LE=Z.readInt16LE,e.readInt16BE=Z.readInt16BE,e.readInt32LE=Z.readInt32LE,e.readInt32BE=Z.readInt32BE,e.readFloatLE=Z.readFloatLE,e.readFloatBE=Z.readFloatBE,e.readDoubleLE=Z.readDoubleLE,e.readDoubleBE=Z.readDoubleBE,e.writeUInt8=Z.writeUInt8,e.writeUInt16LE=Z.writeUInt16LE,e.writeUInt16BE=Z.writeUInt16BE,e.writeUInt32LE=Z.writeUInt32LE,e.writeUInt32BE=Z.writeUInt32BE,e.writeInt8=Z.writeInt8,e.writeInt16LE=Z.writeInt16LE,e.writeInt16BE=Z.writeInt16BE,e.writeInt32LE=Z.writeInt32LE,e.writeInt32BE=Z.writeInt32BE,e.writeFloatLE=Z.writeFloatLE,e.writeFloatBE=Z.writeFloatBE,e.writeDoubleLE=Z.writeDoubleLE,e.writeDoubleBE=Z.writeDoubleBE,e.fill=Z.fill,e.inspect=Z.inspect,e.toArrayBuffer=Z.toArrayBuffer,e}}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/buffer/index.js","/node_modules/gulp-browserify/node_modules/buffer")},{"base64-js":2,buffer:3,ieee754:11,lYpoI2:10}],4:[function(e,t,n){(function(n,r,o,i,u,a,f,s,c){function l(e,t){if(e.length%p!==0){var n=e.length+(p-e.length%p);e=o.concat([e,g],n)}for(var r=[],i=t?e.readInt32BE:e.readInt32LE,u=0;u<e.length;u+=p)r.push(i.call(e,u));return r}function d(e,t,n){for(var r=new o(t),i=n?r.writeInt32BE:r.writeInt32LE,u=0;u<e.length;u++)i.call(r,e[u],4*u,!0);return r}function h(e,t,n,r){o.isBuffer(e)||(e=new o(e));var i=t(l(e,r),e.length*y);return d(i,n,r)}var o=e("buffer").Buffer,p=4,g=new o(p);g.fill(0);var y=8;t.exports={hash:h}}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/helpers.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{buffer:3,lYpoI2:10}],5:[function(e,t,n){(function(t,r,o,i,u,a,f,s,c){function l(e,t,n){o.isBuffer(t)||(t=new o(t)),o.isBuffer(n)||(n=new o(n)),t.length>m?t=e(t):t.length<m&&(t=o.concat([t,_],m));for(var r=new o(m),i=new o(m),u=0;u<m;u++)r[u]=54^t[u],i[u]=92^t[u];var a=e(o.concat([r,n]));return e(o.concat([i,a]))}function d(e,t){e=e||"sha1";var n=v[e],r=[],i=0;return n||h("algorithm:",e,"is not yet supported"),{update:function(e){return o.isBuffer(e)||(e=new o(e)),r.push(e),i+=e.length,this},digest:function(e){var i=o.concat(r),u=t?l(n,t,i):n(i);return r=null,e?u.toString(e):u}}}function h(){var e=[].slice.call(arguments).join(" ");throw new Error([e,"we accept pull requests","http://github.com/dominictarr/crypto-browserify"].join("\n"))}function p(e,t){for(var n in e)t(e[n],n)}var o=e("buffer").Buffer,g=e("./sha"),y=e("./sha256"),w=e("./rng"),b=e("./md5"),v={sha1:g,sha256:y,md5:b},m=64,_=new o(m);_.fill(0),n.createHash=function(e){return d(e)},n.createHmac=function(e,t){return d(e,t)},n.randomBytes=function(e,t){if(!t||!t.call)return new o(w(e));try{t.call(this,void 0,new o(w(e)))}catch(n){t(n)}},p(["createCredentials","createCipher","createCipheriv","createDecipher","createDecipheriv","createSign","createVerify","createDiffieHellman","pbkdf2"],function(e){n[e]=function(){h("sorry,",e,"is not implemented yet")}})}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/index.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./md5":6,"./rng":7,"./sha":8,"./sha256":9,buffer:3,lYpoI2:10}],6:[function(e,t,n){(function(n,r,o,i,u,a,f,s,c){function l(e,t){e[t>>5]|=128<<t%32,e[(t+64>>>9<<4)+14]=t;for(var n=1732584193,r=-271733879,o=-1732584194,i=271733878,u=0;u<e.length;u+=16){var a=n,f=r,s=o,c=i;n=h(n,r,o,i,e[u+0],7,-680876936),i=h(i,n,r,o,e[u+1],12,-389564586),o=h(o,i,n,r,e[u+2],17,606105819),r=h(r,o,i,n,e[u+3],22,-1044525330),n=h(n,r,o,i,e[u+4],7,-176418897),i=h(i,n,r,o,e[u+5],12,1200080426),o=h(o,i,n,r,e[u+6],17,-1473231341),r=h(r,o,i,n,e[u+7],22,-45705983),n=h(n,r,o,i,e[u+8],7,1770035416),i=h(i,n,r,o,e[u+9],12,-1958414417),o=h(o,i,n,r,e[u+10],17,-42063),r=h(r,o,i,n,e[u+11],22,-1990404162),n=h(n,r,o,i,e[u+12],7,1804603682),i=h(i,n,r,o,e[u+13],12,-40341101),o=h(o,i,n,r,e[u+14],17,-1502002290),r=h(r,o,i,n,e[u+15],22,1236535329),n=p(n,r,o,i,e[u+1],5,-165796510),i=p(i,n,r,o,e[u+6],9,-1069501632),o=p(o,i,n,r,e[u+11],14,643717713),r=p(r,o,i,n,e[u+0],20,-373897302),n=p(n,r,o,i,e[u+5],5,-701558691),i=p(i,n,r,o,e[u+10],9,38016083),o=p(o,i,n,r,e[u+15],14,-660478335),r=p(r,o,i,n,e[u+4],20,-405537848),n=p(n,r,o,i,e[u+9],5,568446438),i=p(i,n,r,o,e[u+14],9,-1019803690),o=p(o,i,n,r,e[u+3],14,-187363961),r=p(r,o,i,n,e[u+8],20,1163531501),n=p(n,r,o,i,e[u+13],5,-1444681467),i=p(i,n,r,o,e[u+2],9,-51403784),o=p(o,i,n,r,e[u+7],14,1735328473),r=p(r,o,i,n,e[u+12],20,-1926607734),n=g(n,r,o,i,e[u+5],4,-378558),i=g(i,n,r,o,e[u+8],11,-2022574463),o=g(o,i,n,r,e[u+11],16,1839030562),r=g(r,o,i,n,e[u+14],23,-35309556),n=g(n,r,o,i,e[u+1],4,-1530992060),i=g(i,n,r,o,e[u+4],11,1272893353),o=g(o,i,n,r,e[u+7],16,-155497632),r=g(r,o,i,n,e[u+10],23,-1094730640),n=g(n,r,o,i,e[u+13],4,681279174),i=g(i,n,r,o,e[u+0],11,-358537222),o=g(o,i,n,r,e[u+3],16,-722521979),r=g(r,o,i,n,e[u+6],23,76029189),n=g(n,r,o,i,e[u+9],4,-640364487),i=g(i,n,r,o,e[u+12],11,-421815835),o=g(o,i,n,r,e[u+15],16,530742520),r=g(r,o,i,n,e[u+2],23,-995338651),n=y(n,r,o,i,e[u+0],6,-198630844),i=y(i,n,r,o,e[u+7],10,1126891415),o=y(o,i,n,r,e[u+14],15,-1416354905),r=y(r,o,i,n,e[u+5],21,-57434055),n=y(n,r,o,i,e[u+12],6,1700485571),i=y(i,n,r,o,e[u+3],10,-1894986606),o=y(o,i,n,r,e[u+10],15,-1051523),r=y(r,o,i,n,e[u+1],21,-2054922799),n=y(n,r,o,i,e[u+8],6,1873313359),i=y(i,n,r,o,e[u+15],10,-30611744),o=y(o,i,n,r,e[u+6],15,-1560198380),r=y(r,o,i,n,e[u+13],21,1309151649),n=y(n,r,o,i,e[u+4],6,-145523070),i=y(i,n,r,o,e[u+11],10,-1120210379),o=y(o,i,n,r,e[u+2],15,718787259),r=y(r,o,i,n,e[u+9],21,-343485551),n=w(n,a),r=w(r,f),o=w(o,s),i=w(i,c)}return Array(n,r,o,i)}function d(e,t,n,r,o,i){return w(b(w(w(t,e),w(r,i)),o),n)}function h(e,t,n,r,o,i,u){return d(t&n|~t&r,e,t,o,i,u)}function p(e,t,n,r,o,i,u){return d(t&r|n&~r,e,t,o,i,u)}function g(e,t,n,r,o,i,u){return d(t^n^r,e,t,o,i,u)}function y(e,t,n,r,o,i,u){return d(n^(t|~r),e,t,o,i,u)}function w(e,t){var n=(65535&e)+(65535&t),r=(e>>16)+(t>>16)+(n>>16);return r<<16|65535&n}function b(e,t){return e<<t|e>>>32-t}var v=e("./helpers");t.exports=function(e){return v.hash(e,l,16)}}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/md5.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:10}],7:[function(e,t,n){(function(e,n,r,o,i,u,a,f,s){!function(){var e,n,r=this;e=function(e){for(var t,t,n=new Array(e),r=0;r<e;r++)0==(3&r)&&(t=4294967296*Math.random()),n[r]=t>>>((3&r)<<3)&255;return n},r.crypto&&crypto.getRandomValues&&(n=function(e){var t=new Uint8Array(e);return crypto.getRandomValues(t),t}),t.exports=n||e}()}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/rng.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{buffer:3,lYpoI2:10}],8:[function(e,t,n){(function(n,r,o,i,u,a,f,s,c){function l(e,t){e[t>>5]|=128<<24-t%32,e[(t+64>>9<<4)+15]=t;for(var n=Array(80),r=1732584193,o=-271733879,i=-1732584194,u=271733878,a=-1009589776,f=0;f<e.length;f+=16){for(var s=r,c=o,l=i,y=u,w=a,b=0;b<80;b++){b<16?n[b]=e[f+b]:n[b]=g(n[b-3]^n[b-8]^n[b-14]^n[b-16],1);var v=p(p(g(r,5),d(b,o,i,u)),p(p(a,n[b]),h(b)));a=u,u=i,i=g(o,30),o=r,r=v}r=p(r,s),o=p(o,c),i=p(i,l),u=p(u,y),a=p(a,w)}return Array(r,o,i,u,a)}function d(e,t,n,r){return e<20?t&n|~t&r:e<40?t^n^r:e<60?t&n|t&r|n&r:t^n^r}function h(e){return e<20?1518500249:e<40?1859775393:e<60?-1894007588:-899497514}function p(e,t){var n=(65535&e)+(65535&t),r=(e>>16)+(t>>16)+(n>>16);return r<<16|65535&n}function g(e,t){return e<<t|e>>>32-t}var y=e("./helpers");t.exports=function(e){return y.hash(e,l,20,!0)}}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/sha.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:10}],9:[function(e,t,n){(function(n,r,o,i,u,a,f,s,c){var l=e("./helpers"),d=function(e,t){var n=(65535&e)+(65535&t),r=(e>>16)+(t>>16)+(n>>16);return r<<16|65535&n},h=function(e,t){return e>>>t|e<<32-t},p=function(e,t){return e>>>t},g=function(e,t,n){return e&t^~e&n},y=function(e,t,n){return e&t^e&n^t&n},w=function(e){return h(e,2)^h(e,13)^h(e,22);
  4. },b=function(e){return h(e,6)^h(e,11)^h(e,25)},v=function(e){return h(e,7)^h(e,18)^p(e,3)},m=function(e){return h(e,17)^h(e,19)^p(e,10)},_=function(e,t){var n,r,o,i,u,a,f,s,c,l,h,p,_=new Array(1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298),E=new Array(1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225),I=new Array(64);e[t>>5]|=128<<24-t%32,e[(t+64>>9<<4)+15]=t;for(var c=0;c<e.length;c+=16){n=E[0],r=E[1],o=E[2],i=E[3],u=E[4],a=E[5],f=E[6],s=E[7];for(var l=0;l<64;l++)l<16?I[l]=e[l+c]:I[l]=d(d(d(m(I[l-2]),I[l-7]),v(I[l-15])),I[l-16]),h=d(d(d(d(s,b(u)),g(u,a,f)),_[l]),I[l]),p=d(w(n),y(n,r,o)),s=f,f=a,a=u,u=d(i,h),i=o,o=r,r=n,n=d(h,p);E[0]=d(n,E[0]),E[1]=d(r,E[1]),E[2]=d(o,E[2]),E[3]=d(i,E[3]),E[4]=d(u,E[4]),E[5]=d(a,E[5]),E[6]=d(f,E[6]),E[7]=d(s,E[7])}return E};t.exports=function(e){return l.hash(e,_,32,!0)}}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/crypto-browserify/sha256.js","/node_modules/gulp-browserify/node_modules/crypto-browserify")},{"./helpers":4,buffer:3,lYpoI2:10}],10:[function(e,t,n){(function(e,n,r,o,i,u,a,f,s){function c(){}var e=t.exports={};e.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(t){var n=[];return window.addEventListener("message",function(e){var t=e.source;if((t===window||null===t)&&"process-tick"===e.data&&(e.stopPropagation(),n.length>0)){var r=n.shift();r()}},!0),function(e){n.push(e),window.postMessage("process-tick","*")}}return function(e){setTimeout(e,0)}}(),e.title="browser",e.browser=!0,e.env={},e.argv=[],e.on=c,e.addListener=c,e.once=c,e.off=c,e.removeListener=c,e.removeAllListeners=c,e.emit=c,e.binding=function(e){throw new Error("process.binding is not supported")},e.cwd=function(){return"/"},e.chdir=function(e){throw new Error("process.chdir is not supported")}}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/gulp-browserify/node_modules/process/browser.js","/node_modules/gulp-browserify/node_modules/process")},{buffer:3,lYpoI2:10}],11:[function(e,t,n){(function(e,t,r,o,i,u,a,f,s){n.read=function(e,t,n,r,o){var i,u,a=8*o-r-1,f=(1<<a)-1,s=f>>1,c=-7,l=n?o-1:0,d=n?-1:1,h=e[t+l];for(l+=d,i=h&(1<<-c)-1,h>>=-c,c+=a;c>0;i=256*i+e[t+l],l+=d,c-=8);for(u=i&(1<<-c)-1,i>>=-c,c+=r;c>0;u=256*u+e[t+l],l+=d,c-=8);if(0===i)i=1-s;else{if(i===f)return u?NaN:(h?-1:1)*(1/0);u+=Math.pow(2,r),i-=s}return(h?-1:1)*u*Math.pow(2,i-r)},n.write=function(e,t,n,r,o,i){var u,a,f,s=8*i-o-1,c=(1<<s)-1,l=c>>1,d=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,h=r?0:i-1,p=r?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,u=c):(u=Math.floor(Math.log(t)/Math.LN2),t*(f=Math.pow(2,-u))<1&&(u--,f*=2),t+=u+l>=1?d/f:d*Math.pow(2,1-l),t*f>=2&&(u++,f/=2),u+l>=c?(a=0,u=c):u+l>=1?(a=(t*f-1)*Math.pow(2,o),u+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,o),u=0));o>=8;e[n+h]=255&a,h+=p,a/=256,o-=8);for(u=u<<o|a,s+=o;s>0;e[n+h]=255&u,h+=p,u/=256,s-=8);e[n+h-p]|=128*g}}).call(this,e("lYpoI2"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/ieee754/index.js","/node_modules/ieee754")},{buffer:3,lYpoI2:10}]},{},[1])(1)});
  5. }).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6. },{}],2:[function(require,module,exports){
  7. // http://wiki.commonjs.org/wiki/Unit_Testing/1.0
  8. //
  9. // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
  10. //
  11. // Originally from narwhal.js (http://narwhaljs.org)
  12. // Copyright (c) 2009 Thomas Robinson <280north.com>
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining a copy
  15. // of this software and associated documentation files (the 'Software'), to
  16. // deal in the Software without restriction, including without limitation the
  17. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  18. // sell copies of the Software, and to permit persons to whom the Software is
  19. // furnished to do so, subject to the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be included in
  22. // all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27. // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. // when used in node, this will actually load the util module we depend on
  31. // versus loading the builtin util module as happens otherwise
  32. // this is a bug in node module loading as far as I am concerned
  33. var util = require('util/');
  34. var pSlice = Array.prototype.slice;
  35. var hasOwn = Object.prototype.hasOwnProperty;
  36. // 1. The assert module provides functions that throw
  37. // AssertionError's when particular conditions are not met. The
  38. // assert module must conform to the following interface.
  39. var assert = module.exports = ok;
  40. // 2. The AssertionError is defined in assert.
  41. // new assert.AssertionError({ message: message,
  42. // actual: actual,
  43. // expected: expected })
  44. assert.AssertionError = function AssertionError(options) {
  45. this.name = 'AssertionError';
  46. this.actual = options.actual;
  47. this.expected = options.expected;
  48. this.operator = options.operator;
  49. if (options.message) {
  50. this.message = options.message;
  51. this.generatedMessage = false;
  52. } else {
  53. this.message = getMessage(this);
  54. this.generatedMessage = true;
  55. }
  56. var stackStartFunction = options.stackStartFunction || fail;
  57. if (Error.captureStackTrace) {
  58. Error.captureStackTrace(this, stackStartFunction);
  59. }
  60. else {
  61. // non v8 browsers so we can have a stacktrace
  62. var err = new Error();
  63. if (err.stack) {
  64. var out = err.stack;
  65. // try to strip useless frames
  66. var fn_name = stackStartFunction.name;
  67. var idx = out.indexOf('\n' + fn_name);
  68. if (idx >= 0) {
  69. // once we have located the function frame
  70. // we need to strip out everything before it (and its line)
  71. var next_line = out.indexOf('\n', idx + 1);
  72. out = out.substring(next_line + 1);
  73. }
  74. this.stack = out;
  75. }
  76. }
  77. };
  78. // assert.AssertionError instanceof Error
  79. util.inherits(assert.AssertionError, Error);
  80. function replacer(key, value) {
  81. if (util.isUndefined(value)) {
  82. return '' + value;
  83. }
  84. if (util.isNumber(value) && (isNaN(value) || !isFinite(value))) {
  85. return value.toString();
  86. }
  87. if (util.isFunction(value) || util.isRegExp(value)) {
  88. return value.toString();
  89. }
  90. return value;
  91. }
  92. function truncate(s, n) {
  93. if (util.isString(s)) {
  94. return s.length < n ? s : s.slice(0, n);
  95. } else {
  96. return s;
  97. }
  98. }
  99. function getMessage(self) {
  100. return truncate(JSON.stringify(self.actual, replacer), 128) + ' ' +
  101. self.operator + ' ' +
  102. truncate(JSON.stringify(self.expected, replacer), 128);
  103. }
  104. // At present only the three keys mentioned above are used and
  105. // understood by the spec. Implementations or sub modules can pass
  106. // other keys to the AssertionError's constructor - they will be
  107. // ignored.
  108. // 3. All of the following functions must throw an AssertionError
  109. // when a corresponding condition is not met, with a message that
  110. // may be undefined if not provided. All assertion methods provide
  111. // both the actual and expected values to the assertion error for
  112. // display purposes.
  113. function fail(actual, expected, message, operator, stackStartFunction) {
  114. throw new assert.AssertionError({
  115. message: message,
  116. actual: actual,
  117. expected: expected,
  118. operator: operator,
  119. stackStartFunction: stackStartFunction
  120. });
  121. }
  122. // EXTENSION! allows for well behaved errors defined elsewhere.
  123. assert.fail = fail;
  124. // 4. Pure assertion tests whether a value is truthy, as determined
  125. // by !!guard.
  126. // assert.ok(guard, message_opt);
  127. // This statement is equivalent to assert.equal(true, !!guard,
  128. // message_opt);. To test strictly for the value true, use
  129. // assert.strictEqual(true, guard, message_opt);.
  130. function ok(value, message) {
  131. if (!value) fail(value, true, message, '==', assert.ok);
  132. }
  133. assert.ok = ok;
  134. // 5. The equality assertion tests shallow, coercive equality with
  135. // ==.
  136. // assert.equal(actual, expected, message_opt);
  137. assert.equal = function equal(actual, expected, message) {
  138. if (actual != expected) fail(actual, expected, message, '==', assert.equal);
  139. };
  140. // 6. The non-equality assertion tests for whether two objects are not equal
  141. // with != assert.notEqual(actual, expected, message_opt);
  142. assert.notEqual = function notEqual(actual, expected, message) {
  143. if (actual == expected) {
  144. fail(actual, expected, message, '!=', assert.notEqual);
  145. }
  146. };
  147. // 7. The equivalence assertion tests a deep equality relation.
  148. // assert.deepEqual(actual, expected, message_opt);
  149. assert.deepEqual = function deepEqual(actual, expected, message) {
  150. if (!_deepEqual(actual, expected)) {
  151. fail(actual, expected, message, 'deepEqual', assert.deepEqual);
  152. }
  153. };
  154. function _deepEqual(actual, expected) {
  155. // 7.1. All identical values are equivalent, as determined by ===.
  156. if (actual === expected) {
  157. return true;
  158. } else if (util.isBuffer(actual) && util.isBuffer(expected)) {
  159. if (actual.length != expected.length) return false;
  160. for (var i = 0; i < actual.length; i++) {
  161. if (actual[i] !== expected[i]) return false;
  162. }
  163. return true;
  164. // 7.2. If the expected value is a Date object, the actual value is
  165. // equivalent if it is also a Date object that refers to the same time.
  166. } else if (util.isDate(actual) && util.isDate(expected)) {
  167. return actual.getTime() === expected.getTime();
  168. // 7.3 If the expected value is a RegExp object, the actual value is
  169. // equivalent if it is also a RegExp object with the same source and
  170. // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
  171. } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
  172. return actual.source === expected.source &&
  173. actual.global === expected.global &&
  174. actual.multiline === expected.multiline &&
  175. actual.lastIndex === expected.lastIndex &&
  176. actual.ignoreCase === expected.ignoreCase;
  177. // 7.4. Other pairs that do not both pass typeof value == 'object',
  178. // equivalence is determined by ==.
  179. } else if (!util.isObject(actual) && !util.isObject(expected)) {
  180. return actual == expected;
  181. // 7.5 For all other Object pairs, including Array objects, equivalence is
  182. // determined by having the same number of owned properties (as verified
  183. // with Object.prototype.hasOwnProperty.call), the same set of keys
  184. // (although not necessarily the same order), equivalent values for every
  185. // corresponding key, and an identical 'prototype' property. Note: this
  186. // accounts for both named and indexed properties on Arrays.
  187. } else {
  188. return objEquiv(actual, expected);
  189. }
  190. }
  191. function isArguments(object) {
  192. return Object.prototype.toString.call(object) == '[object Arguments]';
  193. }
  194. function objEquiv(a, b) {
  195. if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b))
  196. return false;
  197. // an identical 'prototype' property.
  198. if (a.prototype !== b.prototype) return false;
  199. //~~~I've managed to break Object.keys through screwy arguments passing.
  200. // Converting to array solves the problem.
  201. if (isArguments(a)) {
  202. if (!isArguments(b)) {
  203. return false;
  204. }
  205. a = pSlice.call(a);
  206. b = pSlice.call(b);
  207. return _deepEqual(a, b);
  208. }
  209. try {
  210. var ka = objectKeys(a),
  211. kb = objectKeys(b),
  212. key, i;
  213. } catch (e) {//happens when one is a string literal and the other isn't
  214. return false;
  215. }
  216. // having the same number of owned properties (keys incorporates
  217. // hasOwnProperty)
  218. if (ka.length != kb.length)
  219. return false;
  220. //the same set of keys (although not necessarily the same order),
  221. ka.sort();
  222. kb.sort();
  223. //~~~cheap key test
  224. for (i = ka.length - 1; i >= 0; i--) {
  225. if (ka[i] != kb[i])
  226. return false;
  227. }
  228. //equivalent values for every corresponding key, and
  229. //~~~possibly expensive deep test
  230. for (i = ka.length - 1; i >= 0; i--) {
  231. key = ka[i];
  232. if (!_deepEqual(a[key], b[key])) return false;
  233. }
  234. return true;
  235. }
  236. // 8. The non-equivalence assertion tests for any deep inequality.
  237. // assert.notDeepEqual(actual, expected, message_opt);
  238. assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
  239. if (_deepEqual(actual, expected)) {
  240. fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
  241. }
  242. };
  243. // 9. The strict equality assertion tests strict equality, as determined by ===.
  244. // assert.strictEqual(actual, expected, message_opt);
  245. assert.strictEqual = function strictEqual(actual, expected, message) {
  246. if (actual !== expected) {
  247. fail(actual, expected, message, '===', assert.strictEqual);
  248. }
  249. };
  250. // 10. The strict non-equality assertion tests for strict inequality, as
  251. // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
  252. assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
  253. if (actual === expected) {
  254. fail(actual, expected, message, '!==', assert.notStrictEqual);
  255. }
  256. };
  257. function expectedException(actual, expected) {
  258. if (!actual || !expected) {
  259. return false;
  260. }
  261. if (Object.prototype.toString.call(expected) == '[object RegExp]') {
  262. return expected.test(actual);
  263. } else if (actual instanceof expected) {
  264. return true;
  265. } else if (expected.call({}, actual) === true) {
  266. return true;
  267. }
  268. return false;
  269. }
  270. function _throws(shouldThrow, block, expected, message) {
  271. var actual;
  272. if (util.isString(expected)) {
  273. message = expected;
  274. expected = null;
  275. }
  276. try {
  277. block();
  278. } catch (e) {
  279. actual = e;
  280. }
  281. message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
  282. (message ? ' ' + message : '.');
  283. if (shouldThrow && !actual) {
  284. fail(actual, expected, 'Missing expected exception' + message);
  285. }
  286. if (!shouldThrow && expectedException(actual, expected)) {
  287. fail(actual, expected, 'Got unwanted exception' + message);
  288. }
  289. if ((shouldThrow && actual && expected &&
  290. !expectedException(actual, expected)) || (!shouldThrow && actual)) {
  291. throw actual;
  292. }
  293. }
  294. // 11. Expected to throw an error:
  295. // assert.throws(block, Error_opt, message_opt);
  296. assert.throws = function(block, /*optional*/error, /*optional*/message) {
  297. _throws.apply(this, [true].concat(pSlice.call(arguments)));
  298. };
  299. // EXTENSION! This is annoying to write outside this module.
  300. assert.doesNotThrow = function(block, /*optional*/message) {
  301. _throws.apply(this, [false].concat(pSlice.call(arguments)));
  302. };
  303. assert.ifError = function(err) { if (err) {throw err;}};
  304. var objectKeys = Object.keys || function (obj) {
  305. var keys = [];
  306. for (var key in obj) {
  307. if (hasOwn.call(obj, key)) keys.push(key);
  308. }
  309. return keys;
  310. };
  311. },{"util/":5}],3:[function(require,module,exports){
  312. if (typeof Object.create === 'function') {
  313. // implementation from standard node.js 'util' module
  314. module.exports = function inherits(ctor, superCtor) {
  315. ctor.super_ = superCtor
  316. ctor.prototype = Object.create(superCtor.prototype, {
  317. constructor: {
  318. value: ctor,
  319. enumerable: false,
  320. writable: true,
  321. configurable: true
  322. }
  323. });
  324. };
  325. } else {
  326. // old school shim for old browsers
  327. module.exports = function inherits(ctor, superCtor) {
  328. ctor.super_ = superCtor
  329. var TempCtor = function () {}
  330. TempCtor.prototype = superCtor.prototype
  331. ctor.prototype = new TempCtor()
  332. ctor.prototype.constructor = ctor
  333. }
  334. }
  335. },{}],4:[function(require,module,exports){
  336. module.exports = function isBuffer(arg) {
  337. return arg && typeof arg === 'object'
  338. && typeof arg.copy === 'function'
  339. && typeof arg.fill === 'function'
  340. && typeof arg.readUInt8 === 'function';
  341. }
  342. },{}],5:[function(require,module,exports){
  343. (function (process,global){
  344. // Copyright Joyent, Inc. and other Node contributors.
  345. //
  346. // Permission is hereby granted, free of charge, to any person obtaining a
  347. // copy of this software and associated documentation files (the
  348. // "Software"), to deal in the Software without restriction, including
  349. // without limitation the rights to use, copy, modify, merge, publish,
  350. // distribute, sublicense, and/or sell copies of the Software, and to permit
  351. // persons to whom the Software is furnished to do so, subject to the
  352. // following conditions:
  353. //
  354. // The above copyright notice and this permission notice shall be included
  355. // in all copies or substantial portions of the Software.
  356. //
  357. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  358. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  359. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  360. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  361. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  362. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  363. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  364. var formatRegExp = /%[sdj%]/g;
  365. exports.format = function(f) {
  366. if (!isString(f)) {
  367. var objects = [];
  368. for (var i = 0; i < arguments.length; i++) {
  369. objects.push(inspect(arguments[i]));
  370. }
  371. return objects.join(' ');
  372. }
  373. var i = 1;
  374. var args = arguments;
  375. var len = args.length;
  376. var str = String(f).replace(formatRegExp, function(x) {
  377. if (x === '%%') return '%';
  378. if (i >= len) return x;
  379. switch (x) {
  380. case '%s': return String(args[i++]);
  381. case '%d': return Number(args[i++]);
  382. case '%j':
  383. try {
  384. return JSON.stringify(args[i++]);
  385. } catch (_) {
  386. return '[Circular]';
  387. }
  388. default:
  389. return x;
  390. }
  391. });
  392. for (var x = args[i]; i < len; x = args[++i]) {
  393. if (isNull(x) || !isObject(x)) {
  394. str += ' ' + x;
  395. } else {
  396. str += ' ' + inspect(x);
  397. }
  398. }
  399. return str;
  400. };
  401. // Mark that a method should not be used.
  402. // Returns a modified function which warns once by default.
  403. // If --no-deprecation is set, then it is a no-op.
  404. exports.deprecate = function(fn, msg) {
  405. // Allow for deprecating things in the process of starting up.
  406. if (isUndefined(global.process)) {
  407. return function() {
  408. return exports.deprecate(fn, msg).apply(this, arguments);
  409. };
  410. }
  411. if (process.noDeprecation === true) {
  412. return fn;
  413. }
  414. var warned = false;
  415. function deprecated() {
  416. if (!warned) {
  417. if (process.throwDeprecation) {
  418. throw new Error(msg);
  419. } else if (process.traceDeprecation) {
  420. console.trace(msg);
  421. } else {
  422. console.error(msg);
  423. }
  424. warned = true;
  425. }
  426. return fn.apply(this, arguments);
  427. }
  428. return deprecated;
  429. };
  430. var debugs = {};
  431. var debugEnviron;
  432. exports.debuglog = function(set) {
  433. if (isUndefined(debugEnviron))
  434. debugEnviron = process.env.NODE_DEBUG || '';
  435. set = set.toUpperCase();
  436. if (!debugs[set]) {
  437. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  438. var pid = process.pid;
  439. debugs[set] = function() {
  440. var msg = exports.format.apply(exports, arguments);
  441. console.error('%s %d: %s', set, pid, msg);
  442. };
  443. } else {
  444. debugs[set] = function() {};
  445. }
  446. }
  447. return debugs[set];
  448. };
  449. /**
  450. * Echos the value of a value. Trys to print the value out
  451. * in the best way possible given the different types.
  452. *
  453. * @param {Object} obj The object to print out.
  454. * @param {Object} opts Optional options object that alters the output.
  455. */
  456. /* legacy: obj, showHidden, depth, colors*/
  457. function inspect(obj, opts) {
  458. // default options
  459. var ctx = {
  460. seen: [],
  461. stylize: stylizeNoColor
  462. };
  463. // legacy...
  464. if (arguments.length >= 3) ctx.depth = arguments[2];
  465. if (arguments.length >= 4) ctx.colors = arguments[3];
  466. if (isBoolean(opts)) {
  467. // legacy...
  468. ctx.showHidden = opts;
  469. } else if (opts) {
  470. // got an "options" object
  471. exports._extend(ctx, opts);
  472. }
  473. // set default options
  474. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  475. if (isUndefined(ctx.depth)) ctx.depth = 2;
  476. if (isUndefined(ctx.colors)) ctx.colors = false;
  477. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  478. if (ctx.colors) ctx.stylize = stylizeWithColor;
  479. return formatValue(ctx, obj, ctx.depth);
  480. }
  481. exports.inspect = inspect;
  482. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  483. inspect.colors = {
  484. 'bold' : [1, 22],
  485. 'italic' : [3, 23],
  486. 'underline' : [4, 24],
  487. 'inverse' : [7, 27],
  488. 'white' : [37, 39],
  489. 'grey' : [90, 39],
  490. 'black' : [30, 39],
  491. 'blue' : [34, 39],
  492. 'cyan' : [36, 39],
  493. 'green' : [32, 39],
  494. 'magenta' : [35, 39],
  495. 'red' : [31, 39],
  496. 'yellow' : [33, 39]
  497. };
  498. // Don't use 'blue' not visible on cmd.exe
  499. inspect.styles = {
  500. 'special': 'cyan',
  501. 'number': 'yellow',
  502. 'boolean': 'yellow',
  503. 'undefined': 'grey',
  504. 'null': 'bold',
  505. 'string': 'green',
  506. 'date': 'magenta',
  507. // "name": intentionally not styling
  508. 'regexp': 'red'
  509. };
  510. function stylizeWithColor(str, styleType) {
  511. var style = inspect.styles[styleType];
  512. if (style) {
  513. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  514. '\u001b[' + inspect.colors[style][1] + 'm';
  515. } else {
  516. return str;
  517. }
  518. }
  519. function stylizeNoColor(str, styleType) {
  520. return str;
  521. }
  522. function arrayToHash(array) {
  523. var hash = {};
  524. array.forEach(function(val, idx) {
  525. hash[val] = true;
  526. });
  527. return hash;
  528. }
  529. function formatValue(ctx, value, recurseTimes) {
  530. // Provide a hook for user-specified inspect functions.
  531. // Check that value is an object with an inspect function on it
  532. if (ctx.customInspect &&
  533. value &&
  534. isFunction(value.inspect) &&
  535. // Filter out the util module, it's inspect function is special
  536. value.inspect !== exports.inspect &&
  537. // Also filter out any prototype objects using the circular check.
  538. !(value.constructor && value.constructor.prototype === value)) {
  539. var ret = value.inspect(recurseTimes, ctx);
  540. if (!isString(ret)) {
  541. ret = formatValue(ctx, ret, recurseTimes);
  542. }
  543. return ret;
  544. }
  545. // Primitive types cannot have properties
  546. var primitive = formatPrimitive(ctx, value);
  547. if (primitive) {
  548. return primitive;
  549. }
  550. // Look up the keys of the object.
  551. var keys = Object.keys(value);
  552. var visibleKeys = arrayToHash(keys);
  553. if (ctx.showHidden) {
  554. keys = Object.getOwnPropertyNames(value);
  555. }
  556. // IE doesn't make error fields non-enumerable
  557. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  558. if (isError(value)
  559. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  560. return formatError(value);
  561. }
  562. // Some type of object without properties can be shortcutted.
  563. if (keys.length === 0) {
  564. if (isFunction(value)) {
  565. var name = value.name ? ': ' + value.name : '';
  566. return ctx.stylize('[Function' + name + ']', 'special');
  567. }
  568. if (isRegExp(value)) {
  569. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  570. }
  571. if (isDate(value)) {
  572. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  573. }
  574. if (isError(value)) {
  575. return formatError(value);
  576. }
  577. }
  578. var base = '', array = false, braces = ['{', '}'];
  579. // Make Array say that they are Array
  580. if (isArray(value)) {
  581. array = true;
  582. braces = ['[', ']'];
  583. }
  584. // Make functions say that they are functions
  585. if (isFunction(value)) {
  586. var n = value.name ? ': ' + value.name : '';
  587. base = ' [Function' + n + ']';
  588. }
  589. // Make RegExps say that they are RegExps
  590. if (isRegExp(value)) {
  591. base = ' ' + RegExp.prototype.toString.call(value);
  592. }
  593. // Make dates with properties first say the date
  594. if (isDate(value)) {
  595. base = ' ' + Date.prototype.toUTCString.call(value);
  596. }
  597. // Make error with message first say the error
  598. if (isError(value)) {
  599. base = ' ' + formatError(value);
  600. }
  601. if (keys.length === 0 && (!array || value.length == 0)) {
  602. return braces[0] + base + braces[1];
  603. }
  604. if (recurseTimes < 0) {
  605. if (isRegExp(value)) {
  606. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  607. } else {
  608. return ctx.stylize('[Object]', 'special');
  609. }
  610. }
  611. ctx.seen.push(value);
  612. var output;
  613. if (array) {
  614. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  615. } else {
  616. output = keys.map(function(key) {
  617. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  618. });
  619. }
  620. ctx.seen.pop();
  621. return reduceToSingleString(output, base, braces);
  622. }
  623. function formatPrimitive(ctx, value) {
  624. if (isUndefined(value))
  625. return ctx.stylize('undefined', 'undefined');
  626. if (isString(value)) {
  627. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  628. .replace(/'/g, "\\'")
  629. .replace(/\\"/g, '"') + '\'';
  630. return ctx.stylize(simple, 'string');
  631. }
  632. if (isNumber(value))
  633. return ctx.stylize('' + value, 'number');
  634. if (isBoolean(value))
  635. return ctx.stylize('' + value, 'boolean');
  636. // For some reason typeof null is "object", so special case here.
  637. if (isNull(value))
  638. return ctx.stylize('null', 'null');
  639. }
  640. function formatError(value) {
  641. return '[' + Error.prototype.toString.call(value) + ']';
  642. }
  643. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  644. var output = [];
  645. for (var i = 0, l = value.length; i < l; ++i) {
  646. if (hasOwnProperty(value, String(i))) {
  647. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  648. String(i), true));
  649. } else {
  650. output.push('');
  651. }
  652. }
  653. keys.forEach(function(key) {
  654. if (!key.match(/^\d+$/)) {
  655. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  656. key, true));
  657. }
  658. });
  659. return output;
  660. }
  661. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  662. var name, str, desc;
  663. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  664. if (desc.get) {
  665. if (desc.set) {
  666. str = ctx.stylize('[Getter/Setter]', 'special');
  667. } else {
  668. str = ctx.stylize('[Getter]', 'special');
  669. }
  670. } else {
  671. if (desc.set) {
  672. str = ctx.stylize('[Setter]', 'special');
  673. }
  674. }
  675. if (!hasOwnProperty(visibleKeys, key)) {
  676. name = '[' + key + ']';
  677. }
  678. if (!str) {
  679. if (ctx.seen.indexOf(desc.value) < 0) {
  680. if (isNull(recurseTimes)) {
  681. str = formatValue(ctx, desc.value, null);
  682. } else {
  683. str = formatValue(ctx, desc.value, recurseTimes - 1);
  684. }
  685. if (str.indexOf('\n') > -1) {
  686. if (array) {
  687. str = str.split('\n').map(function(line) {
  688. return ' ' + line;
  689. }).join('\n').substr(2);
  690. } else {
  691. str = '\n' + str.split('\n').map(function(line) {
  692. return ' ' + line;
  693. }).join('\n');
  694. }
  695. }
  696. } else {
  697. str = ctx.stylize('[Circular]', 'special');
  698. }
  699. }
  700. if (isUndefined(name)) {
  701. if (array && key.match(/^\d+$/)) {
  702. return str;
  703. }
  704. name = JSON.stringify('' + key);
  705. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  706. name = name.substr(1, name.length - 2);
  707. name = ctx.stylize(name, 'name');
  708. } else {
  709. name = name.replace(/'/g, "\\'")
  710. .replace(/\\"/g, '"')
  711. .replace(/(^"|"$)/g, "'");
  712. name = ctx.stylize(name, 'string');
  713. }
  714. }
  715. return name + ': ' + str;
  716. }
  717. function reduceToSingleString(output, base, braces) {
  718. var numLinesEst = 0;
  719. var length = output.reduce(function(prev, cur) {
  720. numLinesEst++;
  721. if (cur.indexOf('\n') >= 0) numLinesEst++;
  722. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  723. }, 0);
  724. if (length > 60) {
  725. return braces[0] +
  726. (base === '' ? '' : base + '\n ') +
  727. ' ' +
  728. output.join(',\n ') +
  729. ' ' +
  730. braces[1];
  731. }
  732. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  733. }
  734. // NOTE: These type checking functions intentionally don't use `instanceof`
  735. // because it is fragile and can be easily faked with `Object.create()`.
  736. function isArray(ar) {
  737. return Array.isArray(ar);
  738. }
  739. exports.isArray = isArray;
  740. function isBoolean(arg) {
  741. return typeof arg === 'boolean';
  742. }
  743. exports.isBoolean = isBoolean;
  744. function isNull(arg) {
  745. return arg === null;
  746. }
  747. exports.isNull = isNull;
  748. function isNullOrUndefined(arg) {
  749. return arg == null;
  750. }
  751. exports.isNullOrUndefined = isNullOrUndefined;
  752. function isNumber(arg) {
  753. return typeof arg === 'number';
  754. }
  755. exports.isNumber = isNumber;
  756. function isString(arg) {
  757. return typeof arg === 'string';
  758. }
  759. exports.isString = isString;
  760. function isSymbol(arg) {
  761. return typeof arg === 'symbol';
  762. }
  763. exports.isSymbol = isSymbol;
  764. function isUndefined(arg) {
  765. return arg === void 0;
  766. }
  767. exports.isUndefined = isUndefined;
  768. function isRegExp(re) {
  769. return isObject(re) && objectToString(re) === '[object RegExp]';
  770. }
  771. exports.isRegExp = isRegExp;
  772. function isObject(arg) {
  773. return typeof arg === 'object' && arg !== null;
  774. }
  775. exports.isObject = isObject;
  776. function isDate(d) {
  777. return isObject(d) && objectToString(d) === '[object Date]';
  778. }
  779. exports.isDate = isDate;
  780. function isError(e) {
  781. return isObject(e) &&
  782. (objectToString(e) === '[object Error]' || e instanceof Error);
  783. }
  784. exports.isError = isError;
  785. function isFunction(arg) {
  786. return typeof arg === 'function';
  787. }
  788. exports.isFunction = isFunction;
  789. function isPrimitive(arg) {
  790. return arg === null ||
  791. typeof arg === 'boolean' ||
  792. typeof arg === 'number' ||
  793. typeof arg === 'string' ||
  794. typeof arg === 'symbol' || // ES6 symbol
  795. typeof arg === 'undefined';
  796. }
  797. exports.isPrimitive = isPrimitive;
  798. exports.isBuffer = require('./support/isBuffer');
  799. function objectToString(o) {
  800. return Object.prototype.toString.call(o);
  801. }
  802. function pad(n) {
  803. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  804. }
  805. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  806. 'Oct', 'Nov', 'Dec'];
  807. // 26 Feb 16:19:34
  808. function timestamp() {
  809. var d = new Date();
  810. var time = [pad(d.getHours()),
  811. pad(d.getMinutes()),
  812. pad(d.getSeconds())].join(':');
  813. return [d.getDate(), months[d.getMonth()], time].join(' ');
  814. }
  815. // log is just a thin wrapper to console.log that prepends a timestamp
  816. exports.log = function() {
  817. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  818. };
  819. /**
  820. * Inherit the prototype methods from one constructor into another.
  821. *
  822. * The Function.prototype.inherits from lang.js rewritten as a standalone
  823. * function (not on Function.prototype). NOTE: If this file is to be loaded
  824. * during bootstrapping this function needs to be rewritten using some native
  825. * functions as prototype setup using normal JavaScript does not work as
  826. * expected during bootstrapping (see mirror.js in r114903).
  827. *
  828. * @param {function} ctor Constructor function which needs to inherit the
  829. * prototype.
  830. * @param {function} superCtor Constructor function to inherit prototype from.
  831. */
  832. exports.inherits = require('inherits');
  833. exports._extend = function(origin, add) {
  834. // Don't do anything if add isn't an object
  835. if (!add || !isObject(add)) return origin;
  836. var keys = Object.keys(add);
  837. var i = keys.length;
  838. while (i--) {
  839. origin[keys[i]] = add[keys[i]];
  840. }
  841. return origin;
  842. };
  843. function hasOwnProperty(obj, prop) {
  844. return Object.prototype.hasOwnProperty.call(obj, prop);
  845. }
  846. }).call(this,require("7YKIPe"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  847. },{"./support/isBuffer":4,"7YKIPe":9,"inherits":3}],6:[function(require,module,exports){
  848. var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  849. ;(function (exports) {
  850. 'use strict';
  851. var Arr = (typeof Uint8Array !== 'undefined')
  852. ? Uint8Array
  853. : Array
  854. var PLUS = '+'.charCodeAt(0)
  855. var SLASH = '/'.charCodeAt(0)
  856. var NUMBER = '0'.charCodeAt(0)
  857. var LOWER = 'a'.charCodeAt(0)
  858. var UPPER = 'A'.charCodeAt(0)
  859. var PLUS_URL_SAFE = '-'.charCodeAt(0)
  860. var SLASH_URL_SAFE = '_'.charCodeAt(0)
  861. function decode (elt) {
  862. var code = elt.charCodeAt(0)
  863. if (code === PLUS ||
  864. code === PLUS_URL_SAFE)
  865. return 62 // '+'
  866. if (code === SLASH ||
  867. code === SLASH_URL_SAFE)
  868. return 63 // '/'
  869. if (code < NUMBER)
  870. return -1 //no match
  871. if (code < NUMBER + 10)
  872. return code - NUMBER + 26 + 26
  873. if (code < UPPER + 26)
  874. return code - UPPER
  875. if (code < LOWER + 26)
  876. return code - LOWER + 26
  877. }
  878. function b64ToByteArray (b64) {
  879. var i, j, l, tmp, placeHolders, arr
  880. if (b64.length % 4 > 0) {
  881. throw new Error('Invalid string. Length must be a multiple of 4')
  882. }
  883. // the number of equal signs (place holders)
  884. // if there are two placeholders, than the two characters before it
  885. // represent one byte
  886. // if there is only one, then the three characters before it represent 2 bytes
  887. // this is just a cheap hack to not do indexOf twice
  888. var len = b64.length
  889. placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
  890. // base64 is 4/3 + up to two characters of the original data
  891. arr = new Arr(b64.length * 3 / 4 - placeHolders)
  892. // if there are placeholders, only get up to the last complete 4 chars
  893. l = placeHolders > 0 ? b64.length - 4 : b64.length
  894. var L = 0
  895. function push (v) {
  896. arr[L++] = v
  897. }
  898. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  899. tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
  900. push((tmp & 0xFF0000) >> 16)
  901. push((tmp & 0xFF00) >> 8)
  902. push(tmp & 0xFF)
  903. }
  904. if (placeHolders === 2) {
  905. tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
  906. push(tmp & 0xFF)
  907. } else if (placeHolders === 1) {
  908. tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
  909. push((tmp >> 8) & 0xFF)
  910. push(tmp & 0xFF)
  911. }
  912. return arr
  913. }
  914. function uint8ToBase64 (uint8) {
  915. var i,
  916. extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
  917. output = "",
  918. temp, length
  919. function encode (num) {
  920. return lookup.charAt(num)
  921. }
  922. function tripletToBase64 (num) {
  923. return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
  924. }
  925. // go through the array every three bytes, we'll deal with trailing stuff later
  926. for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
  927. temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  928. output += tripletToBase64(temp)
  929. }
  930. // pad the end with zeros, but make sure to not forget the extra bytes
  931. switch (extraBytes) {
  932. case 1:
  933. temp = uint8[uint8.length - 1]
  934. output += encode(temp >> 2)
  935. output += encode((temp << 4) & 0x3F)
  936. output += '=='
  937. break
  938. case 2:
  939. temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
  940. output += encode(temp >> 10)
  941. output += encode((temp >> 4) & 0x3F)
  942. output += encode((temp << 2) & 0x3F)
  943. output += '='
  944. break
  945. }
  946. return output
  947. }
  948. exports.toByteArray = b64ToByteArray
  949. exports.fromByteArray = uint8ToBase64
  950. }(typeof exports === 'undefined' ? (this.base64js = {}) : exports))
  951. },{}],7:[function(require,module,exports){
  952. /*!
  953. * The buffer module from node.js, for the browser.
  954. *
  955. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  956. * @license MIT
  957. */
  958. var base64 = require('base64-js')
  959. var ieee754 = require('ieee754')
  960. exports.Buffer = Buffer
  961. exports.SlowBuffer = Buffer
  962. exports.INSPECT_MAX_BYTES = 50
  963. Buffer.poolSize = 8192
  964. /**
  965. * If `Buffer._useTypedArrays`:
  966. * === true Use Uint8Array implementation (fastest)
  967. * === false Use Object implementation (compatible down to IE6)
  968. */
  969. Buffer._useTypedArrays = (function () {
  970. // Detect if browser supports Typed Arrays. Supported browsers are IE 10+, Firefox 4+,
  971. // Chrome 7+, Safari 5.1+, Opera 11.6+, iOS 4.2+. If the browser does not support adding
  972. // properties to `Uint8Array` instances, then that's the same as no `Uint8Array` support
  973. // because we need to be able to add all the node Buffer API methods. This is an issue
  974. // in Firefox 4-29. Now fixed: https://bugzilla.mozilla.org/show_bug.cgi?id=695438
  975. try {
  976. var buf = new ArrayBuffer(0)
  977. var arr = new Uint8Array(buf)
  978. arr.foo = function () { return 42 }
  979. return 42 === arr.foo() &&
  980. typeof arr.subarray === 'function' // Chrome 9-10 lack `subarray`
  981. } catch (e) {
  982. return false
  983. }
  984. })()
  985. /**
  986. * Class: Buffer
  987. * =============
  988. *
  989. * The Buffer constructor returns instances of `Uint8Array` that are augmented
  990. * with function properties for all the node `Buffer` API functions. We use
  991. * `Uint8Array` so that square bracket notation works as expected -- it returns
  992. * a single octet.
  993. *
  994. * By augmenting the instances, we can avoid modifying the `Uint8Array`
  995. * prototype.
  996. */
  997. function Buffer (subject, encoding, noZero) {
  998. if (!(this instanceof Buffer))
  999. return new Buffer(subject, encoding, noZero)
  1000. var type = typeof subject
  1001. // Workaround: node's base64 implementation allows for non-padded strings
  1002. // while base64-js does not.
  1003. if (encoding === 'base64' && type === 'string') {
  1004. subject = stringtrim(subject)
  1005. while (subject.length % 4 !== 0) {
  1006. subject = subject + '='
  1007. }
  1008. }
  1009. // Find the length
  1010. var length
  1011. if (type === 'number')
  1012. length = coerce(subject)
  1013. else if (type === 'string')
  1014. length = Buffer.byteLength(subject, encoding)
  1015. else if (type === 'object')
  1016. length = coerce(subject.length) // assume that object is array-like
  1017. else
  1018. throw new Error('First argument needs to be a number, array or string.')
  1019. var buf
  1020. if (Buffer._useTypedArrays) {
  1021. // Preferred: Return an augmented `Uint8Array` instance for best performance
  1022. buf = Buffer._augment(new Uint8Array(length))
  1023. } else {
  1024. // Fallback: Return THIS instance of Buffer (created by `new`)
  1025. buf = this
  1026. buf.length = length
  1027. buf._isBuffer = true
  1028. }
  1029. var i
  1030. if (Buffer._useTypedArrays && typeof subject.byteLength === 'number') {
  1031. // Speed optimization -- use set if we're copying from a typed array
  1032. buf._set(subject)
  1033. } else if (isArrayish(subject)) {
  1034. // Treat array-ish objects as a byte array
  1035. for (i = 0; i < length; i++) {
  1036. if (Buffer.isBuffer(subject))
  1037. buf[i] = subject.readUInt8(i)
  1038. else
  1039. buf[i] = subject[i]
  1040. }
  1041. } else if (type === 'string') {
  1042. buf.write(subject, 0, encoding)
  1043. } else if (type === 'number' && !Buffer._useTypedArrays && !noZero) {
  1044. for (i = 0; i < length; i++) {
  1045. buf[i] = 0
  1046. }
  1047. }
  1048. return buf
  1049. }
  1050. // STATIC METHODS
  1051. // ==============
  1052. Buffer.isEncoding = function (encoding) {
  1053. switch (String(encoding).toLowerCase()) {
  1054. case 'hex':
  1055. case 'utf8':
  1056. case 'utf-8':
  1057. case 'ascii':
  1058. case 'binary':
  1059. case 'base64':
  1060. case 'raw':
  1061. case 'ucs2':
  1062. case 'ucs-2':
  1063. case 'utf16le':
  1064. case 'utf-16le':
  1065. return true
  1066. default:
  1067. return false
  1068. }
  1069. }
  1070. Buffer.isBuffer = function (b) {
  1071. return !!(b !== null && b !== undefined && b._isBuffer)
  1072. }
  1073. Buffer.byteLength = function (str, encoding) {
  1074. var ret
  1075. str = str + ''
  1076. switch (encoding || 'utf8') {
  1077. case 'hex':
  1078. ret = str.length / 2
  1079. break
  1080. case 'utf8':
  1081. case 'utf-8':
  1082. ret = utf8ToBytes(str).length
  1083. break
  1084. case 'ascii':
  1085. case 'binary':
  1086. case 'raw':
  1087. ret = str.length
  1088. break
  1089. case 'base64':
  1090. ret = base64ToBytes(str).length
  1091. break
  1092. case 'ucs2':
  1093. case 'ucs-2':
  1094. case 'utf16le':
  1095. case 'utf-16le':
  1096. ret = str.length * 2
  1097. break
  1098. default:
  1099. throw new Error('Unknown encoding')
  1100. }
  1101. return ret
  1102. }
  1103. Buffer.concat = function (list, totalLength) {
  1104. assert(isArray(list), 'Usage: Buffer.concat(list, [totalLength])\n' +
  1105. 'list should be an Array.')
  1106. if (list.length === 0) {
  1107. return new Buffer(0)
  1108. } else if (list.length === 1) {
  1109. return list[0]
  1110. }
  1111. var i
  1112. if (typeof totalLength !== 'number') {
  1113. totalLength = 0
  1114. for (i = 0; i < list.length; i++) {
  1115. totalLength += list[i].length
  1116. }
  1117. }
  1118. var buf = new Buffer(totalLength)
  1119. var pos = 0
  1120. for (i = 0; i < list.length; i++) {
  1121. var item = list[i]
  1122. item.copy(buf, pos)
  1123. pos += item.length
  1124. }
  1125. return buf
  1126. }
  1127. // BUFFER INSTANCE METHODS
  1128. // =======================
  1129. function _hexWrite (buf, string, offset, length) {
  1130. offset = Number(offset) || 0
  1131. var remaining = buf.length - offset
  1132. if (!length) {
  1133. length = remaining
  1134. } else {
  1135. length = Number(length)
  1136. if (length > remaining) {
  1137. length = remaining
  1138. }
  1139. }
  1140. // must be an even number of digits
  1141. var strLen = string.length
  1142. assert(strLen % 2 === 0, 'Invalid hex string')
  1143. if (length > strLen / 2) {
  1144. length = strLen / 2
  1145. }
  1146. for (var i = 0; i < length; i++) {
  1147. var byte = parseInt(string.substr(i * 2, 2), 16)
  1148. assert(!isNaN(byte), 'Invalid hex string')
  1149. buf[offset + i] = byte
  1150. }
  1151. Buffer._charsWritten = i * 2
  1152. return i
  1153. }
  1154. function _utf8Write (buf, string, offset, length) {
  1155. var charsWritten = Buffer._charsWritten =
  1156. blitBuffer(utf8ToBytes(string), buf, offset, length)
  1157. return charsWritten
  1158. }
  1159. function _asciiWrite (buf, string, offset, length) {
  1160. var charsWritten = Buffer._charsWritten =
  1161. blitBuffer(asciiToBytes(string), buf, offset, length)
  1162. return charsWritten
  1163. }
  1164. function _binaryWrite (buf, string, offset, length) {
  1165. return _asciiWrite(buf, string, offset, length)
  1166. }
  1167. function _base64Write (buf, string, offset, length) {
  1168. var charsWritten = Buffer._charsWritten =
  1169. blitBuffer(base64ToBytes(string), buf, offset, length)
  1170. return charsWritten
  1171. }
  1172. function _utf16leWrite (buf, string, offset, length) {
  1173. var charsWritten = Buffer._charsWritten =
  1174. blitBuffer(utf16leToBytes(string), buf, offset, length)
  1175. return charsWritten
  1176. }
  1177. Buffer.prototype.write = function (string, offset, length, encoding) {
  1178. // Support both (string, offset, length, encoding)
  1179. // and the legacy (string, encoding, offset, length)
  1180. if (isFinite(offset)) {
  1181. if (!isFinite(length)) {
  1182. encoding = length
  1183. length = undefined
  1184. }
  1185. } else { // legacy
  1186. var swap = encoding
  1187. encoding = offset
  1188. offset = length
  1189. length = swap
  1190. }
  1191. offset = Number(offset) || 0
  1192. var remaining = this.length - offset
  1193. if (!length) {
  1194. length = remaining
  1195. } else {
  1196. length = Number(length)
  1197. if (length > remaining) {
  1198. length = remaining
  1199. }
  1200. }
  1201. encoding = String(encoding || 'utf8').toLowerCase()
  1202. var ret
  1203. switch (encoding) {
  1204. case 'hex':
  1205. ret = _hexWrite(this, string, offset, length)
  1206. break
  1207. case 'utf8':
  1208. case 'utf-8':
  1209. ret = _utf8Write(this, string, offset, length)
  1210. break
  1211. case 'ascii':
  1212. ret = _asciiWrite(this, string, offset, length)
  1213. break
  1214. case 'binary':
  1215. ret = _binaryWrite(this, string, offset, length)
  1216. break
  1217. case 'base64':
  1218. ret = _base64Write(this, string, offset, length)
  1219. break
  1220. case 'ucs2':
  1221. case 'ucs-2':
  1222. case 'utf16le':
  1223. case 'utf-16le':
  1224. ret = _utf16leWrite(this, string, offset, length)
  1225. break
  1226. default:
  1227. throw new Error('Unknown encoding')
  1228. }
  1229. return ret
  1230. }
  1231. Buffer.prototype.toString = function (encoding, start, end) {
  1232. var self = this
  1233. encoding = String(encoding || 'utf8').toLowerCase()
  1234. start = Number(start) || 0
  1235. end = (end !== undefined)
  1236. ? Number(end)
  1237. : end = self.length
  1238. // Fastpath empty strings
  1239. if (end === start)
  1240. return ''
  1241. var ret
  1242. switch (encoding) {
  1243. case 'hex':
  1244. ret = _hexSlice(self, start, end)
  1245. break
  1246. case 'utf8':
  1247. case 'utf-8':
  1248. ret = _utf8Slice(self, start, end)
  1249. break
  1250. case 'ascii':
  1251. ret = _asciiSlice(self, start, end)
  1252. break
  1253. case 'binary':
  1254. ret = _binarySlice(self, start, end)
  1255. break
  1256. case 'base64':
  1257. ret = _base64Slice(self, start, end)
  1258. break
  1259. case 'ucs2':
  1260. case 'ucs-2':
  1261. case 'utf16le':
  1262. case 'utf-16le':
  1263. ret = _utf16leSlice(self, start, end)
  1264. break
  1265. default:
  1266. throw new Error('Unknown encoding')
  1267. }
  1268. return ret
  1269. }
  1270. Buffer.prototype.toJSON = function () {
  1271. return {
  1272. type: 'Buffer',
  1273. data: Array.prototype.slice.call(this._arr || this, 0)
  1274. }
  1275. }
  1276. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  1277. Buffer.prototype.copy = function (target, target_start, start, end) {
  1278. var source = this
  1279. if (!start) start = 0
  1280. if (!end && end !== 0) end = this.length
  1281. if (!target_start) target_start = 0
  1282. // Copy 0 bytes; we're done
  1283. if (end === start) return
  1284. if (target.length === 0 || source.length === 0) return
  1285. // Fatal error conditions
  1286. assert(end >= start, 'sourceEnd < sourceStart')
  1287. assert(target_start >= 0 && target_start < target.length,
  1288. 'targetStart out of bounds')
  1289. assert(start >= 0 && start < source.length, 'sourceStart out of bounds')
  1290. assert(end >= 0 && end <= source.length, 'sourceEnd out of bounds')
  1291. // Are we oob?
  1292. if (end > this.length)
  1293. end = this.length
  1294. if (target.length - target_start < end - start)
  1295. end = target.length - target_start + start
  1296. var len = end - start
  1297. if (len < 100 || !Buffer._useTypedArrays) {
  1298. for (var i = 0; i < len; i++)
  1299. target[i + target_start] = this[i + start]
  1300. } else {
  1301. target._set(this.subarray(start, start + len), target_start)
  1302. }
  1303. }
  1304. function _base64Slice (buf, start, end) {
  1305. if (start === 0 && end === buf.length) {
  1306. return base64.fromByteArray(buf)
  1307. } else {
  1308. return base64.fromByteArray(buf.slice(start, end))
  1309. }
  1310. }
  1311. function _utf8Slice (buf, start, end) {
  1312. var res = ''
  1313. var tmp = ''
  1314. end = Math.min(buf.length, end)
  1315. for (var i = start; i < end; i++) {
  1316. if (buf[i] <= 0x7F) {
  1317. res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])
  1318. tmp = ''
  1319. } else {
  1320. tmp += '%' + buf[i].toString(16)
  1321. }
  1322. }
  1323. return res + decodeUtf8Char(tmp)
  1324. }
  1325. function _asciiSlice (buf, start, end) {
  1326. var ret = ''
  1327. end = Math.min(buf.length, end)
  1328. for (var i = start; i < end; i++)
  1329. ret += String.fromCharCode(buf[i])
  1330. return ret
  1331. }
  1332. function _binarySlice (buf, start, end) {
  1333. return _asciiSlice(buf, start, end)
  1334. }
  1335. function _hexSlice (buf, start, end) {
  1336. var len = buf.length
  1337. if (!start || start < 0) start = 0
  1338. if (!end || end < 0 || end > len) end = len
  1339. var out = ''
  1340. for (var i = start; i < end; i++) {
  1341. out += toHex(buf[i])
  1342. }
  1343. return out
  1344. }
  1345. function _utf16leSlice (buf, start, end) {
  1346. var bytes = buf.slice(start, end)
  1347. var res = ''
  1348. for (var i = 0; i < bytes.length; i += 2) {
  1349. res += String.fromCharCode(bytes[i] + bytes[i+1] * 256)
  1350. }
  1351. return res
  1352. }
  1353. Buffer.prototype.slice = function (start, end) {
  1354. var len = this.length
  1355. start = clamp(start, len, 0)
  1356. end = clamp(end, len, len)
  1357. if (Buffer._useTypedArrays) {
  1358. return Buffer._augment(this.subarray(start, end))
  1359. } else {
  1360. var sliceLen = end - start
  1361. var newBuf = new Buffer(sliceLen, undefined, true)
  1362. for (var i = 0; i < sliceLen; i++) {
  1363. newBuf[i] = this[i + start]
  1364. }
  1365. return newBuf
  1366. }
  1367. }
  1368. // `get` will be removed in Node 0.13+
  1369. Buffer.prototype.get = function (offset) {
  1370. console.log('.get() is deprecated. Access using array indexes instead.')
  1371. return this.readUInt8(offset)
  1372. }
  1373. // `set` will be removed in Node 0.13+
  1374. Buffer.prototype.set = function (v, offset) {
  1375. console.log('.set() is deprecated. Access using array indexes instead.')
  1376. return this.writeUInt8(v, offset)
  1377. }
  1378. Buffer.prototype.readUInt8 = function (offset, noAssert) {
  1379. if (!noAssert) {
  1380. assert(offset !== undefined && offset !== null, 'missing offset')
  1381. assert(offset < this.length, 'Trying to read beyond buffer length')
  1382. }
  1383. if (offset >= this.length)
  1384. return
  1385. return this[offset]
  1386. }
  1387. function _readUInt16 (buf, offset, littleEndian, noAssert) {
  1388. if (!noAssert) {
  1389. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  1390. assert(offset !== undefined && offset !== null, 'missing offset')
  1391. assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
  1392. }
  1393. var len = buf.length
  1394. if (offset >= len)
  1395. return
  1396. var val
  1397. if (littleEndian) {
  1398. val = buf[offset]
  1399. if (offset + 1 < len)
  1400. val |= buf[offset + 1] << 8
  1401. } else {
  1402. val = buf[offset] << 8
  1403. if (offset + 1 < len)
  1404. val |= buf[offset + 1]
  1405. }
  1406. return val
  1407. }
  1408. Buffer.prototype.readUInt16LE = function (offset, noAssert) {
  1409. return _readUInt16(this, offset, true, noAssert)
  1410. }
  1411. Buffer.prototype.readUInt16BE = function (offset, noAssert) {
  1412. return _readUInt16(this, offset, false, noAssert)
  1413. }
  1414. function _readUInt32 (buf, offset, littleEndian, noAssert) {
  1415. if (!noAssert) {
  1416. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  1417. assert(offset !== undefined && offset !== null, 'missing offset')
  1418. assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
  1419. }
  1420. var len = buf.length
  1421. if (offset >= len)
  1422. return
  1423. var val
  1424. if (littleEndian) {
  1425. if (offset + 2 < len)
  1426. val = buf[offset + 2] << 16
  1427. if (offset + 1 < len)
  1428. val |= buf[offset + 1] << 8
  1429. val |= buf[offset]
  1430. if (offset + 3 < len)
  1431. val = val + (buf[offset + 3] << 24 >>> 0)
  1432. } else {
  1433. if (offset + 1 < len)
  1434. val = buf[offset + 1] << 16
  1435. if (offset + 2 < len)
  1436. val |= buf[offset + 2] << 8
  1437. if (offset + 3 < len)
  1438. val |= buf[offset + 3]
  1439. val = val + (buf[offset] << 24 >>> 0)
  1440. }
  1441. return val
  1442. }
  1443. Buffer.prototype.readUInt32LE = function (offset, noAssert) {
  1444. return _readUInt32(this, offset, true, noAssert)
  1445. }
  1446. Buffer.prototype.readUInt32BE = function (offset, noAssert) {
  1447. return _readUInt32(this, offset, false, noAssert)
  1448. }
  1449. Buffer.prototype.readInt8 = function (offset, noAssert) {
  1450. if (!noAssert) {
  1451. assert(offset !== undefined && offset !== null,
  1452. 'missing offset')
  1453. assert(offset < this.length, 'Trying to read beyond buffer length')
  1454. }
  1455. if (offset >= this.length)
  1456. return
  1457. var neg = this[offset] & 0x80
  1458. if (neg)
  1459. return (0xff - this[offset] + 1) * -1
  1460. else
  1461. return this[offset]
  1462. }
  1463. function _readInt16 (buf, offset, littleEndian, noAssert) {
  1464. if (!noAssert) {
  1465. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  1466. assert(offset !== undefined && offset !== null, 'missing offset')
  1467. assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
  1468. }
  1469. var len = buf.length
  1470. if (offset >= len)
  1471. return
  1472. var val = _readUInt16(buf, offset, littleEndian, true)
  1473. var neg = val & 0x8000
  1474. if (neg)
  1475. return (0xffff - val + 1) * -1
  1476. else
  1477. return val
  1478. }
  1479. Buffer.prototype.readInt16LE = function (offset, noAssert) {
  1480. return _readInt16(this, offset, true, noAssert)
  1481. }
  1482. Buffer.prototype.readInt16BE = function (offset, noAssert) {
  1483. return _readInt16(this, offset, false, noAssert)
  1484. }
  1485. function _readInt32 (buf, offset, littleEndian, noAssert) {
  1486. if (!noAssert) {
  1487. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  1488. assert(offset !== undefined && offset !== null, 'missing offset')
  1489. assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
  1490. }
  1491. var len = buf.length
  1492. if (offset >= len)
  1493. return
  1494. var val = _readUInt32(buf, offset, littleEndian, true)
  1495. var neg = val & 0x80000000
  1496. if (neg)
  1497. return (0xffffffff - val + 1) * -1
  1498. else
  1499. return val
  1500. }
  1501. Buffer.prototype.readInt32LE = function (offset, noAssert) {
  1502. return _readInt32(this, offset, true, noAssert)
  1503. }
  1504. Buffer.prototype.readInt32BE = function (offset, noAssert) {
  1505. return _readInt32(this, offset, false, noAssert)
  1506. }
  1507. function _readFloat (buf, offset, littleEndian, noAssert) {
  1508. if (!noAssert) {
  1509. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  1510. assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
  1511. }
  1512. return ieee754.read(buf, offset, littleEndian, 23, 4)
  1513. }
  1514. Buffer.prototype.readFloatLE = function (offset, noAssert) {
  1515. return _readFloat(this, offset, true, noAssert)
  1516. }
  1517. Buffer.prototype.readFloatBE = function (offset, noAssert) {
  1518. return _readFloat(this, offset, false, noAssert)
  1519. }
  1520. function _readDouble (buf, offset, littleEndian, noAssert) {
  1521. if (!noAssert) {
  1522. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  1523. assert(offset + 7 < buf.length, 'Trying to read beyond buffer length')
  1524. }
  1525. return ieee754.read(buf, offset, littleEndian, 52, 8)
  1526. }
  1527. Buffer.prototype.readDoubleLE = function (offset, noAssert) {
  1528. return _readDouble(this, offset, true, noAssert)
  1529. }
  1530. Buffer.prototype.readDoubleBE = function (offset, noAssert) {
  1531. return _readDouble(this, offset, false, noAssert)
  1532. }
  1533. Buffer.prototype.writeUInt8 = function (value, offset, noAssert) {
  1534. if (!noAssert) {
  1535. assert(value !== undefined && value !== null, 'missing value')
  1536. assert(offset !== undefined && offset !== null, 'missing offset')
  1537. assert(offset < this.length, 'trying to write beyond buffer length')
  1538. verifuint(value, 0xff)
  1539. }
  1540. if (offset >= this.length) return
  1541. this[offset] = value
  1542. }
  1543. function _writeUInt16 (buf, value, offset, littleEndian, noAssert) {
  1544. if (!noAssert) {
  1545. assert(value !== undefined && value !== null, 'missing value')
  1546. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  1547. assert(offset !== undefined && offset !== null, 'missing offset')
  1548. assert(offset + 1 < buf.length, 'trying to write beyond buffer length')
  1549. verifuint(value, 0xffff)
  1550. }
  1551. var len = buf.length
  1552. if (offset >= len)
  1553. return
  1554. for (var i = 0, j = Math.min(len - offset, 2); i < j; i++) {
  1555. buf[offset + i] =
  1556. (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  1557. (littleEndian ? i : 1 - i) * 8
  1558. }
  1559. }
  1560. Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) {
  1561. _writeUInt16(this, value, offset, true, noAssert)
  1562. }
  1563. Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) {
  1564. _writeUInt16(this, value, offset, false, noAssert)
  1565. }
  1566. function _writeUInt32 (buf, value, offset, littleEndian, noAssert) {
  1567. if (!noAssert) {
  1568. assert(value !== undefined && value !== null, 'missing value')
  1569. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  1570. assert(offset !== undefined && offset !== null, 'missing offset')
  1571. assert(offset + 3 < buf.length, 'trying to write beyond buffer length')
  1572. verifuint(value, 0xffffffff)
  1573. }
  1574. var len = buf.length
  1575. if (offset >= len)
  1576. return
  1577. for (var i = 0, j = Math.min(len - offset, 4); i < j; i++) {
  1578. buf[offset + i] =
  1579. (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  1580. }
  1581. }
  1582. Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) {
  1583. _writeUInt32(this, value, offset, true, noAssert)
  1584. }
  1585. Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) {
  1586. _writeUInt32(this, value, offset, false, noAssert)
  1587. }
  1588. Buffer.prototype.writeInt8 = function (value, offset, noAssert) {
  1589. if (!noAssert) {
  1590. assert(value !== undefined && value !== null, 'missing value')
  1591. assert(offset !== undefined && offset !== null, 'missing offset')
  1592. assert(offset < this.length, 'Trying to write beyond buffer length')
  1593. verifsint(value, 0x7f, -0x80)
  1594. }
  1595. if (offset >= this.length)
  1596. return
  1597. if (value >= 0)
  1598. this.writeUInt8(value, offset, noAssert)
  1599. else
  1600. this.writeUInt8(0xff + value + 1, offset, noAssert)
  1601. }
  1602. function _writeInt16 (buf, value, offset, littleEndian, noAssert) {
  1603. if (!noAssert) {
  1604. assert(value !== undefined && value !== null, 'missing value')
  1605. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  1606. assert(offset !== undefined && offset !== null, 'missing offset')
  1607. assert(offset + 1 < buf.length, 'Trying to write beyond buffer length')
  1608. verifsint(value, 0x7fff, -0x8000)
  1609. }
  1610. var len = buf.length
  1611. if (offset >= len)
  1612. return
  1613. if (value >= 0)
  1614. _writeUInt16(buf, value, offset, littleEndian, noAssert)
  1615. else
  1616. _writeUInt16(buf, 0xffff + value + 1, offset, littleEndian, noAssert)
  1617. }
  1618. Buffer.prototype.writeInt16LE = function (value, offset, noAssert) {
  1619. _writeInt16(this, value, offset, true, noAssert)
  1620. }
  1621. Buffer.prototype.writeInt16BE = function (value, offset, noAssert) {
  1622. _writeInt16(this, value, offset, false, noAssert)
  1623. }
  1624. function _writeInt32 (buf, value, offset, littleEndian, noAssert) {
  1625. if (!noAssert) {
  1626. assert(value !== undefined && value !== null, 'missing value')
  1627. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  1628. assert(offset !== undefined && offset !== null, 'missing offset')
  1629. assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
  1630. verifsint(value, 0x7fffffff, -0x80000000)
  1631. }
  1632. var len = buf.length
  1633. if (offset >= len)
  1634. return
  1635. if (value >= 0)
  1636. _writeUInt32(buf, value, offset, littleEndian, noAssert)
  1637. else
  1638. _writeUInt32(buf, 0xffffffff + value + 1, offset, littleEndian, noAssert)
  1639. }
  1640. Buffer.prototype.writeInt32LE = function (value, offset, noAssert) {
  1641. _writeInt32(this, value, offset, true, noAssert)
  1642. }
  1643. Buffer.prototype.writeInt32BE = function (value, offset, noAssert) {
  1644. _writeInt32(this, value, offset, false, noAssert)
  1645. }
  1646. function _writeFloat (buf, value, offset, littleEndian, noAssert) {
  1647. if (!noAssert) {
  1648. assert(value !== undefined && value !== null, 'missing value')
  1649. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  1650. assert(offset !== undefined && offset !== null, 'missing offset')
  1651. assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
  1652. verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38)
  1653. }
  1654. var len = buf.length
  1655. if (offset >= len)
  1656. return
  1657. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  1658. }
  1659. Buffer.prototype.writeFloatLE = function (value, offset, noAssert) {
  1660. _writeFloat(this, value, offset, true, noAssert)
  1661. }
  1662. Buffer.prototype.writeFloatBE = function (value, offset, noAssert) {
  1663. _writeFloat(this, value, offset, false, noAssert)
  1664. }
  1665. function _writeDouble (buf, value, offset, littleEndian, noAssert) {
  1666. if (!noAssert) {
  1667. assert(value !== undefined && value !== null, 'missing value')
  1668. assert(typeof littleEndian === 'boolean', 'missing or invalid endian')
  1669. assert(offset !== undefined && offset !== null, 'missing offset')
  1670. assert(offset + 7 < buf.length,
  1671. 'Trying to write beyond buffer length')
  1672. verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308)
  1673. }
  1674. var len = buf.length
  1675. if (offset >= len)
  1676. return
  1677. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  1678. }
  1679. Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) {
  1680. _writeDouble(this, value, offset, true, noAssert)
  1681. }
  1682. Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) {
  1683. _writeDouble(this, value, offset, false, noAssert)
  1684. }
  1685. // fill(value, start=0, end=buffer.length)
  1686. Buffer.prototype.fill = function (value, start, end) {
  1687. if (!value) value = 0
  1688. if (!start) start = 0
  1689. if (!end) end = this.length
  1690. if (typeof value === 'string') {
  1691. value = value.charCodeAt(0)
  1692. }
  1693. assert(typeof value === 'number' && !isNaN(value), 'value is not a number')
  1694. assert(end >= start, 'end < start')
  1695. // Fill 0 bytes; we're done
  1696. if (end === start) return
  1697. if (this.length === 0) return
  1698. assert(start >= 0 && start < this.length, 'start out of bounds')
  1699. assert(end >= 0 && end <= this.length, 'end out of bounds')
  1700. for (var i = start; i < end; i++) {
  1701. this[i] = value
  1702. }
  1703. }
  1704. Buffer.prototype.inspect = function () {
  1705. var out = []
  1706. var len = this.length
  1707. for (var i = 0; i < len; i++) {
  1708. out[i] = toHex(this[i])
  1709. if (i === exports.INSPECT_MAX_BYTES) {
  1710. out[i + 1] = '...'
  1711. break
  1712. }
  1713. }
  1714. return '<Buffer ' + out.join(' ') + '>'
  1715. }
  1716. /**
  1717. * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
  1718. * Added in Node 0.12. Only available in browsers that support ArrayBuffer.
  1719. */
  1720. Buffer.prototype.toArrayBuffer = function () {
  1721. if (typeof Uint8Array !== 'undefined') {
  1722. if (Buffer._useTypedArrays) {
  1723. return (new Buffer(this)).buffer
  1724. } else {
  1725. var buf = new Uint8Array(this.length)
  1726. for (var i = 0, len = buf.length; i < len; i += 1)
  1727. buf[i] = this[i]
  1728. return buf.buffer
  1729. }
  1730. } else {
  1731. throw new Error('Buffer.toArrayBuffer not supported in this browser')
  1732. }
  1733. }
  1734. // HELPER FUNCTIONS
  1735. // ================
  1736. function stringtrim (str) {
  1737. if (str.trim) return str.trim()
  1738. return str.replace(/^\s+|\s+$/g, '')
  1739. }
  1740. var BP = Buffer.prototype
  1741. /**
  1742. * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods
  1743. */
  1744. Buffer._augment = function (arr) {
  1745. arr._isBuffer = true
  1746. // save reference to original Uint8Array get/set methods before overwriting
  1747. arr._get = arr.get
  1748. arr._set = arr.set
  1749. // deprecated, will be removed in node 0.13+
  1750. arr.get = BP.get
  1751. arr.set = BP.set
  1752. arr.write = BP.write
  1753. arr.toString = BP.toString
  1754. arr.toLocaleString = BP.toString
  1755. arr.toJSON = BP.toJSON
  1756. arr.copy = BP.copy
  1757. arr.slice = BP.slice
  1758. arr.readUInt8 = BP.readUInt8
  1759. arr.readUInt16LE = BP.readUInt16LE
  1760. arr.readUInt16BE = BP.readUInt16BE
  1761. arr.readUInt32LE = BP.readUInt32LE
  1762. arr.readUInt32BE = BP.readUInt32BE
  1763. arr.readInt8 = BP.readInt8
  1764. arr.readInt16LE = BP.readInt16LE
  1765. arr.readInt16BE = BP.readInt16BE
  1766. arr.readInt32LE = BP.readInt32LE
  1767. arr.readInt32BE = BP.readInt32BE
  1768. arr.readFloatLE = BP.readFloatLE
  1769. arr.readFloatBE = BP.readFloatBE
  1770. arr.readDoubleLE = BP.readDoubleLE
  1771. arr.readDoubleBE = BP.readDoubleBE
  1772. arr.writeUInt8 = BP.writeUInt8
  1773. arr.writeUInt16LE = BP.writeUInt16LE
  1774. arr.writeUInt16BE = BP.writeUInt16BE
  1775. arr.writeUInt32LE = BP.writeUInt32LE
  1776. arr.writeUInt32BE = BP.writeUInt32BE
  1777. arr.writeInt8 = BP.writeInt8
  1778. arr.writeInt16LE = BP.writeInt16LE
  1779. arr.writeInt16BE = BP.writeInt16BE
  1780. arr.writeInt32LE = BP.writeInt32LE
  1781. arr.writeInt32BE = BP.writeInt32BE
  1782. arr.writeFloatLE = BP.writeFloatLE
  1783. arr.writeFloatBE = BP.writeFloatBE
  1784. arr.writeDoubleLE = BP.writeDoubleLE
  1785. arr.writeDoubleBE = BP.writeDoubleBE
  1786. arr.fill = BP.fill
  1787. arr.inspect = BP.inspect
  1788. arr.toArrayBuffer = BP.toArrayBuffer
  1789. return arr
  1790. }
  1791. // slice(start, end)
  1792. function clamp (index, len, defaultValue) {
  1793. if (typeof index !== 'number') return defaultValue
  1794. index = ~~index; // Coerce to integer.
  1795. if (index >= len) return len
  1796. if (index >= 0) return index
  1797. index += len
  1798. if (index >= 0) return index
  1799. return 0
  1800. }
  1801. function coerce (length) {
  1802. // Coerce length to a number (possibly NaN), round up
  1803. // in case it's fractional (e.g. 123.456) then do a
  1804. // double negate to coerce a NaN to 0. Easy, right?
  1805. length = ~~Math.ceil(+length)
  1806. return length < 0 ? 0 : length
  1807. }
  1808. function isArray (subject) {
  1809. return (Array.isArray || function (subject) {
  1810. return Object.prototype.toString.call(subject) === '[object Array]'
  1811. })(subject)
  1812. }
  1813. function isArrayish (subject) {
  1814. return isArray(subject) || Buffer.isBuffer(subject) ||
  1815. subject && typeof subject === 'object' &&
  1816. typeof subject.length === 'number'
  1817. }
  1818. function toHex (n) {
  1819. if (n < 16) return '0' + n.toString(16)
  1820. return n.toString(16)
  1821. }
  1822. function utf8ToBytes (str) {
  1823. var byteArray = []
  1824. for (var i = 0; i < str.length; i++) {
  1825. var b = str.charCodeAt(i)
  1826. if (b <= 0x7F)
  1827. byteArray.push(str.charCodeAt(i))
  1828. else {
  1829. var start = i
  1830. if (b >= 0xD800 && b <= 0xDFFF) i++
  1831. var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%')
  1832. for (var j = 0; j < h.length; j++)
  1833. byteArray.push(parseInt(h[j], 16))
  1834. }
  1835. }
  1836. return byteArray
  1837. }
  1838. function asciiToBytes (str) {
  1839. var byteArray = []
  1840. for (var i = 0; i < str.length; i++) {
  1841. // Node's code seems to be doing this and not & 0x7F..
  1842. byteArray.push(str.charCodeAt(i) & 0xFF)
  1843. }
  1844. return byteArray
  1845. }
  1846. function utf16leToBytes (str) {
  1847. var c, hi, lo
  1848. var byteArray = []
  1849. for (var i = 0; i < str.length; i++) {
  1850. c = str.charCodeAt(i)
  1851. hi = c >> 8
  1852. lo = c % 256
  1853. byteArray.push(lo)
  1854. byteArray.push(hi)
  1855. }
  1856. return byteArray
  1857. }
  1858. function base64ToBytes (str) {
  1859. return base64.toByteArray(str)
  1860. }
  1861. function blitBuffer (src, dst, offset, length) {
  1862. var pos
  1863. for (var i = 0; i < length; i++) {
  1864. if ((i + offset >= dst.length) || (i >= src.length))
  1865. break
  1866. dst[i + offset] = src[i]
  1867. }
  1868. return i
  1869. }
  1870. function decodeUtf8Char (str) {
  1871. try {
  1872. return decodeURIComponent(str)
  1873. } catch (err) {
  1874. return String.fromCharCode(0xFFFD) // UTF 8 invalid char
  1875. }
  1876. }
  1877. /*
  1878. * We have to make sure that the value is a valid integer. This means that it
  1879. * is non-negative. It has no fractional component and that it does not
  1880. * exceed the maximum allowed value.
  1881. */
  1882. function verifuint (value, max) {
  1883. assert(typeof value === 'number', 'cannot write a non-number as a number')
  1884. assert(value >= 0, 'specified a negative value for writing an unsigned value')
  1885. assert(value <= max, 'value is larger than maximum value for type')
  1886. assert(Math.floor(value) === value, 'value has a fractional component')
  1887. }
  1888. function verifsint (value, max, min) {
  1889. assert(typeof value === 'number', 'cannot write a non-number as a number')
  1890. assert(value <= max, 'value larger than maximum allowed value')
  1891. assert(value >= min, 'value smaller than minimum allowed value')
  1892. assert(Math.floor(value) === value, 'value has a fractional component')
  1893. }
  1894. function verifIEEE754 (value, max, min) {
  1895. assert(typeof value === 'number', 'cannot write a non-number as a number')
  1896. assert(value <= max, 'value larger than maximum allowed value')
  1897. assert(value >= min, 'value smaller than minimum allowed value')
  1898. }
  1899. function assert (test, message) {
  1900. if (!test) throw new Error(message || 'Failed assertion')
  1901. }
  1902. },{"base64-js":6,"ieee754":18}],8:[function(require,module,exports){
  1903. // Copyright Joyent, Inc. and other Node contributors.
  1904. //
  1905. // Permission is hereby granted, free of charge, to any person obtaining a
  1906. // copy of this software and associated documentation files (the
  1907. // "Software"), to deal in the Software without restriction, including
  1908. // without limitation the rights to use, copy, modify, merge, publish,
  1909. // distribute, sublicense, and/or sell copies of the Software, and to permit
  1910. // persons to whom the Software is furnished to do so, subject to the
  1911. // following conditions:
  1912. //
  1913. // The above copyright notice and this permission notice shall be included
  1914. // in all copies or substantial portions of the Software.
  1915. //
  1916. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  1917. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  1918. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  1919. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  1920. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  1921. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  1922. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  1923. function EventEmitter() {
  1924. this._events = this._events || {};
  1925. this._maxListeners = this._maxListeners || undefined;
  1926. }
  1927. module.exports = EventEmitter;
  1928. // Backwards-compat with node 0.10.x
  1929. EventEmitter.EventEmitter = EventEmitter;
  1930. EventEmitter.prototype._events = undefined;
  1931. EventEmitter.prototype._maxListeners = undefined;
  1932. // By default EventEmitters will print a warning if more than 10 listeners are
  1933. // added to it. This is a useful default which helps finding memory leaks.
  1934. EventEmitter.defaultMaxListeners = 10;
  1935. // Obviously not all Emitters should be limited to 10. This function allows
  1936. // that to be increased. Set to zero for unlimited.
  1937. EventEmitter.prototype.setMaxListeners = function(n) {
  1938. if (!isNumber(n) || n < 0 || isNaN(n))
  1939. throw TypeError('n must be a positive number');
  1940. this._maxListeners = n;
  1941. return this;
  1942. };
  1943. EventEmitter.prototype.emit = function(type) {
  1944. var er, handler, len, args, i, listeners;
  1945. if (!this._events)
  1946. this._events = {};
  1947. // If there is no 'error' event listener then throw.
  1948. if (type === 'error') {
  1949. if (!this._events.error ||
  1950. (isObject(this._events.error) && !this._events.error.length)) {
  1951. er = arguments[1];
  1952. if (er instanceof Error) {
  1953. throw er; // Unhandled 'error' event
  1954. }
  1955. throw TypeError('Uncaught, unspecified "error" event.');
  1956. }
  1957. }
  1958. handler = this._events[type];
  1959. if (isUndefined(handler))
  1960. return false;
  1961. if (isFunction(handler)) {
  1962. switch (arguments.length) {
  1963. // fast cases
  1964. case 1:
  1965. handler.call(this);
  1966. break;
  1967. case 2:
  1968. handler.call(this, arguments[1]);
  1969. break;
  1970. case 3:
  1971. handler.call(this, arguments[1], arguments[2]);
  1972. break;
  1973. // slower
  1974. default:
  1975. len = arguments.length;
  1976. args = new Array(len - 1);
  1977. for (i = 1; i < len; i++)
  1978. args[i - 1] = arguments[i];
  1979. handler.apply(this, args);
  1980. }
  1981. } else if (isObject(handler)) {
  1982. len = arguments.length;
  1983. args = new Array(len - 1);
  1984. for (i = 1; i < len; i++)
  1985. args[i - 1] = arguments[i];
  1986. listeners = handler.slice();
  1987. len = listeners.length;
  1988. for (i = 0; i < len; i++)
  1989. listeners[i].apply(this, args);
  1990. }
  1991. return true;
  1992. };
  1993. EventEmitter.prototype.addListener = function(type, listener) {
  1994. var m;
  1995. if (!isFunction(listener))
  1996. throw TypeError('listener must be a function');
  1997. if (!this._events)
  1998. this._events = {};
  1999. // To avoid recursion in the case that type === "newListener"! Before
  2000. // adding it to the listeners, first emit "newListener".
  2001. if (this._events.newListener)
  2002. this.emit('newListener', type,
  2003. isFunction(listener.listener) ?
  2004. listener.listener : listener);
  2005. if (!this._events[type])
  2006. // Optimize the case of one listener. Don't need the extra array object.
  2007. this._events[type] = listener;
  2008. else if (isObject(this._events[type]))
  2009. // If we've already got an array, just append.
  2010. this._events[type].push(listener);
  2011. else
  2012. // Adding the second element, need to change to array.
  2013. this._events[type] = [this._events[type], listener];
  2014. // Check for listener leak
  2015. if (isObject(this._events[type]) && !this._events[type].warned) {
  2016. var m;
  2017. if (!isUndefined(this._maxListeners)) {
  2018. m = this._maxListeners;
  2019. } else {
  2020. m = EventEmitter.defaultMaxListeners;
  2021. }
  2022. if (m && m > 0 && this._events[type].length > m) {
  2023. this._events[type].warned = true;
  2024. console.error('(node) warning: possible EventEmitter memory ' +
  2025. 'leak detected. %d listeners added. ' +
  2026. 'Use emitter.setMaxListeners() to increase limit.',
  2027. this._events[type].length);
  2028. if (typeof console.trace === 'function') {
  2029. // not supported in IE 10
  2030. console.trace();
  2031. }
  2032. }
  2033. }
  2034. return this;
  2035. };
  2036. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  2037. EventEmitter.prototype.once = function(type, listener) {
  2038. if (!isFunction(listener))
  2039. throw TypeError('listener must be a function');
  2040. var fired = false;
  2041. function g() {
  2042. this.removeListener(type, g);
  2043. if (!fired) {
  2044. fired = true;
  2045. listener.apply(this, arguments);
  2046. }
  2047. }
  2048. g.listener = listener;
  2049. this.on(type, g);
  2050. return this;
  2051. };
  2052. // emits a 'removeListener' event iff the listener was removed
  2053. EventEmitter.prototype.removeListener = function(type, listener) {
  2054. var list, position, length, i;
  2055. if (!isFunction(listener))
  2056. throw TypeError('listener must be a function');
  2057. if (!this._events || !this._events[type])
  2058. return this;
  2059. list = this._events[type];
  2060. length = list.length;
  2061. position = -1;
  2062. if (list === listener ||
  2063. (isFunction(list.listener) && list.listener === listener)) {
  2064. delete this._events[type];
  2065. if (this._events.removeListener)
  2066. this.emit('removeListener', type, listener);
  2067. } else if (isObject(list)) {
  2068. for (i = length; i-- > 0;) {
  2069. if (list[i] === listener ||
  2070. (list[i].listener && list[i].listener === listener)) {
  2071. position = i;
  2072. break;
  2073. }
  2074. }
  2075. if (position < 0)
  2076. return this;
  2077. if (list.length === 1) {
  2078. list.length = 0;
  2079. delete this._events[type];
  2080. } else {
  2081. list.splice(position, 1);
  2082. }
  2083. if (this._events.removeListener)
  2084. this.emit('removeListener', type, listener);
  2085. }
  2086. return this;
  2087. };
  2088. EventEmitter.prototype.removeAllListeners = function(type) {
  2089. var key, listeners;
  2090. if (!this._events)
  2091. return this;
  2092. // not listening for removeListener, no need to emit
  2093. if (!this._events.removeListener) {
  2094. if (arguments.length === 0)
  2095. this._events = {};
  2096. else if (this._events[type])
  2097. delete this._events[type];
  2098. return this;
  2099. }
  2100. // emit removeListener for all listeners on all events
  2101. if (arguments.length === 0) {
  2102. for (key in this._events) {
  2103. if (key === 'removeListener') continue;
  2104. this.removeAllListeners(key);
  2105. }
  2106. this.removeAllListeners('removeListener');
  2107. this._events = {};
  2108. return this;
  2109. }
  2110. listeners = this._events[type];
  2111. if (isFunction(listeners)) {
  2112. this.removeListener(type, listeners);
  2113. } else {
  2114. // LIFO order
  2115. while (listeners.length)
  2116. this.removeListener(type, listeners[listeners.length - 1]);
  2117. }
  2118. delete this._events[type];
  2119. return this;
  2120. };
  2121. EventEmitter.prototype.listeners = function(type) {
  2122. var ret;
  2123. if (!this._events || !this._events[type])
  2124. ret = [];
  2125. else if (isFunction(this._events[type]))
  2126. ret = [this._events[type]];
  2127. else
  2128. ret = this._events[type].slice();
  2129. return ret;
  2130. };
  2131. EventEmitter.listenerCount = function(emitter, type) {
  2132. var ret;
  2133. if (!emitter._events || !emitter._events[type])
  2134. ret = 0;
  2135. else if (isFunction(emitter._events[type]))
  2136. ret = 1;
  2137. else
  2138. ret = emitter._events[type].length;
  2139. return ret;
  2140. };
  2141. function isFunction(arg) {
  2142. return typeof arg === 'function';
  2143. }
  2144. function isNumber(arg) {
  2145. return typeof arg === 'number';
  2146. }
  2147. function isObject(arg) {
  2148. return typeof arg === 'object' && arg !== null;
  2149. }
  2150. function isUndefined(arg) {
  2151. return arg === void 0;
  2152. }
  2153. },{}],9:[function(require,module,exports){
  2154. // shim for using process in browser
  2155. var process = module.exports = {};
  2156. process.nextTick = (function () {
  2157. var canSetImmediate = typeof window !== 'undefined'
  2158. && window.setImmediate;
  2159. var canPost = typeof window !== 'undefined'
  2160. && window.postMessage && window.addEventListener
  2161. ;
  2162. if (canSetImmediate) {
  2163. return function (f) { return window.setImmediate(f) };
  2164. }
  2165. if (canPost) {
  2166. var queue = [];
  2167. window.addEventListener('message', function (ev) {
  2168. var source = ev.source;
  2169. if ((source === window || source === null) && ev.data === 'process-tick') {
  2170. ev.stopPropagation();
  2171. if (queue.length > 0) {
  2172. var fn = queue.shift();
  2173. fn();
  2174. }
  2175. }
  2176. }, true);
  2177. return function nextTick(fn) {
  2178. queue.push(fn);
  2179. window.postMessage('process-tick', '*');
  2180. };
  2181. }
  2182. return function nextTick(fn) {
  2183. setTimeout(fn, 0);
  2184. };
  2185. })();
  2186. process.title = 'browser';
  2187. process.browser = true;
  2188. process.env = {};
  2189. process.argv = [];
  2190. function noop() {}
  2191. process.on = noop;
  2192. process.addListener = noop;
  2193. process.once = noop;
  2194. process.off = noop;
  2195. process.removeListener = noop;
  2196. process.removeAllListeners = noop;
  2197. process.emit = noop;
  2198. process.binding = function (name) {
  2199. throw new Error('process.binding is not supported');
  2200. }
  2201. // TODO(shtylman)
  2202. process.cwd = function () { return '/' };
  2203. process.chdir = function (dir) {
  2204. throw new Error('process.chdir is not supported');
  2205. };
  2206. },{}],10:[function(require,module,exports){
  2207. // Copyright Joyent, Inc. and other Node contributors.
  2208. //
  2209. // Permission is hereby granted, free of charge, to any person obtaining a
  2210. // copy of this software and associated documentation files (the
  2211. // "Software"), to deal in the Software without restriction, including
  2212. // without limitation the rights to use, copy, modify, merge, publish,
  2213. // distribute, sublicense, and/or sell copies of the Software, and to permit
  2214. // persons to whom the Software is furnished to do so, subject to the
  2215. // following conditions:
  2216. //
  2217. // The above copyright notice and this permission notice shall be included
  2218. // in all copies or substantial portions of the Software.
  2219. //
  2220. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2221. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2222. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2223. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2224. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2225. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2226. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  2227. // a duplex stream is just a stream that is both readable and writable.
  2228. // Since JS doesn't have multiple prototypal inheritance, this class
  2229. // prototypally inherits from Readable, and then parasitically from
  2230. // Writable.
  2231. module.exports = Duplex;
  2232. var inherits = require('inherits');
  2233. var setImmediate = require('process/browser.js').nextTick;
  2234. var Readable = require('./readable.js');
  2235. var Writable = require('./writable.js');
  2236. inherits(Duplex, Readable);
  2237. Duplex.prototype.write = Writable.prototype.write;
  2238. Duplex.prototype.end = Writable.prototype.end;
  2239. Duplex.prototype._write = Writable.prototype._write;
  2240. function Duplex(options) {
  2241. if (!(this instanceof Duplex))
  2242. return new Duplex(options);
  2243. Readable.call(this, options);
  2244. Writable.call(this, options);
  2245. if (options && options.readable === false)
  2246. this.readable = false;
  2247. if (options && options.writable === false)
  2248. this.writable = false;
  2249. this.allowHalfOpen = true;
  2250. if (options && options.allowHalfOpen === false)
  2251. this.allowHalfOpen = false;
  2252. this.once('end', onend);
  2253. }
  2254. // the no-half-open enforcer
  2255. function onend() {
  2256. // if we allow half-open state, or if the writable side ended,
  2257. // then we're ok.
  2258. if (this.allowHalfOpen || this._writableState.ended)
  2259. return;
  2260. // no more data can be written.
  2261. // But allow more writes to happen in this tick.
  2262. var self = this;
  2263. setImmediate(function () {
  2264. self.end();
  2265. });
  2266. }
  2267. },{"./readable.js":14,"./writable.js":16,"inherits":19,"process/browser.js":12}],11:[function(require,module,exports){
  2268. // Copyright Joyent, Inc. and other Node contributors.
  2269. //
  2270. // Permission is hereby granted, free of charge, to any person obtaining a
  2271. // copy of this software and associated documentation files (the
  2272. // "Software"), to deal in the Software without restriction, including
  2273. // without limitation the rights to use, copy, modify, merge, publish,
  2274. // distribute, sublicense, and/or sell copies of the Software, and to permit
  2275. // persons to whom the Software is furnished to do so, subject to the
  2276. // following conditions:
  2277. //
  2278. // The above copyright notice and this permission notice shall be included
  2279. // in all copies or substantial portions of the Software.
  2280. //
  2281. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2282. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2283. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2284. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2285. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2286. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2287. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  2288. module.exports = Stream;
  2289. var EE = require('events').EventEmitter;
  2290. var inherits = require('inherits');
  2291. inherits(Stream, EE);
  2292. Stream.Readable = require('./readable.js');
  2293. Stream.Writable = require('./writable.js');
  2294. Stream.Duplex = require('./duplex.js');
  2295. Stream.Transform = require('./transform.js');
  2296. Stream.PassThrough = require('./passthrough.js');
  2297. // Backwards-compat with node 0.4.x
  2298. Stream.Stream = Stream;
  2299. // old-style streams. Note that the pipe method (the only relevant
  2300. // part of this class) is overridden in the Readable class.
  2301. function Stream() {
  2302. EE.call(this);
  2303. }
  2304. Stream.prototype.pipe = function(dest, options) {
  2305. var source = this;
  2306. function ondata(chunk) {
  2307. if (dest.writable) {
  2308. if (false === dest.write(chunk) && source.pause) {
  2309. source.pause();
  2310. }
  2311. }
  2312. }
  2313. source.on('data', ondata);
  2314. function ondrain() {
  2315. if (source.readable && source.resume) {
  2316. source.resume();
  2317. }
  2318. }
  2319. dest.on('drain', ondrain);
  2320. // If the 'end' option is not supplied, dest.end() will be called when
  2321. // source gets the 'end' or 'close' events. Only dest.end() once.
  2322. if (!dest._isStdio && (!options || options.end !== false)) {
  2323. source.on('end', onend);
  2324. source.on('close', onclose);
  2325. }
  2326. var didOnEnd = false;
  2327. function onend() {
  2328. if (didOnEnd) return;
  2329. didOnEnd = true;
  2330. dest.end();
  2331. }
  2332. function onclose() {
  2333. if (didOnEnd) return;
  2334. didOnEnd = true;
  2335. if (typeof dest.destroy === 'function') dest.destroy();
  2336. }
  2337. // don't leave dangling pipes when there are errors.
  2338. function onerror(er) {
  2339. cleanup();
  2340. if (EE.listenerCount(this, 'error') === 0) {
  2341. throw er; // Unhandled stream error in pipe.
  2342. }
  2343. }
  2344. source.on('error', onerror);
  2345. dest.on('error', onerror);
  2346. // remove all the event listeners that were added.
  2347. function cleanup() {
  2348. source.removeListener('data', ondata);
  2349. dest.removeListener('drain', ondrain);
  2350. source.removeListener('end', onend);
  2351. source.removeListener('close', onclose);
  2352. source.removeListener('error', onerror);
  2353. dest.removeListener('error', onerror);
  2354. source.removeListener('end', cleanup);
  2355. source.removeListener('close', cleanup);
  2356. dest.removeListener('close', cleanup);
  2357. }
  2358. source.on('end', cleanup);
  2359. source.on('close', cleanup);
  2360. dest.on('close', cleanup);
  2361. dest.emit('pipe', source);
  2362. // Allow for unix-like usage: A.pipe(B).pipe(C)
  2363. return dest;
  2364. };
  2365. },{"./duplex.js":10,"./passthrough.js":13,"./readable.js":14,"./transform.js":15,"./writable.js":16,"events":8,"inherits":19}],12:[function(require,module,exports){
  2366. // shim for using process in browser
  2367. var process = module.exports = {};
  2368. process.nextTick = (function () {
  2369. var canSetImmediate = typeof window !== 'undefined'
  2370. && window.setImmediate;
  2371. var canPost = typeof window !== 'undefined'
  2372. && window.postMessage && window.addEventListener
  2373. ;
  2374. if (canSetImmediate) {
  2375. return function (f) { return window.setImmediate(f) };
  2376. }
  2377. if (canPost) {
  2378. var queue = [];
  2379. window.addEventListener('message', function (ev) {
  2380. var source = ev.source;
  2381. if ((source === window || source === null) && ev.data === 'process-tick') {
  2382. ev.stopPropagation();
  2383. if (queue.length > 0) {
  2384. var fn = queue.shift();
  2385. fn();
  2386. }
  2387. }
  2388. }, true);
  2389. return function nextTick(fn) {
  2390. queue.push(fn);
  2391. window.postMessage('process-tick', '*');
  2392. };
  2393. }
  2394. return function nextTick(fn) {
  2395. setTimeout(fn, 0);
  2396. };
  2397. })();
  2398. process.title = 'browser';
  2399. process.browser = true;
  2400. process.env = {};
  2401. process.argv = [];
  2402. process.binding = function (name) {
  2403. throw new Error('process.binding is not supported');
  2404. }
  2405. // TODO(shtylman)
  2406. process.cwd = function () { return '/' };
  2407. process.chdir = function (dir) {
  2408. throw new Error('process.chdir is not supported');
  2409. };
  2410. },{}],13:[function(require,module,exports){
  2411. // Copyright Joyent, Inc. and other Node contributors.
  2412. //
  2413. // Permission is hereby granted, free of charge, to any person obtaining a
  2414. // copy of this software and associated documentation files (the
  2415. // "Software"), to deal in the Software without restriction, including
  2416. // without limitation the rights to use, copy, modify, merge, publish,
  2417. // distribute, sublicense, and/or sell copies of the Software, and to permit
  2418. // persons to whom the Software is furnished to do so, subject to the
  2419. // following conditions:
  2420. //
  2421. // The above copyright notice and this permission notice shall be included
  2422. // in all copies or substantial portions of the Software.
  2423. //
  2424. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2425. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2426. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2427. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2428. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2429. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2430. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  2431. // a passthrough stream.
  2432. // basically just the most minimal sort of Transform stream.
  2433. // Every written chunk gets output as-is.
  2434. module.exports = PassThrough;
  2435. var Transform = require('./transform.js');
  2436. var inherits = require('inherits');
  2437. inherits(PassThrough, Transform);
  2438. function PassThrough(options) {
  2439. if (!(this instanceof PassThrough))
  2440. return new PassThrough(options);
  2441. Transform.call(this, options);
  2442. }
  2443. PassThrough.prototype._transform = function(chunk, encoding, cb) {
  2444. cb(null, chunk);
  2445. };
  2446. },{"./transform.js":15,"inherits":19}],14:[function(require,module,exports){
  2447. (function (process){
  2448. // Copyright Joyent, Inc. and other Node contributors.
  2449. //
  2450. // Permission is hereby granted, free of charge, to any person obtaining a
  2451. // copy of this software and associated documentation files (the
  2452. // "Software"), to deal in the Software without restriction, including
  2453. // without limitation the rights to use, copy, modify, merge, publish,
  2454. // distribute, sublicense, and/or sell copies of the Software, and to permit
  2455. // persons to whom the Software is furnished to do so, subject to the
  2456. // following conditions:
  2457. //
  2458. // The above copyright notice and this permission notice shall be included
  2459. // in all copies or substantial portions of the Software.
  2460. //
  2461. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2462. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2463. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2464. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2465. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2466. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2467. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  2468. module.exports = Readable;
  2469. Readable.ReadableState = ReadableState;
  2470. var EE = require('events').EventEmitter;
  2471. var Stream = require('./index.js');
  2472. var Buffer = require('buffer').Buffer;
  2473. var setImmediate = require('process/browser.js').nextTick;
  2474. var StringDecoder;
  2475. var inherits = require('inherits');
  2476. inherits(Readable, Stream);
  2477. function ReadableState(options, stream) {
  2478. options = options || {};
  2479. // the point at which it stops calling _read() to fill the buffer
  2480. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  2481. var hwm = options.highWaterMark;
  2482. this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
  2483. // cast to ints.
  2484. this.highWaterMark = ~~this.highWaterMark;
  2485. this.buffer = [];
  2486. this.length = 0;
  2487. this.pipes = null;
  2488. this.pipesCount = 0;
  2489. this.flowing = false;
  2490. this.ended = false;
  2491. this.endEmitted = false;
  2492. this.reading = false;
  2493. // In streams that never have any data, and do push(null) right away,
  2494. // the consumer can miss the 'end' event if they do some I/O before
  2495. // consuming the stream. So, we don't emit('end') until some reading
  2496. // happens.
  2497. this.calledRead = false;
  2498. // a flag to be able to tell if the onwrite cb is called immediately,
  2499. // or on a later tick. We set this to true at first, becuase any
  2500. // actions that shouldn't happen until "later" should generally also
  2501. // not happen before the first write call.
  2502. this.sync = true;
  2503. // whenever we return null, then we set a flag to say
  2504. // that we're awaiting a 'readable' event emission.
  2505. this.needReadable = false;
  2506. this.emittedReadable = false;
  2507. this.readableListening = false;
  2508. // object stream flag. Used to make read(n) ignore n and to
  2509. // make all the buffer merging and length checks go away
  2510. this.objectMode = !!options.objectMode;
  2511. // Crypto is kind of old and crusty. Historically, its default string
  2512. // encoding is 'binary' so we have to make this configurable.
  2513. // Everything else in the universe uses 'utf8', though.
  2514. this.defaultEncoding = options.defaultEncoding || 'utf8';
  2515. // when piping, we only care about 'readable' events that happen
  2516. // after read()ing all the bytes and not getting any pushback.
  2517. this.ranOut = false;
  2518. // the number of writers that are awaiting a drain event in .pipe()s
  2519. this.awaitDrain = 0;
  2520. // if true, a maybeReadMore has been scheduled
  2521. this.readingMore = false;
  2522. this.decoder = null;
  2523. this.encoding = null;
  2524. if (options.encoding) {
  2525. if (!StringDecoder)
  2526. StringDecoder = require('string_decoder').StringDecoder;
  2527. this.decoder = new StringDecoder(options.encoding);
  2528. this.encoding = options.encoding;
  2529. }
  2530. }
  2531. function Readable(options) {
  2532. if (!(this instanceof Readable))
  2533. return new Readable(options);
  2534. this._readableState = new ReadableState(options, this);
  2535. // legacy
  2536. this.readable = true;
  2537. Stream.call(this);
  2538. }
  2539. // Manually shove something into the read() buffer.
  2540. // This returns true if the highWaterMark has not been hit yet,
  2541. // similar to how Writable.write() returns true if you should
  2542. // write() some more.
  2543. Readable.prototype.push = function(chunk, encoding) {
  2544. var state = this._readableState;
  2545. if (typeof chunk === 'string' && !state.objectMode) {
  2546. encoding = encoding || state.defaultEncoding;
  2547. if (encoding !== state.encoding) {
  2548. chunk = new Buffer(chunk, encoding);
  2549. encoding = '';
  2550. }
  2551. }
  2552. return readableAddChunk(this, state, chunk, encoding, false);
  2553. };
  2554. // Unshift should *always* be something directly out of read()
  2555. Readable.prototype.unshift = function(chunk) {
  2556. var state = this._readableState;
  2557. return readableAddChunk(this, state, chunk, '', true);
  2558. };
  2559. function readableAddChunk(stream, state, chunk, encoding, addToFront) {
  2560. var er = chunkInvalid(state, chunk);
  2561. if (er) {
  2562. stream.emit('error', er);
  2563. } else if (chunk === null || chunk === undefined) {
  2564. state.reading = false;
  2565. if (!state.ended)
  2566. onEofChunk(stream, state);
  2567. } else if (state.objectMode || chunk && chunk.length > 0) {
  2568. if (state.ended && !addToFront) {
  2569. var e = new Error('stream.push() after EOF');
  2570. stream.emit('error', e);
  2571. } else if (state.endEmitted && addToFront) {
  2572. var e = new Error('stream.unshift() after end event');
  2573. stream.emit('error', e);
  2574. } else {
  2575. if (state.decoder && !addToFront && !encoding)
  2576. chunk = state.decoder.write(chunk);
  2577. // update the buffer info.
  2578. state.length += state.objectMode ? 1 : chunk.length;
  2579. if (addToFront) {
  2580. state.buffer.unshift(chunk);
  2581. } else {
  2582. state.reading = false;
  2583. state.buffer.push(chunk);
  2584. }
  2585. if (state.needReadable)
  2586. emitReadable(stream);
  2587. maybeReadMore(stream, state);
  2588. }
  2589. } else if (!addToFront) {
  2590. state.reading = false;
  2591. }
  2592. return needMoreData(state);
  2593. }
  2594. // if it's past the high water mark, we can push in some more.
  2595. // Also, if we have no data yet, we can stand some
  2596. // more bytes. This is to work around cases where hwm=0,
  2597. // such as the repl. Also, if the push() triggered a
  2598. // readable event, and the user called read(largeNumber) such that
  2599. // needReadable was set, then we ought to push more, so that another
  2600. // 'readable' event will be triggered.
  2601. function needMoreData(state) {
  2602. return !state.ended &&
  2603. (state.needReadable ||
  2604. state.length < state.highWaterMark ||
  2605. state.length === 0);
  2606. }
  2607. // backwards compatibility.
  2608. Readable.prototype.setEncoding = function(enc) {
  2609. if (!StringDecoder)
  2610. StringDecoder = require('string_decoder').StringDecoder;
  2611. this._readableState.decoder = new StringDecoder(enc);
  2612. this._readableState.encoding = enc;
  2613. };
  2614. // Don't raise the hwm > 128MB
  2615. var MAX_HWM = 0x800000;
  2616. function roundUpToNextPowerOf2(n) {
  2617. if (n >= MAX_HWM) {
  2618. n = MAX_HWM;
  2619. } else {
  2620. // Get the next highest power of 2
  2621. n--;
  2622. for (var p = 1; p < 32; p <<= 1) n |= n >> p;
  2623. n++;
  2624. }
  2625. return n;
  2626. }
  2627. function howMuchToRead(n, state) {
  2628. if (state.length === 0 && state.ended)
  2629. return 0;
  2630. if (state.objectMode)
  2631. return n === 0 ? 0 : 1;
  2632. if (isNaN(n) || n === null) {
  2633. // only flow one buffer at a time
  2634. if (state.flowing && state.buffer.length)
  2635. return state.buffer[0].length;
  2636. else
  2637. return state.length;
  2638. }
  2639. if (n <= 0)
  2640. return 0;
  2641. // If we're asking for more than the target buffer level,
  2642. // then raise the water mark. Bump up to the next highest
  2643. // power of 2, to prevent increasing it excessively in tiny
  2644. // amounts.
  2645. if (n > state.highWaterMark)
  2646. state.highWaterMark = roundUpToNextPowerOf2(n);
  2647. // don't have that much. return null, unless we've ended.
  2648. if (n > state.length) {
  2649. if (!state.ended) {
  2650. state.needReadable = true;
  2651. return 0;
  2652. } else
  2653. return state.length;
  2654. }
  2655. return n;
  2656. }
  2657. // you can override either this method, or the async _read(n) below.
  2658. Readable.prototype.read = function(n) {
  2659. var state = this._readableState;
  2660. state.calledRead = true;
  2661. var nOrig = n;
  2662. if (typeof n !== 'number' || n > 0)
  2663. state.emittedReadable = false;
  2664. // if we're doing read(0) to trigger a readable event, but we
  2665. // already have a bunch of data in the buffer, then just trigger
  2666. // the 'readable' event and move on.
  2667. if (n === 0 &&
  2668. state.needReadable &&
  2669. (state.length >= state.highWaterMark || state.ended)) {
  2670. emitReadable(this);
  2671. return null;
  2672. }
  2673. n = howMuchToRead(n, state);
  2674. // if we've ended, and we're now clear, then finish it up.
  2675. if (n === 0 && state.ended) {
  2676. if (state.length === 0)
  2677. endReadable(this);
  2678. return null;
  2679. }
  2680. // All the actual chunk generation logic needs to be
  2681. // *below* the call to _read. The reason is that in certain
  2682. // synthetic stream cases, such as passthrough streams, _read
  2683. // may be a completely synchronous operation which may change
  2684. // the state of the read buffer, providing enough data when
  2685. // before there was *not* enough.
  2686. //
  2687. // So, the steps are:
  2688. // 1. Figure out what the state of things will be after we do
  2689. // a read from the buffer.
  2690. //
  2691. // 2. If that resulting state will trigger a _read, then call _read.
  2692. // Note that this may be asynchronous, or synchronous. Yes, it is
  2693. // deeply ugly to write APIs this way, but that still doesn't mean
  2694. // that the Readable class should behave improperly, as streams are
  2695. // designed to be sync/async agnostic.
  2696. // Take note if the _read call is sync or async (ie, if the read call
  2697. // has returned yet), so that we know whether or not it's safe to emit
  2698. // 'readable' etc.
  2699. //
  2700. // 3. Actually pull the requested chunks out of the buffer and return.
  2701. // if we need a readable event, then we need to do some reading.
  2702. var doRead = state.needReadable;
  2703. // if we currently have less than the highWaterMark, then also read some
  2704. if (state.length - n <= state.highWaterMark)
  2705. doRead = true;
  2706. // however, if we've ended, then there's no point, and if we're already
  2707. // reading, then it's unnecessary.
  2708. if (state.ended || state.reading)
  2709. doRead = false;
  2710. if (doRead) {
  2711. state.reading = true;
  2712. state.sync = true;
  2713. // if the length is currently zero, then we *need* a readable event.
  2714. if (state.length === 0)
  2715. state.needReadable = true;
  2716. // call internal read method
  2717. this._read(state.highWaterMark);
  2718. state.sync = false;
  2719. }
  2720. // If _read called its callback synchronously, then `reading`
  2721. // will be false, and we need to re-evaluate how much data we
  2722. // can return to the user.
  2723. if (doRead && !state.reading)
  2724. n = howMuchToRead(nOrig, state);
  2725. var ret;
  2726. if (n > 0)
  2727. ret = fromList(n, state);
  2728. else
  2729. ret = null;
  2730. if (ret === null) {
  2731. state.needReadable = true;
  2732. n = 0;
  2733. }
  2734. state.length -= n;
  2735. // If we have nothing in the buffer, then we want to know
  2736. // as soon as we *do* get something into the buffer.
  2737. if (state.length === 0 && !state.ended)
  2738. state.needReadable = true;
  2739. // If we happened to read() exactly the remaining amount in the
  2740. // buffer, and the EOF has been seen at this point, then make sure
  2741. // that we emit 'end' on the very next tick.
  2742. if (state.ended && !state.endEmitted && state.length === 0)
  2743. endReadable(this);
  2744. return ret;
  2745. };
  2746. function chunkInvalid(state, chunk) {
  2747. var er = null;
  2748. if (!Buffer.isBuffer(chunk) &&
  2749. 'string' !== typeof chunk &&
  2750. chunk !== null &&
  2751. chunk !== undefined &&
  2752. !state.objectMode &&
  2753. !er) {
  2754. er = new TypeError('Invalid non-string/buffer chunk');
  2755. }
  2756. return er;
  2757. }
  2758. function onEofChunk(stream, state) {
  2759. if (state.decoder && !state.ended) {
  2760. var chunk = state.decoder.end();
  2761. if (chunk && chunk.length) {
  2762. state.buffer.push(chunk);
  2763. state.length += state.objectMode ? 1 : chunk.length;
  2764. }
  2765. }
  2766. state.ended = true;
  2767. // if we've ended and we have some data left, then emit
  2768. // 'readable' now to make sure it gets picked up.
  2769. if (state.length > 0)
  2770. emitReadable(stream);
  2771. else
  2772. endReadable(stream);
  2773. }
  2774. // Don't emit readable right away in sync mode, because this can trigger
  2775. // another read() call => stack overflow. This way, it might trigger
  2776. // a nextTick recursion warning, but that's not so bad.
  2777. function emitReadable(stream) {
  2778. var state = stream._readableState;
  2779. state.needReadable = false;
  2780. if (state.emittedReadable)
  2781. return;
  2782. state.emittedReadable = true;
  2783. if (state.sync)
  2784. setImmediate(function() {
  2785. emitReadable_(stream);
  2786. });
  2787. else
  2788. emitReadable_(stream);
  2789. }
  2790. function emitReadable_(stream) {
  2791. stream.emit('readable');
  2792. }
  2793. // at this point, the user has presumably seen the 'readable' event,
  2794. // and called read() to consume some data. that may have triggered
  2795. // in turn another _read(n) call, in which case reading = true if
  2796. // it's in progress.
  2797. // However, if we're not ended, or reading, and the length < hwm,
  2798. // then go ahead and try to read some more preemptively.
  2799. function maybeReadMore(stream, state) {
  2800. if (!state.readingMore) {
  2801. state.readingMore = true;
  2802. setImmediate(function() {
  2803. maybeReadMore_(stream, state);
  2804. });
  2805. }
  2806. }
  2807. function maybeReadMore_(stream, state) {
  2808. var len = state.length;
  2809. while (!state.reading && !state.flowing && !state.ended &&
  2810. state.length < state.highWaterMark) {
  2811. stream.read(0);
  2812. if (len === state.length)
  2813. // didn't get any data, stop spinning.
  2814. break;
  2815. else
  2816. len = state.length;
  2817. }
  2818. state.readingMore = false;
  2819. }
  2820. // abstract method. to be overridden in specific implementation classes.
  2821. // call cb(er, data) where data is <= n in length.
  2822. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  2823. // arbitrary, and perhaps not very meaningful.
  2824. Readable.prototype._read = function(n) {
  2825. this.emit('error', new Error('not implemented'));
  2826. };
  2827. Readable.prototype.pipe = function(dest, pipeOpts) {
  2828. var src = this;
  2829. var state = this._readableState;
  2830. switch (state.pipesCount) {
  2831. case 0:
  2832. state.pipes = dest;
  2833. break;
  2834. case 1:
  2835. state.pipes = [state.pipes, dest];
  2836. break;
  2837. default:
  2838. state.pipes.push(dest);
  2839. break;
  2840. }
  2841. state.pipesCount += 1;
  2842. var doEnd = (!pipeOpts || pipeOpts.end !== false) &&
  2843. dest !== process.stdout &&
  2844. dest !== process.stderr;
  2845. var endFn = doEnd ? onend : cleanup;
  2846. if (state.endEmitted)
  2847. setImmediate(endFn);
  2848. else
  2849. src.once('end', endFn);
  2850. dest.on('unpipe', onunpipe);
  2851. function onunpipe(readable) {
  2852. if (readable !== src) return;
  2853. cleanup();
  2854. }
  2855. function onend() {
  2856. dest.end();
  2857. }
  2858. // when the dest drains, it reduces the awaitDrain counter
  2859. // on the source. This would be more elegant with a .once()
  2860. // handler in flow(), but adding and removing repeatedly is
  2861. // too slow.
  2862. var ondrain = pipeOnDrain(src);
  2863. dest.on('drain', ondrain);
  2864. function cleanup() {
  2865. // cleanup event handlers once the pipe is broken
  2866. dest.removeListener('close', onclose);
  2867. dest.removeListener('finish', onfinish);
  2868. dest.removeListener('drain', ondrain);
  2869. dest.removeListener('error', onerror);
  2870. dest.removeListener('unpipe', onunpipe);
  2871. src.removeListener('end', onend);
  2872. src.removeListener('end', cleanup);
  2873. // if the reader is waiting for a drain event from this
  2874. // specific writer, then it would cause it to never start
  2875. // flowing again.
  2876. // So, if this is awaiting a drain, then we just call it now.
  2877. // If we don't know, then assume that we are waiting for one.
  2878. if (!dest._writableState || dest._writableState.needDrain)
  2879. ondrain();
  2880. }
  2881. // if the dest has an error, then stop piping into it.
  2882. // however, don't suppress the throwing behavior for this.
  2883. // check for listeners before emit removes one-time listeners.
  2884. var errListeners = EE.listenerCount(dest, 'error');
  2885. function onerror(er) {
  2886. unpipe();
  2887. if (errListeners === 0 && EE.listenerCount(dest, 'error') === 0)
  2888. dest.emit('error', er);
  2889. }
  2890. dest.once('error', onerror);
  2891. // Both close and finish should trigger unpipe, but only once.
  2892. function onclose() {
  2893. dest.removeListener('finish', onfinish);
  2894. unpipe();
  2895. }
  2896. dest.once('close', onclose);
  2897. function onfinish() {
  2898. dest.removeListener('close', onclose);
  2899. unpipe();
  2900. }
  2901. dest.once('finish', onfinish);
  2902. function unpipe() {
  2903. src.unpipe(dest);
  2904. }
  2905. // tell the dest that it's being piped to
  2906. dest.emit('pipe', src);
  2907. // start the flow if it hasn't been started already.
  2908. if (!state.flowing) {
  2909. // the handler that waits for readable events after all
  2910. // the data gets sucked out in flow.
  2911. // This would be easier to follow with a .once() handler
  2912. // in flow(), but that is too slow.
  2913. this.on('readable', pipeOnReadable);
  2914. state.flowing = true;
  2915. setImmediate(function() {
  2916. flow(src);
  2917. });
  2918. }
  2919. return dest;
  2920. };
  2921. function pipeOnDrain(src) {
  2922. return function() {
  2923. var dest = this;
  2924. var state = src._readableState;
  2925. state.awaitDrain--;
  2926. if (state.awaitDrain === 0)
  2927. flow(src);
  2928. };
  2929. }
  2930. function flow(src) {
  2931. var state = src._readableState;
  2932. var chunk;
  2933. state.awaitDrain = 0;
  2934. function write(dest, i, list) {
  2935. var written = dest.write(chunk);
  2936. if (false === written) {
  2937. state.awaitDrain++;
  2938. }
  2939. }
  2940. while (state.pipesCount && null !== (chunk = src.read())) {
  2941. if (state.pipesCount === 1)
  2942. write(state.pipes, 0, null);
  2943. else
  2944. forEach(state.pipes, write);
  2945. src.emit('data', chunk);
  2946. // if anyone needs a drain, then we have to wait for that.
  2947. if (state.awaitDrain > 0)
  2948. return;
  2949. }
  2950. // if every destination was unpiped, either before entering this
  2951. // function, or in the while loop, then stop flowing.
  2952. //
  2953. // NB: This is a pretty rare edge case.
  2954. if (state.pipesCount === 0) {
  2955. state.flowing = false;
  2956. // if there were data event listeners added, then switch to old mode.
  2957. if (EE.listenerCount(src, 'data') > 0)
  2958. emitDataEvents(src);
  2959. return;
  2960. }
  2961. // at this point, no one needed a drain, so we just ran out of data
  2962. // on the next readable event, start it over again.
  2963. state.ranOut = true;
  2964. }
  2965. function pipeOnReadable() {
  2966. if (this._readableState.ranOut) {
  2967. this._readableState.ranOut = false;
  2968. flow(this);
  2969. }
  2970. }
  2971. Readable.prototype.unpipe = function(dest) {
  2972. var state = this._readableState;
  2973. // if we're not piping anywhere, then do nothing.
  2974. if (state.pipesCount === 0)
  2975. return this;
  2976. // just one destination. most common case.
  2977. if (state.pipesCount === 1) {
  2978. // passed in one, but it's not the right one.
  2979. if (dest && dest !== state.pipes)
  2980. return this;
  2981. if (!dest)
  2982. dest = state.pipes;
  2983. // got a match.
  2984. state.pipes = null;
  2985. state.pipesCount = 0;
  2986. this.removeListener('readable', pipeOnReadable);
  2987. state.flowing = false;
  2988. if (dest)
  2989. dest.emit('unpipe', this);
  2990. return this;
  2991. }
  2992. // slow case. multiple pipe destinations.
  2993. if (!dest) {
  2994. // remove all.
  2995. var dests = state.pipes;
  2996. var len = state.pipesCount;
  2997. state.pipes = null;
  2998. state.pipesCount = 0;
  2999. this.removeListener('readable', pipeOnReadable);
  3000. state.flowing = false;
  3001. for (var i = 0; i < len; i++)
  3002. dests[i].emit('unpipe', this);
  3003. return this;
  3004. }
  3005. // try to find the right one.
  3006. var i = indexOf(state.pipes, dest);
  3007. if (i === -1)
  3008. return this;
  3009. state.pipes.splice(i, 1);
  3010. state.pipesCount -= 1;
  3011. if (state.pipesCount === 1)
  3012. state.pipes = state.pipes[0];
  3013. dest.emit('unpipe', this);
  3014. return this;
  3015. };
  3016. // set up data events if they are asked for
  3017. // Ensure readable listeners eventually get something
  3018. Readable.prototype.on = function(ev, fn) {
  3019. var res = Stream.prototype.on.call(this, ev, fn);
  3020. if (ev === 'data' && !this._readableState.flowing)
  3021. emitDataEvents(this);
  3022. if (ev === 'readable' && this.readable) {
  3023. var state = this._readableState;
  3024. if (!state.readableListening) {
  3025. state.readableListening = true;
  3026. state.emittedReadable = false;
  3027. state.needReadable = true;
  3028. if (!state.reading) {
  3029. this.read(0);
  3030. } else if (state.length) {
  3031. emitReadable(this, state);
  3032. }
  3033. }
  3034. }
  3035. return res;
  3036. };
  3037. Readable.prototype.addListener = Readable.prototype.on;
  3038. // pause() and resume() are remnants of the legacy readable stream API
  3039. // If the user uses them, then switch into old mode.
  3040. Readable.prototype.resume = function() {
  3041. emitDataEvents(this);
  3042. this.read(0);
  3043. this.emit('resume');
  3044. };
  3045. Readable.prototype.pause = function() {
  3046. emitDataEvents(this, true);
  3047. this.emit('pause');
  3048. };
  3049. function emitDataEvents(stream, startPaused) {
  3050. var state = stream._readableState;
  3051. if (state.flowing) {
  3052. // https://github.com/isaacs/readable-stream/issues/16
  3053. throw new Error('Cannot switch to old mode now.');
  3054. }
  3055. var paused = startPaused || false;
  3056. var readable = false;
  3057. // convert to an old-style stream.
  3058. stream.readable = true;
  3059. stream.pipe = Stream.prototype.pipe;
  3060. stream.on = stream.addListener = Stream.prototype.on;
  3061. stream.on('readable', function() {
  3062. readable = true;
  3063. var c;
  3064. while (!paused && (null !== (c = stream.read())))
  3065. stream.emit('data', c);
  3066. if (c === null) {
  3067. readable = false;
  3068. stream._readableState.needReadable = true;
  3069. }
  3070. });
  3071. stream.pause = function() {
  3072. paused = true;
  3073. this.emit('pause');
  3074. };
  3075. stream.resume = function() {
  3076. paused = false;
  3077. if (readable)
  3078. setImmediate(function() {
  3079. stream.emit('readable');
  3080. });
  3081. else
  3082. this.read(0);
  3083. this.emit('resume');
  3084. };
  3085. // now make it start, just in case it hadn't already.
  3086. stream.emit('readable');
  3087. }
  3088. // wrap an old-style stream as the async data source.
  3089. // This is *not* part of the readable stream interface.
  3090. // It is an ugly unfortunate mess of history.
  3091. Readable.prototype.wrap = function(stream) {
  3092. var state = this._readableState;
  3093. var paused = false;
  3094. var self = this;
  3095. stream.on('end', function() {
  3096. if (state.decoder && !state.ended) {
  3097. var chunk = state.decoder.end();
  3098. if (chunk && chunk.length)
  3099. self.push(chunk);
  3100. }
  3101. self.push(null);
  3102. });
  3103. stream.on('data', function(chunk) {
  3104. if (state.decoder)
  3105. chunk = state.decoder.write(chunk);
  3106. if (!chunk || !state.objectMode && !chunk.length)
  3107. return;
  3108. var ret = self.push(chunk);
  3109. if (!ret) {
  3110. paused = true;
  3111. stream.pause();
  3112. }
  3113. });
  3114. // proxy all the other methods.
  3115. // important when wrapping filters and duplexes.
  3116. for (var i in stream) {
  3117. if (typeof stream[i] === 'function' &&
  3118. typeof this[i] === 'undefined') {
  3119. this[i] = function(method) { return function() {
  3120. return stream[method].apply(stream, arguments);
  3121. }}(i);
  3122. }
  3123. }
  3124. // proxy certain important events.
  3125. var events = ['error', 'close', 'destroy', 'pause', 'resume'];
  3126. forEach(events, function(ev) {
  3127. stream.on(ev, function (x) {
  3128. return self.emit.apply(self, ev, x);
  3129. });
  3130. });
  3131. // when we try to consume some more bytes, simply unpause the
  3132. // underlying stream.
  3133. self._read = function(n) {
  3134. if (paused) {
  3135. paused = false;
  3136. stream.resume();
  3137. }
  3138. };
  3139. return self;
  3140. };
  3141. // exposed for testing purposes only.
  3142. Readable._fromList = fromList;
  3143. // Pluck off n bytes from an array of buffers.
  3144. // Length is the combined lengths of all the buffers in the list.
  3145. function fromList(n, state) {
  3146. var list = state.buffer;
  3147. var length = state.length;
  3148. var stringMode = !!state.decoder;
  3149. var objectMode = !!state.objectMode;
  3150. var ret;
  3151. // nothing in the list, definitely empty.
  3152. if (list.length === 0)
  3153. return null;
  3154. if (length === 0)
  3155. ret = null;
  3156. else if (objectMode)
  3157. ret = list.shift();
  3158. else if (!n || n >= length) {
  3159. // read it all, truncate the array.
  3160. if (stringMode)
  3161. ret = list.join('');
  3162. else
  3163. ret = Buffer.concat(list, length);
  3164. list.length = 0;
  3165. } else {
  3166. // read just some of it.
  3167. if (n < list[0].length) {
  3168. // just take a part of the first list item.
  3169. // slice is the same for buffers and strings.
  3170. var buf = list[0];
  3171. ret = buf.slice(0, n);
  3172. list[0] = buf.slice(n);
  3173. } else if (n === list[0].length) {
  3174. // first list is a perfect match
  3175. ret = list.shift();
  3176. } else {
  3177. // complex case.
  3178. // we have enough to cover it, but it spans past the first buffer.
  3179. if (stringMode)
  3180. ret = '';
  3181. else
  3182. ret = new Buffer(n);
  3183. var c = 0;
  3184. for (var i = 0, l = list.length; i < l && c < n; i++) {
  3185. var buf = list[0];
  3186. var cpy = Math.min(n - c, buf.length);
  3187. if (stringMode)
  3188. ret += buf.slice(0, cpy);
  3189. else
  3190. buf.copy(ret, c, 0, cpy);
  3191. if (cpy < buf.length)
  3192. list[0] = buf.slice(cpy);
  3193. else
  3194. list.shift();
  3195. c += cpy;
  3196. }
  3197. }
  3198. }
  3199. return ret;
  3200. }
  3201. function endReadable(stream) {
  3202. var state = stream._readableState;
  3203. // If we get here before consuming all the bytes, then that is a
  3204. // bug in node. Should never happen.
  3205. if (state.length > 0)
  3206. throw new Error('endReadable called on non-empty stream');
  3207. if (!state.endEmitted && state.calledRead) {
  3208. state.ended = true;
  3209. setImmediate(function() {
  3210. // Check that we didn't get one last unshift.
  3211. if (!state.endEmitted && state.length === 0) {
  3212. state.endEmitted = true;
  3213. stream.readable = false;
  3214. stream.emit('end');
  3215. }
  3216. });
  3217. }
  3218. }
  3219. function forEach (xs, f) {
  3220. for (var i = 0, l = xs.length; i < l; i++) {
  3221. f(xs[i], i);
  3222. }
  3223. }
  3224. function indexOf (xs, x) {
  3225. for (var i = 0, l = xs.length; i < l; i++) {
  3226. if (xs[i] === x) return i;
  3227. }
  3228. return -1;
  3229. }
  3230. }).call(this,require("7YKIPe"))
  3231. },{"./index.js":11,"7YKIPe":9,"buffer":7,"events":8,"inherits":19,"process/browser.js":12,"string_decoder":17}],15:[function(require,module,exports){
  3232. // Copyright Joyent, Inc. and other Node contributors.
  3233. //
  3234. // Permission is hereby granted, free of charge, to any person obtaining a
  3235. // copy of this software and associated documentation files (the
  3236. // "Software"), to deal in the Software without restriction, including
  3237. // without limitation the rights to use, copy, modify, merge, publish,
  3238. // distribute, sublicense, and/or sell copies of the Software, and to permit
  3239. // persons to whom the Software is furnished to do so, subject to the
  3240. // following conditions:
  3241. //
  3242. // The above copyright notice and this permission notice shall be included
  3243. // in all copies or substantial portions of the Software.
  3244. //
  3245. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  3246. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3247. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  3248. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  3249. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  3250. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  3251. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  3252. // a transform stream is a readable/writable stream where you do
  3253. // something with the data. Sometimes it's called a "filter",
  3254. // but that's not a great name for it, since that implies a thing where
  3255. // some bits pass through, and others are simply ignored. (That would
  3256. // be a valid example of a transform, of course.)
  3257. //
  3258. // While the output is causally related to the input, it's not a
  3259. // necessarily symmetric or synchronous transformation. For example,
  3260. // a zlib stream might take multiple plain-text writes(), and then
  3261. // emit a single compressed chunk some time in the future.
  3262. //
  3263. // Here's how this works:
  3264. //
  3265. // The Transform stream has all the aspects of the readable and writable
  3266. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  3267. // internally, and returns false if there's a lot of pending writes
  3268. // buffered up. When you call read(), that calls _read(n) until
  3269. // there's enough pending readable data buffered up.
  3270. //
  3271. // In a transform stream, the written data is placed in a buffer. When
  3272. // _read(n) is called, it transforms the queued up data, calling the
  3273. // buffered _write cb's as it consumes chunks. If consuming a single
  3274. // written chunk would result in multiple output chunks, then the first
  3275. // outputted bit calls the readcb, and subsequent chunks just go into
  3276. // the read buffer, and will cause it to emit 'readable' if necessary.
  3277. //
  3278. // This way, back-pressure is actually determined by the reading side,
  3279. // since _read has to be called to start processing a new chunk. However,
  3280. // a pathological inflate type of transform can cause excessive buffering
  3281. // here. For example, imagine a stream where every byte of input is
  3282. // interpreted as an integer from 0-255, and then results in that many
  3283. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  3284. // 1kb of data being output. In this case, you could write a very small
  3285. // amount of input, and end up with a very large amount of output. In
  3286. // such a pathological inflating mechanism, there'd be no way to tell
  3287. // the system to stop doing the transform. A single 4MB write could
  3288. // cause the system to run out of memory.
  3289. //
  3290. // However, even in such a pathological case, only a single written chunk
  3291. // would be consumed, and then the rest would wait (un-transformed) until
  3292. // the results of the previous transformed chunk were consumed.
  3293. module.exports = Transform;
  3294. var Duplex = require('./duplex.js');
  3295. var inherits = require('inherits');
  3296. inherits(Transform, Duplex);
  3297. function TransformState(options, stream) {
  3298. this.afterTransform = function(er, data) {
  3299. return afterTransform(stream, er, data);
  3300. };
  3301. this.needTransform = false;
  3302. this.transforming = false;
  3303. this.writecb = null;
  3304. this.writechunk = null;
  3305. }
  3306. function afterTransform(stream, er, data) {
  3307. var ts = stream._transformState;
  3308. ts.transforming = false;
  3309. var cb = ts.writecb;
  3310. if (!cb)
  3311. return stream.emit('error', new Error('no writecb in Transform class'));
  3312. ts.writechunk = null;
  3313. ts.writecb = null;
  3314. if (data !== null && data !== undefined)
  3315. stream.push(data);
  3316. if (cb)
  3317. cb(er);
  3318. var rs = stream._readableState;
  3319. rs.reading = false;
  3320. if (rs.needReadable || rs.length < rs.highWaterMark) {
  3321. stream._read(rs.highWaterMark);
  3322. }
  3323. }
  3324. function Transform(options) {
  3325. if (!(this instanceof Transform))
  3326. return new Transform(options);
  3327. Duplex.call(this, options);
  3328. var ts = this._transformState = new TransformState(options, this);
  3329. // when the writable side finishes, then flush out anything remaining.
  3330. var stream = this;
  3331. // start out asking for a readable event once data is transformed.
  3332. this._readableState.needReadable = true;
  3333. // we have implemented the _read method, and done the other things
  3334. // that Readable wants before the first _read call, so unset the
  3335. // sync guard flag.
  3336. this._readableState.sync = false;
  3337. this.once('finish', function() {
  3338. if ('function' === typeof this._flush)
  3339. this._flush(function(er) {
  3340. done(stream, er);
  3341. });
  3342. else
  3343. done(stream);
  3344. });
  3345. }
  3346. Transform.prototype.push = function(chunk, encoding) {
  3347. this._transformState.needTransform = false;
  3348. return Duplex.prototype.push.call(this, chunk, encoding);
  3349. };
  3350. // This is the part where you do stuff!
  3351. // override this function in implementation classes.
  3352. // 'chunk' is an input chunk.
  3353. //
  3354. // Call `push(newChunk)` to pass along transformed output
  3355. // to the readable side. You may call 'push' zero or more times.
  3356. //
  3357. // Call `cb(err)` when you are done with this chunk. If you pass
  3358. // an error, then that'll put the hurt on the whole operation. If you
  3359. // never call cb(), then you'll never get another chunk.
  3360. Transform.prototype._transform = function(chunk, encoding, cb) {
  3361. throw new Error('not implemented');
  3362. };
  3363. Transform.prototype._write = function(chunk, encoding, cb) {
  3364. var ts = this._transformState;
  3365. ts.writecb = cb;
  3366. ts.writechunk = chunk;
  3367. ts.writeencoding = encoding;
  3368. if (!ts.transforming) {
  3369. var rs = this._readableState;
  3370. if (ts.needTransform ||
  3371. rs.needReadable ||
  3372. rs.length < rs.highWaterMark)
  3373. this._read(rs.highWaterMark);
  3374. }
  3375. };
  3376. // Doesn't matter what the args are here.
  3377. // _transform does all the work.
  3378. // That we got here means that the readable side wants more data.
  3379. Transform.prototype._read = function(n) {
  3380. var ts = this._transformState;
  3381. if (ts.writechunk && ts.writecb && !ts.transforming) {
  3382. ts.transforming = true;
  3383. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  3384. } else {
  3385. // mark that we need a transform, so that any data that comes in
  3386. // will get processed, now that we've asked for it.
  3387. ts.needTransform = true;
  3388. }
  3389. };
  3390. function done(stream, er) {
  3391. if (er)
  3392. return stream.emit('error', er);
  3393. // if there's nothing in the write buffer, then that means
  3394. // that nothing more will ever be provided
  3395. var ws = stream._writableState;
  3396. var rs = stream._readableState;
  3397. var ts = stream._transformState;
  3398. if (ws.length)
  3399. throw new Error('calling transform done when ws.length != 0');
  3400. if (ts.transforming)
  3401. throw new Error('calling transform done when still transforming');
  3402. return stream.push(null);
  3403. }
  3404. },{"./duplex.js":10,"inherits":19}],16:[function(require,module,exports){
  3405. // Copyright Joyent, Inc. and other Node contributors.
  3406. //
  3407. // Permission is hereby granted, free of charge, to any person obtaining a
  3408. // copy of this software and associated documentation files (the
  3409. // "Software"), to deal in the Software without restriction, including
  3410. // without limitation the rights to use, copy, modify, merge, publish,
  3411. // distribute, sublicense, and/or sell copies of the Software, and to permit
  3412. // persons to whom the Software is furnished to do so, subject to the
  3413. // following conditions:
  3414. //
  3415. // The above copyright notice and this permission notice shall be included
  3416. // in all copies or substantial portions of the Software.
  3417. //
  3418. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  3419. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3420. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  3421. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  3422. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  3423. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  3424. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  3425. // A bit simpler than readable streams.
  3426. // Implement an async ._write(chunk, cb), and it'll handle all
  3427. // the drain event emission and buffering.
  3428. module.exports = Writable;
  3429. Writable.WritableState = WritableState;
  3430. var isUint8Array = typeof Uint8Array !== 'undefined'
  3431. ? function (x) { return x instanceof Uint8Array }
  3432. : function (x) {
  3433. return x && x.constructor && x.constructor.name === 'Uint8Array'
  3434. }
  3435. ;
  3436. var isArrayBuffer = typeof ArrayBuffer !== 'undefined'
  3437. ? function (x) { return x instanceof ArrayBuffer }
  3438. : function (x) {
  3439. return x && x.constructor && x.constructor.name === 'ArrayBuffer'
  3440. }
  3441. ;
  3442. var inherits = require('inherits');
  3443. var Stream = require('./index.js');
  3444. var setImmediate = require('process/browser.js').nextTick;
  3445. var Buffer = require('buffer').Buffer;
  3446. inherits(Writable, Stream);
  3447. function WriteReq(chunk, encoding, cb) {
  3448. this.chunk = chunk;
  3449. this.encoding = encoding;
  3450. this.callback = cb;
  3451. }
  3452. function WritableState(options, stream) {
  3453. options = options || {};
  3454. // the point at which write() starts returning false
  3455. // Note: 0 is a valid value, means that we always return false if
  3456. // the entire buffer is not flushed immediately on write()
  3457. var hwm = options.highWaterMark;
  3458. this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024;
  3459. // object stream flag to indicate whether or not this stream
  3460. // contains buffers or objects.
  3461. this.objectMode = !!options.objectMode;
  3462. // cast to ints.
  3463. this.highWaterMark = ~~this.highWaterMark;
  3464. this.needDrain = false;
  3465. // at the start of calling end()
  3466. this.ending = false;
  3467. // when end() has been called, and returned
  3468. this.ended = false;
  3469. // when 'finish' is emitted
  3470. this.finished = false;
  3471. // should we decode strings into buffers before passing to _write?
  3472. // this is here so that some node-core streams can optimize string
  3473. // handling at a lower level.
  3474. var noDecode = options.decodeStrings === false;
  3475. this.decodeStrings = !noDecode;
  3476. // Crypto is kind of old and crusty. Historically, its default string
  3477. // encoding is 'binary' so we have to make this configurable.
  3478. // Everything else in the universe uses 'utf8', though.
  3479. this.defaultEncoding = options.defaultEncoding || 'utf8';
  3480. // not an actual buffer we keep track of, but a measurement
  3481. // of how much we're waiting to get pushed to some underlying
  3482. // socket or file.
  3483. this.length = 0;
  3484. // a flag to see when we're in the middle of a write.
  3485. this.writing = false;
  3486. // a flag to be able to tell if the onwrite cb is called immediately,
  3487. // or on a later tick. We set this to true at first, becuase any
  3488. // actions that shouldn't happen until "later" should generally also
  3489. // not happen before the first write call.
  3490. this.sync = true;
  3491. // a flag to know if we're processing previously buffered items, which
  3492. // may call the _write() callback in the same tick, so that we don't
  3493. // end up in an overlapped onwrite situation.
  3494. this.bufferProcessing = false;
  3495. // the callback that's passed to _write(chunk,cb)
  3496. this.onwrite = function(er) {
  3497. onwrite(stream, er);
  3498. };
  3499. // the callback that the user supplies to write(chunk,encoding,cb)
  3500. this.writecb = null;
  3501. // the amount that is being written when _write is called.
  3502. this.writelen = 0;
  3503. this.buffer = [];
  3504. }
  3505. function Writable(options) {
  3506. // Writable ctor is applied to Duplexes, though they're not
  3507. // instanceof Writable, they're instanceof Readable.
  3508. if (!(this instanceof Writable) && !(this instanceof Stream.Duplex))
  3509. return new Writable(options);
  3510. this._writableState = new WritableState(options, this);
  3511. // legacy.
  3512. this.writable = true;
  3513. Stream.call(this);
  3514. }
  3515. // Otherwise people can pipe Writable streams, which is just wrong.
  3516. Writable.prototype.pipe = function() {
  3517. this.emit('error', new Error('Cannot pipe. Not readable.'));
  3518. };
  3519. function writeAfterEnd(stream, state, cb) {
  3520. var er = new Error('write after end');
  3521. // TODO: defer error events consistently everywhere, not just the cb
  3522. stream.emit('error', er);
  3523. setImmediate(function() {
  3524. cb(er);
  3525. });
  3526. }
  3527. // If we get something that is not a buffer, string, null, or undefined,
  3528. // and we're not in objectMode, then that's an error.
  3529. // Otherwise stream chunks are all considered to be of length=1, and the
  3530. // watermarks determine how many objects to keep in the buffer, rather than
  3531. // how many bytes or characters.
  3532. function validChunk(stream, state, chunk, cb) {
  3533. var valid = true;
  3534. if (!Buffer.isBuffer(chunk) &&
  3535. 'string' !== typeof chunk &&
  3536. chunk !== null &&
  3537. chunk !== undefined &&
  3538. !state.objectMode) {
  3539. var er = new TypeError('Invalid non-string/buffer chunk');
  3540. stream.emit('error', er);
  3541. setImmediate(function() {
  3542. cb(er);
  3543. });
  3544. valid = false;
  3545. }
  3546. return valid;
  3547. }
  3548. Writable.prototype.write = function(chunk, encoding, cb) {
  3549. var state = this._writableState;
  3550. var ret = false;
  3551. if (typeof encoding === 'function') {
  3552. cb = encoding;
  3553. encoding = null;
  3554. }
  3555. if (!Buffer.isBuffer(chunk) && isUint8Array(chunk))
  3556. chunk = new Buffer(chunk);
  3557. if (isArrayBuffer(chunk) && typeof Uint8Array !== 'undefined')
  3558. chunk = new Buffer(new Uint8Array(chunk));
  3559. if (Buffer.isBuffer(chunk))
  3560. encoding = 'buffer';
  3561. else if (!encoding)
  3562. encoding = state.defaultEncoding;
  3563. if (typeof cb !== 'function')
  3564. cb = function() {};
  3565. if (state.ended)
  3566. writeAfterEnd(this, state, cb);
  3567. else if (validChunk(this, state, chunk, cb))
  3568. ret = writeOrBuffer(this, state, chunk, encoding, cb);
  3569. return ret;
  3570. };
  3571. function decodeChunk(state, chunk, encoding) {
  3572. if (!state.objectMode &&
  3573. state.decodeStrings !== false &&
  3574. typeof chunk === 'string') {
  3575. chunk = new Buffer(chunk, encoding);
  3576. }
  3577. return chunk;
  3578. }
  3579. // if we're already writing something, then just put this
  3580. // in the queue, and wait our turn. Otherwise, call _write
  3581. // If we return false, then we need a drain event, so set that flag.
  3582. function writeOrBuffer(stream, state, chunk, encoding, cb) {
  3583. chunk = decodeChunk(state, chunk, encoding);
  3584. var len = state.objectMode ? 1 : chunk.length;
  3585. state.length += len;
  3586. var ret = state.length < state.highWaterMark;
  3587. state.needDrain = !ret;
  3588. if (state.writing)
  3589. state.buffer.push(new WriteReq(chunk, encoding, cb));
  3590. else
  3591. doWrite(stream, state, len, chunk, encoding, cb);
  3592. return ret;
  3593. }
  3594. function doWrite(stream, state, len, chunk, encoding, cb) {
  3595. state.writelen = len;
  3596. state.writecb = cb;
  3597. state.writing = true;
  3598. state.sync = true;
  3599. stream._write(chunk, encoding, state.onwrite);
  3600. state.sync = false;
  3601. }
  3602. function onwriteError(stream, state, sync, er, cb) {
  3603. if (sync)
  3604. setImmediate(function() {
  3605. cb(er);
  3606. });
  3607. else
  3608. cb(er);
  3609. stream.emit('error', er);
  3610. }
  3611. function onwriteStateUpdate(state) {
  3612. state.writing = false;
  3613. state.writecb = null;
  3614. state.length -= state.writelen;
  3615. state.writelen = 0;
  3616. }
  3617. function onwrite(stream, er) {
  3618. var state = stream._writableState;
  3619. var sync = state.sync;
  3620. var cb = state.writecb;
  3621. onwriteStateUpdate(state);
  3622. if (er)
  3623. onwriteError(stream, state, sync, er, cb);
  3624. else {
  3625. // Check if we're actually ready to finish, but don't emit yet
  3626. var finished = needFinish(stream, state);
  3627. if (!finished && !state.bufferProcessing && state.buffer.length)
  3628. clearBuffer(stream, state);
  3629. if (sync) {
  3630. setImmediate(function() {
  3631. afterWrite(stream, state, finished, cb);
  3632. });
  3633. } else {
  3634. afterWrite(stream, state, finished, cb);
  3635. }
  3636. }
  3637. }
  3638. function afterWrite(stream, state, finished, cb) {
  3639. if (!finished)
  3640. onwriteDrain(stream, state);
  3641. cb();
  3642. if (finished)
  3643. finishMaybe(stream, state);
  3644. }
  3645. // Must force callback to be called on nextTick, so that we don't
  3646. // emit 'drain' before the write() consumer gets the 'false' return
  3647. // value, and has a chance to attach a 'drain' listener.
  3648. function onwriteDrain(stream, state) {
  3649. if (state.length === 0 && state.needDrain) {
  3650. state.needDrain = false;
  3651. stream.emit('drain');
  3652. }
  3653. }
  3654. // if there's something in the buffer waiting, then process it
  3655. function clearBuffer(stream, state) {
  3656. state.bufferProcessing = true;
  3657. for (var c = 0; c < state.buffer.length; c++) {
  3658. var entry = state.buffer[c];
  3659. var chunk = entry.chunk;
  3660. var encoding = entry.encoding;
  3661. var cb = entry.callback;
  3662. var len = state.objectMode ? 1 : chunk.length;
  3663. doWrite(stream, state, len, chunk, encoding, cb);
  3664. // if we didn't call the onwrite immediately, then
  3665. // it means that we need to wait until it does.
  3666. // also, that means that the chunk and cb are currently
  3667. // being processed, so move the buffer counter past them.
  3668. if (state.writing) {
  3669. c++;
  3670. break;
  3671. }
  3672. }
  3673. state.bufferProcessing = false;
  3674. if (c < state.buffer.length)
  3675. state.buffer = state.buffer.slice(c);
  3676. else
  3677. state.buffer.length = 0;
  3678. }
  3679. Writable.prototype._write = function(chunk, encoding, cb) {
  3680. cb(new Error('not implemented'));
  3681. };
  3682. Writable.prototype.end = function(chunk, encoding, cb) {
  3683. var state = this._writableState;
  3684. if (typeof chunk === 'function') {
  3685. cb = chunk;
  3686. chunk = null;
  3687. encoding = null;
  3688. } else if (typeof encoding === 'function') {
  3689. cb = encoding;
  3690. encoding = null;
  3691. }
  3692. if (typeof chunk !== 'undefined' && chunk !== null)
  3693. this.write(chunk, encoding);
  3694. // ignore unnecessary end() calls.
  3695. if (!state.ending && !state.finished)
  3696. endWritable(this, state, cb);
  3697. };
  3698. function needFinish(stream, state) {
  3699. return (state.ending &&
  3700. state.length === 0 &&
  3701. !state.finished &&
  3702. !state.writing);
  3703. }
  3704. function finishMaybe(stream, state) {
  3705. var need = needFinish(stream, state);
  3706. if (need) {
  3707. state.finished = true;
  3708. stream.emit('finish');
  3709. }
  3710. return need;
  3711. }
  3712. function endWritable(stream, state, cb) {
  3713. state.ending = true;
  3714. finishMaybe(stream, state);
  3715. if (cb) {
  3716. if (state.finished)
  3717. setImmediate(cb);
  3718. else
  3719. stream.once('finish', cb);
  3720. }
  3721. state.ended = true;
  3722. }
  3723. },{"./index.js":11,"buffer":7,"inherits":19,"process/browser.js":12}],17:[function(require,module,exports){
  3724. // Copyright Joyent, Inc. and other Node contributors.
  3725. //
  3726. // Permission is hereby granted, free of charge, to any person obtaining a
  3727. // copy of this software and associated documentation files (the
  3728. // "Software"), to deal in the Software without restriction, including
  3729. // without limitation the rights to use, copy, modify, merge, publish,
  3730. // distribute, sublicense, and/or sell copies of the Software, and to permit
  3731. // persons to whom the Software is furnished to do so, subject to the
  3732. // following conditions:
  3733. //
  3734. // The above copyright notice and this permission notice shall be included
  3735. // in all copies or substantial portions of the Software.
  3736. //
  3737. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  3738. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  3739. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  3740. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  3741. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  3742. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  3743. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  3744. var Buffer = require('buffer').Buffer;
  3745. function assertEncoding(encoding) {
  3746. if (encoding && !Buffer.isEncoding(encoding)) {
  3747. throw new Error('Unknown encoding: ' + encoding);
  3748. }
  3749. }
  3750. var StringDecoder = exports.StringDecoder = function(encoding) {
  3751. this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
  3752. assertEncoding(encoding);
  3753. switch (this.encoding) {
  3754. case 'utf8':
  3755. // CESU-8 represents each of Surrogate Pair by 3-bytes
  3756. this.surrogateSize = 3;
  3757. break;
  3758. case 'ucs2':
  3759. case 'utf16le':
  3760. // UTF-16 represents each of Surrogate Pair by 2-bytes
  3761. this.surrogateSize = 2;
  3762. this.detectIncompleteChar = utf16DetectIncompleteChar;
  3763. break;
  3764. case 'base64':
  3765. // Base-64 stores 3 bytes in 4 chars, and pads the remainder.
  3766. this.surrogateSize = 3;
  3767. this.detectIncompleteChar = base64DetectIncompleteChar;
  3768. break;
  3769. default:
  3770. this.write = passThroughWrite;
  3771. return;
  3772. }
  3773. this.charBuffer = new Buffer(6);
  3774. this.charReceived = 0;
  3775. this.charLength = 0;
  3776. };
  3777. StringDecoder.prototype.write = function(buffer) {
  3778. var charStr = '';
  3779. var offset = 0;
  3780. // if our last write ended with an incomplete multibyte character
  3781. while (this.charLength) {
  3782. // determine how many remaining bytes this buffer has to offer for this char
  3783. var i = (buffer.length >= this.charLength - this.charReceived) ?
  3784. this.charLength - this.charReceived :
  3785. buffer.length;
  3786. // add the new bytes to the char buffer
  3787. buffer.copy(this.charBuffer, this.charReceived, offset, i);
  3788. this.charReceived += (i - offset);
  3789. offset = i;
  3790. if (this.charReceived < this.charLength) {
  3791. // still not enough chars in this buffer? wait for more ...
  3792. return '';
  3793. }
  3794. // get the character that was split
  3795. charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
  3796. // lead surrogate (D800-DBFF) is also the incomplete character
  3797. var charCode = charStr.charCodeAt(charStr.length - 1);
  3798. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  3799. this.charLength += this.surrogateSize;
  3800. charStr = '';
  3801. continue;
  3802. }
  3803. this.charReceived = this.charLength = 0;
  3804. // if there are no more bytes in this buffer, just emit our char
  3805. if (i == buffer.length) return charStr;
  3806. // otherwise cut off the characters end from the beginning of this buffer
  3807. buffer = buffer.slice(i, buffer.length);
  3808. break;
  3809. }
  3810. var lenIncomplete = this.detectIncompleteChar(buffer);
  3811. var end = buffer.length;
  3812. if (this.charLength) {
  3813. // buffer the incomplete character bytes we got
  3814. buffer.copy(this.charBuffer, 0, buffer.length - lenIncomplete, end);
  3815. this.charReceived = lenIncomplete;
  3816. end -= lenIncomplete;
  3817. }
  3818. charStr += buffer.toString(this.encoding, 0, end);
  3819. var end = charStr.length - 1;
  3820. var charCode = charStr.charCodeAt(end);
  3821. // lead surrogate (D800-DBFF) is also the incomplete character
  3822. if (charCode >= 0xD800 && charCode <= 0xDBFF) {
  3823. var size = this.surrogateSize;
  3824. this.charLength += size;
  3825. this.charReceived += size;
  3826. this.charBuffer.copy(this.charBuffer, size, 0, size);
  3827. this.charBuffer.write(charStr.charAt(charStr.length - 1), this.encoding);
  3828. return charStr.substring(0, end);
  3829. }
  3830. // or just emit the charStr
  3831. return charStr;
  3832. };
  3833. StringDecoder.prototype.detectIncompleteChar = function(buffer) {
  3834. // determine how many bytes we have to check at the end of this buffer
  3835. var i = (buffer.length >= 3) ? 3 : buffer.length;
  3836. // Figure out if one of the last i bytes of our buffer announces an
  3837. // incomplete char.
  3838. for (; i > 0; i--) {
  3839. var c = buffer[buffer.length - i];
  3840. // See http://en.wikipedia.org/wiki/UTF-8#Description
  3841. // 110XXXXX
  3842. if (i == 1 && c >> 5 == 0x06) {
  3843. this.charLength = 2;
  3844. break;
  3845. }
  3846. // 1110XXXX
  3847. if (i <= 2 && c >> 4 == 0x0E) {
  3848. this.charLength = 3;
  3849. break;
  3850. }
  3851. // 11110XXX
  3852. if (i <= 3 && c >> 3 == 0x1E) {
  3853. this.charLength = 4;
  3854. break;
  3855. }
  3856. }
  3857. return i;
  3858. };
  3859. StringDecoder.prototype.end = function(buffer) {
  3860. var res = '';
  3861. if (buffer && buffer.length)
  3862. res = this.write(buffer);
  3863. if (this.charReceived) {
  3864. var cr = this.charReceived;
  3865. var buf = this.charBuffer;
  3866. var enc = this.encoding;
  3867. res += buf.slice(0, cr).toString(enc);
  3868. }
  3869. return res;
  3870. };
  3871. function passThroughWrite(buffer) {
  3872. return buffer.toString(this.encoding);
  3873. }
  3874. function utf16DetectIncompleteChar(buffer) {
  3875. var incomplete = this.charReceived = buffer.length % 2;
  3876. this.charLength = incomplete ? 2 : 0;
  3877. return incomplete;
  3878. }
  3879. function base64DetectIncompleteChar(buffer) {
  3880. var incomplete = this.charReceived = buffer.length % 3;
  3881. this.charLength = incomplete ? 3 : 0;
  3882. return incomplete;
  3883. }
  3884. },{"buffer":7}],18:[function(require,module,exports){
  3885. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  3886. var e, m
  3887. var eLen = (nBytes * 8) - mLen - 1
  3888. var eMax = (1 << eLen) - 1
  3889. var eBias = eMax >> 1
  3890. var nBits = -7
  3891. var i = isLE ? (nBytes - 1) : 0
  3892. var d = isLE ? -1 : 1
  3893. var s = buffer[offset + i]
  3894. i += d
  3895. e = s & ((1 << (-nBits)) - 1)
  3896. s >>= (-nBits)
  3897. nBits += eLen
  3898. for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  3899. m = e & ((1 << (-nBits)) - 1)
  3900. e >>= (-nBits)
  3901. nBits += mLen
  3902. for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  3903. if (e === 0) {
  3904. e = 1 - eBias
  3905. } else if (e === eMax) {
  3906. return m ? NaN : ((s ? -1 : 1) * Infinity)
  3907. } else {
  3908. m = m + Math.pow(2, mLen)
  3909. e = e - eBias
  3910. }
  3911. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  3912. }
  3913. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  3914. var e, m, c
  3915. var eLen = (nBytes * 8) - mLen - 1
  3916. var eMax = (1 << eLen) - 1
  3917. var eBias = eMax >> 1
  3918. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  3919. var i = isLE ? 0 : (nBytes - 1)
  3920. var d = isLE ? 1 : -1
  3921. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  3922. value = Math.abs(value)
  3923. if (isNaN(value) || value === Infinity) {
  3924. m = isNaN(value) ? 1 : 0
  3925. e = eMax
  3926. } else {
  3927. e = Math.floor(Math.log(value) / Math.LN2)
  3928. if (value * (c = Math.pow(2, -e)) < 1) {
  3929. e--
  3930. c *= 2
  3931. }
  3932. if (e + eBias >= 1) {
  3933. value += rt / c
  3934. } else {
  3935. value += rt * Math.pow(2, 1 - eBias)
  3936. }
  3937. if (value * c >= 2) {
  3938. e++
  3939. c /= 2
  3940. }
  3941. if (e + eBias >= eMax) {
  3942. m = 0
  3943. e = eMax
  3944. } else if (e + eBias >= 1) {
  3945. m = ((value * c) - 1) * Math.pow(2, mLen)
  3946. e = e + eBias
  3947. } else {
  3948. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  3949. e = 0
  3950. }
  3951. }
  3952. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  3953. e = (e << mLen) | m
  3954. eLen += mLen
  3955. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  3956. buffer[offset + i - d] |= s * 128
  3957. }
  3958. },{}],19:[function(require,module,exports){
  3959. module.exports=require(3)
  3960. },{}],20:[function(require,module,exports){
  3961. 'use strict';
  3962. var assert = require('assert');
  3963. var stream = require('stream');
  3964. var hash = require('../index');
  3965. describe('writeToStream', function() {
  3966. it('should emit information about an object to a stream', function() {
  3967. var strm = new stream.PassThrough();
  3968. hash.writeToStream({foo: 'bar'}, strm);
  3969. var result = strm.read().toString();
  3970. assert.strictEqual(typeof result, 'string');
  3971. assert.notStrictEqual(result.indexOf('foo'), -1);
  3972. assert.notStrictEqual(result.indexOf('bar'), -1);
  3973. });
  3974. it('should leave out keys when excludeValues = true', function() {
  3975. var strm = new stream.PassThrough();
  3976. hash.writeToStream({foo: 'bar'}, {excludeValues: true}, strm);
  3977. var result = strm.read().toString();
  3978. assert.strictEqual(typeof result, 'string');
  3979. assert.notStrictEqual(result.indexOf('foo'), -1);
  3980. assert. strictEqual(result.indexOf('bar'), -1);
  3981. });
  3982. });
  3983. },{"../index":1,"assert":2,"stream":11}]},{},[20])