buffer.js 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045
  1. (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  2. /* eslint-disable node/no-deprecated-api */
  3. var buffer = require('buffer')
  4. var Buffer = buffer.Buffer
  5. window.Buffer = Buffer;
  6. // alternative to using Object.keys for old browsers
  7. function copyProps (src, dst) {
  8. for (var key in src) {
  9. dst[key] = src[key]
  10. }
  11. }
  12. if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  13. module.exports = buffer
  14. } else {
  15. // Copy properties from require('buffer')
  16. copyProps(buffer, exports)
  17. exports.Buffer = SafeBuffer
  18. }
  19. function SafeBuffer (arg, encodingOrOffset, length) {
  20. return Buffer(arg, encodingOrOffset, length)
  21. }
  22. // Copy static methods from Buffer
  23. copyProps(Buffer, SafeBuffer)
  24. SafeBuffer.from = function (arg, encodingOrOffset, length) {
  25. if (typeof arg === 'number') {
  26. throw new TypeError('Argument must not be a number')
  27. }
  28. return Buffer(arg, encodingOrOffset, length)
  29. }
  30. SafeBuffer.alloc = function (size, fill, encoding) {
  31. if (typeof size !== 'number') {
  32. throw new TypeError('Argument must be a number')
  33. }
  34. var buf = Buffer(size)
  35. if (fill !== undefined) {
  36. if (typeof encoding === 'string') {
  37. buf.fill(fill, encoding)
  38. } else {
  39. buf.fill(fill)
  40. }
  41. } else {
  42. buf.fill(0)
  43. }
  44. return buf
  45. }
  46. SafeBuffer.allocUnsafe = function (size) {
  47. if (typeof size !== 'number') {
  48. throw new TypeError('Argument must be a number')
  49. }
  50. return Buffer(size)
  51. }
  52. SafeBuffer.allocUnsafeSlow = function (size) {
  53. if (typeof size !== 'number') {
  54. throw new TypeError('Argument must be a number')
  55. }
  56. return buffer.SlowBuffer(size)
  57. }
  58. },{"buffer":3}],2:[function(require,module,exports){
  59. 'use strict'
  60. exports.byteLength = byteLength
  61. exports.toByteArray = toByteArray
  62. exports.fromByteArray = fromByteArray
  63. var lookup = []
  64. var revLookup = []
  65. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
  66. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  67. for (var i = 0, len = code.length; i < len; ++i) {
  68. lookup[i] = code[i]
  69. revLookup[code.charCodeAt(i)] = i
  70. }
  71. // Support decoding URL-safe base64 strings, as Node.js does.
  72. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  73. revLookup['-'.charCodeAt(0)] = 62
  74. revLookup['_'.charCodeAt(0)] = 63
  75. function getLens (b64) {
  76. var len = b64.length
  77. if (len % 4 > 0) {
  78. throw new Error('Invalid string. Length must be a multiple of 4')
  79. }
  80. // Trim off extra bytes after placeholder bytes are found
  81. // See: https://github.com/beatgammit/base64-js/issues/42
  82. var validLen = b64.indexOf('=')
  83. if (validLen === -1) validLen = len
  84. var placeHoldersLen = validLen === len
  85. ? 0
  86. : 4 - (validLen % 4)
  87. return [validLen, placeHoldersLen]
  88. }
  89. // base64 is 4/3 + up to two characters of the original data
  90. function byteLength (b64) {
  91. var lens = getLens(b64)
  92. var validLen = lens[0]
  93. var placeHoldersLen = lens[1]
  94. return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  95. }
  96. function _byteLength (b64, validLen, placeHoldersLen) {
  97. return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
  98. }
  99. function toByteArray (b64) {
  100. var tmp
  101. var lens = getLens(b64)
  102. var validLen = lens[0]
  103. var placeHoldersLen = lens[1]
  104. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
  105. var curByte = 0
  106. // if there are placeholders, only get up to the last complete 4 chars
  107. var len = placeHoldersLen > 0
  108. ? validLen - 4
  109. : validLen
  110. for (var i = 0; i < len; i += 4) {
  111. tmp =
  112. (revLookup[b64.charCodeAt(i)] << 18) |
  113. (revLookup[b64.charCodeAt(i + 1)] << 12) |
  114. (revLookup[b64.charCodeAt(i + 2)] << 6) |
  115. revLookup[b64.charCodeAt(i + 3)]
  116. arr[curByte++] = (tmp >> 16) & 0xFF
  117. arr[curByte++] = (tmp >> 8) & 0xFF
  118. arr[curByte++] = tmp & 0xFF
  119. }
  120. if (placeHoldersLen === 2) {
  121. tmp =
  122. (revLookup[b64.charCodeAt(i)] << 2) |
  123. (revLookup[b64.charCodeAt(i + 1)] >> 4)
  124. arr[curByte++] = tmp & 0xFF
  125. }
  126. if (placeHoldersLen === 1) {
  127. tmp =
  128. (revLookup[b64.charCodeAt(i)] << 10) |
  129. (revLookup[b64.charCodeAt(i + 1)] << 4) |
  130. (revLookup[b64.charCodeAt(i + 2)] >> 2)
  131. arr[curByte++] = (tmp >> 8) & 0xFF
  132. arr[curByte++] = tmp & 0xFF
  133. }
  134. return arr
  135. }
  136. function tripletToBase64 (num) {
  137. return lookup[num >> 18 & 0x3F] +
  138. lookup[num >> 12 & 0x3F] +
  139. lookup[num >> 6 & 0x3F] +
  140. lookup[num & 0x3F]
  141. }
  142. function encodeChunk (uint8, start, end) {
  143. var tmp
  144. var output = []
  145. for (var i = start; i < end; i += 3) {
  146. tmp =
  147. ((uint8[i] << 16) & 0xFF0000) +
  148. ((uint8[i + 1] << 8) & 0xFF00) +
  149. (uint8[i + 2] & 0xFF)
  150. output.push(tripletToBase64(tmp))
  151. }
  152. return output.join('')
  153. }
  154. function fromByteArray (uint8) {
  155. var tmp
  156. var len = uint8.length
  157. var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
  158. var parts = []
  159. var maxChunkLength = 16383 // must be multiple of 3
  160. // go through the array every three bytes, we'll deal with trailing stuff later
  161. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  162. parts.push(encodeChunk(
  163. uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)
  164. ))
  165. }
  166. // pad the end with zeros, but make sure to not forget the extra bytes
  167. if (extraBytes === 1) {
  168. tmp = uint8[len - 1]
  169. parts.push(
  170. lookup[tmp >> 2] +
  171. lookup[(tmp << 4) & 0x3F] +
  172. '=='
  173. )
  174. } else if (extraBytes === 2) {
  175. tmp = (uint8[len - 2] << 8) + uint8[len - 1]
  176. parts.push(
  177. lookup[tmp >> 10] +
  178. lookup[(tmp >> 4) & 0x3F] +
  179. lookup[(tmp << 2) & 0x3F] +
  180. '='
  181. )
  182. }
  183. return parts.join('')
  184. }
  185. },{}],3:[function(require,module,exports){
  186. /*!
  187. * The buffer module from node.js, for the browser.
  188. *
  189. * @author Feross Aboukhadijeh <https://feross.org>
  190. * @license MIT
  191. */
  192. /* eslint-disable no-proto */
  193. 'use strict'
  194. var base64 = require('base64-js')
  195. var ieee754 = require('ieee754')
  196. exports.Buffer = Buffer
  197. exports.SlowBuffer = SlowBuffer
  198. exports.INSPECT_MAX_BYTES = 50
  199. var K_MAX_LENGTH = 0x7fffffff
  200. exports.kMaxLength = K_MAX_LENGTH
  201. /**
  202. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  203. * === true Use Uint8Array implementation (fastest)
  204. * === false Print warning and recommend using `buffer` v4.x which has an Object
  205. * implementation (most compatible, even IE6)
  206. *
  207. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  208. * Opera 11.6+, iOS 4.2+.
  209. *
  210. * We report that the browser does not support typed arrays if the are not subclassable
  211. * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  212. * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  213. * for __proto__ and has a buggy typed array implementation.
  214. */
  215. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport()
  216. if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
  217. typeof console.error === 'function') {
  218. console.error(
  219. 'This browser lacks typed array (Uint8Array) support which is required by ' +
  220. '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
  221. )
  222. }
  223. function typedArraySupport () {
  224. // Can typed array instances can be augmented?
  225. try {
  226. var arr = new Uint8Array(1)
  227. arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
  228. return arr.foo() === 42
  229. } catch (e) {
  230. return false
  231. }
  232. }
  233. Object.defineProperty(Buffer.prototype, 'parent', {
  234. get: function () {
  235. if (!(this instanceof Buffer)) {
  236. return undefined
  237. }
  238. return this.buffer
  239. }
  240. })
  241. Object.defineProperty(Buffer.prototype, 'offset', {
  242. get: function () {
  243. if (!(this instanceof Buffer)) {
  244. return undefined
  245. }
  246. return this.byteOffset
  247. }
  248. })
  249. function createBuffer (length) {
  250. if (length > K_MAX_LENGTH) {
  251. throw new RangeError('Invalid typed array length')
  252. }
  253. // Return an augmented `Uint8Array` instance
  254. var buf = new Uint8Array(length)
  255. buf.__proto__ = Buffer.prototype
  256. return buf
  257. }
  258. /**
  259. * The Buffer constructor returns instances of `Uint8Array` that have their
  260. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  261. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  262. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  263. * returns a single octet.
  264. *
  265. * The `Uint8Array` prototype remains unmodified.
  266. */
  267. function Buffer (arg, encodingOrOffset, length) {
  268. // Common case.
  269. if (typeof arg === 'number') {
  270. if (typeof encodingOrOffset === 'string') {
  271. throw new Error(
  272. 'If encoding is specified then the first argument must be a string'
  273. )
  274. }
  275. return allocUnsafe(arg)
  276. }
  277. return from(arg, encodingOrOffset, length)
  278. }
  279. // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  280. if (typeof Symbol !== 'undefined' && Symbol.species &&
  281. Buffer[Symbol.species] === Buffer) {
  282. Object.defineProperty(Buffer, Symbol.species, {
  283. value: null,
  284. configurable: true,
  285. enumerable: false,
  286. writable: false
  287. })
  288. }
  289. Buffer.poolSize = 8192 // not used by this implementation
  290. function from (value, encodingOrOffset, length) {
  291. if (typeof value === 'number') {
  292. throw new TypeError('"value" argument must not be a number')
  293. }
  294. if (isArrayBuffer(value) || (value && isArrayBuffer(value.buffer))) {
  295. return fromArrayBuffer(value, encodingOrOffset, length)
  296. }
  297. if (typeof value === 'string') {
  298. return fromString(value, encodingOrOffset)
  299. }
  300. return fromObject(value)
  301. }
  302. /**
  303. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  304. * if value is a number.
  305. * Buffer.from(str[, encoding])
  306. * Buffer.from(array)
  307. * Buffer.from(buffer)
  308. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  309. **/
  310. Buffer.from = function (value, encodingOrOffset, length) {
  311. return from(value, encodingOrOffset, length)
  312. }
  313. // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  314. // https://github.com/feross/buffer/pull/148
  315. Buffer.prototype.__proto__ = Uint8Array.prototype
  316. Buffer.__proto__ = Uint8Array
  317. function assertSize (size) {
  318. if (typeof size !== 'number') {
  319. throw new TypeError('"size" argument must be of type number')
  320. } else if (size < 0) {
  321. throw new RangeError('"size" argument must not be negative')
  322. }
  323. }
  324. function alloc (size, fill, encoding) {
  325. assertSize(size)
  326. if (size <= 0) {
  327. return createBuffer(size)
  328. }
  329. if (fill !== undefined) {
  330. // Only pay attention to encoding if it's a string. This
  331. // prevents accidentally sending in a number that would
  332. // be interpretted as a start offset.
  333. return typeof encoding === 'string'
  334. ? createBuffer(size).fill(fill, encoding)
  335. : createBuffer(size).fill(fill)
  336. }
  337. return createBuffer(size)
  338. }
  339. /**
  340. * Creates a new filled Buffer instance.
  341. * alloc(size[, fill[, encoding]])
  342. **/
  343. Buffer.alloc = function (size, fill, encoding) {
  344. return alloc(size, fill, encoding)
  345. }
  346. function allocUnsafe (size) {
  347. assertSize(size)
  348. return createBuffer(size < 0 ? 0 : checked(size) | 0)
  349. }
  350. /**
  351. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  352. * */
  353. Buffer.allocUnsafe = function (size) {
  354. return allocUnsafe(size)
  355. }
  356. /**
  357. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  358. */
  359. Buffer.allocUnsafeSlow = function (size) {
  360. return allocUnsafe(size)
  361. }
  362. function fromString (string, encoding) {
  363. if (typeof encoding !== 'string' || encoding === '') {
  364. encoding = 'utf8'
  365. }
  366. if (!Buffer.isEncoding(encoding)) {
  367. throw new TypeError('Unknown encoding: ' + encoding)
  368. }
  369. var length = byteLength(string, encoding) | 0
  370. var buf = createBuffer(length)
  371. var actual = buf.write(string, encoding)
  372. if (actual !== length) {
  373. // Writing a hex string, for example, that contains invalid characters will
  374. // cause everything after the first invalid character to be ignored. (e.g.
  375. // 'abxxcd' will be treated as 'ab')
  376. buf = buf.slice(0, actual)
  377. }
  378. return buf
  379. }
  380. function fromArrayLike (array) {
  381. var length = array.length < 0 ? 0 : checked(array.length) | 0
  382. var buf = createBuffer(length)
  383. for (var i = 0; i < length; i += 1) {
  384. buf[i] = array[i] & 255
  385. }
  386. return buf
  387. }
  388. function fromArrayBuffer (array, byteOffset, length) {
  389. if (byteOffset < 0 || array.byteLength < byteOffset) {
  390. throw new RangeError('"offset" is outside of buffer bounds')
  391. }
  392. if (array.byteLength < byteOffset + (length || 0)) {
  393. throw new RangeError('"length" is outside of buffer bounds')
  394. }
  395. var buf
  396. if (byteOffset === undefined && length === undefined) {
  397. buf = new Uint8Array(array)
  398. } else if (length === undefined) {
  399. buf = new Uint8Array(array, byteOffset)
  400. } else {
  401. buf = new Uint8Array(array, byteOffset, length)
  402. }
  403. // Return an augmented `Uint8Array` instance
  404. buf.__proto__ = Buffer.prototype
  405. return buf
  406. }
  407. function fromObject (obj) {
  408. if (Buffer.isBuffer(obj)) {
  409. var len = checked(obj.length) | 0
  410. var buf = createBuffer(len)
  411. if (buf.length === 0) {
  412. return buf
  413. }
  414. obj.copy(buf, 0, 0, len)
  415. return buf
  416. }
  417. if (obj) {
  418. if (ArrayBuffer.isView(obj) || 'length' in obj) {
  419. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  420. return createBuffer(0)
  421. }
  422. return fromArrayLike(obj)
  423. }
  424. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  425. return fromArrayLike(obj.data)
  426. }
  427. }
  428. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object.')
  429. }
  430. function checked (length) {
  431. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  432. // length is NaN (which is otherwise coerced to zero.)
  433. if (length >= K_MAX_LENGTH) {
  434. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  435. 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
  436. }
  437. return length | 0
  438. }
  439. function SlowBuffer (length) {
  440. if (+length != length) { // eslint-disable-line eqeqeq
  441. length = 0
  442. }
  443. return Buffer.alloc(+length)
  444. }
  445. Buffer.isBuffer = function isBuffer (b) {
  446. return b != null && b._isBuffer === true
  447. }
  448. Buffer.compare = function compare (a, b) {
  449. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  450. throw new TypeError('Arguments must be Buffers')
  451. }
  452. if (a === b) return 0
  453. var x = a.length
  454. var y = b.length
  455. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  456. if (a[i] !== b[i]) {
  457. x = a[i]
  458. y = b[i]
  459. break
  460. }
  461. }
  462. if (x < y) return -1
  463. if (y < x) return 1
  464. return 0
  465. }
  466. Buffer.isEncoding = function isEncoding (encoding) {
  467. switch (String(encoding).toLowerCase()) {
  468. case 'hex':
  469. case 'utf8':
  470. case 'utf-8':
  471. case 'ascii':
  472. case 'latin1':
  473. case 'binary':
  474. case 'base64':
  475. case 'ucs2':
  476. case 'ucs-2':
  477. case 'utf16le':
  478. case 'utf-16le':
  479. return true
  480. default:
  481. return false
  482. }
  483. }
  484. Buffer.concat = function concat (list, length) {
  485. if (!Array.isArray(list)) {
  486. throw new TypeError('"list" argument must be an Array of Buffers')
  487. }
  488. if (list.length === 0) {
  489. return Buffer.alloc(0)
  490. }
  491. var i
  492. if (length === undefined) {
  493. length = 0
  494. for (i = 0; i < list.length; ++i) {
  495. length += list[i].length
  496. }
  497. }
  498. var buffer = Buffer.allocUnsafe(length)
  499. var pos = 0
  500. for (i = 0; i < list.length; ++i) {
  501. var buf = list[i]
  502. if (ArrayBuffer.isView(buf)) {
  503. buf = Buffer.from(buf)
  504. }
  505. if (!Buffer.isBuffer(buf)) {
  506. throw new TypeError('"list" argument must be an Array of Buffers')
  507. }
  508. buf.copy(buffer, pos)
  509. pos += buf.length
  510. }
  511. return buffer
  512. }
  513. function byteLength (string, encoding) {
  514. if (Buffer.isBuffer(string)) {
  515. return string.length
  516. }
  517. if (ArrayBuffer.isView(string) || isArrayBuffer(string)) {
  518. return string.byteLength
  519. }
  520. if (typeof string !== 'string') {
  521. string = '' + string
  522. }
  523. var len = string.length
  524. if (len === 0) return 0
  525. // Use a for loop to avoid recursion
  526. var loweredCase = false
  527. for (;;) {
  528. switch (encoding) {
  529. case 'ascii':
  530. case 'latin1':
  531. case 'binary':
  532. return len
  533. case 'utf8':
  534. case 'utf-8':
  535. case undefined:
  536. return utf8ToBytes(string).length
  537. case 'ucs2':
  538. case 'ucs-2':
  539. case 'utf16le':
  540. case 'utf-16le':
  541. return len * 2
  542. case 'hex':
  543. return len >>> 1
  544. case 'base64':
  545. return base64ToBytes(string).length
  546. default:
  547. if (loweredCase) return utf8ToBytes(string).length // assume utf8
  548. encoding = ('' + encoding).toLowerCase()
  549. loweredCase = true
  550. }
  551. }
  552. }
  553. Buffer.byteLength = byteLength
  554. function slowToString (encoding, start, end) {
  555. var loweredCase = false
  556. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  557. // property of a typed array.
  558. // This behaves neither like String nor Uint8Array in that we set start/end
  559. // to their upper/lower bounds if the value passed is out of range.
  560. // undefined is handled specially as per ECMA-262 6th Edition,
  561. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  562. if (start === undefined || start < 0) {
  563. start = 0
  564. }
  565. // Return early if start > this.length. Done here to prevent potential uint32
  566. // coercion fail below.
  567. if (start > this.length) {
  568. return ''
  569. }
  570. if (end === undefined || end > this.length) {
  571. end = this.length
  572. }
  573. if (end <= 0) {
  574. return ''
  575. }
  576. // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  577. end >>>= 0
  578. start >>>= 0
  579. if (end <= start) {
  580. return ''
  581. }
  582. if (!encoding) encoding = 'utf8'
  583. while (true) {
  584. switch (encoding) {
  585. case 'hex':
  586. return hexSlice(this, start, end)
  587. case 'utf8':
  588. case 'utf-8':
  589. return utf8Slice(this, start, end)
  590. case 'ascii':
  591. return asciiSlice(this, start, end)
  592. case 'latin1':
  593. case 'binary':
  594. return latin1Slice(this, start, end)
  595. case 'base64':
  596. return base64Slice(this, start, end)
  597. case 'ucs2':
  598. case 'ucs-2':
  599. case 'utf16le':
  600. case 'utf-16le':
  601. return utf16leSlice(this, start, end)
  602. default:
  603. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  604. encoding = (encoding + '').toLowerCase()
  605. loweredCase = true
  606. }
  607. }
  608. }
  609. // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  610. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  611. // reliably in a browserify context because there could be multiple different
  612. // copies of the 'buffer' package in use. This method works even for Buffer
  613. // instances that were created from another copy of the `buffer` package.
  614. // See: https://github.com/feross/buffer/issues/154
  615. Buffer.prototype._isBuffer = true
  616. function swap (b, n, m) {
  617. var i = b[n]
  618. b[n] = b[m]
  619. b[m] = i
  620. }
  621. Buffer.prototype.swap16 = function swap16 () {
  622. var len = this.length
  623. if (len % 2 !== 0) {
  624. throw new RangeError('Buffer size must be a multiple of 16-bits')
  625. }
  626. for (var i = 0; i < len; i += 2) {
  627. swap(this, i, i + 1)
  628. }
  629. return this
  630. }
  631. Buffer.prototype.swap32 = function swap32 () {
  632. var len = this.length
  633. if (len % 4 !== 0) {
  634. throw new RangeError('Buffer size must be a multiple of 32-bits')
  635. }
  636. for (var i = 0; i < len; i += 4) {
  637. swap(this, i, i + 3)
  638. swap(this, i + 1, i + 2)
  639. }
  640. return this
  641. }
  642. Buffer.prototype.swap64 = function swap64 () {
  643. var len = this.length
  644. if (len % 8 !== 0) {
  645. throw new RangeError('Buffer size must be a multiple of 64-bits')
  646. }
  647. for (var i = 0; i < len; i += 8) {
  648. swap(this, i, i + 7)
  649. swap(this, i + 1, i + 6)
  650. swap(this, i + 2, i + 5)
  651. swap(this, i + 3, i + 4)
  652. }
  653. return this
  654. }
  655. Buffer.prototype.toString = function toString () {
  656. var length = this.length
  657. if (length === 0) return ''
  658. if (arguments.length === 0) return utf8Slice(this, 0, length)
  659. return slowToString.apply(this, arguments)
  660. }
  661. Buffer.prototype.toLocaleString = Buffer.prototype.toString
  662. Buffer.prototype.equals = function equals (b) {
  663. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  664. if (this === b) return true
  665. return Buffer.compare(this, b) === 0
  666. }
  667. Buffer.prototype.inspect = function inspect () {
  668. var str = ''
  669. var max = exports.INSPECT_MAX_BYTES
  670. if (this.length > 0) {
  671. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
  672. if (this.length > max) str += ' ... '
  673. }
  674. return '<Buffer ' + str + '>'
  675. }
  676. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  677. if (!Buffer.isBuffer(target)) {
  678. throw new TypeError('Argument must be a Buffer')
  679. }
  680. if (start === undefined) {
  681. start = 0
  682. }
  683. if (end === undefined) {
  684. end = target ? target.length : 0
  685. }
  686. if (thisStart === undefined) {
  687. thisStart = 0
  688. }
  689. if (thisEnd === undefined) {
  690. thisEnd = this.length
  691. }
  692. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  693. throw new RangeError('out of range index')
  694. }
  695. if (thisStart >= thisEnd && start >= end) {
  696. return 0
  697. }
  698. if (thisStart >= thisEnd) {
  699. return -1
  700. }
  701. if (start >= end) {
  702. return 1
  703. }
  704. start >>>= 0
  705. end >>>= 0
  706. thisStart >>>= 0
  707. thisEnd >>>= 0
  708. if (this === target) return 0
  709. var x = thisEnd - thisStart
  710. var y = end - start
  711. var len = Math.min(x, y)
  712. var thisCopy = this.slice(thisStart, thisEnd)
  713. var targetCopy = target.slice(start, end)
  714. for (var i = 0; i < len; ++i) {
  715. if (thisCopy[i] !== targetCopy[i]) {
  716. x = thisCopy[i]
  717. y = targetCopy[i]
  718. break
  719. }
  720. }
  721. if (x < y) return -1
  722. if (y < x) return 1
  723. return 0
  724. }
  725. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  726. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  727. //
  728. // Arguments:
  729. // - buffer - a Buffer to search
  730. // - val - a string, Buffer, or number
  731. // - byteOffset - an index into `buffer`; will be clamped to an int32
  732. // - encoding - an optional encoding, relevant is val is a string
  733. // - dir - true for indexOf, false for lastIndexOf
  734. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  735. // Empty buffer means no match
  736. if (buffer.length === 0) return -1
  737. // Normalize byteOffset
  738. if (typeof byteOffset === 'string') {
  739. encoding = byteOffset
  740. byteOffset = 0
  741. } else if (byteOffset > 0x7fffffff) {
  742. byteOffset = 0x7fffffff
  743. } else if (byteOffset < -0x80000000) {
  744. byteOffset = -0x80000000
  745. }
  746. byteOffset = +byteOffset // Coerce to Number.
  747. if (numberIsNaN(byteOffset)) {
  748. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  749. byteOffset = dir ? 0 : (buffer.length - 1)
  750. }
  751. // Normalize byteOffset: negative offsets start from the end of the buffer
  752. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  753. if (byteOffset >= buffer.length) {
  754. if (dir) return -1
  755. else byteOffset = buffer.length - 1
  756. } else if (byteOffset < 0) {
  757. if (dir) byteOffset = 0
  758. else return -1
  759. }
  760. // Normalize val
  761. if (typeof val === 'string') {
  762. val = Buffer.from(val, encoding)
  763. }
  764. // Finally, search either indexOf (if dir is true) or lastIndexOf
  765. if (Buffer.isBuffer(val)) {
  766. // Special case: looking for empty string/buffer always fails
  767. if (val.length === 0) {
  768. return -1
  769. }
  770. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  771. } else if (typeof val === 'number') {
  772. val = val & 0xFF // Search for a byte value [0-255]
  773. if (typeof Uint8Array.prototype.indexOf === 'function') {
  774. if (dir) {
  775. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  776. } else {
  777. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  778. }
  779. }
  780. return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
  781. }
  782. throw new TypeError('val must be string, number or Buffer')
  783. }
  784. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  785. var indexSize = 1
  786. var arrLength = arr.length
  787. var valLength = val.length
  788. if (encoding !== undefined) {
  789. encoding = String(encoding).toLowerCase()
  790. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  791. encoding === 'utf16le' || encoding === 'utf-16le') {
  792. if (arr.length < 2 || val.length < 2) {
  793. return -1
  794. }
  795. indexSize = 2
  796. arrLength /= 2
  797. valLength /= 2
  798. byteOffset /= 2
  799. }
  800. }
  801. function read (buf, i) {
  802. if (indexSize === 1) {
  803. return buf[i]
  804. } else {
  805. return buf.readUInt16BE(i * indexSize)
  806. }
  807. }
  808. var i
  809. if (dir) {
  810. var foundIndex = -1
  811. for (i = byteOffset; i < arrLength; i++) {
  812. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  813. if (foundIndex === -1) foundIndex = i
  814. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  815. } else {
  816. if (foundIndex !== -1) i -= i - foundIndex
  817. foundIndex = -1
  818. }
  819. }
  820. } else {
  821. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  822. for (i = byteOffset; i >= 0; i--) {
  823. var found = true
  824. for (var j = 0; j < valLength; j++) {
  825. if (read(arr, i + j) !== read(val, j)) {
  826. found = false
  827. break
  828. }
  829. }
  830. if (found) return i
  831. }
  832. }
  833. return -1
  834. }
  835. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  836. return this.indexOf(val, byteOffset, encoding) !== -1
  837. }
  838. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  839. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  840. }
  841. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  842. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  843. }
  844. function hexWrite (buf, string, offset, length) {
  845. offset = Number(offset) || 0
  846. var remaining = buf.length - offset
  847. if (!length) {
  848. length = remaining
  849. } else {
  850. length = Number(length)
  851. if (length > remaining) {
  852. length = remaining
  853. }
  854. }
  855. var strLen = string.length
  856. if (length > strLen / 2) {
  857. length = strLen / 2
  858. }
  859. for (var i = 0; i < length; ++i) {
  860. var parsed = parseInt(string.substr(i * 2, 2), 16)
  861. if (numberIsNaN(parsed)) return i
  862. buf[offset + i] = parsed
  863. }
  864. return i
  865. }
  866. function utf8Write (buf, string, offset, length) {
  867. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
  868. }
  869. function asciiWrite (buf, string, offset, length) {
  870. return blitBuffer(asciiToBytes(string), buf, offset, length)
  871. }
  872. function latin1Write (buf, string, offset, length) {
  873. return asciiWrite(buf, string, offset, length)
  874. }
  875. function base64Write (buf, string, offset, length) {
  876. return blitBuffer(base64ToBytes(string), buf, offset, length)
  877. }
  878. function ucs2Write (buf, string, offset, length) {
  879. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
  880. }
  881. Buffer.prototype.write = function write (string, offset, length, encoding) {
  882. // Buffer#write(string)
  883. if (offset === undefined) {
  884. encoding = 'utf8'
  885. length = this.length
  886. offset = 0
  887. // Buffer#write(string, encoding)
  888. } else if (length === undefined && typeof offset === 'string') {
  889. encoding = offset
  890. length = this.length
  891. offset = 0
  892. // Buffer#write(string, offset[, length][, encoding])
  893. } else if (isFinite(offset)) {
  894. offset = offset >>> 0
  895. if (isFinite(length)) {
  896. length = length >>> 0
  897. if (encoding === undefined) encoding = 'utf8'
  898. } else {
  899. encoding = length
  900. length = undefined
  901. }
  902. } else {
  903. throw new Error(
  904. 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
  905. )
  906. }
  907. var remaining = this.length - offset
  908. if (length === undefined || length > remaining) length = remaining
  909. if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
  910. throw new RangeError('Attempt to write outside buffer bounds')
  911. }
  912. if (!encoding) encoding = 'utf8'
  913. var loweredCase = false
  914. for (;;) {
  915. switch (encoding) {
  916. case 'hex':
  917. return hexWrite(this, string, offset, length)
  918. case 'utf8':
  919. case 'utf-8':
  920. return utf8Write(this, string, offset, length)
  921. case 'ascii':
  922. return asciiWrite(this, string, offset, length)
  923. case 'latin1':
  924. case 'binary':
  925. return latin1Write(this, string, offset, length)
  926. case 'base64':
  927. // Warning: maxLength not taken into account in base64Write
  928. return base64Write(this, string, offset, length)
  929. case 'ucs2':
  930. case 'ucs-2':
  931. case 'utf16le':
  932. case 'utf-16le':
  933. return ucs2Write(this, string, offset, length)
  934. default:
  935. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  936. encoding = ('' + encoding).toLowerCase()
  937. loweredCase = true
  938. }
  939. }
  940. }
  941. Buffer.prototype.toJSON = function toJSON () {
  942. return {
  943. type: 'Buffer',
  944. data: Array.prototype.slice.call(this._arr || this, 0)
  945. }
  946. }
  947. function base64Slice (buf, start, end) {
  948. if (start === 0 && end === buf.length) {
  949. return base64.fromByteArray(buf)
  950. } else {
  951. return base64.fromByteArray(buf.slice(start, end))
  952. }
  953. }
  954. function utf8Slice (buf, start, end) {
  955. end = Math.min(buf.length, end)
  956. var res = []
  957. var i = start
  958. while (i < end) {
  959. var firstByte = buf[i]
  960. var codePoint = null
  961. var bytesPerSequence = (firstByte > 0xEF) ? 4
  962. : (firstByte > 0xDF) ? 3
  963. : (firstByte > 0xBF) ? 2
  964. : 1
  965. if (i + bytesPerSequence <= end) {
  966. var secondByte, thirdByte, fourthByte, tempCodePoint
  967. switch (bytesPerSequence) {
  968. case 1:
  969. if (firstByte < 0x80) {
  970. codePoint = firstByte
  971. }
  972. break
  973. case 2:
  974. secondByte = buf[i + 1]
  975. if ((secondByte & 0xC0) === 0x80) {
  976. tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
  977. if (tempCodePoint > 0x7F) {
  978. codePoint = tempCodePoint
  979. }
  980. }
  981. break
  982. case 3:
  983. secondByte = buf[i + 1]
  984. thirdByte = buf[i + 2]
  985. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  986. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
  987. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  988. codePoint = tempCodePoint
  989. }
  990. }
  991. break
  992. case 4:
  993. secondByte = buf[i + 1]
  994. thirdByte = buf[i + 2]
  995. fourthByte = buf[i + 3]
  996. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  997. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
  998. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  999. codePoint = tempCodePoint
  1000. }
  1001. }
  1002. }
  1003. }
  1004. if (codePoint === null) {
  1005. // we did not generate a valid codePoint so insert a
  1006. // replacement char (U+FFFD) and advance only 1 byte
  1007. codePoint = 0xFFFD
  1008. bytesPerSequence = 1
  1009. } else if (codePoint > 0xFFFF) {
  1010. // encode to utf16 (surrogate pair dance)
  1011. codePoint -= 0x10000
  1012. res.push(codePoint >>> 10 & 0x3FF | 0xD800)
  1013. codePoint = 0xDC00 | codePoint & 0x3FF
  1014. }
  1015. res.push(codePoint)
  1016. i += bytesPerSequence
  1017. }
  1018. return decodeCodePointsArray(res)
  1019. }
  1020. // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  1021. // the lowest limit is Chrome, with 0x10000 args.
  1022. // We go 1 magnitude less, for safety
  1023. var MAX_ARGUMENTS_LENGTH = 0x1000
  1024. function decodeCodePointsArray (codePoints) {
  1025. var len = codePoints.length
  1026. if (len <= MAX_ARGUMENTS_LENGTH) {
  1027. return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
  1028. }
  1029. // Decode in chunks to avoid "call stack size exceeded".
  1030. var res = ''
  1031. var i = 0
  1032. while (i < len) {
  1033. res += String.fromCharCode.apply(
  1034. String,
  1035. codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
  1036. )
  1037. }
  1038. return res
  1039. }
  1040. function asciiSlice (buf, start, end) {
  1041. var ret = ''
  1042. end = Math.min(buf.length, end)
  1043. for (var i = start; i < end; ++i) {
  1044. ret += String.fromCharCode(buf[i] & 0x7F)
  1045. }
  1046. return ret
  1047. }
  1048. function latin1Slice (buf, start, end) {
  1049. var ret = ''
  1050. end = Math.min(buf.length, end)
  1051. for (var i = start; i < end; ++i) {
  1052. ret += String.fromCharCode(buf[i])
  1053. }
  1054. return ret
  1055. }
  1056. function hexSlice (buf, start, end) {
  1057. var len = buf.length
  1058. if (!start || start < 0) start = 0
  1059. if (!end || end < 0 || end > len) end = len
  1060. var out = ''
  1061. for (var i = start; i < end; ++i) {
  1062. out += toHex(buf[i])
  1063. }
  1064. return out
  1065. }
  1066. function utf16leSlice (buf, start, end) {
  1067. var bytes = buf.slice(start, end)
  1068. var res = ''
  1069. for (var i = 0; i < bytes.length; i += 2) {
  1070. res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256))
  1071. }
  1072. return res
  1073. }
  1074. Buffer.prototype.slice = function slice (start, end) {
  1075. var len = this.length
  1076. start = ~~start
  1077. end = end === undefined ? len : ~~end
  1078. if (start < 0) {
  1079. start += len
  1080. if (start < 0) start = 0
  1081. } else if (start > len) {
  1082. start = len
  1083. }
  1084. if (end < 0) {
  1085. end += len
  1086. if (end < 0) end = 0
  1087. } else if (end > len) {
  1088. end = len
  1089. }
  1090. if (end < start) end = start
  1091. var newBuf = this.subarray(start, end)
  1092. // Return an augmented `Uint8Array` instance
  1093. newBuf.__proto__ = Buffer.prototype
  1094. return newBuf
  1095. }
  1096. /*
  1097. * Need to make sure that buffer isn't trying to write out of bounds.
  1098. */
  1099. function checkOffset (offset, ext, length) {
  1100. if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
  1101. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
  1102. }
  1103. Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
  1104. offset = offset >>> 0
  1105. byteLength = byteLength >>> 0
  1106. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1107. var val = this[offset]
  1108. var mul = 1
  1109. var i = 0
  1110. while (++i < byteLength && (mul *= 0x100)) {
  1111. val += this[offset + i] * mul
  1112. }
  1113. return val
  1114. }
  1115. Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
  1116. offset = offset >>> 0
  1117. byteLength = byteLength >>> 0
  1118. if (!noAssert) {
  1119. checkOffset(offset, byteLength, this.length)
  1120. }
  1121. var val = this[offset + --byteLength]
  1122. var mul = 1
  1123. while (byteLength > 0 && (mul *= 0x100)) {
  1124. val += this[offset + --byteLength] * mul
  1125. }
  1126. return val
  1127. }
  1128. Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
  1129. offset = offset >>> 0
  1130. if (!noAssert) checkOffset(offset, 1, this.length)
  1131. return this[offset]
  1132. }
  1133. Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
  1134. offset = offset >>> 0
  1135. if (!noAssert) checkOffset(offset, 2, this.length)
  1136. return this[offset] | (this[offset + 1] << 8)
  1137. }
  1138. Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
  1139. offset = offset >>> 0
  1140. if (!noAssert) checkOffset(offset, 2, this.length)
  1141. return (this[offset] << 8) | this[offset + 1]
  1142. }
  1143. Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
  1144. offset = offset >>> 0
  1145. if (!noAssert) checkOffset(offset, 4, this.length)
  1146. return ((this[offset]) |
  1147. (this[offset + 1] << 8) |
  1148. (this[offset + 2] << 16)) +
  1149. (this[offset + 3] * 0x1000000)
  1150. }
  1151. Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
  1152. offset = offset >>> 0
  1153. if (!noAssert) checkOffset(offset, 4, this.length)
  1154. return (this[offset] * 0x1000000) +
  1155. ((this[offset + 1] << 16) |
  1156. (this[offset + 2] << 8) |
  1157. this[offset + 3])
  1158. }
  1159. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  1160. offset = offset >>> 0
  1161. byteLength = byteLength >>> 0
  1162. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1163. var val = this[offset]
  1164. var mul = 1
  1165. var i = 0
  1166. while (++i < byteLength && (mul *= 0x100)) {
  1167. val += this[offset + i] * mul
  1168. }
  1169. mul *= 0x80
  1170. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1171. return val
  1172. }
  1173. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  1174. offset = offset >>> 0
  1175. byteLength = byteLength >>> 0
  1176. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1177. var i = byteLength
  1178. var mul = 1
  1179. var val = this[offset + --i]
  1180. while (i > 0 && (mul *= 0x100)) {
  1181. val += this[offset + --i] * mul
  1182. }
  1183. mul *= 0x80
  1184. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1185. return val
  1186. }
  1187. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  1188. offset = offset >>> 0
  1189. if (!noAssert) checkOffset(offset, 1, this.length)
  1190. if (!(this[offset] & 0x80)) return (this[offset])
  1191. return ((0xff - this[offset] + 1) * -1)
  1192. }
  1193. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  1194. offset = offset >>> 0
  1195. if (!noAssert) checkOffset(offset, 2, this.length)
  1196. var val = this[offset] | (this[offset + 1] << 8)
  1197. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1198. }
  1199. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  1200. offset = offset >>> 0
  1201. if (!noAssert) checkOffset(offset, 2, this.length)
  1202. var val = this[offset + 1] | (this[offset] << 8)
  1203. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1204. }
  1205. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  1206. offset = offset >>> 0
  1207. if (!noAssert) checkOffset(offset, 4, this.length)
  1208. return (this[offset]) |
  1209. (this[offset + 1] << 8) |
  1210. (this[offset + 2] << 16) |
  1211. (this[offset + 3] << 24)
  1212. }
  1213. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  1214. offset = offset >>> 0
  1215. if (!noAssert) checkOffset(offset, 4, this.length)
  1216. return (this[offset] << 24) |
  1217. (this[offset + 1] << 16) |
  1218. (this[offset + 2] << 8) |
  1219. (this[offset + 3])
  1220. }
  1221. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  1222. offset = offset >>> 0
  1223. if (!noAssert) checkOffset(offset, 4, this.length)
  1224. return ieee754.read(this, offset, true, 23, 4)
  1225. }
  1226. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  1227. offset = offset >>> 0
  1228. if (!noAssert) checkOffset(offset, 4, this.length)
  1229. return ieee754.read(this, offset, false, 23, 4)
  1230. }
  1231. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  1232. offset = offset >>> 0
  1233. if (!noAssert) checkOffset(offset, 8, this.length)
  1234. return ieee754.read(this, offset, true, 52, 8)
  1235. }
  1236. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  1237. offset = offset >>> 0
  1238. if (!noAssert) checkOffset(offset, 8, this.length)
  1239. return ieee754.read(this, offset, false, 52, 8)
  1240. }
  1241. function checkInt (buf, value, offset, ext, max, min) {
  1242. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  1243. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  1244. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1245. }
  1246. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  1247. value = +value
  1248. offset = offset >>> 0
  1249. byteLength = byteLength >>> 0
  1250. if (!noAssert) {
  1251. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  1252. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1253. }
  1254. var mul = 1
  1255. var i = 0
  1256. this[offset] = value & 0xFF
  1257. while (++i < byteLength && (mul *= 0x100)) {
  1258. this[offset + i] = (value / mul) & 0xFF
  1259. }
  1260. return offset + byteLength
  1261. }
  1262. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  1263. value = +value
  1264. offset = offset >>> 0
  1265. byteLength = byteLength >>> 0
  1266. if (!noAssert) {
  1267. var maxBytes = Math.pow(2, 8 * byteLength) - 1
  1268. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1269. }
  1270. var i = byteLength - 1
  1271. var mul = 1
  1272. this[offset + i] = value & 0xFF
  1273. while (--i >= 0 && (mul *= 0x100)) {
  1274. this[offset + i] = (value / mul) & 0xFF
  1275. }
  1276. return offset + byteLength
  1277. }
  1278. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  1279. value = +value
  1280. offset = offset >>> 0
  1281. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  1282. this[offset] = (value & 0xff)
  1283. return offset + 1
  1284. }
  1285. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  1286. value = +value
  1287. offset = offset >>> 0
  1288. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1289. this[offset] = (value & 0xff)
  1290. this[offset + 1] = (value >>> 8)
  1291. return offset + 2
  1292. }
  1293. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  1294. value = +value
  1295. offset = offset >>> 0
  1296. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1297. this[offset] = (value >>> 8)
  1298. this[offset + 1] = (value & 0xff)
  1299. return offset + 2
  1300. }
  1301. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  1302. value = +value
  1303. offset = offset >>> 0
  1304. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1305. this[offset + 3] = (value >>> 24)
  1306. this[offset + 2] = (value >>> 16)
  1307. this[offset + 1] = (value >>> 8)
  1308. this[offset] = (value & 0xff)
  1309. return offset + 4
  1310. }
  1311. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  1312. value = +value
  1313. offset = offset >>> 0
  1314. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1315. this[offset] = (value >>> 24)
  1316. this[offset + 1] = (value >>> 16)
  1317. this[offset + 2] = (value >>> 8)
  1318. this[offset + 3] = (value & 0xff)
  1319. return offset + 4
  1320. }
  1321. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  1322. value = +value
  1323. offset = offset >>> 0
  1324. if (!noAssert) {
  1325. var limit = Math.pow(2, (8 * byteLength) - 1)
  1326. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1327. }
  1328. var i = 0
  1329. var mul = 1
  1330. var sub = 0
  1331. this[offset] = value & 0xFF
  1332. while (++i < byteLength && (mul *= 0x100)) {
  1333. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  1334. sub = 1
  1335. }
  1336. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1337. }
  1338. return offset + byteLength
  1339. }
  1340. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  1341. value = +value
  1342. offset = offset >>> 0
  1343. if (!noAssert) {
  1344. var limit = Math.pow(2, (8 * byteLength) - 1)
  1345. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1346. }
  1347. var i = byteLength - 1
  1348. var mul = 1
  1349. var sub = 0
  1350. this[offset + i] = value & 0xFF
  1351. while (--i >= 0 && (mul *= 0x100)) {
  1352. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  1353. sub = 1
  1354. }
  1355. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1356. }
  1357. return offset + byteLength
  1358. }
  1359. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  1360. value = +value
  1361. offset = offset >>> 0
  1362. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  1363. if (value < 0) value = 0xff + value + 1
  1364. this[offset] = (value & 0xff)
  1365. return offset + 1
  1366. }
  1367. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  1368. value = +value
  1369. offset = offset >>> 0
  1370. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1371. this[offset] = (value & 0xff)
  1372. this[offset + 1] = (value >>> 8)
  1373. return offset + 2
  1374. }
  1375. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  1376. value = +value
  1377. offset = offset >>> 0
  1378. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1379. this[offset] = (value >>> 8)
  1380. this[offset + 1] = (value & 0xff)
  1381. return offset + 2
  1382. }
  1383. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  1384. value = +value
  1385. offset = offset >>> 0
  1386. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1387. this[offset] = (value & 0xff)
  1388. this[offset + 1] = (value >>> 8)
  1389. this[offset + 2] = (value >>> 16)
  1390. this[offset + 3] = (value >>> 24)
  1391. return offset + 4
  1392. }
  1393. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  1394. value = +value
  1395. offset = offset >>> 0
  1396. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1397. if (value < 0) value = 0xffffffff + value + 1
  1398. this[offset] = (value >>> 24)
  1399. this[offset + 1] = (value >>> 16)
  1400. this[offset + 2] = (value >>> 8)
  1401. this[offset + 3] = (value & 0xff)
  1402. return offset + 4
  1403. }
  1404. function checkIEEE754 (buf, value, offset, ext, max, min) {
  1405. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1406. if (offset < 0) throw new RangeError('Index out of range')
  1407. }
  1408. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  1409. value = +value
  1410. offset = offset >>> 0
  1411. if (!noAssert) {
  1412. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  1413. }
  1414. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  1415. return offset + 4
  1416. }
  1417. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  1418. return writeFloat(this, value, offset, true, noAssert)
  1419. }
  1420. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  1421. return writeFloat(this, value, offset, false, noAssert)
  1422. }
  1423. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  1424. value = +value
  1425. offset = offset >>> 0
  1426. if (!noAssert) {
  1427. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  1428. }
  1429. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  1430. return offset + 8
  1431. }
  1432. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  1433. return writeDouble(this, value, offset, true, noAssert)
  1434. }
  1435. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  1436. return writeDouble(this, value, offset, false, noAssert)
  1437. }
  1438. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  1439. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  1440. if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
  1441. if (!start) start = 0
  1442. if (!end && end !== 0) end = this.length
  1443. if (targetStart >= target.length) targetStart = target.length
  1444. if (!targetStart) targetStart = 0
  1445. if (end > 0 && end < start) end = start
  1446. // Copy 0 bytes; we're done
  1447. if (end === start) return 0
  1448. if (target.length === 0 || this.length === 0) return 0
  1449. // Fatal error conditions
  1450. if (targetStart < 0) {
  1451. throw new RangeError('targetStart out of bounds')
  1452. }
  1453. if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
  1454. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  1455. // Are we oob?
  1456. if (end > this.length) end = this.length
  1457. if (target.length - targetStart < end - start) {
  1458. end = target.length - targetStart + start
  1459. }
  1460. var len = end - start
  1461. if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  1462. // Use built-in when available, missing from IE11
  1463. this.copyWithin(targetStart, start, end)
  1464. } else if (this === target && start < targetStart && targetStart < end) {
  1465. // descending copy from end
  1466. for (var i = len - 1; i >= 0; --i) {
  1467. target[i + targetStart] = this[i + start]
  1468. }
  1469. } else {
  1470. Uint8Array.prototype.set.call(
  1471. target,
  1472. this.subarray(start, end),
  1473. targetStart
  1474. )
  1475. }
  1476. return len
  1477. }
  1478. // Usage:
  1479. // buffer.fill(number[, offset[, end]])
  1480. // buffer.fill(buffer[, offset[, end]])
  1481. // buffer.fill(string[, offset[, end]][, encoding])
  1482. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  1483. // Handle string cases:
  1484. if (typeof val === 'string') {
  1485. if (typeof start === 'string') {
  1486. encoding = start
  1487. start = 0
  1488. end = this.length
  1489. } else if (typeof end === 'string') {
  1490. encoding = end
  1491. end = this.length
  1492. }
  1493. if (encoding !== undefined && typeof encoding !== 'string') {
  1494. throw new TypeError('encoding must be a string')
  1495. }
  1496. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  1497. throw new TypeError('Unknown encoding: ' + encoding)
  1498. }
  1499. if (val.length === 1) {
  1500. var code = val.charCodeAt(0)
  1501. if ((encoding === 'utf8' && code < 128) ||
  1502. encoding === 'latin1') {
  1503. // Fast path: If `val` fits into a single byte, use that numeric value.
  1504. val = code
  1505. }
  1506. }
  1507. } else if (typeof val === 'number') {
  1508. val = val & 255
  1509. }
  1510. // Invalid ranges are not set to a default, so can range check early.
  1511. if (start < 0 || this.length < start || this.length < end) {
  1512. throw new RangeError('Out of range index')
  1513. }
  1514. if (end <= start) {
  1515. return this
  1516. }
  1517. start = start >>> 0
  1518. end = end === undefined ? this.length : end >>> 0
  1519. if (!val) val = 0
  1520. var i
  1521. if (typeof val === 'number') {
  1522. for (i = start; i < end; ++i) {
  1523. this[i] = val
  1524. }
  1525. } else {
  1526. var bytes = Buffer.isBuffer(val)
  1527. ? val
  1528. : new Buffer(val, encoding)
  1529. var len = bytes.length
  1530. if (len === 0) {
  1531. throw new TypeError('The value "' + val +
  1532. '" is invalid for argument "value"')
  1533. }
  1534. for (i = 0; i < end - start; ++i) {
  1535. this[i + start] = bytes[i % len]
  1536. }
  1537. }
  1538. return this
  1539. }
  1540. // HELPER FUNCTIONS
  1541. // ================
  1542. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
  1543. function base64clean (str) {
  1544. // Node takes equal signs as end of the Base64 encoding
  1545. str = str.split('=')[0]
  1546. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  1547. str = str.trim().replace(INVALID_BASE64_RE, '')
  1548. // Node converts strings with length < 2 to ''
  1549. if (str.length < 2) return ''
  1550. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  1551. while (str.length % 4 !== 0) {
  1552. str = str + '='
  1553. }
  1554. return str
  1555. }
  1556. function toHex (n) {
  1557. if (n < 16) return '0' + n.toString(16)
  1558. return n.toString(16)
  1559. }
  1560. function utf8ToBytes (string, units) {
  1561. units = units || Infinity
  1562. var codePoint
  1563. var length = string.length
  1564. var leadSurrogate = null
  1565. var bytes = []
  1566. for (var i = 0; i < length; ++i) {
  1567. codePoint = string.charCodeAt(i)
  1568. // is surrogate component
  1569. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  1570. // last char was a lead
  1571. if (!leadSurrogate) {
  1572. // no lead yet
  1573. if (codePoint > 0xDBFF) {
  1574. // unexpected trail
  1575. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1576. continue
  1577. } else if (i + 1 === length) {
  1578. // unpaired lead
  1579. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1580. continue
  1581. }
  1582. // valid lead
  1583. leadSurrogate = codePoint
  1584. continue
  1585. }
  1586. // 2 leads in a row
  1587. if (codePoint < 0xDC00) {
  1588. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1589. leadSurrogate = codePoint
  1590. continue
  1591. }
  1592. // valid surrogate pair
  1593. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  1594. } else if (leadSurrogate) {
  1595. // valid bmp char, but last char was a lead
  1596. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1597. }
  1598. leadSurrogate = null
  1599. // encode utf8
  1600. if (codePoint < 0x80) {
  1601. if ((units -= 1) < 0) break
  1602. bytes.push(codePoint)
  1603. } else if (codePoint < 0x800) {
  1604. if ((units -= 2) < 0) break
  1605. bytes.push(
  1606. codePoint >> 0x6 | 0xC0,
  1607. codePoint & 0x3F | 0x80
  1608. )
  1609. } else if (codePoint < 0x10000) {
  1610. if ((units -= 3) < 0) break
  1611. bytes.push(
  1612. codePoint >> 0xC | 0xE0,
  1613. codePoint >> 0x6 & 0x3F | 0x80,
  1614. codePoint & 0x3F | 0x80
  1615. )
  1616. } else if (codePoint < 0x110000) {
  1617. if ((units -= 4) < 0) break
  1618. bytes.push(
  1619. codePoint >> 0x12 | 0xF0,
  1620. codePoint >> 0xC & 0x3F | 0x80,
  1621. codePoint >> 0x6 & 0x3F | 0x80,
  1622. codePoint & 0x3F | 0x80
  1623. )
  1624. } else {
  1625. throw new Error('Invalid code point')
  1626. }
  1627. }
  1628. return bytes
  1629. }
  1630. function asciiToBytes (str) {
  1631. var byteArray = []
  1632. for (var i = 0; i < str.length; ++i) {
  1633. // Node's code seems to be doing this and not & 0x7F..
  1634. byteArray.push(str.charCodeAt(i) & 0xFF)
  1635. }
  1636. return byteArray
  1637. }
  1638. function utf16leToBytes (str, units) {
  1639. var c, hi, lo
  1640. var byteArray = []
  1641. for (var i = 0; i < str.length; ++i) {
  1642. if ((units -= 2) < 0) break
  1643. c = str.charCodeAt(i)
  1644. hi = c >> 8
  1645. lo = c % 256
  1646. byteArray.push(lo)
  1647. byteArray.push(hi)
  1648. }
  1649. return byteArray
  1650. }
  1651. function base64ToBytes (str) {
  1652. return base64.toByteArray(base64clean(str))
  1653. }
  1654. function blitBuffer (src, dst, offset, length) {
  1655. for (var i = 0; i < length; ++i) {
  1656. if ((i + offset >= dst.length) || (i >= src.length)) break
  1657. dst[i + offset] = src[i]
  1658. }
  1659. return i
  1660. }
  1661. // ArrayBuffers from another context (i.e. an iframe) do not pass the `instanceof` check
  1662. // but they should be treated as valid. See: https://github.com/feross/buffer/issues/166
  1663. function isArrayBuffer (obj) {
  1664. return obj instanceof ArrayBuffer ||
  1665. (obj != null && obj.constructor != null && obj.constructor.name === 'ArrayBuffer' &&
  1666. typeof obj.byteLength === 'number')
  1667. }
  1668. function numberIsNaN (obj) {
  1669. return obj !== obj // eslint-disable-line no-self-compare
  1670. }
  1671. },{"base64-js":2,"ieee754":4}],4:[function(require,module,exports){
  1672. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  1673. var e, m
  1674. var eLen = (nBytes * 8) - mLen - 1
  1675. var eMax = (1 << eLen) - 1
  1676. var eBias = eMax >> 1
  1677. var nBits = -7
  1678. var i = isLE ? (nBytes - 1) : 0
  1679. var d = isLE ? -1 : 1
  1680. var s = buffer[offset + i]
  1681. i += d
  1682. e = s & ((1 << (-nBits)) - 1)
  1683. s >>= (-nBits)
  1684. nBits += eLen
  1685. for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  1686. m = e & ((1 << (-nBits)) - 1)
  1687. e >>= (-nBits)
  1688. nBits += mLen
  1689. for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
  1690. if (e === 0) {
  1691. e = 1 - eBias
  1692. } else if (e === eMax) {
  1693. return m ? NaN : ((s ? -1 : 1) * Infinity)
  1694. } else {
  1695. m = m + Math.pow(2, mLen)
  1696. e = e - eBias
  1697. }
  1698. return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
  1699. }
  1700. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  1701. var e, m, c
  1702. var eLen = (nBytes * 8) - mLen - 1
  1703. var eMax = (1 << eLen) - 1
  1704. var eBias = eMax >> 1
  1705. var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
  1706. var i = isLE ? 0 : (nBytes - 1)
  1707. var d = isLE ? 1 : -1
  1708. var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
  1709. value = Math.abs(value)
  1710. if (isNaN(value) || value === Infinity) {
  1711. m = isNaN(value) ? 1 : 0
  1712. e = eMax
  1713. } else {
  1714. e = Math.floor(Math.log(value) / Math.LN2)
  1715. if (value * (c = Math.pow(2, -e)) < 1) {
  1716. e--
  1717. c *= 2
  1718. }
  1719. if (e + eBias >= 1) {
  1720. value += rt / c
  1721. } else {
  1722. value += rt * Math.pow(2, 1 - eBias)
  1723. }
  1724. if (value * c >= 2) {
  1725. e++
  1726. c /= 2
  1727. }
  1728. if (e + eBias >= eMax) {
  1729. m = 0
  1730. e = eMax
  1731. } else if (e + eBias >= 1) {
  1732. m = ((value * c) - 1) * Math.pow(2, mLen)
  1733. e = e + eBias
  1734. } else {
  1735. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
  1736. e = 0
  1737. }
  1738. }
  1739. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  1740. e = (e << mLen) | m
  1741. eLen += mLen
  1742. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  1743. buffer[offset + i - d] |= s * 128
  1744. }
  1745. },{}]},{},[1]);