@jsenv/core 39.3.12 → 39.4.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/js/ws.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import require$$0 from "stream";
2
- import require$$0$3 from "events";
2
+ import require$$0$2 from "events";
3
3
  import require$$2 from "http";
4
4
  import require$$1 from "crypto";
5
5
  import require$$0$1 from "zlib";
6
- import require$$0$2 from "buffer";
7
6
  import require$$1$1 from "https";
8
7
  import require$$3 from "net";
9
8
  import require$$4 from "tls";
@@ -736,9 +735,2069 @@ function inflateOnError(err) {
736
735
 
737
736
  var validation = {exports: {}};
738
737
 
738
+ var buffer = {};
739
+
740
+ var base64Js = {};
741
+
742
+ base64Js.byteLength = byteLength;
743
+ base64Js.toByteArray = toByteArray;
744
+ base64Js.fromByteArray = fromByteArray;
745
+
746
+ var lookup = [];
747
+ var revLookup = [];
748
+ var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
749
+
750
+ var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
751
+ for (var i = 0, len = code.length; i < len; ++i) {
752
+ lookup[i] = code[i];
753
+ revLookup[code.charCodeAt(i)] = i;
754
+ }
755
+
756
+ // Support decoding URL-safe base64 strings, as Node.js does.
757
+ // See: https://en.wikipedia.org/wiki/Base64#URL_applications
758
+ revLookup['-'.charCodeAt(0)] = 62;
759
+ revLookup['_'.charCodeAt(0)] = 63;
760
+
761
+ function getLens (b64) {
762
+ var len = b64.length;
763
+
764
+ if (len % 4 > 0) {
765
+ throw new Error('Invalid string. Length must be a multiple of 4')
766
+ }
767
+
768
+ // Trim off extra bytes after placeholder bytes are found
769
+ // See: https://github.com/beatgammit/base64-js/issues/42
770
+ var validLen = b64.indexOf('=');
771
+ if (validLen === -1) validLen = len;
772
+
773
+ var placeHoldersLen = validLen === len
774
+ ? 0
775
+ : 4 - (validLen % 4);
776
+
777
+ return [validLen, placeHoldersLen]
778
+ }
779
+
780
+ // base64 is 4/3 + up to two characters of the original data
781
+ function byteLength (b64) {
782
+ var lens = getLens(b64);
783
+ var validLen = lens[0];
784
+ var placeHoldersLen = lens[1];
785
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
786
+ }
787
+
788
+ function _byteLength (b64, validLen, placeHoldersLen) {
789
+ return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
790
+ }
791
+
792
+ function toByteArray (b64) {
793
+ var tmp;
794
+ var lens = getLens(b64);
795
+ var validLen = lens[0];
796
+ var placeHoldersLen = lens[1];
797
+
798
+ var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
799
+
800
+ var curByte = 0;
801
+
802
+ // if there are placeholders, only get up to the last complete 4 chars
803
+ var len = placeHoldersLen > 0
804
+ ? validLen - 4
805
+ : validLen;
806
+
807
+ var i;
808
+ for (i = 0; i < len; i += 4) {
809
+ tmp =
810
+ (revLookup[b64.charCodeAt(i)] << 18) |
811
+ (revLookup[b64.charCodeAt(i + 1)] << 12) |
812
+ (revLookup[b64.charCodeAt(i + 2)] << 6) |
813
+ revLookup[b64.charCodeAt(i + 3)];
814
+ arr[curByte++] = (tmp >> 16) & 0xFF;
815
+ arr[curByte++] = (tmp >> 8) & 0xFF;
816
+ arr[curByte++] = tmp & 0xFF;
817
+ }
818
+
819
+ if (placeHoldersLen === 2) {
820
+ tmp =
821
+ (revLookup[b64.charCodeAt(i)] << 2) |
822
+ (revLookup[b64.charCodeAt(i + 1)] >> 4);
823
+ arr[curByte++] = tmp & 0xFF;
824
+ }
825
+
826
+ if (placeHoldersLen === 1) {
827
+ tmp =
828
+ (revLookup[b64.charCodeAt(i)] << 10) |
829
+ (revLookup[b64.charCodeAt(i + 1)] << 4) |
830
+ (revLookup[b64.charCodeAt(i + 2)] >> 2);
831
+ arr[curByte++] = (tmp >> 8) & 0xFF;
832
+ arr[curByte++] = tmp & 0xFF;
833
+ }
834
+
835
+ return arr
836
+ }
837
+
838
+ function tripletToBase64 (num) {
839
+ return lookup[num >> 18 & 0x3F] +
840
+ lookup[num >> 12 & 0x3F] +
841
+ lookup[num >> 6 & 0x3F] +
842
+ lookup[num & 0x3F]
843
+ }
844
+
845
+ function encodeChunk (uint8, start, end) {
846
+ var tmp;
847
+ var output = [];
848
+ for (var i = start; i < end; i += 3) {
849
+ tmp =
850
+ ((uint8[i] << 16) & 0xFF0000) +
851
+ ((uint8[i + 1] << 8) & 0xFF00) +
852
+ (uint8[i + 2] & 0xFF);
853
+ output.push(tripletToBase64(tmp));
854
+ }
855
+ return output.join('')
856
+ }
857
+
858
+ function fromByteArray (uint8) {
859
+ var tmp;
860
+ var len = uint8.length;
861
+ var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
862
+ var parts = [];
863
+ var maxChunkLength = 16383; // must be multiple of 3
864
+
865
+ // go through the array every three bytes, we'll deal with trailing stuff later
866
+ for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
867
+ parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)));
868
+ }
869
+
870
+ // pad the end with zeros, but make sure to not forget the extra bytes
871
+ if (extraBytes === 1) {
872
+ tmp = uint8[len - 1];
873
+ parts.push(
874
+ lookup[tmp >> 2] +
875
+ lookup[(tmp << 4) & 0x3F] +
876
+ '=='
877
+ );
878
+ } else if (extraBytes === 2) {
879
+ tmp = (uint8[len - 2] << 8) + uint8[len - 1];
880
+ parts.push(
881
+ lookup[tmp >> 10] +
882
+ lookup[(tmp >> 4) & 0x3F] +
883
+ lookup[(tmp << 2) & 0x3F] +
884
+ '='
885
+ );
886
+ }
887
+
888
+ return parts.join('')
889
+ }
890
+
891
+ var ieee754 = {};
892
+
893
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
894
+
895
+ ieee754.read = function (buffer, offset, isLE, mLen, nBytes) {
896
+ var e, m;
897
+ var eLen = (nBytes * 8) - mLen - 1;
898
+ var eMax = (1 << eLen) - 1;
899
+ var eBias = eMax >> 1;
900
+ var nBits = -7;
901
+ var i = isLE ? (nBytes - 1) : 0;
902
+ var d = isLE ? -1 : 1;
903
+ var s = buffer[offset + i];
904
+
905
+ i += d;
906
+
907
+ e = s & ((1 << (-nBits)) - 1);
908
+ s >>= (-nBits);
909
+ nBits += eLen;
910
+ for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
911
+
912
+ m = e & ((1 << (-nBits)) - 1);
913
+ e >>= (-nBits);
914
+ nBits += mLen;
915
+ for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
916
+
917
+ if (e === 0) {
918
+ e = 1 - eBias;
919
+ } else if (e === eMax) {
920
+ return m ? NaN : ((s ? -1 : 1) * Infinity)
921
+ } else {
922
+ m = m + Math.pow(2, mLen);
923
+ e = e - eBias;
924
+ }
925
+ return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
926
+ };
927
+
928
+ ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes) {
929
+ var e, m, c;
930
+ var eLen = (nBytes * 8) - mLen - 1;
931
+ var eMax = (1 << eLen) - 1;
932
+ var eBias = eMax >> 1;
933
+ var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0);
934
+ var i = isLE ? 0 : (nBytes - 1);
935
+ var d = isLE ? 1 : -1;
936
+ var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
937
+
938
+ value = Math.abs(value);
939
+
940
+ if (isNaN(value) || value === Infinity) {
941
+ m = isNaN(value) ? 1 : 0;
942
+ e = eMax;
943
+ } else {
944
+ e = Math.floor(Math.log(value) / Math.LN2);
945
+ if (value * (c = Math.pow(2, -e)) < 1) {
946
+ e--;
947
+ c *= 2;
948
+ }
949
+ if (e + eBias >= 1) {
950
+ value += rt / c;
951
+ } else {
952
+ value += rt * Math.pow(2, 1 - eBias);
953
+ }
954
+ if (value * c >= 2) {
955
+ e++;
956
+ c /= 2;
957
+ }
958
+
959
+ if (e + eBias >= eMax) {
960
+ m = 0;
961
+ e = eMax;
962
+ } else if (e + eBias >= 1) {
963
+ m = ((value * c) - 1) * Math.pow(2, mLen);
964
+ e = e + eBias;
965
+ } else {
966
+ m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
967
+ e = 0;
968
+ }
969
+ }
970
+
971
+ for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
972
+
973
+ e = (e << mLen) | m;
974
+ eLen += mLen;
975
+ for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
976
+
977
+ buffer[offset + i - d] |= s * 128;
978
+ };
979
+
980
+ /*!
981
+ * The buffer module from node.js, for the browser.
982
+ *
983
+ * @author Feross Aboukhadijeh <https://feross.org>
984
+ * @license MIT
985
+ */
986
+
987
+ (function (exports) {
988
+
989
+ var base64 = base64Js;
990
+ var ieee754$1 = ieee754;
991
+ var customInspectSymbol =
992
+ (typeof Symbol === 'function' && typeof Symbol['for'] === 'function') // eslint-disable-line dot-notation
993
+ ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
994
+ : null;
995
+
996
+ exports.Buffer = Buffer;
997
+ exports.SlowBuffer = SlowBuffer;
998
+ exports.INSPECT_MAX_BYTES = 50;
999
+
1000
+ var K_MAX_LENGTH = 0x7fffffff;
1001
+ exports.kMaxLength = K_MAX_LENGTH;
1002
+
1003
+ /**
1004
+ * If `Buffer.TYPED_ARRAY_SUPPORT`:
1005
+ * === true Use Uint8Array implementation (fastest)
1006
+ * === false Print warning and recommend using `buffer` v4.x which has an Object
1007
+ * implementation (most compatible, even IE6)
1008
+ *
1009
+ * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
1010
+ * Opera 11.6+, iOS 4.2+.
1011
+ *
1012
+ * We report that the browser does not support typed arrays if the are not subclassable
1013
+ * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
1014
+ * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
1015
+ * for __proto__ and has a buggy typed array implementation.
1016
+ */
1017
+ Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
1018
+
1019
+ if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' &&
1020
+ typeof console.error === 'function') {
1021
+ console.error(
1022
+ 'This browser lacks typed array (Uint8Array) support which is required by ' +
1023
+ '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.'
1024
+ );
1025
+ }
1026
+
1027
+ function typedArraySupport () {
1028
+ // Can typed array instances can be augmented?
1029
+ try {
1030
+ var arr = new Uint8Array(1);
1031
+ var proto = { foo: function () { return 42 } };
1032
+ Object.setPrototypeOf(proto, Uint8Array.prototype);
1033
+ Object.setPrototypeOf(arr, proto);
1034
+ return arr.foo() === 42
1035
+ } catch (e) {
1036
+ return false
1037
+ }
1038
+ }
1039
+
1040
+ Object.defineProperty(Buffer.prototype, 'parent', {
1041
+ enumerable: true,
1042
+ get: function () {
1043
+ if (!Buffer.isBuffer(this)) return undefined
1044
+ return this.buffer
1045
+ }
1046
+ });
1047
+
1048
+ Object.defineProperty(Buffer.prototype, 'offset', {
1049
+ enumerable: true,
1050
+ get: function () {
1051
+ if (!Buffer.isBuffer(this)) return undefined
1052
+ return this.byteOffset
1053
+ }
1054
+ });
1055
+
1056
+ function createBuffer (length) {
1057
+ if (length > K_MAX_LENGTH) {
1058
+ throw new RangeError('The value "' + length + '" is invalid for option "size"')
1059
+ }
1060
+ // Return an augmented `Uint8Array` instance
1061
+ var buf = new Uint8Array(length);
1062
+ Object.setPrototypeOf(buf, Buffer.prototype);
1063
+ return buf
1064
+ }
1065
+
1066
+ /**
1067
+ * The Buffer constructor returns instances of `Uint8Array` that have their
1068
+ * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
1069
+ * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
1070
+ * and the `Uint8Array` methods. Square bracket notation works as expected -- it
1071
+ * returns a single octet.
1072
+ *
1073
+ * The `Uint8Array` prototype remains unmodified.
1074
+ */
1075
+
1076
+ function Buffer (arg, encodingOrOffset, length) {
1077
+ // Common case.
1078
+ if (typeof arg === 'number') {
1079
+ if (typeof encodingOrOffset === 'string') {
1080
+ throw new TypeError(
1081
+ 'The "string" argument must be of type string. Received type number'
1082
+ )
1083
+ }
1084
+ return allocUnsafe(arg)
1085
+ }
1086
+ return from(arg, encodingOrOffset, length)
1087
+ }
1088
+
1089
+ Buffer.poolSize = 8192; // not used by this implementation
1090
+
1091
+ function from (value, encodingOrOffset, length) {
1092
+ if (typeof value === 'string') {
1093
+ return fromString(value, encodingOrOffset)
1094
+ }
1095
+
1096
+ if (ArrayBuffer.isView(value)) {
1097
+ return fromArrayView(value)
1098
+ }
1099
+
1100
+ if (value == null) {
1101
+ throw new TypeError(
1102
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
1103
+ 'or Array-like Object. Received type ' + (typeof value)
1104
+ )
1105
+ }
1106
+
1107
+ if (isInstance(value, ArrayBuffer) ||
1108
+ (value && isInstance(value.buffer, ArrayBuffer))) {
1109
+ return fromArrayBuffer(value, encodingOrOffset, length)
1110
+ }
1111
+
1112
+ if (typeof SharedArrayBuffer !== 'undefined' &&
1113
+ (isInstance(value, SharedArrayBuffer) ||
1114
+ (value && isInstance(value.buffer, SharedArrayBuffer)))) {
1115
+ return fromArrayBuffer(value, encodingOrOffset, length)
1116
+ }
1117
+
1118
+ if (typeof value === 'number') {
1119
+ throw new TypeError(
1120
+ 'The "value" argument must not be of type number. Received type number'
1121
+ )
1122
+ }
1123
+
1124
+ var valueOf = value.valueOf && value.valueOf();
1125
+ if (valueOf != null && valueOf !== value) {
1126
+ return Buffer.from(valueOf, encodingOrOffset, length)
1127
+ }
1128
+
1129
+ var b = fromObject(value);
1130
+ if (b) return b
1131
+
1132
+ if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null &&
1133
+ typeof value[Symbol.toPrimitive] === 'function') {
1134
+ return Buffer.from(
1135
+ value[Symbol.toPrimitive]('string'), encodingOrOffset, length
1136
+ )
1137
+ }
1138
+
1139
+ throw new TypeError(
1140
+ 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
1141
+ 'or Array-like Object. Received type ' + (typeof value)
1142
+ )
1143
+ }
1144
+
1145
+ /**
1146
+ * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
1147
+ * if value is a number.
1148
+ * Buffer.from(str[, encoding])
1149
+ * Buffer.from(array)
1150
+ * Buffer.from(buffer)
1151
+ * Buffer.from(arrayBuffer[, byteOffset[, length]])
1152
+ **/
1153
+ Buffer.from = function (value, encodingOrOffset, length) {
1154
+ return from(value, encodingOrOffset, length)
1155
+ };
1156
+
1157
+ // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
1158
+ // https://github.com/feross/buffer/pull/148
1159
+ Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
1160
+ Object.setPrototypeOf(Buffer, Uint8Array);
1161
+
1162
+ function assertSize (size) {
1163
+ if (typeof size !== 'number') {
1164
+ throw new TypeError('"size" argument must be of type number')
1165
+ } else if (size < 0) {
1166
+ throw new RangeError('The value "' + size + '" is invalid for option "size"')
1167
+ }
1168
+ }
1169
+
1170
+ function alloc (size, fill, encoding) {
1171
+ assertSize(size);
1172
+ if (size <= 0) {
1173
+ return createBuffer(size)
1174
+ }
1175
+ if (fill !== undefined) {
1176
+ // Only pay attention to encoding if it's a string. This
1177
+ // prevents accidentally sending in a number that would
1178
+ // be interpreted as a start offset.
1179
+ return typeof encoding === 'string'
1180
+ ? createBuffer(size).fill(fill, encoding)
1181
+ : createBuffer(size).fill(fill)
1182
+ }
1183
+ return createBuffer(size)
1184
+ }
1185
+
1186
+ /**
1187
+ * Creates a new filled Buffer instance.
1188
+ * alloc(size[, fill[, encoding]])
1189
+ **/
1190
+ Buffer.alloc = function (size, fill, encoding) {
1191
+ return alloc(size, fill, encoding)
1192
+ };
1193
+
1194
+ function allocUnsafe (size) {
1195
+ assertSize(size);
1196
+ return createBuffer(size < 0 ? 0 : checked(size) | 0)
1197
+ }
1198
+
1199
+ /**
1200
+ * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
1201
+ * */
1202
+ Buffer.allocUnsafe = function (size) {
1203
+ return allocUnsafe(size)
1204
+ };
1205
+ /**
1206
+ * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
1207
+ */
1208
+ Buffer.allocUnsafeSlow = function (size) {
1209
+ return allocUnsafe(size)
1210
+ };
1211
+
1212
+ function fromString (string, encoding) {
1213
+ if (typeof encoding !== 'string' || encoding === '') {
1214
+ encoding = 'utf8';
1215
+ }
1216
+
1217
+ if (!Buffer.isEncoding(encoding)) {
1218
+ throw new TypeError('Unknown encoding: ' + encoding)
1219
+ }
1220
+
1221
+ var length = byteLength(string, encoding) | 0;
1222
+ var buf = createBuffer(length);
1223
+
1224
+ var actual = buf.write(string, encoding);
1225
+
1226
+ if (actual !== length) {
1227
+ // Writing a hex string, for example, that contains invalid characters will
1228
+ // cause everything after the first invalid character to be ignored. (e.g.
1229
+ // 'abxxcd' will be treated as 'ab')
1230
+ buf = buf.slice(0, actual);
1231
+ }
1232
+
1233
+ return buf
1234
+ }
1235
+
1236
+ function fromArrayLike (array) {
1237
+ var length = array.length < 0 ? 0 : checked(array.length) | 0;
1238
+ var buf = createBuffer(length);
1239
+ for (var i = 0; i < length; i += 1) {
1240
+ buf[i] = array[i] & 255;
1241
+ }
1242
+ return buf
1243
+ }
1244
+
1245
+ function fromArrayView (arrayView) {
1246
+ if (isInstance(arrayView, Uint8Array)) {
1247
+ var copy = new Uint8Array(arrayView);
1248
+ return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength)
1249
+ }
1250
+ return fromArrayLike(arrayView)
1251
+ }
1252
+
1253
+ function fromArrayBuffer (array, byteOffset, length) {
1254
+ if (byteOffset < 0 || array.byteLength < byteOffset) {
1255
+ throw new RangeError('"offset" is outside of buffer bounds')
1256
+ }
1257
+
1258
+ if (array.byteLength < byteOffset + (length || 0)) {
1259
+ throw new RangeError('"length" is outside of buffer bounds')
1260
+ }
1261
+
1262
+ var buf;
1263
+ if (byteOffset === undefined && length === undefined) {
1264
+ buf = new Uint8Array(array);
1265
+ } else if (length === undefined) {
1266
+ buf = new Uint8Array(array, byteOffset);
1267
+ } else {
1268
+ buf = new Uint8Array(array, byteOffset, length);
1269
+ }
1270
+
1271
+ // Return an augmented `Uint8Array` instance
1272
+ Object.setPrototypeOf(buf, Buffer.prototype);
1273
+
1274
+ return buf
1275
+ }
1276
+
1277
+ function fromObject (obj) {
1278
+ if (Buffer.isBuffer(obj)) {
1279
+ var len = checked(obj.length) | 0;
1280
+ var buf = createBuffer(len);
1281
+
1282
+ if (buf.length === 0) {
1283
+ return buf
1284
+ }
1285
+
1286
+ obj.copy(buf, 0, 0, len);
1287
+ return buf
1288
+ }
1289
+
1290
+ if (obj.length !== undefined) {
1291
+ if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
1292
+ return createBuffer(0)
1293
+ }
1294
+ return fromArrayLike(obj)
1295
+ }
1296
+
1297
+ if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
1298
+ return fromArrayLike(obj.data)
1299
+ }
1300
+ }
1301
+
1302
+ function checked (length) {
1303
+ // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
1304
+ // length is NaN (which is otherwise coerced to zero.)
1305
+ if (length >= K_MAX_LENGTH) {
1306
+ throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
1307
+ 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes')
1308
+ }
1309
+ return length | 0
1310
+ }
1311
+
1312
+ function SlowBuffer (length) {
1313
+ if (+length != length) { // eslint-disable-line eqeqeq
1314
+ length = 0;
1315
+ }
1316
+ return Buffer.alloc(+length)
1317
+ }
1318
+
1319
+ Buffer.isBuffer = function isBuffer (b) {
1320
+ return b != null && b._isBuffer === true &&
1321
+ b !== Buffer.prototype // so Buffer.isBuffer(Buffer.prototype) will be false
1322
+ };
1323
+
1324
+ Buffer.compare = function compare (a, b) {
1325
+ if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
1326
+ if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
1327
+ if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
1328
+ throw new TypeError(
1329
+ 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array'
1330
+ )
1331
+ }
1332
+
1333
+ if (a === b) return 0
1334
+
1335
+ var x = a.length;
1336
+ var y = b.length;
1337
+
1338
+ for (var i = 0, len = Math.min(x, y); i < len; ++i) {
1339
+ if (a[i] !== b[i]) {
1340
+ x = a[i];
1341
+ y = b[i];
1342
+ break
1343
+ }
1344
+ }
1345
+
1346
+ if (x < y) return -1
1347
+ if (y < x) return 1
1348
+ return 0
1349
+ };
1350
+
1351
+ Buffer.isEncoding = function isEncoding (encoding) {
1352
+ switch (String(encoding).toLowerCase()) {
1353
+ case 'hex':
1354
+ case 'utf8':
1355
+ case 'utf-8':
1356
+ case 'ascii':
1357
+ case 'latin1':
1358
+ case 'binary':
1359
+ case 'base64':
1360
+ case 'ucs2':
1361
+ case 'ucs-2':
1362
+ case 'utf16le':
1363
+ case 'utf-16le':
1364
+ return true
1365
+ default:
1366
+ return false
1367
+ }
1368
+ };
1369
+
1370
+ Buffer.concat = function concat (list, length) {
1371
+ if (!Array.isArray(list)) {
1372
+ throw new TypeError('"list" argument must be an Array of Buffers')
1373
+ }
1374
+
1375
+ if (list.length === 0) {
1376
+ return Buffer.alloc(0)
1377
+ }
1378
+
1379
+ var i;
1380
+ if (length === undefined) {
1381
+ length = 0;
1382
+ for (i = 0; i < list.length; ++i) {
1383
+ length += list[i].length;
1384
+ }
1385
+ }
1386
+
1387
+ var buffer = Buffer.allocUnsafe(length);
1388
+ var pos = 0;
1389
+ for (i = 0; i < list.length; ++i) {
1390
+ var buf = list[i];
1391
+ if (isInstance(buf, Uint8Array)) {
1392
+ if (pos + buf.length > buffer.length) {
1393
+ Buffer.from(buf).copy(buffer, pos);
1394
+ } else {
1395
+ Uint8Array.prototype.set.call(
1396
+ buffer,
1397
+ buf,
1398
+ pos
1399
+ );
1400
+ }
1401
+ } else if (!Buffer.isBuffer(buf)) {
1402
+ throw new TypeError('"list" argument must be an Array of Buffers')
1403
+ } else {
1404
+ buf.copy(buffer, pos);
1405
+ }
1406
+ pos += buf.length;
1407
+ }
1408
+ return buffer
1409
+ };
1410
+
1411
+ function byteLength (string, encoding) {
1412
+ if (Buffer.isBuffer(string)) {
1413
+ return string.length
1414
+ }
1415
+ if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
1416
+ return string.byteLength
1417
+ }
1418
+ if (typeof string !== 'string') {
1419
+ throw new TypeError(
1420
+ 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
1421
+ 'Received type ' + typeof string
1422
+ )
1423
+ }
1424
+
1425
+ var len = string.length;
1426
+ var mustMatch = (arguments.length > 2 && arguments[2] === true);
1427
+ if (!mustMatch && len === 0) return 0
1428
+
1429
+ // Use a for loop to avoid recursion
1430
+ var loweredCase = false;
1431
+ for (;;) {
1432
+ switch (encoding) {
1433
+ case 'ascii':
1434
+ case 'latin1':
1435
+ case 'binary':
1436
+ return len
1437
+ case 'utf8':
1438
+ case 'utf-8':
1439
+ return utf8ToBytes(string).length
1440
+ case 'ucs2':
1441
+ case 'ucs-2':
1442
+ case 'utf16le':
1443
+ case 'utf-16le':
1444
+ return len * 2
1445
+ case 'hex':
1446
+ return len >>> 1
1447
+ case 'base64':
1448
+ return base64ToBytes(string).length
1449
+ default:
1450
+ if (loweredCase) {
1451
+ return mustMatch ? -1 : utf8ToBytes(string).length // assume utf8
1452
+ }
1453
+ encoding = ('' + encoding).toLowerCase();
1454
+ loweredCase = true;
1455
+ }
1456
+ }
1457
+ }
1458
+ Buffer.byteLength = byteLength;
1459
+
1460
+ function slowToString (encoding, start, end) {
1461
+ var loweredCase = false;
1462
+
1463
+ // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
1464
+ // property of a typed array.
1465
+
1466
+ // This behaves neither like String nor Uint8Array in that we set start/end
1467
+ // to their upper/lower bounds if the value passed is out of range.
1468
+ // undefined is handled specially as per ECMA-262 6th Edition,
1469
+ // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
1470
+ if (start === undefined || start < 0) {
1471
+ start = 0;
1472
+ }
1473
+ // Return early if start > this.length. Done here to prevent potential uint32
1474
+ // coercion fail below.
1475
+ if (start > this.length) {
1476
+ return ''
1477
+ }
1478
+
1479
+ if (end === undefined || end > this.length) {
1480
+ end = this.length;
1481
+ }
1482
+
1483
+ if (end <= 0) {
1484
+ return ''
1485
+ }
1486
+
1487
+ // Force coercion to uint32. This will also coerce falsey/NaN values to 0.
1488
+ end >>>= 0;
1489
+ start >>>= 0;
1490
+
1491
+ if (end <= start) {
1492
+ return ''
1493
+ }
1494
+
1495
+ if (!encoding) encoding = 'utf8';
1496
+
1497
+ while (true) {
1498
+ switch (encoding) {
1499
+ case 'hex':
1500
+ return hexSlice(this, start, end)
1501
+
1502
+ case 'utf8':
1503
+ case 'utf-8':
1504
+ return utf8Slice(this, start, end)
1505
+
1506
+ case 'ascii':
1507
+ return asciiSlice(this, start, end)
1508
+
1509
+ case 'latin1':
1510
+ case 'binary':
1511
+ return latin1Slice(this, start, end)
1512
+
1513
+ case 'base64':
1514
+ return base64Slice(this, start, end)
1515
+
1516
+ case 'ucs2':
1517
+ case 'ucs-2':
1518
+ case 'utf16le':
1519
+ case 'utf-16le':
1520
+ return utf16leSlice(this, start, end)
1521
+
1522
+ default:
1523
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
1524
+ encoding = (encoding + '').toLowerCase();
1525
+ loweredCase = true;
1526
+ }
1527
+ }
1528
+ }
1529
+
1530
+ // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
1531
+ // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
1532
+ // reliably in a browserify context because there could be multiple different
1533
+ // copies of the 'buffer' package in use. This method works even for Buffer
1534
+ // instances that were created from another copy of the `buffer` package.
1535
+ // See: https://github.com/feross/buffer/issues/154
1536
+ Buffer.prototype._isBuffer = true;
1537
+
1538
+ function swap (b, n, m) {
1539
+ var i = b[n];
1540
+ b[n] = b[m];
1541
+ b[m] = i;
1542
+ }
1543
+
1544
+ Buffer.prototype.swap16 = function swap16 () {
1545
+ var len = this.length;
1546
+ if (len % 2 !== 0) {
1547
+ throw new RangeError('Buffer size must be a multiple of 16-bits')
1548
+ }
1549
+ for (var i = 0; i < len; i += 2) {
1550
+ swap(this, i, i + 1);
1551
+ }
1552
+ return this
1553
+ };
1554
+
1555
+ Buffer.prototype.swap32 = function swap32 () {
1556
+ var len = this.length;
1557
+ if (len % 4 !== 0) {
1558
+ throw new RangeError('Buffer size must be a multiple of 32-bits')
1559
+ }
1560
+ for (var i = 0; i < len; i += 4) {
1561
+ swap(this, i, i + 3);
1562
+ swap(this, i + 1, i + 2);
1563
+ }
1564
+ return this
1565
+ };
1566
+
1567
+ Buffer.prototype.swap64 = function swap64 () {
1568
+ var len = this.length;
1569
+ if (len % 8 !== 0) {
1570
+ throw new RangeError('Buffer size must be a multiple of 64-bits')
1571
+ }
1572
+ for (var i = 0; i < len; i += 8) {
1573
+ swap(this, i, i + 7);
1574
+ swap(this, i + 1, i + 6);
1575
+ swap(this, i + 2, i + 5);
1576
+ swap(this, i + 3, i + 4);
1577
+ }
1578
+ return this
1579
+ };
1580
+
1581
+ Buffer.prototype.toString = function toString () {
1582
+ var length = this.length;
1583
+ if (length === 0) return ''
1584
+ if (arguments.length === 0) return utf8Slice(this, 0, length)
1585
+ return slowToString.apply(this, arguments)
1586
+ };
1587
+
1588
+ Buffer.prototype.toLocaleString = Buffer.prototype.toString;
1589
+
1590
+ Buffer.prototype.equals = function equals (b) {
1591
+ if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
1592
+ if (this === b) return true
1593
+ return Buffer.compare(this, b) === 0
1594
+ };
1595
+
1596
+ Buffer.prototype.inspect = function inspect () {
1597
+ var str = '';
1598
+ var max = exports.INSPECT_MAX_BYTES;
1599
+ str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
1600
+ if (this.length > max) str += ' ... ';
1601
+ return '<Buffer ' + str + '>'
1602
+ };
1603
+ if (customInspectSymbol) {
1604
+ Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
1605
+ }
1606
+
1607
+ Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) {
1608
+ if (isInstance(target, Uint8Array)) {
1609
+ target = Buffer.from(target, target.offset, target.byteLength);
1610
+ }
1611
+ if (!Buffer.isBuffer(target)) {
1612
+ throw new TypeError(
1613
+ 'The "target" argument must be one of type Buffer or Uint8Array. ' +
1614
+ 'Received type ' + (typeof target)
1615
+ )
1616
+ }
1617
+
1618
+ if (start === undefined) {
1619
+ start = 0;
1620
+ }
1621
+ if (end === undefined) {
1622
+ end = target ? target.length : 0;
1623
+ }
1624
+ if (thisStart === undefined) {
1625
+ thisStart = 0;
1626
+ }
1627
+ if (thisEnd === undefined) {
1628
+ thisEnd = this.length;
1629
+ }
1630
+
1631
+ if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
1632
+ throw new RangeError('out of range index')
1633
+ }
1634
+
1635
+ if (thisStart >= thisEnd && start >= end) {
1636
+ return 0
1637
+ }
1638
+ if (thisStart >= thisEnd) {
1639
+ return -1
1640
+ }
1641
+ if (start >= end) {
1642
+ return 1
1643
+ }
1644
+
1645
+ start >>>= 0;
1646
+ end >>>= 0;
1647
+ thisStart >>>= 0;
1648
+ thisEnd >>>= 0;
1649
+
1650
+ if (this === target) return 0
1651
+
1652
+ var x = thisEnd - thisStart;
1653
+ var y = end - start;
1654
+ var len = Math.min(x, y);
1655
+
1656
+ var thisCopy = this.slice(thisStart, thisEnd);
1657
+ var targetCopy = target.slice(start, end);
1658
+
1659
+ for (var i = 0; i < len; ++i) {
1660
+ if (thisCopy[i] !== targetCopy[i]) {
1661
+ x = thisCopy[i];
1662
+ y = targetCopy[i];
1663
+ break
1664
+ }
1665
+ }
1666
+
1667
+ if (x < y) return -1
1668
+ if (y < x) return 1
1669
+ return 0
1670
+ };
1671
+
1672
+ // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
1673
+ // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
1674
+ //
1675
+ // Arguments:
1676
+ // - buffer - a Buffer to search
1677
+ // - val - a string, Buffer, or number
1678
+ // - byteOffset - an index into `buffer`; will be clamped to an int32
1679
+ // - encoding - an optional encoding, relevant is val is a string
1680
+ // - dir - true for indexOf, false for lastIndexOf
1681
+ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
1682
+ // Empty buffer means no match
1683
+ if (buffer.length === 0) return -1
1684
+
1685
+ // Normalize byteOffset
1686
+ if (typeof byteOffset === 'string') {
1687
+ encoding = byteOffset;
1688
+ byteOffset = 0;
1689
+ } else if (byteOffset > 0x7fffffff) {
1690
+ byteOffset = 0x7fffffff;
1691
+ } else if (byteOffset < -0x80000000) {
1692
+ byteOffset = -0x80000000;
1693
+ }
1694
+ byteOffset = +byteOffset; // Coerce to Number.
1695
+ if (numberIsNaN(byteOffset)) {
1696
+ // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
1697
+ byteOffset = dir ? 0 : (buffer.length - 1);
1698
+ }
1699
+
1700
+ // Normalize byteOffset: negative offsets start from the end of the buffer
1701
+ if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
1702
+ if (byteOffset >= buffer.length) {
1703
+ if (dir) return -1
1704
+ else byteOffset = buffer.length - 1;
1705
+ } else if (byteOffset < 0) {
1706
+ if (dir) byteOffset = 0;
1707
+ else return -1
1708
+ }
1709
+
1710
+ // Normalize val
1711
+ if (typeof val === 'string') {
1712
+ val = Buffer.from(val, encoding);
1713
+ }
1714
+
1715
+ // Finally, search either indexOf (if dir is true) or lastIndexOf
1716
+ if (Buffer.isBuffer(val)) {
1717
+ // Special case: looking for empty string/buffer always fails
1718
+ if (val.length === 0) {
1719
+ return -1
1720
+ }
1721
+ return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
1722
+ } else if (typeof val === 'number') {
1723
+ val = val & 0xFF; // Search for a byte value [0-255]
1724
+ if (typeof Uint8Array.prototype.indexOf === 'function') {
1725
+ if (dir) {
1726
+ return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
1727
+ } else {
1728
+ return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
1729
+ }
1730
+ }
1731
+ return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
1732
+ }
1733
+
1734
+ throw new TypeError('val must be string, number or Buffer')
1735
+ }
1736
+
1737
+ function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
1738
+ var indexSize = 1;
1739
+ var arrLength = arr.length;
1740
+ var valLength = val.length;
1741
+
1742
+ if (encoding !== undefined) {
1743
+ encoding = String(encoding).toLowerCase();
1744
+ if (encoding === 'ucs2' || encoding === 'ucs-2' ||
1745
+ encoding === 'utf16le' || encoding === 'utf-16le') {
1746
+ if (arr.length < 2 || val.length < 2) {
1747
+ return -1
1748
+ }
1749
+ indexSize = 2;
1750
+ arrLength /= 2;
1751
+ valLength /= 2;
1752
+ byteOffset /= 2;
1753
+ }
1754
+ }
1755
+
1756
+ function read (buf, i) {
1757
+ if (indexSize === 1) {
1758
+ return buf[i]
1759
+ } else {
1760
+ return buf.readUInt16BE(i * indexSize)
1761
+ }
1762
+ }
1763
+
1764
+ var i;
1765
+ if (dir) {
1766
+ var foundIndex = -1;
1767
+ for (i = byteOffset; i < arrLength; i++) {
1768
+ if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
1769
+ if (foundIndex === -1) foundIndex = i;
1770
+ if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
1771
+ } else {
1772
+ if (foundIndex !== -1) i -= i - foundIndex;
1773
+ foundIndex = -1;
1774
+ }
1775
+ }
1776
+ } else {
1777
+ if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
1778
+ for (i = byteOffset; i >= 0; i--) {
1779
+ var found = true;
1780
+ for (var j = 0; j < valLength; j++) {
1781
+ if (read(arr, i + j) !== read(val, j)) {
1782
+ found = false;
1783
+ break
1784
+ }
1785
+ }
1786
+ if (found) return i
1787
+ }
1788
+ }
1789
+
1790
+ return -1
1791
+ }
1792
+
1793
+ Buffer.prototype.includes = function includes (val, byteOffset, encoding) {
1794
+ return this.indexOf(val, byteOffset, encoding) !== -1
1795
+ };
1796
+
1797
+ Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) {
1798
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, true)
1799
+ };
1800
+
1801
+ Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) {
1802
+ return bidirectionalIndexOf(this, val, byteOffset, encoding, false)
1803
+ };
1804
+
1805
+ function hexWrite (buf, string, offset, length) {
1806
+ offset = Number(offset) || 0;
1807
+ var remaining = buf.length - offset;
1808
+ if (!length) {
1809
+ length = remaining;
1810
+ } else {
1811
+ length = Number(length);
1812
+ if (length > remaining) {
1813
+ length = remaining;
1814
+ }
1815
+ }
1816
+
1817
+ var strLen = string.length;
1818
+
1819
+ if (length > strLen / 2) {
1820
+ length = strLen / 2;
1821
+ }
1822
+ for (var i = 0; i < length; ++i) {
1823
+ var parsed = parseInt(string.substr(i * 2, 2), 16);
1824
+ if (numberIsNaN(parsed)) return i
1825
+ buf[offset + i] = parsed;
1826
+ }
1827
+ return i
1828
+ }
1829
+
1830
+ function utf8Write (buf, string, offset, length) {
1831
+ return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
1832
+ }
1833
+
1834
+ function asciiWrite (buf, string, offset, length) {
1835
+ return blitBuffer(asciiToBytes(string), buf, offset, length)
1836
+ }
1837
+
1838
+ function base64Write (buf, string, offset, length) {
1839
+ return blitBuffer(base64ToBytes(string), buf, offset, length)
1840
+ }
1841
+
1842
+ function ucs2Write (buf, string, offset, length) {
1843
+ return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
1844
+ }
1845
+
1846
+ Buffer.prototype.write = function write (string, offset, length, encoding) {
1847
+ // Buffer#write(string)
1848
+ if (offset === undefined) {
1849
+ encoding = 'utf8';
1850
+ length = this.length;
1851
+ offset = 0;
1852
+ // Buffer#write(string, encoding)
1853
+ } else if (length === undefined && typeof offset === 'string') {
1854
+ encoding = offset;
1855
+ length = this.length;
1856
+ offset = 0;
1857
+ // Buffer#write(string, offset[, length][, encoding])
1858
+ } else if (isFinite(offset)) {
1859
+ offset = offset >>> 0;
1860
+ if (isFinite(length)) {
1861
+ length = length >>> 0;
1862
+ if (encoding === undefined) encoding = 'utf8';
1863
+ } else {
1864
+ encoding = length;
1865
+ length = undefined;
1866
+ }
1867
+ } else {
1868
+ throw new Error(
1869
+ 'Buffer.write(string, encoding, offset[, length]) is no longer supported'
1870
+ )
1871
+ }
1872
+
1873
+ var remaining = this.length - offset;
1874
+ if (length === undefined || length > remaining) length = remaining;
1875
+
1876
+ if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
1877
+ throw new RangeError('Attempt to write outside buffer bounds')
1878
+ }
1879
+
1880
+ if (!encoding) encoding = 'utf8';
1881
+
1882
+ var loweredCase = false;
1883
+ for (;;) {
1884
+ switch (encoding) {
1885
+ case 'hex':
1886
+ return hexWrite(this, string, offset, length)
1887
+
1888
+ case 'utf8':
1889
+ case 'utf-8':
1890
+ return utf8Write(this, string, offset, length)
1891
+
1892
+ case 'ascii':
1893
+ case 'latin1':
1894
+ case 'binary':
1895
+ return asciiWrite(this, string, offset, length)
1896
+
1897
+ case 'base64':
1898
+ // Warning: maxLength not taken into account in base64Write
1899
+ return base64Write(this, string, offset, length)
1900
+
1901
+ case 'ucs2':
1902
+ case 'ucs-2':
1903
+ case 'utf16le':
1904
+ case 'utf-16le':
1905
+ return ucs2Write(this, string, offset, length)
1906
+
1907
+ default:
1908
+ if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
1909
+ encoding = ('' + encoding).toLowerCase();
1910
+ loweredCase = true;
1911
+ }
1912
+ }
1913
+ };
1914
+
1915
+ Buffer.prototype.toJSON = function toJSON () {
1916
+ return {
1917
+ type: 'Buffer',
1918
+ data: Array.prototype.slice.call(this._arr || this, 0)
1919
+ }
1920
+ };
1921
+
1922
+ function base64Slice (buf, start, end) {
1923
+ if (start === 0 && end === buf.length) {
1924
+ return base64.fromByteArray(buf)
1925
+ } else {
1926
+ return base64.fromByteArray(buf.slice(start, end))
1927
+ }
1928
+ }
1929
+
1930
+ function utf8Slice (buf, start, end) {
1931
+ end = Math.min(buf.length, end);
1932
+ var res = [];
1933
+
1934
+ var i = start;
1935
+ while (i < end) {
1936
+ var firstByte = buf[i];
1937
+ var codePoint = null;
1938
+ var bytesPerSequence = (firstByte > 0xEF)
1939
+ ? 4
1940
+ : (firstByte > 0xDF)
1941
+ ? 3
1942
+ : (firstByte > 0xBF)
1943
+ ? 2
1944
+ : 1;
1945
+
1946
+ if (i + bytesPerSequence <= end) {
1947
+ var secondByte, thirdByte, fourthByte, tempCodePoint;
1948
+
1949
+ switch (bytesPerSequence) {
1950
+ case 1:
1951
+ if (firstByte < 0x80) {
1952
+ codePoint = firstByte;
1953
+ }
1954
+ break
1955
+ case 2:
1956
+ secondByte = buf[i + 1];
1957
+ if ((secondByte & 0xC0) === 0x80) {
1958
+ tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F);
1959
+ if (tempCodePoint > 0x7F) {
1960
+ codePoint = tempCodePoint;
1961
+ }
1962
+ }
1963
+ break
1964
+ case 3:
1965
+ secondByte = buf[i + 1];
1966
+ thirdByte = buf[i + 2];
1967
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
1968
+ tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F);
1969
+ if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
1970
+ codePoint = tempCodePoint;
1971
+ }
1972
+ }
1973
+ break
1974
+ case 4:
1975
+ secondByte = buf[i + 1];
1976
+ thirdByte = buf[i + 2];
1977
+ fourthByte = buf[i + 3];
1978
+ if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
1979
+ tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F);
1980
+ if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
1981
+ codePoint = tempCodePoint;
1982
+ }
1983
+ }
1984
+ }
1985
+ }
1986
+
1987
+ if (codePoint === null) {
1988
+ // we did not generate a valid codePoint so insert a
1989
+ // replacement char (U+FFFD) and advance only 1 byte
1990
+ codePoint = 0xFFFD;
1991
+ bytesPerSequence = 1;
1992
+ } else if (codePoint > 0xFFFF) {
1993
+ // encode to utf16 (surrogate pair dance)
1994
+ codePoint -= 0x10000;
1995
+ res.push(codePoint >>> 10 & 0x3FF | 0xD800);
1996
+ codePoint = 0xDC00 | codePoint & 0x3FF;
1997
+ }
1998
+
1999
+ res.push(codePoint);
2000
+ i += bytesPerSequence;
2001
+ }
2002
+
2003
+ return decodeCodePointsArray(res)
2004
+ }
2005
+
2006
+ // Based on http://stackoverflow.com/a/22747272/680742, the browser with
2007
+ // the lowest limit is Chrome, with 0x10000 args.
2008
+ // We go 1 magnitude less, for safety
2009
+ var MAX_ARGUMENTS_LENGTH = 0x1000;
2010
+
2011
+ function decodeCodePointsArray (codePoints) {
2012
+ var len = codePoints.length;
2013
+ if (len <= MAX_ARGUMENTS_LENGTH) {
2014
+ return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
2015
+ }
2016
+
2017
+ // Decode in chunks to avoid "call stack size exceeded".
2018
+ var res = '';
2019
+ var i = 0;
2020
+ while (i < len) {
2021
+ res += String.fromCharCode.apply(
2022
+ String,
2023
+ codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
2024
+ );
2025
+ }
2026
+ return res
2027
+ }
2028
+
2029
+ function asciiSlice (buf, start, end) {
2030
+ var ret = '';
2031
+ end = Math.min(buf.length, end);
2032
+
2033
+ for (var i = start; i < end; ++i) {
2034
+ ret += String.fromCharCode(buf[i] & 0x7F);
2035
+ }
2036
+ return ret
2037
+ }
2038
+
2039
+ function latin1Slice (buf, start, end) {
2040
+ var ret = '';
2041
+ end = Math.min(buf.length, end);
2042
+
2043
+ for (var i = start; i < end; ++i) {
2044
+ ret += String.fromCharCode(buf[i]);
2045
+ }
2046
+ return ret
2047
+ }
2048
+
2049
+ function hexSlice (buf, start, end) {
2050
+ var len = buf.length;
2051
+
2052
+ if (!start || start < 0) start = 0;
2053
+ if (!end || end < 0 || end > len) end = len;
2054
+
2055
+ var out = '';
2056
+ for (var i = start; i < end; ++i) {
2057
+ out += hexSliceLookupTable[buf[i]];
2058
+ }
2059
+ return out
2060
+ }
2061
+
2062
+ function utf16leSlice (buf, start, end) {
2063
+ var bytes = buf.slice(start, end);
2064
+ var res = '';
2065
+ // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
2066
+ for (var i = 0; i < bytes.length - 1; i += 2) {
2067
+ res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256));
2068
+ }
2069
+ return res
2070
+ }
2071
+
2072
+ Buffer.prototype.slice = function slice (start, end) {
2073
+ var len = this.length;
2074
+ start = ~~start;
2075
+ end = end === undefined ? len : ~~end;
2076
+
2077
+ if (start < 0) {
2078
+ start += len;
2079
+ if (start < 0) start = 0;
2080
+ } else if (start > len) {
2081
+ start = len;
2082
+ }
2083
+
2084
+ if (end < 0) {
2085
+ end += len;
2086
+ if (end < 0) end = 0;
2087
+ } else if (end > len) {
2088
+ end = len;
2089
+ }
2090
+
2091
+ if (end < start) end = start;
2092
+
2093
+ var newBuf = this.subarray(start, end);
2094
+ // Return an augmented `Uint8Array` instance
2095
+ Object.setPrototypeOf(newBuf, Buffer.prototype);
2096
+
2097
+ return newBuf
2098
+ };
2099
+
2100
+ /*
2101
+ * Need to make sure that buffer isn't trying to write out of bounds.
2102
+ */
2103
+ function checkOffset (offset, ext, length) {
2104
+ if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
2105
+ if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
2106
+ }
2107
+
2108
+ Buffer.prototype.readUintLE =
2109
+ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
2110
+ offset = offset >>> 0;
2111
+ byteLength = byteLength >>> 0;
2112
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
2113
+
2114
+ var val = this[offset];
2115
+ var mul = 1;
2116
+ var i = 0;
2117
+ while (++i < byteLength && (mul *= 0x100)) {
2118
+ val += this[offset + i] * mul;
2119
+ }
2120
+
2121
+ return val
2122
+ };
2123
+
2124
+ Buffer.prototype.readUintBE =
2125
+ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
2126
+ offset = offset >>> 0;
2127
+ byteLength = byteLength >>> 0;
2128
+ if (!noAssert) {
2129
+ checkOffset(offset, byteLength, this.length);
2130
+ }
2131
+
2132
+ var val = this[offset + --byteLength];
2133
+ var mul = 1;
2134
+ while (byteLength > 0 && (mul *= 0x100)) {
2135
+ val += this[offset + --byteLength] * mul;
2136
+ }
2137
+
2138
+ return val
2139
+ };
2140
+
2141
+ Buffer.prototype.readUint8 =
2142
+ Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
2143
+ offset = offset >>> 0;
2144
+ if (!noAssert) checkOffset(offset, 1, this.length);
2145
+ return this[offset]
2146
+ };
2147
+
2148
+ Buffer.prototype.readUint16LE =
2149
+ Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
2150
+ offset = offset >>> 0;
2151
+ if (!noAssert) checkOffset(offset, 2, this.length);
2152
+ return this[offset] | (this[offset + 1] << 8)
2153
+ };
2154
+
2155
+ Buffer.prototype.readUint16BE =
2156
+ Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
2157
+ offset = offset >>> 0;
2158
+ if (!noAssert) checkOffset(offset, 2, this.length);
2159
+ return (this[offset] << 8) | this[offset + 1]
2160
+ };
2161
+
2162
+ Buffer.prototype.readUint32LE =
2163
+ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
2164
+ offset = offset >>> 0;
2165
+ if (!noAssert) checkOffset(offset, 4, this.length);
2166
+
2167
+ return ((this[offset]) |
2168
+ (this[offset + 1] << 8) |
2169
+ (this[offset + 2] << 16)) +
2170
+ (this[offset + 3] * 0x1000000)
2171
+ };
2172
+
2173
+ Buffer.prototype.readUint32BE =
2174
+ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
2175
+ offset = offset >>> 0;
2176
+ if (!noAssert) checkOffset(offset, 4, this.length);
2177
+
2178
+ return (this[offset] * 0x1000000) +
2179
+ ((this[offset + 1] << 16) |
2180
+ (this[offset + 2] << 8) |
2181
+ this[offset + 3])
2182
+ };
2183
+
2184
+ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
2185
+ offset = offset >>> 0;
2186
+ byteLength = byteLength >>> 0;
2187
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
2188
+
2189
+ var val = this[offset];
2190
+ var mul = 1;
2191
+ var i = 0;
2192
+ while (++i < byteLength && (mul *= 0x100)) {
2193
+ val += this[offset + i] * mul;
2194
+ }
2195
+ mul *= 0x80;
2196
+
2197
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
2198
+
2199
+ return val
2200
+ };
2201
+
2202
+ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
2203
+ offset = offset >>> 0;
2204
+ byteLength = byteLength >>> 0;
2205
+ if (!noAssert) checkOffset(offset, byteLength, this.length);
2206
+
2207
+ var i = byteLength;
2208
+ var mul = 1;
2209
+ var val = this[offset + --i];
2210
+ while (i > 0 && (mul *= 0x100)) {
2211
+ val += this[offset + --i] * mul;
2212
+ }
2213
+ mul *= 0x80;
2214
+
2215
+ if (val >= mul) val -= Math.pow(2, 8 * byteLength);
2216
+
2217
+ return val
2218
+ };
2219
+
2220
+ Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
2221
+ offset = offset >>> 0;
2222
+ if (!noAssert) checkOffset(offset, 1, this.length);
2223
+ if (!(this[offset] & 0x80)) return (this[offset])
2224
+ return ((0xff - this[offset] + 1) * -1)
2225
+ };
2226
+
2227
+ Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
2228
+ offset = offset >>> 0;
2229
+ if (!noAssert) checkOffset(offset, 2, this.length);
2230
+ var val = this[offset] | (this[offset + 1] << 8);
2231
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
2232
+ };
2233
+
2234
+ Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
2235
+ offset = offset >>> 0;
2236
+ if (!noAssert) checkOffset(offset, 2, this.length);
2237
+ var val = this[offset + 1] | (this[offset] << 8);
2238
+ return (val & 0x8000) ? val | 0xFFFF0000 : val
2239
+ };
2240
+
2241
+ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
2242
+ offset = offset >>> 0;
2243
+ if (!noAssert) checkOffset(offset, 4, this.length);
2244
+
2245
+ return (this[offset]) |
2246
+ (this[offset + 1] << 8) |
2247
+ (this[offset + 2] << 16) |
2248
+ (this[offset + 3] << 24)
2249
+ };
2250
+
2251
+ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
2252
+ offset = offset >>> 0;
2253
+ if (!noAssert) checkOffset(offset, 4, this.length);
2254
+
2255
+ return (this[offset] << 24) |
2256
+ (this[offset + 1] << 16) |
2257
+ (this[offset + 2] << 8) |
2258
+ (this[offset + 3])
2259
+ };
2260
+
2261
+ Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
2262
+ offset = offset >>> 0;
2263
+ if (!noAssert) checkOffset(offset, 4, this.length);
2264
+ return ieee754$1.read(this, offset, true, 23, 4)
2265
+ };
2266
+
2267
+ Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
2268
+ offset = offset >>> 0;
2269
+ if (!noAssert) checkOffset(offset, 4, this.length);
2270
+ return ieee754$1.read(this, offset, false, 23, 4)
2271
+ };
2272
+
2273
+ Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
2274
+ offset = offset >>> 0;
2275
+ if (!noAssert) checkOffset(offset, 8, this.length);
2276
+ return ieee754$1.read(this, offset, true, 52, 8)
2277
+ };
2278
+
2279
+ Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
2280
+ offset = offset >>> 0;
2281
+ if (!noAssert) checkOffset(offset, 8, this.length);
2282
+ return ieee754$1.read(this, offset, false, 52, 8)
2283
+ };
2284
+
2285
+ function checkInt (buf, value, offset, ext, max, min) {
2286
+ if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
2287
+ if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
2288
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
2289
+ }
2290
+
2291
+ Buffer.prototype.writeUintLE =
2292
+ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
2293
+ value = +value;
2294
+ offset = offset >>> 0;
2295
+ byteLength = byteLength >>> 0;
2296
+ if (!noAssert) {
2297
+ var maxBytes = Math.pow(2, 8 * byteLength) - 1;
2298
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
2299
+ }
2300
+
2301
+ var mul = 1;
2302
+ var i = 0;
2303
+ this[offset] = value & 0xFF;
2304
+ while (++i < byteLength && (mul *= 0x100)) {
2305
+ this[offset + i] = (value / mul) & 0xFF;
2306
+ }
2307
+
2308
+ return offset + byteLength
2309
+ };
2310
+
2311
+ Buffer.prototype.writeUintBE =
2312
+ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
2313
+ value = +value;
2314
+ offset = offset >>> 0;
2315
+ byteLength = byteLength >>> 0;
2316
+ if (!noAssert) {
2317
+ var maxBytes = Math.pow(2, 8 * byteLength) - 1;
2318
+ checkInt(this, value, offset, byteLength, maxBytes, 0);
2319
+ }
2320
+
2321
+ var i = byteLength - 1;
2322
+ var mul = 1;
2323
+ this[offset + i] = value & 0xFF;
2324
+ while (--i >= 0 && (mul *= 0x100)) {
2325
+ this[offset + i] = (value / mul) & 0xFF;
2326
+ }
2327
+
2328
+ return offset + byteLength
2329
+ };
2330
+
2331
+ Buffer.prototype.writeUint8 =
2332
+ Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
2333
+ value = +value;
2334
+ offset = offset >>> 0;
2335
+ if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
2336
+ this[offset] = (value & 0xff);
2337
+ return offset + 1
2338
+ };
2339
+
2340
+ Buffer.prototype.writeUint16LE =
2341
+ Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
2342
+ value = +value;
2343
+ offset = offset >>> 0;
2344
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
2345
+ this[offset] = (value & 0xff);
2346
+ this[offset + 1] = (value >>> 8);
2347
+ return offset + 2
2348
+ };
2349
+
2350
+ Buffer.prototype.writeUint16BE =
2351
+ Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
2352
+ value = +value;
2353
+ offset = offset >>> 0;
2354
+ if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
2355
+ this[offset] = (value >>> 8);
2356
+ this[offset + 1] = (value & 0xff);
2357
+ return offset + 2
2358
+ };
2359
+
2360
+ Buffer.prototype.writeUint32LE =
2361
+ Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
2362
+ value = +value;
2363
+ offset = offset >>> 0;
2364
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
2365
+ this[offset + 3] = (value >>> 24);
2366
+ this[offset + 2] = (value >>> 16);
2367
+ this[offset + 1] = (value >>> 8);
2368
+ this[offset] = (value & 0xff);
2369
+ return offset + 4
2370
+ };
2371
+
2372
+ Buffer.prototype.writeUint32BE =
2373
+ Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
2374
+ value = +value;
2375
+ offset = offset >>> 0;
2376
+ if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
2377
+ this[offset] = (value >>> 24);
2378
+ this[offset + 1] = (value >>> 16);
2379
+ this[offset + 2] = (value >>> 8);
2380
+ this[offset + 3] = (value & 0xff);
2381
+ return offset + 4
2382
+ };
2383
+
2384
+ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
2385
+ value = +value;
2386
+ offset = offset >>> 0;
2387
+ if (!noAssert) {
2388
+ var limit = Math.pow(2, (8 * byteLength) - 1);
2389
+
2390
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
2391
+ }
2392
+
2393
+ var i = 0;
2394
+ var mul = 1;
2395
+ var sub = 0;
2396
+ this[offset] = value & 0xFF;
2397
+ while (++i < byteLength && (mul *= 0x100)) {
2398
+ if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
2399
+ sub = 1;
2400
+ }
2401
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
2402
+ }
2403
+
2404
+ return offset + byteLength
2405
+ };
2406
+
2407
+ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
2408
+ value = +value;
2409
+ offset = offset >>> 0;
2410
+ if (!noAssert) {
2411
+ var limit = Math.pow(2, (8 * byteLength) - 1);
2412
+
2413
+ checkInt(this, value, offset, byteLength, limit - 1, -limit);
2414
+ }
2415
+
2416
+ var i = byteLength - 1;
2417
+ var mul = 1;
2418
+ var sub = 0;
2419
+ this[offset + i] = value & 0xFF;
2420
+ while (--i >= 0 && (mul *= 0x100)) {
2421
+ if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
2422
+ sub = 1;
2423
+ }
2424
+ this[offset + i] = ((value / mul) >> 0) - sub & 0xFF;
2425
+ }
2426
+
2427
+ return offset + byteLength
2428
+ };
2429
+
2430
+ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
2431
+ value = +value;
2432
+ offset = offset >>> 0;
2433
+ if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
2434
+ if (value < 0) value = 0xff + value + 1;
2435
+ this[offset] = (value & 0xff);
2436
+ return offset + 1
2437
+ };
2438
+
2439
+ Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
2440
+ value = +value;
2441
+ offset = offset >>> 0;
2442
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
2443
+ this[offset] = (value & 0xff);
2444
+ this[offset + 1] = (value >>> 8);
2445
+ return offset + 2
2446
+ };
2447
+
2448
+ Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
2449
+ value = +value;
2450
+ offset = offset >>> 0;
2451
+ if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
2452
+ this[offset] = (value >>> 8);
2453
+ this[offset + 1] = (value & 0xff);
2454
+ return offset + 2
2455
+ };
2456
+
2457
+ Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
2458
+ value = +value;
2459
+ offset = offset >>> 0;
2460
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
2461
+ this[offset] = (value & 0xff);
2462
+ this[offset + 1] = (value >>> 8);
2463
+ this[offset + 2] = (value >>> 16);
2464
+ this[offset + 3] = (value >>> 24);
2465
+ return offset + 4
2466
+ };
2467
+
2468
+ Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
2469
+ value = +value;
2470
+ offset = offset >>> 0;
2471
+ if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
2472
+ if (value < 0) value = 0xffffffff + value + 1;
2473
+ this[offset] = (value >>> 24);
2474
+ this[offset + 1] = (value >>> 16);
2475
+ this[offset + 2] = (value >>> 8);
2476
+ this[offset + 3] = (value & 0xff);
2477
+ return offset + 4
2478
+ };
2479
+
2480
+ function checkIEEE754 (buf, value, offset, ext, max, min) {
2481
+ if (offset + ext > buf.length) throw new RangeError('Index out of range')
2482
+ if (offset < 0) throw new RangeError('Index out of range')
2483
+ }
2484
+
2485
+ function writeFloat (buf, value, offset, littleEndian, noAssert) {
2486
+ value = +value;
2487
+ offset = offset >>> 0;
2488
+ if (!noAssert) {
2489
+ checkIEEE754(buf, value, offset, 4);
2490
+ }
2491
+ ieee754$1.write(buf, value, offset, littleEndian, 23, 4);
2492
+ return offset + 4
2493
+ }
2494
+
2495
+ Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
2496
+ return writeFloat(this, value, offset, true, noAssert)
2497
+ };
2498
+
2499
+ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
2500
+ return writeFloat(this, value, offset, false, noAssert)
2501
+ };
2502
+
2503
+ function writeDouble (buf, value, offset, littleEndian, noAssert) {
2504
+ value = +value;
2505
+ offset = offset >>> 0;
2506
+ if (!noAssert) {
2507
+ checkIEEE754(buf, value, offset, 8);
2508
+ }
2509
+ ieee754$1.write(buf, value, offset, littleEndian, 52, 8);
2510
+ return offset + 8
2511
+ }
2512
+
2513
+ Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
2514
+ return writeDouble(this, value, offset, true, noAssert)
2515
+ };
2516
+
2517
+ Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
2518
+ return writeDouble(this, value, offset, false, noAssert)
2519
+ };
2520
+
2521
+ // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
2522
+ Buffer.prototype.copy = function copy (target, targetStart, start, end) {
2523
+ if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer')
2524
+ if (!start) start = 0;
2525
+ if (!end && end !== 0) end = this.length;
2526
+ if (targetStart >= target.length) targetStart = target.length;
2527
+ if (!targetStart) targetStart = 0;
2528
+ if (end > 0 && end < start) end = start;
2529
+
2530
+ // Copy 0 bytes; we're done
2531
+ if (end === start) return 0
2532
+ if (target.length === 0 || this.length === 0) return 0
2533
+
2534
+ // Fatal error conditions
2535
+ if (targetStart < 0) {
2536
+ throw new RangeError('targetStart out of bounds')
2537
+ }
2538
+ if (start < 0 || start >= this.length) throw new RangeError('Index out of range')
2539
+ if (end < 0) throw new RangeError('sourceEnd out of bounds')
2540
+
2541
+ // Are we oob?
2542
+ if (end > this.length) end = this.length;
2543
+ if (target.length - targetStart < end - start) {
2544
+ end = target.length - targetStart + start;
2545
+ }
2546
+
2547
+ var len = end - start;
2548
+
2549
+ if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
2550
+ // Use built-in when available, missing from IE11
2551
+ this.copyWithin(targetStart, start, end);
2552
+ } else {
2553
+ Uint8Array.prototype.set.call(
2554
+ target,
2555
+ this.subarray(start, end),
2556
+ targetStart
2557
+ );
2558
+ }
2559
+
2560
+ return len
2561
+ };
2562
+
2563
+ // Usage:
2564
+ // buffer.fill(number[, offset[, end]])
2565
+ // buffer.fill(buffer[, offset[, end]])
2566
+ // buffer.fill(string[, offset[, end]][, encoding])
2567
+ Buffer.prototype.fill = function fill (val, start, end, encoding) {
2568
+ // Handle string cases:
2569
+ if (typeof val === 'string') {
2570
+ if (typeof start === 'string') {
2571
+ encoding = start;
2572
+ start = 0;
2573
+ end = this.length;
2574
+ } else if (typeof end === 'string') {
2575
+ encoding = end;
2576
+ end = this.length;
2577
+ }
2578
+ if (encoding !== undefined && typeof encoding !== 'string') {
2579
+ throw new TypeError('encoding must be a string')
2580
+ }
2581
+ if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
2582
+ throw new TypeError('Unknown encoding: ' + encoding)
2583
+ }
2584
+ if (val.length === 1) {
2585
+ var code = val.charCodeAt(0);
2586
+ if ((encoding === 'utf8' && code < 128) ||
2587
+ encoding === 'latin1') {
2588
+ // Fast path: If `val` fits into a single byte, use that numeric value.
2589
+ val = code;
2590
+ }
2591
+ }
2592
+ } else if (typeof val === 'number') {
2593
+ val = val & 255;
2594
+ } else if (typeof val === 'boolean') {
2595
+ val = Number(val);
2596
+ }
2597
+
2598
+ // Invalid ranges are not set to a default, so can range check early.
2599
+ if (start < 0 || this.length < start || this.length < end) {
2600
+ throw new RangeError('Out of range index')
2601
+ }
2602
+
2603
+ if (end <= start) {
2604
+ return this
2605
+ }
2606
+
2607
+ start = start >>> 0;
2608
+ end = end === undefined ? this.length : end >>> 0;
2609
+
2610
+ if (!val) val = 0;
2611
+
2612
+ var i;
2613
+ if (typeof val === 'number') {
2614
+ for (i = start; i < end; ++i) {
2615
+ this[i] = val;
2616
+ }
2617
+ } else {
2618
+ var bytes = Buffer.isBuffer(val)
2619
+ ? val
2620
+ : Buffer.from(val, encoding);
2621
+ var len = bytes.length;
2622
+ if (len === 0) {
2623
+ throw new TypeError('The value "' + val +
2624
+ '" is invalid for argument "value"')
2625
+ }
2626
+ for (i = 0; i < end - start; ++i) {
2627
+ this[i + start] = bytes[i % len];
2628
+ }
2629
+ }
2630
+
2631
+ return this
2632
+ };
2633
+
2634
+ // HELPER FUNCTIONS
2635
+ // ================
2636
+
2637
+ var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
2638
+
2639
+ function base64clean (str) {
2640
+ // Node takes equal signs as end of the Base64 encoding
2641
+ str = str.split('=')[0];
2642
+ // Node strips out invalid characters like \n and \t from the string, base64-js does not
2643
+ str = str.trim().replace(INVALID_BASE64_RE, '');
2644
+ // Node converts strings with length < 2 to ''
2645
+ if (str.length < 2) return ''
2646
+ // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
2647
+ while (str.length % 4 !== 0) {
2648
+ str = str + '=';
2649
+ }
2650
+ return str
2651
+ }
2652
+
2653
+ function utf8ToBytes (string, units) {
2654
+ units = units || Infinity;
2655
+ var codePoint;
2656
+ var length = string.length;
2657
+ var leadSurrogate = null;
2658
+ var bytes = [];
2659
+
2660
+ for (var i = 0; i < length; ++i) {
2661
+ codePoint = string.charCodeAt(i);
2662
+
2663
+ // is surrogate component
2664
+ if (codePoint > 0xD7FF && codePoint < 0xE000) {
2665
+ // last char was a lead
2666
+ if (!leadSurrogate) {
2667
+ // no lead yet
2668
+ if (codePoint > 0xDBFF) {
2669
+ // unexpected trail
2670
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2671
+ continue
2672
+ } else if (i + 1 === length) {
2673
+ // unpaired lead
2674
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2675
+ continue
2676
+ }
2677
+
2678
+ // valid lead
2679
+ leadSurrogate = codePoint;
2680
+
2681
+ continue
2682
+ }
2683
+
2684
+ // 2 leads in a row
2685
+ if (codePoint < 0xDC00) {
2686
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2687
+ leadSurrogate = codePoint;
2688
+ continue
2689
+ }
2690
+
2691
+ // valid surrogate pair
2692
+ codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
2693
+ } else if (leadSurrogate) {
2694
+ // valid bmp char, but last char was a lead
2695
+ if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
2696
+ }
2697
+
2698
+ leadSurrogate = null;
2699
+
2700
+ // encode utf8
2701
+ if (codePoint < 0x80) {
2702
+ if ((units -= 1) < 0) break
2703
+ bytes.push(codePoint);
2704
+ } else if (codePoint < 0x800) {
2705
+ if ((units -= 2) < 0) break
2706
+ bytes.push(
2707
+ codePoint >> 0x6 | 0xC0,
2708
+ codePoint & 0x3F | 0x80
2709
+ );
2710
+ } else if (codePoint < 0x10000) {
2711
+ if ((units -= 3) < 0) break
2712
+ bytes.push(
2713
+ codePoint >> 0xC | 0xE0,
2714
+ codePoint >> 0x6 & 0x3F | 0x80,
2715
+ codePoint & 0x3F | 0x80
2716
+ );
2717
+ } else if (codePoint < 0x110000) {
2718
+ if ((units -= 4) < 0) break
2719
+ bytes.push(
2720
+ codePoint >> 0x12 | 0xF0,
2721
+ codePoint >> 0xC & 0x3F | 0x80,
2722
+ codePoint >> 0x6 & 0x3F | 0x80,
2723
+ codePoint & 0x3F | 0x80
2724
+ );
2725
+ } else {
2726
+ throw new Error('Invalid code point')
2727
+ }
2728
+ }
2729
+
2730
+ return bytes
2731
+ }
2732
+
2733
+ function asciiToBytes (str) {
2734
+ var byteArray = [];
2735
+ for (var i = 0; i < str.length; ++i) {
2736
+ // Node's code seems to be doing this and not & 0x7F..
2737
+ byteArray.push(str.charCodeAt(i) & 0xFF);
2738
+ }
2739
+ return byteArray
2740
+ }
2741
+
2742
+ function utf16leToBytes (str, units) {
2743
+ var c, hi, lo;
2744
+ var byteArray = [];
2745
+ for (var i = 0; i < str.length; ++i) {
2746
+ if ((units -= 2) < 0) break
2747
+
2748
+ c = str.charCodeAt(i);
2749
+ hi = c >> 8;
2750
+ lo = c % 256;
2751
+ byteArray.push(lo);
2752
+ byteArray.push(hi);
2753
+ }
2754
+
2755
+ return byteArray
2756
+ }
2757
+
2758
+ function base64ToBytes (str) {
2759
+ return base64.toByteArray(base64clean(str))
2760
+ }
2761
+
2762
+ function blitBuffer (src, dst, offset, length) {
2763
+ for (var i = 0; i < length; ++i) {
2764
+ if ((i + offset >= dst.length) || (i >= src.length)) break
2765
+ dst[i + offset] = src[i];
2766
+ }
2767
+ return i
2768
+ }
2769
+
2770
+ // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
2771
+ // the `instanceof` check but they should be treated as of that type.
2772
+ // See: https://github.com/feross/buffer/issues/166
2773
+ function isInstance (obj, type) {
2774
+ return obj instanceof type ||
2775
+ (obj != null && obj.constructor != null && obj.constructor.name != null &&
2776
+ obj.constructor.name === type.name)
2777
+ }
2778
+ function numberIsNaN (obj) {
2779
+ // For IE11 support
2780
+ return obj !== obj // eslint-disable-line no-self-compare
2781
+ }
2782
+
2783
+ // Create lookup table for `toString('hex')`
2784
+ // See: https://github.com/feross/buffer/issues/219
2785
+ var hexSliceLookupTable = (function () {
2786
+ var alphabet = '0123456789abcdef';
2787
+ var table = new Array(256);
2788
+ for (var i = 0; i < 16; ++i) {
2789
+ var i16 = i * 16;
2790
+ for (var j = 0; j < 16; ++j) {
2791
+ table[i16 + j] = alphabet[i] + alphabet[j];
2792
+ }
2793
+ }
2794
+ return table
2795
+ })();
2796
+ } (buffer));
2797
+
739
2798
  var isValidUTF8_1;
740
2799
 
741
- const { isUtf8 } = require$$0$2;
2800
+ const { isUtf8 } = buffer;
742
2801
 
743
2802
  const { hasBlob } = constants;
744
2803
 
@@ -2690,7 +4749,7 @@ var extension$1 = { format: format$1, parse: parse$2 };
2690
4749
 
2691
4750
  /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex|Readable$", "caughtErrors": "none" }] */
2692
4751
 
2693
- const EventEmitter$1 = require$$0$3;
4752
+ const EventEmitter$1 = require$$0$2;
2694
4753
  const https = require$$1$1;
2695
4754
  const http$1 = require$$2;
2696
4755
  const net = require$$3;
@@ -4137,7 +6196,7 @@ var subprotocol$1 = { parse };
4137
6196
 
4138
6197
  /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex$", "caughtErrors": "none" }] */
4139
6198
 
4140
- const EventEmitter = require$$0$3;
6199
+ const EventEmitter = require$$0$2;
4141
6200
  const http = require$$2;
4142
6201
  const { createHash } = require$$1;
4143
6202