tape.js 146 KB

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