index.js 49 KB

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