index.js 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119
  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__(1682324647460, 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. const base64 = require('base64-js')
  16. const ieee754 = require('ieee754')
  17. const 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. const 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. const arr = new Uint8Array(1)
  52. const 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. const 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. const valueOf = value.valueOf && value.valueOf()
  133. if (valueOf != null && valueOf !== value) {
  134. return Buffer.from(valueOf, encodingOrOffset, length)
  135. }
  136. const 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(value[Symbol.toPrimitive]('string'), encodingOrOffset, length)
  141. }
  142. throw new TypeError(
  143. 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
  144. 'or Array-like Object. Received type ' + (typeof value)
  145. )
  146. }
  147. /**
  148. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  149. * if value is a number.
  150. * Buffer.from(str[, encoding])
  151. * Buffer.from(array)
  152. * Buffer.from(buffer)
  153. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  154. **/
  155. Buffer.from = function (value, encodingOrOffset, length) {
  156. return from(value, encodingOrOffset, length)
  157. }
  158. // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  159. // https://github.com/feross/buffer/pull/148
  160. Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype)
  161. Object.setPrototypeOf(Buffer, Uint8Array)
  162. function assertSize (size) {
  163. if (typeof size !== 'number') {
  164. throw new TypeError('"size" argument must be of type number')
  165. } else if (size < 0) {
  166. throw new RangeError('The value "' + size + '" is invalid for option "size"')
  167. }
  168. }
  169. function alloc (size, fill, encoding) {
  170. assertSize(size)
  171. if (size <= 0) {
  172. return createBuffer(size)
  173. }
  174. if (fill !== undefined) {
  175. // Only pay attention to encoding if it's a string. This
  176. // prevents accidentally sending in a number that would
  177. // be interpreted as a start offset.
  178. return typeof encoding === 'string'
  179. ? createBuffer(size).fill(fill, encoding)
  180. : createBuffer(size).fill(fill)
  181. }
  182. return createBuffer(size)
  183. }
  184. /**
  185. * Creates a new filled Buffer instance.
  186. * alloc(size[, fill[, encoding]])
  187. **/
  188. Buffer.alloc = function (size, fill, encoding) {
  189. return alloc(size, fill, encoding)
  190. }
  191. function allocUnsafe (size) {
  192. assertSize(size)
  193. return createBuffer(size < 0 ? 0 : checked(size) | 0)
  194. }
  195. /**
  196. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  197. * */
  198. Buffer.allocUnsafe = function (size) {
  199. return allocUnsafe(size)
  200. }
  201. /**
  202. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  203. */
  204. Buffer.allocUnsafeSlow = function (size) {
  205. return allocUnsafe(size)
  206. }
  207. function fromString (string, encoding) {
  208. if (typeof encoding !== 'string' || encoding === '') {
  209. encoding = 'utf8'
  210. }
  211. if (!Buffer.isEncoding(encoding)) {
  212. throw new TypeError('Unknown encoding: ' + encoding)
  213. }
  214. const length = byteLength(string, encoding) | 0
  215. let buf = createBuffer(length)
  216. const actual = buf.write(string, encoding)
  217. if (actual !== length) {
  218. // Writing a hex string, for example, that contains invalid characters will
  219. // cause everything after the first invalid character to be ignored. (e.g.
  220. // 'abxxcd' will be treated as 'ab')
  221. buf = buf.slice(0, actual)
  222. }
  223. return buf
  224. }
  225. function fromArrayLike (array) {
  226. const length = array.length < 0 ? 0 : checked(array.length) | 0
  227. const buf = createBuffer(length)
  228. for (let i = 0; i < length; i += 1) {
  229. buf[i] = array[i] & 255
  230. }
  231. return buf
  232. }
  233. function fromArrayView (arrayView) {
  234. if (isInstance(arrayView, Uint8Array)) {
  235. const copy = new Uint8Array(arrayView)
  236. return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
  237. }
  238. return fromArrayLike(arrayView)
  239. }
  240. function fromArrayBuffer (array, byteOffset, length) {
  241. if (byteOffset < 0 || array.byteLength < byteOffset) {
  242. throw new RangeError('"offset" is outside of buffer bounds')
  243. }
  244. if (array.byteLength < byteOffset + (length || 0)) {
  245. throw new RangeError('"length" is outside of buffer bounds')
  246. }
  247. let buf
  248. if (byteOffset === undefined && length === undefined) {
  249. buf = new Uint8Array(array)
  250. } else if (length === undefined) {
  251. buf = new Uint8Array(array, byteOffset)
  252. } else {
  253. buf = new Uint8Array(array, byteOffset, length)
  254. }
  255. // Return an augmented `Uint8Array` instance
  256. Object.setPrototypeOf(buf, Buffer.prototype)
  257. return buf
  258. }
  259. function fromObject (obj) {
  260. if (Buffer.isBuffer(obj)) {
  261. const len = checked(obj.length) | 0
  262. const buf = createBuffer(len)
  263. if (buf.length === 0) {
  264. return buf
  265. }
  266. obj.copy(buf, 0, 0, len)
  267. return buf
  268. }
  269. if (obj.length !== undefined) {
  270. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  271. return createBuffer(0)
  272. }
  273. return fromArrayLike(obj)
  274. }
  275. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  276. return fromArrayLike(obj.data)
  277. }
  278. }
  279. function checked (length) {
  280. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  281. // length is NaN (which is otherwise coerced to zero.)
  282. if (length >= K_MAX_LENGTH) {
  283. throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
  284. 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
  285. }
  286. return length | 0
  287. }
  288. function SlowBuffer (length) {
  289. if (+length != length) { // eslint-disable-line eqeqeq
  290. length = 0
  291. }
  292. return Buffer.alloc(+length)
  293. }
  294. Buffer.isBuffer = function isBuffer (b) {
  295. return b != null && b._isBuffer === true &&
  296. b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
  297. }
  298. Buffer.compare = function compare (a, b) {
  299. if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength)
  300. if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength)
  301. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  302. throw new TypeError(
  303. 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
  304. )
  305. }
  306. if (a === b) return 0
  307. let x = a.length
  308. let y = b.length
  309. for (let i = 0, len = Math.min(x, y); i < len; ++i) {
  310. if (a[i] !== b[i]) {
  311. x = a[i]
  312. y = b[i]
  313. break
  314. }
  315. }
  316. if (x < y) return -1
  317. if (y < x) return 1
  318. return 0
  319. }
  320. Buffer.isEncoding = function isEncoding (encoding) {
  321. switch (String(encoding).toLowerCase()) {
  322. case 'hex':
  323. case 'utf8':
  324. case 'utf-8':
  325. case 'ascii':
  326. case 'latin1':
  327. case 'binary':
  328. case 'base64':
  329. case 'ucs2':
  330. case 'ucs-2':
  331. case 'utf16le':
  332. case 'utf-16le':
  333. return true
  334. default:
  335. return false
  336. }
  337. }
  338. Buffer.concat = function concat (list, length) {
  339. if (!Array.isArray(list)) {
  340. throw new TypeError('"list" argument must be an Array of Buffers')
  341. }
  342. if (list.length === 0) {
  343. return Buffer.alloc(0)
  344. }
  345. let i
  346. if (length === undefined) {
  347. length = 0
  348. for (i = 0; i < list.length; ++i) {
  349. length += list[i].length
  350. }
  351. }
  352. const buffer = Buffer.allocUnsafe(length)
  353. let pos = 0
  354. for (i = 0; i < list.length; ++i) {
  355. let buf = list[i]
  356. if (isInstance(buf, Uint8Array)) {
  357. if (pos + buf.length > buffer.length) {
  358. if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf)
  359. buf.copy(buffer, pos)
  360. } else {
  361. Uint8Array.prototype.set.call(
  362. buffer,
  363. buf,
  364. pos
  365. )
  366. }
  367. } else if (!Buffer.isBuffer(buf)) {
  368. throw new TypeError('"list" argument must be an Array of Buffers')
  369. } else {
  370. buf.copy(buffer, pos)
  371. }
  372. pos += buf.length
  373. }
  374. return buffer
  375. }
  376. function byteLength (string, encoding) {
  377. if (Buffer.isBuffer(string)) {
  378. return string.length
  379. }
  380. if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
  381. return string.byteLength
  382. }
  383. if (typeof string !== 'string') {
  384. throw new TypeError(
  385. 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
  386. 'Received type ' + typeof string
  387. )
  388. }
  389. const len = string.length
  390. const mustMatch = (arguments.length > 2 && arguments[2] === true)
  391. if (!mustMatch && len === 0) return 0
  392. // Use a for loop to avoid recursion
  393. let loweredCase = false
  394. for (;;) {
  395. switch (encoding) {
  396. case 'ascii':
  397. case 'latin1':
  398. case 'binary':
  399. return len
  400. case 'utf8':
  401. case 'utf-8':
  402. return utf8ToBytes(string).length
  403. case 'ucs2':
  404. case 'ucs-2':
  405. case 'utf16le':
  406. case 'utf-16le':
  407. return len * 2
  408. case 'hex':
  409. return len >>> 1
  410. case 'base64':
  411. return base64ToBytes(string).length
  412. default:
  413. if (loweredCase) {
  414. return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
  415. }
  416. encoding = ('' + encoding).toLowerCase()
  417. loweredCase = true
  418. }
  419. }
  420. }
  421. Buffer.byteLength = byteLength
  422. function slowToString (encoding, start, end) {
  423. let loweredCase = false
  424. // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  425. // property of a typed array.
  426. // This behaves neither like String nor Uint8Array in that we set start/end
  427. // to their upper/lower bounds if the value passed is out of range.
  428. // undefined is handled specially as per ECMA-262 6th Edition,
  429. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  430. if (start === undefined || start < 0) {
  431. start = 0
  432. }
  433. // Return early if start > this.length. Done here to prevent potential uint32
  434. // coercion fail below.
  435. if (start > this.length) {
  436. return ''
  437. }
  438. if (end === undefined || end > this.length) {
  439. end = this.length
  440. }
  441. if (end <= 0) {
  442. return ''
  443. }
  444. // Force coercion to uint32. This will also coerce falsey/NaN values to 0.
  445. end >>>= 0
  446. start >>>= 0
  447. if (end <= start) {
  448. return ''
  449. }
  450. if (!encoding) encoding = 'utf8'
  451. while (true) {
  452. switch (encoding) {
  453. case 'hex':
  454. return hexSlice(this, start, end)
  455. case 'utf8':
  456. case 'utf-8':
  457. return utf8Slice(this, start, end)
  458. case 'ascii':
  459. return asciiSlice(this, start, end)
  460. case 'latin1':
  461. case 'binary':
  462. return latin1Slice(this, start, end)
  463. case 'base64':
  464. return base64Slice(this, start, end)
  465. case 'ucs2':
  466. case 'ucs-2':
  467. case 'utf16le':
  468. case 'utf-16le':
  469. return utf16leSlice(this, start, end)
  470. default:
  471. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
  472. encoding = (encoding + '').toLowerCase()
  473. loweredCase = true
  474. }
  475. }
  476. }
  477. // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  478. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  479. // reliably in a browserify context because there could be multiple different
  480. // copies of the 'buffer' package in use. This method works even for Buffer
  481. // instances that were created from another copy of the `buffer` package.
  482. // See: https://github.com/feross/buffer/issues/154
  483. Buffer.prototype._isBuffer = true
  484. function swap (b, n, m) {
  485. const i = b[n]
  486. b[n] = b[m]
  487. b[m] = i
  488. }
  489. Buffer.prototype.swap16 = function swap16 () {
  490. const len = this.length
  491. if (len % 2 !== 0) {
  492. throw new RangeError('Buffer size must be a multiple of 16-bits')
  493. }
  494. for (let i = 0; i < len; i += 2) {
  495. swap(this, i, i + 1)
  496. }
  497. return this
  498. }
  499. Buffer.prototype.swap32 = function swap32 () {
  500. const len = this.length
  501. if (len % 4 !== 0) {
  502. throw new RangeError('Buffer size must be a multiple of 32-bits')
  503. }
  504. for (let i = 0; i < len; i += 4) {
  505. swap(this, i, i + 3)
  506. swap(this, i + 1, i + 2)
  507. }
  508. return this
  509. }
  510. Buffer.prototype.swap64 = function swap64 () {
  511. const len = this.length
  512. if (len % 8 !== 0) {
  513. throw new RangeError('Buffer size must be a multiple of 64-bits')
  514. }
  515. for (let i = 0; i < len; i += 8) {
  516. swap(this, i, i + 7)
  517. swap(this, i + 1, i + 6)
  518. swap(this, i + 2, i + 5)
  519. swap(this, i + 3, i + 4)
  520. }
  521. return this
  522. }
  523. Buffer.prototype.toString = function toString () {
  524. const length = this.length
  525. if (length === 0) return ''
  526. if (arguments.length === 0) return utf8Slice(this, 0, length)
  527. return slowToString.apply(this, arguments)
  528. }
  529. Buffer.prototype.toLocaleString = Buffer.prototype.toString
  530. Buffer.prototype.equals = function equals (b) {
  531. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
  532. if (this === b) return true
  533. return Buffer.compare(this, b) === 0
  534. }
  535. Buffer.prototype.inspect = function inspect () {
  536. let str = ''
  537. const max = exports.INSPECT_MAX_BYTES
  538. str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim()
  539. if (this.length > max) str += ' ... '
  540. return '<Buffer ' + str + '>'
  541. }
  542. if (customInspectSymbol) {
  543. Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect
  544. }
  545. Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
  546. if (isInstance(target, Uint8Array)) {
  547. target = Buffer.from(target, target.offset, target.byteLength)
  548. }
  549. if (!Buffer.isBuffer(target)) {
  550. throw new TypeError(
  551. 'The "target" argument must be one of type Buffer or Uint8Array. ' +
  552. 'Received type ' + (typeof target)
  553. )
  554. }
  555. if (start === undefined) {
  556. start = 0
  557. }
  558. if (end === undefined) {
  559. end = target ? target.length : 0
  560. }
  561. if (thisStart === undefined) {
  562. thisStart = 0
  563. }
  564. if (thisEnd === undefined) {
  565. thisEnd = this.length
  566. }
  567. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  568. throw new RangeError('out of range index')
  569. }
  570. if (thisStart >= thisEnd && start >= end) {
  571. return 0
  572. }
  573. if (thisStart >= thisEnd) {
  574. return -1
  575. }
  576. if (start >= end) {
  577. return 1
  578. }
  579. start >>>= 0
  580. end >>>= 0
  581. thisStart >>>= 0
  582. thisEnd >>>= 0
  583. if (this === target) return 0
  584. let x = thisEnd - thisStart
  585. let y = end - start
  586. const len = Math.min(x, y)
  587. const thisCopy = this.slice(thisStart, thisEnd)
  588. const targetCopy = target.slice(start, end)
  589. for (let i = 0; i < len; ++i) {
  590. if (thisCopy[i] !== targetCopy[i]) {
  591. x = thisCopy[i]
  592. y = targetCopy[i]
  593. break
  594. }
  595. }
  596. if (x < y) return -1
  597. if (y < x) return 1
  598. return 0
  599. }
  600. // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  601. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  602. //
  603. // Arguments:
  604. // - buffer - a Buffer to search
  605. // - val - a string, Buffer, or number
  606. // - byteOffset - an index into `buffer`; will be clamped to an int32
  607. // - encoding - an optional encoding, relevant is val is a string
  608. // - dir - true for indexOf, false for lastIndexOf
  609. function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
  610. // Empty buffer means no match
  611. if (buffer.length === 0) return -1
  612. // Normalize byteOffset
  613. if (typeof byteOffset === 'string') {
  614. encoding = byteOffset
  615. byteOffset = 0
  616. } else if (byteOffset > 0x7fffffff) {
  617. byteOffset = 0x7fffffff
  618. } else if (byteOffset < -0x80000000) {
  619. byteOffset = -0x80000000
  620. }
  621. byteOffset = +byteOffset // Coerce to Number.
  622. if (numberIsNaN(byteOffset)) {
  623. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  624. byteOffset = dir ? 0 : (buffer.length - 1)
  625. }
  626. // Normalize byteOffset: negative offsets start from the end of the buffer
  627. if (byteOffset < 0) byteOffset = buffer.length + byteOffset
  628. if (byteOffset >= buffer.length) {
  629. if (dir) return -1
  630. else byteOffset = buffer.length - 1
  631. } else if (byteOffset < 0) {
  632. if (dir) byteOffset = 0
  633. else return -1
  634. }
  635. // Normalize val
  636. if (typeof val === 'string') {
  637. val = Buffer.from(val, encoding)
  638. }
  639. // Finally, search either indexOf (if dir is true) or lastIndexOf
  640. if (Buffer.isBuffer(val)) {
  641. // Special case: looking for empty string/buffer always fails
  642. if (val.length === 0) {
  643. return -1
  644. }
  645. return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
  646. } else if (typeof val === 'number') {
  647. val = val & 0xFF // Search for a byte value [0-255]
  648. if (typeof Uint8Array.prototype.indexOf === 'function') {
  649. if (dir) {
  650. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
  651. } else {
  652. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
  653. }
  654. }
  655. return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
  656. }
  657. throw new TypeError('val must be string, number or Buffer')
  658. }
  659. function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
  660. let indexSize = 1
  661. let arrLength = arr.length
  662. let valLength = val.length
  663. if (encoding !== undefined) {
  664. encoding = String(encoding).toLowerCase()
  665. if (encoding === 'ucs2' || encoding === 'ucs-2' ||
  666. encoding === 'utf16le' || encoding === 'utf-16le') {
  667. if (arr.length < 2 || val.length < 2) {
  668. return -1
  669. }
  670. indexSize = 2
  671. arrLength /= 2
  672. valLength /= 2
  673. byteOffset /= 2
  674. }
  675. }
  676. function read (buf, i) {
  677. if (indexSize === 1) {
  678. return buf[i]
  679. } else {
  680. return buf.readUInt16BE(i * indexSize)
  681. }
  682. }
  683. let i
  684. if (dir) {
  685. let foundIndex = -1
  686. for (i = byteOffset; i < arrLength; i++) {
  687. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  688. if (foundIndex === -1) foundIndex = i
  689. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
  690. } else {
  691. if (foundIndex !== -1) i -= i - foundIndex
  692. foundIndex = -1
  693. }
  694. }
  695. } else {
  696. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
  697. for (i = byteOffset; i >= 0; i--) {
  698. let found = true
  699. for (let j = 0; j < valLength; j++) {
  700. if (read(arr, i + j) !== read(val, j)) {
  701. found = false
  702. break
  703. }
  704. }
  705. if (found) return i
  706. }
  707. }
  708. return -1
  709. }
  710. Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
  711. return this.indexOf(val, byteOffset, encoding) !== -1
  712. }
  713. Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
  714. return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
  715. }
  716. Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
  717. return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
  718. }
  719. function hexWrite (buf, string, offset, length) {
  720. offset = Number(offset) || 0
  721. const remaining = buf.length - offset
  722. if (!length) {
  723. length = remaining
  724. } else {
  725. length = Number(length)
  726. if (length > remaining) {
  727. length = remaining
  728. }
  729. }
  730. const strLen = string.length
  731. if (length > strLen / 2) {
  732. length = strLen / 2
  733. }
  734. let i
  735. for (i = 0; i < length; ++i) {
  736. const 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. const 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. let 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. const res = []
  829. let i = start
  830. while (i < end) {
  831. const firstByte = buf[i]
  832. let codePoint = null
  833. let bytesPerSequence = (firstByte > 0xEF)
  834. ? 4
  835. : (firstByte > 0xDF)
  836. ? 3
  837. : (firstByte > 0xBF)
  838. ? 2
  839. : 1
  840. if (i + bytesPerSequence <= end) {
  841. let 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. const MAX_ARGUMENTS_LENGTH = 0x1000
  899. function decodeCodePointsArray (codePoints) {
  900. const 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. let res = ''
  906. let 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. let ret = ''
  917. end = Math.min(buf.length, end)
  918. for (let i = start; i < end; ++i) {
  919. ret += String.fromCharCode(buf[i] & 0x7F)
  920. }
  921. return ret
  922. }
  923. function latin1Slice (buf, start, end) {
  924. let ret = ''
  925. end = Math.min(buf.length, end)
  926. for (let i = start; i < end; ++i) {
  927. ret += String.fromCharCode(buf[i])
  928. }
  929. return ret
  930. }
  931. function hexSlice (buf, start, end) {
  932. const len = buf.length
  933. if (!start || start < 0) start = 0
  934. if (!end || end < 0 || end > len) end = len
  935. let out = ''
  936. for (let i = start; i < end; ++i) {
  937. out += hexSliceLookupTable[buf[i]]
  938. }
  939. return out
  940. }
  941. function utf16leSlice (buf, start, end) {
  942. const bytes = buf.slice(start, end)
  943. let res = ''
  944. // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
  945. for (let 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. const 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. const 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. let val = this[offset]
  985. let mul = 1
  986. let 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. let val = this[offset + --byteLength]
  1000. let 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.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset) {
  1043. offset = offset >>> 0
  1044. validateNumber(offset, 'offset')
  1045. const first = this[offset]
  1046. const last = this[offset + 7]
  1047. if (first === undefined || last === undefined) {
  1048. boundsError(offset, this.length - 8)
  1049. }
  1050. const lo = first +
  1051. this[++offset] * 2 ** 8 +
  1052. this[++offset] * 2 ** 16 +
  1053. this[++offset] * 2 ** 24
  1054. const hi = this[++offset] +
  1055. this[++offset] * 2 ** 8 +
  1056. this[++offset] * 2 ** 16 +
  1057. last * 2 ** 24
  1058. return BigInt(lo) + (BigInt(hi) << BigInt(32))
  1059. })
  1060. Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
  1061. offset = offset >>> 0
  1062. validateNumber(offset, 'offset')
  1063. const first = this[offset]
  1064. const last = this[offset + 7]
  1065. if (first === undefined || last === undefined) {
  1066. boundsError(offset, this.length - 8)
  1067. }
  1068. const hi = first * 2 ** 24 +
  1069. this[++offset] * 2 ** 16 +
  1070. this[++offset] * 2 ** 8 +
  1071. this[++offset]
  1072. const lo = this[++offset] * 2 ** 24 +
  1073. this[++offset] * 2 ** 16 +
  1074. this[++offset] * 2 ** 8 +
  1075. last
  1076. return (BigInt(hi) << BigInt(32)) + BigInt(lo)
  1077. })
  1078. Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
  1079. offset = offset >>> 0
  1080. byteLength = byteLength >>> 0
  1081. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1082. let val = this[offset]
  1083. let mul = 1
  1084. let i = 0
  1085. while (++i < byteLength && (mul *= 0x100)) {
  1086. val += this[offset + i] * mul
  1087. }
  1088. mul *= 0x80
  1089. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1090. return val
  1091. }
  1092. Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
  1093. offset = offset >>> 0
  1094. byteLength = byteLength >>> 0
  1095. if (!noAssert) checkOffset(offset, byteLength, this.length)
  1096. let i = byteLength
  1097. let mul = 1
  1098. let val = this[offset + --i]
  1099. while (i > 0 && (mul *= 0x100)) {
  1100. val += this[offset + --i] * mul
  1101. }
  1102. mul *= 0x80
  1103. if (val >= mul) val -= Math.pow(2, 8 * byteLength)
  1104. return val
  1105. }
  1106. Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
  1107. offset = offset >>> 0
  1108. if (!noAssert) checkOffset(offset, 1, this.length)
  1109. if (!(this[offset] & 0x80)) return (this[offset])
  1110. return ((0xff - this[offset] + 1) * -1)
  1111. }
  1112. Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
  1113. offset = offset >>> 0
  1114. if (!noAssert) checkOffset(offset, 2, this.length)
  1115. const val = this[offset] | (this[offset + 1] << 8)
  1116. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1117. }
  1118. Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
  1119. offset = offset >>> 0
  1120. if (!noAssert) checkOffset(offset, 2, this.length)
  1121. const val = this[offset + 1] | (this[offset] << 8)
  1122. return (val & 0x8000) ? val | 0xFFFF0000 : val
  1123. }
  1124. Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
  1125. offset = offset >>> 0
  1126. if (!noAssert) checkOffset(offset, 4, this.length)
  1127. return (this[offset]) |
  1128. (this[offset + 1] << 8) |
  1129. (this[offset + 2] << 16) |
  1130. (this[offset + 3] << 24)
  1131. }
  1132. Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
  1133. offset = offset >>> 0
  1134. if (!noAssert) checkOffset(offset, 4, this.length)
  1135. return (this[offset] << 24) |
  1136. (this[offset + 1] << 16) |
  1137. (this[offset + 2] << 8) |
  1138. (this[offset + 3])
  1139. }
  1140. Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset) {
  1141. offset = offset >>> 0
  1142. validateNumber(offset, 'offset')
  1143. const first = this[offset]
  1144. const last = this[offset + 7]
  1145. if (first === undefined || last === undefined) {
  1146. boundsError(offset, this.length - 8)
  1147. }
  1148. const val = this[offset + 4] +
  1149. this[offset + 5] * 2 ** 8 +
  1150. this[offset + 6] * 2 ** 16 +
  1151. (last << 24) // Overflow
  1152. return (BigInt(val) << BigInt(32)) +
  1153. BigInt(first +
  1154. this[++offset] * 2 ** 8 +
  1155. this[++offset] * 2 ** 16 +
  1156. this[++offset] * 2 ** 24)
  1157. })
  1158. Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset) {
  1159. offset = offset >>> 0
  1160. validateNumber(offset, 'offset')
  1161. const first = this[offset]
  1162. const last = this[offset + 7]
  1163. if (first === undefined || last === undefined) {
  1164. boundsError(offset, this.length - 8)
  1165. }
  1166. const val = (first << 24) + // Overflow
  1167. this[++offset] * 2 ** 16 +
  1168. this[++offset] * 2 ** 8 +
  1169. this[++offset]
  1170. return (BigInt(val) << BigInt(32)) +
  1171. BigInt(this[++offset] * 2 ** 24 +
  1172. this[++offset] * 2 ** 16 +
  1173. this[++offset] * 2 ** 8 +
  1174. last)
  1175. })
  1176. Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
  1177. offset = offset >>> 0
  1178. if (!noAssert) checkOffset(offset, 4, this.length)
  1179. return ieee754.read(this, offset, true, 23, 4)
  1180. }
  1181. Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
  1182. offset = offset >>> 0
  1183. if (!noAssert) checkOffset(offset, 4, this.length)
  1184. return ieee754.read(this, offset, false, 23, 4)
  1185. }
  1186. Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
  1187. offset = offset >>> 0
  1188. if (!noAssert) checkOffset(offset, 8, this.length)
  1189. return ieee754.read(this, offset, true, 52, 8)
  1190. }
  1191. Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
  1192. offset = offset >>> 0
  1193. if (!noAssert) checkOffset(offset, 8, this.length)
  1194. return ieee754.read(this, offset, false, 52, 8)
  1195. }
  1196. function checkInt (buf, value, offset, ext, max, min) {
  1197. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
  1198. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
  1199. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1200. }
  1201. Buffer.prototype.writeUintLE =
  1202. Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
  1203. value = +value
  1204. offset = offset >>> 0
  1205. byteLength = byteLength >>> 0
  1206. if (!noAssert) {
  1207. const maxBytes = Math.pow(2, 8 * byteLength) - 1
  1208. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1209. }
  1210. let mul = 1
  1211. let i = 0
  1212. this[offset] = value & 0xFF
  1213. while (++i < byteLength && (mul *= 0x100)) {
  1214. this[offset + i] = (value / mul) & 0xFF
  1215. }
  1216. return offset + byteLength
  1217. }
  1218. Buffer.prototype.writeUintBE =
  1219. Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
  1220. value = +value
  1221. offset = offset >>> 0
  1222. byteLength = byteLength >>> 0
  1223. if (!noAssert) {
  1224. const maxBytes = Math.pow(2, 8 * byteLength) - 1
  1225. checkInt(this, value, offset, byteLength, maxBytes, 0)
  1226. }
  1227. let i = byteLength - 1
  1228. let mul = 1
  1229. this[offset + i] = value & 0xFF
  1230. while (--i >= 0 && (mul *= 0x100)) {
  1231. this[offset + i] = (value / mul) & 0xFF
  1232. }
  1233. return offset + byteLength
  1234. }
  1235. Buffer.prototype.writeUint8 =
  1236. Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
  1237. value = +value
  1238. offset = offset >>> 0
  1239. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
  1240. this[offset] = (value & 0xff)
  1241. return offset + 1
  1242. }
  1243. Buffer.prototype.writeUint16LE =
  1244. Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
  1245. value = +value
  1246. offset = offset >>> 0
  1247. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1248. this[offset] = (value & 0xff)
  1249. this[offset + 1] = (value >>> 8)
  1250. return offset + 2
  1251. }
  1252. Buffer.prototype.writeUint16BE =
  1253. Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
  1254. value = +value
  1255. offset = offset >>> 0
  1256. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
  1257. this[offset] = (value >>> 8)
  1258. this[offset + 1] = (value & 0xff)
  1259. return offset + 2
  1260. }
  1261. Buffer.prototype.writeUint32LE =
  1262. Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
  1263. value = +value
  1264. offset = offset >>> 0
  1265. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1266. this[offset + 3] = (value >>> 24)
  1267. this[offset + 2] = (value >>> 16)
  1268. this[offset + 1] = (value >>> 8)
  1269. this[offset] = (value & 0xff)
  1270. return offset + 4
  1271. }
  1272. Buffer.prototype.writeUint32BE =
  1273. Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
  1274. value = +value
  1275. offset = offset >>> 0
  1276. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
  1277. this[offset] = (value >>> 24)
  1278. this[offset + 1] = (value >>> 16)
  1279. this[offset + 2] = (value >>> 8)
  1280. this[offset + 3] = (value & 0xff)
  1281. return offset + 4
  1282. }
  1283. function wrtBigUInt64LE (buf, value, offset, min, max) {
  1284. checkIntBI(value, min, max, buf, offset, 7)
  1285. let lo = Number(value & BigInt(0xffffffff))
  1286. buf[offset++] = lo
  1287. lo = lo >> 8
  1288. buf[offset++] = lo
  1289. lo = lo >> 8
  1290. buf[offset++] = lo
  1291. lo = lo >> 8
  1292. buf[offset++] = lo
  1293. let hi = Number(value >> BigInt(32) & BigInt(0xffffffff))
  1294. buf[offset++] = hi
  1295. hi = hi >> 8
  1296. buf[offset++] = hi
  1297. hi = hi >> 8
  1298. buf[offset++] = hi
  1299. hi = hi >> 8
  1300. buf[offset++] = hi
  1301. return offset
  1302. }
  1303. function wrtBigUInt64BE (buf, value, offset, min, max) {
  1304. checkIntBI(value, min, max, buf, offset, 7)
  1305. let lo = Number(value & BigInt(0xffffffff))
  1306. buf[offset + 7] = lo
  1307. lo = lo >> 8
  1308. buf[offset + 6] = lo
  1309. lo = lo >> 8
  1310. buf[offset + 5] = lo
  1311. lo = lo >> 8
  1312. buf[offset + 4] = lo
  1313. let hi = Number(value >> BigInt(32) & BigInt(0xffffffff))
  1314. buf[offset + 3] = hi
  1315. hi = hi >> 8
  1316. buf[offset + 2] = hi
  1317. hi = hi >> 8
  1318. buf[offset + 1] = hi
  1319. hi = hi >> 8
  1320. buf[offset] = hi
  1321. return offset + 8
  1322. }
  1323. Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
  1324. return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
  1325. })
  1326. Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
  1327. return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
  1328. })
  1329. Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
  1330. value = +value
  1331. offset = offset >>> 0
  1332. if (!noAssert) {
  1333. const limit = Math.pow(2, (8 * byteLength) - 1)
  1334. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1335. }
  1336. let i = 0
  1337. let mul = 1
  1338. let sub = 0
  1339. this[offset] = value & 0xFF
  1340. while (++i < byteLength && (mul *= 0x100)) {
  1341. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  1342. sub = 1
  1343. }
  1344. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1345. }
  1346. return offset + byteLength
  1347. }
  1348. Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
  1349. value = +value
  1350. offset = offset >>> 0
  1351. if (!noAssert) {
  1352. const limit = Math.pow(2, (8 * byteLength) - 1)
  1353. checkInt(this, value, offset, byteLength, limit - 1, -limit)
  1354. }
  1355. let i = byteLength - 1
  1356. let mul = 1
  1357. let sub = 0
  1358. this[offset + i] = value & 0xFF
  1359. while (--i >= 0 && (mul *= 0x100)) {
  1360. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  1361. sub = 1
  1362. }
  1363. this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
  1364. }
  1365. return offset + byteLength
  1366. }
  1367. Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
  1368. value = +value
  1369. offset = offset >>> 0
  1370. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
  1371. if (value < 0) value = 0xff + value + 1
  1372. this[offset] = (value & 0xff)
  1373. return offset + 1
  1374. }
  1375. Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
  1376. value = +value
  1377. offset = offset >>> 0
  1378. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1379. this[offset] = (value & 0xff)
  1380. this[offset + 1] = (value >>> 8)
  1381. return offset + 2
  1382. }
  1383. Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
  1384. value = +value
  1385. offset = offset >>> 0
  1386. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
  1387. this[offset] = (value >>> 8)
  1388. this[offset + 1] = (value & 0xff)
  1389. return offset + 2
  1390. }
  1391. Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
  1392. value = +value
  1393. offset = offset >>> 0
  1394. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1395. this[offset] = (value & 0xff)
  1396. this[offset + 1] = (value >>> 8)
  1397. this[offset + 2] = (value >>> 16)
  1398. this[offset + 3] = (value >>> 24)
  1399. return offset + 4
  1400. }
  1401. Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
  1402. value = +value
  1403. offset = offset >>> 0
  1404. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
  1405. if (value < 0) value = 0xffffffff + value + 1
  1406. this[offset] = (value >>> 24)
  1407. this[offset + 1] = (value >>> 16)
  1408. this[offset + 2] = (value >>> 8)
  1409. this[offset + 3] = (value & 0xff)
  1410. return offset + 4
  1411. }
  1412. Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
  1413. return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
  1414. })
  1415. Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
  1416. return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
  1417. })
  1418. function checkIEEE754 (buf, value, offset, ext, max, min) {
  1419. if (offset + ext > buf.length) throw new RangeError('Index out of range')
  1420. if (offset < 0) throw new RangeError('Index out of range')
  1421. }
  1422. function writeFloat (buf, value, offset, littleEndian, noAssert) {
  1423. value = +value
  1424. offset = offset >>> 0
  1425. if (!noAssert) {
  1426. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
  1427. }
  1428. ieee754.write(buf, value, offset, littleEndian, 23, 4)
  1429. return offset + 4
  1430. }
  1431. Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
  1432. return writeFloat(this, value, offset, true, noAssert)
  1433. }
  1434. Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
  1435. return writeFloat(this, value, offset, false, noAssert)
  1436. }
  1437. function writeDouble (buf, value, offset, littleEndian, noAssert) {
  1438. value = +value
  1439. offset = offset >>> 0
  1440. if (!noAssert) {
  1441. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
  1442. }
  1443. ieee754.write(buf, value, offset, littleEndian, 52, 8)
  1444. return offset + 8
  1445. }
  1446. Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
  1447. return writeDouble(this, value, offset, true, noAssert)
  1448. }
  1449. Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
  1450. return writeDouble(this, value, offset, false, noAssert)
  1451. }
  1452. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  1453. Buffer.prototype.copy = function copy (target, targetStart, start, end) {
  1454. if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
  1455. if (!start) start = 0
  1456. if (!end && end !== 0) end = this.length
  1457. if (targetStart >= target.length) targetStart = target.length
  1458. if (!targetStart) targetStart = 0
  1459. if (end > 0 && end < start) end = start
  1460. // Copy 0 bytes; we're done
  1461. if (end === start) return 0
  1462. if (target.length === 0 || this.length === 0) return 0
  1463. // Fatal error conditions
  1464. if (targetStart < 0) {
  1465. throw new RangeError('targetStart out of bounds')
  1466. }
  1467. if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
  1468. if (end < 0) throw new RangeError('sourceEnd out of bounds')
  1469. // Are we oob?
  1470. if (end > this.length) end = this.length
  1471. if (target.length - targetStart < end - start) {
  1472. end = target.length - targetStart + start
  1473. }
  1474. const len = end - start
  1475. if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  1476. // Use built-in when available, missing from IE11
  1477. this.copyWithin(targetStart, start, end)
  1478. } else {
  1479. Uint8Array.prototype.set.call(
  1480. target,
  1481. this.subarray(start, end),
  1482. targetStart
  1483. )
  1484. }
  1485. return len
  1486. }
  1487. // Usage:
  1488. // buffer.fill(number[, offset[, end]])
  1489. // buffer.fill(buffer[, offset[, end]])
  1490. // buffer.fill(string[, offset[, end]][, encoding])
  1491. Buffer.prototype.fill = function fill (val, start, end, encoding) {
  1492. // Handle string cases:
  1493. if (typeof val === 'string') {
  1494. if (typeof start === 'string') {
  1495. encoding = start
  1496. start = 0
  1497. end = this.length
  1498. } else if (typeof end === 'string') {
  1499. encoding = end
  1500. end = this.length
  1501. }
  1502. if (encoding !== undefined && typeof encoding !== 'string') {
  1503. throw new TypeError('encoding must be a string')
  1504. }
  1505. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  1506. throw new TypeError('Unknown encoding: ' + encoding)
  1507. }
  1508. if (val.length === 1) {
  1509. const code = val.charCodeAt(0)
  1510. if ((encoding === 'utf8' && code < 128) ||
  1511. encoding === 'latin1') {
  1512. // Fast path: If `val` fits into a single byte, use that numeric value.
  1513. val = code
  1514. }
  1515. }
  1516. } else if (typeof val === 'number') {
  1517. val = val & 255
  1518. } else if (typeof val === 'boolean') {
  1519. val = Number(val)
  1520. }
  1521. // Invalid ranges are not set to a default, so can range check early.
  1522. if (start < 0 || this.length < start || this.length < end) {
  1523. throw new RangeError('Out of range index')
  1524. }
  1525. if (end <= start) {
  1526. return this
  1527. }
  1528. start = start >>> 0
  1529. end = end === undefined ? this.length : end >>> 0
  1530. if (!val) val = 0
  1531. let i
  1532. if (typeof val === 'number') {
  1533. for (i = start; i < end; ++i) {
  1534. this[i] = val
  1535. }
  1536. } else {
  1537. const bytes = Buffer.isBuffer(val)
  1538. ? val
  1539. : Buffer.from(val, encoding)
  1540. const len = bytes.length
  1541. if (len === 0) {
  1542. throw new TypeError('The value "' + val +
  1543. '" is invalid for argument "value"')
  1544. }
  1545. for (i = 0; i < end - start; ++i) {
  1546. this[i + start] = bytes[i % len]
  1547. }
  1548. }
  1549. return this
  1550. }
  1551. // CUSTOM ERRORS
  1552. // =============
  1553. // Simplified versions from Node, changed for Buffer-only usage
  1554. const errors = {}
  1555. function E (sym, getMessage, Base) {
  1556. errors[sym] = class NodeError extends Base {
  1557. constructor () {
  1558. super()
  1559. Object.defineProperty(this, 'message', {
  1560. value: getMessage.apply(this, arguments),
  1561. writable: true,
  1562. configurable: true
  1563. })
  1564. // Add the error code to the name to include it in the stack trace.
  1565. this.name = `${this.name} [${sym}]`
  1566. // Access the stack to generate the error message including the error code
  1567. // from the name.
  1568. this.stack // eslint-disable-line no-unused-expressions
  1569. // Reset the name to the actual name.
  1570. delete this.name
  1571. }
  1572. get code () {
  1573. return sym
  1574. }
  1575. set code (value) {
  1576. Object.defineProperty(this, 'code', {
  1577. configurable: true,
  1578. enumerable: true,
  1579. value,
  1580. writable: true
  1581. })
  1582. }
  1583. toString () {
  1584. return `${this.name} [${sym}]: ${this.message}`
  1585. }
  1586. }
  1587. }
  1588. E('ERR_BUFFER_OUT_OF_BOUNDS',
  1589. function (name) {
  1590. if (name) {
  1591. return `${name} is outside of buffer bounds`
  1592. }
  1593. return 'Attempt to access memory outside buffer bounds'
  1594. }, RangeError)
  1595. E('ERR_INVALID_ARG_TYPE',
  1596. function (name, actual) {
  1597. return `The "${name}" argument must be of type number. Received type ${typeof actual}`
  1598. }, TypeError)
  1599. E('ERR_OUT_OF_RANGE',
  1600. function (str, range, input) {
  1601. let msg = `The value of "${str}" is out of range.`
  1602. let received = input
  1603. if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
  1604. received = addNumericalSeparator(String(input))
  1605. } else if (typeof input === 'bigint') {
  1606. received = String(input)
  1607. if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
  1608. received = addNumericalSeparator(received)
  1609. }
  1610. received += 'n'
  1611. }
  1612. msg += ` It must be ${range}. Received ${received}`
  1613. return msg
  1614. }, RangeError)
  1615. function addNumericalSeparator (val) {
  1616. let res = ''
  1617. let i = val.length
  1618. const start = val[0] === '-' ? 1 : 0
  1619. for (; i >= start + 4; i -= 3) {
  1620. res = `_${val.slice(i - 3, i)}${res}`
  1621. }
  1622. return `${val.slice(0, i)}${res}`
  1623. }
  1624. // CHECK FUNCTIONS
  1625. // ===============
  1626. function checkBounds (buf, offset, byteLength) {
  1627. validateNumber(offset, 'offset')
  1628. if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
  1629. boundsError(offset, buf.length - (byteLength + 1))
  1630. }
  1631. }
  1632. function checkIntBI (value, min, max, buf, offset, byteLength) {
  1633. if (value > max || value < min) {
  1634. const n = typeof min === 'bigint' ? 'n' : ''
  1635. let range
  1636. if (byteLength > 3) {
  1637. if (min === 0 || min === BigInt(0)) {
  1638. range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`
  1639. } else {
  1640. range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
  1641. `${(byteLength + 1) * 8 - 1}${n}`
  1642. }
  1643. } else {
  1644. range = `>= ${min}${n} and <= ${max}${n}`
  1645. }
  1646. throw new errors.ERR_OUT_OF_RANGE('value', range, value)
  1647. }
  1648. checkBounds(buf, offset, byteLength)
  1649. }
  1650. function validateNumber (value, name) {
  1651. if (typeof value !== 'number') {
  1652. throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
  1653. }
  1654. }
  1655. function boundsError (value, length, type) {
  1656. if (Math.floor(value) !== value) {
  1657. validateNumber(value, type)
  1658. throw new errors.ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value)
  1659. }
  1660. if (length < 0) {
  1661. throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
  1662. }
  1663. throw new errors.ERR_OUT_OF_RANGE(type || 'offset',
  1664. `>= ${type ? 1 : 0} and <= ${length}`,
  1665. value)
  1666. }
  1667. // HELPER FUNCTIONS
  1668. // ================
  1669. const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g
  1670. function base64clean (str) {
  1671. // Node takes equal signs as end of the Base64 encoding
  1672. str = str.split('=')[0]
  1673. // Node strips out invalid characters like \n and \t from the string, base64-js does not
  1674. str = str.trim().replace(INVALID_BASE64_RE, '')
  1675. // Node converts strings with length < 2 to ''
  1676. if (str.length < 2) return ''
  1677. // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  1678. while (str.length % 4 !== 0) {
  1679. str = str + '='
  1680. }
  1681. return str
  1682. }
  1683. function utf8ToBytes (string, units) {
  1684. units = units || Infinity
  1685. let codePoint
  1686. const length = string.length
  1687. let leadSurrogate = null
  1688. const bytes = []
  1689. for (let i = 0; i < length; ++i) {
  1690. codePoint = string.charCodeAt(i)
  1691. // is surrogate component
  1692. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  1693. // last char was a lead
  1694. if (!leadSurrogate) {
  1695. // no lead yet
  1696. if (codePoint > 0xDBFF) {
  1697. // unexpected trail
  1698. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1699. continue
  1700. } else if (i + 1 === length) {
  1701. // unpaired lead
  1702. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1703. continue
  1704. }
  1705. // valid lead
  1706. leadSurrogate = codePoint
  1707. continue
  1708. }
  1709. // 2 leads in a row
  1710. if (codePoint < 0xDC00) {
  1711. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1712. leadSurrogate = codePoint
  1713. continue
  1714. }
  1715. // valid surrogate pair
  1716. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
  1717. } else if (leadSurrogate) {
  1718. // valid bmp char, but last char was a lead
  1719. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
  1720. }
  1721. leadSurrogate = null
  1722. // encode utf8
  1723. if (codePoint < 0x80) {
  1724. if ((units -= 1) < 0) break
  1725. bytes.push(codePoint)
  1726. } else if (codePoint < 0x800) {
  1727. if ((units -= 2) < 0) break
  1728. bytes.push(
  1729. codePoint >> 0x6 | 0xC0,
  1730. codePoint & 0x3F | 0x80
  1731. )
  1732. } else if (codePoint < 0x10000) {
  1733. if ((units -= 3) < 0) break
  1734. bytes.push(
  1735. codePoint >> 0xC | 0xE0,
  1736. codePoint >> 0x6 & 0x3F | 0x80,
  1737. codePoint & 0x3F | 0x80
  1738. )
  1739. } else if (codePoint < 0x110000) {
  1740. if ((units -= 4) < 0) break
  1741. bytes.push(
  1742. codePoint >> 0x12 | 0xF0,
  1743. codePoint >> 0xC & 0x3F | 0x80,
  1744. codePoint >> 0x6 & 0x3F | 0x80,
  1745. codePoint & 0x3F | 0x80
  1746. )
  1747. } else {
  1748. throw new Error('Invalid code point')
  1749. }
  1750. }
  1751. return bytes
  1752. }
  1753. function asciiToBytes (str) {
  1754. const byteArray = []
  1755. for (let i = 0; i < str.length; ++i) {
  1756. // Node's code seems to be doing this and not & 0x7F..
  1757. byteArray.push(str.charCodeAt(i) & 0xFF)
  1758. }
  1759. return byteArray
  1760. }
  1761. function utf16leToBytes (str, units) {
  1762. let c, hi, lo
  1763. const byteArray = []
  1764. for (let i = 0; i < str.length; ++i) {
  1765. if ((units -= 2) < 0) break
  1766. c = str.charCodeAt(i)
  1767. hi = c >> 8
  1768. lo = c % 256
  1769. byteArray.push(lo)
  1770. byteArray.push(hi)
  1771. }
  1772. return byteArray
  1773. }
  1774. function base64ToBytes (str) {
  1775. return base64.toByteArray(base64clean(str))
  1776. }
  1777. function blitBuffer (src, dst, offset, length) {
  1778. let i
  1779. for (i = 0; i < length; ++i) {
  1780. if ((i + offset >= dst.length) || (i >= src.length)) break
  1781. dst[i + offset] = src[i]
  1782. }
  1783. return i
  1784. }
  1785. // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
  1786. // the `instanceof` check but they should be treated as of that type.
  1787. // See: https://github.com/feross/buffer/issues/166
  1788. function isInstance (obj, type) {
  1789. return obj instanceof type ||
  1790. (obj != null && obj.constructor != null && obj.constructor.name != null &&
  1791. obj.constructor.name === type.name)
  1792. }
  1793. function numberIsNaN (obj) {
  1794. // For IE11 support
  1795. return obj !== obj // eslint-disable-line no-self-compare
  1796. }
  1797. // Create lookup table for `toString('hex')`
  1798. // See: https://github.com/feross/buffer/issues/219
  1799. const hexSliceLookupTable = (function () {
  1800. const alphabet = '0123456789abcdef'
  1801. const table = new Array(256)
  1802. for (let i = 0; i < 16; ++i) {
  1803. const i16 = i * 16
  1804. for (let j = 0; j < 16; ++j) {
  1805. table[i16 + j] = alphabet[i] + alphabet[j]
  1806. }
  1807. }
  1808. return table
  1809. })()
  1810. // Return not function with Error if BigInt not supported
  1811. function defineBigIntMethod (fn) {
  1812. return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
  1813. }
  1814. function BufferBigIntNotDefined () {
  1815. throw new Error('BigInt not supported')
  1816. }
  1817. }, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); })
  1818. return __REQUIRE__(1682324647460);
  1819. })()
  1820. //miniprogram-npm-outsideDeps=["base64-js","ieee754"]
  1821. //# sourceMappingURL=index.js.map