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