axios 0.27.1 → 0.27.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -1
- package/dist/axios.js +27 -2113
- package/dist/axios.map +1 -1
- package/dist/axios.min.js +2 -11
- package/dist/axios.min.map +1 -1
- package/lib/adapters/xhr.js +6 -2
- package/lib/env/data.js +1 -1
- package/lib/helpers/parseProtocol.js +6 -0
- package/package.json +2 -5
package/dist/axios.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* axios v0.27.
|
1
|
+
/* axios v0.27.2 | (c) 2022 by Matt Zabriskie */
|
2
2
|
(function webpackUniversalModuleDefinition(root, factory) {
|
3
3
|
if(typeof exports === 'object' && typeof module === 'object')
|
4
4
|
module.exports = factory();
|
@@ -128,6 +128,7 @@ var isURLSameOrigin = __webpack_require__(/*! ./../helpers/isURLSameOrigin */ ".
|
|
128
128
|
var transitionalDefaults = __webpack_require__(/*! ../defaults/transitional */ "./lib/defaults/transitional.js");
|
129
129
|
var AxiosError = __webpack_require__(/*! ../core/AxiosError */ "./lib/core/AxiosError.js");
|
130
130
|
var CanceledError = __webpack_require__(/*! ../cancel/CanceledError */ "./lib/cancel/CanceledError.js");
|
131
|
+
var parseProtocol = __webpack_require__(/*! ../helpers/parseProtocol */ "./lib/helpers/parseProtocol.js");
|
131
132
|
|
132
133
|
module.exports = function xhrAdapter(config) {
|
133
134
|
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
@@ -145,6 +146,10 @@ module.exports = function xhrAdapter(config) {
|
|
145
146
|
}
|
146
147
|
}
|
147
148
|
|
149
|
+
if (utils.isFormData(requestData) && utils.isStandardBrowserEnv()) {
|
150
|
+
delete requestHeaders['Content-Type']; // Let the browser set it
|
151
|
+
}
|
152
|
+
|
148
153
|
var request = new XMLHttpRequest();
|
149
154
|
|
150
155
|
// HTTP basic authentication
|
@@ -321,8 +326,7 @@ module.exports = function xhrAdapter(config) {
|
|
321
326
|
requestData = null;
|
322
327
|
}
|
323
328
|
|
324
|
-
var
|
325
|
-
var protocol = tokens.length > 1 && tokens[0];
|
329
|
+
var protocol = parseProtocol(fullPath);
|
326
330
|
|
327
331
|
if (protocol && [ 'http', 'https', 'file' ].indexOf(protocol) === -1) {
|
328
332
|
reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
|
@@ -1431,7 +1435,7 @@ module.exports = {
|
|
1431
1435
|
/***/ (function(module, exports) {
|
1432
1436
|
|
1433
1437
|
module.exports = {
|
1434
|
-
"version": "0.27.
|
1438
|
+
"version": "0.27.2"
|
1435
1439
|
};
|
1436
1440
|
|
1437
1441
|
/***/ }),
|
@@ -1863,6 +1867,24 @@ module.exports = function parseHeaders(headers) {
|
|
1863
1867
|
};
|
1864
1868
|
|
1865
1869
|
|
1870
|
+
/***/ }),
|
1871
|
+
|
1872
|
+
/***/ "./lib/helpers/parseProtocol.js":
|
1873
|
+
/*!**************************************!*\
|
1874
|
+
!*** ./lib/helpers/parseProtocol.js ***!
|
1875
|
+
\**************************************/
|
1876
|
+
/*! no static exports found */
|
1877
|
+
/***/ (function(module, exports, __webpack_require__) {
|
1878
|
+
|
1879
|
+
"use strict";
|
1880
|
+
|
1881
|
+
|
1882
|
+
module.exports = function parseProtocol(url) {
|
1883
|
+
var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
1884
|
+
return match && match[1] || '';
|
1885
|
+
};
|
1886
|
+
|
1887
|
+
|
1866
1888
|
/***/ }),
|
1867
1889
|
|
1868
1890
|
/***/ "./lib/helpers/spread.js":
|
@@ -1912,7 +1934,7 @@ module.exports = function spread(callback) {
|
|
1912
1934
|
/***/ (function(module, exports, __webpack_require__) {
|
1913
1935
|
|
1914
1936
|
"use strict";
|
1915
|
-
|
1937
|
+
|
1916
1938
|
|
1917
1939
|
var utils = __webpack_require__(/*! ../utils */ "./lib/utils.js");
|
1918
1940
|
|
@@ -1985,7 +2007,6 @@ function toFormData(obj, formData) {
|
|
1985
2007
|
|
1986
2008
|
module.exports = toFormData;
|
1987
2009
|
|
1988
|
-
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../node_modules/node-libs-browser/node_modules/buffer/index.js */ "./node_modules/node-libs-browser/node_modules/buffer/index.js").Buffer))
|
1989
2010
|
|
1990
2011
|
/***/ }),
|
1991
2012
|
|
@@ -2567,2113 +2588,6 @@ module.exports = {
|
|
2567
2588
|
};
|
2568
2589
|
|
2569
2590
|
|
2570
|
-
/***/ }),
|
2571
|
-
|
2572
|
-
/***/ "./node_modules/base64-js/index.js":
|
2573
|
-
/*!*****************************************!*\
|
2574
|
-
!*** ./node_modules/base64-js/index.js ***!
|
2575
|
-
\*****************************************/
|
2576
|
-
/*! no static exports found */
|
2577
|
-
/***/ (function(module, exports, __webpack_require__) {
|
2578
|
-
|
2579
|
-
"use strict";
|
2580
|
-
|
2581
|
-
|
2582
|
-
exports.byteLength = byteLength
|
2583
|
-
exports.toByteArray = toByteArray
|
2584
|
-
exports.fromByteArray = fromByteArray
|
2585
|
-
|
2586
|
-
var lookup = []
|
2587
|
-
var revLookup = []
|
2588
|
-
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array
|
2589
|
-
|
2590
|
-
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
2591
|
-
for (var i = 0, len = code.length; i < len; ++i) {
|
2592
|
-
lookup[i] = code[i]
|
2593
|
-
revLookup[code.charCodeAt(i)] = i
|
2594
|
-
}
|
2595
|
-
|
2596
|
-
// Support decoding URL-safe base64 strings, as Node.js does.
|
2597
|
-
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
|
2598
|
-
revLookup['-'.charCodeAt(0)] = 62
|
2599
|
-
revLookup['_'.charCodeAt(0)] = 63
|
2600
|
-
|
2601
|
-
function getLens (b64) {
|
2602
|
-
var len = b64.length
|
2603
|
-
|
2604
|
-
if (len % 4 > 0) {
|
2605
|
-
throw new Error('Invalid string. Length must be a multiple of 4')
|
2606
|
-
}
|
2607
|
-
|
2608
|
-
// Trim off extra bytes after placeholder bytes are found
|
2609
|
-
// See: https://github.com/beatgammit/base64-js/issues/42
|
2610
|
-
var validLen = b64.indexOf('=')
|
2611
|
-
if (validLen === -1) validLen = len
|
2612
|
-
|
2613
|
-
var placeHoldersLen = validLen === len
|
2614
|
-
? 0
|
2615
|
-
: 4 - (validLen % 4)
|
2616
|
-
|
2617
|
-
return [validLen, placeHoldersLen]
|
2618
|
-
}
|
2619
|
-
|
2620
|
-
// base64 is 4/3 + up to two characters of the original data
|
2621
|
-
function byteLength (b64) {
|
2622
|
-
var lens = getLens(b64)
|
2623
|
-
var validLen = lens[0]
|
2624
|
-
var placeHoldersLen = lens[1]
|
2625
|
-
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
2626
|
-
}
|
2627
|
-
|
2628
|
-
function _byteLength (b64, validLen, placeHoldersLen) {
|
2629
|
-
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
2630
|
-
}
|
2631
|
-
|
2632
|
-
function toByteArray (b64) {
|
2633
|
-
var tmp
|
2634
|
-
var lens = getLens(b64)
|
2635
|
-
var validLen = lens[0]
|
2636
|
-
var placeHoldersLen = lens[1]
|
2637
|
-
|
2638
|
-
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen))
|
2639
|
-
|
2640
|
-
var curByte = 0
|
2641
|
-
|
2642
|
-
// if there are placeholders, only get up to the last complete 4 chars
|
2643
|
-
var len = placeHoldersLen > 0
|
2644
|
-
? validLen - 4
|
2645
|
-
: validLen
|
2646
|
-
|
2647
|
-
var i
|
2648
|
-
for (i = 0; i < len; i += 4) {
|
2649
|
-
tmp =
|
2650
|
-
(revLookup[b64.charCodeAt(i)] << 18) |
|
2651
|
-
(revLookup[b64.charCodeAt(i + 1)] << 12) |
|
2652
|
-
(revLookup[b64.charCodeAt(i + 2)] << 6) |
|
2653
|
-
revLookup[b64.charCodeAt(i + 3)]
|
2654
|
-
arr[curByte++] = (tmp >> 16) & 0xFF
|
2655
|
-
arr[curByte++] = (tmp >> 8) & 0xFF
|
2656
|
-
arr[curByte++] = tmp & 0xFF
|
2657
|
-
}
|
2658
|
-
|
2659
|
-
if (placeHoldersLen === 2) {
|
2660
|
-
tmp =
|
2661
|
-
(revLookup[b64.charCodeAt(i)] << 2) |
|
2662
|
-
(revLookup[b64.charCodeAt(i + 1)] >> 4)
|
2663
|
-
arr[curByte++] = tmp & 0xFF
|
2664
|
-
}
|
2665
|
-
|
2666
|
-
if (placeHoldersLen === 1) {
|
2667
|
-
tmp =
|
2668
|
-
(revLookup[b64.charCodeAt(i)] << 10) |
|
2669
|
-
(revLookup[b64.charCodeAt(i + 1)] << 4) |
|
2670
|
-
(revLookup[b64.charCodeAt(i + 2)] >> 2)
|
2671
|
-
arr[curByte++] = (tmp >> 8) & 0xFF
|
2672
|
-
arr[curByte++] = tmp & 0xFF
|
2673
|
-
}
|
2674
|
-
|
2675
|
-
return arr
|
2676
|
-
}
|
2677
|
-
|
2678
|
-
function tripletToBase64 (num) {
|
2679
|
-
return lookup[num >> 18 & 0x3F] +
|
2680
|
-
lookup[num >> 12 & 0x3F] +
|
2681
|
-
lookup[num >> 6 & 0x3F] +
|
2682
|
-
lookup[num & 0x3F]
|
2683
|
-
}
|
2684
|
-
|
2685
|
-
function encodeChunk (uint8, start, end) {
|
2686
|
-
var tmp
|
2687
|
-
var output = []
|
2688
|
-
for (var i = start; i < end; i += 3) {
|
2689
|
-
tmp =
|
2690
|
-
((uint8[i] << 16) & 0xFF0000) +
|
2691
|
-
((uint8[i + 1] << 8) & 0xFF00) +
|
2692
|
-
(uint8[i + 2] & 0xFF)
|
2693
|
-
output.push(tripletToBase64(tmp))
|
2694
|
-
}
|
2695
|
-
return output.join('')
|
2696
|
-
}
|
2697
|
-
|
2698
|
-
function fromByteArray (uint8) {
|
2699
|
-
var tmp
|
2700
|
-
var len = uint8.length
|
2701
|
-
var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
|
2702
|
-
var parts = []
|
2703
|
-
var maxChunkLength = 16383 // must be multiple of 3
|
2704
|
-
|
2705
|
-
// go through the array every three bytes, we'll deal with trailing stuff later
|
2706
|
-
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
2707
|
-
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
|
2708
|
-
}
|
2709
|
-
|
2710
|
-
// pad the end with zeros, but make sure to not forget the extra bytes
|
2711
|
-
if (extraBytes === 1) {
|
2712
|
-
tmp = uint8[len - 1]
|
2713
|
-
parts.push(
|
2714
|
-
lookup[tmp >> 2] +
|
2715
|
-
lookup[(tmp << 4) & 0x3F] +
|
2716
|
-
'=='
|
2717
|
-
)
|
2718
|
-
} else if (extraBytes === 2) {
|
2719
|
-
tmp = (uint8[len - 2] << 8) + uint8[len - 1]
|
2720
|
-
parts.push(
|
2721
|
-
lookup[tmp >> 10] +
|
2722
|
-
lookup[(tmp >> 4) & 0x3F] +
|
2723
|
-
lookup[(tmp << 2) & 0x3F] +
|
2724
|
-
'='
|
2725
|
-
)
|
2726
|
-
}
|
2727
|
-
|
2728
|
-
return parts.join('')
|
2729
|
-
}
|
2730
|
-
|
2731
|
-
|
2732
|
-
/***/ }),
|
2733
|
-
|
2734
|
-
/***/ "./node_modules/ieee754/index.js":
|
2735
|
-
/*!***************************************!*\
|
2736
|
-
!*** ./node_modules/ieee754/index.js ***!
|
2737
|
-
\***************************************/
|
2738
|
-
/*! no static exports found */
|
2739
|
-
/***/ (function(module, exports) {
|
2740
|
-
|
2741
|
-
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
2742
|
-
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
|
2743
|
-
var e, m
|
2744
|
-
var eLen = (nBytes * 8) - mLen - 1
|
2745
|
-
var eMax = (1 << eLen) - 1
|
2746
|
-
var eBias = eMax >> 1
|
2747
|
-
var nBits = -7
|
2748
|
-
var i = isLE ? (nBytes - 1) : 0
|
2749
|
-
var d = isLE ? -1 : 1
|
2750
|
-
var s = buffer[offset + i]
|
2751
|
-
|
2752
|
-
i += d
|
2753
|
-
|
2754
|
-
e = s & ((1 << (-nBits)) - 1)
|
2755
|
-
s >>= (-nBits)
|
2756
|
-
nBits += eLen
|
2757
|
-
for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
2758
|
-
|
2759
|
-
m = e & ((1 << (-nBits)) - 1)
|
2760
|
-
e >>= (-nBits)
|
2761
|
-
nBits += mLen
|
2762
|
-
for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
2763
|
-
|
2764
|
-
if (e === 0) {
|
2765
|
-
e = 1 - eBias
|
2766
|
-
} else if (e === eMax) {
|
2767
|
-
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
2768
|
-
} else {
|
2769
|
-
m = m + Math.pow(2, mLen)
|
2770
|
-
e = e - eBias
|
2771
|
-
}
|
2772
|
-
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
2773
|
-
}
|
2774
|
-
|
2775
|
-
exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
2776
|
-
var e, m, c
|
2777
|
-
var eLen = (nBytes * 8) - mLen - 1
|
2778
|
-
var eMax = (1 << eLen) - 1
|
2779
|
-
var eBias = eMax >> 1
|
2780
|
-
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
|
2781
|
-
var i = isLE ? 0 : (nBytes - 1)
|
2782
|
-
var d = isLE ? 1 : -1
|
2783
|
-
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
|
2784
|
-
|
2785
|
-
value = Math.abs(value)
|
2786
|
-
|
2787
|
-
if (isNaN(value) || value === Infinity) {
|
2788
|
-
m = isNaN(value) ? 1 : 0
|
2789
|
-
e = eMax
|
2790
|
-
} else {
|
2791
|
-
e = Math.floor(Math.log(value) / Math.LN2)
|
2792
|
-
if (value * (c = Math.pow(2, -e)) < 1) {
|
2793
|
-
e--
|
2794
|
-
c *= 2
|
2795
|
-
}
|
2796
|
-
if (e + eBias >= 1) {
|
2797
|
-
value += rt / c
|
2798
|
-
} else {
|
2799
|
-
value += rt * Math.pow(2, 1 - eBias)
|
2800
|
-
}
|
2801
|
-
if (value * c >= 2) {
|
2802
|
-
e++
|
2803
|
-
c /= 2
|
2804
|
-
}
|
2805
|
-
|
2806
|
-
if (e + eBias >= eMax) {
|
2807
|
-
m = 0
|
2808
|
-
e = eMax
|
2809
|
-
} else if (e + eBias >= 1) {
|
2810
|
-
m = ((value * c) - 1) * Math.pow(2, mLen)
|
2811
|
-
e = e + eBias
|
2812
|
-
} else {
|
2813
|
-
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
|
2814
|
-
e = 0
|
2815
|
-
}
|
2816
|
-
}
|
2817
|
-
|
2818
|
-
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
2819
|
-
|
2820
|
-
e = (e << mLen) | m
|
2821
|
-
eLen += mLen
|
2822
|
-
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
2823
|
-
|
2824
|
-
buffer[offset + i - d] |= s * 128
|
2825
|
-
}
|
2826
|
-
|
2827
|
-
|
2828
|
-
/***/ }),
|
2829
|
-
|
2830
|
-
/***/ "./node_modules/node-libs-browser/node_modules/buffer/index.js":
|
2831
|
-
/*!*********************************************************************!*\
|
2832
|
-
!*** ./node_modules/node-libs-browser/node_modules/buffer/index.js ***!
|
2833
|
-
\*********************************************************************/
|
2834
|
-
/*! no static exports found */
|
2835
|
-
/***/ (function(module, exports, __webpack_require__) {
|
2836
|
-
|
2837
|
-
"use strict";
|
2838
|
-
/* WEBPACK VAR INJECTION */(function(global) {/*!
|
2839
|
-
* The buffer module from node.js, for the browser.
|
2840
|
-
*
|
2841
|
-
* @author Feross Aboukhadijeh <http://feross.org>
|
2842
|
-
* @license MIT
|
2843
|
-
*/
|
2844
|
-
/* eslint-disable no-proto */
|
2845
|
-
|
2846
|
-
|
2847
|
-
|
2848
|
-
var base64 = __webpack_require__(/*! base64-js */ "./node_modules/base64-js/index.js")
|
2849
|
-
var ieee754 = __webpack_require__(/*! ieee754 */ "./node_modules/ieee754/index.js")
|
2850
|
-
var isArray = __webpack_require__(/*! isarray */ "./node_modules/node-libs-browser/node_modules/isarray/index.js")
|
2851
|
-
|
2852
|
-
exports.Buffer = Buffer
|
2853
|
-
exports.SlowBuffer = SlowBuffer
|
2854
|
-
exports.INSPECT_MAX_BYTES = 50
|
2855
|
-
|
2856
|
-
/**
|
2857
|
-
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
2858
|
-
* === true Use Uint8Array implementation (fastest)
|
2859
|
-
* === false Use Object implementation (most compatible, even IE6)
|
2860
|
-
*
|
2861
|
-
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
2862
|
-
* Opera 11.6+, iOS 4.2+.
|
2863
|
-
*
|
2864
|
-
* Due to various browser bugs, sometimes the Object implementation will be used even
|
2865
|
-
* when the browser supports typed arrays.
|
2866
|
-
*
|
2867
|
-
* Note:
|
2868
|
-
*
|
2869
|
-
* - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
|
2870
|
-
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
|
2871
|
-
*
|
2872
|
-
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
|
2873
|
-
*
|
2874
|
-
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
|
2875
|
-
* incorrect length in some situations.
|
2876
|
-
|
2877
|
-
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
|
2878
|
-
* get the Object implementation, which is slower but behaves correctly.
|
2879
|
-
*/
|
2880
|
-
Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
|
2881
|
-
? global.TYPED_ARRAY_SUPPORT
|
2882
|
-
: typedArraySupport()
|
2883
|
-
|
2884
|
-
/*
|
2885
|
-
* Export kMaxLength after typed array support is determined.
|
2886
|
-
*/
|
2887
|
-
exports.kMaxLength = kMaxLength()
|
2888
|
-
|
2889
|
-
function typedArraySupport () {
|
2890
|
-
try {
|
2891
|
-
var arr = new Uint8Array(1)
|
2892
|
-
arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
|
2893
|
-
return arr.foo() === 42 && // typed array instances can be augmented
|
2894
|
-
typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
|
2895
|
-
arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
|
2896
|
-
} catch (e) {
|
2897
|
-
return false
|
2898
|
-
}
|
2899
|
-
}
|
2900
|
-
|
2901
|
-
function kMaxLength () {
|
2902
|
-
return Buffer.TYPED_ARRAY_SUPPORT
|
2903
|
-
? 0x7fffffff
|
2904
|
-
: 0x3fffffff
|
2905
|
-
}
|
2906
|
-
|
2907
|
-
function createBuffer (that, length) {
|
2908
|
-
if (kMaxLength() < length) {
|
2909
|
-
throw new RangeError('Invalid typed array length')
|
2910
|
-
}
|
2911
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
2912
|
-
// Return an augmented `Uint8Array` instance, for best performance
|
2913
|
-
that = new Uint8Array(length)
|
2914
|
-
that.__proto__ = Buffer.prototype
|
2915
|
-
} else {
|
2916
|
-
// Fallback: Return an object instance of the Buffer class
|
2917
|
-
if (that === null) {
|
2918
|
-
that = new Buffer(length)
|
2919
|
-
}
|
2920
|
-
that.length = length
|
2921
|
-
}
|
2922
|
-
|
2923
|
-
return that
|
2924
|
-
}
|
2925
|
-
|
2926
|
-
/**
|
2927
|
-
* The Buffer constructor returns instances of `Uint8Array` that have their
|
2928
|
-
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
2929
|
-
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
2930
|
-
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
2931
|
-
* returns a single octet.
|
2932
|
-
*
|
2933
|
-
* The `Uint8Array` prototype remains unmodified.
|
2934
|
-
*/
|
2935
|
-
|
2936
|
-
function Buffer (arg, encodingOrOffset, length) {
|
2937
|
-
if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
|
2938
|
-
return new Buffer(arg, encodingOrOffset, length)
|
2939
|
-
}
|
2940
|
-
|
2941
|
-
// Common case.
|
2942
|
-
if (typeof arg === 'number') {
|
2943
|
-
if (typeof encodingOrOffset === 'string') {
|
2944
|
-
throw new Error(
|
2945
|
-
'If encoding is specified then the first argument must be a string'
|
2946
|
-
)
|
2947
|
-
}
|
2948
|
-
return allocUnsafe(this, arg)
|
2949
|
-
}
|
2950
|
-
return from(this, arg, encodingOrOffset, length)
|
2951
|
-
}
|
2952
|
-
|
2953
|
-
Buffer.poolSize = 8192 // not used by this implementation
|
2954
|
-
|
2955
|
-
// TODO: Legacy, not needed anymore. Remove in next major version.
|
2956
|
-
Buffer._augment = function (arr) {
|
2957
|
-
arr.__proto__ = Buffer.prototype
|
2958
|
-
return arr
|
2959
|
-
}
|
2960
|
-
|
2961
|
-
function from (that, value, encodingOrOffset, length) {
|
2962
|
-
if (typeof value === 'number') {
|
2963
|
-
throw new TypeError('"value" argument must not be a number')
|
2964
|
-
}
|
2965
|
-
|
2966
|
-
if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
|
2967
|
-
return fromArrayBuffer(that, value, encodingOrOffset, length)
|
2968
|
-
}
|
2969
|
-
|
2970
|
-
if (typeof value === 'string') {
|
2971
|
-
return fromString(that, value, encodingOrOffset)
|
2972
|
-
}
|
2973
|
-
|
2974
|
-
return fromObject(that, value)
|
2975
|
-
}
|
2976
|
-
|
2977
|
-
/**
|
2978
|
-
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
2979
|
-
* if value is a number.
|
2980
|
-
* Buffer.from(str[, encoding])
|
2981
|
-
* Buffer.from(array)
|
2982
|
-
* Buffer.from(buffer)
|
2983
|
-
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
2984
|
-
**/
|
2985
|
-
Buffer.from = function (value, encodingOrOffset, length) {
|
2986
|
-
return from(null, value, encodingOrOffset, length)
|
2987
|
-
}
|
2988
|
-
|
2989
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
2990
|
-
Buffer.prototype.__proto__ = Uint8Array.prototype
|
2991
|
-
Buffer.__proto__ = Uint8Array
|
2992
|
-
if (typeof Symbol !== 'undefined' && Symbol.species &&
|
2993
|
-
Buffer[Symbol.species] === Buffer) {
|
2994
|
-
// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
|
2995
|
-
Object.defineProperty(Buffer, Symbol.species, {
|
2996
|
-
value: null,
|
2997
|
-
configurable: true
|
2998
|
-
})
|
2999
|
-
}
|
3000
|
-
}
|
3001
|
-
|
3002
|
-
function assertSize (size) {
|
3003
|
-
if (typeof size !== 'number') {
|
3004
|
-
throw new TypeError('"size" argument must be a number')
|
3005
|
-
} else if (size < 0) {
|
3006
|
-
throw new RangeError('"size" argument must not be negative')
|
3007
|
-
}
|
3008
|
-
}
|
3009
|
-
|
3010
|
-
function alloc (that, size, fill, encoding) {
|
3011
|
-
assertSize(size)
|
3012
|
-
if (size <= 0) {
|
3013
|
-
return createBuffer(that, size)
|
3014
|
-
}
|
3015
|
-
if (fill !== undefined) {
|
3016
|
-
// Only pay attention to encoding if it's a string. This
|
3017
|
-
// prevents accidentally sending in a number that would
|
3018
|
-
// be interpretted as a start offset.
|
3019
|
-
return typeof encoding === 'string'
|
3020
|
-
? createBuffer(that, size).fill(fill, encoding)
|
3021
|
-
: createBuffer(that, size).fill(fill)
|
3022
|
-
}
|
3023
|
-
return createBuffer(that, size)
|
3024
|
-
}
|
3025
|
-
|
3026
|
-
/**
|
3027
|
-
* Creates a new filled Buffer instance.
|
3028
|
-
* alloc(size[, fill[, encoding]])
|
3029
|
-
**/
|
3030
|
-
Buffer.alloc = function (size, fill, encoding) {
|
3031
|
-
return alloc(null, size, fill, encoding)
|
3032
|
-
}
|
3033
|
-
|
3034
|
-
function allocUnsafe (that, size) {
|
3035
|
-
assertSize(size)
|
3036
|
-
that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
|
3037
|
-
if (!Buffer.TYPED_ARRAY_SUPPORT) {
|
3038
|
-
for (var i = 0; i < size; ++i) {
|
3039
|
-
that[i] = 0
|
3040
|
-
}
|
3041
|
-
}
|
3042
|
-
return that
|
3043
|
-
}
|
3044
|
-
|
3045
|
-
/**
|
3046
|
-
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
3047
|
-
* */
|
3048
|
-
Buffer.allocUnsafe = function (size) {
|
3049
|
-
return allocUnsafe(null, size)
|
3050
|
-
}
|
3051
|
-
/**
|
3052
|
-
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
3053
|
-
*/
|
3054
|
-
Buffer.allocUnsafeSlow = function (size) {
|
3055
|
-
return allocUnsafe(null, size)
|
3056
|
-
}
|
3057
|
-
|
3058
|
-
function fromString (that, string, encoding) {
|
3059
|
-
if (typeof encoding !== 'string' || encoding === '') {
|
3060
|
-
encoding = 'utf8'
|
3061
|
-
}
|
3062
|
-
|
3063
|
-
if (!Buffer.isEncoding(encoding)) {
|
3064
|
-
throw new TypeError('"encoding" must be a valid string encoding')
|
3065
|
-
}
|
3066
|
-
|
3067
|
-
var length = byteLength(string, encoding) | 0
|
3068
|
-
that = createBuffer(that, length)
|
3069
|
-
|
3070
|
-
var actual = that.write(string, encoding)
|
3071
|
-
|
3072
|
-
if (actual !== length) {
|
3073
|
-
// Writing a hex string, for example, that contains invalid characters will
|
3074
|
-
// cause everything after the first invalid character to be ignored. (e.g.
|
3075
|
-
// 'abxxcd' will be treated as 'ab')
|
3076
|
-
that = that.slice(0, actual)
|
3077
|
-
}
|
3078
|
-
|
3079
|
-
return that
|
3080
|
-
}
|
3081
|
-
|
3082
|
-
function fromArrayLike (that, array) {
|
3083
|
-
var length = array.length < 0 ? 0 : checked(array.length) | 0
|
3084
|
-
that = createBuffer(that, length)
|
3085
|
-
for (var i = 0; i < length; i += 1) {
|
3086
|
-
that[i] = array[i] & 255
|
3087
|
-
}
|
3088
|
-
return that
|
3089
|
-
}
|
3090
|
-
|
3091
|
-
function fromArrayBuffer (that, array, byteOffset, length) {
|
3092
|
-
array.byteLength // this throws if `array` is not a valid ArrayBuffer
|
3093
|
-
|
3094
|
-
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
3095
|
-
throw new RangeError('\'offset\' is out of bounds')
|
3096
|
-
}
|
3097
|
-
|
3098
|
-
if (array.byteLength < byteOffset + (length || 0)) {
|
3099
|
-
throw new RangeError('\'length\' is out of bounds')
|
3100
|
-
}
|
3101
|
-
|
3102
|
-
if (byteOffset === undefined && length === undefined) {
|
3103
|
-
array = new Uint8Array(array)
|
3104
|
-
} else if (length === undefined) {
|
3105
|
-
array = new Uint8Array(array, byteOffset)
|
3106
|
-
} else {
|
3107
|
-
array = new Uint8Array(array, byteOffset, length)
|
3108
|
-
}
|
3109
|
-
|
3110
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
3111
|
-
// Return an augmented `Uint8Array` instance, for best performance
|
3112
|
-
that = array
|
3113
|
-
that.__proto__ = Buffer.prototype
|
3114
|
-
} else {
|
3115
|
-
// Fallback: Return an object instance of the Buffer class
|
3116
|
-
that = fromArrayLike(that, array)
|
3117
|
-
}
|
3118
|
-
return that
|
3119
|
-
}
|
3120
|
-
|
3121
|
-
function fromObject (that, obj) {
|
3122
|
-
if (Buffer.isBuffer(obj)) {
|
3123
|
-
var len = checked(obj.length) | 0
|
3124
|
-
that = createBuffer(that, len)
|
3125
|
-
|
3126
|
-
if (that.length === 0) {
|
3127
|
-
return that
|
3128
|
-
}
|
3129
|
-
|
3130
|
-
obj.copy(that, 0, 0, len)
|
3131
|
-
return that
|
3132
|
-
}
|
3133
|
-
|
3134
|
-
if (obj) {
|
3135
|
-
if ((typeof ArrayBuffer !== 'undefined' &&
|
3136
|
-
obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
|
3137
|
-
if (typeof obj.length !== 'number' || isnan(obj.length)) {
|
3138
|
-
return createBuffer(that, 0)
|
3139
|
-
}
|
3140
|
-
return fromArrayLike(that, obj)
|
3141
|
-
}
|
3142
|
-
|
3143
|
-
if (obj.type === 'Buffer' && isArray(obj.data)) {
|
3144
|
-
return fromArrayLike(that, obj.data)
|
3145
|
-
}
|
3146
|
-
}
|
3147
|
-
|
3148
|
-
throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
|
3149
|
-
}
|
3150
|
-
|
3151
|
-
function checked (length) {
|
3152
|
-
// Note: cannot use `length < kMaxLength()` here because that fails when
|
3153
|
-
// length is NaN (which is otherwise coerced to zero.)
|
3154
|
-
if (length >= kMaxLength()) {
|
3155
|
-
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
3156
|
-
'size: 0x' + kMaxLength().toString(16) + ' bytes')
|
3157
|
-
}
|
3158
|
-
return length | 0
|
3159
|
-
}
|
3160
|
-
|
3161
|
-
function SlowBuffer (length) {
|
3162
|
-
if (+length != length) { // eslint-disable-line eqeqeq
|
3163
|
-
length = 0
|
3164
|
-
}
|
3165
|
-
return Buffer.alloc(+length)
|
3166
|
-
}
|
3167
|
-
|
3168
|
-
Buffer.isBuffer = function isBuffer (b) {
|
3169
|
-
return !!(b != null && b._isBuffer)
|
3170
|
-
}
|
3171
|
-
|
3172
|
-
Buffer.compare = function compare (a, b) {
|
3173
|
-
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
3174
|
-
throw new TypeError('Arguments must be Buffers')
|
3175
|
-
}
|
3176
|
-
|
3177
|
-
if (a === b) return 0
|
3178
|
-
|
3179
|
-
var x = a.length
|
3180
|
-
var y = b.length
|
3181
|
-
|
3182
|
-
for (var i = 0, len = Math.min(x, y); i < len; ++i) {
|
3183
|
-
if (a[i] !== b[i]) {
|
3184
|
-
x = a[i]
|
3185
|
-
y = b[i]
|
3186
|
-
break
|
3187
|
-
}
|
3188
|
-
}
|
3189
|
-
|
3190
|
-
if (x < y) return -1
|
3191
|
-
if (y < x) return 1
|
3192
|
-
return 0
|
3193
|
-
}
|
3194
|
-
|
3195
|
-
Buffer.isEncoding = function isEncoding (encoding) {
|
3196
|
-
switch (String(encoding).toLowerCase()) {
|
3197
|
-
case 'hex':
|
3198
|
-
case 'utf8':
|
3199
|
-
case 'utf-8':
|
3200
|
-
case 'ascii':
|
3201
|
-
case 'latin1':
|
3202
|
-
case 'binary':
|
3203
|
-
case 'base64':
|
3204
|
-
case 'ucs2':
|
3205
|
-
case 'ucs-2':
|
3206
|
-
case 'utf16le':
|
3207
|
-
case 'utf-16le':
|
3208
|
-
return true
|
3209
|
-
default:
|
3210
|
-
return false
|
3211
|
-
}
|
3212
|
-
}
|
3213
|
-
|
3214
|
-
Buffer.concat = function concat (list, length) {
|
3215
|
-
if (!isArray(list)) {
|
3216
|
-
throw new TypeError('"list" argument must be an Array of Buffers')
|
3217
|
-
}
|
3218
|
-
|
3219
|
-
if (list.length === 0) {
|
3220
|
-
return Buffer.alloc(0)
|
3221
|
-
}
|
3222
|
-
|
3223
|
-
var i
|
3224
|
-
if (length === undefined) {
|
3225
|
-
length = 0
|
3226
|
-
for (i = 0; i < list.length; ++i) {
|
3227
|
-
length += list[i].length
|
3228
|
-
}
|
3229
|
-
}
|
3230
|
-
|
3231
|
-
var buffer = Buffer.allocUnsafe(length)
|
3232
|
-
var pos = 0
|
3233
|
-
for (i = 0; i < list.length; ++i) {
|
3234
|
-
var buf = list[i]
|
3235
|
-
if (!Buffer.isBuffer(buf)) {
|
3236
|
-
throw new TypeError('"list" argument must be an Array of Buffers')
|
3237
|
-
}
|
3238
|
-
buf.copy(buffer, pos)
|
3239
|
-
pos += buf.length
|
3240
|
-
}
|
3241
|
-
return buffer
|
3242
|
-
}
|
3243
|
-
|
3244
|
-
function byteLength (string, encoding) {
|
3245
|
-
if (Buffer.isBuffer(string)) {
|
3246
|
-
return string.length
|
3247
|
-
}
|
3248
|
-
if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
|
3249
|
-
(ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
|
3250
|
-
return string.byteLength
|
3251
|
-
}
|
3252
|
-
if (typeof string !== 'string') {
|
3253
|
-
string = '' + string
|
3254
|
-
}
|
3255
|
-
|
3256
|
-
var len = string.length
|
3257
|
-
if (len === 0) return 0
|
3258
|
-
|
3259
|
-
// Use a for loop to avoid recursion
|
3260
|
-
var loweredCase = false
|
3261
|
-
for (;;) {
|
3262
|
-
switch (encoding) {
|
3263
|
-
case 'ascii':
|
3264
|
-
case 'latin1':
|
3265
|
-
case 'binary':
|
3266
|
-
return len
|
3267
|
-
case 'utf8':
|
3268
|
-
case 'utf-8':
|
3269
|
-
case undefined:
|
3270
|
-
return utf8ToBytes(string).length
|
3271
|
-
case 'ucs2':
|
3272
|
-
case 'ucs-2':
|
3273
|
-
case 'utf16le':
|
3274
|
-
case 'utf-16le':
|
3275
|
-
return len * 2
|
3276
|
-
case 'hex':
|
3277
|
-
return len >>> 1
|
3278
|
-
case 'base64':
|
3279
|
-
return base64ToBytes(string).length
|
3280
|
-
default:
|
3281
|
-
if (loweredCase) return utf8ToBytes(string).length // assume utf8
|
3282
|
-
encoding = ('' + encoding).toLowerCase()
|
3283
|
-
loweredCase = true
|
3284
|
-
}
|
3285
|
-
}
|
3286
|
-
}
|
3287
|
-
Buffer.byteLength = byteLength
|
3288
|
-
|
3289
|
-
function slowToString (encoding, start, end) {
|
3290
|
-
var loweredCase = false
|
3291
|
-
|
3292
|
-
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
3293
|
-
// property of a typed array.
|
3294
|
-
|
3295
|
-
// This behaves neither like String nor Uint8Array in that we set start/end
|
3296
|
-
// to their upper/lower bounds if the value passed is out of range.
|
3297
|
-
// undefined is handled specially as per ECMA-262 6th Edition,
|
3298
|
-
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
3299
|
-
if (start === undefined || start < 0) {
|
3300
|
-
start = 0
|
3301
|
-
}
|
3302
|
-
// Return early if start > this.length. Done here to prevent potential uint32
|
3303
|
-
// coercion fail below.
|
3304
|
-
if (start > this.length) {
|
3305
|
-
return ''
|
3306
|
-
}
|
3307
|
-
|
3308
|
-
if (end === undefined || end > this.length) {
|
3309
|
-
end = this.length
|
3310
|
-
}
|
3311
|
-
|
3312
|
-
if (end <= 0) {
|
3313
|
-
return ''
|
3314
|
-
}
|
3315
|
-
|
3316
|
-
// Force coersion to uint32. This will also coerce falsey/NaN values to 0.
|
3317
|
-
end >>>= 0
|
3318
|
-
start >>>= 0
|
3319
|
-
|
3320
|
-
if (end <= start) {
|
3321
|
-
return ''
|
3322
|
-
}
|
3323
|
-
|
3324
|
-
if (!encoding) encoding = 'utf8'
|
3325
|
-
|
3326
|
-
while (true) {
|
3327
|
-
switch (encoding) {
|
3328
|
-
case 'hex':
|
3329
|
-
return hexSlice(this, start, end)
|
3330
|
-
|
3331
|
-
case 'utf8':
|
3332
|
-
case 'utf-8':
|
3333
|
-
return utf8Slice(this, start, end)
|
3334
|
-
|
3335
|
-
case 'ascii':
|
3336
|
-
return asciiSlice(this, start, end)
|
3337
|
-
|
3338
|
-
case 'latin1':
|
3339
|
-
case 'binary':
|
3340
|
-
return latin1Slice(this, start, end)
|
3341
|
-
|
3342
|
-
case 'base64':
|
3343
|
-
return base64Slice(this, start, end)
|
3344
|
-
|
3345
|
-
case 'ucs2':
|
3346
|
-
case 'ucs-2':
|
3347
|
-
case 'utf16le':
|
3348
|
-
case 'utf-16le':
|
3349
|
-
return utf16leSlice(this, start, end)
|
3350
|
-
|
3351
|
-
default:
|
3352
|
-
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
3353
|
-
encoding = (encoding + '').toLowerCase()
|
3354
|
-
loweredCase = true
|
3355
|
-
}
|
3356
|
-
}
|
3357
|
-
}
|
3358
|
-
|
3359
|
-
// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect
|
3360
|
-
// Buffer instances.
|
3361
|
-
Buffer.prototype._isBuffer = true
|
3362
|
-
|
3363
|
-
function swap (b, n, m) {
|
3364
|
-
var i = b[n]
|
3365
|
-
b[n] = b[m]
|
3366
|
-
b[m] = i
|
3367
|
-
}
|
3368
|
-
|
3369
|
-
Buffer.prototype.swap16 = function swap16 () {
|
3370
|
-
var len = this.length
|
3371
|
-
if (len % 2 !== 0) {
|
3372
|
-
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
3373
|
-
}
|
3374
|
-
for (var i = 0; i < len; i += 2) {
|
3375
|
-
swap(this, i, i + 1)
|
3376
|
-
}
|
3377
|
-
return this
|
3378
|
-
}
|
3379
|
-
|
3380
|
-
Buffer.prototype.swap32 = function swap32 () {
|
3381
|
-
var len = this.length
|
3382
|
-
if (len % 4 !== 0) {
|
3383
|
-
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
3384
|
-
}
|
3385
|
-
for (var i = 0; i < len; i += 4) {
|
3386
|
-
swap(this, i, i + 3)
|
3387
|
-
swap(this, i + 1, i + 2)
|
3388
|
-
}
|
3389
|
-
return this
|
3390
|
-
}
|
3391
|
-
|
3392
|
-
Buffer.prototype.swap64 = function swap64 () {
|
3393
|
-
var len = this.length
|
3394
|
-
if (len % 8 !== 0) {
|
3395
|
-
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
3396
|
-
}
|
3397
|
-
for (var i = 0; i < len; i += 8) {
|
3398
|
-
swap(this, i, i + 7)
|
3399
|
-
swap(this, i + 1, i + 6)
|
3400
|
-
swap(this, i + 2, i + 5)
|
3401
|
-
swap(this, i + 3, i + 4)
|
3402
|
-
}
|
3403
|
-
return this
|
3404
|
-
}
|
3405
|
-
|
3406
|
-
Buffer.prototype.toString = function toString () {
|
3407
|
-
var length = this.length | 0
|
3408
|
-
if (length === 0) return ''
|
3409
|
-
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
3410
|
-
return slowToString.apply(this, arguments)
|
3411
|
-
}
|
3412
|
-
|
3413
|
-
Buffer.prototype.equals = function equals (b) {
|
3414
|
-
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
3415
|
-
if (this === b) return true
|
3416
|
-
return Buffer.compare(this, b) === 0
|
3417
|
-
}
|
3418
|
-
|
3419
|
-
Buffer.prototype.inspect = function inspect () {
|
3420
|
-
var str = ''
|
3421
|
-
var max = exports.INSPECT_MAX_BYTES
|
3422
|
-
if (this.length > 0) {
|
3423
|
-
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
|
3424
|
-
if (this.length > max) str += ' ... '
|
3425
|
-
}
|
3426
|
-
return '<Buffer ' + str + '>'
|
3427
|
-
}
|
3428
|
-
|
3429
|
-
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
3430
|
-
if (!Buffer.isBuffer(target)) {
|
3431
|
-
throw new TypeError('Argument must be a Buffer')
|
3432
|
-
}
|
3433
|
-
|
3434
|
-
if (start === undefined) {
|
3435
|
-
start = 0
|
3436
|
-
}
|
3437
|
-
if (end === undefined) {
|
3438
|
-
end = target ? target.length : 0
|
3439
|
-
}
|
3440
|
-
if (thisStart === undefined) {
|
3441
|
-
thisStart = 0
|
3442
|
-
}
|
3443
|
-
if (thisEnd === undefined) {
|
3444
|
-
thisEnd = this.length
|
3445
|
-
}
|
3446
|
-
|
3447
|
-
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
3448
|
-
throw new RangeError('out of range index')
|
3449
|
-
}
|
3450
|
-
|
3451
|
-
if (thisStart >= thisEnd && start >= end) {
|
3452
|
-
return 0
|
3453
|
-
}
|
3454
|
-
if (thisStart >= thisEnd) {
|
3455
|
-
return -1
|
3456
|
-
}
|
3457
|
-
if (start >= end) {
|
3458
|
-
return 1
|
3459
|
-
}
|
3460
|
-
|
3461
|
-
start >>>= 0
|
3462
|
-
end >>>= 0
|
3463
|
-
thisStart >>>= 0
|
3464
|
-
thisEnd >>>= 0
|
3465
|
-
|
3466
|
-
if (this === target) return 0
|
3467
|
-
|
3468
|
-
var x = thisEnd - thisStart
|
3469
|
-
var y = end - start
|
3470
|
-
var len = Math.min(x, y)
|
3471
|
-
|
3472
|
-
var thisCopy = this.slice(thisStart, thisEnd)
|
3473
|
-
var targetCopy = target.slice(start, end)
|
3474
|
-
|
3475
|
-
for (var i = 0; i < len; ++i) {
|
3476
|
-
if (thisCopy[i] !== targetCopy[i]) {
|
3477
|
-
x = thisCopy[i]
|
3478
|
-
y = targetCopy[i]
|
3479
|
-
break
|
3480
|
-
}
|
3481
|
-
}
|
3482
|
-
|
3483
|
-
if (x < y) return -1
|
3484
|
-
if (y < x) return 1
|
3485
|
-
return 0
|
3486
|
-
}
|
3487
|
-
|
3488
|
-
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
3489
|
-
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
3490
|
-
//
|
3491
|
-
// Arguments:
|
3492
|
-
// - buffer - a Buffer to search
|
3493
|
-
// - val - a string, Buffer, or number
|
3494
|
-
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
3495
|
-
// - encoding - an optional encoding, relevant is val is a string
|
3496
|
-
// - dir - true for indexOf, false for lastIndexOf
|
3497
|
-
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
3498
|
-
// Empty buffer means no match
|
3499
|
-
if (buffer.length === 0) return -1
|
3500
|
-
|
3501
|
-
// Normalize byteOffset
|
3502
|
-
if (typeof byteOffset === 'string') {
|
3503
|
-
encoding = byteOffset
|
3504
|
-
byteOffset = 0
|
3505
|
-
} else if (byteOffset > 0x7fffffff) {
|
3506
|
-
byteOffset = 0x7fffffff
|
3507
|
-
} else if (byteOffset < -0x80000000) {
|
3508
|
-
byteOffset = -0x80000000
|
3509
|
-
}
|
3510
|
-
byteOffset = +byteOffset // Coerce to Number.
|
3511
|
-
if (isNaN(byteOffset)) {
|
3512
|
-
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
3513
|
-
byteOffset = dir ? 0 : (buffer.length - 1)
|
3514
|
-
}
|
3515
|
-
|
3516
|
-
// Normalize byteOffset: negative offsets start from the end of the buffer
|
3517
|
-
if (byteOffset < 0) byteOffset = buffer.length + byteOffset
|
3518
|
-
if (byteOffset >= buffer.length) {
|
3519
|
-
if (dir) return -1
|
3520
|
-
else byteOffset = buffer.length - 1
|
3521
|
-
} else if (byteOffset < 0) {
|
3522
|
-
if (dir) byteOffset = 0
|
3523
|
-
else return -1
|
3524
|
-
}
|
3525
|
-
|
3526
|
-
// Normalize val
|
3527
|
-
if (typeof val === 'string') {
|
3528
|
-
val = Buffer.from(val, encoding)
|
3529
|
-
}
|
3530
|
-
|
3531
|
-
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
3532
|
-
if (Buffer.isBuffer(val)) {
|
3533
|
-
// Special case: looking for empty string/buffer always fails
|
3534
|
-
if (val.length === 0) {
|
3535
|
-
return -1
|
3536
|
-
}
|
3537
|
-
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
3538
|
-
} else if (typeof val === 'number') {
|
3539
|
-
val = val & 0xFF // Search for a byte value [0-255]
|
3540
|
-
if (Buffer.TYPED_ARRAY_SUPPORT &&
|
3541
|
-
typeof Uint8Array.prototype.indexOf === 'function') {
|
3542
|
-
if (dir) {
|
3543
|
-
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
3544
|
-
} else {
|
3545
|
-
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
3546
|
-
}
|
3547
|
-
}
|
3548
|
-
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
|
3549
|
-
}
|
3550
|
-
|
3551
|
-
throw new TypeError('val must be string, number or Buffer')
|
3552
|
-
}
|
3553
|
-
|
3554
|
-
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
3555
|
-
var indexSize = 1
|
3556
|
-
var arrLength = arr.length
|
3557
|
-
var valLength = val.length
|
3558
|
-
|
3559
|
-
if (encoding !== undefined) {
|
3560
|
-
encoding = String(encoding).toLowerCase()
|
3561
|
-
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
3562
|
-
encoding === 'utf16le' || encoding === 'utf-16le') {
|
3563
|
-
if (arr.length < 2 || val.length < 2) {
|
3564
|
-
return -1
|
3565
|
-
}
|
3566
|
-
indexSize = 2
|
3567
|
-
arrLength /= 2
|
3568
|
-
valLength /= 2
|
3569
|
-
byteOffset /= 2
|
3570
|
-
}
|
3571
|
-
}
|
3572
|
-
|
3573
|
-
function read (buf, i) {
|
3574
|
-
if (indexSize === 1) {
|
3575
|
-
return buf[i]
|
3576
|
-
} else {
|
3577
|
-
return buf.readUInt16BE(i * indexSize)
|
3578
|
-
}
|
3579
|
-
}
|
3580
|
-
|
3581
|
-
var i
|
3582
|
-
if (dir) {
|
3583
|
-
var foundIndex = -1
|
3584
|
-
for (i = byteOffset; i < arrLength; i++) {
|
3585
|
-
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
3586
|
-
if (foundIndex === -1) foundIndex = i
|
3587
|
-
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
3588
|
-
} else {
|
3589
|
-
if (foundIndex !== -1) i -= i - foundIndex
|
3590
|
-
foundIndex = -1
|
3591
|
-
}
|
3592
|
-
}
|
3593
|
-
} else {
|
3594
|
-
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
|
3595
|
-
for (i = byteOffset; i >= 0; i--) {
|
3596
|
-
var found = true
|
3597
|
-
for (var j = 0; j < valLength; j++) {
|
3598
|
-
if (read(arr, i + j) !== read(val, j)) {
|
3599
|
-
found = false
|
3600
|
-
break
|
3601
|
-
}
|
3602
|
-
}
|
3603
|
-
if (found) return i
|
3604
|
-
}
|
3605
|
-
}
|
3606
|
-
|
3607
|
-
return -1
|
3608
|
-
}
|
3609
|
-
|
3610
|
-
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
3611
|
-
return this.indexOf(val, byteOffset, encoding) !== -1
|
3612
|
-
}
|
3613
|
-
|
3614
|
-
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
3615
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
3616
|
-
}
|
3617
|
-
|
3618
|
-
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
3619
|
-
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
3620
|
-
}
|
3621
|
-
|
3622
|
-
function hexWrite (buf, string, offset, length) {
|
3623
|
-
offset = Number(offset) || 0
|
3624
|
-
var remaining = buf.length - offset
|
3625
|
-
if (!length) {
|
3626
|
-
length = remaining
|
3627
|
-
} else {
|
3628
|
-
length = Number(length)
|
3629
|
-
if (length > remaining) {
|
3630
|
-
length = remaining
|
3631
|
-
}
|
3632
|
-
}
|
3633
|
-
|
3634
|
-
// must be an even number of digits
|
3635
|
-
var strLen = string.length
|
3636
|
-
if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
|
3637
|
-
|
3638
|
-
if (length > strLen / 2) {
|
3639
|
-
length = strLen / 2
|
3640
|
-
}
|
3641
|
-
for (var i = 0; i < length; ++i) {
|
3642
|
-
var parsed = parseInt(string.substr(i * 2, 2), 16)
|
3643
|
-
if (isNaN(parsed)) return i
|
3644
|
-
buf[offset + i] = parsed
|
3645
|
-
}
|
3646
|
-
return i
|
3647
|
-
}
|
3648
|
-
|
3649
|
-
function utf8Write (buf, string, offset, length) {
|
3650
|
-
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
3651
|
-
}
|
3652
|
-
|
3653
|
-
function asciiWrite (buf, string, offset, length) {
|
3654
|
-
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
3655
|
-
}
|
3656
|
-
|
3657
|
-
function latin1Write (buf, string, offset, length) {
|
3658
|
-
return asciiWrite(buf, string, offset, length)
|
3659
|
-
}
|
3660
|
-
|
3661
|
-
function base64Write (buf, string, offset, length) {
|
3662
|
-
return blitBuffer(base64ToBytes(string), buf, offset, length)
|
3663
|
-
}
|
3664
|
-
|
3665
|
-
function ucs2Write (buf, string, offset, length) {
|
3666
|
-
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
3667
|
-
}
|
3668
|
-
|
3669
|
-
Buffer.prototype.write = function write (string, offset, length, encoding) {
|
3670
|
-
// Buffer#write(string)
|
3671
|
-
if (offset === undefined) {
|
3672
|
-
encoding = 'utf8'
|
3673
|
-
length = this.length
|
3674
|
-
offset = 0
|
3675
|
-
// Buffer#write(string, encoding)
|
3676
|
-
} else if (length === undefined && typeof offset === 'string') {
|
3677
|
-
encoding = offset
|
3678
|
-
length = this.length
|
3679
|
-
offset = 0
|
3680
|
-
// Buffer#write(string, offset[, length][, encoding])
|
3681
|
-
} else if (isFinite(offset)) {
|
3682
|
-
offset = offset | 0
|
3683
|
-
if (isFinite(length)) {
|
3684
|
-
length = length | 0
|
3685
|
-
if (encoding === undefined) encoding = 'utf8'
|
3686
|
-
} else {
|
3687
|
-
encoding = length
|
3688
|
-
length = undefined
|
3689
|
-
}
|
3690
|
-
// legacy write(string, encoding, offset, length) - remove in v0.13
|
3691
|
-
} else {
|
3692
|
-
throw new Error(
|
3693
|
-
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
3694
|
-
)
|
3695
|
-
}
|
3696
|
-
|
3697
|
-
var remaining = this.length - offset
|
3698
|
-
if (length === undefined || length > remaining) length = remaining
|
3699
|
-
|
3700
|
-
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
3701
|
-
throw new RangeError('Attempt to write outside buffer bounds')
|
3702
|
-
}
|
3703
|
-
|
3704
|
-
if (!encoding) encoding = 'utf8'
|
3705
|
-
|
3706
|
-
var loweredCase = false
|
3707
|
-
for (;;) {
|
3708
|
-
switch (encoding) {
|
3709
|
-
case 'hex':
|
3710
|
-
return hexWrite(this, string, offset, length)
|
3711
|
-
|
3712
|
-
case 'utf8':
|
3713
|
-
case 'utf-8':
|
3714
|
-
return utf8Write(this, string, offset, length)
|
3715
|
-
|
3716
|
-
case 'ascii':
|
3717
|
-
return asciiWrite(this, string, offset, length)
|
3718
|
-
|
3719
|
-
case 'latin1':
|
3720
|
-
case 'binary':
|
3721
|
-
return latin1Write(this, string, offset, length)
|
3722
|
-
|
3723
|
-
case 'base64':
|
3724
|
-
// Warning: maxLength not taken into account in base64Write
|
3725
|
-
return base64Write(this, string, offset, length)
|
3726
|
-
|
3727
|
-
case 'ucs2':
|
3728
|
-
case 'ucs-2':
|
3729
|
-
case 'utf16le':
|
3730
|
-
case 'utf-16le':
|
3731
|
-
return ucs2Write(this, string, offset, length)
|
3732
|
-
|
3733
|
-
default:
|
3734
|
-
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
3735
|
-
encoding = ('' + encoding).toLowerCase()
|
3736
|
-
loweredCase = true
|
3737
|
-
}
|
3738
|
-
}
|
3739
|
-
}
|
3740
|
-
|
3741
|
-
Buffer.prototype.toJSON = function toJSON () {
|
3742
|
-
return {
|
3743
|
-
type: 'Buffer',
|
3744
|
-
data: Array.prototype.slice.call(this._arr || this, 0)
|
3745
|
-
}
|
3746
|
-
}
|
3747
|
-
|
3748
|
-
function base64Slice (buf, start, end) {
|
3749
|
-
if (start === 0 && end === buf.length) {
|
3750
|
-
return base64.fromByteArray(buf)
|
3751
|
-
} else {
|
3752
|
-
return base64.fromByteArray(buf.slice(start, end))
|
3753
|
-
}
|
3754
|
-
}
|
3755
|
-
|
3756
|
-
function utf8Slice (buf, start, end) {
|
3757
|
-
end = Math.min(buf.length, end)
|
3758
|
-
var res = []
|
3759
|
-
|
3760
|
-
var i = start
|
3761
|
-
while (i < end) {
|
3762
|
-
var firstByte = buf[i]
|
3763
|
-
var codePoint = null
|
3764
|
-
var bytesPerSequence = (firstByte > 0xEF) ? 4
|
3765
|
-
: (firstByte > 0xDF) ? 3
|
3766
|
-
: (firstByte > 0xBF) ? 2
|
3767
|
-
: 1
|
3768
|
-
|
3769
|
-
if (i + bytesPerSequence <= end) {
|
3770
|
-
var secondByte, thirdByte, fourthByte, tempCodePoint
|
3771
|
-
|
3772
|
-
switch (bytesPerSequence) {
|
3773
|
-
case 1:
|
3774
|
-
if (firstByte < 0x80) {
|
3775
|
-
codePoint = firstByte
|
3776
|
-
}
|
3777
|
-
break
|
3778
|
-
case 2:
|
3779
|
-
secondByte = buf[i + 1]
|
3780
|
-
if ((secondByte & 0xC0) === 0x80) {
|
3781
|
-
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
|
3782
|
-
if (tempCodePoint > 0x7F) {
|
3783
|
-
codePoint = tempCodePoint
|
3784
|
-
}
|
3785
|
-
}
|
3786
|
-
break
|
3787
|
-
case 3:
|
3788
|
-
secondByte = buf[i + 1]
|
3789
|
-
thirdByte = buf[i + 2]
|
3790
|
-
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
3791
|
-
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
|
3792
|
-
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
3793
|
-
codePoint = tempCodePoint
|
3794
|
-
}
|
3795
|
-
}
|
3796
|
-
break
|
3797
|
-
case 4:
|
3798
|
-
secondByte = buf[i + 1]
|
3799
|
-
thirdByte = buf[i + 2]
|
3800
|
-
fourthByte = buf[i + 3]
|
3801
|
-
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
3802
|
-
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
|
3803
|
-
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
3804
|
-
codePoint = tempCodePoint
|
3805
|
-
}
|
3806
|
-
}
|
3807
|
-
}
|
3808
|
-
}
|
3809
|
-
|
3810
|
-
if (codePoint === null) {
|
3811
|
-
// we did not generate a valid codePoint so insert a
|
3812
|
-
// replacement char (U+FFFD) and advance only 1 byte
|
3813
|
-
codePoint = 0xFFFD
|
3814
|
-
bytesPerSequence = 1
|
3815
|
-
} else if (codePoint > 0xFFFF) {
|
3816
|
-
// encode to utf16 (surrogate pair dance)
|
3817
|
-
codePoint -= 0x10000
|
3818
|
-
res.push(codePoint >>> 10 & 0x3FF | 0xD800)
|
3819
|
-
codePoint = 0xDC00 | codePoint & 0x3FF
|
3820
|
-
}
|
3821
|
-
|
3822
|
-
res.push(codePoint)
|
3823
|
-
i += bytesPerSequence
|
3824
|
-
}
|
3825
|
-
|
3826
|
-
return decodeCodePointsArray(res)
|
3827
|
-
}
|
3828
|
-
|
3829
|
-
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
3830
|
-
// the lowest limit is Chrome, with 0x10000 args.
|
3831
|
-
// We go 1 magnitude less, for safety
|
3832
|
-
var MAX_ARGUMENTS_LENGTH = 0x1000
|
3833
|
-
|
3834
|
-
function decodeCodePointsArray (codePoints) {
|
3835
|
-
var len = codePoints.length
|
3836
|
-
if (len <= MAX_ARGUMENTS_LENGTH) {
|
3837
|
-
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
3838
|
-
}
|
3839
|
-
|
3840
|
-
// Decode in chunks to avoid "call stack size exceeded".
|
3841
|
-
var res = ''
|
3842
|
-
var i = 0
|
3843
|
-
while (i < len) {
|
3844
|
-
res += String.fromCharCode.apply(
|
3845
|
-
String,
|
3846
|
-
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
3847
|
-
)
|
3848
|
-
}
|
3849
|
-
return res
|
3850
|
-
}
|
3851
|
-
|
3852
|
-
function asciiSlice (buf, start, end) {
|
3853
|
-
var ret = ''
|
3854
|
-
end = Math.min(buf.length, end)
|
3855
|
-
|
3856
|
-
for (var i = start; i < end; ++i) {
|
3857
|
-
ret += String.fromCharCode(buf[i] & 0x7F)
|
3858
|
-
}
|
3859
|
-
return ret
|
3860
|
-
}
|
3861
|
-
|
3862
|
-
function latin1Slice (buf, start, end) {
|
3863
|
-
var ret = ''
|
3864
|
-
end = Math.min(buf.length, end)
|
3865
|
-
|
3866
|
-
for (var i = start; i < end; ++i) {
|
3867
|
-
ret += String.fromCharCode(buf[i])
|
3868
|
-
}
|
3869
|
-
return ret
|
3870
|
-
}
|
3871
|
-
|
3872
|
-
function hexSlice (buf, start, end) {
|
3873
|
-
var len = buf.length
|
3874
|
-
|
3875
|
-
if (!start || start < 0) start = 0
|
3876
|
-
if (!end || end < 0 || end > len) end = len
|
3877
|
-
|
3878
|
-
var out = ''
|
3879
|
-
for (var i = start; i < end; ++i) {
|
3880
|
-
out += toHex(buf[i])
|
3881
|
-
}
|
3882
|
-
return out
|
3883
|
-
}
|
3884
|
-
|
3885
|
-
function utf16leSlice (buf, start, end) {
|
3886
|
-
var bytes = buf.slice(start, end)
|
3887
|
-
var res = ''
|
3888
|
-
for (var i = 0; i < bytes.length; i += 2) {
|
3889
|
-
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
|
3890
|
-
}
|
3891
|
-
return res
|
3892
|
-
}
|
3893
|
-
|
3894
|
-
Buffer.prototype.slice = function slice (start, end) {
|
3895
|
-
var len = this.length
|
3896
|
-
start = ~~start
|
3897
|
-
end = end === undefined ? len : ~~end
|
3898
|
-
|
3899
|
-
if (start < 0) {
|
3900
|
-
start += len
|
3901
|
-
if (start < 0) start = 0
|
3902
|
-
} else if (start > len) {
|
3903
|
-
start = len
|
3904
|
-
}
|
3905
|
-
|
3906
|
-
if (end < 0) {
|
3907
|
-
end += len
|
3908
|
-
if (end < 0) end = 0
|
3909
|
-
} else if (end > len) {
|
3910
|
-
end = len
|
3911
|
-
}
|
3912
|
-
|
3913
|
-
if (end < start) end = start
|
3914
|
-
|
3915
|
-
var newBuf
|
3916
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
3917
|
-
newBuf = this.subarray(start, end)
|
3918
|
-
newBuf.__proto__ = Buffer.prototype
|
3919
|
-
} else {
|
3920
|
-
var sliceLen = end - start
|
3921
|
-
newBuf = new Buffer(sliceLen, undefined)
|
3922
|
-
for (var i = 0; i < sliceLen; ++i) {
|
3923
|
-
newBuf[i] = this[i + start]
|
3924
|
-
}
|
3925
|
-
}
|
3926
|
-
|
3927
|
-
return newBuf
|
3928
|
-
}
|
3929
|
-
|
3930
|
-
/*
|
3931
|
-
* Need to make sure that buffer isn't trying to write out of bounds.
|
3932
|
-
*/
|
3933
|
-
function checkOffset (offset, ext, length) {
|
3934
|
-
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
3935
|
-
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
3936
|
-
}
|
3937
|
-
|
3938
|
-
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
3939
|
-
offset = offset | 0
|
3940
|
-
byteLength = byteLength | 0
|
3941
|
-
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
3942
|
-
|
3943
|
-
var val = this[offset]
|
3944
|
-
var mul = 1
|
3945
|
-
var i = 0
|
3946
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
3947
|
-
val += this[offset + i] * mul
|
3948
|
-
}
|
3949
|
-
|
3950
|
-
return val
|
3951
|
-
}
|
3952
|
-
|
3953
|
-
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
3954
|
-
offset = offset | 0
|
3955
|
-
byteLength = byteLength | 0
|
3956
|
-
if (!noAssert) {
|
3957
|
-
checkOffset(offset, byteLength, this.length)
|
3958
|
-
}
|
3959
|
-
|
3960
|
-
var val = this[offset + --byteLength]
|
3961
|
-
var mul = 1
|
3962
|
-
while (byteLength > 0 && (mul *= 0x100)) {
|
3963
|
-
val += this[offset + --byteLength] * mul
|
3964
|
-
}
|
3965
|
-
|
3966
|
-
return val
|
3967
|
-
}
|
3968
|
-
|
3969
|
-
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
3970
|
-
if (!noAssert) checkOffset(offset, 1, this.length)
|
3971
|
-
return this[offset]
|
3972
|
-
}
|
3973
|
-
|
3974
|
-
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
3975
|
-
if (!noAssert) checkOffset(offset, 2, this.length)
|
3976
|
-
return this[offset] | (this[offset + 1] << 8)
|
3977
|
-
}
|
3978
|
-
|
3979
|
-
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
3980
|
-
if (!noAssert) checkOffset(offset, 2, this.length)
|
3981
|
-
return (this[offset] << 8) | this[offset + 1]
|
3982
|
-
}
|
3983
|
-
|
3984
|
-
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
3985
|
-
if (!noAssert) checkOffset(offset, 4, this.length)
|
3986
|
-
|
3987
|
-
return ((this[offset]) |
|
3988
|
-
(this[offset + 1] << 8) |
|
3989
|
-
(this[offset + 2] << 16)) +
|
3990
|
-
(this[offset + 3] * 0x1000000)
|
3991
|
-
}
|
3992
|
-
|
3993
|
-
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
3994
|
-
if (!noAssert) checkOffset(offset, 4, this.length)
|
3995
|
-
|
3996
|
-
return (this[offset] * 0x1000000) +
|
3997
|
-
((this[offset + 1] << 16) |
|
3998
|
-
(this[offset + 2] << 8) |
|
3999
|
-
this[offset + 3])
|
4000
|
-
}
|
4001
|
-
|
4002
|
-
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
4003
|
-
offset = offset | 0
|
4004
|
-
byteLength = byteLength | 0
|
4005
|
-
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
4006
|
-
|
4007
|
-
var val = this[offset]
|
4008
|
-
var mul = 1
|
4009
|
-
var i = 0
|
4010
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
4011
|
-
val += this[offset + i] * mul
|
4012
|
-
}
|
4013
|
-
mul *= 0x80
|
4014
|
-
|
4015
|
-
if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
4016
|
-
|
4017
|
-
return val
|
4018
|
-
}
|
4019
|
-
|
4020
|
-
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
4021
|
-
offset = offset | 0
|
4022
|
-
byteLength = byteLength | 0
|
4023
|
-
if (!noAssert) checkOffset(offset, byteLength, this.length)
|
4024
|
-
|
4025
|
-
var i = byteLength
|
4026
|
-
var mul = 1
|
4027
|
-
var val = this[offset + --i]
|
4028
|
-
while (i > 0 && (mul *= 0x100)) {
|
4029
|
-
val += this[offset + --i] * mul
|
4030
|
-
}
|
4031
|
-
mul *= 0x80
|
4032
|
-
|
4033
|
-
if (val >= mul) val -= Math.pow(2, 8 * byteLength)
|
4034
|
-
|
4035
|
-
return val
|
4036
|
-
}
|
4037
|
-
|
4038
|
-
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
4039
|
-
if (!noAssert) checkOffset(offset, 1, this.length)
|
4040
|
-
if (!(this[offset] & 0x80)) return (this[offset])
|
4041
|
-
return ((0xff - this[offset] + 1) * -1)
|
4042
|
-
}
|
4043
|
-
|
4044
|
-
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
4045
|
-
if (!noAssert) checkOffset(offset, 2, this.length)
|
4046
|
-
var val = this[offset] | (this[offset + 1] << 8)
|
4047
|
-
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
4048
|
-
}
|
4049
|
-
|
4050
|
-
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
4051
|
-
if (!noAssert) checkOffset(offset, 2, this.length)
|
4052
|
-
var val = this[offset + 1] | (this[offset] << 8)
|
4053
|
-
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
4054
|
-
}
|
4055
|
-
|
4056
|
-
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
4057
|
-
if (!noAssert) checkOffset(offset, 4, this.length)
|
4058
|
-
|
4059
|
-
return (this[offset]) |
|
4060
|
-
(this[offset + 1] << 8) |
|
4061
|
-
(this[offset + 2] << 16) |
|
4062
|
-
(this[offset + 3] << 24)
|
4063
|
-
}
|
4064
|
-
|
4065
|
-
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
4066
|
-
if (!noAssert) checkOffset(offset, 4, this.length)
|
4067
|
-
|
4068
|
-
return (this[offset] << 24) |
|
4069
|
-
(this[offset + 1] << 16) |
|
4070
|
-
(this[offset + 2] << 8) |
|
4071
|
-
(this[offset + 3])
|
4072
|
-
}
|
4073
|
-
|
4074
|
-
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
4075
|
-
if (!noAssert) checkOffset(offset, 4, this.length)
|
4076
|
-
return ieee754.read(this, offset, true, 23, 4)
|
4077
|
-
}
|
4078
|
-
|
4079
|
-
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
4080
|
-
if (!noAssert) checkOffset(offset, 4, this.length)
|
4081
|
-
return ieee754.read(this, offset, false, 23, 4)
|
4082
|
-
}
|
4083
|
-
|
4084
|
-
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
4085
|
-
if (!noAssert) checkOffset(offset, 8, this.length)
|
4086
|
-
return ieee754.read(this, offset, true, 52, 8)
|
4087
|
-
}
|
4088
|
-
|
4089
|
-
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
4090
|
-
if (!noAssert) checkOffset(offset, 8, this.length)
|
4091
|
-
return ieee754.read(this, offset, false, 52, 8)
|
4092
|
-
}
|
4093
|
-
|
4094
|
-
function checkInt (buf, value, offset, ext, max, min) {
|
4095
|
-
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
4096
|
-
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
4097
|
-
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
4098
|
-
}
|
4099
|
-
|
4100
|
-
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
4101
|
-
value = +value
|
4102
|
-
offset = offset | 0
|
4103
|
-
byteLength = byteLength | 0
|
4104
|
-
if (!noAssert) {
|
4105
|
-
var maxBytes = Math.pow(2, 8 * byteLength) - 1
|
4106
|
-
checkInt(this, value, offset, byteLength, maxBytes, 0)
|
4107
|
-
}
|
4108
|
-
|
4109
|
-
var mul = 1
|
4110
|
-
var i = 0
|
4111
|
-
this[offset] = value & 0xFF
|
4112
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
4113
|
-
this[offset + i] = (value / mul) & 0xFF
|
4114
|
-
}
|
4115
|
-
|
4116
|
-
return offset + byteLength
|
4117
|
-
}
|
4118
|
-
|
4119
|
-
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
4120
|
-
value = +value
|
4121
|
-
offset = offset | 0
|
4122
|
-
byteLength = byteLength | 0
|
4123
|
-
if (!noAssert) {
|
4124
|
-
var maxBytes = Math.pow(2, 8 * byteLength) - 1
|
4125
|
-
checkInt(this, value, offset, byteLength, maxBytes, 0)
|
4126
|
-
}
|
4127
|
-
|
4128
|
-
var i = byteLength - 1
|
4129
|
-
var mul = 1
|
4130
|
-
this[offset + i] = value & 0xFF
|
4131
|
-
while (--i >= 0 && (mul *= 0x100)) {
|
4132
|
-
this[offset + i] = (value / mul) & 0xFF
|
4133
|
-
}
|
4134
|
-
|
4135
|
-
return offset + byteLength
|
4136
|
-
}
|
4137
|
-
|
4138
|
-
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
4139
|
-
value = +value
|
4140
|
-
offset = offset | 0
|
4141
|
-
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
|
4142
|
-
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
|
4143
|
-
this[offset] = (value & 0xff)
|
4144
|
-
return offset + 1
|
4145
|
-
}
|
4146
|
-
|
4147
|
-
function objectWriteUInt16 (buf, value, offset, littleEndian) {
|
4148
|
-
if (value < 0) value = 0xffff + value + 1
|
4149
|
-
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
|
4150
|
-
buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
|
4151
|
-
(littleEndian ? i : 1 - i) * 8
|
4152
|
-
}
|
4153
|
-
}
|
4154
|
-
|
4155
|
-
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
4156
|
-
value = +value
|
4157
|
-
offset = offset | 0
|
4158
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
4159
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
4160
|
-
this[offset] = (value & 0xff)
|
4161
|
-
this[offset + 1] = (value >>> 8)
|
4162
|
-
} else {
|
4163
|
-
objectWriteUInt16(this, value, offset, true)
|
4164
|
-
}
|
4165
|
-
return offset + 2
|
4166
|
-
}
|
4167
|
-
|
4168
|
-
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
4169
|
-
value = +value
|
4170
|
-
offset = offset | 0
|
4171
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
|
4172
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
4173
|
-
this[offset] = (value >>> 8)
|
4174
|
-
this[offset + 1] = (value & 0xff)
|
4175
|
-
} else {
|
4176
|
-
objectWriteUInt16(this, value, offset, false)
|
4177
|
-
}
|
4178
|
-
return offset + 2
|
4179
|
-
}
|
4180
|
-
|
4181
|
-
function objectWriteUInt32 (buf, value, offset, littleEndian) {
|
4182
|
-
if (value < 0) value = 0xffffffff + value + 1
|
4183
|
-
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
|
4184
|
-
buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
|
4185
|
-
}
|
4186
|
-
}
|
4187
|
-
|
4188
|
-
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
4189
|
-
value = +value
|
4190
|
-
offset = offset | 0
|
4191
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
4192
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
4193
|
-
this[offset + 3] = (value >>> 24)
|
4194
|
-
this[offset + 2] = (value >>> 16)
|
4195
|
-
this[offset + 1] = (value >>> 8)
|
4196
|
-
this[offset] = (value & 0xff)
|
4197
|
-
} else {
|
4198
|
-
objectWriteUInt32(this, value, offset, true)
|
4199
|
-
}
|
4200
|
-
return offset + 4
|
4201
|
-
}
|
4202
|
-
|
4203
|
-
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
4204
|
-
value = +value
|
4205
|
-
offset = offset | 0
|
4206
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
|
4207
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
4208
|
-
this[offset] = (value >>> 24)
|
4209
|
-
this[offset + 1] = (value >>> 16)
|
4210
|
-
this[offset + 2] = (value >>> 8)
|
4211
|
-
this[offset + 3] = (value & 0xff)
|
4212
|
-
} else {
|
4213
|
-
objectWriteUInt32(this, value, offset, false)
|
4214
|
-
}
|
4215
|
-
return offset + 4
|
4216
|
-
}
|
4217
|
-
|
4218
|
-
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
4219
|
-
value = +value
|
4220
|
-
offset = offset | 0
|
4221
|
-
if (!noAssert) {
|
4222
|
-
var limit = Math.pow(2, 8 * byteLength - 1)
|
4223
|
-
|
4224
|
-
checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
4225
|
-
}
|
4226
|
-
|
4227
|
-
var i = 0
|
4228
|
-
var mul = 1
|
4229
|
-
var sub = 0
|
4230
|
-
this[offset] = value & 0xFF
|
4231
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
4232
|
-
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
4233
|
-
sub = 1
|
4234
|
-
}
|
4235
|
-
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
4236
|
-
}
|
4237
|
-
|
4238
|
-
return offset + byteLength
|
4239
|
-
}
|
4240
|
-
|
4241
|
-
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
4242
|
-
value = +value
|
4243
|
-
offset = offset | 0
|
4244
|
-
if (!noAssert) {
|
4245
|
-
var limit = Math.pow(2, 8 * byteLength - 1)
|
4246
|
-
|
4247
|
-
checkInt(this, value, offset, byteLength, limit - 1, -limit)
|
4248
|
-
}
|
4249
|
-
|
4250
|
-
var i = byteLength - 1
|
4251
|
-
var mul = 1
|
4252
|
-
var sub = 0
|
4253
|
-
this[offset + i] = value & 0xFF
|
4254
|
-
while (--i >= 0 && (mul *= 0x100)) {
|
4255
|
-
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
4256
|
-
sub = 1
|
4257
|
-
}
|
4258
|
-
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
|
4259
|
-
}
|
4260
|
-
|
4261
|
-
return offset + byteLength
|
4262
|
-
}
|
4263
|
-
|
4264
|
-
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
4265
|
-
value = +value
|
4266
|
-
offset = offset | 0
|
4267
|
-
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
|
4268
|
-
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
|
4269
|
-
if (value < 0) value = 0xff + value + 1
|
4270
|
-
this[offset] = (value & 0xff)
|
4271
|
-
return offset + 1
|
4272
|
-
}
|
4273
|
-
|
4274
|
-
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
4275
|
-
value = +value
|
4276
|
-
offset = offset | 0
|
4277
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
4278
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
4279
|
-
this[offset] = (value & 0xff)
|
4280
|
-
this[offset + 1] = (value >>> 8)
|
4281
|
-
} else {
|
4282
|
-
objectWriteUInt16(this, value, offset, true)
|
4283
|
-
}
|
4284
|
-
return offset + 2
|
4285
|
-
}
|
4286
|
-
|
4287
|
-
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
4288
|
-
value = +value
|
4289
|
-
offset = offset | 0
|
4290
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
|
4291
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
4292
|
-
this[offset] = (value >>> 8)
|
4293
|
-
this[offset + 1] = (value & 0xff)
|
4294
|
-
} else {
|
4295
|
-
objectWriteUInt16(this, value, offset, false)
|
4296
|
-
}
|
4297
|
-
return offset + 2
|
4298
|
-
}
|
4299
|
-
|
4300
|
-
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
4301
|
-
value = +value
|
4302
|
-
offset = offset | 0
|
4303
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
4304
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
4305
|
-
this[offset] = (value & 0xff)
|
4306
|
-
this[offset + 1] = (value >>> 8)
|
4307
|
-
this[offset + 2] = (value >>> 16)
|
4308
|
-
this[offset + 3] = (value >>> 24)
|
4309
|
-
} else {
|
4310
|
-
objectWriteUInt32(this, value, offset, true)
|
4311
|
-
}
|
4312
|
-
return offset + 4
|
4313
|
-
}
|
4314
|
-
|
4315
|
-
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
4316
|
-
value = +value
|
4317
|
-
offset = offset | 0
|
4318
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
|
4319
|
-
if (value < 0) value = 0xffffffff + value + 1
|
4320
|
-
if (Buffer.TYPED_ARRAY_SUPPORT) {
|
4321
|
-
this[offset] = (value >>> 24)
|
4322
|
-
this[offset + 1] = (value >>> 16)
|
4323
|
-
this[offset + 2] = (value >>> 8)
|
4324
|
-
this[offset + 3] = (value & 0xff)
|
4325
|
-
} else {
|
4326
|
-
objectWriteUInt32(this, value, offset, false)
|
4327
|
-
}
|
4328
|
-
return offset + 4
|
4329
|
-
}
|
4330
|
-
|
4331
|
-
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
4332
|
-
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
4333
|
-
if (offset < 0) throw new RangeError('Index out of range')
|
4334
|
-
}
|
4335
|
-
|
4336
|
-
function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
4337
|
-
if (!noAssert) {
|
4338
|
-
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
|
4339
|
-
}
|
4340
|
-
ieee754.write(buf, value, offset, littleEndian, 23, 4)
|
4341
|
-
return offset + 4
|
4342
|
-
}
|
4343
|
-
|
4344
|
-
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
4345
|
-
return writeFloat(this, value, offset, true, noAssert)
|
4346
|
-
}
|
4347
|
-
|
4348
|
-
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
4349
|
-
return writeFloat(this, value, offset, false, noAssert)
|
4350
|
-
}
|
4351
|
-
|
4352
|
-
function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
4353
|
-
if (!noAssert) {
|
4354
|
-
checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
|
4355
|
-
}
|
4356
|
-
ieee754.write(buf, value, offset, littleEndian, 52, 8)
|
4357
|
-
return offset + 8
|
4358
|
-
}
|
4359
|
-
|
4360
|
-
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
4361
|
-
return writeDouble(this, value, offset, true, noAssert)
|
4362
|
-
}
|
4363
|
-
|
4364
|
-
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
4365
|
-
return writeDouble(this, value, offset, false, noAssert)
|
4366
|
-
}
|
4367
|
-
|
4368
|
-
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
4369
|
-
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
4370
|
-
if (!start) start = 0
|
4371
|
-
if (!end && end !== 0) end = this.length
|
4372
|
-
if (targetStart >= target.length) targetStart = target.length
|
4373
|
-
if (!targetStart) targetStart = 0
|
4374
|
-
if (end > 0 && end < start) end = start
|
4375
|
-
|
4376
|
-
// Copy 0 bytes; we're done
|
4377
|
-
if (end === start) return 0
|
4378
|
-
if (target.length === 0 || this.length === 0) return 0
|
4379
|
-
|
4380
|
-
// Fatal error conditions
|
4381
|
-
if (targetStart < 0) {
|
4382
|
-
throw new RangeError('targetStart out of bounds')
|
4383
|
-
}
|
4384
|
-
if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
|
4385
|
-
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
4386
|
-
|
4387
|
-
// Are we oob?
|
4388
|
-
if (end > this.length) end = this.length
|
4389
|
-
if (target.length - targetStart < end - start) {
|
4390
|
-
end = target.length - targetStart + start
|
4391
|
-
}
|
4392
|
-
|
4393
|
-
var len = end - start
|
4394
|
-
var i
|
4395
|
-
|
4396
|
-
if (this === target && start < targetStart && targetStart < end) {
|
4397
|
-
// descending copy from end
|
4398
|
-
for (i = len - 1; i >= 0; --i) {
|
4399
|
-
target[i + targetStart] = this[i + start]
|
4400
|
-
}
|
4401
|
-
} else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
|
4402
|
-
// ascending copy from start
|
4403
|
-
for (i = 0; i < len; ++i) {
|
4404
|
-
target[i + targetStart] = this[i + start]
|
4405
|
-
}
|
4406
|
-
} else {
|
4407
|
-
Uint8Array.prototype.set.call(
|
4408
|
-
target,
|
4409
|
-
this.subarray(start, start + len),
|
4410
|
-
targetStart
|
4411
|
-
)
|
4412
|
-
}
|
4413
|
-
|
4414
|
-
return len
|
4415
|
-
}
|
4416
|
-
|
4417
|
-
// Usage:
|
4418
|
-
// buffer.fill(number[, offset[, end]])
|
4419
|
-
// buffer.fill(buffer[, offset[, end]])
|
4420
|
-
// buffer.fill(string[, offset[, end]][, encoding])
|
4421
|
-
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
4422
|
-
// Handle string cases:
|
4423
|
-
if (typeof val === 'string') {
|
4424
|
-
if (typeof start === 'string') {
|
4425
|
-
encoding = start
|
4426
|
-
start = 0
|
4427
|
-
end = this.length
|
4428
|
-
} else if (typeof end === 'string') {
|
4429
|
-
encoding = end
|
4430
|
-
end = this.length
|
4431
|
-
}
|
4432
|
-
if (val.length === 1) {
|
4433
|
-
var code = val.charCodeAt(0)
|
4434
|
-
if (code < 256) {
|
4435
|
-
val = code
|
4436
|
-
}
|
4437
|
-
}
|
4438
|
-
if (encoding !== undefined && typeof encoding !== 'string') {
|
4439
|
-
throw new TypeError('encoding must be a string')
|
4440
|
-
}
|
4441
|
-
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
4442
|
-
throw new TypeError('Unknown encoding: ' + encoding)
|
4443
|
-
}
|
4444
|
-
} else if (typeof val === 'number') {
|
4445
|
-
val = val & 255
|
4446
|
-
}
|
4447
|
-
|
4448
|
-
// Invalid ranges are not set to a default, so can range check early.
|
4449
|
-
if (start < 0 || this.length < start || this.length < end) {
|
4450
|
-
throw new RangeError('Out of range index')
|
4451
|
-
}
|
4452
|
-
|
4453
|
-
if (end <= start) {
|
4454
|
-
return this
|
4455
|
-
}
|
4456
|
-
|
4457
|
-
start = start >>> 0
|
4458
|
-
end = end === undefined ? this.length : end >>> 0
|
4459
|
-
|
4460
|
-
if (!val) val = 0
|
4461
|
-
|
4462
|
-
var i
|
4463
|
-
if (typeof val === 'number') {
|
4464
|
-
for (i = start; i < end; ++i) {
|
4465
|
-
this[i] = val
|
4466
|
-
}
|
4467
|
-
} else {
|
4468
|
-
var bytes = Buffer.isBuffer(val)
|
4469
|
-
? val
|
4470
|
-
: utf8ToBytes(new Buffer(val, encoding).toString())
|
4471
|
-
var len = bytes.length
|
4472
|
-
for (i = 0; i < end - start; ++i) {
|
4473
|
-
this[i + start] = bytes[i % len]
|
4474
|
-
}
|
4475
|
-
}
|
4476
|
-
|
4477
|
-
return this
|
4478
|
-
}
|
4479
|
-
|
4480
|
-
// HELPER FUNCTIONS
|
4481
|
-
// ================
|
4482
|
-
|
4483
|
-
var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
|
4484
|
-
|
4485
|
-
function base64clean (str) {
|
4486
|
-
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
4487
|
-
str = stringtrim(str).replace(INVALID_BASE64_RE, '')
|
4488
|
-
// Node converts strings with length < 2 to ''
|
4489
|
-
if (str.length < 2) return ''
|
4490
|
-
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
4491
|
-
while (str.length % 4 !== 0) {
|
4492
|
-
str = str + '='
|
4493
|
-
}
|
4494
|
-
return str
|
4495
|
-
}
|
4496
|
-
|
4497
|
-
function stringtrim (str) {
|
4498
|
-
if (str.trim) return str.trim()
|
4499
|
-
return str.replace(/^\s+|\s+$/g, '')
|
4500
|
-
}
|
4501
|
-
|
4502
|
-
function toHex (n) {
|
4503
|
-
if (n < 16) return '0' + n.toString(16)
|
4504
|
-
return n.toString(16)
|
4505
|
-
}
|
4506
|
-
|
4507
|
-
function utf8ToBytes (string, units) {
|
4508
|
-
units = units || Infinity
|
4509
|
-
var codePoint
|
4510
|
-
var length = string.length
|
4511
|
-
var leadSurrogate = null
|
4512
|
-
var bytes = []
|
4513
|
-
|
4514
|
-
for (var i = 0; i < length; ++i) {
|
4515
|
-
codePoint = string.charCodeAt(i)
|
4516
|
-
|
4517
|
-
// is surrogate component
|
4518
|
-
if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
4519
|
-
// last char was a lead
|
4520
|
-
if (!leadSurrogate) {
|
4521
|
-
// no lead yet
|
4522
|
-
if (codePoint > 0xDBFF) {
|
4523
|
-
// unexpected trail
|
4524
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
4525
|
-
continue
|
4526
|
-
} else if (i + 1 === length) {
|
4527
|
-
// unpaired lead
|
4528
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
4529
|
-
continue
|
4530
|
-
}
|
4531
|
-
|
4532
|
-
// valid lead
|
4533
|
-
leadSurrogate = codePoint
|
4534
|
-
|
4535
|
-
continue
|
4536
|
-
}
|
4537
|
-
|
4538
|
-
// 2 leads in a row
|
4539
|
-
if (codePoint < 0xDC00) {
|
4540
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
4541
|
-
leadSurrogate = codePoint
|
4542
|
-
continue
|
4543
|
-
}
|
4544
|
-
|
4545
|
-
// valid surrogate pair
|
4546
|
-
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
|
4547
|
-
} else if (leadSurrogate) {
|
4548
|
-
// valid bmp char, but last char was a lead
|
4549
|
-
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
|
4550
|
-
}
|
4551
|
-
|
4552
|
-
leadSurrogate = null
|
4553
|
-
|
4554
|
-
// encode utf8
|
4555
|
-
if (codePoint < 0x80) {
|
4556
|
-
if ((units -= 1) < 0) break
|
4557
|
-
bytes.push(codePoint)
|
4558
|
-
} else if (codePoint < 0x800) {
|
4559
|
-
if ((units -= 2) < 0) break
|
4560
|
-
bytes.push(
|
4561
|
-
codePoint >> 0x6 | 0xC0,
|
4562
|
-
codePoint & 0x3F | 0x80
|
4563
|
-
)
|
4564
|
-
} else if (codePoint < 0x10000) {
|
4565
|
-
if ((units -= 3) < 0) break
|
4566
|
-
bytes.push(
|
4567
|
-
codePoint >> 0xC | 0xE0,
|
4568
|
-
codePoint >> 0x6 & 0x3F | 0x80,
|
4569
|
-
codePoint & 0x3F | 0x80
|
4570
|
-
)
|
4571
|
-
} else if (codePoint < 0x110000) {
|
4572
|
-
if ((units -= 4) < 0) break
|
4573
|
-
bytes.push(
|
4574
|
-
codePoint >> 0x12 | 0xF0,
|
4575
|
-
codePoint >> 0xC & 0x3F | 0x80,
|
4576
|
-
codePoint >> 0x6 & 0x3F | 0x80,
|
4577
|
-
codePoint & 0x3F | 0x80
|
4578
|
-
)
|
4579
|
-
} else {
|
4580
|
-
throw new Error('Invalid code point')
|
4581
|
-
}
|
4582
|
-
}
|
4583
|
-
|
4584
|
-
return bytes
|
4585
|
-
}
|
4586
|
-
|
4587
|
-
function asciiToBytes (str) {
|
4588
|
-
var byteArray = []
|
4589
|
-
for (var i = 0; i < str.length; ++i) {
|
4590
|
-
// Node's code seems to be doing this and not & 0x7F..
|
4591
|
-
byteArray.push(str.charCodeAt(i) & 0xFF)
|
4592
|
-
}
|
4593
|
-
return byteArray
|
4594
|
-
}
|
4595
|
-
|
4596
|
-
function utf16leToBytes (str, units) {
|
4597
|
-
var c, hi, lo
|
4598
|
-
var byteArray = []
|
4599
|
-
for (var i = 0; i < str.length; ++i) {
|
4600
|
-
if ((units -= 2) < 0) break
|
4601
|
-
|
4602
|
-
c = str.charCodeAt(i)
|
4603
|
-
hi = c >> 8
|
4604
|
-
lo = c % 256
|
4605
|
-
byteArray.push(lo)
|
4606
|
-
byteArray.push(hi)
|
4607
|
-
}
|
4608
|
-
|
4609
|
-
return byteArray
|
4610
|
-
}
|
4611
|
-
|
4612
|
-
function base64ToBytes (str) {
|
4613
|
-
return base64.toByteArray(base64clean(str))
|
4614
|
-
}
|
4615
|
-
|
4616
|
-
function blitBuffer (src, dst, offset, length) {
|
4617
|
-
for (var i = 0; i < length; ++i) {
|
4618
|
-
if ((i + offset >= dst.length) || (i >= src.length)) break
|
4619
|
-
dst[i + offset] = src[i]
|
4620
|
-
}
|
4621
|
-
return i
|
4622
|
-
}
|
4623
|
-
|
4624
|
-
function isnan (val) {
|
4625
|
-
return val !== val // eslint-disable-line no-self-compare
|
4626
|
-
}
|
4627
|
-
|
4628
|
-
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js")))
|
4629
|
-
|
4630
|
-
/***/ }),
|
4631
|
-
|
4632
|
-
/***/ "./node_modules/node-libs-browser/node_modules/isarray/index.js":
|
4633
|
-
/*!**********************************************************************!*\
|
4634
|
-
!*** ./node_modules/node-libs-browser/node_modules/isarray/index.js ***!
|
4635
|
-
\**********************************************************************/
|
4636
|
-
/*! no static exports found */
|
4637
|
-
/***/ (function(module, exports) {
|
4638
|
-
|
4639
|
-
var toString = {}.toString;
|
4640
|
-
|
4641
|
-
module.exports = Array.isArray || function (arr) {
|
4642
|
-
return toString.call(arr) == '[object Array]';
|
4643
|
-
};
|
4644
|
-
|
4645
|
-
|
4646
|
-
/***/ }),
|
4647
|
-
|
4648
|
-
/***/ "./node_modules/webpack/buildin/global.js":
|
4649
|
-
/*!***********************************!*\
|
4650
|
-
!*** (webpack)/buildin/global.js ***!
|
4651
|
-
\***********************************/
|
4652
|
-
/*! no static exports found */
|
4653
|
-
/***/ (function(module, exports) {
|
4654
|
-
|
4655
|
-
var g;
|
4656
|
-
|
4657
|
-
// This works in non-strict mode
|
4658
|
-
g = (function() {
|
4659
|
-
return this;
|
4660
|
-
})();
|
4661
|
-
|
4662
|
-
try {
|
4663
|
-
// This works if eval is allowed (see CSP)
|
4664
|
-
g = g || new Function("return this")();
|
4665
|
-
} catch (e) {
|
4666
|
-
// This works if the window reference is available
|
4667
|
-
if (typeof window === "object") g = window;
|
4668
|
-
}
|
4669
|
-
|
4670
|
-
// g can still be undefined, but nothing to do about it...
|
4671
|
-
// We return undefined, instead of nothing here, so it's
|
4672
|
-
// easier to handle this case. if(!global) { ...}
|
4673
|
-
|
4674
|
-
module.exports = g;
|
4675
|
-
|
4676
|
-
|
4677
2591
|
/***/ })
|
4678
2592
|
|
4679
2593
|
/******/ });
|