xxhash.js 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["XXH"] = factory();
  8. else
  9. root["XXH"] = factory();
  10. })(typeof self !== 'undefined' ? self : this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, {
  50. /******/ configurable: false,
  51. /******/ enumerable: true,
  52. /******/ get: getter
  53. /******/ });
  54. /******/ }
  55. /******/ };
  56. /******/
  57. /******/ // getDefaultExport function for compatibility with non-harmony modules
  58. /******/ __webpack_require__.n = function(module) {
  59. /******/ var getter = module && module.__esModule ?
  60. /******/ function getDefault() { return module['default']; } :
  61. /******/ function getModuleExports() { return module; };
  62. /******/ __webpack_require__.d(getter, 'a', getter);
  63. /******/ return getter;
  64. /******/ };
  65. /******/
  66. /******/ // Object.prototype.hasOwnProperty.call
  67. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  68. /******/
  69. /******/ // __webpack_public_path__
  70. /******/ __webpack_require__.p = "";
  71. /******/
  72. /******/ // Load entry module and return exports
  73. /******/ return __webpack_require__(__webpack_require__.s = 2);
  74. /******/ })
  75. /************************************************************************/
  76. /******/ ([
  77. /* 0 */
  78. /***/ (function(module, exports, __webpack_require__) {
  79. "use strict";
  80. /* WEBPACK VAR INJECTION */(function(global) {/*!
  81. * The buffer module from node.js, for the browser.
  82. *
  83. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  84. * @license MIT
  85. */
  86. /* eslint-disable no-proto */
  87. var base64 = __webpack_require__(5)
  88. var ieee754 = __webpack_require__(6)
  89. var isArray = __webpack_require__(7)
  90. exports.Buffer = Buffer
  91. exports.SlowBuffer = SlowBuffer
  92. exports.INSPECT_MAX_BYTES = 50
  93. /**
  94. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  95. * === true Use Uint8Array implementation (fastest)
  96. * === false Use Object implementation (most compatible, even IE6)
  97. *
  98. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  99. * Opera 11.6+, iOS 4.2+.
  100. *
  101. * Due to various browser bugs, sometimes the Object implementation will be used even
  102. * when the browser supports typed arrays.
  103. *
  104. * Note:
  105. *
  106. * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
  107. * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
  108. *
  109. * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
  110. *
  111. * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
  112. * incorrect length in some situations.
  113. * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
  114. * get the Object implementation, which is slower but behaves correctly.
  115. */
  116. Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
  117. ? global.TYPED_ARRAY_SUPPORT
  118. : typedArraySupport()
  119. /*
  120. * Export kMaxLength after typed array support is determined.
  121. */
  122. exports.kMaxLength = kMaxLength()
  123. function typedArraySupport () {
  124. try {
  125. var arr = new Uint8Array(1)
  126. arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
  127. return arr.foo() === 42 && // typed array instances can be augmented
  128. typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
  129. arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
  130. } catch (e) {
  131. return false
  132. }
  133. }
  134. function kMaxLength () {
  135. return Buffer.TYPED_ARRAY_SUPPORT
  136. ? 0x7fffffff
  137. : 0x3fffffff
  138. }
  139. function createBuffer (that, length) {
  140. if (kMaxLength() < length) {
  141. throw new RangeError('Invalid typed array length')
  142. }
  143. if (Buffer.TYPED_ARRAY_SUPPORT) {
  144. // Return an augmented `Uint8Array` instance, for best performance
  145. that = new Uint8Array(length)
  146. that.__proto__ = Buffer.prototype
  147. } else {
  148. // Fallback: Return an object instance of the Buffer class
  149. if (that === null) {
  150. that = new Buffer(length)
  151. }
  152. that.length = length
  153. }
  154. return that
  155. }
  156. /**
  157. * The Buffer constructor returns instances of `Uint8Array` that have their
  158. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  159. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  160. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  161. * returns a single octet.
  162. *
  163. * The `Uint8Array` prototype remains unmodified.
  164. */
  165. function Buffer (arg, encodingOrOffset, length) {
  166. if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
  167. return new Buffer(arg, encodingOrOffset, length)
  168. }
  169. // Common case.
  170. if (typeof arg === 'number') {
  171. if (typeof encodingOrOffset === 'string') {
  172. throw new Error(
  173. 'If encoding is specified then the first argument must be a string'
  174. )
  175. }
  176. return allocUnsafe(this, arg)
  177. }
  178. return from(this, arg, encodingOrOffset, length)
  179. }
  180. Buffer.poolSize = 8192 // not used by this implementation
  181. // TODO: Legacy, not needed anymore. Remove in next major version.
  182. Buffer._augment = function (arr) {
  183. arr.__proto__ = Buffer.prototype
  184. return arr
  185. }
  186. function from (that, value, encodingOrOffset, length) {
  187. if (typeof value === 'number') {
  188. throw new TypeError('"value" argument must not be a number')
  189. }
  190. if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
  191. return fromArrayBuffer(that, value, encodingOrOffset, length)
  192. }
  193. if (typeof value === 'string') {
  194. return fromString(that, value, encodingOrOffset)
  195. }
  196. return fromObject(that, value)
  197. }
  198. /**
  199. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  200. * if value is a number.
  201. * Buffer.from(str[, encoding])
  202. * Buffer.from(array)
  203. * Buffer.from(buffer)
  204. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  205. **/
  206. Buffer.from = function (value, encodingOrOffset, length) {
  207. return from(null, value, encodingOrOffset, length)
  208. }
  209. if (Buffer.TYPED_ARRAY_SUPPORT) {
  210. Buffer.prototype.__proto__ = Uint8Array.prototype
  211. Buffer.__proto__ = Uint8Array
  212. if (typeof Symbol !== 'undefined' && Symbol.species &&
  213. Buffer[Symbol.species] === Buffer) {
  214. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  215. Object.defineProperty(Buffer, Symbol.species, {
  216. value: null,
  217. configurable: true
  218. })
  219. }
  220. }
  221. function assertSize (size) {
  222. if (typeof size !== 'number') {
  223. throw new TypeError('"size" argument must be a number')
  224. } else if (size < 0) {
  225. throw new RangeError('"size" argument must not be negative')
  226. }
  227. }
  228. function alloc (that, size, fill, encoding) {
  229. assertSize(size)
  230. if (size <= 0) {
  231. return createBuffer(that, size)
  232. }
  233. if (fill !== undefined) {
  234. // Only pay attention to encoding if it's a string. This
  235. // prevents accidentally sending in a number that would
  236. // be interpretted as a start offset.
  237. return typeof encoding === 'string'
  238. ? createBuffer(that, size).fill(fill, encoding)
  239. : createBuffer(that, size).fill(fill)
  240. }
  241. return createBuffer(that, size)
  242. }
  243. /**
  244. * Creates a new filled Buffer instance.
  245. * alloc(size[, fill[, encoding]])
  246. **/
  247. Buffer.alloc = function (size, fill, encoding) {
  248. return alloc(null, size, fill, encoding)
  249. }
  250. function allocUnsafe (that, size) {
  251. assertSize(size)
  252. that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
  253. if (!Buffer.TYPED_ARRAY_SUPPORT) {
  254. for (var i = 0; i < size; ++i) {
  255. that[i] = 0
  256. }
  257. }
  258. return that
  259. }
  260. /**
  261. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  262. * */
  263. Buffer.allocUnsafe = function (size) {
  264. return allocUnsafe(null, size)
  265. }
  266. /**
  267. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  268. */
  269. Buffer.allocUnsafeSlow = function (size) {
  270. return allocUnsafe(null, size)
  271. }
  272. function fromString (that, string, encoding) {
  273. if (typeof encoding !== 'string' || encoding === '') {
  274. encoding = 'utf8'
  275. }
  276. if (!Buffer.isEncoding(encoding)) {
  277. throw new TypeError('"encoding" must be a valid string encoding')
  278. }
  279. var length = byteLength(string, encoding) | 0
  280. that = createBuffer(that, length)
  281. var actual = that.write(string, encoding)
  282. if (actual !== length) {
  283. // Writing a hex string, for example, that contains invalid characters will
  284. // cause everything after the first invalid character to be ignored. (e.g.
  285. // 'abxxcd' will be treated as 'ab')
  286. that = that.slice(0, actual)
  287. }
  288. return that
  289. }
  290. function fromArrayLike (that, array) {
  291. var length = array.length < 0 ? 0 : checked(array.length) | 0
  292. that = createBuffer(that, length)
  293. for (var i = 0; i < length; i += 1) {
  294. that[i] = array[i] & 255
  295. }
  296. return that
  297. }
  298. function fromArrayBuffer (that, array, byteOffset, length) {
  299. array.byteLength // this throws if `array` is not a valid ArrayBuffer
  300. if (byteOffset < 0 || array.byteLength < byteOffset) {
  301. throw new RangeError('\'offset\' is out of bounds')
  302. }
  303. if (array.byteLength < byteOffset + (length || 0)) {
  304. throw new RangeError('\'length\' is out of bounds')
  305. }
  306. if (byteOffset === undefined && length === undefined) {
  307. array = new Uint8Array(array)
  308. } else if (length === undefined) {
  309. array = new Uint8Array(array, byteOffset)
  310. } else {
  311. array = new Uint8Array(array, byteOffset, length)
  312. }
  313. if (Buffer.TYPED_ARRAY_SUPPORT) {
  314. // Return an augmented `Uint8Array` instance, for best performance
  315. that = array
  316. that.__proto__ = Buffer.prototype
  317. } else {
  318. // Fallback: Return an object instance of the Buffer class
  319. that = fromArrayLike(that, array)
  320. }
  321. return that
  322. }
  323. function fromObject (that, obj) {
  324. if (Buffer.isBuffer(obj)) {
  325. var len = checked(obj.length) | 0
  326. that = createBuffer(that, len)
  327. if (that.length === 0) {
  328. return that
  329. }
  330. obj.copy(that, 0, 0, len)
  331. return that
  332. }
  333. if (obj) {
  334. if ((typeof ArrayBuffer !== 'undefined' &&
  335. obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
  336. if (typeof obj.length !== 'number' || isnan(obj.length)) {
  337. return createBuffer(that, 0)
  338. }
  339. return fromArrayLike(that, obj)
  340. }
  341. if (obj.type === 'Buffer' && isArray(obj.data)) {
  342. return fromArrayLike(that, obj.data)
  343. }
  344. }
  345. throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
  346. }
  347. function checked (length) {
  348. // Note: cannot use `length < kMaxLength()` here because that fails when
  349. // length is NaN (which is otherwise coerced to zero.)
  350. if (length >= kMaxLength()) {
  351. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  352. 'size: 0x' + kMaxLength().toString(16) + ' bytes')
  353. }
  354. return length | 0
  355. }
  356. function SlowBuffer (length) {
  357. if (+length != length) { // eslint-disable-line eqeqeq
  358. length = 0
  359. }
  360. return Buffer.alloc(+length)
  361. }
  362. Buffer.isBuffer = function isBuffer (b) {
  363. return !!(b != null && b._isBuffer)
  364. }
  365. Buffer.compare = function compare (a, b) {
  366. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  367. throw new TypeError('Arguments must be Buffers')
  368. }
  369. if (a === b) return 0
  370. var x = a.length
  371. var y = b.length
  372. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  373. if (a[i] !== b[i]) {
  374. x = a[i]
  375. y = b[i]
  376. break
  377. }
  378. }
  379. if (x < y) return -1
  380. if (y < x) return 1
  381. return 0
  382. }
  383. Buffer.isEncoding = function isEncoding (encoding) {
  384. switch (String(encoding).toLowerCase()) {
  385. case 'hex':
  386. case 'utf8':
  387. case 'utf-8':
  388. case 'ascii':
  389. case 'latin1':
  390. case 'binary':
  391. case 'base64':
  392. case 'ucs2':
  393. case 'ucs-2':
  394. case 'utf16le':
  395. case 'utf-16le':
  396. return true
  397. default:
  398. return false
  399. }
  400. }
  401. Buffer.concat = function concat (list, length) {
  402. if (!isArray(list)) {
  403. throw new TypeError('"list" argument must be an Array of Buffers')
  404. }
  405. if (list.length === 0) {
  406. return Buffer.alloc(0)
  407. }
  408. var i
  409. if (length === undefined) {
  410. length = 0
  411. for (i = 0; i < list.length; ++i) {
  412. length += list[i].length
  413. }
  414. }
  415. var buffer = Buffer.allocUnsafe(length)
  416. var pos = 0
  417. for (i = 0; i < list.length; ++i) {
  418. var buf = list[i]
  419. if (!Buffer.isBuffer(buf)) {
  420. throw new TypeError('"list" argument must be an Array of Buffers')
  421. }
  422. buf.copy(buffer, pos)
  423. pos += buf.length
  424. }
  425. return buffer
  426. }
  427. function byteLength (string, encoding) {
  428. if (Buffer.isBuffer(string)) {
  429. return string.length
  430. }
  431. if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
  432. (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
  433. return string.byteLength
  434. }
  435. if (typeof string !== 'string') {
  436. string = '' + string
  437. }
  438. var len = string.length
  439. if (len === 0) return 0
  440. // Use a for loop to avoid recursion
  441. var loweredCase = false
  442. for (;;) {
  443. switch (encoding) {
  444. case 'ascii':
  445. case 'latin1':
  446. case 'binary':
  447. return len
  448. case 'utf8':
  449. case 'utf-8':
  450. case undefined:
  451. return utf8ToBytes(string).length
  452. case 'ucs2':
  453. case 'ucs-2':
  454. case 'utf16le':
  455. case 'utf-16le':
  456. return len * 2
  457. case 'hex':
  458. return len >>> 1
  459. case 'base64':
  460. return base64ToBytes(string).length
  461. default:
  462. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  463. encoding = ('' + encoding).toLowerCase()
  464. loweredCase = true
  465. }
  466. }
  467. }
  468. Buffer.byteLength = byteLength
  469. function slowToString (encoding, start, end) {
  470. var loweredCase = false
  471. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  472. // property of a typed array.
  473. // This behaves neither like String nor Uint8Array in that we set start/end
  474. // to their upper/lower bounds if the value passed is out of range.
  475. // undefined is handled specially as per ECMA-262 6th Edition,
  476. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  477. if (start === undefined || start < 0) {
  478. start = 0
  479. }
  480. // Return early if start > this.length. Done here to prevent potential uint32
  481. // coercion fail below.
  482. if (start > this.length) {
  483. return ''
  484. }
  485. if (end === undefined || end > this.length) {
  486. end = this.length
  487. }
  488. if (end <= 0) {
  489. return ''
  490. }
  491. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  492. end >>>= 0
  493. start >>>= 0
  494. if (end <= start) {
  495. return ''
  496. }
  497. if (!encoding) encoding = 'utf8'
  498. while (true) {
  499. switch (encoding) {
  500. case 'hex':
  501. return hexSlice(this, start, end)
  502. case 'utf8':
  503. case 'utf-8':
  504. return utf8Slice(this, start, end)
  505. case 'ascii':
  506. return asciiSlice(this, start, end)
  507. case 'latin1':
  508. case 'binary':
  509. return latin1Slice(this, start, end)
  510. case 'base64':
  511. return base64Slice(this, start, end)
  512. case 'ucs2':
  513. case 'ucs-2':
  514. case 'utf16le':
  515. case 'utf-16le':
  516. return utf16leSlice(this, start, end)
  517. default:
  518. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  519. encoding = (encoding + '').toLowerCase()
  520. loweredCase = true
  521. }
  522. }
  523. }
  524. // The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
  525. // Buffer instances.
  526. Buffer.prototype._isBuffer = true
  527. function swap (b, n, m) {
  528. var i = b[n]
  529. b[n] = b[m]
  530. b[m] = i
  531. }
  532. Buffer.prototype.swap16 = function swap16 () {
  533. var len = this.length
  534. if (len % 2 !== 0) {
  535. throw new RangeError('Buffer size must be a multiple of 16-bits')
  536. }
  537. for (var i = 0; i < len; i += 2) {
  538. swap(this, i, i + 1)
  539. }
  540. return this
  541. }
  542. Buffer.prototype.swap32 = function swap32 () {
  543. var len = this.length
  544. if (len % 4 !== 0) {
  545. throw new RangeError('Buffer size must be a multiple of 32-bits')
  546. }
  547. for (var i = 0; i < len; i += 4) {
  548. swap(this, i, i + 3)
  549. swap(this, i + 1, i + 2)
  550. }
  551. return this
  552. }
  553. Buffer.prototype.swap64 = function swap64 () {
  554. var len = this.length
  555. if (len % 8 !== 0) {
  556. throw new RangeError('Buffer size must be a multiple of 64-bits')
  557. }
  558. for (var i = 0; i < len; i += 8) {
  559. swap(this, i, i + 7)
  560. swap(this, i + 1, i + 6)
  561. swap(this, i + 2, i + 5)
  562. swap(this, i + 3, i + 4)
  563. }
  564. return this
  565. }
  566. Buffer.prototype.toString = function toString () {
  567. var length = this.length | 0
  568. if (length === 0) return ''
  569. if (arguments.length === 0) return utf8Slice(this, 0, length)
  570. return slowToString.apply(this, arguments)
  571. }
  572. Buffer.prototype.equals = function equals (b) {
  573. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  574. if (this === b) return true
  575. return Buffer.compare(this, b) === 0
  576. }
  577. Buffer.prototype.inspect = function inspect () {
  578. var str = ''
  579. var max = exports.INSPECT_MAX_BYTES
  580. if (this.length > 0) {
  581. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  582. if (this.length > max) str += ' ... '
  583. }
  584. return '<Buffer ' + str + '>'
  585. }
  586. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  587. if (!Buffer.isBuffer(target)) {
  588. throw new TypeError('Argument must be a Buffer')
  589. }
  590. if (start === undefined) {
  591. start = 0
  592. }
  593. if (end === undefined) {
  594. end = target ? target.length : 0
  595. }
  596. if (thisStart === undefined) {
  597. thisStart = 0
  598. }
  599. if (thisEnd === undefined) {
  600. thisEnd = this.length
  601. }
  602. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  603. throw new RangeError('out of range index')
  604. }
  605. if (thisStart >= thisEnd && start >= end) {
  606. return 0
  607. }
  608. if (thisStart >= thisEnd) {
  609. return -1
  610. }
  611. if (start >= end) {
  612. return 1
  613. }
  614. start >>>= 0
  615. end >>>= 0
  616. thisStart >>>= 0
  617. thisEnd >>>= 0
  618. if (this === target) return 0
  619. var x = thisEnd - thisStart
  620. var y = end - start
  621. var len = Math.min(x, y)
  622. var thisCopy = this.slice(thisStart, thisEnd)
  623. var targetCopy = target.slice(start, end)
  624. for (var i = 0; i < len; ++i) {
  625. if (thisCopy[i] !== targetCopy[i]) {
  626. x = thisCopy[i]
  627. y = targetCopy[i]
  628. break
  629. }
  630. }
  631. if (x < y) return -1
  632. if (y < x) return 1
  633. return 0
  634. }
  635. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  636. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  637. //
  638. // Arguments:
  639. // - buffer - a Buffer to search
  640. // - val - a string, Buffer, or number
  641. // - byteOffset - an index into `buffer`; will be clamped to an int32
  642. // - encoding - an optional encoding, relevant is val is a string
  643. // - dir - true for indexOf, false for lastIndexOf
  644. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  645. // Empty buffer means no match
  646. if (buffer.length === 0) return -1
  647. // Normalize byteOffset
  648. if (typeof byteOffset === 'string') {
  649. encoding = byteOffset
  650. byteOffset = 0
  651. } else if (byteOffset > 0x7fffffff) {
  652. byteOffset = 0x7fffffff
  653. } else if (byteOffset < -0x80000000) {
  654. byteOffset = -0x80000000
  655. }
  656. byteOffset = +byteOffset // Coerce to Number.
  657. if (isNaN(byteOffset)) {
  658. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  659. byteOffset = dir ? 0 : (buffer.length - 1)
  660. }
  661. // Normalize byteOffset: negative offsets start from the end of the buffer
  662. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  663. if (byteOffset >= buffer.length) {
  664. if (dir) return -1
  665. else byteOffset = buffer.length - 1
  666. } else if (byteOffset < 0) {
  667. if (dir) byteOffset = 0
  668. else return -1
  669. }
  670. // Normalize val
  671. if (typeof val === 'string') {
  672. val = Buffer.from(val, encoding)
  673. }
  674. // Finally, search either indexOf (if dir is true) or lastIndexOf
  675. if (Buffer.isBuffer(val)) {
  676. // Special case: looking for empty string/buffer always fails
  677. if (val.length === 0) {
  678. return -1
  679. }
  680. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  681. } else if (typeof val === 'number') {
  682. val = val & 0xFF // Search for a byte value [0-255]
  683. if (Buffer.TYPED_ARRAY_SUPPORT &&
  684. typeof Uint8Array.prototype.indexOf === 'function') {
  685. if (dir) {
  686. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  687. } else {
  688. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  689. }
  690. }
  691. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  692. }
  693. throw new TypeError('val must be string, number or Buffer')
  694. }
  695. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  696. var indexSize = 1
  697. var arrLength = arr.length
  698. var valLength = val.length
  699. if (encoding !== undefined) {
  700. encoding = String(encoding).toLowerCase()
  701. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  702. encoding === 'utf16le' || encoding === 'utf-16le') {
  703. if (arr.length < 2 || val.length < 2) {
  704. return -1
  705. }
  706. indexSize = 2
  707. arrLength /= 2
  708. valLength /= 2
  709. byteOffset /= 2
  710. }
  711. }
  712. function read (buf, i) {
  713. if (indexSize === 1) {
  714. return buf[i]
  715. } else {
  716. return buf.readUInt16BE(i * indexSize)
  717. }
  718. }
  719. var i
  720. if (dir) {
  721. var foundIndex = -1
  722. for (i = byteOffset; i < arrLength; i++) {
  723. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  724. if (foundIndex === -1) foundIndex = i
  725. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  726. } else {
  727. if (foundIndex !== -1) i -= i - foundIndex
  728. foundIndex = -1
  729. }
  730. }
  731. } else {
  732. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  733. for (i = byteOffset; i >= 0; i--) {
  734. var found = true
  735. for (var j = 0; j < valLength; j++) {
  736. if (read(arr, i + j) !== read(val, j)) {
  737. found = false
  738. break
  739. }
  740. }
  741. if (found) return i
  742. }
  743. }
  744. return -1
  745. }
  746. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  747. return this.indexOf(val, byteOffset, encoding) !== -1
  748. }
  749. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  750. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  751. }
  752. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  753. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  754. }
  755. function hexWrite (buf, string, offset, length) {
  756. offset = Number(offset) || 0
  757. var remaining = buf.length - offset
  758. if (!length) {
  759. length = remaining
  760. } else {
  761. length = Number(length)
  762. if (length > remaining) {
  763. length = remaining
  764. }
  765. }
  766. // must be an even number of digits
  767. var strLen = string.length
  768. if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
  769. if (length > strLen / 2) {
  770. length = strLen / 2
  771. }
  772. for (var i = 0; i < length; ++i) {
  773. var parsed = parseInt(string.substr(i * 2, 2), 16)
  774. if (isNaN(parsed)) return i
  775. buf[offset + i] = parsed
  776. }
  777. return i
  778. }
  779. function utf8Write (buf, string, offset, length) {
  780. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  781. }
  782. function asciiWrite (buf, string, offset, length) {
  783. return blitBuffer(asciiToBytes(string), buf, offset, length)
  784. }
  785. function latin1Write (buf, string, offset, length) {
  786. return asciiWrite(buf, string, offset, length)
  787. }
  788. function base64Write (buf, string, offset, length) {
  789. return blitBuffer(base64ToBytes(string), buf, offset, length)
  790. }
  791. function ucs2Write (buf, string, offset, length) {
  792. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  793. }
  794. Buffer.prototype.write = function write (string, offset, length, encoding) {
  795. // Buffer#write(string)
  796. if (offset === undefined) {
  797. encoding = 'utf8'
  798. length = this.length
  799. offset = 0
  800. // Buffer#write(string, encoding)
  801. } else if (length === undefined && typeof offset === 'string') {
  802. encoding = offset
  803. length = this.length
  804. offset = 0
  805. // Buffer#write(string, offset[, length][, encoding])
  806. } else if (isFinite(offset)) {
  807. offset = offset | 0
  808. if (isFinite(length)) {
  809. length = length | 0
  810. if (encoding === undefined) encoding = 'utf8'
  811. } else {
  812. encoding = length
  813. length = undefined
  814. }
  815. // legacy write(string, encoding, offset, length) - remove in v0.13
  816. } else {
  817. throw new Error(
  818. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  819. )
  820. }
  821. var remaining = this.length - offset
  822. if (length === undefined || length > remaining) length = remaining
  823. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  824. throw new RangeError('Attempt to write outside buffer bounds')
  825. }
  826. if (!encoding) encoding = 'utf8'
  827. var loweredCase = false
  828. for (;;) {
  829. switch (encoding) {
  830. case 'hex':
  831. return hexWrite(this, string, offset, length)
  832. case 'utf8':
  833. case 'utf-8':
  834. return utf8Write(this, string, offset, length)
  835. case 'ascii':
  836. return asciiWrite(this, string, offset, length)
  837. case 'latin1':
  838. case 'binary':
  839. return latin1Write(this, string, offset, length)
  840. case 'base64':
  841. // Warning: maxLength not taken into account in base64Write
  842. return base64Write(this, string, offset, length)
  843. case 'ucs2':
  844. case 'ucs-2':
  845. case 'utf16le':
  846. case 'utf-16le':
  847. return ucs2Write(this, string, offset, length)
  848. default:
  849. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  850. encoding = ('' + encoding).toLowerCase()
  851. loweredCase = true
  852. }
  853. }
  854. }
  855. Buffer.prototype.toJSON = function toJSON () {
  856. return {
  857. type: 'Buffer',
  858. data: Array.prototype.slice.call(this._arr || this, 0)
  859. }
  860. }
  861. function base64Slice (buf, start, end) {
  862. if (start === 0 && end === buf.length) {
  863. return base64.fromByteArray(buf)
  864. } else {
  865. return base64.fromByteArray(buf.slice(start, end))
  866. }
  867. }
  868. function utf8Slice (buf, start, end) {
  869. end = Math.min(buf.length, end)
  870. var res = []
  871. var i = start
  872. while (i < end) {
  873. var firstByte = buf[i]
  874. var codePoint = null
  875. var bytesPerSequence = (firstByte > 0xEF) ? 4
  876. : (firstByte > 0xDF) ? 3
  877. : (firstByte > 0xBF) ? 2
  878. : 1
  879. if (i + bytesPerSequence <= end) {
  880. var secondByte, thirdByte, fourthByte, tempCodePoint
  881. switch (bytesPerSequence) {
  882. case 1:
  883. if (firstByte < 0x80) {
  884. codePoint = firstByte
  885. }
  886. break
  887. case 2:
  888. secondByte = buf[i + 1]
  889. if ((secondByte & 0xC0) === 0x80) {
  890. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  891. if (tempCodePoint > 0x7F) {
  892. codePoint = tempCodePoint
  893. }
  894. }
  895. break
  896. case 3:
  897. secondByte = buf[i + 1]
  898. thirdByte = buf[i + 2]
  899. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  900. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  901. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  902. codePoint = tempCodePoint
  903. }
  904. }
  905. break
  906. case 4:
  907. secondByte = buf[i + 1]
  908. thirdByte = buf[i + 2]
  909. fourthByte = buf[i + 3]
  910. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  911. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  912. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  913. codePoint = tempCodePoint
  914. }
  915. }
  916. }
  917. }
  918. if (codePoint === null) {
  919. // we did not generate a valid codePoint so insert a
  920. // replacement char (U+FFFD) and advance only 1 byte
  921. codePoint = 0xFFFD
  922. bytesPerSequence = 1
  923. } else if (codePoint > 0xFFFF) {
  924. // encode to utf16 (surrogate pair dance)
  925. codePoint -= 0x10000
  926. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  927. codePoint = 0xDC00 | codePoint & 0x3FF
  928. }
  929. res.push(codePoint)
  930. i += bytesPerSequence
  931. }
  932. return decodeCodePointsArray(res)
  933. }
  934. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  935. // the lowest limit is Chrome, with 0x10000 args.
  936. // We go 1 magnitude less, for safety
  937. var MAX_ARGUMENTS_LENGTH = 0x1000
  938. function decodeCodePointsArray (codePoints) {
  939. var len = codePoints.length
  940. if (len <= MAX_ARGUMENTS_LENGTH) {
  941. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  942. }
  943. // Decode in chunks to avoid "call stack size exceeded".
  944. var res = ''
  945. var i = 0
  946. while (i < len) {
  947. res += String.fromCharCode.apply(
  948. String,
  949. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  950. )
  951. }
  952. return res
  953. }
  954. function asciiSlice (buf, start, end) {
  955. var ret = ''
  956. end = Math.min(buf.length, end)
  957. for (var i = start; i < end; ++i) {
  958. ret += String.fromCharCode(buf[i] & 0x7F)
  959. }
  960. return ret
  961. }
  962. function latin1Slice (buf, start, end) {
  963. var ret = ''
  964. end = Math.min(buf.length, end)
  965. for (var i = start; i < end; ++i) {
  966. ret += String.fromCharCode(buf[i])
  967. }
  968. return ret
  969. }
  970. function hexSlice (buf, start, end) {
  971. var len = buf.length
  972. if (!start || start < 0) start = 0
  973. if (!end || end < 0 || end > len) end = len
  974. var out = ''
  975. for (var i = start; i < end; ++i) {
  976. out += toHex(buf[i])
  977. }
  978. return out
  979. }
  980. function utf16leSlice (buf, start, end) {
  981. var bytes = buf.slice(start, end)
  982. var res = ''
  983. for (var i = 0; i < bytes.length; i += 2) {
  984. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
  985. }
  986. return res
  987. }
  988. Buffer.prototype.slice = function slice (start, end) {
  989. var len = this.length
  990. start = ~~start
  991. end = end === undefined ? len : ~~end
  992. if (start < 0) {
  993. start += len
  994. if (start < 0) start = 0
  995. } else if (start > len) {
  996. start = len
  997. }
  998. if (end < 0) {
  999. end += len
  1000. if (end < 0) end = 0
  1001. } else if (end > len) {
  1002. end = len
  1003. }
  1004. if (end < start) end = start
  1005. var newBuf
  1006. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1007. newBuf = this.subarray(start, end)
  1008. newBuf.__proto__ = Buffer.prototype
  1009. } else {
  1010. var sliceLen = end - start
  1011. newBuf = new Buffer(sliceLen, undefined)
  1012. for (var i = 0; i < sliceLen; ++i) {
  1013. newBuf[i] = this[i + start]
  1014. }
  1015. }
  1016. return newBuf
  1017. }
  1018. /*
  1019. * Need to make sure that buffer isn't trying to write out of bounds.
  1020. */
  1021. function checkOffset (offset, ext, length) {
  1022. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  1023. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  1024. }
  1025. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  1026. offset = offset | 0
  1027. byteLength = byteLength | 0
  1028. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1029. var val = this[offset]
  1030. var mul = 1
  1031. var i = 0
  1032. while (++i < byteLength && (mul *= 0x100)) {
  1033. val += this[offset + i] * mul
  1034. }
  1035. return val
  1036. }
  1037. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  1038. offset = offset | 0
  1039. byteLength = byteLength | 0
  1040. if (!noAssert) {
  1041. checkOffset(offset, byteLength, this.length)
  1042. }
  1043. var val = this[offset + --byteLength]
  1044. var mul = 1
  1045. while (byteLength > 0 && (mul *= 0x100)) {
  1046. val += this[offset + --byteLength] * mul
  1047. }
  1048. return val
  1049. }
  1050. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  1051. if (!noAssert) checkOffset(offset, 1, this.length)
  1052. return this[offset]
  1053. }
  1054. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  1055. if (!noAssert) checkOffset(offset, 2, this.length)
  1056. return this[offset] | (this[offset + 1] << 8)
  1057. }
  1058. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  1059. if (!noAssert) checkOffset(offset, 2, this.length)
  1060. return (this[offset] << 8) | this[offset + 1]
  1061. }
  1062. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  1063. if (!noAssert) checkOffset(offset, 4, this.length)
  1064. return ((this[offset]) |
  1065. (this[offset + 1] << 8) |
  1066. (this[offset + 2] << 16)) +
  1067. (this[offset + 3] * 0x1000000)
  1068. }
  1069. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  1070. if (!noAssert) checkOffset(offset, 4, this.length)
  1071. return (this[offset] * 0x1000000) +
  1072. ((this[offset + 1] << 16) |
  1073. (this[offset + 2] << 8) |
  1074. this[offset + 3])
  1075. }
  1076. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  1077. offset = offset | 0
  1078. byteLength = byteLength | 0
  1079. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1080. var val = this[offset]
  1081. var mul = 1
  1082. var i = 0
  1083. while (++i < byteLength && (mul *= 0x100)) {
  1084. val += this[offset + i] * mul
  1085. }
  1086. mul *= 0x80
  1087. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1088. return val
  1089. }
  1090. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  1091. offset = offset | 0
  1092. byteLength = byteLength | 0
  1093. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1094. var i = byteLength
  1095. var mul = 1
  1096. var val = this[offset + --i]
  1097. while (i > 0 && (mul *= 0x100)) {
  1098. val += this[offset + --i] * mul
  1099. }
  1100. mul *= 0x80
  1101. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1102. return val
  1103. }
  1104. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  1105. if (!noAssert) checkOffset(offset, 1, this.length)
  1106. if (!(this[offset] & 0x80)) return (this[offset])
  1107. return ((0xff - this[offset] + 1) * -1)
  1108. }
  1109. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  1110. if (!noAssert) checkOffset(offset, 2, this.length)
  1111. var val = this[offset] | (this[offset + 1] << 8)
  1112. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1113. }
  1114. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  1115. if (!noAssert) checkOffset(offset, 2, this.length)
  1116. var val = this[offset + 1] | (this[offset] << 8)
  1117. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1118. }
  1119. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  1120. if (!noAssert) checkOffset(offset, 4, this.length)
  1121. return (this[offset]) |
  1122. (this[offset + 1] << 8) |
  1123. (this[offset + 2] << 16) |
  1124. (this[offset + 3] << 24)
  1125. }
  1126. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  1127. if (!noAssert) checkOffset(offset, 4, this.length)
  1128. return (this[offset] << 24) |
  1129. (this[offset + 1] << 16) |
  1130. (this[offset + 2] << 8) |
  1131. (this[offset + 3])
  1132. }
  1133. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  1134. if (!noAssert) checkOffset(offset, 4, this.length)
  1135. return ieee754.read(this, offset, true, 23, 4)
  1136. }
  1137. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  1138. if (!noAssert) checkOffset(offset, 4, this.length)
  1139. return ieee754.read(this, offset, false, 23, 4)
  1140. }
  1141. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  1142. if (!noAssert) checkOffset(offset, 8, this.length)
  1143. return ieee754.read(this, offset, true, 52, 8)
  1144. }
  1145. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  1146. if (!noAssert) checkOffset(offset, 8, this.length)
  1147. return ieee754.read(this, offset, false, 52, 8)
  1148. }
  1149. function checkInt (buf, value, offset, ext, max, min) {
  1150. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  1151. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  1152. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1153. }
  1154. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  1155. value = +value
  1156. offset = offset | 0
  1157. byteLength = byteLength | 0
  1158. if (!noAssert) {
  1159. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  1160. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1161. }
  1162. var mul = 1
  1163. var i = 0
  1164. this[offset] = value & 0xFF
  1165. while (++i < byteLength && (mul *= 0x100)) {
  1166. this[offset + i] = (value / mul) & 0xFF
  1167. }
  1168. return offset + byteLength
  1169. }
  1170. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  1171. value = +value
  1172. offset = offset | 0
  1173. byteLength = byteLength | 0
  1174. if (!noAssert) {
  1175. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  1176. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1177. }
  1178. var i = byteLength - 1
  1179. var mul = 1
  1180. this[offset + i] = value & 0xFF
  1181. while (--i >= 0 && (mul *= 0x100)) {
  1182. this[offset + i] = (value / mul) & 0xFF
  1183. }
  1184. return offset + byteLength
  1185. }
  1186. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  1187. value = +value
  1188. offset = offset | 0
  1189. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  1190. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  1191. this[offset] = (value & 0xff)
  1192. return offset + 1
  1193. }
  1194. function objectWriteUInt16 (buf, value, offset, littleEndian) {
  1195. if (value < 0) value = 0xffff + value + 1
  1196. for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
  1197. buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
  1198. (littleEndian ? i : 1 - i) * 8
  1199. }
  1200. }
  1201. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  1202. value = +value
  1203. offset = offset | 0
  1204. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1205. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1206. this[offset] = (value & 0xff)
  1207. this[offset + 1] = (value >>> 8)
  1208. } else {
  1209. objectWriteUInt16(this, value, offset, true)
  1210. }
  1211. return offset + 2
  1212. }
  1213. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  1214. value = +value
  1215. offset = offset | 0
  1216. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1217. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1218. this[offset] = (value >>> 8)
  1219. this[offset + 1] = (value & 0xff)
  1220. } else {
  1221. objectWriteUInt16(this, value, offset, false)
  1222. }
  1223. return offset + 2
  1224. }
  1225. function objectWriteUInt32 (buf, value, offset, littleEndian) {
  1226. if (value < 0) value = 0xffffffff + value + 1
  1227. for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
  1228. buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
  1229. }
  1230. }
  1231. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  1232. value = +value
  1233. offset = offset | 0
  1234. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1235. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1236. this[offset + 3] = (value >>> 24)
  1237. this[offset + 2] = (value >>> 16)
  1238. this[offset + 1] = (value >>> 8)
  1239. this[offset] = (value & 0xff)
  1240. } else {
  1241. objectWriteUInt32(this, value, offset, true)
  1242. }
  1243. return offset + 4
  1244. }
  1245. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  1246. value = +value
  1247. offset = offset | 0
  1248. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1249. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1250. this[offset] = (value >>> 24)
  1251. this[offset + 1] = (value >>> 16)
  1252. this[offset + 2] = (value >>> 8)
  1253. this[offset + 3] = (value & 0xff)
  1254. } else {
  1255. objectWriteUInt32(this, value, offset, false)
  1256. }
  1257. return offset + 4
  1258. }
  1259. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  1260. value = +value
  1261. offset = offset | 0
  1262. if (!noAssert) {
  1263. var limit = Math.pow(2, 8 * byteLength - 1)
  1264. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1265. }
  1266. var i = 0
  1267. var mul = 1
  1268. var sub = 0
  1269. this[offset] = value & 0xFF
  1270. while (++i < byteLength && (mul *= 0x100)) {
  1271. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  1272. sub = 1
  1273. }
  1274. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1275. }
  1276. return offset + byteLength
  1277. }
  1278. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  1279. value = +value
  1280. offset = offset | 0
  1281. if (!noAssert) {
  1282. var limit = Math.pow(2, 8 * byteLength - 1)
  1283. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1284. }
  1285. var i = byteLength - 1
  1286. var mul = 1
  1287. var sub = 0
  1288. this[offset + i] = value & 0xFF
  1289. while (--i >= 0 && (mul *= 0x100)) {
  1290. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  1291. sub = 1
  1292. }
  1293. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1294. }
  1295. return offset + byteLength
  1296. }
  1297. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  1298. value = +value
  1299. offset = offset | 0
  1300. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  1301. if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
  1302. if (value < 0) value = 0xff + value + 1
  1303. this[offset] = (value & 0xff)
  1304. return offset + 1
  1305. }
  1306. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  1307. value = +value
  1308. offset = offset | 0
  1309. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1310. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1311. this[offset] = (value & 0xff)
  1312. this[offset + 1] = (value >>> 8)
  1313. } else {
  1314. objectWriteUInt16(this, value, offset, true)
  1315. }
  1316. return offset + 2
  1317. }
  1318. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  1319. value = +value
  1320. offset = offset | 0
  1321. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1322. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1323. this[offset] = (value >>> 8)
  1324. this[offset + 1] = (value & 0xff)
  1325. } else {
  1326. objectWriteUInt16(this, value, offset, false)
  1327. }
  1328. return offset + 2
  1329. }
  1330. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  1331. value = +value
  1332. offset = offset | 0
  1333. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1334. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1335. this[offset] = (value & 0xff)
  1336. this[offset + 1] = (value >>> 8)
  1337. this[offset + 2] = (value >>> 16)
  1338. this[offset + 3] = (value >>> 24)
  1339. } else {
  1340. objectWriteUInt32(this, value, offset, true)
  1341. }
  1342. return offset + 4
  1343. }
  1344. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  1345. value = +value
  1346. offset = offset | 0
  1347. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1348. if (value < 0) value = 0xffffffff + value + 1
  1349. if (Buffer.TYPED_ARRAY_SUPPORT) {
  1350. this[offset] = (value >>> 24)
  1351. this[offset + 1] = (value >>> 16)
  1352. this[offset + 2] = (value >>> 8)
  1353. this[offset + 3] = (value & 0xff)
  1354. } else {
  1355. objectWriteUInt32(this, value, offset, false)
  1356. }
  1357. return offset + 4
  1358. }
  1359. function checkIEEE754 (buf, value, offset, ext, max, min) {
  1360. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1361. if (offset < 0) throw new RangeError('Index out of range')
  1362. }
  1363. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  1364. if (!noAssert) {
  1365. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  1366. }
  1367. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  1368. return offset + 4
  1369. }
  1370. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  1371. return writeFloat(this, value, offset, true, noAssert)
  1372. }
  1373. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  1374. return writeFloat(this, value, offset, false, noAssert)
  1375. }
  1376. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  1377. if (!noAssert) {
  1378. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  1379. }
  1380. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  1381. return offset + 8
  1382. }
  1383. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  1384. return writeDouble(this, value, offset, true, noAssert)
  1385. }
  1386. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  1387. return writeDouble(this, value, offset, false, noAssert)
  1388. }
  1389. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  1390. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  1391. if (!start) start = 0
  1392. if (!end && end !== 0) end = this.length
  1393. if (targetStart >= target.length) targetStart = target.length
  1394. if (!targetStart) targetStart = 0
  1395. if (end > 0 && end < start) end = start
  1396. // Copy 0 bytes; we're done
  1397. if (end === start) return 0
  1398. if (target.length === 0 || this.length === 0) return 0
  1399. // Fatal error conditions
  1400. if (targetStart < 0) {
  1401. throw new RangeError('targetStart out of bounds')
  1402. }
  1403. if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
  1404. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  1405. // Are we oob?
  1406. if (end > this.length) end = this.length
  1407. if (target.length - targetStart < end - start) {
  1408. end = target.length - targetStart + start
  1409. }
  1410. var len = end - start
  1411. var i
  1412. if (this === target && start < targetStart && targetStart < end) {
  1413. // descending copy from end
  1414. for (i = len - 1; i >= 0; --i) {
  1415. target[i + targetStart] = this[i + start]
  1416. }
  1417. } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
  1418. // ascending copy from start
  1419. for (i = 0; i < len; ++i) {
  1420. target[i + targetStart] = this[i + start]
  1421. }
  1422. } else {
  1423. Uint8Array.prototype.set.call(
  1424. target,
  1425. this.subarray(start, start + len),
  1426. targetStart
  1427. )
  1428. }
  1429. return len
  1430. }
  1431. // Usage:
  1432. // buffer.fill(number[, offset[, end]])
  1433. // buffer.fill(buffer[, offset[, end]])
  1434. // buffer.fill(string[, offset[, end]][, encoding])
  1435. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  1436. // Handle string cases:
  1437. if (typeof val === 'string') {
  1438. if (typeof start === 'string') {
  1439. encoding = start
  1440. start = 0
  1441. end = this.length
  1442. } else if (typeof end === 'string') {
  1443. encoding = end
  1444. end = this.length
  1445. }
  1446. if (val.length === 1) {
  1447. var code = val.charCodeAt(0)
  1448. if (code < 256) {
  1449. val = code
  1450. }
  1451. }
  1452. if (encoding !== undefined && typeof encoding !== 'string') {
  1453. throw new TypeError('encoding must be a string')
  1454. }
  1455. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  1456. throw new TypeError('Unknown encoding: ' + encoding)
  1457. }
  1458. } else if (typeof val === 'number') {
  1459. val = val & 255
  1460. }
  1461. // Invalid ranges are not set to a default, so can range check early.
  1462. if (start < 0 || this.length < start || this.length < end) {
  1463. throw new RangeError('Out of range index')
  1464. }
  1465. if (end <= start) {
  1466. return this
  1467. }
  1468. start = start >>> 0
  1469. end = end === undefined ? this.length : end >>> 0
  1470. if (!val) val = 0
  1471. var i
  1472. if (typeof val === 'number') {
  1473. for (i = start; i < end; ++i) {
  1474. this[i] = val
  1475. }
  1476. } else {
  1477. var bytes = Buffer.isBuffer(val)
  1478. ? val
  1479. : utf8ToBytes(new Buffer(val, encoding).toString())
  1480. var len = bytes.length
  1481. for (i = 0; i < end - start; ++i) {
  1482. this[i + start] = bytes[i % len]
  1483. }
  1484. }
  1485. return this
  1486. }
  1487. // HELPER FUNCTIONS
  1488. // ================
  1489. var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
  1490. function base64clean (str) {
  1491. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  1492. str = stringtrim(str).replace(INVALID_BASE64_RE, '')
  1493. // Node converts strings with length < 2 to ''
  1494. if (str.length < 2) return ''
  1495. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  1496. while (str.length % 4 !== 0) {
  1497. str = str + '='
  1498. }
  1499. return str
  1500. }
  1501. function stringtrim (str) {
  1502. if (str.trim) return str.trim()
  1503. return str.replace(/^\s+|\s+$/g, '')
  1504. }
  1505. function toHex (n) {
  1506. if (n < 16) return '0' + n.toString(16)
  1507. return n.toString(16)
  1508. }
  1509. function utf8ToBytes (string, units) {
  1510. units = units || Infinity
  1511. var codePoint
  1512. var length = string.length
  1513. var leadSurrogate = null
  1514. var bytes = []
  1515. for (var i = 0; i < length; ++i) {
  1516. codePoint = string.charCodeAt(i)
  1517. // is surrogate component
  1518. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  1519. // last char was a lead
  1520. if (!leadSurrogate) {
  1521. // no lead yet
  1522. if (codePoint > 0xDBFF) {
  1523. // unexpected trail
  1524. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1525. continue
  1526. } else if (i + 1 === length) {
  1527. // unpaired lead
  1528. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1529. continue
  1530. }
  1531. // valid lead
  1532. leadSurrogate = codePoint
  1533. continue
  1534. }
  1535. // 2 leads in a row
  1536. if (codePoint < 0xDC00) {
  1537. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1538. leadSurrogate = codePoint
  1539. continue
  1540. }
  1541. // valid surrogate pair
  1542. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  1543. } else if (leadSurrogate) {
  1544. // valid bmp char, but last char was a lead
  1545. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1546. }
  1547. leadSurrogate = null
  1548. // encode utf8
  1549. if (codePoint < 0x80) {
  1550. if ((units -= 1) < 0) break
  1551. bytes.push(codePoint)
  1552. } else if (codePoint < 0x800) {
  1553. if ((units -= 2) < 0) break
  1554. bytes.push(
  1555. codePoint >> 0x6 | 0xC0,
  1556. codePoint & 0x3F | 0x80
  1557. )
  1558. } else if (codePoint < 0x10000) {
  1559. if ((units -= 3) < 0) break
  1560. bytes.push(
  1561. codePoint >> 0xC | 0xE0,
  1562. codePoint >> 0x6 & 0x3F | 0x80,
  1563. codePoint & 0x3F | 0x80
  1564. )
  1565. } else if (codePoint < 0x110000) {
  1566. if ((units -= 4) < 0) break
  1567. bytes.push(
  1568. codePoint >> 0x12 | 0xF0,
  1569. codePoint >> 0xC & 0x3F | 0x80,
  1570. codePoint >> 0x6 & 0x3F | 0x80,
  1571. codePoint & 0x3F | 0x80
  1572. )
  1573. } else {
  1574. throw new Error('Invalid code point')
  1575. }
  1576. }
  1577. return bytes
  1578. }
  1579. function asciiToBytes (str) {
  1580. var byteArray = []
  1581. for (var i = 0; i < str.length; ++i) {
  1582. // Node's code seems to be doing this and not & 0x7F..
  1583. byteArray.push(str.charCodeAt(i) & 0xFF)
  1584. }
  1585. return byteArray
  1586. }
  1587. function utf16leToBytes (str, units) {
  1588. var c, hi, lo
  1589. var byteArray = []
  1590. for (var i = 0; i < str.length; ++i) {
  1591. if ((units -= 2) < 0) break
  1592. c = str.charCodeAt(i)
  1593. hi = c >> 8
  1594. lo = c % 256
  1595. byteArray.push(lo)
  1596. byteArray.push(hi)
  1597. }
  1598. return byteArray
  1599. }
  1600. function base64ToBytes (str) {
  1601. return base64.toByteArray(base64clean(str))
  1602. }
  1603. function blitBuffer (src, dst, offset, length) {
  1604. for (var i = 0; i < length; ++i) {
  1605. if ((i + offset >= dst.length) || (i >= src.length)) break
  1606. dst[i + offset] = src[i]
  1607. }
  1608. return i
  1609. }
  1610. function isnan (val) {
  1611. return val !== val // eslint-disable-line no-self-compare
  1612. }
  1613. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)))
  1614. /***/ }),
  1615. /* 1 */
  1616. /***/ (function(module, exports, __webpack_require__) {
  1617. exports.UINT32 = __webpack_require__(8)
  1618. exports.UINT64 = __webpack_require__(9)
  1619. /***/ }),
  1620. /* 2 */
  1621. /***/ (function(module, exports, __webpack_require__) {
  1622. module.exports = {
  1623. h32: __webpack_require__(3)
  1624. , h64: __webpack_require__(10)
  1625. }
  1626. /***/ }),
  1627. /* 3 */
  1628. /***/ (function(module, exports, __webpack_require__) {
  1629. /* WEBPACK VAR INJECTION */(function(Buffer) {/**
  1630. xxHash implementation in pure Javascript
  1631. Copyright (C) 2013, Pierre Curto
  1632. MIT license
  1633. */
  1634. var UINT32 = __webpack_require__(1).UINT32
  1635. /*
  1636. Merged this sequence of method calls as it speeds up
  1637. the calculations by a factor of 2
  1638. */
  1639. // this.v1.add( other.multiply(PRIME32_2) ).rotl(13).multiply(PRIME32_1);
  1640. UINT32.prototype.xxh_update = function (low, high) {
  1641. var b00 = PRIME32_2._low
  1642. var b16 = PRIME32_2._high
  1643. var c16, c00
  1644. c00 = low * b00
  1645. c16 = c00 >>> 16
  1646. c16 += high * b00
  1647. c16 &= 0xFFFF // Not required but improves performance
  1648. c16 += low * b16
  1649. var a00 = this._low + (c00 & 0xFFFF)
  1650. var a16 = a00 >>> 16
  1651. a16 += this._high + (c16 & 0xFFFF)
  1652. var v = (a16 << 16) | (a00 & 0xFFFF)
  1653. v = (v << 13) | (v >>> 19)
  1654. a00 = v & 0xFFFF
  1655. a16 = v >>> 16
  1656. b00 = PRIME32_1._low
  1657. b16 = PRIME32_1._high
  1658. c00 = a00 * b00
  1659. c16 = c00 >>> 16
  1660. c16 += a16 * b00
  1661. c16 &= 0xFFFF // Not required but improves performance
  1662. c16 += a00 * b16
  1663. this._low = c00 & 0xFFFF
  1664. this._high = c16 & 0xFFFF
  1665. }
  1666. /*
  1667. * Constants
  1668. */
  1669. var PRIME32_1 = UINT32( '2654435761' )
  1670. var PRIME32_2 = UINT32( '2246822519' )
  1671. var PRIME32_3 = UINT32( '3266489917' )
  1672. var PRIME32_4 = UINT32( '668265263' )
  1673. var PRIME32_5 = UINT32( '374761393' )
  1674. /**
  1675. * Convert string to proper UTF-8 array
  1676. * @param str Input string
  1677. * @returns {Uint8Array} UTF8 array is returned as uint8 array
  1678. */
  1679. function toUTF8Array (str) {
  1680. var utf8 = []
  1681. for (var i=0, n=str.length; i < n; i++) {
  1682. var charcode = str.charCodeAt(i)
  1683. if (charcode < 0x80) utf8.push(charcode)
  1684. else if (charcode < 0x800) {
  1685. utf8.push(0xc0 | (charcode >> 6),
  1686. 0x80 | (charcode & 0x3f))
  1687. }
  1688. else if (charcode < 0xd800 || charcode >= 0xe000) {
  1689. utf8.push(0xe0 | (charcode >> 12),
  1690. 0x80 | ((charcode>>6) & 0x3f),
  1691. 0x80 | (charcode & 0x3f))
  1692. }
  1693. // surrogate pair
  1694. else {
  1695. i++;
  1696. // UTF-16 encodes 0x10000-0x10FFFF by
  1697. // subtracting 0x10000 and splitting the
  1698. // 20 bits of 0x0-0xFFFFF into two halves
  1699. charcode = 0x10000 + (((charcode & 0x3ff)<<10)
  1700. | (str.charCodeAt(i) & 0x3ff))
  1701. utf8.push(0xf0 | (charcode >>18),
  1702. 0x80 | ((charcode>>12) & 0x3f),
  1703. 0x80 | ((charcode>>6) & 0x3f),
  1704. 0x80 | (charcode & 0x3f))
  1705. }
  1706. }
  1707. return new Uint8Array(utf8)
  1708. }
  1709. /**
  1710. * XXH object used as a constructor or a function
  1711. * @constructor
  1712. * or
  1713. * @param {Object|String} input data
  1714. * @param {Number|UINT32} seed
  1715. * @return ThisExpression
  1716. * or
  1717. * @return {UINT32} xxHash
  1718. */
  1719. function XXH () {
  1720. if (arguments.length == 2)
  1721. return new XXH( arguments[1] ).update( arguments[0] ).digest()
  1722. if (!(this instanceof XXH))
  1723. return new XXH( arguments[0] )
  1724. init.call(this, arguments[0])
  1725. }
  1726. /**
  1727. * Initialize the XXH instance with the given seed
  1728. * @method init
  1729. * @param {Number|Object} seed as a number or an unsigned 32 bits integer
  1730. * @return ThisExpression
  1731. */
  1732. function init (seed) {
  1733. this.seed = seed instanceof UINT32 ? seed.clone() : UINT32(seed)
  1734. this.v1 = this.seed.clone().add(PRIME32_1).add(PRIME32_2)
  1735. this.v2 = this.seed.clone().add(PRIME32_2)
  1736. this.v3 = this.seed.clone()
  1737. this.v4 = this.seed.clone().subtract(PRIME32_1)
  1738. this.total_len = 0
  1739. this.memsize = 0
  1740. this.memory = null
  1741. return this
  1742. }
  1743. XXH.prototype.init = init
  1744. /**
  1745. * Add data to be computed for the XXH hash
  1746. * @method update
  1747. * @param {String|Buffer|ArrayBuffer} input as a string or nodejs Buffer or ArrayBuffer
  1748. * @return ThisExpression
  1749. */
  1750. XXH.prototype.update = function (input) {
  1751. var isString = typeof input == 'string'
  1752. var isArrayBuffer
  1753. // Convert all strings to utf-8 first (issue #5)
  1754. if (isString) {
  1755. input = toUTF8Array(input)
  1756. isString = false
  1757. isArrayBuffer = true
  1758. }
  1759. if (typeof ArrayBuffer !== "undefined" && input instanceof ArrayBuffer)
  1760. {
  1761. isArrayBuffer = true
  1762. input = new Uint8Array(input);
  1763. }
  1764. var p = 0
  1765. var len = input.length
  1766. var bEnd = p + len
  1767. if (len == 0) return this
  1768. this.total_len += len
  1769. if (this.memsize == 0)
  1770. {
  1771. if (isString) {
  1772. this.memory = ''
  1773. } else if (isArrayBuffer) {
  1774. this.memory = new Uint8Array(16)
  1775. } else {
  1776. this.memory = new Buffer(16)
  1777. }
  1778. }
  1779. if (this.memsize + len < 16) // fill in tmp buffer
  1780. {
  1781. // XXH_memcpy(this.memory + this.memsize, input, len)
  1782. if (isString) {
  1783. this.memory += input
  1784. } else if (isArrayBuffer) {
  1785. this.memory.set( input.subarray(0, len), this.memsize )
  1786. } else {
  1787. input.copy( this.memory, this.memsize, 0, len )
  1788. }
  1789. this.memsize += len
  1790. return this
  1791. }
  1792. if (this.memsize > 0) // some data left from previous update
  1793. {
  1794. // XXH_memcpy(this.memory + this.memsize, input, 16-this.memsize);
  1795. if (isString) {
  1796. this.memory += input.slice(0, 16 - this.memsize)
  1797. } else if (isArrayBuffer) {
  1798. this.memory.set( input.subarray(0, 16 - this.memsize), this.memsize )
  1799. } else {
  1800. input.copy( this.memory, this.memsize, 0, 16 - this.memsize )
  1801. }
  1802. var p32 = 0
  1803. if (isString) {
  1804. this.v1.xxh_update(
  1805. (this.memory.charCodeAt(p32+1) << 8) | this.memory.charCodeAt(p32)
  1806. , (this.memory.charCodeAt(p32+3) << 8) | this.memory.charCodeAt(p32+2)
  1807. )
  1808. p32 += 4
  1809. this.v2.xxh_update(
  1810. (this.memory.charCodeAt(p32+1) << 8) | this.memory.charCodeAt(p32)
  1811. , (this.memory.charCodeAt(p32+3) << 8) | this.memory.charCodeAt(p32+2)
  1812. )
  1813. p32 += 4
  1814. this.v3.xxh_update(
  1815. (this.memory.charCodeAt(p32+1) << 8) | this.memory.charCodeAt(p32)
  1816. , (this.memory.charCodeAt(p32+3) << 8) | this.memory.charCodeAt(p32+2)
  1817. )
  1818. p32 += 4
  1819. this.v4.xxh_update(
  1820. (this.memory.charCodeAt(p32+1) << 8) | this.memory.charCodeAt(p32)
  1821. , (this.memory.charCodeAt(p32+3) << 8) | this.memory.charCodeAt(p32+2)
  1822. )
  1823. } else {
  1824. this.v1.xxh_update(
  1825. (this.memory[p32+1] << 8) | this.memory[p32]
  1826. , (this.memory[p32+3] << 8) | this.memory[p32+2]
  1827. )
  1828. p32 += 4
  1829. this.v2.xxh_update(
  1830. (this.memory[p32+1] << 8) | this.memory[p32]
  1831. , (this.memory[p32+3] << 8) | this.memory[p32+2]
  1832. )
  1833. p32 += 4
  1834. this.v3.xxh_update(
  1835. (this.memory[p32+1] << 8) | this.memory[p32]
  1836. , (this.memory[p32+3] << 8) | this.memory[p32+2]
  1837. )
  1838. p32 += 4
  1839. this.v4.xxh_update(
  1840. (this.memory[p32+1] << 8) | this.memory[p32]
  1841. , (this.memory[p32+3] << 8) | this.memory[p32+2]
  1842. )
  1843. }
  1844. p += 16 - this.memsize
  1845. this.memsize = 0
  1846. if (isString) this.memory = ''
  1847. }
  1848. if (p <= bEnd - 16)
  1849. {
  1850. var limit = bEnd - 16
  1851. do
  1852. {
  1853. if (isString) {
  1854. this.v1.xxh_update(
  1855. (input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
  1856. , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
  1857. )
  1858. p += 4
  1859. this.v2.xxh_update(
  1860. (input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
  1861. , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
  1862. )
  1863. p += 4
  1864. this.v3.xxh_update(
  1865. (input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
  1866. , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
  1867. )
  1868. p += 4
  1869. this.v4.xxh_update(
  1870. (input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
  1871. , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
  1872. )
  1873. } else {
  1874. this.v1.xxh_update(
  1875. (input[p+1] << 8) | input[p]
  1876. , (input[p+3] << 8) | input[p+2]
  1877. )
  1878. p += 4
  1879. this.v2.xxh_update(
  1880. (input[p+1] << 8) | input[p]
  1881. , (input[p+3] << 8) | input[p+2]
  1882. )
  1883. p += 4
  1884. this.v3.xxh_update(
  1885. (input[p+1] << 8) | input[p]
  1886. , (input[p+3] << 8) | input[p+2]
  1887. )
  1888. p += 4
  1889. this.v4.xxh_update(
  1890. (input[p+1] << 8) | input[p]
  1891. , (input[p+3] << 8) | input[p+2]
  1892. )
  1893. }
  1894. p += 4
  1895. } while (p <= limit)
  1896. }
  1897. if (p < bEnd)
  1898. {
  1899. // XXH_memcpy(this.memory, p, bEnd-p);
  1900. if (isString) {
  1901. this.memory += input.slice(p)
  1902. } else if (isArrayBuffer) {
  1903. this.memory.set( input.subarray(p, bEnd), this.memsize )
  1904. } else {
  1905. input.copy( this.memory, this.memsize, p, bEnd )
  1906. }
  1907. this.memsize = bEnd - p
  1908. }
  1909. return this
  1910. }
  1911. /**
  1912. * Finalize the XXH computation. The XXH instance is ready for reuse for the given seed
  1913. * @method digest
  1914. * @return {UINT32} xxHash
  1915. */
  1916. XXH.prototype.digest = function () {
  1917. var input = this.memory
  1918. var isString = typeof input == 'string'
  1919. var p = 0
  1920. var bEnd = this.memsize
  1921. var h32, h
  1922. var u = new UINT32
  1923. if (this.total_len >= 16)
  1924. {
  1925. h32 = this.v1.rotl(1).add( this.v2.rotl(7).add( this.v3.rotl(12).add( this.v4.rotl(18) ) ) )
  1926. }
  1927. else
  1928. {
  1929. h32 = this.seed.clone().add( PRIME32_5 )
  1930. }
  1931. h32.add( u.fromNumber(this.total_len) )
  1932. while (p <= bEnd - 4)
  1933. {
  1934. if (isString) {
  1935. u.fromBits(
  1936. (input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
  1937. , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
  1938. )
  1939. } else {
  1940. u.fromBits(
  1941. (input[p+1] << 8) | input[p]
  1942. , (input[p+3] << 8) | input[p+2]
  1943. )
  1944. }
  1945. h32
  1946. .add( u.multiply(PRIME32_3) )
  1947. .rotl(17)
  1948. .multiply( PRIME32_4 )
  1949. p += 4
  1950. }
  1951. while (p < bEnd)
  1952. {
  1953. u.fromBits( isString ? input.charCodeAt(p++) : input[p++], 0 )
  1954. h32
  1955. .add( u.multiply(PRIME32_5) )
  1956. .rotl(11)
  1957. .multiply(PRIME32_1)
  1958. }
  1959. h = h32.clone().shiftRight(15)
  1960. h32.xor(h).multiply(PRIME32_2)
  1961. h = h32.clone().shiftRight(13)
  1962. h32.xor(h).multiply(PRIME32_3)
  1963. h = h32.clone().shiftRight(16)
  1964. h32.xor(h)
  1965. // Reset the state
  1966. this.init( this.seed )
  1967. return h32
  1968. }
  1969. module.exports = XXH
  1970. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0).Buffer))
  1971. /***/ }),
  1972. /* 4 */
  1973. /***/ (function(module, exports) {
  1974. var g;
  1975. // This works in non-strict mode
  1976. g = (function() {
  1977. return this;
  1978. })();
  1979. try {
  1980. // This works if eval is allowed (see CSP)
  1981. g = g || Function("return this")() || (1,eval)("this");
  1982. } catch(e) {
  1983. // This works if the window reference is available
  1984. if(typeof window === "object")
  1985. g = window;
  1986. }
  1987. // g can still be undefined, but nothing to do about it...
  1988. // We return undefined, instead of nothing here, so it's
  1989. // easier to handle this case. if(!global) { ...}
  1990. module.exports = g;
  1991. /***/ }),
  1992. /* 5 */
  1993. /***/ (function(module, exports, __webpack_require__) {
  1994. "use strict";
  1995. exports.byteLength = byteLength
  1996. exports.toByteArray = toByteArray
  1997. exports.fromByteArray = fromByteArray
  1998. var lookup = []
  1999. var revLookup = []
  2000. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  2001. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  2002. for (var i = 0, len = code.length; i < len; ++i) {
  2003. lookup[i] = code[i]
  2004. revLookup[code.charCodeAt(i)] = i
  2005. }
  2006. revLookup['-'.charCodeAt(0)] = 62
  2007. revLookup['_'.charCodeAt(0)] = 63
  2008. function placeHoldersCount (b64) {
  2009. var len = b64.length
  2010. if (len % 4 > 0) {
  2011. throw new Error('Invalid string. Length must be a multiple of 4')
  2012. }
  2013. // the number of equal signs (place holders)
  2014. // if there are two placeholders, than the two characters before it
  2015. // represent one byte
  2016. // if there is only one, then the three characters before it represent 2 bytes
  2017. // this is just a cheap hack to not do indexOf twice
  2018. return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0
  2019. }
  2020. function byteLength (b64) {
  2021. // base64 is 4/3 + up to two characters of the original data
  2022. return (b64.length * 3 / 4) - placeHoldersCount(b64)
  2023. }
  2024. function toByteArray (b64) {
  2025. var i, l, tmp, placeHolders, arr
  2026. var len = b64.length
  2027. placeHolders = placeHoldersCount(b64)
  2028. arr = new Arr((len * 3 / 4) - placeHolders)
  2029. // if there are placeholders, only get up to the last complete 4 chars
  2030. l = placeHolders > 0 ? len - 4 : len
  2031. var L = 0
  2032. for (i = 0; i < l; i += 4) {
  2033. tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
  2034. arr[L++] = (tmp >> 16) & 0xFF
  2035. arr[L++] = (tmp >> 8) & 0xFF
  2036. arr[L++] = tmp & 0xFF
  2037. }
  2038. if (placeHolders === 2) {
  2039. tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
  2040. arr[L++] = tmp & 0xFF
  2041. } else if (placeHolders === 1) {
  2042. tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
  2043. arr[L++] = (tmp >> 8) & 0xFF
  2044. arr[L++] = tmp & 0xFF
  2045. }
  2046. return arr
  2047. }
  2048. function tripletToBase64 (num) {
  2049. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]
  2050. }
  2051. function encodeChunk (uint8, start, end) {
  2052. var tmp
  2053. var output = []
  2054. for (var i = start; i < end; i += 3) {
  2055. tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
  2056. output.push(tripletToBase64(tmp))
  2057. }
  2058. return output.join('')
  2059. }
  2060. function fromByteArray (uint8) {
  2061. var tmp
  2062. var len = uint8.length
  2063. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  2064. var output = ''
  2065. var parts = []
  2066. var maxChunkLength = 16383 // must be multiple of 3
  2067. // go through the array every three bytes, we'll deal with trailing stuff later
  2068. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  2069. parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
  2070. }
  2071. // pad the end with zeros, but make sure to not forget the extra bytes
  2072. if (extraBytes === 1) {
  2073. tmp = uint8[len - 1]
  2074. output += lookup[tmp >> 2]
  2075. output += lookup[(tmp << 4) & 0x3F]
  2076. output += '=='
  2077. } else if (extraBytes === 2) {
  2078. tmp = (uint8[len - 2] << 8) + (uint8[len - 1])
  2079. output += lookup[tmp >> 10]
  2080. output += lookup[(tmp >> 4) & 0x3F]
  2081. output += lookup[(tmp << 2) & 0x3F]
  2082. output += '='
  2083. }
  2084. parts.push(output)
  2085. return parts.join('')
  2086. }
  2087. /***/ }),
  2088. /* 6 */
  2089. /***/ (function(module, exports) {
  2090. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  2091. var e, m
  2092. var eLen = nBytes * 8 - mLen - 1
  2093. var eMax = (1 << eLen) - 1
  2094. var eBias = eMax >> 1
  2095. var nBits = -7
  2096. var i = isLE ? (nBytes - 1) : 0
  2097. var d = isLE ? -1 : 1
  2098. var s = buffer[offset + i]
  2099. i += d
  2100. e = s & ((1 << (-nBits)) - 1)
  2101. s >>= (-nBits)
  2102. nBits += eLen
  2103. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  2104. m = e & ((1 << (-nBits)) - 1)
  2105. e >>= (-nBits)
  2106. nBits += mLen
  2107. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  2108. if (e === 0) {
  2109. e = 1 - eBias
  2110. } else if (e === eMax) {
  2111. return m ? NaN : ((s ? -1 : 1) * Infinity)
  2112. } else {
  2113. m = m + Math.pow(2, mLen)
  2114. e = e - eBias
  2115. }
  2116. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  2117. }
  2118. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  2119. var e, m, c
  2120. var eLen = nBytes * 8 - mLen - 1
  2121. var eMax = (1 << eLen) - 1
  2122. var eBias = eMax >> 1
  2123. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  2124. var i = isLE ? 0 : (nBytes - 1)
  2125. var d = isLE ? 1 : -1
  2126. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  2127. value = Math.abs(value)
  2128. if (isNaN(value) || value === Infinity) {
  2129. m = isNaN(value) ? 1 : 0
  2130. e = eMax
  2131. } else {
  2132. e = Math.floor(Math.log(value) / Math.LN2)
  2133. if (value * (c = Math.pow(2, -e)) < 1) {
  2134. e--
  2135. c *= 2
  2136. }
  2137. if (e + eBias >= 1) {
  2138. value += rt / c
  2139. } else {
  2140. value += rt * Math.pow(2, 1 - eBias)
  2141. }
  2142. if (value * c >= 2) {
  2143. e++
  2144. c /= 2
  2145. }
  2146. if (e + eBias >= eMax) {
  2147. m = 0
  2148. e = eMax
  2149. } else if (e + eBias >= 1) {
  2150. m = (value * c - 1) * Math.pow(2, mLen)
  2151. e = e + eBias
  2152. } else {
  2153. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  2154. e = 0
  2155. }
  2156. }
  2157. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  2158. e = (e << mLen) | m
  2159. eLen += mLen
  2160. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  2161. buffer[offset + i - d] |= s * 128
  2162. }
  2163. /***/ }),
  2164. /* 7 */
  2165. /***/ (function(module, exports) {
  2166. var toString = {}.toString;
  2167. module.exports = Array.isArray || function (arr) {
  2168. return toString.call(arr) == '[object Array]';
  2169. };
  2170. /***/ }),
  2171. /* 8 */
  2172. /***/ (function(module, exports, __webpack_require__) {
  2173. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/**
  2174. C-like unsigned 32 bits integers in Javascript
  2175. Copyright (C) 2013, Pierre Curto
  2176. MIT license
  2177. */
  2178. ;(function (root) {
  2179. // Local cache for typical radices
  2180. var radixPowerCache = {
  2181. 36: UINT32( Math.pow(36, 5) )
  2182. , 16: UINT32( Math.pow(16, 7) )
  2183. , 10: UINT32( Math.pow(10, 9) )
  2184. , 2: UINT32( Math.pow(2, 30) )
  2185. }
  2186. var radixCache = {
  2187. 36: UINT32(36)
  2188. , 16: UINT32(16)
  2189. , 10: UINT32(10)
  2190. , 2: UINT32(2)
  2191. }
  2192. /**
  2193. * Represents an unsigned 32 bits integer
  2194. * @constructor
  2195. * @param {Number|String|Number} low bits | integer as a string | integer as a number
  2196. * @param {Number|Number|Undefined} high bits | radix (optional, default=10)
  2197. * @return
  2198. */
  2199. function UINT32 (l, h) {
  2200. if ( !(this instanceof UINT32) )
  2201. return new UINT32(l, h)
  2202. this._low = 0
  2203. this._high = 0
  2204. this.remainder = null
  2205. if (typeof h == 'undefined')
  2206. return fromNumber.call(this, l)
  2207. if (typeof l == 'string')
  2208. return fromString.call(this, l, h)
  2209. fromBits.call(this, l, h)
  2210. }
  2211. /**
  2212. * Set the current _UINT32_ object with its low and high bits
  2213. * @method fromBits
  2214. * @param {Number} low bits
  2215. * @param {Number} high bits
  2216. * @return ThisExpression
  2217. */
  2218. function fromBits (l, h) {
  2219. this._low = l | 0
  2220. this._high = h | 0
  2221. return this
  2222. }
  2223. UINT32.prototype.fromBits = fromBits
  2224. /**
  2225. * Set the current _UINT32_ object from a number
  2226. * @method fromNumber
  2227. * @param {Number} number
  2228. * @return ThisExpression
  2229. */
  2230. function fromNumber (value) {
  2231. this._low = value & 0xFFFF
  2232. this._high = value >>> 16
  2233. return this
  2234. }
  2235. UINT32.prototype.fromNumber = fromNumber
  2236. /**
  2237. * Set the current _UINT32_ object from a string
  2238. * @method fromString
  2239. * @param {String} integer as a string
  2240. * @param {Number} radix (optional, default=10)
  2241. * @return ThisExpression
  2242. */
  2243. function fromString (s, radix) {
  2244. var value = parseInt(s, radix || 10)
  2245. this._low = value & 0xFFFF
  2246. this._high = value >>> 16
  2247. return this
  2248. }
  2249. UINT32.prototype.fromString = fromString
  2250. /**
  2251. * Convert this _UINT32_ to a number
  2252. * @method toNumber
  2253. * @return {Number} the converted UINT32
  2254. */
  2255. UINT32.prototype.toNumber = function () {
  2256. return (this._high * 65536) + this._low
  2257. }
  2258. /**
  2259. * Convert this _UINT32_ to a string
  2260. * @method toString
  2261. * @param {Number} radix (optional, default=10)
  2262. * @return {String} the converted UINT32
  2263. */
  2264. UINT32.prototype.toString = function (radix) {
  2265. return this.toNumber().toString(radix || 10)
  2266. }
  2267. /**
  2268. * Add two _UINT32_. The current _UINT32_ stores the result
  2269. * @method add
  2270. * @param {Object} other UINT32
  2271. * @return ThisExpression
  2272. */
  2273. UINT32.prototype.add = function (other) {
  2274. var a00 = this._low + other._low
  2275. var a16 = a00 >>> 16
  2276. a16 += this._high + other._high
  2277. this._low = a00 & 0xFFFF
  2278. this._high = a16 & 0xFFFF
  2279. return this
  2280. }
  2281. /**
  2282. * Subtract two _UINT32_. The current _UINT32_ stores the result
  2283. * @method subtract
  2284. * @param {Object} other UINT32
  2285. * @return ThisExpression
  2286. */
  2287. UINT32.prototype.subtract = function (other) {
  2288. //TODO inline
  2289. return this.add( other.clone().negate() )
  2290. }
  2291. /**
  2292. * Multiply two _UINT32_. The current _UINT32_ stores the result
  2293. * @method multiply
  2294. * @param {Object} other UINT32
  2295. * @return ThisExpression
  2296. */
  2297. UINT32.prototype.multiply = function (other) {
  2298. /*
  2299. a = a00 + a16
  2300. b = b00 + b16
  2301. a*b = (a00 + a16)(b00 + b16)
  2302. = a00b00 + a00b16 + a16b00 + a16b16
  2303. a16b16 overflows the 32bits
  2304. */
  2305. var a16 = this._high
  2306. var a00 = this._low
  2307. var b16 = other._high
  2308. var b00 = other._low
  2309. /* Removed to increase speed under normal circumstances (i.e. not multiplying by 0 or 1)
  2310. // this == 0 or other == 1: nothing to do
  2311. if ((a00 == 0 && a16 == 0) || (b00 == 1 && b16 == 0)) return this
  2312. // other == 0 or this == 1: this = other
  2313. if ((b00 == 0 && b16 == 0) || (a00 == 1 && a16 == 0)) {
  2314. this._low = other._low
  2315. this._high = other._high
  2316. return this
  2317. }
  2318. */
  2319. var c16, c00
  2320. c00 = a00 * b00
  2321. c16 = c00 >>> 16
  2322. c16 += a16 * b00
  2323. c16 &= 0xFFFF // Not required but improves performance
  2324. c16 += a00 * b16
  2325. this._low = c00 & 0xFFFF
  2326. this._high = c16 & 0xFFFF
  2327. return this
  2328. }
  2329. /**
  2330. * Divide two _UINT32_. The current _UINT32_ stores the result.
  2331. * The remainder is made available as the _remainder_ property on
  2332. * the _UINT32_ object. It can be null, meaning there are no remainder.
  2333. * @method div
  2334. * @param {Object} other UINT32
  2335. * @return ThisExpression
  2336. */
  2337. UINT32.prototype.div = function (other) {
  2338. if ( (other._low == 0) && (other._high == 0) ) throw Error('division by zero')
  2339. // other == 1
  2340. if (other._high == 0 && other._low == 1) {
  2341. this.remainder = new UINT32(0)
  2342. return this
  2343. }
  2344. // other > this: 0
  2345. if ( other.gt(this) ) {
  2346. this.remainder = this.clone()
  2347. this._low = 0
  2348. this._high = 0
  2349. return this
  2350. }
  2351. // other == this: 1
  2352. if ( this.eq(other) ) {
  2353. this.remainder = new UINT32(0)
  2354. this._low = 1
  2355. this._high = 0
  2356. return this
  2357. }
  2358. // Shift the divisor left until it is higher than the dividend
  2359. var _other = other.clone()
  2360. var i = -1
  2361. while ( !this.lt(_other) ) {
  2362. // High bit can overflow the default 16bits
  2363. // Its ok since we right shift after this loop
  2364. // The overflown bit must be kept though
  2365. _other.shiftLeft(1, true)
  2366. i++
  2367. }
  2368. // Set the remainder
  2369. this.remainder = this.clone()
  2370. // Initialize the current result to 0
  2371. this._low = 0
  2372. this._high = 0
  2373. for (; i >= 0; i--) {
  2374. _other.shiftRight(1)
  2375. // If shifted divisor is smaller than the dividend
  2376. // then subtract it from the dividend
  2377. if ( !this.remainder.lt(_other) ) {
  2378. this.remainder.subtract(_other)
  2379. // Update the current result
  2380. if (i >= 16) {
  2381. this._high |= 1 << (i - 16)
  2382. } else {
  2383. this._low |= 1 << i
  2384. }
  2385. }
  2386. }
  2387. return this
  2388. }
  2389. /**
  2390. * Negate the current _UINT32_
  2391. * @method negate
  2392. * @return ThisExpression
  2393. */
  2394. UINT32.prototype.negate = function () {
  2395. var v = ( ~this._low & 0xFFFF ) + 1
  2396. this._low = v & 0xFFFF
  2397. this._high = (~this._high + (v >>> 16)) & 0xFFFF
  2398. return this
  2399. }
  2400. /**
  2401. * Equals
  2402. * @method eq
  2403. * @param {Object} other UINT32
  2404. * @return {Boolean}
  2405. */
  2406. UINT32.prototype.equals = UINT32.prototype.eq = function (other) {
  2407. return (this._low == other._low) && (this._high == other._high)
  2408. }
  2409. /**
  2410. * Greater than (strict)
  2411. * @method gt
  2412. * @param {Object} other UINT32
  2413. * @return {Boolean}
  2414. */
  2415. UINT32.prototype.greaterThan = UINT32.prototype.gt = function (other) {
  2416. if (this._high > other._high) return true
  2417. if (this._high < other._high) return false
  2418. return this._low > other._low
  2419. }
  2420. /**
  2421. * Less than (strict)
  2422. * @method lt
  2423. * @param {Object} other UINT32
  2424. * @return {Boolean}
  2425. */
  2426. UINT32.prototype.lessThan = UINT32.prototype.lt = function (other) {
  2427. if (this._high < other._high) return true
  2428. if (this._high > other._high) return false
  2429. return this._low < other._low
  2430. }
  2431. /**
  2432. * Bitwise OR
  2433. * @method or
  2434. * @param {Object} other UINT32
  2435. * @return ThisExpression
  2436. */
  2437. UINT32.prototype.or = function (other) {
  2438. this._low |= other._low
  2439. this._high |= other._high
  2440. return this
  2441. }
  2442. /**
  2443. * Bitwise AND
  2444. * @method and
  2445. * @param {Object} other UINT32
  2446. * @return ThisExpression
  2447. */
  2448. UINT32.prototype.and = function (other) {
  2449. this._low &= other._low
  2450. this._high &= other._high
  2451. return this
  2452. }
  2453. /**
  2454. * Bitwise NOT
  2455. * @method not
  2456. * @return ThisExpression
  2457. */
  2458. UINT32.prototype.not = function() {
  2459. this._low = ~this._low & 0xFFFF
  2460. this._high = ~this._high & 0xFFFF
  2461. return this
  2462. }
  2463. /**
  2464. * Bitwise XOR
  2465. * @method xor
  2466. * @param {Object} other UINT32
  2467. * @return ThisExpression
  2468. */
  2469. UINT32.prototype.xor = function (other) {
  2470. this._low ^= other._low
  2471. this._high ^= other._high
  2472. return this
  2473. }
  2474. /**
  2475. * Bitwise shift right
  2476. * @method shiftRight
  2477. * @param {Number} number of bits to shift
  2478. * @return ThisExpression
  2479. */
  2480. UINT32.prototype.shiftRight = UINT32.prototype.shiftr = function (n) {
  2481. if (n > 16) {
  2482. this._low = this._high >> (n - 16)
  2483. this._high = 0
  2484. } else if (n == 16) {
  2485. this._low = this._high
  2486. this._high = 0
  2487. } else {
  2488. this._low = (this._low >> n) | ( (this._high << (16-n)) & 0xFFFF )
  2489. this._high >>= n
  2490. }
  2491. return this
  2492. }
  2493. /**
  2494. * Bitwise shift left
  2495. * @method shiftLeft
  2496. * @param {Number} number of bits to shift
  2497. * @param {Boolean} allow overflow
  2498. * @return ThisExpression
  2499. */
  2500. UINT32.prototype.shiftLeft = UINT32.prototype.shiftl = function (n, allowOverflow) {
  2501. if (n > 16) {
  2502. this._high = this._low << (n - 16)
  2503. this._low = 0
  2504. if (!allowOverflow) {
  2505. this._high &= 0xFFFF
  2506. }
  2507. } else if (n == 16) {
  2508. this._high = this._low
  2509. this._low = 0
  2510. } else {
  2511. this._high = (this._high << n) | (this._low >> (16-n))
  2512. this._low = (this._low << n) & 0xFFFF
  2513. if (!allowOverflow) {
  2514. // Overflow only allowed on the high bits...
  2515. this._high &= 0xFFFF
  2516. }
  2517. }
  2518. return this
  2519. }
  2520. /**
  2521. * Bitwise rotate left
  2522. * @method rotl
  2523. * @param {Number} number of bits to rotate
  2524. * @return ThisExpression
  2525. */
  2526. UINT32.prototype.rotateLeft = UINT32.prototype.rotl = function (n) {
  2527. var v = (this._high << 16) | this._low
  2528. v = (v << n) | (v >>> (32 - n))
  2529. this._low = v & 0xFFFF
  2530. this._high = v >>> 16
  2531. return this
  2532. }
  2533. /**
  2534. * Bitwise rotate right
  2535. * @method rotr
  2536. * @param {Number} number of bits to rotate
  2537. * @return ThisExpression
  2538. */
  2539. UINT32.prototype.rotateRight = UINT32.prototype.rotr = function (n) {
  2540. var v = (this._high << 16) | this._low
  2541. v = (v >>> n) | (v << (32 - n))
  2542. this._low = v & 0xFFFF
  2543. this._high = v >>> 16
  2544. return this
  2545. }
  2546. /**
  2547. * Clone the current _UINT32_
  2548. * @method clone
  2549. * @return {Object} cloned UINT32
  2550. */
  2551. UINT32.prototype.clone = function () {
  2552. return new UINT32(this._low, this._high)
  2553. }
  2554. if (true) {
  2555. // AMD / RequireJS
  2556. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () {
  2557. return UINT32
  2558. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  2559. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))
  2560. } else if (typeof module != 'undefined' && module.exports) {
  2561. // Node.js
  2562. module.exports = UINT32
  2563. } else {
  2564. // Browser
  2565. root['UINT32'] = UINT32
  2566. }
  2567. })(this)
  2568. /***/ }),
  2569. /* 9 */
  2570. /***/ (function(module, exports, __webpack_require__) {
  2571. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/**
  2572. C-like unsigned 64 bits integers in Javascript
  2573. Copyright (C) 2013, Pierre Curto
  2574. MIT license
  2575. */
  2576. ;(function (root) {
  2577. // Local cache for typical radices
  2578. var radixPowerCache = {
  2579. 16: UINT64( Math.pow(16, 5) )
  2580. , 10: UINT64( Math.pow(10, 5) )
  2581. , 2: UINT64( Math.pow(2, 5) )
  2582. }
  2583. var radixCache = {
  2584. 16: UINT64(16)
  2585. , 10: UINT64(10)
  2586. , 2: UINT64(2)
  2587. }
  2588. /**
  2589. * Represents an unsigned 64 bits integer
  2590. * @constructor
  2591. * @param {Number} first low bits (8)
  2592. * @param {Number} second low bits (8)
  2593. * @param {Number} first high bits (8)
  2594. * @param {Number} second high bits (8)
  2595. * or
  2596. * @param {Number} low bits (32)
  2597. * @param {Number} high bits (32)
  2598. * or
  2599. * @param {String|Number} integer as a string | integer as a number
  2600. * @param {Number|Undefined} radix (optional, default=10)
  2601. * @return
  2602. */
  2603. function UINT64 (a00, a16, a32, a48) {
  2604. if ( !(this instanceof UINT64) )
  2605. return new UINT64(a00, a16, a32, a48)
  2606. this.remainder = null
  2607. if (typeof a00 == 'string')
  2608. return fromString.call(this, a00, a16)
  2609. if (typeof a16 == 'undefined')
  2610. return fromNumber.call(this, a00)
  2611. fromBits.apply(this, arguments)
  2612. }
  2613. /**
  2614. * Set the current _UINT64_ object with its low and high bits
  2615. * @method fromBits
  2616. * @param {Number} first low bits (8)
  2617. * @param {Number} second low bits (8)
  2618. * @param {Number} first high bits (8)
  2619. * @param {Number} second high bits (8)
  2620. * or
  2621. * @param {Number} low bits (32)
  2622. * @param {Number} high bits (32)
  2623. * @return ThisExpression
  2624. */
  2625. function fromBits (a00, a16, a32, a48) {
  2626. if (typeof a32 == 'undefined') {
  2627. this._a00 = a00 & 0xFFFF
  2628. this._a16 = a00 >>> 16
  2629. this._a32 = a16 & 0xFFFF
  2630. this._a48 = a16 >>> 16
  2631. return this
  2632. }
  2633. this._a00 = a00 | 0
  2634. this._a16 = a16 | 0
  2635. this._a32 = a32 | 0
  2636. this._a48 = a48 | 0
  2637. return this
  2638. }
  2639. UINT64.prototype.fromBits = fromBits
  2640. /**
  2641. * Set the current _UINT64_ object from a number
  2642. * @method fromNumber
  2643. * @param {Number} number
  2644. * @return ThisExpression
  2645. */
  2646. function fromNumber (value) {
  2647. this._a00 = value & 0xFFFF
  2648. this._a16 = value >>> 16
  2649. this._a32 = 0
  2650. this._a48 = 0
  2651. return this
  2652. }
  2653. UINT64.prototype.fromNumber = fromNumber
  2654. /**
  2655. * Set the current _UINT64_ object from a string
  2656. * @method fromString
  2657. * @param {String} integer as a string
  2658. * @param {Number} radix (optional, default=10)
  2659. * @return ThisExpression
  2660. */
  2661. function fromString (s, radix) {
  2662. radix = radix || 10
  2663. this._a00 = 0
  2664. this._a16 = 0
  2665. this._a32 = 0
  2666. this._a48 = 0
  2667. /*
  2668. In Javascript, bitwise operators only operate on the first 32 bits
  2669. of a number, even though parseInt() encodes numbers with a 53 bits
  2670. mantissa.
  2671. Therefore UINT64(<Number>) can only work on 32 bits.
  2672. The radix maximum value is 36 (as per ECMA specs) (26 letters + 10 digits)
  2673. maximum input value is m = 32bits as 1 = 2^32 - 1
  2674. So the maximum substring length n is:
  2675. 36^(n+1) - 1 = 2^32 - 1
  2676. 36^(n+1) = 2^32
  2677. (n+1)ln(36) = 32ln(2)
  2678. n = 32ln(2)/ln(36) - 1
  2679. n = 5.189644915687692
  2680. n = 5
  2681. */
  2682. var radixUint = radixPowerCache[radix] || new UINT64( Math.pow(radix, 5) )
  2683. for (var i = 0, len = s.length; i < len; i += 5) {
  2684. var size = Math.min(5, len - i)
  2685. var value = parseInt( s.slice(i, i + size), radix )
  2686. this.multiply(
  2687. size < 5
  2688. ? new UINT64( Math.pow(radix, size) )
  2689. : radixUint
  2690. )
  2691. .add( new UINT64(value) )
  2692. }
  2693. return this
  2694. }
  2695. UINT64.prototype.fromString = fromString
  2696. /**
  2697. * Convert this _UINT64_ to a number (last 32 bits are dropped)
  2698. * @method toNumber
  2699. * @return {Number} the converted UINT64
  2700. */
  2701. UINT64.prototype.toNumber = function () {
  2702. return (this._a16 * 65536) + this._a00
  2703. }
  2704. /**
  2705. * Convert this _UINT64_ to a string
  2706. * @method toString
  2707. * @param {Number} radix (optional, default=10)
  2708. * @return {String} the converted UINT64
  2709. */
  2710. UINT64.prototype.toString = function (radix) {
  2711. radix = radix || 10
  2712. var radixUint = radixCache[radix] || new UINT64(radix)
  2713. if ( !this.gt(radixUint) ) return this.toNumber().toString(radix)
  2714. var self = this.clone()
  2715. var res = new Array(64)
  2716. for (var i = 63; i >= 0; i--) {
  2717. self.div(radixUint)
  2718. res[i] = self.remainder.toNumber().toString(radix)
  2719. if ( !self.gt(radixUint) ) break
  2720. }
  2721. res[i-1] = self.toNumber().toString(radix)
  2722. return res.join('')
  2723. }
  2724. /**
  2725. * Add two _UINT64_. The current _UINT64_ stores the result
  2726. * @method add
  2727. * @param {Object} other UINT64
  2728. * @return ThisExpression
  2729. */
  2730. UINT64.prototype.add = function (other) {
  2731. var a00 = this._a00 + other._a00
  2732. var a16 = a00 >>> 16
  2733. a16 += this._a16 + other._a16
  2734. var a32 = a16 >>> 16
  2735. a32 += this._a32 + other._a32
  2736. var a48 = a32 >>> 16
  2737. a48 += this._a48 + other._a48
  2738. this._a00 = a00 & 0xFFFF
  2739. this._a16 = a16 & 0xFFFF
  2740. this._a32 = a32 & 0xFFFF
  2741. this._a48 = a48 & 0xFFFF
  2742. return this
  2743. }
  2744. /**
  2745. * Subtract two _UINT64_. The current _UINT64_ stores the result
  2746. * @method subtract
  2747. * @param {Object} other UINT64
  2748. * @return ThisExpression
  2749. */
  2750. UINT64.prototype.subtract = function (other) {
  2751. return this.add( other.clone().negate() )
  2752. }
  2753. /**
  2754. * Multiply two _UINT64_. The current _UINT64_ stores the result
  2755. * @method multiply
  2756. * @param {Object} other UINT64
  2757. * @return ThisExpression
  2758. */
  2759. UINT64.prototype.multiply = function (other) {
  2760. /*
  2761. a = a00 + a16 + a32 + a48
  2762. b = b00 + b16 + b32 + b48
  2763. a*b = (a00 + a16 + a32 + a48)(b00 + b16 + b32 + b48)
  2764. = a00b00 + a00b16 + a00b32 + a00b48
  2765. + a16b00 + a16b16 + a16b32 + a16b48
  2766. + a32b00 + a32b16 + a32b32 + a32b48
  2767. + a48b00 + a48b16 + a48b32 + a48b48
  2768. a16b48, a32b32, a48b16, a48b32 and a48b48 overflow the 64 bits
  2769. so it comes down to:
  2770. a*b = a00b00 + a00b16 + a00b32 + a00b48
  2771. + a16b00 + a16b16 + a16b32
  2772. + a32b00 + a32b16
  2773. + a48b00
  2774. = a00b00
  2775. + a00b16 + a16b00
  2776. + a00b32 + a16b16 + a32b00
  2777. + a00b48 + a16b32 + a32b16 + a48b00
  2778. */
  2779. var a00 = this._a00
  2780. var a16 = this._a16
  2781. var a32 = this._a32
  2782. var a48 = this._a48
  2783. var b00 = other._a00
  2784. var b16 = other._a16
  2785. var b32 = other._a32
  2786. var b48 = other._a48
  2787. var c00 = a00 * b00
  2788. var c16 = c00 >>> 16
  2789. c16 += a00 * b16
  2790. var c32 = c16 >>> 16
  2791. c16 &= 0xFFFF
  2792. c16 += a16 * b00
  2793. c32 += c16 >>> 16
  2794. c32 += a00 * b32
  2795. var c48 = c32 >>> 16
  2796. c32 &= 0xFFFF
  2797. c32 += a16 * b16
  2798. c48 += c32 >>> 16
  2799. c32 &= 0xFFFF
  2800. c32 += a32 * b00
  2801. c48 += c32 >>> 16
  2802. c48 += a00 * b48
  2803. c48 &= 0xFFFF
  2804. c48 += a16 * b32
  2805. c48 &= 0xFFFF
  2806. c48 += a32 * b16
  2807. c48 &= 0xFFFF
  2808. c48 += a48 * b00
  2809. this._a00 = c00 & 0xFFFF
  2810. this._a16 = c16 & 0xFFFF
  2811. this._a32 = c32 & 0xFFFF
  2812. this._a48 = c48 & 0xFFFF
  2813. return this
  2814. }
  2815. /**
  2816. * Divide two _UINT64_. The current _UINT64_ stores the result.
  2817. * The remainder is made available as the _remainder_ property on
  2818. * the _UINT64_ object. It can be null, meaning there are no remainder.
  2819. * @method div
  2820. * @param {Object} other UINT64
  2821. * @return ThisExpression
  2822. */
  2823. UINT64.prototype.div = function (other) {
  2824. if ( (other._a16 == 0) && (other._a32 == 0) && (other._a48 == 0) ) {
  2825. if (other._a00 == 0) throw Error('division by zero')
  2826. // other == 1: this
  2827. if (other._a00 == 1) {
  2828. this.remainder = new UINT64(0)
  2829. return this
  2830. }
  2831. }
  2832. // other > this: 0
  2833. if ( other.gt(this) ) {
  2834. this.remainder = this.clone()
  2835. this._a00 = 0
  2836. this._a16 = 0
  2837. this._a32 = 0
  2838. this._a48 = 0
  2839. return this
  2840. }
  2841. // other == this: 1
  2842. if ( this.eq(other) ) {
  2843. this.remainder = new UINT64(0)
  2844. this._a00 = 1
  2845. this._a16 = 0
  2846. this._a32 = 0
  2847. this._a48 = 0
  2848. return this
  2849. }
  2850. // Shift the divisor left until it is higher than the dividend
  2851. var _other = other.clone()
  2852. var i = -1
  2853. while ( !this.lt(_other) ) {
  2854. // High bit can overflow the default 16bits
  2855. // Its ok since we right shift after this loop
  2856. // The overflown bit must be kept though
  2857. _other.shiftLeft(1, true)
  2858. i++
  2859. }
  2860. // Set the remainder
  2861. this.remainder = this.clone()
  2862. // Initialize the current result to 0
  2863. this._a00 = 0
  2864. this._a16 = 0
  2865. this._a32 = 0
  2866. this._a48 = 0
  2867. for (; i >= 0; i--) {
  2868. _other.shiftRight(1)
  2869. // If shifted divisor is smaller than the dividend
  2870. // then subtract it from the dividend
  2871. if ( !this.remainder.lt(_other) ) {
  2872. this.remainder.subtract(_other)
  2873. // Update the current result
  2874. if (i >= 48) {
  2875. this._a48 |= 1 << (i - 48)
  2876. } else if (i >= 32) {
  2877. this._a32 |= 1 << (i - 32)
  2878. } else if (i >= 16) {
  2879. this._a16 |= 1 << (i - 16)
  2880. } else {
  2881. this._a00 |= 1 << i
  2882. }
  2883. }
  2884. }
  2885. return this
  2886. }
  2887. /**
  2888. * Negate the current _UINT64_
  2889. * @method negate
  2890. * @return ThisExpression
  2891. */
  2892. UINT64.prototype.negate = function () {
  2893. var v = ( ~this._a00 & 0xFFFF ) + 1
  2894. this._a00 = v & 0xFFFF
  2895. v = (~this._a16 & 0xFFFF) + (v >>> 16)
  2896. this._a16 = v & 0xFFFF
  2897. v = (~this._a32 & 0xFFFF) + (v >>> 16)
  2898. this._a32 = v & 0xFFFF
  2899. this._a48 = (~this._a48 + (v >>> 16)) & 0xFFFF
  2900. return this
  2901. }
  2902. /**
  2903. * @method eq
  2904. * @param {Object} other UINT64
  2905. * @return {Boolean}
  2906. */
  2907. UINT64.prototype.equals = UINT64.prototype.eq = function (other) {
  2908. return (this._a48 == other._a48) && (this._a00 == other._a00)
  2909. && (this._a32 == other._a32) && (this._a16 == other._a16)
  2910. }
  2911. /**
  2912. * Greater than (strict)
  2913. * @method gt
  2914. * @param {Object} other UINT64
  2915. * @return {Boolean}
  2916. */
  2917. UINT64.prototype.greaterThan = UINT64.prototype.gt = function (other) {
  2918. if (this._a48 > other._a48) return true
  2919. if (this._a48 < other._a48) return false
  2920. if (this._a32 > other._a32) return true
  2921. if (this._a32 < other._a32) return false
  2922. if (this._a16 > other._a16) return true
  2923. if (this._a16 < other._a16) return false
  2924. return this._a00 > other._a00
  2925. }
  2926. /**
  2927. * Less than (strict)
  2928. * @method lt
  2929. * @param {Object} other UINT64
  2930. * @return {Boolean}
  2931. */
  2932. UINT64.prototype.lessThan = UINT64.prototype.lt = function (other) {
  2933. if (this._a48 < other._a48) return true
  2934. if (this._a48 > other._a48) return false
  2935. if (this._a32 < other._a32) return true
  2936. if (this._a32 > other._a32) return false
  2937. if (this._a16 < other._a16) return true
  2938. if (this._a16 > other._a16) return false
  2939. return this._a00 < other._a00
  2940. }
  2941. /**
  2942. * Bitwise OR
  2943. * @method or
  2944. * @param {Object} other UINT64
  2945. * @return ThisExpression
  2946. */
  2947. UINT64.prototype.or = function (other) {
  2948. this._a00 |= other._a00
  2949. this._a16 |= other._a16
  2950. this._a32 |= other._a32
  2951. this._a48 |= other._a48
  2952. return this
  2953. }
  2954. /**
  2955. * Bitwise AND
  2956. * @method and
  2957. * @param {Object} other UINT64
  2958. * @return ThisExpression
  2959. */
  2960. UINT64.prototype.and = function (other) {
  2961. this._a00 &= other._a00
  2962. this._a16 &= other._a16
  2963. this._a32 &= other._a32
  2964. this._a48 &= other._a48
  2965. return this
  2966. }
  2967. /**
  2968. * Bitwise XOR
  2969. * @method xor
  2970. * @param {Object} other UINT64
  2971. * @return ThisExpression
  2972. */
  2973. UINT64.prototype.xor = function (other) {
  2974. this._a00 ^= other._a00
  2975. this._a16 ^= other._a16
  2976. this._a32 ^= other._a32
  2977. this._a48 ^= other._a48
  2978. return this
  2979. }
  2980. /**
  2981. * Bitwise NOT
  2982. * @method not
  2983. * @return ThisExpression
  2984. */
  2985. UINT64.prototype.not = function() {
  2986. this._a00 = ~this._a00 & 0xFFFF
  2987. this._a16 = ~this._a16 & 0xFFFF
  2988. this._a32 = ~this._a32 & 0xFFFF
  2989. this._a48 = ~this._a48 & 0xFFFF
  2990. return this
  2991. }
  2992. /**
  2993. * Bitwise shift right
  2994. * @method shiftRight
  2995. * @param {Number} number of bits to shift
  2996. * @return ThisExpression
  2997. */
  2998. UINT64.prototype.shiftRight = UINT64.prototype.shiftr = function (n) {
  2999. n %= 64
  3000. if (n >= 48) {
  3001. this._a00 = this._a48 >> (n - 48)
  3002. this._a16 = 0
  3003. this._a32 = 0
  3004. this._a48 = 0
  3005. } else if (n >= 32) {
  3006. n -= 32
  3007. this._a00 = ( (this._a32 >> n) | (this._a48 << (16-n)) ) & 0xFFFF
  3008. this._a16 = (this._a48 >> n) & 0xFFFF
  3009. this._a32 = 0
  3010. this._a48 = 0
  3011. } else if (n >= 16) {
  3012. n -= 16
  3013. this._a00 = ( (this._a16 >> n) | (this._a32 << (16-n)) ) & 0xFFFF
  3014. this._a16 = ( (this._a32 >> n) | (this._a48 << (16-n)) ) & 0xFFFF
  3015. this._a32 = (this._a48 >> n) & 0xFFFF
  3016. this._a48 = 0
  3017. } else {
  3018. this._a00 = ( (this._a00 >> n) | (this._a16 << (16-n)) ) & 0xFFFF
  3019. this._a16 = ( (this._a16 >> n) | (this._a32 << (16-n)) ) & 0xFFFF
  3020. this._a32 = ( (this._a32 >> n) | (this._a48 << (16-n)) ) & 0xFFFF
  3021. this._a48 = (this._a48 >> n) & 0xFFFF
  3022. }
  3023. return this
  3024. }
  3025. /**
  3026. * Bitwise shift left
  3027. * @method shiftLeft
  3028. * @param {Number} number of bits to shift
  3029. * @param {Boolean} allow overflow
  3030. * @return ThisExpression
  3031. */
  3032. UINT64.prototype.shiftLeft = UINT64.prototype.shiftl = function (n, allowOverflow) {
  3033. n %= 64
  3034. if (n >= 48) {
  3035. this._a48 = this._a00 << (n - 48)
  3036. this._a32 = 0
  3037. this._a16 = 0
  3038. this._a00 = 0
  3039. } else if (n >= 32) {
  3040. n -= 32
  3041. this._a48 = (this._a16 << n) | (this._a00 >> (16-n))
  3042. this._a32 = (this._a00 << n) & 0xFFFF
  3043. this._a16 = 0
  3044. this._a00 = 0
  3045. } else if (n >= 16) {
  3046. n -= 16
  3047. this._a48 = (this._a32 << n) | (this._a16 >> (16-n))
  3048. this._a32 = ( (this._a16 << n) | (this._a00 >> (16-n)) ) & 0xFFFF
  3049. this._a16 = (this._a00 << n) & 0xFFFF
  3050. this._a00 = 0
  3051. } else {
  3052. this._a48 = (this._a48 << n) | (this._a32 >> (16-n))
  3053. this._a32 = ( (this._a32 << n) | (this._a16 >> (16-n)) ) & 0xFFFF
  3054. this._a16 = ( (this._a16 << n) | (this._a00 >> (16-n)) ) & 0xFFFF
  3055. this._a00 = (this._a00 << n) & 0xFFFF
  3056. }
  3057. if (!allowOverflow) {
  3058. this._a48 &= 0xFFFF
  3059. }
  3060. return this
  3061. }
  3062. /**
  3063. * Bitwise rotate left
  3064. * @method rotl
  3065. * @param {Number} number of bits to rotate
  3066. * @return ThisExpression
  3067. */
  3068. UINT64.prototype.rotateLeft = UINT64.prototype.rotl = function (n) {
  3069. n %= 64
  3070. if (n == 0) return this
  3071. if (n >= 32) {
  3072. // A.B.C.D
  3073. // B.C.D.A rotl(16)
  3074. // C.D.A.B rotl(32)
  3075. var v = this._a00
  3076. this._a00 = this._a32
  3077. this._a32 = v
  3078. v = this._a48
  3079. this._a48 = this._a16
  3080. this._a16 = v
  3081. if (n == 32) return this
  3082. n -= 32
  3083. }
  3084. var high = (this._a48 << 16) | this._a32
  3085. var low = (this._a16 << 16) | this._a00
  3086. var _high = (high << n) | (low >>> (32 - n))
  3087. var _low = (low << n) | (high >>> (32 - n))
  3088. this._a00 = _low & 0xFFFF
  3089. this._a16 = _low >>> 16
  3090. this._a32 = _high & 0xFFFF
  3091. this._a48 = _high >>> 16
  3092. return this
  3093. }
  3094. /**
  3095. * Bitwise rotate right
  3096. * @method rotr
  3097. * @param {Number} number of bits to rotate
  3098. * @return ThisExpression
  3099. */
  3100. UINT64.prototype.rotateRight = UINT64.prototype.rotr = function (n) {
  3101. n %= 64
  3102. if (n == 0) return this
  3103. if (n >= 32) {
  3104. // A.B.C.D
  3105. // D.A.B.C rotr(16)
  3106. // C.D.A.B rotr(32)
  3107. var v = this._a00
  3108. this._a00 = this._a32
  3109. this._a32 = v
  3110. v = this._a48
  3111. this._a48 = this._a16
  3112. this._a16 = v
  3113. if (n == 32) return this
  3114. n -= 32
  3115. }
  3116. var high = (this._a48 << 16) | this._a32
  3117. var low = (this._a16 << 16) | this._a00
  3118. var _high = (high >>> n) | (low << (32 - n))
  3119. var _low = (low >>> n) | (high << (32 - n))
  3120. this._a00 = _low & 0xFFFF
  3121. this._a16 = _low >>> 16
  3122. this._a32 = _high & 0xFFFF
  3123. this._a48 = _high >>> 16
  3124. return this
  3125. }
  3126. /**
  3127. * Clone the current _UINT64_
  3128. * @method clone
  3129. * @return {Object} cloned UINT64
  3130. */
  3131. UINT64.prototype.clone = function () {
  3132. return new UINT64(this._a00, this._a16, this._a32, this._a48)
  3133. }
  3134. if (true) {
  3135. // AMD / RequireJS
  3136. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () {
  3137. return UINT64
  3138. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  3139. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__))
  3140. } else if (typeof module != 'undefined' && module.exports) {
  3141. // Node.js
  3142. module.exports = UINT64
  3143. } else {
  3144. // Browser
  3145. root['UINT64'] = UINT64
  3146. }
  3147. })(this)
  3148. /***/ }),
  3149. /* 10 */
  3150. /***/ (function(module, exports, __webpack_require__) {
  3151. /* WEBPACK VAR INJECTION */(function(Buffer) {/**
  3152. xxHash64 implementation in pure Javascript
  3153. Copyright (C) 2016, Pierre Curto
  3154. MIT license
  3155. */
  3156. var UINT64 = __webpack_require__(1).UINT64
  3157. /*
  3158. * Constants
  3159. */
  3160. var PRIME64_1 = UINT64( '11400714785074694791' )
  3161. var PRIME64_2 = UINT64( '14029467366897019727' )
  3162. var PRIME64_3 = UINT64( '1609587929392839161' )
  3163. var PRIME64_4 = UINT64( '9650029242287828579' )
  3164. var PRIME64_5 = UINT64( '2870177450012600261' )
  3165. /**
  3166. * Convert string to proper UTF-8 array
  3167. * @param str Input string
  3168. * @returns {Uint8Array} UTF8 array is returned as uint8 array
  3169. */
  3170. function toUTF8Array (str) {
  3171. var utf8 = []
  3172. for (var i=0, n=str.length; i < n; i++) {
  3173. var charcode = str.charCodeAt(i)
  3174. if (charcode < 0x80) utf8.push(charcode)
  3175. else if (charcode < 0x800) {
  3176. utf8.push(0xc0 | (charcode >> 6),
  3177. 0x80 | (charcode & 0x3f))
  3178. }
  3179. else if (charcode < 0xd800 || charcode >= 0xe000) {
  3180. utf8.push(0xe0 | (charcode >> 12),
  3181. 0x80 | ((charcode>>6) & 0x3f),
  3182. 0x80 | (charcode & 0x3f))
  3183. }
  3184. // surrogate pair
  3185. else {
  3186. i++;
  3187. // UTF-16 encodes 0x10000-0x10FFFF by
  3188. // subtracting 0x10000 and splitting the
  3189. // 20 bits of 0x0-0xFFFFF into two halves
  3190. charcode = 0x10000 + (((charcode & 0x3ff)<<10)
  3191. | (str.charCodeAt(i) & 0x3ff))
  3192. utf8.push(0xf0 | (charcode >>18),
  3193. 0x80 | ((charcode>>12) & 0x3f),
  3194. 0x80 | ((charcode>>6) & 0x3f),
  3195. 0x80 | (charcode & 0x3f))
  3196. }
  3197. }
  3198. return new Uint8Array(utf8)
  3199. }
  3200. /**
  3201. * XXH64 object used as a constructor or a function
  3202. * @constructor
  3203. * or
  3204. * @param {Object|String} input data
  3205. * @param {Number|UINT64} seed
  3206. * @return ThisExpression
  3207. * or
  3208. * @return {UINT64} xxHash
  3209. */
  3210. function XXH64 () {
  3211. if (arguments.length == 2)
  3212. return new XXH64( arguments[1] ).update( arguments[0] ).digest()
  3213. if (!(this instanceof XXH64))
  3214. return new XXH64( arguments[0] )
  3215. init.call(this, arguments[0])
  3216. }
  3217. /**
  3218. * Initialize the XXH64 instance with the given seed
  3219. * @method init
  3220. * @param {Number|Object} seed as a number or an unsigned 32 bits integer
  3221. * @return ThisExpression
  3222. */
  3223. function init (seed) {
  3224. this.seed = seed instanceof UINT64 ? seed.clone() : UINT64(seed)
  3225. this.v1 = this.seed.clone().add(PRIME64_1).add(PRIME64_2)
  3226. this.v2 = this.seed.clone().add(PRIME64_2)
  3227. this.v3 = this.seed.clone()
  3228. this.v4 = this.seed.clone().subtract(PRIME64_1)
  3229. this.total_len = 0
  3230. this.memsize = 0
  3231. this.memory = null
  3232. return this
  3233. }
  3234. XXH64.prototype.init = init
  3235. /**
  3236. * Add data to be computed for the XXH64 hash
  3237. * @method update
  3238. * @param {String|Buffer|ArrayBuffer} input as a string or nodejs Buffer or ArrayBuffer
  3239. * @return ThisExpression
  3240. */
  3241. XXH64.prototype.update = function (input) {
  3242. var isString = typeof input == 'string'
  3243. var isArrayBuffer
  3244. // Convert all strings to utf-8 first (issue #5)
  3245. if (isString) {
  3246. input = toUTF8Array(input)
  3247. isString = false
  3248. isArrayBuffer = true
  3249. }
  3250. if (typeof ArrayBuffer !== "undefined" && input instanceof ArrayBuffer)
  3251. {
  3252. isArrayBuffer = true
  3253. input = new Uint8Array(input);
  3254. }
  3255. var p = 0
  3256. var len = input.length
  3257. var bEnd = p + len
  3258. if (len == 0) return this
  3259. this.total_len += len
  3260. if (this.memsize == 0)
  3261. {
  3262. if (isString) {
  3263. this.memory = ''
  3264. } else if (isArrayBuffer) {
  3265. this.memory = new Uint8Array(32)
  3266. } else {
  3267. this.memory = new Buffer(32)
  3268. }
  3269. }
  3270. if (this.memsize + len < 32) // fill in tmp buffer
  3271. {
  3272. // XXH64_memcpy(this.memory + this.memsize, input, len)
  3273. if (isString) {
  3274. this.memory += input
  3275. } else if (isArrayBuffer) {
  3276. this.memory.set( input.subarray(0, len), this.memsize )
  3277. } else {
  3278. input.copy( this.memory, this.memsize, 0, len )
  3279. }
  3280. this.memsize += len
  3281. return this
  3282. }
  3283. if (this.memsize > 0) // some data left from previous update
  3284. {
  3285. // XXH64_memcpy(this.memory + this.memsize, input, 16-this.memsize);
  3286. if (isString) {
  3287. this.memory += input.slice(0, 32 - this.memsize)
  3288. } else if (isArrayBuffer) {
  3289. this.memory.set( input.subarray(0, 32 - this.memsize), this.memsize )
  3290. } else {
  3291. input.copy( this.memory, this.memsize, 0, 32 - this.memsize )
  3292. }
  3293. var p64 = 0
  3294. if (isString) {
  3295. var other
  3296. other = UINT64(
  3297. (this.memory.charCodeAt(p64+1) << 8) | this.memory.charCodeAt(p64)
  3298. , (this.memory.charCodeAt(p64+3) << 8) | this.memory.charCodeAt(p64+2)
  3299. , (this.memory.charCodeAt(p64+5) << 8) | this.memory.charCodeAt(p64+4)
  3300. , (this.memory.charCodeAt(p64+7) << 8) | this.memory.charCodeAt(p64+6)
  3301. )
  3302. this.v1.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3303. p64 += 8
  3304. other = UINT64(
  3305. (this.memory.charCodeAt(p64+1) << 8) | this.memory.charCodeAt(p64)
  3306. , (this.memory.charCodeAt(p64+3) << 8) | this.memory.charCodeAt(p64+2)
  3307. , (this.memory.charCodeAt(p64+5) << 8) | this.memory.charCodeAt(p64+4)
  3308. , (this.memory.charCodeAt(p64+7) << 8) | this.memory.charCodeAt(p64+6)
  3309. )
  3310. this.v2.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3311. p64 += 8
  3312. other = UINT64(
  3313. (this.memory.charCodeAt(p64+1) << 8) | this.memory.charCodeAt(p64)
  3314. , (this.memory.charCodeAt(p64+3) << 8) | this.memory.charCodeAt(p64+2)
  3315. , (this.memory.charCodeAt(p64+5) << 8) | this.memory.charCodeAt(p64+4)
  3316. , (this.memory.charCodeAt(p64+7) << 8) | this.memory.charCodeAt(p64+6)
  3317. )
  3318. this.v3.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3319. p64 += 8
  3320. other = UINT64(
  3321. (this.memory.charCodeAt(p64+1) << 8) | this.memory.charCodeAt(p64)
  3322. , (this.memory.charCodeAt(p64+3) << 8) | this.memory.charCodeAt(p64+2)
  3323. , (this.memory.charCodeAt(p64+5) << 8) | this.memory.charCodeAt(p64+4)
  3324. , (this.memory.charCodeAt(p64+7) << 8) | this.memory.charCodeAt(p64+6)
  3325. )
  3326. this.v4.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3327. } else {
  3328. var other
  3329. other = UINT64(
  3330. (this.memory[p64+1] << 8) | this.memory[p64]
  3331. , (this.memory[p64+3] << 8) | this.memory[p64+2]
  3332. , (this.memory[p64+5] << 8) | this.memory[p64+4]
  3333. , (this.memory[p64+7] << 8) | this.memory[p64+6]
  3334. )
  3335. this.v1.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3336. p64 += 8
  3337. other = UINT64(
  3338. (this.memory[p64+1] << 8) | this.memory[p64]
  3339. , (this.memory[p64+3] << 8) | this.memory[p64+2]
  3340. , (this.memory[p64+5] << 8) | this.memory[p64+4]
  3341. , (this.memory[p64+7] << 8) | this.memory[p64+6]
  3342. )
  3343. this.v2.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3344. p64 += 8
  3345. other = UINT64(
  3346. (this.memory[p64+1] << 8) | this.memory[p64]
  3347. , (this.memory[p64+3] << 8) | this.memory[p64+2]
  3348. , (this.memory[p64+5] << 8) | this.memory[p64+4]
  3349. , (this.memory[p64+7] << 8) | this.memory[p64+6]
  3350. )
  3351. this.v3.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3352. p64 += 8
  3353. other = UINT64(
  3354. (this.memory[p64+1] << 8) | this.memory[p64]
  3355. , (this.memory[p64+3] << 8) | this.memory[p64+2]
  3356. , (this.memory[p64+5] << 8) | this.memory[p64+4]
  3357. , (this.memory[p64+7] << 8) | this.memory[p64+6]
  3358. )
  3359. this.v4.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3360. }
  3361. p += 32 - this.memsize
  3362. this.memsize = 0
  3363. if (isString) this.memory = ''
  3364. }
  3365. if (p <= bEnd - 32)
  3366. {
  3367. var limit = bEnd - 32
  3368. do
  3369. {
  3370. if (isString) {
  3371. var other
  3372. other = UINT64(
  3373. (input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
  3374. , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
  3375. , (input.charCodeAt(p+5) << 8) | input.charCodeAt(p+4)
  3376. , (input.charCodeAt(p+7) << 8) | input.charCodeAt(p+6)
  3377. )
  3378. this.v1.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3379. p += 8
  3380. other = UINT64(
  3381. (input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
  3382. , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
  3383. , (input.charCodeAt(p+5) << 8) | input.charCodeAt(p+4)
  3384. , (input.charCodeAt(p+7) << 8) | input.charCodeAt(p+6)
  3385. )
  3386. this.v2.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3387. p += 8
  3388. other = UINT64(
  3389. (input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
  3390. , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
  3391. , (input.charCodeAt(p+5) << 8) | input.charCodeAt(p+4)
  3392. , (input.charCodeAt(p+7) << 8) | input.charCodeAt(p+6)
  3393. )
  3394. this.v3.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3395. p += 8
  3396. other = UINT64(
  3397. (input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
  3398. , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
  3399. , (input.charCodeAt(p+5) << 8) | input.charCodeAt(p+4)
  3400. , (input.charCodeAt(p+7) << 8) | input.charCodeAt(p+6)
  3401. )
  3402. this.v4.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3403. } else {
  3404. var other
  3405. other = UINT64(
  3406. (input[p+1] << 8) | input[p]
  3407. , (input[p+3] << 8) | input[p+2]
  3408. , (input[p+5] << 8) | input[p+4]
  3409. , (input[p+7] << 8) | input[p+6]
  3410. )
  3411. this.v1.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3412. p += 8
  3413. other = UINT64(
  3414. (input[p+1] << 8) | input[p]
  3415. , (input[p+3] << 8) | input[p+2]
  3416. , (input[p+5] << 8) | input[p+4]
  3417. , (input[p+7] << 8) | input[p+6]
  3418. )
  3419. this.v2.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3420. p += 8
  3421. other = UINT64(
  3422. (input[p+1] << 8) | input[p]
  3423. , (input[p+3] << 8) | input[p+2]
  3424. , (input[p+5] << 8) | input[p+4]
  3425. , (input[p+7] << 8) | input[p+6]
  3426. )
  3427. this.v3.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3428. p += 8
  3429. other = UINT64(
  3430. (input[p+1] << 8) | input[p]
  3431. , (input[p+3] << 8) | input[p+2]
  3432. , (input[p+5] << 8) | input[p+4]
  3433. , (input[p+7] << 8) | input[p+6]
  3434. )
  3435. this.v4.add( other.multiply(PRIME64_2) ).rotl(31).multiply(PRIME64_1);
  3436. }
  3437. p += 8
  3438. } while (p <= limit)
  3439. }
  3440. if (p < bEnd)
  3441. {
  3442. // XXH64_memcpy(this.memory, p, bEnd-p);
  3443. if (isString) {
  3444. this.memory += input.slice(p)
  3445. } else if (isArrayBuffer) {
  3446. this.memory.set( input.subarray(p, bEnd), this.memsize )
  3447. } else {
  3448. input.copy( this.memory, this.memsize, p, bEnd )
  3449. }
  3450. this.memsize = bEnd - p
  3451. }
  3452. return this
  3453. }
  3454. /**
  3455. * Finalize the XXH64 computation. The XXH64 instance is ready for reuse for the given seed
  3456. * @method digest
  3457. * @return {UINT64} xxHash
  3458. */
  3459. XXH64.prototype.digest = function () {
  3460. var input = this.memory
  3461. var isString = typeof input == 'string'
  3462. var p = 0
  3463. var bEnd = this.memsize
  3464. var h64, h
  3465. var u = new UINT64
  3466. if (this.total_len >= 32)
  3467. {
  3468. h64 = this.v1.clone().rotl(1)
  3469. h64.add( this.v2.clone().rotl(7) )
  3470. h64.add( this.v3.clone().rotl(12) )
  3471. h64.add( this.v4.clone().rotl(18) )
  3472. h64.xor( this.v1.multiply(PRIME64_2).rotl(31).multiply(PRIME64_1) )
  3473. h64.multiply(PRIME64_1).add(PRIME64_4)
  3474. h64.xor( this.v2.multiply(PRIME64_2).rotl(31).multiply(PRIME64_1) )
  3475. h64.multiply(PRIME64_1).add(PRIME64_4)
  3476. h64.xor( this.v3.multiply(PRIME64_2).rotl(31).multiply(PRIME64_1) )
  3477. h64.multiply(PRIME64_1).add(PRIME64_4)
  3478. h64.xor( this.v4.multiply(PRIME64_2).rotl(31).multiply(PRIME64_1) )
  3479. h64.multiply(PRIME64_1).add(PRIME64_4)
  3480. }
  3481. else
  3482. {
  3483. h64 = this.seed.clone().add( PRIME64_5 )
  3484. }
  3485. h64.add( u.fromNumber(this.total_len) )
  3486. while (p <= bEnd - 8)
  3487. {
  3488. if (isString) {
  3489. u.fromBits(
  3490. (input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
  3491. , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
  3492. , (input.charCodeAt(p+5) << 8) | input.charCodeAt(p+4)
  3493. , (input.charCodeAt(p+7) << 8) | input.charCodeAt(p+6)
  3494. )
  3495. } else {
  3496. u.fromBits(
  3497. (input[p+1] << 8) | input[p]
  3498. , (input[p+3] << 8) | input[p+2]
  3499. , (input[p+5] << 8) | input[p+4]
  3500. , (input[p+7] << 8) | input[p+6]
  3501. )
  3502. }
  3503. u.multiply(PRIME64_2).rotl(31).multiply(PRIME64_1)
  3504. h64
  3505. .xor(u)
  3506. .rotl(27)
  3507. .multiply( PRIME64_1 )
  3508. .add( PRIME64_4 )
  3509. p += 8
  3510. }
  3511. if (p + 4 <= bEnd) {
  3512. if (isString) {
  3513. u.fromBits(
  3514. (input.charCodeAt(p+1) << 8) | input.charCodeAt(p)
  3515. , (input.charCodeAt(p+3) << 8) | input.charCodeAt(p+2)
  3516. , 0
  3517. , 0
  3518. )
  3519. } else {
  3520. u.fromBits(
  3521. (input[p+1] << 8) | input[p]
  3522. , (input[p+3] << 8) | input[p+2]
  3523. , 0
  3524. , 0
  3525. )
  3526. }
  3527. h64
  3528. .xor( u.multiply(PRIME64_1) )
  3529. .rotl(23)
  3530. .multiply( PRIME64_2 )
  3531. .add( PRIME64_3 )
  3532. p += 4
  3533. }
  3534. while (p < bEnd)
  3535. {
  3536. u.fromBits( isString ? input.charCodeAt(p++) : input[p++], 0, 0, 0 )
  3537. h64
  3538. .xor( u.multiply(PRIME64_5) )
  3539. .rotl(11)
  3540. .multiply(PRIME64_1)
  3541. }
  3542. h = h64.clone().shiftRight(33)
  3543. h64.xor(h).multiply(PRIME64_2)
  3544. h = h64.clone().shiftRight(29)
  3545. h64.xor(h).multiply(PRIME64_3)
  3546. h = h64.clone().shiftRight(32)
  3547. h64.xor(h)
  3548. // Reset the state
  3549. this.init( this.seed )
  3550. return h64
  3551. }
  3552. module.exports = XXH64
  3553. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(0).Buffer))
  3554. /***/ })
  3555. /******/ ]);
  3556. });