index.js 50 KB

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