UNPKG

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