@neurosity/sdk 6.4.1 → 6.5.0
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/dist/browser/neurosity.iife.js +2579 -102
- package/dist/browser/neurosity.js +129 -113
- package/dist/browser/neurosity.js.map +1 -1
- package/dist/cjs/api/bluetooth/BluetoothClient.d.ts +1 -1
- package/dist/cjs/api/bluetooth/BluetoothClient.js +10 -8
- package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.d.ts +3 -1
- package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.js +17 -17
- package/dist/cjs/api/bluetooth/types/index.d.ts +1 -0
- package/dist/cjs/api/bluetooth/utils/binaryBufferToEpoch.d.ts +51 -0
- package/dist/cjs/api/bluetooth/utils/binaryBufferToEpoch.js +116 -0
- package/dist/cjs/api/bluetooth/utils/decodeJSONChunks.d.ts +15 -0
- package/dist/cjs/api/bluetooth/utils/decodeJSONChunks.js +25 -0
- package/dist/cjs/api/bluetooth/utils/textCodec.d.ts +17 -0
- package/dist/cjs/api/bluetooth/utils/textCodec.js +40 -0
- package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.d.ts +3 -1
- package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.js +19 -34
- package/dist/electron/index.js +15 -13
- package/dist/electron/index.js.map +1 -1
- package/dist/esm/api/bluetooth/BluetoothClient.d.ts +1 -1
- package/dist/esm/api/bluetooth/BluetoothClient.js +10 -8
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.d.ts +3 -1
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.js +18 -18
- package/dist/esm/api/bluetooth/types/index.d.ts +1 -0
- package/dist/esm/api/bluetooth/utils/binaryBufferToEpoch.d.ts +51 -0
- package/dist/esm/api/bluetooth/utils/binaryBufferToEpoch.js +109 -0
- package/dist/esm/api/bluetooth/utils/decodeJSONChunks.d.ts +15 -0
- package/dist/esm/api/bluetooth/utils/decodeJSONChunks.js +21 -0
- package/dist/esm/api/bluetooth/utils/textCodec.d.ts +17 -0
- package/dist/esm/api/bluetooth/utils/textCodec.js +36 -0
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.d.ts +3 -1
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.js +20 -35
- package/dist/esm/neurosity.mjs +2579 -102
- package/dist/examples/neurosity.iife.js +2579 -102
- package/dist/examples/neurosity.js +129 -113
- package/dist/examples/neurosity.mjs +2579 -102
- package/package.json +2 -1
- package/dist/cjs/api/bluetooth/utils/encoding.d.ts +0 -3
- package/dist/cjs/api/bluetooth/utils/encoding.js +0 -22
- package/dist/esm/api/bluetooth/utils/encoding.d.ts +0 -3
- package/dist/esm/api/bluetooth/utils/encoding.js +0 -17
package/dist/esm/neurosity.mjs
CHANGED
|
@@ -2771,7 +2771,7 @@ var fastDeepEqual = function equal(a, b) {
|
|
|
2771
2771
|
return a!==a && b!==b;
|
|
2772
2772
|
};
|
|
2773
2773
|
|
|
2774
|
-
|
|
2774
|
+
/******************************************************************************
|
|
2775
2775
|
Copyright (c) Microsoft Corporation.
|
|
2776
2776
|
|
|
2777
2777
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -2797,7 +2797,7 @@ var __assign$1 = function() {
|
|
|
2797
2797
|
return __assign$1.apply(this, arguments);
|
|
2798
2798
|
};
|
|
2799
2799
|
|
|
2800
|
-
|
|
2800
|
+
/******************************************************************************
|
|
2801
2801
|
Copyright (c) Microsoft Corporation.
|
|
2802
2802
|
|
|
2803
2803
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -4399,7 +4399,7 @@ function getModularInstance(service) {
|
|
|
4399
4399
|
}
|
|
4400
4400
|
}
|
|
4401
4401
|
|
|
4402
|
-
|
|
4402
|
+
/******************************************************************************
|
|
4403
4403
|
Copyright (c) Microsoft Corporation.
|
|
4404
4404
|
|
|
4405
4405
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -4430,7 +4430,7 @@ function __generator$3(thisArg, body) {
|
|
|
4430
4430
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
4431
4431
|
function step(op) {
|
|
4432
4432
|
if (f) throw new TypeError("Generator is already executing.");
|
|
4433
|
-
while (_) try {
|
|
4433
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
4434
4434
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
4435
4435
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
4436
4436
|
switch (op[0]) {
|
|
@@ -5909,7 +5909,7 @@ var version$2 = "8.10.0";
|
|
|
5909
5909
|
firebase.registerVersion(name$d, version$2, 'app');
|
|
5910
5910
|
firebase.SDK_VERSION = version$2;
|
|
5911
5911
|
|
|
5912
|
-
|
|
5912
|
+
/******************************************************************************
|
|
5913
5913
|
Copyright (c) Microsoft Corporation.
|
|
5914
5914
|
|
|
5915
5915
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -5967,7 +5967,7 @@ function __generator$4(thisArg, body) {
|
|
|
5967
5967
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
5968
5968
|
function step(op) {
|
|
5969
5969
|
if (f) throw new TypeError("Generator is already executing.");
|
|
5970
|
-
while (_) try {
|
|
5970
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
5971
5971
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
5972
5972
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
5973
5973
|
switch (op[0]) {
|
|
@@ -21721,7 +21721,7 @@ Z(a,"OAuthProvider",Pg,[V("providerId")]);Z(a,"SAMLAuthProvider",Og,[V("provider
|
|
|
21721
21721
|
firebase.INTERNAL.registerComponent({name:"auth-internal",instanceFactory:function(b){b=b.getProvider("auth").getImmediate();return {getUid:q(b.getUid,b),getToken:q(b.nc,b),addAuthTokenListener:q(b.cc,b),removeAuthTokenListener:q(b.Pc,b)}},multipleInstances:!1,instantiationMode:"LAZY",type:"PRIVATE"});firebase.registerVersion("@firebase/auth","0.16.8");firebase.INTERNAL.extendNamespace({User:Im});}else throw Error("Cannot find the firebase namespace; be sure to include firebase-app.js before this library.");
|
|
21722
21722
|
})();}).apply(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : {});
|
|
21723
21723
|
|
|
21724
|
-
|
|
21724
|
+
/******************************************************************************
|
|
21725
21725
|
Copyright (c) Microsoft Corporation.
|
|
21726
21726
|
|
|
21727
21727
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -21768,7 +21768,7 @@ function __generator$5(thisArg, body) {
|
|
|
21768
21768
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21769
21769
|
function step(op) {
|
|
21770
21770
|
if (f) throw new TypeError("Generator is already executing.");
|
|
21771
|
-
while (_) try {
|
|
21771
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
21772
21772
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
21773
21773
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21774
21774
|
switch (op[0]) {
|
|
@@ -22490,7 +22490,7 @@ var version$4 = "0.6.15";
|
|
|
22490
22490
|
registerFunctions(firebase, fetch.bind(self));
|
|
22491
22491
|
firebase.registerVersion(name$f, version$4);
|
|
22492
22492
|
|
|
22493
|
-
|
|
22493
|
+
/******************************************************************************
|
|
22494
22494
|
Copyright (c) Microsoft Corporation.
|
|
22495
22495
|
|
|
22496
22496
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -22537,7 +22537,7 @@ function __generator$6(thisArg, body) {
|
|
|
22537
22537
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
22538
22538
|
function step(op) {
|
|
22539
22539
|
if (f) throw new TypeError("Generator is already executing.");
|
|
22540
|
-
while (_) try {
|
|
22540
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
22541
22541
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
22542
22542
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
22543
22543
|
switch (op[0]) {
|
|
@@ -45691,23 +45691,2385 @@ function create6DigitPin() {
|
|
|
45691
45691
|
return Math.floor(100000 + Math.random() * 900000);
|
|
45692
45692
|
}
|
|
45693
45693
|
|
|
45694
|
-
function
|
|
45695
|
-
|
|
45696
|
-
|
|
45697
|
-
|
|
45698
|
-
|
|
45694
|
+
function createCommonjsModule(fn, module) {
|
|
45695
|
+
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
45696
|
+
}
|
|
45697
|
+
|
|
45698
|
+
var byteLength_1 = byteLength;
|
|
45699
|
+
var toByteArray_1 = toByteArray;
|
|
45700
|
+
var fromByteArray_1 = fromByteArray;
|
|
45701
|
+
|
|
45702
|
+
var lookup = [];
|
|
45703
|
+
var revLookup = [];
|
|
45704
|
+
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
|
|
45705
|
+
|
|
45706
|
+
var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
45707
|
+
for (var i = 0, len = code.length; i < len; ++i) {
|
|
45708
|
+
lookup[i] = code[i];
|
|
45709
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
45710
|
+
}
|
|
45711
|
+
|
|
45712
|
+
// Support decoding URL-safe base64 strings, as Node.js does.
|
|
45713
|
+
// See: https://en.wikipedia.org/wiki/Base64#URL_applications
|
|
45714
|
+
revLookup['-'.charCodeAt(0)] = 62;
|
|
45715
|
+
revLookup['_'.charCodeAt(0)] = 63;
|
|
45716
|
+
|
|
45717
|
+
function getLens (b64) {
|
|
45718
|
+
var len = b64.length;
|
|
45719
|
+
|
|
45720
|
+
if (len % 4 > 0) {
|
|
45721
|
+
throw new Error('Invalid string. Length must be a multiple of 4')
|
|
45722
|
+
}
|
|
45723
|
+
|
|
45724
|
+
// Trim off extra bytes after placeholder bytes are found
|
|
45725
|
+
// See: https://github.com/beatgammit/base64-js/issues/42
|
|
45726
|
+
var validLen = b64.indexOf('=');
|
|
45727
|
+
if (validLen === -1) validLen = len;
|
|
45728
|
+
|
|
45729
|
+
var placeHoldersLen = validLen === len
|
|
45730
|
+
? 0
|
|
45731
|
+
: 4 - (validLen % 4);
|
|
45732
|
+
|
|
45733
|
+
return [validLen, placeHoldersLen]
|
|
45734
|
+
}
|
|
45735
|
+
|
|
45736
|
+
// base64 is 4/3 + up to two characters of the original data
|
|
45737
|
+
function byteLength (b64) {
|
|
45738
|
+
var lens = getLens(b64);
|
|
45739
|
+
var validLen = lens[0];
|
|
45740
|
+
var placeHoldersLen = lens[1];
|
|
45741
|
+
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
|
45742
|
+
}
|
|
45743
|
+
|
|
45744
|
+
function _byteLength (b64, validLen, placeHoldersLen) {
|
|
45745
|
+
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
|
|
45746
|
+
}
|
|
45747
|
+
|
|
45748
|
+
function toByteArray (b64) {
|
|
45749
|
+
var tmp;
|
|
45750
|
+
var lens = getLens(b64);
|
|
45751
|
+
var validLen = lens[0];
|
|
45752
|
+
var placeHoldersLen = lens[1];
|
|
45753
|
+
|
|
45754
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
45755
|
+
|
|
45756
|
+
var curByte = 0;
|
|
45757
|
+
|
|
45758
|
+
// if there are placeholders, only get up to the last complete 4 chars
|
|
45759
|
+
var len = placeHoldersLen > 0
|
|
45760
|
+
? validLen - 4
|
|
45761
|
+
: validLen;
|
|
45762
|
+
|
|
45763
|
+
var i;
|
|
45764
|
+
for (i = 0; i < len; i += 4) {
|
|
45765
|
+
tmp =
|
|
45766
|
+
(revLookup[b64.charCodeAt(i)] << 18) |
|
|
45767
|
+
(revLookup[b64.charCodeAt(i + 1)] << 12) |
|
|
45768
|
+
(revLookup[b64.charCodeAt(i + 2)] << 6) |
|
|
45769
|
+
revLookup[b64.charCodeAt(i + 3)];
|
|
45770
|
+
arr[curByte++] = (tmp >> 16) & 0xFF;
|
|
45771
|
+
arr[curByte++] = (tmp >> 8) & 0xFF;
|
|
45772
|
+
arr[curByte++] = tmp & 0xFF;
|
|
45773
|
+
}
|
|
45774
|
+
|
|
45775
|
+
if (placeHoldersLen === 2) {
|
|
45776
|
+
tmp =
|
|
45777
|
+
(revLookup[b64.charCodeAt(i)] << 2) |
|
|
45778
|
+
(revLookup[b64.charCodeAt(i + 1)] >> 4);
|
|
45779
|
+
arr[curByte++] = tmp & 0xFF;
|
|
45780
|
+
}
|
|
45781
|
+
|
|
45782
|
+
if (placeHoldersLen === 1) {
|
|
45783
|
+
tmp =
|
|
45784
|
+
(revLookup[b64.charCodeAt(i)] << 10) |
|
|
45785
|
+
(revLookup[b64.charCodeAt(i + 1)] << 4) |
|
|
45786
|
+
(revLookup[b64.charCodeAt(i + 2)] >> 2);
|
|
45787
|
+
arr[curByte++] = (tmp >> 8) & 0xFF;
|
|
45788
|
+
arr[curByte++] = tmp & 0xFF;
|
|
45789
|
+
}
|
|
45790
|
+
|
|
45791
|
+
return arr
|
|
45792
|
+
}
|
|
45793
|
+
|
|
45794
|
+
function tripletToBase64 (num) {
|
|
45795
|
+
return lookup[num >> 18 & 0x3F] +
|
|
45796
|
+
lookup[num >> 12 & 0x3F] +
|
|
45797
|
+
lookup[num >> 6 & 0x3F] +
|
|
45798
|
+
lookup[num & 0x3F]
|
|
45799
|
+
}
|
|
45800
|
+
|
|
45801
|
+
function encodeChunk (uint8, start, end) {
|
|
45802
|
+
var tmp;
|
|
45803
|
+
var output = [];
|
|
45804
|
+
for (var i = start; i < end; i += 3) {
|
|
45805
|
+
tmp =
|
|
45806
|
+
((uint8[i] << 16) & 0xFF0000) +
|
|
45807
|
+
((uint8[i + 1] << 8) & 0xFF00) +
|
|
45808
|
+
(uint8[i + 2] & 0xFF);
|
|
45809
|
+
output.push(tripletToBase64(tmp));
|
|
45810
|
+
}
|
|
45811
|
+
return output.join('')
|
|
45812
|
+
}
|
|
45813
|
+
|
|
45814
|
+
function fromByteArray (uint8) {
|
|
45815
|
+
var tmp;
|
|
45816
|
+
var len = uint8.length;
|
|
45817
|
+
var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
|
|
45818
|
+
var parts = [];
|
|
45819
|
+
var maxChunkLength = 16383; // must be multiple of 3
|
|
45820
|
+
|
|
45821
|
+
// go through the array every three bytes, we'll deal with trailing stuff later
|
|
45822
|
+
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
|
45823
|
+
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
|
|
45824
|
+
}
|
|
45825
|
+
|
|
45826
|
+
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
45827
|
+
if (extraBytes === 1) {
|
|
45828
|
+
tmp = uint8[len - 1];
|
|
45829
|
+
parts.push(
|
|
45830
|
+
lookup[tmp >> 2] +
|
|
45831
|
+
lookup[(tmp << 4) & 0x3F] +
|
|
45832
|
+
'=='
|
|
45833
|
+
);
|
|
45834
|
+
} else if (extraBytes === 2) {
|
|
45835
|
+
tmp = (uint8[len - 2] << 8) + uint8[len - 1];
|
|
45836
|
+
parts.push(
|
|
45837
|
+
lookup[tmp >> 10] +
|
|
45838
|
+
lookup[(tmp >> 4) & 0x3F] +
|
|
45839
|
+
lookup[(tmp << 2) & 0x3F] +
|
|
45840
|
+
'='
|
|
45841
|
+
);
|
|
45842
|
+
}
|
|
45843
|
+
|
|
45844
|
+
return parts.join('')
|
|
45845
|
+
}
|
|
45846
|
+
|
|
45847
|
+
var base64Js = {
|
|
45848
|
+
byteLength: byteLength_1,
|
|
45849
|
+
toByteArray: toByteArray_1,
|
|
45850
|
+
fromByteArray: fromByteArray_1
|
|
45851
|
+
};
|
|
45852
|
+
|
|
45853
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
45854
|
+
var read = function (buffer, offset, isLE, mLen, nBytes) {
|
|
45855
|
+
var e, m;
|
|
45856
|
+
var eLen = (nBytes * 8) - mLen - 1;
|
|
45857
|
+
var eMax = (1 << eLen) - 1;
|
|
45858
|
+
var eBias = eMax >> 1;
|
|
45859
|
+
var nBits = -7;
|
|
45860
|
+
var i = isLE ? (nBytes - 1) : 0;
|
|
45861
|
+
var d = isLE ? -1 : 1;
|
|
45862
|
+
var s = buffer[offset + i];
|
|
45863
|
+
|
|
45864
|
+
i += d;
|
|
45865
|
+
|
|
45866
|
+
e = s & ((1 << (-nBits)) - 1);
|
|
45867
|
+
s >>= (-nBits);
|
|
45868
|
+
nBits += eLen;
|
|
45869
|
+
for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
|
45870
|
+
|
|
45871
|
+
m = e & ((1 << (-nBits)) - 1);
|
|
45872
|
+
e >>= (-nBits);
|
|
45873
|
+
nBits += mLen;
|
|
45874
|
+
for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
|
|
45875
|
+
|
|
45876
|
+
if (e === 0) {
|
|
45877
|
+
e = 1 - eBias;
|
|
45878
|
+
} else if (e === eMax) {
|
|
45879
|
+
return m ? NaN : ((s ? -1 : 1) * Infinity)
|
|
45880
|
+
} else {
|
|
45881
|
+
m = m + Math.pow(2, mLen);
|
|
45882
|
+
e = e - eBias;
|
|
45883
|
+
}
|
|
45884
|
+
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
|
|
45885
|
+
};
|
|
45886
|
+
|
|
45887
|
+
var write = function (buffer, value, offset, isLE, mLen, nBytes) {
|
|
45888
|
+
var e, m, c;
|
|
45889
|
+
var eLen = (nBytes * 8) - mLen - 1;
|
|
45890
|
+
var eMax = (1 << eLen) - 1;
|
|
45891
|
+
var eBias = eMax >> 1;
|
|
45892
|
+
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
|
|
45893
|
+
var i = isLE ? 0 : (nBytes - 1);
|
|
45894
|
+
var d = isLE ? 1 : -1;
|
|
45895
|
+
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
|
45896
|
+
|
|
45897
|
+
value = Math.abs(value);
|
|
45898
|
+
|
|
45899
|
+
if (isNaN(value) || value === Infinity) {
|
|
45900
|
+
m = isNaN(value) ? 1 : 0;
|
|
45901
|
+
e = eMax;
|
|
45902
|
+
} else {
|
|
45903
|
+
e = Math.floor(Math.log(value) / Math.LN2);
|
|
45904
|
+
if (value * (c = Math.pow(2, -e)) < 1) {
|
|
45905
|
+
e--;
|
|
45906
|
+
c *= 2;
|
|
45907
|
+
}
|
|
45908
|
+
if (e + eBias >= 1) {
|
|
45909
|
+
value += rt / c;
|
|
45910
|
+
} else {
|
|
45911
|
+
value += rt * Math.pow(2, 1 - eBias);
|
|
45912
|
+
}
|
|
45913
|
+
if (value * c >= 2) {
|
|
45914
|
+
e++;
|
|
45915
|
+
c /= 2;
|
|
45916
|
+
}
|
|
45917
|
+
|
|
45918
|
+
if (e + eBias >= eMax) {
|
|
45919
|
+
m = 0;
|
|
45920
|
+
e = eMax;
|
|
45921
|
+
} else if (e + eBias >= 1) {
|
|
45922
|
+
m = ((value * c) - 1) * Math.pow(2, mLen);
|
|
45923
|
+
e = e + eBias;
|
|
45924
|
+
} else {
|
|
45925
|
+
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
|
45926
|
+
e = 0;
|
|
45927
|
+
}
|
|
45928
|
+
}
|
|
45929
|
+
|
|
45930
|
+
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
|
45931
|
+
|
|
45932
|
+
e = (e << mLen) | m;
|
|
45933
|
+
eLen += mLen;
|
|
45934
|
+
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
|
45935
|
+
|
|
45936
|
+
buffer[offset + i - d] |= s * 128;
|
|
45937
|
+
};
|
|
45938
|
+
|
|
45939
|
+
var ieee754 = {
|
|
45940
|
+
read: read,
|
|
45941
|
+
write: write
|
|
45942
|
+
};
|
|
45943
|
+
|
|
45944
|
+
var buffer$1 = createCommonjsModule(function (module, exports) {
|
|
45945
|
+
/*!
|
|
45946
|
+
* The buffer module from node.js, for the browser.
|
|
45947
|
+
*
|
|
45948
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
45949
|
+
* @license MIT
|
|
45950
|
+
*/
|
|
45951
|
+
/* eslint-disable no-proto */
|
|
45952
|
+
|
|
45953
|
+
console.log("********* buffer start *********");
|
|
45954
|
+
|
|
45955
|
+
|
|
45956
|
+
|
|
45957
|
+
const customInspectSymbol =
|
|
45958
|
+
(typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
|
|
45959
|
+
? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
|
|
45960
|
+
: null;
|
|
45961
|
+
|
|
45962
|
+
exports.Buffer = Buffer;
|
|
45963
|
+
exports.SlowBuffer = SlowBuffer;
|
|
45964
|
+
exports.INSPECT_MAX_BYTES = 50;
|
|
45965
|
+
|
|
45966
|
+
const K_MAX_LENGTH = 0x7fffffff;
|
|
45967
|
+
exports.kMaxLength = K_MAX_LENGTH;
|
|
45968
|
+
|
|
45969
|
+
/**
|
|
45970
|
+
* If `Buffer.TYPED_ARRAY_SUPPORT`:
|
|
45971
|
+
* === true Use Uint8Array implementation (fastest)
|
|
45972
|
+
* === false Print warning and recommend using `buffer` v4.x which has an Object
|
|
45973
|
+
* implementation (most compatible, even IE6)
|
|
45974
|
+
*
|
|
45975
|
+
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
|
|
45976
|
+
* Opera 11.6+, iOS 4.2+.
|
|
45977
|
+
*
|
|
45978
|
+
* We report that the browser does not support typed arrays if the are not subclassable
|
|
45979
|
+
* using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
|
|
45980
|
+
* (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
|
|
45981
|
+
* for __proto__ and has a buggy typed array implementation.
|
|
45982
|
+
*/
|
|
45983
|
+
Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
|
|
45984
|
+
|
|
45985
|
+
if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
|
|
45986
|
+
typeof console.error === 'function') {
|
|
45987
|
+
console.error(
|
|
45988
|
+
'This browser lacks typed array (Uint8Array) support which is required by ' +
|
|
45989
|
+
'`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
|
|
45990
|
+
);
|
|
45991
|
+
}
|
|
45992
|
+
|
|
45993
|
+
function typedArraySupport () {
|
|
45994
|
+
// Can typed array instances can be augmented?
|
|
45995
|
+
try {
|
|
45996
|
+
const arr = new Uint8Array(1);
|
|
45997
|
+
const proto = { foo: function () { return 42 } };
|
|
45998
|
+
Object.setPrototypeOf(proto, Uint8Array.prototype);
|
|
45999
|
+
Object.setPrototypeOf(arr, proto);
|
|
46000
|
+
return arr.foo() === 42
|
|
46001
|
+
} catch (e) {
|
|
46002
|
+
return false
|
|
46003
|
+
}
|
|
46004
|
+
}
|
|
46005
|
+
|
|
46006
|
+
Object.defineProperty(Buffer.prototype, 'parent', {
|
|
46007
|
+
enumerable: true,
|
|
46008
|
+
get: function () {
|
|
46009
|
+
if (!Buffer.isBuffer(this)) return undefined
|
|
46010
|
+
return this.buffer
|
|
46011
|
+
}
|
|
46012
|
+
});
|
|
46013
|
+
|
|
46014
|
+
Object.defineProperty(Buffer.prototype, 'offset', {
|
|
46015
|
+
enumerable: true,
|
|
46016
|
+
get: function () {
|
|
46017
|
+
if (!Buffer.isBuffer(this)) return undefined
|
|
46018
|
+
return this.byteOffset
|
|
46019
|
+
}
|
|
46020
|
+
});
|
|
46021
|
+
|
|
46022
|
+
function createBuffer (length) {
|
|
46023
|
+
if (length > K_MAX_LENGTH) {
|
|
46024
|
+
throw new RangeError('The value "' + length + '" is invalid for option "size"')
|
|
46025
|
+
}
|
|
46026
|
+
// Return an augmented `Uint8Array` instance
|
|
46027
|
+
const buf = new Uint8Array(length);
|
|
46028
|
+
Object.setPrototypeOf(buf, Buffer.prototype);
|
|
46029
|
+
return buf
|
|
46030
|
+
}
|
|
46031
|
+
|
|
46032
|
+
/**
|
|
46033
|
+
* The Buffer constructor returns instances of `Uint8Array` that have their
|
|
46034
|
+
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
|
46035
|
+
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
|
46036
|
+
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
|
46037
|
+
* returns a single octet.
|
|
46038
|
+
*
|
|
46039
|
+
* The `Uint8Array` prototype remains unmodified.
|
|
46040
|
+
*/
|
|
46041
|
+
|
|
46042
|
+
function Buffer (arg, encodingOrOffset, length) {
|
|
46043
|
+
// Common case.
|
|
46044
|
+
if (typeof arg === 'number') {
|
|
46045
|
+
if (typeof encodingOrOffset === 'string') {
|
|
46046
|
+
throw new TypeError(
|
|
46047
|
+
'The "string" argument must be of type string. Received type number'
|
|
46048
|
+
)
|
|
46049
|
+
}
|
|
46050
|
+
return allocUnsafe(arg)
|
|
46051
|
+
}
|
|
46052
|
+
return from(arg, encodingOrOffset, length)
|
|
46053
|
+
}
|
|
46054
|
+
|
|
46055
|
+
Buffer.poolSize = 8192; // not used by this implementation
|
|
46056
|
+
|
|
46057
|
+
function from (value, encodingOrOffset, length) {
|
|
46058
|
+
if (typeof value === 'string') {
|
|
46059
|
+
return fromString(value, encodingOrOffset)
|
|
46060
|
+
}
|
|
46061
|
+
|
|
46062
|
+
if (ArrayBuffer.isView(value)) {
|
|
46063
|
+
return fromArrayView(value)
|
|
46064
|
+
}
|
|
46065
|
+
|
|
46066
|
+
if (value == null) {
|
|
46067
|
+
throw new TypeError(
|
|
46068
|
+
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
46069
|
+
'or Array-like Object. Received type ' + (typeof value)
|
|
46070
|
+
)
|
|
46071
|
+
}
|
|
46072
|
+
|
|
46073
|
+
if (isInstance(value, ArrayBuffer) ||
|
|
46074
|
+
(value && isInstance(value.buffer, ArrayBuffer))) {
|
|
46075
|
+
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
46076
|
+
}
|
|
46077
|
+
|
|
46078
|
+
if (typeof SharedArrayBuffer !== 'undefined' &&
|
|
46079
|
+
(isInstance(value, SharedArrayBuffer) ||
|
|
46080
|
+
(value && isInstance(value.buffer, SharedArrayBuffer)))) {
|
|
46081
|
+
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
46082
|
+
}
|
|
46083
|
+
|
|
46084
|
+
console.log("********* buffer line 142 *********");
|
|
46085
|
+
|
|
46086
|
+
|
|
46087
|
+
if (typeof value === 'number') {
|
|
46088
|
+
throw new TypeError(
|
|
46089
|
+
'The "value" argument must not be of type number. Received type number'
|
|
46090
|
+
)
|
|
46091
|
+
}
|
|
46092
|
+
|
|
46093
|
+
const valueOf = value.valueOf && value.valueOf();
|
|
46094
|
+
if (valueOf != null && valueOf !== value) {
|
|
46095
|
+
return Buffer.from(valueOf, encodingOrOffset, length)
|
|
46096
|
+
}
|
|
46097
|
+
|
|
46098
|
+
const b = fromObject(value);
|
|
46099
|
+
if (b) return b
|
|
46100
|
+
|
|
46101
|
+
if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
|
|
46102
|
+
typeof value[Symbol.toPrimitive] === 'function') {
|
|
46103
|
+
return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length)
|
|
46104
|
+
}
|
|
46105
|
+
|
|
46106
|
+
throw new TypeError(
|
|
46107
|
+
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
46108
|
+
'or Array-like Object. Received type ' + (typeof value)
|
|
46109
|
+
)
|
|
46110
|
+
}
|
|
46111
|
+
|
|
46112
|
+
/**
|
|
46113
|
+
* Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
|
|
46114
|
+
* if value is a number.
|
|
46115
|
+
* Buffer.from(str[, encoding])
|
|
46116
|
+
* Buffer.from(array)
|
|
46117
|
+
* Buffer.from(buffer)
|
|
46118
|
+
* Buffer.from(arrayBuffer[, byteOffset[, length]])
|
|
46119
|
+
**/
|
|
46120
|
+
Buffer.from = function (value, encodingOrOffset, length) {
|
|
46121
|
+
return from(value, encodingOrOffset, length)
|
|
46122
|
+
};
|
|
46123
|
+
|
|
46124
|
+
// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
|
|
46125
|
+
// https://github.com/feross/buffer/pull/148
|
|
46126
|
+
Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
|
|
46127
|
+
Object.setPrototypeOf(Buffer, Uint8Array);
|
|
46128
|
+
|
|
46129
|
+
function assertSize (size) {
|
|
46130
|
+
if (typeof size !== 'number') {
|
|
46131
|
+
throw new TypeError('"size" argument must be of type number')
|
|
46132
|
+
} else if (size < 0) {
|
|
46133
|
+
throw new RangeError('The value "' + size + '" is invalid for option "size"')
|
|
46134
|
+
}
|
|
46135
|
+
}
|
|
46136
|
+
|
|
46137
|
+
function alloc (size, fill, encoding) {
|
|
46138
|
+
assertSize(size);
|
|
46139
|
+
if (size <= 0) {
|
|
46140
|
+
return createBuffer(size)
|
|
46141
|
+
}
|
|
46142
|
+
if (fill !== undefined) {
|
|
46143
|
+
// Only pay attention to encoding if it's a string. This
|
|
46144
|
+
// prevents accidentally sending in a number that would
|
|
46145
|
+
// be interpreted as a start offset.
|
|
46146
|
+
return typeof encoding === 'string'
|
|
46147
|
+
? createBuffer(size).fill(fill, encoding)
|
|
46148
|
+
: createBuffer(size).fill(fill)
|
|
46149
|
+
}
|
|
46150
|
+
return createBuffer(size)
|
|
46151
|
+
}
|
|
46152
|
+
|
|
46153
|
+
/**
|
|
46154
|
+
* Creates a new filled Buffer instance.
|
|
46155
|
+
* alloc(size[, fill[, encoding]])
|
|
46156
|
+
**/
|
|
46157
|
+
Buffer.alloc = function (size, fill, encoding) {
|
|
46158
|
+
return alloc(size, fill, encoding)
|
|
46159
|
+
};
|
|
46160
|
+
|
|
46161
|
+
function allocUnsafe (size) {
|
|
46162
|
+
assertSize(size);
|
|
46163
|
+
return createBuffer(size < 0 ? 0 : checked(size) | 0)
|
|
46164
|
+
}
|
|
46165
|
+
|
|
46166
|
+
/**
|
|
46167
|
+
* Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
|
|
46168
|
+
* */
|
|
46169
|
+
Buffer.allocUnsafe = function (size) {
|
|
46170
|
+
return allocUnsafe(size)
|
|
46171
|
+
};
|
|
46172
|
+
/**
|
|
46173
|
+
* Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
|
|
46174
|
+
*/
|
|
46175
|
+
Buffer.allocUnsafeSlow = function (size) {
|
|
46176
|
+
return allocUnsafe(size)
|
|
46177
|
+
};
|
|
46178
|
+
|
|
46179
|
+
function fromString (string, encoding) {
|
|
46180
|
+
if (typeof encoding !== 'string' || encoding === '') {
|
|
46181
|
+
encoding = 'utf8';
|
|
46182
|
+
}
|
|
46183
|
+
|
|
46184
|
+
if (!Buffer.isEncoding(encoding)) {
|
|
46185
|
+
throw new TypeError('Unknown encoding: ' + encoding)
|
|
46186
|
+
}
|
|
46187
|
+
|
|
46188
|
+
const length = byteLength(string, encoding) | 0;
|
|
46189
|
+
let buf = createBuffer(length);
|
|
46190
|
+
|
|
46191
|
+
const actual = buf.write(string, encoding);
|
|
46192
|
+
|
|
46193
|
+
if (actual !== length) {
|
|
46194
|
+
// Writing a hex string, for example, that contains invalid characters will
|
|
46195
|
+
// cause everything after the first invalid character to be ignored. (e.g.
|
|
46196
|
+
// 'abxxcd' will be treated as 'ab')
|
|
46197
|
+
buf = buf.slice(0, actual);
|
|
46198
|
+
}
|
|
46199
|
+
|
|
46200
|
+
return buf
|
|
46201
|
+
}
|
|
46202
|
+
|
|
46203
|
+
function fromArrayLike (array) {
|
|
46204
|
+
const length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
46205
|
+
const buf = createBuffer(length);
|
|
46206
|
+
for (let i = 0; i < length; i += 1) {
|
|
46207
|
+
buf[i] = array[i] & 255;
|
|
46208
|
+
}
|
|
46209
|
+
return buf
|
|
46210
|
+
}
|
|
46211
|
+
|
|
46212
|
+
function fromArrayView (arrayView) {
|
|
46213
|
+
if (isInstance(arrayView, Uint8Array)) {
|
|
46214
|
+
const copy = new Uint8Array(arrayView);
|
|
46215
|
+
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
|
|
46216
|
+
}
|
|
46217
|
+
return fromArrayLike(arrayView)
|
|
46218
|
+
}
|
|
46219
|
+
|
|
46220
|
+
function fromArrayBuffer (array, byteOffset, length) {
|
|
46221
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
46222
|
+
throw new RangeError('"offset" is outside of buffer bounds')
|
|
46223
|
+
}
|
|
46224
|
+
|
|
46225
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
|
46226
|
+
throw new RangeError('"length" is outside of buffer bounds')
|
|
46227
|
+
}
|
|
46228
|
+
|
|
46229
|
+
let buf;
|
|
46230
|
+
if (byteOffset === undefined && length === undefined) {
|
|
46231
|
+
buf = new Uint8Array(array);
|
|
46232
|
+
} else if (length === undefined) {
|
|
46233
|
+
buf = new Uint8Array(array, byteOffset);
|
|
46234
|
+
} else {
|
|
46235
|
+
buf = new Uint8Array(array, byteOffset, length);
|
|
46236
|
+
}
|
|
46237
|
+
|
|
46238
|
+
// Return an augmented `Uint8Array` instance
|
|
46239
|
+
Object.setPrototypeOf(buf, Buffer.prototype);
|
|
46240
|
+
|
|
46241
|
+
return buf
|
|
46242
|
+
}
|
|
46243
|
+
|
|
46244
|
+
function fromObject (obj) {
|
|
46245
|
+
if (Buffer.isBuffer(obj)) {
|
|
46246
|
+
const len = checked(obj.length) | 0;
|
|
46247
|
+
const buf = createBuffer(len);
|
|
46248
|
+
|
|
46249
|
+
if (buf.length === 0) {
|
|
46250
|
+
return buf
|
|
46251
|
+
}
|
|
46252
|
+
|
|
46253
|
+
obj.copy(buf, 0, 0, len);
|
|
46254
|
+
return buf
|
|
46255
|
+
}
|
|
46256
|
+
|
|
46257
|
+
if (obj.length !== undefined) {
|
|
46258
|
+
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
|
|
46259
|
+
return createBuffer(0)
|
|
46260
|
+
}
|
|
46261
|
+
return fromArrayLike(obj)
|
|
46262
|
+
}
|
|
46263
|
+
|
|
46264
|
+
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
|
46265
|
+
return fromArrayLike(obj.data)
|
|
46266
|
+
}
|
|
46267
|
+
}
|
|
46268
|
+
|
|
46269
|
+
console.log("********* buffer line 327 *********");
|
|
46270
|
+
|
|
46271
|
+
|
|
46272
|
+
function checked (length) {
|
|
46273
|
+
// Note: cannot use `length < K_MAX_LENGTH` here because that fails when
|
|
46274
|
+
// length is NaN (which is otherwise coerced to zero.)
|
|
46275
|
+
if (length >= K_MAX_LENGTH) {
|
|
46276
|
+
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
|
|
46277
|
+
'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
|
|
46278
|
+
}
|
|
46279
|
+
return length | 0
|
|
46280
|
+
}
|
|
46281
|
+
|
|
46282
|
+
function SlowBuffer (length) {
|
|
46283
|
+
if (+length != length) { // eslint-disable-line eqeqeq
|
|
46284
|
+
length = 0;
|
|
46285
|
+
}
|
|
46286
|
+
return Buffer.alloc(+length)
|
|
46287
|
+
}
|
|
46288
|
+
|
|
46289
|
+
Buffer.isBuffer = function isBuffer (b) {
|
|
46290
|
+
return b != null && b._isBuffer === true &&
|
|
46291
|
+
b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
|
|
46292
|
+
};
|
|
46293
|
+
|
|
46294
|
+
Buffer.compare = function compare (a, b) {
|
|
46295
|
+
if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
|
|
46296
|
+
if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
|
|
46297
|
+
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
|
46298
|
+
throw new TypeError(
|
|
46299
|
+
'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
|
|
46300
|
+
)
|
|
46301
|
+
}
|
|
46302
|
+
|
|
46303
|
+
if (a === b) return 0
|
|
46304
|
+
|
|
46305
|
+
let x = a.length;
|
|
46306
|
+
let y = b.length;
|
|
46307
|
+
|
|
46308
|
+
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
46309
|
+
if (a[i] !== b[i]) {
|
|
46310
|
+
x = a[i];
|
|
46311
|
+
y = b[i];
|
|
46312
|
+
break
|
|
46313
|
+
}
|
|
46314
|
+
}
|
|
46315
|
+
|
|
46316
|
+
if (x < y) return -1
|
|
46317
|
+
if (y < x) return 1
|
|
46318
|
+
return 0
|
|
46319
|
+
};
|
|
46320
|
+
|
|
46321
|
+
Buffer.isEncoding = function isEncoding (encoding) {
|
|
46322
|
+
switch (String(encoding).toLowerCase()) {
|
|
46323
|
+
case 'hex':
|
|
46324
|
+
case 'utf8':
|
|
46325
|
+
case 'utf-8':
|
|
46326
|
+
case 'ascii':
|
|
46327
|
+
case 'latin1':
|
|
46328
|
+
case 'binary':
|
|
46329
|
+
case 'base64':
|
|
46330
|
+
case 'ucs2':
|
|
46331
|
+
case 'ucs-2':
|
|
46332
|
+
case 'utf16le':
|
|
46333
|
+
case 'utf-16le':
|
|
46334
|
+
return true
|
|
46335
|
+
default:
|
|
46336
|
+
return false
|
|
46337
|
+
}
|
|
46338
|
+
};
|
|
46339
|
+
|
|
46340
|
+
Buffer.concat = function concat (list, length) {
|
|
46341
|
+
if (!Array.isArray(list)) {
|
|
46342
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
46343
|
+
}
|
|
46344
|
+
|
|
46345
|
+
if (list.length === 0) {
|
|
46346
|
+
return Buffer.alloc(0)
|
|
46347
|
+
}
|
|
46348
|
+
|
|
46349
|
+
let i;
|
|
46350
|
+
if (length === undefined) {
|
|
46351
|
+
length = 0;
|
|
46352
|
+
for (i = 0; i < list.length; ++i) {
|
|
46353
|
+
length += list[i].length;
|
|
46354
|
+
}
|
|
46355
|
+
}
|
|
46356
|
+
|
|
46357
|
+
const buffer = Buffer.allocUnsafe(length);
|
|
46358
|
+
let pos = 0;
|
|
46359
|
+
for (i = 0; i < list.length; ++i) {
|
|
46360
|
+
let buf = list[i];
|
|
46361
|
+
if (isInstance(buf, Uint8Array)) {
|
|
46362
|
+
if (pos + buf.length > buffer.length) {
|
|
46363
|
+
if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
|
|
46364
|
+
buf.copy(buffer, pos);
|
|
46365
|
+
} else {
|
|
46366
|
+
Uint8Array.prototype.set.call(
|
|
46367
|
+
buffer,
|
|
46368
|
+
buf,
|
|
46369
|
+
pos
|
|
46370
|
+
);
|
|
46371
|
+
}
|
|
46372
|
+
} else if (!Buffer.isBuffer(buf)) {
|
|
46373
|
+
throw new TypeError('"list" argument must be an Array of Buffers')
|
|
46374
|
+
} else {
|
|
46375
|
+
buf.copy(buffer, pos);
|
|
46376
|
+
}
|
|
46377
|
+
pos += buf.length;
|
|
46378
|
+
}
|
|
46379
|
+
return buffer
|
|
46380
|
+
};
|
|
46381
|
+
|
|
46382
|
+
console.log("********* buffer line 440 *********");
|
|
46383
|
+
|
|
46384
|
+
|
|
46385
|
+
function byteLength (string, encoding) {
|
|
46386
|
+
if (Buffer.isBuffer(string)) {
|
|
46387
|
+
return string.length
|
|
46388
|
+
}
|
|
46389
|
+
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
46390
|
+
return string.byteLength
|
|
46391
|
+
}
|
|
46392
|
+
if (typeof string !== 'string') {
|
|
46393
|
+
throw new TypeError(
|
|
46394
|
+
'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
|
|
46395
|
+
'Received type ' + typeof string
|
|
46396
|
+
)
|
|
46397
|
+
}
|
|
46398
|
+
|
|
46399
|
+
const len = string.length;
|
|
46400
|
+
const mustMatch = (arguments.length > 2 && arguments[2] === true);
|
|
46401
|
+
if (!mustMatch && len === 0) return 0
|
|
46402
|
+
|
|
46403
|
+
// Use a for loop to avoid recursion
|
|
46404
|
+
let loweredCase = false;
|
|
46405
|
+
for (;;) {
|
|
46406
|
+
switch (encoding) {
|
|
46407
|
+
case 'ascii':
|
|
46408
|
+
case 'latin1':
|
|
46409
|
+
case 'binary':
|
|
46410
|
+
return len
|
|
46411
|
+
case 'utf8':
|
|
46412
|
+
case 'utf-8':
|
|
46413
|
+
return utf8ToBytes(string).length
|
|
46414
|
+
case 'ucs2':
|
|
46415
|
+
case 'ucs-2':
|
|
46416
|
+
case 'utf16le':
|
|
46417
|
+
case 'utf-16le':
|
|
46418
|
+
return len * 2
|
|
46419
|
+
case 'hex':
|
|
46420
|
+
return len >>> 1
|
|
46421
|
+
case 'base64':
|
|
46422
|
+
return base64ToBytes(string).length
|
|
46423
|
+
default:
|
|
46424
|
+
if (loweredCase) {
|
|
46425
|
+
return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
|
|
45699
46426
|
}
|
|
45700
|
-
|
|
45701
|
-
|
|
46427
|
+
encoding = ('' + encoding).toLowerCase();
|
|
46428
|
+
loweredCase = true;
|
|
46429
|
+
}
|
|
46430
|
+
}
|
|
46431
|
+
}
|
|
46432
|
+
Buffer.byteLength = byteLength;
|
|
46433
|
+
|
|
46434
|
+
function slowToString (encoding, start, end) {
|
|
46435
|
+
let loweredCase = false;
|
|
46436
|
+
|
|
46437
|
+
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
|
46438
|
+
// property of a typed array.
|
|
46439
|
+
|
|
46440
|
+
// This behaves neither like String nor Uint8Array in that we set start/end
|
|
46441
|
+
// to their upper/lower bounds if the value passed is out of range.
|
|
46442
|
+
// undefined is handled specially as per ECMA-262 6th Edition,
|
|
46443
|
+
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
|
46444
|
+
if (start === undefined || start < 0) {
|
|
46445
|
+
start = 0;
|
|
46446
|
+
}
|
|
46447
|
+
// Return early if start > this.length. Done here to prevent potential uint32
|
|
46448
|
+
// coercion fail below.
|
|
46449
|
+
if (start > this.length) {
|
|
46450
|
+
return ''
|
|
46451
|
+
}
|
|
46452
|
+
|
|
46453
|
+
if (end === undefined || end > this.length) {
|
|
46454
|
+
end = this.length;
|
|
46455
|
+
}
|
|
46456
|
+
|
|
46457
|
+
if (end <= 0) {
|
|
46458
|
+
return ''
|
|
46459
|
+
}
|
|
46460
|
+
|
|
46461
|
+
// Force coercion to uint32. This will also coerce falsey/NaN values to 0.
|
|
46462
|
+
end >>>= 0;
|
|
46463
|
+
start >>>= 0;
|
|
46464
|
+
|
|
46465
|
+
if (end <= start) {
|
|
46466
|
+
return ''
|
|
46467
|
+
}
|
|
46468
|
+
|
|
46469
|
+
if (!encoding) encoding = 'utf8';
|
|
46470
|
+
|
|
46471
|
+
while (true) {
|
|
46472
|
+
switch (encoding) {
|
|
46473
|
+
case 'hex':
|
|
46474
|
+
return hexSlice(this, start, end)
|
|
46475
|
+
|
|
46476
|
+
case 'utf8':
|
|
46477
|
+
case 'utf-8':
|
|
46478
|
+
return utf8Slice(this, start, end)
|
|
46479
|
+
|
|
46480
|
+
case 'ascii':
|
|
46481
|
+
return asciiSlice(this, start, end)
|
|
46482
|
+
|
|
46483
|
+
case 'latin1':
|
|
46484
|
+
case 'binary':
|
|
46485
|
+
return latin1Slice(this, start, end)
|
|
46486
|
+
|
|
46487
|
+
case 'base64':
|
|
46488
|
+
return base64Slice(this, start, end)
|
|
46489
|
+
|
|
46490
|
+
case 'ucs2':
|
|
46491
|
+
case 'ucs-2':
|
|
46492
|
+
case 'utf16le':
|
|
46493
|
+
case 'utf-16le':
|
|
46494
|
+
return utf16leSlice(this, start, end)
|
|
46495
|
+
|
|
46496
|
+
default:
|
|
46497
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
46498
|
+
encoding = (encoding + '').toLowerCase();
|
|
46499
|
+
loweredCase = true;
|
|
46500
|
+
}
|
|
46501
|
+
}
|
|
46502
|
+
}
|
|
46503
|
+
|
|
46504
|
+
// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
|
|
46505
|
+
// to detect a Buffer instance. It's not possible to use `instanceof Buffer`
|
|
46506
|
+
// reliably in a browserify context because there could be multiple different
|
|
46507
|
+
// copies of the 'buffer' package in use. This method works even for Buffer
|
|
46508
|
+
// instances that were created from another copy of the `buffer` package.
|
|
46509
|
+
// See: https://github.com/feross/buffer/issues/154
|
|
46510
|
+
Buffer.prototype._isBuffer = true;
|
|
46511
|
+
|
|
46512
|
+
function swap (b, n, m) {
|
|
46513
|
+
const i = b[n];
|
|
46514
|
+
b[n] = b[m];
|
|
46515
|
+
b[m] = i;
|
|
46516
|
+
}
|
|
46517
|
+
|
|
46518
|
+
Buffer.prototype.swap16 = function swap16 () {
|
|
46519
|
+
const len = this.length;
|
|
46520
|
+
if (len % 2 !== 0) {
|
|
46521
|
+
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
|
46522
|
+
}
|
|
46523
|
+
for (let i = 0; i < len; i += 2) {
|
|
46524
|
+
swap(this, i, i + 1);
|
|
46525
|
+
}
|
|
46526
|
+
return this
|
|
46527
|
+
};
|
|
46528
|
+
|
|
46529
|
+
Buffer.prototype.swap32 = function swap32 () {
|
|
46530
|
+
const len = this.length;
|
|
46531
|
+
if (len % 4 !== 0) {
|
|
46532
|
+
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
|
46533
|
+
}
|
|
46534
|
+
for (let i = 0; i < len; i += 4) {
|
|
46535
|
+
swap(this, i, i + 3);
|
|
46536
|
+
swap(this, i + 1, i + 2);
|
|
46537
|
+
}
|
|
46538
|
+
return this
|
|
46539
|
+
};
|
|
46540
|
+
|
|
46541
|
+
Buffer.prototype.swap64 = function swap64 () {
|
|
46542
|
+
const len = this.length;
|
|
46543
|
+
if (len % 8 !== 0) {
|
|
46544
|
+
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
|
46545
|
+
}
|
|
46546
|
+
for (let i = 0; i < len; i += 8) {
|
|
46547
|
+
swap(this, i, i + 7);
|
|
46548
|
+
swap(this, i + 1, i + 6);
|
|
46549
|
+
swap(this, i + 2, i + 5);
|
|
46550
|
+
swap(this, i + 3, i + 4);
|
|
46551
|
+
}
|
|
46552
|
+
return this
|
|
46553
|
+
};
|
|
46554
|
+
|
|
46555
|
+
Buffer.prototype.toString = function toString () {
|
|
46556
|
+
const length = this.length;
|
|
46557
|
+
if (length === 0) return ''
|
|
46558
|
+
if (arguments.length === 0) return utf8Slice(this, 0, length)
|
|
46559
|
+
return slowToString.apply(this, arguments)
|
|
46560
|
+
};
|
|
46561
|
+
|
|
46562
|
+
Buffer.prototype.toLocaleString = Buffer.prototype.toString;
|
|
46563
|
+
|
|
46564
|
+
Buffer.prototype.equals = function equals (b) {
|
|
46565
|
+
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
|
|
46566
|
+
if (this === b) return true
|
|
46567
|
+
return Buffer.compare(this, b) === 0
|
|
46568
|
+
};
|
|
46569
|
+
|
|
46570
|
+
Buffer.prototype.inspect = function inspect () {
|
|
46571
|
+
let str = '';
|
|
46572
|
+
const max = exports.INSPECT_MAX_BYTES;
|
|
46573
|
+
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
|
|
46574
|
+
if (this.length > max) str += ' ... ';
|
|
46575
|
+
return '<Buffer ' + str + '>'
|
|
46576
|
+
};
|
|
46577
|
+
if (customInspectSymbol) {
|
|
46578
|
+
Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
|
|
46579
|
+
}
|
|
46580
|
+
|
|
46581
|
+
Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
|
|
46582
|
+
if (isInstance(target, Uint8Array)) {
|
|
46583
|
+
target = Buffer.from(target, target.offset, target.byteLength);
|
|
46584
|
+
}
|
|
46585
|
+
if (!Buffer.isBuffer(target)) {
|
|
46586
|
+
throw new TypeError(
|
|
46587
|
+
'The "target" argument must be one of type Buffer or Uint8Array. ' +
|
|
46588
|
+
'Received type ' + (typeof target)
|
|
46589
|
+
)
|
|
46590
|
+
}
|
|
46591
|
+
|
|
46592
|
+
if (start === undefined) {
|
|
46593
|
+
start = 0;
|
|
46594
|
+
}
|
|
46595
|
+
if (end === undefined) {
|
|
46596
|
+
end = target ? target.length : 0;
|
|
46597
|
+
}
|
|
46598
|
+
if (thisStart === undefined) {
|
|
46599
|
+
thisStart = 0;
|
|
46600
|
+
}
|
|
46601
|
+
if (thisEnd === undefined) {
|
|
46602
|
+
thisEnd = this.length;
|
|
46603
|
+
}
|
|
46604
|
+
|
|
46605
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
46606
|
+
throw new RangeError('out of range index')
|
|
46607
|
+
}
|
|
46608
|
+
|
|
46609
|
+
if (thisStart >= thisEnd && start >= end) {
|
|
46610
|
+
return 0
|
|
46611
|
+
}
|
|
46612
|
+
if (thisStart >= thisEnd) {
|
|
46613
|
+
return -1
|
|
46614
|
+
}
|
|
46615
|
+
if (start >= end) {
|
|
46616
|
+
return 1
|
|
46617
|
+
}
|
|
46618
|
+
|
|
46619
|
+
start >>>= 0;
|
|
46620
|
+
end >>>= 0;
|
|
46621
|
+
thisStart >>>= 0;
|
|
46622
|
+
thisEnd >>>= 0;
|
|
46623
|
+
|
|
46624
|
+
if (this === target) return 0
|
|
46625
|
+
|
|
46626
|
+
let x = thisEnd - thisStart;
|
|
46627
|
+
let y = end - start;
|
|
46628
|
+
const len = Math.min(x, y);
|
|
46629
|
+
|
|
46630
|
+
const thisCopy = this.slice(thisStart, thisEnd);
|
|
46631
|
+
const targetCopy = target.slice(start, end);
|
|
46632
|
+
|
|
46633
|
+
for (let i = 0; i < len; ++i) {
|
|
46634
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
|
46635
|
+
x = thisCopy[i];
|
|
46636
|
+
y = targetCopy[i];
|
|
46637
|
+
break
|
|
46638
|
+
}
|
|
46639
|
+
}
|
|
46640
|
+
|
|
46641
|
+
if (x < y) return -1
|
|
46642
|
+
if (y < x) return 1
|
|
46643
|
+
return 0
|
|
46644
|
+
};
|
|
46645
|
+
|
|
46646
|
+
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
|
46647
|
+
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
|
46648
|
+
//
|
|
46649
|
+
// Arguments:
|
|
46650
|
+
// - buffer - a Buffer to search
|
|
46651
|
+
// - val - a string, Buffer, or number
|
|
46652
|
+
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
|
46653
|
+
// - encoding - an optional encoding, relevant is val is a string
|
|
46654
|
+
// - dir - true for indexOf, false for lastIndexOf
|
|
46655
|
+
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
|
|
46656
|
+
// Empty buffer means no match
|
|
46657
|
+
if (buffer.length === 0) return -1
|
|
46658
|
+
|
|
46659
|
+
// Normalize byteOffset
|
|
46660
|
+
if (typeof byteOffset === 'string') {
|
|
46661
|
+
encoding = byteOffset;
|
|
46662
|
+
byteOffset = 0;
|
|
46663
|
+
} else if (byteOffset > 0x7fffffff) {
|
|
46664
|
+
byteOffset = 0x7fffffff;
|
|
46665
|
+
} else if (byteOffset < -0x80000000) {
|
|
46666
|
+
byteOffset = -0x80000000;
|
|
46667
|
+
}
|
|
46668
|
+
byteOffset = +byteOffset; // Coerce to Number.
|
|
46669
|
+
if (numberIsNaN(byteOffset)) {
|
|
46670
|
+
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
|
46671
|
+
byteOffset = dir ? 0 : (buffer.length - 1);
|
|
46672
|
+
}
|
|
46673
|
+
|
|
46674
|
+
// Normalize byteOffset: negative offsets start from the end of the buffer
|
|
46675
|
+
if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
|
|
46676
|
+
if (byteOffset >= buffer.length) {
|
|
46677
|
+
if (dir) return -1
|
|
46678
|
+
else byteOffset = buffer.length - 1;
|
|
46679
|
+
} else if (byteOffset < 0) {
|
|
46680
|
+
if (dir) byteOffset = 0;
|
|
46681
|
+
else return -1
|
|
46682
|
+
}
|
|
46683
|
+
|
|
46684
|
+
// Normalize val
|
|
46685
|
+
if (typeof val === 'string') {
|
|
46686
|
+
val = Buffer.from(val, encoding);
|
|
46687
|
+
}
|
|
46688
|
+
|
|
46689
|
+
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
|
46690
|
+
if (Buffer.isBuffer(val)) {
|
|
46691
|
+
// Special case: looking for empty string/buffer always fails
|
|
46692
|
+
if (val.length === 0) {
|
|
46693
|
+
return -1
|
|
46694
|
+
}
|
|
46695
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
|
|
46696
|
+
} else if (typeof val === 'number') {
|
|
46697
|
+
val = val & 0xFF; // Search for a byte value [0-255]
|
|
46698
|
+
if (typeof Uint8Array.prototype.indexOf === 'function') {
|
|
46699
|
+
if (dir) {
|
|
46700
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
|
|
46701
|
+
} else {
|
|
46702
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
|
|
46703
|
+
}
|
|
46704
|
+
}
|
|
46705
|
+
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
|
|
46706
|
+
}
|
|
46707
|
+
|
|
46708
|
+
throw new TypeError('val must be string, number or Buffer')
|
|
46709
|
+
}
|
|
46710
|
+
|
|
46711
|
+
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
|
|
46712
|
+
let indexSize = 1;
|
|
46713
|
+
let arrLength = arr.length;
|
|
46714
|
+
let valLength = val.length;
|
|
46715
|
+
|
|
46716
|
+
if (encoding !== undefined) {
|
|
46717
|
+
encoding = String(encoding).toLowerCase();
|
|
46718
|
+
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
|
|
46719
|
+
encoding === 'utf16le' || encoding === 'utf-16le') {
|
|
46720
|
+
if (arr.length < 2 || val.length < 2) {
|
|
46721
|
+
return -1
|
|
46722
|
+
}
|
|
46723
|
+
indexSize = 2;
|
|
46724
|
+
arrLength /= 2;
|
|
46725
|
+
valLength /= 2;
|
|
46726
|
+
byteOffset /= 2;
|
|
46727
|
+
}
|
|
46728
|
+
}
|
|
46729
|
+
|
|
46730
|
+
function read (buf, i) {
|
|
46731
|
+
if (indexSize === 1) {
|
|
46732
|
+
return buf[i]
|
|
46733
|
+
} else {
|
|
46734
|
+
return buf.readUInt16BE(i * indexSize)
|
|
46735
|
+
}
|
|
46736
|
+
}
|
|
46737
|
+
|
|
46738
|
+
let i;
|
|
46739
|
+
if (dir) {
|
|
46740
|
+
let foundIndex = -1;
|
|
46741
|
+
for (i = byteOffset; i < arrLength; i++) {
|
|
46742
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
46743
|
+
if (foundIndex === -1) foundIndex = i;
|
|
46744
|
+
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
|
|
46745
|
+
} else {
|
|
46746
|
+
if (foundIndex !== -1) i -= i - foundIndex;
|
|
46747
|
+
foundIndex = -1;
|
|
46748
|
+
}
|
|
46749
|
+
}
|
|
46750
|
+
} else {
|
|
46751
|
+
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
|
|
46752
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
46753
|
+
let found = true;
|
|
46754
|
+
for (let j = 0; j < valLength; j++) {
|
|
46755
|
+
if (read(arr, i + j) !== read(val, j)) {
|
|
46756
|
+
found = false;
|
|
46757
|
+
break
|
|
45702
46758
|
}
|
|
45703
|
-
|
|
45704
|
-
|
|
45705
|
-
|
|
45706
|
-
|
|
45707
|
-
|
|
45708
|
-
|
|
46759
|
+
}
|
|
46760
|
+
if (found) return i
|
|
46761
|
+
}
|
|
46762
|
+
}
|
|
46763
|
+
|
|
46764
|
+
return -1
|
|
46765
|
+
}
|
|
46766
|
+
|
|
46767
|
+
Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
|
|
46768
|
+
return this.indexOf(val, byteOffset, encoding) !== -1
|
|
46769
|
+
};
|
|
46770
|
+
|
|
46771
|
+
Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
|
|
46772
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
|
|
46773
|
+
};
|
|
46774
|
+
|
|
46775
|
+
Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
|
|
46776
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
|
|
46777
|
+
};
|
|
46778
|
+
|
|
46779
|
+
function hexWrite (buf, string, offset, length) {
|
|
46780
|
+
offset = Number(offset) || 0;
|
|
46781
|
+
const remaining = buf.length - offset;
|
|
46782
|
+
if (!length) {
|
|
46783
|
+
length = remaining;
|
|
46784
|
+
} else {
|
|
46785
|
+
length = Number(length);
|
|
46786
|
+
if (length > remaining) {
|
|
46787
|
+
length = remaining;
|
|
46788
|
+
}
|
|
46789
|
+
}
|
|
46790
|
+
|
|
46791
|
+
const strLen = string.length;
|
|
46792
|
+
|
|
46793
|
+
if (length > strLen / 2) {
|
|
46794
|
+
length = strLen / 2;
|
|
46795
|
+
}
|
|
46796
|
+
let i;
|
|
46797
|
+
for (i = 0; i < length; ++i) {
|
|
46798
|
+
const parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
46799
|
+
if (numberIsNaN(parsed)) return i
|
|
46800
|
+
buf[offset + i] = parsed;
|
|
46801
|
+
}
|
|
46802
|
+
return i
|
|
46803
|
+
}
|
|
46804
|
+
|
|
46805
|
+
function utf8Write (buf, string, offset, length) {
|
|
46806
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
|
|
46807
|
+
}
|
|
46808
|
+
|
|
46809
|
+
function asciiWrite (buf, string, offset, length) {
|
|
46810
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length)
|
|
46811
|
+
}
|
|
46812
|
+
|
|
46813
|
+
function base64Write (buf, string, offset, length) {
|
|
46814
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length)
|
|
45709
46815
|
}
|
|
45710
46816
|
|
|
46817
|
+
function ucs2Write (buf, string, offset, length) {
|
|
46818
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
|
|
46819
|
+
}
|
|
46820
|
+
|
|
46821
|
+
Buffer.prototype.write = function write (string, offset, length, encoding) {
|
|
46822
|
+
// Buffer#write(string)
|
|
46823
|
+
if (offset === undefined) {
|
|
46824
|
+
encoding = 'utf8';
|
|
46825
|
+
length = this.length;
|
|
46826
|
+
offset = 0;
|
|
46827
|
+
// Buffer#write(string, encoding)
|
|
46828
|
+
} else if (length === undefined && typeof offset === 'string') {
|
|
46829
|
+
encoding = offset;
|
|
46830
|
+
length = this.length;
|
|
46831
|
+
offset = 0;
|
|
46832
|
+
// Buffer#write(string, offset[, length][, encoding])
|
|
46833
|
+
} else if (isFinite(offset)) {
|
|
46834
|
+
offset = offset >>> 0;
|
|
46835
|
+
if (isFinite(length)) {
|
|
46836
|
+
length = length >>> 0;
|
|
46837
|
+
if (encoding === undefined) encoding = 'utf8';
|
|
46838
|
+
} else {
|
|
46839
|
+
encoding = length;
|
|
46840
|
+
length = undefined;
|
|
46841
|
+
}
|
|
46842
|
+
} else {
|
|
46843
|
+
throw new Error(
|
|
46844
|
+
'Buffer.write(string, encoding, offset[, length]) is no longer supported'
|
|
46845
|
+
)
|
|
46846
|
+
}
|
|
46847
|
+
|
|
46848
|
+
const remaining = this.length - offset;
|
|
46849
|
+
if (length === undefined || length > remaining) length = remaining;
|
|
46850
|
+
|
|
46851
|
+
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
|
46852
|
+
throw new RangeError('Attempt to write outside buffer bounds')
|
|
46853
|
+
}
|
|
46854
|
+
|
|
46855
|
+
if (!encoding) encoding = 'utf8';
|
|
46856
|
+
|
|
46857
|
+
let loweredCase = false;
|
|
46858
|
+
for (;;) {
|
|
46859
|
+
switch (encoding) {
|
|
46860
|
+
case 'hex':
|
|
46861
|
+
return hexWrite(this, string, offset, length)
|
|
46862
|
+
|
|
46863
|
+
case 'utf8':
|
|
46864
|
+
case 'utf-8':
|
|
46865
|
+
return utf8Write(this, string, offset, length)
|
|
46866
|
+
|
|
46867
|
+
case 'ascii':
|
|
46868
|
+
case 'latin1':
|
|
46869
|
+
case 'binary':
|
|
46870
|
+
return asciiWrite(this, string, offset, length)
|
|
46871
|
+
|
|
46872
|
+
case 'base64':
|
|
46873
|
+
// Warning: maxLength not taken into account in base64Write
|
|
46874
|
+
return base64Write(this, string, offset, length)
|
|
46875
|
+
|
|
46876
|
+
case 'ucs2':
|
|
46877
|
+
case 'ucs-2':
|
|
46878
|
+
case 'utf16le':
|
|
46879
|
+
case 'utf-16le':
|
|
46880
|
+
return ucs2Write(this, string, offset, length)
|
|
46881
|
+
|
|
46882
|
+
default:
|
|
46883
|
+
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
|
|
46884
|
+
encoding = ('' + encoding).toLowerCase();
|
|
46885
|
+
loweredCase = true;
|
|
46886
|
+
}
|
|
46887
|
+
}
|
|
46888
|
+
};
|
|
46889
|
+
|
|
46890
|
+
Buffer.prototype.toJSON = function toJSON () {
|
|
46891
|
+
return {
|
|
46892
|
+
type: 'Buffer',
|
|
46893
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
46894
|
+
}
|
|
46895
|
+
};
|
|
46896
|
+
|
|
46897
|
+
function base64Slice (buf, start, end) {
|
|
46898
|
+
if (start === 0 && end === buf.length) {
|
|
46899
|
+
return base64Js.fromByteArray(buf)
|
|
46900
|
+
} else {
|
|
46901
|
+
return base64Js.fromByteArray(buf.slice(start, end))
|
|
46902
|
+
}
|
|
46903
|
+
}
|
|
46904
|
+
|
|
46905
|
+
function utf8Slice (buf, start, end) {
|
|
46906
|
+
end = Math.min(buf.length, end);
|
|
46907
|
+
const res = [];
|
|
46908
|
+
|
|
46909
|
+
let i = start;
|
|
46910
|
+
while (i < end) {
|
|
46911
|
+
const firstByte = buf[i];
|
|
46912
|
+
let codePoint = null;
|
|
46913
|
+
let bytesPerSequence = (firstByte > 0xEF)
|
|
46914
|
+
? 4
|
|
46915
|
+
: (firstByte > 0xDF)
|
|
46916
|
+
? 3
|
|
46917
|
+
: (firstByte > 0xBF)
|
|
46918
|
+
? 2
|
|
46919
|
+
: 1;
|
|
46920
|
+
|
|
46921
|
+
if (i + bytesPerSequence <= end) {
|
|
46922
|
+
let secondByte, thirdByte, fourthByte, tempCodePoint;
|
|
46923
|
+
|
|
46924
|
+
switch (bytesPerSequence) {
|
|
46925
|
+
case 1:
|
|
46926
|
+
if (firstByte < 0x80) {
|
|
46927
|
+
codePoint = firstByte;
|
|
46928
|
+
}
|
|
46929
|
+
break
|
|
46930
|
+
case 2:
|
|
46931
|
+
secondByte = buf[i + 1];
|
|
46932
|
+
if ((secondByte & 0xC0) === 0x80) {
|
|
46933
|
+
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
|
|
46934
|
+
if (tempCodePoint > 0x7F) {
|
|
46935
|
+
codePoint = tempCodePoint;
|
|
46936
|
+
}
|
|
46937
|
+
}
|
|
46938
|
+
break
|
|
46939
|
+
case 3:
|
|
46940
|
+
secondByte = buf[i + 1];
|
|
46941
|
+
thirdByte = buf[i + 2];
|
|
46942
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
|
|
46943
|
+
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
|
|
46944
|
+
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
|
|
46945
|
+
codePoint = tempCodePoint;
|
|
46946
|
+
}
|
|
46947
|
+
}
|
|
46948
|
+
break
|
|
46949
|
+
case 4:
|
|
46950
|
+
secondByte = buf[i + 1];
|
|
46951
|
+
thirdByte = buf[i + 2];
|
|
46952
|
+
fourthByte = buf[i + 3];
|
|
46953
|
+
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
|
|
46954
|
+
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
|
|
46955
|
+
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
|
|
46956
|
+
codePoint = tempCodePoint;
|
|
46957
|
+
}
|
|
46958
|
+
}
|
|
46959
|
+
}
|
|
46960
|
+
}
|
|
46961
|
+
|
|
46962
|
+
if (codePoint === null) {
|
|
46963
|
+
// we did not generate a valid codePoint so insert a
|
|
46964
|
+
// replacement char (U+FFFD) and advance only 1 byte
|
|
46965
|
+
codePoint = 0xFFFD;
|
|
46966
|
+
bytesPerSequence = 1;
|
|
46967
|
+
} else if (codePoint > 0xFFFF) {
|
|
46968
|
+
// encode to utf16 (surrogate pair dance)
|
|
46969
|
+
codePoint -= 0x10000;
|
|
46970
|
+
res.push(codePoint >>> 10 & 0x3FF | 0xD800);
|
|
46971
|
+
codePoint = 0xDC00 | codePoint & 0x3FF;
|
|
46972
|
+
}
|
|
46973
|
+
|
|
46974
|
+
res.push(codePoint);
|
|
46975
|
+
i += bytesPerSequence;
|
|
46976
|
+
}
|
|
46977
|
+
|
|
46978
|
+
return decodeCodePointsArray(res)
|
|
46979
|
+
}
|
|
46980
|
+
|
|
46981
|
+
console.log("********* buffer line 1039 *********");
|
|
46982
|
+
|
|
46983
|
+
|
|
46984
|
+
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
|
46985
|
+
// the lowest limit is Chrome, with 0x10000 args.
|
|
46986
|
+
// We go 1 magnitude less, for safety
|
|
46987
|
+
const MAX_ARGUMENTS_LENGTH = 0x1000;
|
|
46988
|
+
|
|
46989
|
+
function decodeCodePointsArray (codePoints) {
|
|
46990
|
+
const len = codePoints.length;
|
|
46991
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
46992
|
+
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
|
|
46993
|
+
}
|
|
46994
|
+
|
|
46995
|
+
// Decode in chunks to avoid "call stack size exceeded".
|
|
46996
|
+
let res = '';
|
|
46997
|
+
let i = 0;
|
|
46998
|
+
while (i < len) {
|
|
46999
|
+
res += String.fromCharCode.apply(
|
|
47000
|
+
String,
|
|
47001
|
+
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
|
|
47002
|
+
);
|
|
47003
|
+
}
|
|
47004
|
+
return res
|
|
47005
|
+
}
|
|
47006
|
+
|
|
47007
|
+
function asciiSlice (buf, start, end) {
|
|
47008
|
+
let ret = '';
|
|
47009
|
+
end = Math.min(buf.length, end);
|
|
47010
|
+
|
|
47011
|
+
for (let i = start; i < end; ++i) {
|
|
47012
|
+
ret += String.fromCharCode(buf[i] & 0x7F);
|
|
47013
|
+
}
|
|
47014
|
+
return ret
|
|
47015
|
+
}
|
|
47016
|
+
|
|
47017
|
+
function latin1Slice (buf, start, end) {
|
|
47018
|
+
let ret = '';
|
|
47019
|
+
end = Math.min(buf.length, end);
|
|
47020
|
+
|
|
47021
|
+
for (let i = start; i < end; ++i) {
|
|
47022
|
+
ret += String.fromCharCode(buf[i]);
|
|
47023
|
+
}
|
|
47024
|
+
return ret
|
|
47025
|
+
}
|
|
47026
|
+
|
|
47027
|
+
function hexSlice (buf, start, end) {
|
|
47028
|
+
const len = buf.length;
|
|
47029
|
+
|
|
47030
|
+
if (!start || start < 0) start = 0;
|
|
47031
|
+
if (!end || end < 0 || end > len) end = len;
|
|
47032
|
+
|
|
47033
|
+
let out = '';
|
|
47034
|
+
for (let i = start; i < end; ++i) {
|
|
47035
|
+
out += hexSliceLookupTable[buf[i]];
|
|
47036
|
+
}
|
|
47037
|
+
return out
|
|
47038
|
+
}
|
|
47039
|
+
|
|
47040
|
+
function utf16leSlice (buf, start, end) {
|
|
47041
|
+
const bytes = buf.slice(start, end);
|
|
47042
|
+
let res = '';
|
|
47043
|
+
// If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
|
|
47044
|
+
for (let i = 0; i < bytes.length - 1; i += 2) {
|
|
47045
|
+
res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
|
|
47046
|
+
}
|
|
47047
|
+
return res
|
|
47048
|
+
}
|
|
47049
|
+
|
|
47050
|
+
Buffer.prototype.slice = function slice (start, end) {
|
|
47051
|
+
const len = this.length;
|
|
47052
|
+
start = ~~start;
|
|
47053
|
+
end = end === undefined ? len : ~~end;
|
|
47054
|
+
|
|
47055
|
+
if (start < 0) {
|
|
47056
|
+
start += len;
|
|
47057
|
+
if (start < 0) start = 0;
|
|
47058
|
+
} else if (start > len) {
|
|
47059
|
+
start = len;
|
|
47060
|
+
}
|
|
47061
|
+
|
|
47062
|
+
if (end < 0) {
|
|
47063
|
+
end += len;
|
|
47064
|
+
if (end < 0) end = 0;
|
|
47065
|
+
} else if (end > len) {
|
|
47066
|
+
end = len;
|
|
47067
|
+
}
|
|
47068
|
+
|
|
47069
|
+
if (end < start) end = start;
|
|
47070
|
+
|
|
47071
|
+
const newBuf = this.subarray(start, end);
|
|
47072
|
+
// Return an augmented `Uint8Array` instance
|
|
47073
|
+
Object.setPrototypeOf(newBuf, Buffer.prototype);
|
|
47074
|
+
|
|
47075
|
+
return newBuf
|
|
47076
|
+
};
|
|
47077
|
+
|
|
47078
|
+
/*
|
|
47079
|
+
* Need to make sure that buffer isn't trying to write out of bounds.
|
|
47080
|
+
*/
|
|
47081
|
+
function checkOffset (offset, ext, length) {
|
|
47082
|
+
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
|
|
47083
|
+
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
|
|
47084
|
+
}
|
|
47085
|
+
|
|
47086
|
+
Buffer.prototype.readUintLE =
|
|
47087
|
+
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
|
|
47088
|
+
offset = offset >>> 0;
|
|
47089
|
+
byteLength = byteLength >>> 0;
|
|
47090
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
47091
|
+
|
|
47092
|
+
let val = this[offset];
|
|
47093
|
+
let mul = 1;
|
|
47094
|
+
let i = 0;
|
|
47095
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
47096
|
+
val += this[offset + i] * mul;
|
|
47097
|
+
}
|
|
47098
|
+
|
|
47099
|
+
return val
|
|
47100
|
+
};
|
|
47101
|
+
|
|
47102
|
+
Buffer.prototype.readUintBE =
|
|
47103
|
+
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
|
|
47104
|
+
offset = offset >>> 0;
|
|
47105
|
+
byteLength = byteLength >>> 0;
|
|
47106
|
+
if (!noAssert) {
|
|
47107
|
+
checkOffset(offset, byteLength, this.length);
|
|
47108
|
+
}
|
|
47109
|
+
|
|
47110
|
+
let val = this[offset + --byteLength];
|
|
47111
|
+
let mul = 1;
|
|
47112
|
+
while (byteLength > 0 && (mul *= 0x100)) {
|
|
47113
|
+
val += this[offset + --byteLength] * mul;
|
|
47114
|
+
}
|
|
47115
|
+
|
|
47116
|
+
return val
|
|
47117
|
+
};
|
|
47118
|
+
|
|
47119
|
+
Buffer.prototype.readUint8 =
|
|
47120
|
+
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
|
|
47121
|
+
offset = offset >>> 0;
|
|
47122
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
47123
|
+
return this[offset]
|
|
47124
|
+
};
|
|
47125
|
+
|
|
47126
|
+
Buffer.prototype.readUint16LE =
|
|
47127
|
+
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
|
|
47128
|
+
offset = offset >>> 0;
|
|
47129
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
47130
|
+
return this[offset] | (this[offset + 1] << 8)
|
|
47131
|
+
};
|
|
47132
|
+
|
|
47133
|
+
Buffer.prototype.readUint16BE =
|
|
47134
|
+
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
|
|
47135
|
+
offset = offset >>> 0;
|
|
47136
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
47137
|
+
return (this[offset] << 8) | this[offset + 1]
|
|
47138
|
+
};
|
|
47139
|
+
|
|
47140
|
+
Buffer.prototype.readUint32LE =
|
|
47141
|
+
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
|
|
47142
|
+
offset = offset >>> 0;
|
|
47143
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
47144
|
+
|
|
47145
|
+
return ((this[offset]) |
|
|
47146
|
+
(this[offset + 1] << 8) |
|
|
47147
|
+
(this[offset + 2] << 16)) +
|
|
47148
|
+
(this[offset + 3] * 0x1000000)
|
|
47149
|
+
};
|
|
47150
|
+
|
|
47151
|
+
Buffer.prototype.readUint32BE =
|
|
47152
|
+
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
|
|
47153
|
+
offset = offset >>> 0;
|
|
47154
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
47155
|
+
|
|
47156
|
+
return (this[offset] * 0x1000000) +
|
|
47157
|
+
((this[offset + 1] << 16) |
|
|
47158
|
+
(this[offset + 2] << 8) |
|
|
47159
|
+
this[offset + 3])
|
|
47160
|
+
};
|
|
47161
|
+
|
|
47162
|
+
Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE (offset) {
|
|
47163
|
+
offset = offset >>> 0;
|
|
47164
|
+
validateNumber(offset, 'offset');
|
|
47165
|
+
const first = this[offset];
|
|
47166
|
+
const last = this[offset + 7];
|
|
47167
|
+
if (first === undefined || last === undefined) {
|
|
47168
|
+
boundsError(offset, this.length - 8);
|
|
47169
|
+
}
|
|
47170
|
+
|
|
47171
|
+
const lo = first +
|
|
47172
|
+
this[++offset] * 2 ** 8 +
|
|
47173
|
+
this[++offset] * 2 ** 16 +
|
|
47174
|
+
this[++offset] * 2 ** 24;
|
|
47175
|
+
|
|
47176
|
+
const hi = this[++offset] +
|
|
47177
|
+
this[++offset] * 2 ** 8 +
|
|
47178
|
+
this[++offset] * 2 ** 16 +
|
|
47179
|
+
last * 2 ** 24;
|
|
47180
|
+
|
|
47181
|
+
return BigInt(lo) + (BigInt(hi) << BigInt(32))
|
|
47182
|
+
});
|
|
47183
|
+
|
|
47184
|
+
console.log("********* buffer line 1241 *********");
|
|
47185
|
+
|
|
47186
|
+
|
|
47187
|
+
console.log("beofre readBigUInt64BE!");
|
|
47188
|
+
Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE (offset) {
|
|
47189
|
+
offset = offset >>> 0;
|
|
47190
|
+
validateNumber(offset, 'offset');
|
|
47191
|
+
const first = this[offset];
|
|
47192
|
+
const last = this[offset + 7];
|
|
47193
|
+
if (first === undefined || last === undefined) {
|
|
47194
|
+
boundsError(offset, this.length - 8);
|
|
47195
|
+
}
|
|
47196
|
+
|
|
47197
|
+
const hi = first * 2 ** 24 +
|
|
47198
|
+
this[++offset] * 2 ** 16 +
|
|
47199
|
+
this[++offset] * 2 ** 8 +
|
|
47200
|
+
this[++offset];
|
|
47201
|
+
|
|
47202
|
+
const lo = this[++offset] * 2 ** 24 +
|
|
47203
|
+
this[++offset] * 2 ** 16 +
|
|
47204
|
+
this[++offset] * 2 ** 8 +
|
|
47205
|
+
last;
|
|
47206
|
+
|
|
47207
|
+
return (BigInt(hi) << BigInt(32)) + BigInt(lo)
|
|
47208
|
+
});
|
|
47209
|
+
|
|
47210
|
+
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
|
|
47211
|
+
offset = offset >>> 0;
|
|
47212
|
+
byteLength = byteLength >>> 0;
|
|
47213
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
47214
|
+
|
|
47215
|
+
let val = this[offset];
|
|
47216
|
+
let mul = 1;
|
|
47217
|
+
let i = 0;
|
|
47218
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
47219
|
+
val += this[offset + i] * mul;
|
|
47220
|
+
}
|
|
47221
|
+
mul *= 0x80;
|
|
47222
|
+
|
|
47223
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
47224
|
+
|
|
47225
|
+
return val
|
|
47226
|
+
};
|
|
47227
|
+
|
|
47228
|
+
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
|
|
47229
|
+
offset = offset >>> 0;
|
|
47230
|
+
byteLength = byteLength >>> 0;
|
|
47231
|
+
if (!noAssert) checkOffset(offset, byteLength, this.length);
|
|
47232
|
+
|
|
47233
|
+
let i = byteLength;
|
|
47234
|
+
let mul = 1;
|
|
47235
|
+
let val = this[offset + --i];
|
|
47236
|
+
while (i > 0 && (mul *= 0x100)) {
|
|
47237
|
+
val += this[offset + --i] * mul;
|
|
47238
|
+
}
|
|
47239
|
+
mul *= 0x80;
|
|
47240
|
+
|
|
47241
|
+
if (val >= mul) val -= Math.pow(2, 8 * byteLength);
|
|
47242
|
+
|
|
47243
|
+
return val
|
|
47244
|
+
};
|
|
47245
|
+
|
|
47246
|
+
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
|
|
47247
|
+
offset = offset >>> 0;
|
|
47248
|
+
if (!noAssert) checkOffset(offset, 1, this.length);
|
|
47249
|
+
if (!(this[offset] & 0x80)) return (this[offset])
|
|
47250
|
+
return ((0xff - this[offset] + 1) * -1)
|
|
47251
|
+
};
|
|
47252
|
+
|
|
47253
|
+
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
|
|
47254
|
+
offset = offset >>> 0;
|
|
47255
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
47256
|
+
const val = this[offset] | (this[offset + 1] << 8);
|
|
47257
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
47258
|
+
};
|
|
47259
|
+
|
|
47260
|
+
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
|
|
47261
|
+
offset = offset >>> 0;
|
|
47262
|
+
if (!noAssert) checkOffset(offset, 2, this.length);
|
|
47263
|
+
const val = this[offset + 1] | (this[offset] << 8);
|
|
47264
|
+
return (val & 0x8000) ? val | 0xFFFF0000 : val
|
|
47265
|
+
};
|
|
47266
|
+
|
|
47267
|
+
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
|
|
47268
|
+
offset = offset >>> 0;
|
|
47269
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
47270
|
+
|
|
47271
|
+
return (this[offset]) |
|
|
47272
|
+
(this[offset + 1] << 8) |
|
|
47273
|
+
(this[offset + 2] << 16) |
|
|
47274
|
+
(this[offset + 3] << 24)
|
|
47275
|
+
};
|
|
47276
|
+
|
|
47277
|
+
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
|
|
47278
|
+
offset = offset >>> 0;
|
|
47279
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
47280
|
+
|
|
47281
|
+
return (this[offset] << 24) |
|
|
47282
|
+
(this[offset + 1] << 16) |
|
|
47283
|
+
(this[offset + 2] << 8) |
|
|
47284
|
+
(this[offset + 3])
|
|
47285
|
+
};
|
|
47286
|
+
|
|
47287
|
+
Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE (offset) {
|
|
47288
|
+
offset = offset >>> 0;
|
|
47289
|
+
validateNumber(offset, 'offset');
|
|
47290
|
+
const first = this[offset];
|
|
47291
|
+
const last = this[offset + 7];
|
|
47292
|
+
if (first === undefined || last === undefined) {
|
|
47293
|
+
boundsError(offset, this.length - 8);
|
|
47294
|
+
}
|
|
47295
|
+
|
|
47296
|
+
const val = this[offset + 4] +
|
|
47297
|
+
this[offset + 5] * 2 ** 8 +
|
|
47298
|
+
this[offset + 6] * 2 ** 16 +
|
|
47299
|
+
(last << 24); // Overflow
|
|
47300
|
+
|
|
47301
|
+
return (BigInt(val) << BigInt(32)) +
|
|
47302
|
+
BigInt(first +
|
|
47303
|
+
this[++offset] * 2 ** 8 +
|
|
47304
|
+
this[++offset] * 2 ** 16 +
|
|
47305
|
+
this[++offset] * 2 ** 24)
|
|
47306
|
+
});
|
|
47307
|
+
|
|
47308
|
+
Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE (offset) {
|
|
47309
|
+
offset = offset >>> 0;
|
|
47310
|
+
validateNumber(offset, 'offset');
|
|
47311
|
+
const first = this[offset];
|
|
47312
|
+
const last = this[offset + 7];
|
|
47313
|
+
if (first === undefined || last === undefined) {
|
|
47314
|
+
boundsError(offset, this.length - 8);
|
|
47315
|
+
}
|
|
47316
|
+
|
|
47317
|
+
const val = (first << 24) + // Overflow
|
|
47318
|
+
this[++offset] * 2 ** 16 +
|
|
47319
|
+
this[++offset] * 2 ** 8 +
|
|
47320
|
+
this[++offset];
|
|
47321
|
+
|
|
47322
|
+
return (BigInt(val) << BigInt(32)) +
|
|
47323
|
+
BigInt(this[++offset] * 2 ** 24 +
|
|
47324
|
+
this[++offset] * 2 ** 16 +
|
|
47325
|
+
this[++offset] * 2 ** 8 +
|
|
47326
|
+
last)
|
|
47327
|
+
});
|
|
47328
|
+
|
|
47329
|
+
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
|
|
47330
|
+
offset = offset >>> 0;
|
|
47331
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
47332
|
+
return ieee754.read(this, offset, true, 23, 4)
|
|
47333
|
+
};
|
|
47334
|
+
|
|
47335
|
+
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
|
|
47336
|
+
offset = offset >>> 0;
|
|
47337
|
+
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
47338
|
+
return ieee754.read(this, offset, false, 23, 4)
|
|
47339
|
+
};
|
|
47340
|
+
|
|
47341
|
+
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
|
|
47342
|
+
offset = offset >>> 0;
|
|
47343
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
47344
|
+
return ieee754.read(this, offset, true, 52, 8)
|
|
47345
|
+
};
|
|
47346
|
+
|
|
47347
|
+
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
|
|
47348
|
+
offset = offset >>> 0;
|
|
47349
|
+
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
47350
|
+
return ieee754.read(this, offset, false, 52, 8)
|
|
47351
|
+
};
|
|
47352
|
+
|
|
47353
|
+
function checkInt (buf, value, offset, ext, max, min) {
|
|
47354
|
+
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
|
|
47355
|
+
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
|
|
47356
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
47357
|
+
}
|
|
47358
|
+
|
|
47359
|
+
Buffer.prototype.writeUintLE =
|
|
47360
|
+
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
|
|
47361
|
+
value = +value;
|
|
47362
|
+
offset = offset >>> 0;
|
|
47363
|
+
byteLength = byteLength >>> 0;
|
|
47364
|
+
if (!noAssert) {
|
|
47365
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
47366
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
47367
|
+
}
|
|
47368
|
+
|
|
47369
|
+
let mul = 1;
|
|
47370
|
+
let i = 0;
|
|
47371
|
+
this[offset] = value & 0xFF;
|
|
47372
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
47373
|
+
this[offset + i] = (value / mul) & 0xFF;
|
|
47374
|
+
}
|
|
47375
|
+
|
|
47376
|
+
return offset + byteLength
|
|
47377
|
+
};
|
|
47378
|
+
|
|
47379
|
+
Buffer.prototype.writeUintBE =
|
|
47380
|
+
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
|
|
47381
|
+
value = +value;
|
|
47382
|
+
offset = offset >>> 0;
|
|
47383
|
+
byteLength = byteLength >>> 0;
|
|
47384
|
+
if (!noAssert) {
|
|
47385
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
47386
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
47387
|
+
}
|
|
47388
|
+
|
|
47389
|
+
let i = byteLength - 1;
|
|
47390
|
+
let mul = 1;
|
|
47391
|
+
this[offset + i] = value & 0xFF;
|
|
47392
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
47393
|
+
this[offset + i] = (value / mul) & 0xFF;
|
|
47394
|
+
}
|
|
47395
|
+
|
|
47396
|
+
return offset + byteLength
|
|
47397
|
+
};
|
|
47398
|
+
|
|
47399
|
+
Buffer.prototype.writeUint8 =
|
|
47400
|
+
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
|
|
47401
|
+
value = +value;
|
|
47402
|
+
offset = offset >>> 0;
|
|
47403
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
|
|
47404
|
+
this[offset] = (value & 0xff);
|
|
47405
|
+
return offset + 1
|
|
47406
|
+
};
|
|
47407
|
+
|
|
47408
|
+
Buffer.prototype.writeUint16LE =
|
|
47409
|
+
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
|
|
47410
|
+
value = +value;
|
|
47411
|
+
offset = offset >>> 0;
|
|
47412
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
47413
|
+
this[offset] = (value & 0xff);
|
|
47414
|
+
this[offset + 1] = (value >>> 8);
|
|
47415
|
+
return offset + 2
|
|
47416
|
+
};
|
|
47417
|
+
|
|
47418
|
+
Buffer.prototype.writeUint16BE =
|
|
47419
|
+
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
|
|
47420
|
+
value = +value;
|
|
47421
|
+
offset = offset >>> 0;
|
|
47422
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
47423
|
+
this[offset] = (value >>> 8);
|
|
47424
|
+
this[offset + 1] = (value & 0xff);
|
|
47425
|
+
return offset + 2
|
|
47426
|
+
};
|
|
47427
|
+
|
|
47428
|
+
Buffer.prototype.writeUint32LE =
|
|
47429
|
+
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
|
|
47430
|
+
value = +value;
|
|
47431
|
+
offset = offset >>> 0;
|
|
47432
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
47433
|
+
this[offset + 3] = (value >>> 24);
|
|
47434
|
+
this[offset + 2] = (value >>> 16);
|
|
47435
|
+
this[offset + 1] = (value >>> 8);
|
|
47436
|
+
this[offset] = (value & 0xff);
|
|
47437
|
+
return offset + 4
|
|
47438
|
+
};
|
|
47439
|
+
|
|
47440
|
+
Buffer.prototype.writeUint32BE =
|
|
47441
|
+
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
|
|
47442
|
+
value = +value;
|
|
47443
|
+
offset = offset >>> 0;
|
|
47444
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
47445
|
+
this[offset] = (value >>> 24);
|
|
47446
|
+
this[offset + 1] = (value >>> 16);
|
|
47447
|
+
this[offset + 2] = (value >>> 8);
|
|
47448
|
+
this[offset + 3] = (value & 0xff);
|
|
47449
|
+
return offset + 4
|
|
47450
|
+
};
|
|
47451
|
+
|
|
47452
|
+
function wrtBigUInt64LE (buf, value, offset, min, max) {
|
|
47453
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
47454
|
+
|
|
47455
|
+
let lo = Number(value & BigInt(0xffffffff));
|
|
47456
|
+
buf[offset++] = lo;
|
|
47457
|
+
lo = lo >> 8;
|
|
47458
|
+
buf[offset++] = lo;
|
|
47459
|
+
lo = lo >> 8;
|
|
47460
|
+
buf[offset++] = lo;
|
|
47461
|
+
lo = lo >> 8;
|
|
47462
|
+
buf[offset++] = lo;
|
|
47463
|
+
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
|
|
47464
|
+
buf[offset++] = hi;
|
|
47465
|
+
hi = hi >> 8;
|
|
47466
|
+
buf[offset++] = hi;
|
|
47467
|
+
hi = hi >> 8;
|
|
47468
|
+
buf[offset++] = hi;
|
|
47469
|
+
hi = hi >> 8;
|
|
47470
|
+
buf[offset++] = hi;
|
|
47471
|
+
return offset
|
|
47472
|
+
}
|
|
47473
|
+
|
|
47474
|
+
function wrtBigUInt64BE (buf, value, offset, min, max) {
|
|
47475
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
47476
|
+
|
|
47477
|
+
let lo = Number(value & BigInt(0xffffffff));
|
|
47478
|
+
buf[offset + 7] = lo;
|
|
47479
|
+
lo = lo >> 8;
|
|
47480
|
+
buf[offset + 6] = lo;
|
|
47481
|
+
lo = lo >> 8;
|
|
47482
|
+
buf[offset + 5] = lo;
|
|
47483
|
+
lo = lo >> 8;
|
|
47484
|
+
buf[offset + 4] = lo;
|
|
47485
|
+
let hi = Number(value >> BigInt(32) & BigInt(0xffffffff));
|
|
47486
|
+
buf[offset + 3] = hi;
|
|
47487
|
+
hi = hi >> 8;
|
|
47488
|
+
buf[offset + 2] = hi;
|
|
47489
|
+
hi = hi >> 8;
|
|
47490
|
+
buf[offset + 1] = hi;
|
|
47491
|
+
hi = hi >> 8;
|
|
47492
|
+
buf[offset] = hi;
|
|
47493
|
+
return offset + 8
|
|
47494
|
+
}
|
|
47495
|
+
|
|
47496
|
+
Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE (value, offset = 0) {
|
|
47497
|
+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
|
|
47498
|
+
});
|
|
47499
|
+
|
|
47500
|
+
Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE (value, offset = 0) {
|
|
47501
|
+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'))
|
|
47502
|
+
});
|
|
47503
|
+
|
|
47504
|
+
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
|
|
47505
|
+
value = +value;
|
|
47506
|
+
offset = offset >>> 0;
|
|
47507
|
+
if (!noAssert) {
|
|
47508
|
+
const limit = Math.pow(2, (8 * byteLength) - 1);
|
|
47509
|
+
|
|
47510
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
47511
|
+
}
|
|
47512
|
+
|
|
47513
|
+
let i = 0;
|
|
47514
|
+
let mul = 1;
|
|
47515
|
+
let sub = 0;
|
|
47516
|
+
this[offset] = value & 0xFF;
|
|
47517
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
47518
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
47519
|
+
sub = 1;
|
|
47520
|
+
}
|
|
47521
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
47522
|
+
}
|
|
47523
|
+
|
|
47524
|
+
return offset + byteLength
|
|
47525
|
+
};
|
|
47526
|
+
|
|
47527
|
+
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
|
|
47528
|
+
value = +value;
|
|
47529
|
+
offset = offset >>> 0;
|
|
47530
|
+
if (!noAssert) {
|
|
47531
|
+
const limit = Math.pow(2, (8 * byteLength) - 1);
|
|
47532
|
+
|
|
47533
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
47534
|
+
}
|
|
47535
|
+
|
|
47536
|
+
let i = byteLength - 1;
|
|
47537
|
+
let mul = 1;
|
|
47538
|
+
let sub = 0;
|
|
47539
|
+
this[offset + i] = value & 0xFF;
|
|
47540
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
47541
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
47542
|
+
sub = 1;
|
|
47543
|
+
}
|
|
47544
|
+
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
|
|
47545
|
+
}
|
|
47546
|
+
|
|
47547
|
+
return offset + byteLength
|
|
47548
|
+
};
|
|
47549
|
+
|
|
47550
|
+
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
|
|
47551
|
+
value = +value;
|
|
47552
|
+
offset = offset >>> 0;
|
|
47553
|
+
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
|
|
47554
|
+
if (value < 0) value = 0xff + value + 1;
|
|
47555
|
+
this[offset] = (value & 0xff);
|
|
47556
|
+
return offset + 1
|
|
47557
|
+
};
|
|
47558
|
+
|
|
47559
|
+
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
|
|
47560
|
+
value = +value;
|
|
47561
|
+
offset = offset >>> 0;
|
|
47562
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
|
47563
|
+
this[offset] = (value & 0xff);
|
|
47564
|
+
this[offset + 1] = (value >>> 8);
|
|
47565
|
+
return offset + 2
|
|
47566
|
+
};
|
|
47567
|
+
|
|
47568
|
+
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
|
|
47569
|
+
value = +value;
|
|
47570
|
+
offset = offset >>> 0;
|
|
47571
|
+
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
|
47572
|
+
this[offset] = (value >>> 8);
|
|
47573
|
+
this[offset + 1] = (value & 0xff);
|
|
47574
|
+
return offset + 2
|
|
47575
|
+
};
|
|
47576
|
+
|
|
47577
|
+
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
|
|
47578
|
+
value = +value;
|
|
47579
|
+
offset = offset >>> 0;
|
|
47580
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
|
47581
|
+
this[offset] = (value & 0xff);
|
|
47582
|
+
this[offset + 1] = (value >>> 8);
|
|
47583
|
+
this[offset + 2] = (value >>> 16);
|
|
47584
|
+
this[offset + 3] = (value >>> 24);
|
|
47585
|
+
return offset + 4
|
|
47586
|
+
};
|
|
47587
|
+
|
|
47588
|
+
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
|
|
47589
|
+
value = +value;
|
|
47590
|
+
offset = offset >>> 0;
|
|
47591
|
+
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
|
47592
|
+
if (value < 0) value = 0xffffffff + value + 1;
|
|
47593
|
+
this[offset] = (value >>> 24);
|
|
47594
|
+
this[offset + 1] = (value >>> 16);
|
|
47595
|
+
this[offset + 2] = (value >>> 8);
|
|
47596
|
+
this[offset + 3] = (value & 0xff);
|
|
47597
|
+
return offset + 4
|
|
47598
|
+
};
|
|
47599
|
+
|
|
47600
|
+
Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE (value, offset = 0) {
|
|
47601
|
+
return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
|
|
47602
|
+
});
|
|
47603
|
+
|
|
47604
|
+
Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE (value, offset = 0) {
|
|
47605
|
+
return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'))
|
|
47606
|
+
});
|
|
47607
|
+
|
|
47608
|
+
function checkIEEE754 (buf, value, offset, ext, max, min) {
|
|
47609
|
+
if (offset + ext > buf.length) throw new RangeError('Index out of range')
|
|
47610
|
+
if (offset < 0) throw new RangeError('Index out of range')
|
|
47611
|
+
}
|
|
47612
|
+
|
|
47613
|
+
function writeFloat (buf, value, offset, littleEndian, noAssert) {
|
|
47614
|
+
value = +value;
|
|
47615
|
+
offset = offset >>> 0;
|
|
47616
|
+
if (!noAssert) {
|
|
47617
|
+
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38);
|
|
47618
|
+
}
|
|
47619
|
+
ieee754.write(buf, value, offset, littleEndian, 23, 4);
|
|
47620
|
+
return offset + 4
|
|
47621
|
+
}
|
|
47622
|
+
|
|
47623
|
+
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
|
|
47624
|
+
return writeFloat(this, value, offset, true, noAssert)
|
|
47625
|
+
};
|
|
47626
|
+
|
|
47627
|
+
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
|
|
47628
|
+
return writeFloat(this, value, offset, false, noAssert)
|
|
47629
|
+
};
|
|
47630
|
+
|
|
47631
|
+
function writeDouble (buf, value, offset, littleEndian, noAssert) {
|
|
47632
|
+
value = +value;
|
|
47633
|
+
offset = offset >>> 0;
|
|
47634
|
+
if (!noAssert) {
|
|
47635
|
+
checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308);
|
|
47636
|
+
}
|
|
47637
|
+
ieee754.write(buf, value, offset, littleEndian, 52, 8);
|
|
47638
|
+
return offset + 8
|
|
47639
|
+
}
|
|
47640
|
+
|
|
47641
|
+
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
|
|
47642
|
+
return writeDouble(this, value, offset, true, noAssert)
|
|
47643
|
+
};
|
|
47644
|
+
|
|
47645
|
+
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
|
|
47646
|
+
return writeDouble(this, value, offset, false, noAssert)
|
|
47647
|
+
};
|
|
47648
|
+
|
|
47649
|
+
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
47650
|
+
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
|
|
47651
|
+
if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
|
|
47652
|
+
if (!start) start = 0;
|
|
47653
|
+
if (!end && end !== 0) end = this.length;
|
|
47654
|
+
if (targetStart >= target.length) targetStart = target.length;
|
|
47655
|
+
if (!targetStart) targetStart = 0;
|
|
47656
|
+
if (end > 0 && end < start) end = start;
|
|
47657
|
+
|
|
47658
|
+
// Copy 0 bytes; we're done
|
|
47659
|
+
if (end === start) return 0
|
|
47660
|
+
if (target.length === 0 || this.length === 0) return 0
|
|
47661
|
+
|
|
47662
|
+
// Fatal error conditions
|
|
47663
|
+
if (targetStart < 0) {
|
|
47664
|
+
throw new RangeError('targetStart out of bounds')
|
|
47665
|
+
}
|
|
47666
|
+
if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
|
|
47667
|
+
if (end < 0) throw new RangeError('sourceEnd out of bounds')
|
|
47668
|
+
|
|
47669
|
+
// Are we oob?
|
|
47670
|
+
if (end > this.length) end = this.length;
|
|
47671
|
+
if (target.length - targetStart < end - start) {
|
|
47672
|
+
end = target.length - targetStart + start;
|
|
47673
|
+
}
|
|
47674
|
+
|
|
47675
|
+
const len = end - start;
|
|
47676
|
+
|
|
47677
|
+
if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
|
47678
|
+
// Use built-in when available, missing from IE11
|
|
47679
|
+
this.copyWithin(targetStart, start, end);
|
|
47680
|
+
} else {
|
|
47681
|
+
Uint8Array.prototype.set.call(
|
|
47682
|
+
target,
|
|
47683
|
+
this.subarray(start, end),
|
|
47684
|
+
targetStart
|
|
47685
|
+
);
|
|
47686
|
+
}
|
|
47687
|
+
|
|
47688
|
+
return len
|
|
47689
|
+
};
|
|
47690
|
+
|
|
47691
|
+
// Usage:
|
|
47692
|
+
// buffer.fill(number[, offset[, end]])
|
|
47693
|
+
// buffer.fill(buffer[, offset[, end]])
|
|
47694
|
+
// buffer.fill(string[, offset[, end]][, encoding])
|
|
47695
|
+
Buffer.prototype.fill = function fill (val, start, end, encoding) {
|
|
47696
|
+
// Handle string cases:
|
|
47697
|
+
if (typeof val === 'string') {
|
|
47698
|
+
if (typeof start === 'string') {
|
|
47699
|
+
encoding = start;
|
|
47700
|
+
start = 0;
|
|
47701
|
+
end = this.length;
|
|
47702
|
+
} else if (typeof end === 'string') {
|
|
47703
|
+
encoding = end;
|
|
47704
|
+
end = this.length;
|
|
47705
|
+
}
|
|
47706
|
+
if (encoding !== undefined && typeof encoding !== 'string') {
|
|
47707
|
+
throw new TypeError('encoding must be a string')
|
|
47708
|
+
}
|
|
47709
|
+
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
|
47710
|
+
throw new TypeError('Unknown encoding: ' + encoding)
|
|
47711
|
+
}
|
|
47712
|
+
if (val.length === 1) {
|
|
47713
|
+
const code = val.charCodeAt(0);
|
|
47714
|
+
if ((encoding === 'utf8' && code < 128) ||
|
|
47715
|
+
encoding === 'latin1') {
|
|
47716
|
+
// Fast path: If `val` fits into a single byte, use that numeric value.
|
|
47717
|
+
val = code;
|
|
47718
|
+
}
|
|
47719
|
+
}
|
|
47720
|
+
} else if (typeof val === 'number') {
|
|
47721
|
+
val = val & 255;
|
|
47722
|
+
} else if (typeof val === 'boolean') {
|
|
47723
|
+
val = Number(val);
|
|
47724
|
+
}
|
|
47725
|
+
|
|
47726
|
+
// Invalid ranges are not set to a default, so can range check early.
|
|
47727
|
+
if (start < 0 || this.length < start || this.length < end) {
|
|
47728
|
+
throw new RangeError('Out of range index')
|
|
47729
|
+
}
|
|
47730
|
+
|
|
47731
|
+
if (end <= start) {
|
|
47732
|
+
return this
|
|
47733
|
+
}
|
|
47734
|
+
|
|
47735
|
+
start = start >>> 0;
|
|
47736
|
+
end = end === undefined ? this.length : end >>> 0;
|
|
47737
|
+
|
|
47738
|
+
if (!val) val = 0;
|
|
47739
|
+
|
|
47740
|
+
let i;
|
|
47741
|
+
if (typeof val === 'number') {
|
|
47742
|
+
for (i = start; i < end; ++i) {
|
|
47743
|
+
this[i] = val;
|
|
47744
|
+
}
|
|
47745
|
+
} else {
|
|
47746
|
+
const bytes = Buffer.isBuffer(val)
|
|
47747
|
+
? val
|
|
47748
|
+
: Buffer.from(val, encoding);
|
|
47749
|
+
const len = bytes.length;
|
|
47750
|
+
if (len === 0) {
|
|
47751
|
+
throw new TypeError('The value "' + val +
|
|
47752
|
+
'" is invalid for argument "value"')
|
|
47753
|
+
}
|
|
47754
|
+
for (i = 0; i < end - start; ++i) {
|
|
47755
|
+
this[i + start] = bytes[i % len];
|
|
47756
|
+
}
|
|
47757
|
+
}
|
|
47758
|
+
|
|
47759
|
+
return this
|
|
47760
|
+
};
|
|
47761
|
+
|
|
47762
|
+
// CUSTOM ERRORS
|
|
47763
|
+
// =============
|
|
47764
|
+
|
|
47765
|
+
// Simplified versions from Node, changed for Buffer-only usage
|
|
47766
|
+
const errors = {};
|
|
47767
|
+
function E (sym, getMessage, Base) {
|
|
47768
|
+
errors[sym] = class NodeError extends Base {
|
|
47769
|
+
constructor () {
|
|
47770
|
+
super();
|
|
47771
|
+
|
|
47772
|
+
Object.defineProperty(this, 'message', {
|
|
47773
|
+
value: getMessage.apply(this, arguments),
|
|
47774
|
+
writable: true,
|
|
47775
|
+
configurable: true
|
|
47776
|
+
});
|
|
47777
|
+
|
|
47778
|
+
// Add the error code to the name to include it in the stack trace.
|
|
47779
|
+
this.name = `${this.name} [${sym}]`;
|
|
47780
|
+
// Access the stack to generate the error message including the error code
|
|
47781
|
+
// from the name.
|
|
47782
|
+
this.stack; // eslint-disable-line no-unused-expressions
|
|
47783
|
+
// Reset the name to the actual name.
|
|
47784
|
+
delete this.name;
|
|
47785
|
+
}
|
|
47786
|
+
|
|
47787
|
+
get code () {
|
|
47788
|
+
return sym
|
|
47789
|
+
}
|
|
47790
|
+
|
|
47791
|
+
set code (value) {
|
|
47792
|
+
Object.defineProperty(this, 'code', {
|
|
47793
|
+
configurable: true,
|
|
47794
|
+
enumerable: true,
|
|
47795
|
+
value,
|
|
47796
|
+
writable: true
|
|
47797
|
+
});
|
|
47798
|
+
}
|
|
47799
|
+
|
|
47800
|
+
toString () {
|
|
47801
|
+
return `${this.name} [${sym}]: ${this.message}`
|
|
47802
|
+
}
|
|
47803
|
+
};
|
|
47804
|
+
}
|
|
47805
|
+
|
|
47806
|
+
E('ERR_BUFFER_OUT_OF_BOUNDS',
|
|
47807
|
+
function (name) {
|
|
47808
|
+
if (name) {
|
|
47809
|
+
return `${name} is outside of buffer bounds`
|
|
47810
|
+
}
|
|
47811
|
+
|
|
47812
|
+
return 'Attempt to access memory outside buffer bounds'
|
|
47813
|
+
}, RangeError);
|
|
47814
|
+
E('ERR_INVALID_ARG_TYPE',
|
|
47815
|
+
function (name, actual) {
|
|
47816
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`
|
|
47817
|
+
}, TypeError);
|
|
47818
|
+
E('ERR_OUT_OF_RANGE',
|
|
47819
|
+
function (str, range, input) {
|
|
47820
|
+
let msg = `The value of "${str}" is out of range.`;
|
|
47821
|
+
let received = input;
|
|
47822
|
+
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
47823
|
+
received = addNumericalSeparator(String(input));
|
|
47824
|
+
} else if (typeof input === 'bigint') {
|
|
47825
|
+
received = String(input);
|
|
47826
|
+
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
47827
|
+
received = addNumericalSeparator(received);
|
|
47828
|
+
}
|
|
47829
|
+
received += 'n';
|
|
47830
|
+
}
|
|
47831
|
+
msg += ` It must be ${range}. Received ${received}`;
|
|
47832
|
+
return msg
|
|
47833
|
+
}, RangeError);
|
|
47834
|
+
|
|
47835
|
+
function addNumericalSeparator (val) {
|
|
47836
|
+
let res = '';
|
|
47837
|
+
let i = val.length;
|
|
47838
|
+
const start = val[0] === '-' ? 1 : 0;
|
|
47839
|
+
for (; i >= start + 4; i -= 3) {
|
|
47840
|
+
res = `_${val.slice(i - 3, i)}${res}`;
|
|
47841
|
+
}
|
|
47842
|
+
return `${val.slice(0, i)}${res}`
|
|
47843
|
+
}
|
|
47844
|
+
|
|
47845
|
+
// CHECK FUNCTIONS
|
|
47846
|
+
// ===============
|
|
47847
|
+
|
|
47848
|
+
function checkBounds (buf, offset, byteLength) {
|
|
47849
|
+
validateNumber(offset, 'offset');
|
|
47850
|
+
if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
|
|
47851
|
+
boundsError(offset, buf.length - (byteLength + 1));
|
|
47852
|
+
}
|
|
47853
|
+
}
|
|
47854
|
+
|
|
47855
|
+
function checkIntBI (value, min, max, buf, offset, byteLength) {
|
|
47856
|
+
if (value > max || value < min) {
|
|
47857
|
+
const n = typeof min === 'bigint' ? 'n' : '';
|
|
47858
|
+
let range;
|
|
47859
|
+
if (byteLength > 3) {
|
|
47860
|
+
if (min === 0 || min === BigInt(0)) {
|
|
47861
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
|
|
47862
|
+
} else {
|
|
47863
|
+
range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
|
|
47864
|
+
`${(byteLength + 1) * 8 - 1}${n}`;
|
|
47865
|
+
}
|
|
47866
|
+
} else {
|
|
47867
|
+
range = `>= ${min}${n} and <= ${max}${n}`;
|
|
47868
|
+
}
|
|
47869
|
+
throw new errors.ERR_OUT_OF_RANGE('value', range, value)
|
|
47870
|
+
}
|
|
47871
|
+
checkBounds(buf, offset, byteLength);
|
|
47872
|
+
}
|
|
47873
|
+
|
|
47874
|
+
function validateNumber (value, name) {
|
|
47875
|
+
if (typeof value !== 'number') {
|
|
47876
|
+
throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value)
|
|
47877
|
+
}
|
|
47878
|
+
}
|
|
47879
|
+
|
|
47880
|
+
function boundsError (value, length, type) {
|
|
47881
|
+
if (Math.floor(value) !== value) {
|
|
47882
|
+
validateNumber(value, type);
|
|
47883
|
+
throw new errors.ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value)
|
|
47884
|
+
}
|
|
47885
|
+
|
|
47886
|
+
if (length < 0) {
|
|
47887
|
+
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
|
|
47888
|
+
}
|
|
47889
|
+
|
|
47890
|
+
throw new errors.ERR_OUT_OF_RANGE(type || 'offset',
|
|
47891
|
+
`>= ${type ? 1 : 0} and <= ${length}`,
|
|
47892
|
+
value)
|
|
47893
|
+
}
|
|
47894
|
+
|
|
47895
|
+
// HELPER FUNCTIONS
|
|
47896
|
+
// ================
|
|
47897
|
+
|
|
47898
|
+
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
47899
|
+
|
|
47900
|
+
function base64clean (str) {
|
|
47901
|
+
// Node takes equal signs as end of the Base64 encoding
|
|
47902
|
+
str = str.split('=')[0];
|
|
47903
|
+
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
|
47904
|
+
str = str.trim().replace(INVALID_BASE64_RE, '');
|
|
47905
|
+
// Node converts strings with length < 2 to ''
|
|
47906
|
+
if (str.length < 2) return ''
|
|
47907
|
+
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
|
47908
|
+
while (str.length % 4 !== 0) {
|
|
47909
|
+
str = str + '=';
|
|
47910
|
+
}
|
|
47911
|
+
return str
|
|
47912
|
+
}
|
|
47913
|
+
|
|
47914
|
+
function utf8ToBytes (string, units) {
|
|
47915
|
+
units = units || Infinity;
|
|
47916
|
+
let codePoint;
|
|
47917
|
+
const length = string.length;
|
|
47918
|
+
let leadSurrogate = null;
|
|
47919
|
+
const bytes = [];
|
|
47920
|
+
|
|
47921
|
+
for (let i = 0; i < length; ++i) {
|
|
47922
|
+
codePoint = string.charCodeAt(i);
|
|
47923
|
+
|
|
47924
|
+
// is surrogate component
|
|
47925
|
+
if (codePoint > 0xD7FF && codePoint < 0xE000) {
|
|
47926
|
+
// last char was a lead
|
|
47927
|
+
if (!leadSurrogate) {
|
|
47928
|
+
// no lead yet
|
|
47929
|
+
if (codePoint > 0xDBFF) {
|
|
47930
|
+
// unexpected trail
|
|
47931
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
47932
|
+
continue
|
|
47933
|
+
} else if (i + 1 === length) {
|
|
47934
|
+
// unpaired lead
|
|
47935
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
47936
|
+
continue
|
|
47937
|
+
}
|
|
47938
|
+
|
|
47939
|
+
// valid lead
|
|
47940
|
+
leadSurrogate = codePoint;
|
|
47941
|
+
|
|
47942
|
+
continue
|
|
47943
|
+
}
|
|
47944
|
+
|
|
47945
|
+
// 2 leads in a row
|
|
47946
|
+
if (codePoint < 0xDC00) {
|
|
47947
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
47948
|
+
leadSurrogate = codePoint;
|
|
47949
|
+
continue
|
|
47950
|
+
}
|
|
47951
|
+
|
|
47952
|
+
// valid surrogate pair
|
|
47953
|
+
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
|
|
47954
|
+
} else if (leadSurrogate) {
|
|
47955
|
+
// valid bmp char, but last char was a lead
|
|
47956
|
+
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
|
|
47957
|
+
}
|
|
47958
|
+
|
|
47959
|
+
leadSurrogate = null;
|
|
47960
|
+
|
|
47961
|
+
// encode utf8
|
|
47962
|
+
if (codePoint < 0x80) {
|
|
47963
|
+
if ((units -= 1) < 0) break
|
|
47964
|
+
bytes.push(codePoint);
|
|
47965
|
+
} else if (codePoint < 0x800) {
|
|
47966
|
+
if ((units -= 2) < 0) break
|
|
47967
|
+
bytes.push(
|
|
47968
|
+
codePoint >> 0x6 | 0xC0,
|
|
47969
|
+
codePoint & 0x3F | 0x80
|
|
47970
|
+
);
|
|
47971
|
+
} else if (codePoint < 0x10000) {
|
|
47972
|
+
if ((units -= 3) < 0) break
|
|
47973
|
+
bytes.push(
|
|
47974
|
+
codePoint >> 0xC | 0xE0,
|
|
47975
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
|
47976
|
+
codePoint & 0x3F | 0x80
|
|
47977
|
+
);
|
|
47978
|
+
} else if (codePoint < 0x110000) {
|
|
47979
|
+
if ((units -= 4) < 0) break
|
|
47980
|
+
bytes.push(
|
|
47981
|
+
codePoint >> 0x12 | 0xF0,
|
|
47982
|
+
codePoint >> 0xC & 0x3F | 0x80,
|
|
47983
|
+
codePoint >> 0x6 & 0x3F | 0x80,
|
|
47984
|
+
codePoint & 0x3F | 0x80
|
|
47985
|
+
);
|
|
47986
|
+
} else {
|
|
47987
|
+
throw new Error('Invalid code point')
|
|
47988
|
+
}
|
|
47989
|
+
}
|
|
47990
|
+
|
|
47991
|
+
return bytes
|
|
47992
|
+
}
|
|
47993
|
+
|
|
47994
|
+
function asciiToBytes (str) {
|
|
47995
|
+
const byteArray = [];
|
|
47996
|
+
for (let i = 0; i < str.length; ++i) {
|
|
47997
|
+
// Node's code seems to be doing this and not & 0x7F..
|
|
47998
|
+
byteArray.push(str.charCodeAt(i) & 0xFF);
|
|
47999
|
+
}
|
|
48000
|
+
return byteArray
|
|
48001
|
+
}
|
|
48002
|
+
|
|
48003
|
+
function utf16leToBytes (str, units) {
|
|
48004
|
+
let c, hi, lo;
|
|
48005
|
+
const byteArray = [];
|
|
48006
|
+
for (let i = 0; i < str.length; ++i) {
|
|
48007
|
+
if ((units -= 2) < 0) break
|
|
48008
|
+
|
|
48009
|
+
c = str.charCodeAt(i);
|
|
48010
|
+
hi = c >> 8;
|
|
48011
|
+
lo = c % 256;
|
|
48012
|
+
byteArray.push(lo);
|
|
48013
|
+
byteArray.push(hi);
|
|
48014
|
+
}
|
|
48015
|
+
|
|
48016
|
+
return byteArray
|
|
48017
|
+
}
|
|
48018
|
+
|
|
48019
|
+
function base64ToBytes (str) {
|
|
48020
|
+
return base64Js.toByteArray(base64clean(str))
|
|
48021
|
+
}
|
|
48022
|
+
|
|
48023
|
+
function blitBuffer (src, dst, offset, length) {
|
|
48024
|
+
let i;
|
|
48025
|
+
for (i = 0; i < length; ++i) {
|
|
48026
|
+
if ((i + offset >= dst.length) || (i >= src.length)) break
|
|
48027
|
+
dst[i + offset] = src[i];
|
|
48028
|
+
}
|
|
48029
|
+
return i
|
|
48030
|
+
}
|
|
48031
|
+
|
|
48032
|
+
// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
|
|
48033
|
+
// the `instanceof` check but they should be treated as of that type.
|
|
48034
|
+
// See: https://github.com/feross/buffer/issues/166
|
|
48035
|
+
function isInstance (obj, type) {
|
|
48036
|
+
return obj instanceof type ||
|
|
48037
|
+
(obj != null && obj.constructor != null && obj.constructor.name != null &&
|
|
48038
|
+
obj.constructor.name === type.name)
|
|
48039
|
+
}
|
|
48040
|
+
function numberIsNaN (obj) {
|
|
48041
|
+
// For IE11 support
|
|
48042
|
+
return obj !== obj // eslint-disable-line no-self-compare
|
|
48043
|
+
}
|
|
48044
|
+
|
|
48045
|
+
// Create lookup table for `toString('hex')`
|
|
48046
|
+
// See: https://github.com/feross/buffer/issues/219
|
|
48047
|
+
const hexSliceLookupTable = (function () {
|
|
48048
|
+
const alphabet = '0123456789abcdef';
|
|
48049
|
+
const table = new Array(256);
|
|
48050
|
+
for (let i = 0; i < 16; ++i) {
|
|
48051
|
+
const i16 = i * 16;
|
|
48052
|
+
for (let j = 0; j < 16; ++j) {
|
|
48053
|
+
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
48054
|
+
}
|
|
48055
|
+
}
|
|
48056
|
+
return table
|
|
48057
|
+
})();
|
|
48058
|
+
|
|
48059
|
+
// Return not function with Error if BigInt not supported
|
|
48060
|
+
function defineBigIntMethod (fn) {
|
|
48061
|
+
return typeof BigInt === 'undefined' ? BufferBigIntNotDefined : fn
|
|
48062
|
+
}
|
|
48063
|
+
|
|
48064
|
+
function BufferBigIntNotDefined () {
|
|
48065
|
+
throw new Error('BigInt not supported')
|
|
48066
|
+
}
|
|
48067
|
+
});
|
|
48068
|
+
var buffer_1 = buffer$1.Buffer;
|
|
48069
|
+
var buffer_2 = buffer$1.SlowBuffer;
|
|
48070
|
+
var buffer_3 = buffer$1.INSPECT_MAX_BYTES;
|
|
48071
|
+
var buffer_4 = buffer$1.kMaxLength;
|
|
48072
|
+
|
|
45711
48073
|
/**
|
|
45712
48074
|
* @hidden
|
|
45713
48075
|
*/
|
|
@@ -45728,21 +48090,39 @@ var TRANSPORT_TYPE;
|
|
|
45728
48090
|
TRANSPORT_TYPE["REACT_NATIVE"] = "reactNative";
|
|
45729
48091
|
})(TRANSPORT_TYPE || (TRANSPORT_TYPE = {}));
|
|
45730
48092
|
|
|
45731
|
-
|
|
45732
|
-
|
|
45733
|
-
|
|
45734
|
-
|
|
45735
|
-
|
|
45736
|
-
|
|
45737
|
-
|
|
45738
|
-
|
|
45739
|
-
|
|
45740
|
-
|
|
45741
|
-
|
|
45742
|
-
|
|
45743
|
-
|
|
48093
|
+
/**
|
|
48094
|
+
* @hidden
|
|
48095
|
+
*/
|
|
48096
|
+
class TextCodec {
|
|
48097
|
+
constructor(transportType) {
|
|
48098
|
+
this.transportType = transportType;
|
|
48099
|
+
if (transportType === TRANSPORT_TYPE.WEB) {
|
|
48100
|
+
this.webEncoder = new TextEncoder();
|
|
48101
|
+
this.webDecoder = new TextDecoder("utf-8");
|
|
48102
|
+
}
|
|
48103
|
+
}
|
|
48104
|
+
encode(data) {
|
|
48105
|
+
if (this.transportType === TRANSPORT_TYPE.WEB) {
|
|
48106
|
+
const encoded = this.webEncoder.encode(data);
|
|
48107
|
+
return encoded;
|
|
48108
|
+
}
|
|
48109
|
+
if (this.transportType === TRANSPORT_TYPE.REACT_NATIVE) {
|
|
48110
|
+
// React Native BLE Manager expects a number[] instead of a Uint8Array
|
|
48111
|
+
const encoded = [...buffer_1.from(data)];
|
|
48112
|
+
return encoded;
|
|
48113
|
+
}
|
|
48114
|
+
const encoded = buffer_1.from(data);
|
|
48115
|
+
return encoded;
|
|
48116
|
+
}
|
|
48117
|
+
decode(arrayBuffer) {
|
|
48118
|
+
if (this.transportType === TRANSPORT_TYPE.WEB) {
|
|
48119
|
+
const decoded = this.webDecoder.decode(arrayBuffer);
|
|
48120
|
+
return decoded;
|
|
48121
|
+
}
|
|
48122
|
+
// For React Native, and as a default
|
|
48123
|
+
const decoded = buffer_1.from(arrayBuffer).toString("utf-8");
|
|
48124
|
+
return decoded;
|
|
45744
48125
|
}
|
|
45745
|
-
return decoder.decode(data);
|
|
45746
48126
|
}
|
|
45747
48127
|
|
|
45748
48128
|
const ANDROID_MAX_MTU = 512;
|
|
@@ -45751,6 +48131,43 @@ const DEFAULT_ACTION_RESPONSE_TIMEOUT = 1000 * 60; // 1 minute
|
|
|
45751
48131
|
// Reverse BLUETOOTH_CHARACTERISTICS key/values for easy lookup
|
|
45752
48132
|
const CHARACTERISTIC_UUIDS_TO_NAMES = Object.fromEntries(Object.entries(BLUETOOTH_CHARACTERISTICS).map((entries) => entries.reverse()));
|
|
45753
48133
|
|
|
48134
|
+
function stitchChunks({ delimiter }) {
|
|
48135
|
+
return pipe(scan(([remainder], currentBuffer) => {
|
|
48136
|
+
const nextBuffer = remainder + currentBuffer;
|
|
48137
|
+
if (!nextBuffer.includes(delimiter)) {
|
|
48138
|
+
return [nextBuffer, ""];
|
|
48139
|
+
}
|
|
48140
|
+
if (nextBuffer.endsWith(delimiter)) {
|
|
48141
|
+
return ["", nextBuffer];
|
|
48142
|
+
}
|
|
48143
|
+
const remainderStart = nextBuffer.lastIndexOf(delimiter);
|
|
48144
|
+
const remainderIndex = remainderStart + delimiter.length;
|
|
48145
|
+
const nextPacket = nextBuffer.slice(0, remainderIndex);
|
|
48146
|
+
const nextRemainder = nextBuffer.slice(remainderIndex);
|
|
48147
|
+
return [nextRemainder, nextPacket];
|
|
48148
|
+
}, ["", ""]), map(([, nextPacket]) => nextPacket.slice(0, -delimiter.length)), filter((nextPacket) => !!nextPacket.length));
|
|
48149
|
+
}
|
|
48150
|
+
|
|
48151
|
+
/**
|
|
48152
|
+
* @hidden
|
|
48153
|
+
*/
|
|
48154
|
+
function decodeJSONChunks({ textCodec, characteristicName, delimiter, addLog }) {
|
|
48155
|
+
return pipe(map((arrayBuffer) => {
|
|
48156
|
+
const decoded = textCodec.decode(arrayBuffer);
|
|
48157
|
+
addLog(`Received chunk with buffer size of ${arrayBuffer.byteLength} and decoded size ${decoded.length} for ${characteristicName} characteristic: \n${decoded}`);
|
|
48158
|
+
return decoded;
|
|
48159
|
+
}), stitchChunks({ delimiter }), map((payload) => {
|
|
48160
|
+
var _a;
|
|
48161
|
+
try {
|
|
48162
|
+
return JSON.parse(payload);
|
|
48163
|
+
}
|
|
48164
|
+
catch (error) {
|
|
48165
|
+
addLog(`Failed to parse JSON for ${characteristicName} characteristic. Falling back to unparsed string. ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
|
|
48166
|
+
return payload;
|
|
48167
|
+
}
|
|
48168
|
+
}));
|
|
48169
|
+
}
|
|
48170
|
+
|
|
45754
48171
|
var __awaiter$d = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
45755
48172
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
45756
48173
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -45766,6 +48183,7 @@ const defaultOptions$1 = {
|
|
|
45766
48183
|
class WebBluetoothTransport {
|
|
45767
48184
|
constructor(options = {}) {
|
|
45768
48185
|
this.type = TRANSPORT_TYPE.WEB;
|
|
48186
|
+
this.textCodec = new TextCodec(this.type);
|
|
45769
48187
|
this.characteristicsByName = {};
|
|
45770
48188
|
this.connection$ = new BehaviorSubject(BLUETOOTH_CONNECTION.DISCONNECTED);
|
|
45771
48189
|
this.pendingActions$ = new BehaviorSubject([]);
|
|
@@ -45945,7 +48363,7 @@ class WebBluetoothTransport {
|
|
|
45945
48363
|
return (_a = this.characteristicsByName) === null || _a === void 0 ? void 0 : _a[characteristicName];
|
|
45946
48364
|
});
|
|
45947
48365
|
}
|
|
45948
|
-
subscribeToCharacteristic({ characteristicName, manageNotifications = true }) {
|
|
48366
|
+
subscribeToCharacteristic({ characteristicName, manageNotifications = true, skipJSONDecoding = false }) {
|
|
45949
48367
|
const data$ = defer(() => this.getCharacteristicByName(characteristicName)).pipe(switchMap((characteristic) => __awaiter$d(this, void 0, void 0, function* () {
|
|
45950
48368
|
var _a;
|
|
45951
48369
|
if (this.isConnected() && manageNotifications) {
|
|
@@ -45971,33 +48389,17 @@ class WebBluetoothTransport {
|
|
|
45971
48389
|
}
|
|
45972
48390
|
}
|
|
45973
48391
|
}));
|
|
45974
|
-
}), map((event) =>
|
|
45975
|
-
|
|
45976
|
-
|
|
45977
|
-
|
|
45978
|
-
|
|
45979
|
-
|
|
45980
|
-
|
|
45981
|
-
|
|
45982
|
-
|
|
45983
|
-
|
|
45984
|
-
|
|
45985
|
-
this.addLog(`Failed to parse JSON for ${characteristicName} characteristic. Falling back to unparsed string. ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
|
|
45986
|
-
return payload;
|
|
45987
|
-
}
|
|
45988
|
-
})
|
|
45989
|
-
// when streaming at ultra-low latency, the logs will slow down rendering
|
|
45990
|
-
// tap((data) => {
|
|
45991
|
-
// this.addLog(
|
|
45992
|
-
// `Received data for ${characteristicName} characteristic: \n${JSON.stringify(
|
|
45993
|
-
// data,
|
|
45994
|
-
// null,
|
|
45995
|
-
// 2
|
|
45996
|
-
// )}`
|
|
45997
|
-
// );
|
|
45998
|
-
// })
|
|
45999
|
-
);
|
|
46000
|
-
return this.connection$.pipe(switchMap((connection) => connection === BLUETOOTH_CONNECTION.CONNECTED ? data$ : NEVER));
|
|
48392
|
+
}), map((event) => event.target.value.buffer));
|
|
48393
|
+
return this.connection$.pipe(switchMap((connection) => connection === BLUETOOTH_CONNECTION.CONNECTED
|
|
48394
|
+
? data$.pipe(skipJSONDecoding
|
|
48395
|
+
? identity // noop
|
|
48396
|
+
: decodeJSONChunks({
|
|
48397
|
+
textCodec: this.textCodec,
|
|
48398
|
+
characteristicName,
|
|
48399
|
+
delimiter: BLUETOOTH_CHUNK_DELIMITER,
|
|
48400
|
+
addLog: (message) => this.addLog(message)
|
|
48401
|
+
}))
|
|
48402
|
+
: NEVER));
|
|
46001
48403
|
}
|
|
46002
48404
|
readCharacteristic(characteristicName, parse = false) {
|
|
46003
48405
|
return __awaiter$d(this, void 0, void 0, function* () {
|
|
@@ -46008,9 +48410,9 @@ class WebBluetoothTransport {
|
|
|
46008
48410
|
this.addLog(`Did not fund ${characteristicName} characteristic`);
|
|
46009
48411
|
return Promise.reject(`Did not find characteristic by the name: ${characteristicName}`);
|
|
46010
48412
|
}
|
|
46011
|
-
const
|
|
46012
|
-
const
|
|
46013
|
-
const decodedValue = decode
|
|
48413
|
+
const dataview = yield characteristic.readValue();
|
|
48414
|
+
const arrayBuffer = dataview.buffer;
|
|
48415
|
+
const decodedValue = this.textCodec.decode(arrayBuffer);
|
|
46014
48416
|
const data = parse ? JSON.parse(decodedValue) : decodedValue;
|
|
46015
48417
|
this.addLog(`Received read data from ${characteristicName} characteristic: \n${data}`);
|
|
46016
48418
|
return data;
|
|
@@ -46028,7 +48430,7 @@ class WebBluetoothTransport {
|
|
|
46028
48430
|
this.addLog(`Did not fund ${characteristicName} characteristic`);
|
|
46029
48431
|
return Promise.reject(`Did not find characteristic by the name: ${characteristicName}`);
|
|
46030
48432
|
}
|
|
46031
|
-
const encoded = encode
|
|
48433
|
+
const encoded = this.textCodec.encode(data);
|
|
46032
48434
|
yield characteristic.writeValueWithResponse(encoded);
|
|
46033
48435
|
});
|
|
46034
48436
|
}
|
|
@@ -46171,6 +48573,7 @@ const defaultOptions$2 = {
|
|
|
46171
48573
|
class ReactNativeTransport {
|
|
46172
48574
|
constructor(options) {
|
|
46173
48575
|
this.type = TRANSPORT_TYPE.REACT_NATIVE;
|
|
48576
|
+
this.textCodec = new TextCodec(this.type);
|
|
46174
48577
|
this.characteristicsByName = {};
|
|
46175
48578
|
this.connection$ = new BehaviorSubject(BLUETOOTH_CONNECTION.DISCONNECTED);
|
|
46176
48579
|
this.pendingActions$ = new BehaviorSubject([]);
|
|
@@ -46321,7 +48724,8 @@ class ReactNativeTransport {
|
|
|
46321
48724
|
// it only has peripheral.advertising.localName as deviceNickname
|
|
46322
48725
|
// and OS v16 has both as deviceNickname
|
|
46323
48726
|
const peripheralName = (_c = (_b = (_a = peripheral === null || peripheral === void 0 ? void 0 : peripheral.advertising) === null || _a === void 0 ? void 0 : _a.localName) !== null && _b !== void 0 ? _b : peripheral.name) !== null && _c !== void 0 ? _c : "";
|
|
46324
|
-
const manufactureDataString = (_h = (_g =
|
|
48727
|
+
const manufactureDataString = (_h = (_g = this.textCodec
|
|
48728
|
+
.decode((_f = (_e = (_d = peripheral === null || peripheral === void 0 ? void 0 : peripheral.advertising) === null || _d === void 0 ? void 0 : _d.manufacturerData) === null || _e === void 0 ? void 0 : _e.bytes) !== null && _f !== void 0 ? _f : [])) === null || _g === void 0 ? void 0 : _g.slice) === null || _h === void 0 ? void 0 : _h.call(_g, 2); // First 2 bytes are reserved for the Neurosity company code
|
|
46325
48729
|
return Object.assign(Object.assign({}, acc), { [peripheral.id]: Object.assign(Object.assign({}, peripheral), { name: peripheralName, manufactureDataString }) });
|
|
46326
48730
|
}, {}), distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)), map((peripheralMap) => Object.values(peripheralMap)), share());
|
|
46327
48731
|
return peripherals$;
|
|
@@ -46396,7 +48800,7 @@ class ReactNativeTransport {
|
|
|
46396
48800
|
}
|
|
46397
48801
|
return (_a = this.characteristicsByName) === null || _a === void 0 ? void 0 : _a[characteristicName];
|
|
46398
48802
|
}
|
|
46399
|
-
subscribeToCharacteristic({ characteristicName, manageNotifications = true }) {
|
|
48803
|
+
subscribeToCharacteristic({ characteristicName, manageNotifications = true, skipJSONDecoding = false }) {
|
|
46400
48804
|
const getData = ({ peripheralId, serviceUUID, characteristicUUID }) => defer(() => __awaiter$e(this, void 0, void 0, function* () {
|
|
46401
48805
|
var _a;
|
|
46402
48806
|
if (manageNotifications) {
|
|
@@ -46419,18 +48823,16 @@ class ReactNativeTransport {
|
|
|
46419
48823
|
this.addLog(`Attemped to stop notifications for ${characteristicName} characteristic: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`);
|
|
46420
48824
|
}
|
|
46421
48825
|
}
|
|
46422
|
-
})), filter(({ characteristic }) => characteristic === characteristicUUID), map(({ value }) =>
|
|
46423
|
-
var _a;
|
|
46424
|
-
try {
|
|
46425
|
-
return JSON.parse(payload);
|
|
46426
|
-
}
|
|
46427
|
-
catch (error) {
|
|
46428
|
-
this.addLog(`Failed to parse JSON for ${characteristicName} characteristic. Falling back to unparsed string. ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
|
|
46429
|
-
return payload;
|
|
46430
|
-
}
|
|
46431
|
-
}));
|
|
48826
|
+
})), filter(({ characteristic }) => characteristic === characteristicUUID), map(({ value }) => new Uint8Array(value)));
|
|
46432
48827
|
return this.connection$.pipe(switchMap((connection) => connection === BLUETOOTH_CONNECTION.CONNECTED
|
|
46433
|
-
? getData(this.getCharacteristicByName(characteristicName))
|
|
48828
|
+
? getData(this.getCharacteristicByName(characteristicName)).pipe(skipJSONDecoding
|
|
48829
|
+
? identity // noop
|
|
48830
|
+
: decodeJSONChunks({
|
|
48831
|
+
textCodec: this.textCodec,
|
|
48832
|
+
characteristicName,
|
|
48833
|
+
delimiter: BLUETOOTH_CHUNK_DELIMITER,
|
|
48834
|
+
addLog: (message) => this.addLog(message)
|
|
48835
|
+
}))
|
|
46434
48836
|
: NEVER));
|
|
46435
48837
|
}
|
|
46436
48838
|
readCharacteristic(characteristicName, parse = false) {
|
|
@@ -46443,7 +48845,7 @@ class ReactNativeTransport {
|
|
|
46443
48845
|
}
|
|
46444
48846
|
try {
|
|
46445
48847
|
const value = yield this.BleManager.read(peripheralId, serviceUUID, characteristicUUID);
|
|
46446
|
-
const decodedValue = decode
|
|
48848
|
+
const decodedValue = this.textCodec.decode(new Uint8Array(value));
|
|
46447
48849
|
const data = parse ? JSON.parse(decodedValue) : decodedValue;
|
|
46448
48850
|
this.addLog(`Received read data from ${characteristicName} characteristic: \n${data}`);
|
|
46449
48851
|
return data;
|
|
@@ -46460,7 +48862,7 @@ class ReactNativeTransport {
|
|
|
46460
48862
|
if (!characteristicUUID) {
|
|
46461
48863
|
return Promise.reject(new Error(`Did not find characteristic matching ${characteristicName}`));
|
|
46462
48864
|
}
|
|
46463
|
-
const encoded = encode
|
|
48865
|
+
const encoded = this.textCodec.encode(data);
|
|
46464
48866
|
yield this.BleManager.write(peripheralId, serviceUUID, characteristicUUID, encoded, REACT_NATIVE_MAX_BYTE_SIZE);
|
|
46465
48867
|
});
|
|
46466
48868
|
}
|
|
@@ -46612,15 +49014,21 @@ const epoch = ({ duration, interval: interval$$1, samplingRate, dataProp = defau
|
|
|
46612
49014
|
|
|
46613
49015
|
const EPOCH_BUFFER_SIZE = 16;
|
|
46614
49016
|
const SAMPLING_RATE_FALLBACK = 256; // Crown's sampling rate
|
|
49017
|
+
/** Size in bytes for each channel's payload. */
|
|
49018
|
+
const TimestampSize = 8; // UInt64
|
|
49019
|
+
const MarkerSize = 2; // UInt16
|
|
49020
|
+
const ChannelDataSize = 8; // Double
|
|
49021
|
+
/** Size in bytes for the static payload of every sample (Timestamp + Marker) */
|
|
49022
|
+
const SampleFixedSize = TimestampSize + MarkerSize;
|
|
46615
49023
|
/**
|
|
46616
49024
|
* @hidden
|
|
46617
49025
|
*/
|
|
46618
|
-
function
|
|
49026
|
+
function binaryBufferToEpoch(deviceInfo) {
|
|
46619
49027
|
var _a;
|
|
46620
49028
|
if (!(deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.samplingRate)) {
|
|
46621
49029
|
console.warn(`Didn't receive a sampling rate, defaulting to ${SAMPLING_RATE_FALLBACK}`);
|
|
46622
49030
|
}
|
|
46623
|
-
return pipe(
|
|
49031
|
+
return pipe(binaryBufferToSamples(deviceInfo.channels), epoch({
|
|
46624
49032
|
duration: EPOCH_BUFFER_SIZE,
|
|
46625
49033
|
interval: EPOCH_BUFFER_SIZE,
|
|
46626
49034
|
samplingRate: (_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.samplingRate) !== null && _a !== void 0 ? _a : SAMPLING_RATE_FALLBACK
|
|
@@ -46632,11 +49040,82 @@ function csvBufferToEpoch(deviceInfo) {
|
|
|
46632
49040
|
/**
|
|
46633
49041
|
* @hidden
|
|
46634
49042
|
*/
|
|
46635
|
-
function
|
|
46636
|
-
return pipe(mergeMap((
|
|
46637
|
-
|
|
46638
|
-
|
|
46639
|
-
|
|
49043
|
+
function binaryBufferToSamples(channelCount) {
|
|
49044
|
+
return pipe(mergeMap((arrayBuffer) => {
|
|
49045
|
+
const buffer$$1 = buffer_1.from(arrayBuffer);
|
|
49046
|
+
const decoded = decode$1(buffer$$1, channelCount);
|
|
49047
|
+
return from(decoded); // `from` creates an Observable emission from each item (Sample) in the array
|
|
49048
|
+
}));
|
|
49049
|
+
}
|
|
49050
|
+
/**
|
|
49051
|
+
* @hidden
|
|
49052
|
+
*
|
|
49053
|
+
* Decode the supplied Buffer as a list of Sample.
|
|
49054
|
+
*
|
|
49055
|
+
* Supplied buffer's length must be multiple of
|
|
49056
|
+
* `encodedSampleSize(channelCount)`.
|
|
49057
|
+
*
|
|
49058
|
+
* NB: This method does not guarantee validity of decoded samples. When
|
|
49059
|
+
* supplied with a buffer of appropriate length, it will always return a
|
|
49060
|
+
* matching number of Sample8. Since the encoding protocol defines no
|
|
49061
|
+
* metadata/checksum, correctness must be guaranteed via test coverage.
|
|
49062
|
+
*
|
|
49063
|
+
* @param buffer Buffer with binary payload to decode.
|
|
49064
|
+
* @param channelCount Number of expected channels in each sample.
|
|
49065
|
+
*
|
|
49066
|
+
* @returns List of decoded Samples present in buffer.
|
|
49067
|
+
*/
|
|
49068
|
+
function decode$1(buffer$$1, channelCount) {
|
|
49069
|
+
let sampleLen = encodedSampleSize(channelCount);
|
|
49070
|
+
// Alternative: relax this check, process sampleLen at a time, discard remainder?
|
|
49071
|
+
if (buffer$$1.length % sampleLen != 0) {
|
|
49072
|
+
throw new Error(`buffer.length (${buffer$$1.length}) for ${channelCount} channels must be multiple of ${sampleLen}B)`);
|
|
49073
|
+
}
|
|
49074
|
+
let sampleCount = buffer$$1.length / sampleLen;
|
|
49075
|
+
let samples = new Array(sampleCount);
|
|
49076
|
+
for (let i = 0; i < sampleCount; i++) {
|
|
49077
|
+
let offset = i * sampleLen;
|
|
49078
|
+
let channelData = new Array(channelCount);
|
|
49079
|
+
// Read 8 bytes for timestamp & advance offset
|
|
49080
|
+
let ts = buffer$$1.readBigUInt64BE(offset);
|
|
49081
|
+
offset += TimestampSize;
|
|
49082
|
+
// Read 1 byte for marker & advance offset
|
|
49083
|
+
let marker = buffer$$1.readUInt16BE(offset);
|
|
49084
|
+
offset += MarkerSize;
|
|
49085
|
+
// Read 8 bytes for each channel & advance offset
|
|
49086
|
+
for (let i = 0; i < channelCount; i++) {
|
|
49087
|
+
channelData[i] = buffer$$1.readDoubleBE(offset);
|
|
49088
|
+
offset += ChannelDataSize;
|
|
49089
|
+
}
|
|
49090
|
+
samples[i] = {
|
|
49091
|
+
timestamp: Number(ts),
|
|
49092
|
+
// TODO: uncomment when ready
|
|
49093
|
+
// marker: marker,
|
|
49094
|
+
data: channelData
|
|
49095
|
+
};
|
|
49096
|
+
}
|
|
49097
|
+
return samples;
|
|
49098
|
+
}
|
|
49099
|
+
/**
|
|
49100
|
+
* @hidden
|
|
49101
|
+
*
|
|
49102
|
+
* Calculate the size of each sample based on the number of channels.
|
|
49103
|
+
*
|
|
49104
|
+
* Each sample has the following 3 segments:
|
|
49105
|
+
* - Timestamp: 8 bytes (UInt64); contains current time in millis since epoch)
|
|
49106
|
+
* - Marker: 2 bytes (UInt16); for classifier data
|
|
49107
|
+
* - Data: N * 8 bytes (Double), each entry representing data from a different
|
|
49108
|
+
* electrode.
|
|
49109
|
+
*
|
|
49110
|
+
* +-----------+--------+------------------+
|
|
49111
|
+
* | timestamp | marker | data (e1 ... eN) |
|
|
49112
|
+
* +-----------+--------+------------------+
|
|
49113
|
+
*
|
|
49114
|
+
* The number of entries for Data varies per hardware model. It can be assumed
|
|
49115
|
+
* to remain constant for the lifetime of the program.
|
|
49116
|
+
*/
|
|
49117
|
+
function encodedSampleSize(channelCount) {
|
|
49118
|
+
return SampleFixedSize + channelCount * ChannelDataSize;
|
|
46640
49119
|
}
|
|
46641
49120
|
|
|
46642
49121
|
var __awaiter$f = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
@@ -46694,9 +49173,10 @@ class BluetoothClient {
|
|
|
46694
49173
|
this._focus$ = this._subscribeWhileAuthenticated("focus");
|
|
46695
49174
|
this._calm$ = this._subscribeWhileAuthenticated("calm");
|
|
46696
49175
|
this._accelerometer$ = this._subscribeWhileAuthenticated("accelerometer");
|
|
46697
|
-
this._brainwavesRaw$ = this._subscribeWhileAuthenticated("raw"
|
|
46698
|
-
|
|
46699
|
-
|
|
49176
|
+
this._brainwavesRaw$ = this._subscribeWhileAuthenticated("raw", true // skipJSONDecoding
|
|
49177
|
+
);
|
|
49178
|
+
this._brainwavesRawUnfiltered$ = this._subscribeWhileAuthenticated("rawUnfiltered", true // skipJSONDecoding
|
|
49179
|
+
);
|
|
46700
49180
|
this._brainwavesPSD$ = this._subscribeWhileAuthenticated("psd");
|
|
46701
49181
|
this._brainwavesPowerByBand$ =
|
|
46702
49182
|
this._subscribeWhileAuthenticated("powerByBand");
|
|
@@ -46818,10 +49298,11 @@ class BluetoothClient {
|
|
|
46818
49298
|
return yield getter();
|
|
46819
49299
|
});
|
|
46820
49300
|
}
|
|
46821
|
-
_subscribeWhileAuthenticated(characteristicName) {
|
|
49301
|
+
_subscribeWhileAuthenticated(characteristicName, skipJSONDecoding = false) {
|
|
46822
49302
|
return this.osHasBluetoothSupport$.pipe(switchMap((osHasBluetoothSupport) => osHasBluetoothSupport ? this.isAuthenticated$ : EMPTY), distinctUntilChanged(), switchMap((isAuthenticated) => isAuthenticated
|
|
46823
49303
|
? this.transport.subscribeToCharacteristic({
|
|
46824
|
-
characteristicName
|
|
49304
|
+
characteristicName,
|
|
49305
|
+
skipJSONDecoding
|
|
46825
49306
|
})
|
|
46826
49307
|
: EMPTY), share());
|
|
46827
49308
|
}
|
|
@@ -46838,9 +49319,9 @@ class BluetoothClient {
|
|
|
46838
49319
|
switch (label) {
|
|
46839
49320
|
default:
|
|
46840
49321
|
case "raw":
|
|
46841
|
-
return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._brainwavesRaw$.pipe(
|
|
49322
|
+
return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._brainwavesRaw$.pipe(binaryBufferToEpoch(deviceInfo))));
|
|
46842
49323
|
case "rawUnfiltered":
|
|
46843
|
-
return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._brainwavesRawUnfiltered$.pipe(
|
|
49324
|
+
return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._brainwavesRawUnfiltered$.pipe(binaryBufferToEpoch(deviceInfo))));
|
|
46844
49325
|
case "psd":
|
|
46845
49326
|
return this._brainwavesPSD$;
|
|
46846
49327
|
case "powerByBand":
|
|
@@ -46980,10 +49461,6 @@ var constants = {
|
|
|
46980
49461
|
MAX_SAFE_COMPONENT_LENGTH,
|
|
46981
49462
|
};
|
|
46982
49463
|
|
|
46983
|
-
function createCommonjsModule(fn, module) {
|
|
46984
|
-
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
46985
|
-
}
|
|
46986
|
-
|
|
46987
49464
|
var re_1 = createCommonjsModule(function (module, exports) {
|
|
46988
49465
|
const { MAX_SAFE_COMPONENT_LENGTH } = constants;
|
|
46989
49466
|
|